upload zunicode
This commit is contained in:
parent
09c43d4a03
commit
1b3b5ef32b
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/zunicode/file/main.cpp" charset="ISO-8859-1" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
2
go.mod
2
go.mod
@ -3,7 +3,9 @@ module zlib
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect
|
||||
github.com/benbjohnson/clock v1.3.0 // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/zap v1.25.0 // indirect
|
||||
)
|
||||
|
||||
4
go.sum
4
go.sum
@ -1,7 +1,11 @@
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
||||
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
|
||||
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA=
|
||||
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
|
||||
@ -4,12 +4,13 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
"zlib/src/zlog"
|
||||
"zlib/src/zos"
|
||||
)
|
||||
|
||||
type FFileArchive struct {
|
||||
pos, start, stop, size int
|
||||
swapBytes bool
|
||||
reader FReader
|
||||
reader zos.FReader
|
||||
}
|
||||
|
||||
func (ar *FFileArchive) SwapStructBytes(e any) {
|
||||
@ -27,7 +28,7 @@ func NewFileArchive(filename string) *FFileArchive {
|
||||
return nil
|
||||
}
|
||||
s, _ := f.Stat()
|
||||
io := NewReader(f)
|
||||
io := zos.NewReader(f)
|
||||
return &FFileArchive{
|
||||
size: int(s.Size()),
|
||||
stop: -1,
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package zos
|
||||
|
||||
import "errors"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package zos
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
33
src/zunicode/file/00Window.h
Normal file
33
src/zunicode/file/00Window.h
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <wtypes.h>
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(int width, int height, const char* name);
|
||||
HWND GetHWnd() {
|
||||
return hWnd;
|
||||
}
|
||||
static bool ProcessMessages(int& code);
|
||||
private:
|
||||
class WindowClass
|
||||
{
|
||||
public:
|
||||
static const char* GetName() noexcept;
|
||||
static HINSTANCE GetInstance() noexcept;
|
||||
private:
|
||||
WindowClass() noexcept;
|
||||
~WindowClass();
|
||||
WindowClass(const WindowClass&) = delete;
|
||||
WindowClass& operator=(const WindowClass&) = delete;
|
||||
static constexpr const char* wndClassName = "MainWnd";
|
||||
static WindowClass wndClass;
|
||||
HINSTANCE hInst;
|
||||
};
|
||||
private:
|
||||
static LRESULT CALLBACK HandleMsgSetup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
static LRESULT CALLBACK HandleMsgThunk(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
LRESULT HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept;
|
||||
int width;
|
||||
int height;
|
||||
HWND hWnd;
|
||||
};
|
||||
94
src/zunicode/file/01.cpp
Normal file
94
src/zunicode/file/01.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "01 Instance and Devices/03 Connecting with a Vulkan Loader library.h"
|
||||
#include "01 Instance and Devices/05 Loading function exported from a Vulkan Loader library.h"
|
||||
#include "01 Instance and Devices/06 Loading global-level functions.h"
|
||||
#include "01 Instance and Devices/07 Checking available Instance extensions.h"
|
||||
#include "01 Instance and Devices/08 Creating a Vulkan Instance.h"
|
||||
#include "01 Instance and Devices/09 Loading instance-level functions.h"
|
||||
#include "01 Instance and Devices/10 Enumerating available physical devices.h"
|
||||
#include "01 Instance and Devices/11 Checking available device extensions.h"
|
||||
#include <01 Instance and Devices/12 Getting features and properties of a physical device.h>
|
||||
#include <01 Instance and Devices/13 Checking available queue families and their properties.h>
|
||||
#include <01 Instance and Devices/14 Selecting index of a queue family with desired capabilities.h>
|
||||
#include <01 Instance and Devices/15 Creating a logical device.h>
|
||||
#include <01 Instance and Devices/16 Loading device-level functions.h>
|
||||
#include <01 Instance and Devices/17 Getting a device queue.h>
|
||||
#include <01 Instance and Devices/18 Creating a logical device with geometry shaders and graphics queue.h>
|
||||
#include <01 Instance and Devices/19 Destroying a logical device.h>
|
||||
#include <01 Instance and Devices/20 Destroying a Vulkan Instance.h>
|
||||
#include <01 Instance and Devices/21 Releasing a Vulkan Loader library.h>
|
||||
using namespace VulkanCookbook;
|
||||
int main01() {
|
||||
//加载dll
|
||||
LIBRARY_TYPE vulkan_library;
|
||||
ConnectWithVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
|
||||
//加载vulkan接口
|
||||
LoadFunctionExportedFromVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
|
||||
//调用vulkan接口,加载全局函数指针
|
||||
LoadGlobalLevelFunctions();
|
||||
{
|
||||
//调用全局函数指针,检查实例扩展
|
||||
std::vector<VkExtensionProperties> available_extensions;
|
||||
CheckAvailableInstanceExtensions(available_extensions);
|
||||
}
|
||||
|
||||
|
||||
std::vector<char const*> desired_extensions;
|
||||
VkInstance instance;
|
||||
char* application_name = "hello world";
|
||||
//创建实例,依赖实例扩展,需要先检查是否支持
|
||||
CreateVulkanInstance(desired_extensions, application_name, instance);
|
||||
|
||||
|
||||
//调用vulkan接口,加载实例函数指针
|
||||
LoadInstanceLevelFunctions(instance, desired_extensions);
|
||||
//调用实例接口,获取物理设备列表
|
||||
std::vector<VkPhysicalDevice> available_devices;
|
||||
EnumerateAvailablePhysicalDevices(instance, available_devices);
|
||||
VkPhysicalDevice physical_device = available_devices[0];
|
||||
{
|
||||
//调用实例接口,检查物理设备扩展
|
||||
std::vector<VkExtensionProperties> available_extensions;
|
||||
CheckAvailableDeviceExtensions(physical_device, available_extensions);
|
||||
}
|
||||
//调用实例接口,检查物理设备功能
|
||||
VkPhysicalDeviceFeatures device_features;
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
GetFeaturesAndPropertiesOfPhysicalDevice(physical_device, device_features, device_properties);
|
||||
{
|
||||
//调用实例接口,获取物理设备属性
|
||||
std::vector<VkQueueFamilyProperties> queue_families;
|
||||
CheckAvailableQueueFamiliesAndTheirProperties(physical_device, queue_families);
|
||||
}
|
||||
//调用实例接口,获取命令队列信息
|
||||
uint32_t graphics_queue_family_index, compute_queue_family_index;
|
||||
SelectIndexOfQueueFamilyWithDesiredCapabilities(physical_device, VK_QUEUE_GRAPHICS_BIT, graphics_queue_family_index);
|
||||
SelectIndexOfQueueFamilyWithDesiredCapabilities(physical_device, VK_QUEUE_COMPUTE_BIT, compute_queue_family_index);
|
||||
std::vector<QueueInfo> requested_queues = { { graphics_queue_family_index, { 1.0f } } };
|
||||
if (graphics_queue_family_index != compute_queue_family_index) {
|
||||
requested_queues.push_back({ compute_queue_family_index, { 1.0f } });
|
||||
}
|
||||
//调用实例接口,创建逻辑设备,需要检查物理设备扩展,功能,命令队列
|
||||
VkDevice logical_device;
|
||||
CreateLogicalDevice(physical_device, requested_queues, {}, &device_features, logical_device);
|
||||
|
||||
|
||||
//调用vulkan接口,加载设备函数指针
|
||||
LoadDeviceLevelFunctions(logical_device, desired_extensions);
|
||||
//调用设备接口,获取命令队列
|
||||
VkQueue graphics_queue, compute_queue;
|
||||
GetDeviceQueue(logical_device, graphics_queue_family_index, 0, graphics_queue);
|
||||
GetDeviceQueue(logical_device, compute_queue_family_index, 0, compute_queue);
|
||||
CreateLogicalDeviceWithGeometryShadersAndGraphicsAndComputeQueues(instance, logical_device, graphics_queue, compute_queue);
|
||||
|
||||
//调用设备接口,销毁逻辑设备
|
||||
DestroyLogicalDevice(logical_device);
|
||||
//调用实例接口,销毁vulkan实例1
|
||||
DestroyVulkanInstance(instance);
|
||||
//调用系统接口,销毁dll
|
||||
ReleaseVulkanLoaderLibrary(vulkan_library);
|
||||
return 1;
|
||||
}
|
||||
41
src/zunicode/file/main.cpp
Normal file
41
src/zunicode/file/main.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#define VK_USE_PLATFORM_WIN32_KHR 1
|
||||
#include "external/vulkan.h"
|
||||
#include <Window.h>
|
||||
#include "01 Instance and Devices/03 Connecting with a Vulkan Loader library.h"
|
||||
#include "01 Instance and Devices/05 Loading function exported from a Vulkan Loader library.h"
|
||||
#include "01 Instance and Devices/06 Loading global-level functions.h"
|
||||
#include "01 Instance and Devices/07 Checking available Instance extensions.h"
|
||||
#include "02 Image Presentation/02 Creating a presentation surface.h"
|
||||
#include "02 Image Presentation/01 Creating a Vulkan Instance with WSI extensions enabled.h"
|
||||
|
||||
using namespace VulkanCookbook;
|
||||
int main() {
|
||||
//加载dll
|
||||
LIBRARY_TYPE vulkan_library;
|
||||
ConnectWithVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
//加载vulkan接口
|
||||
LoadFunctionExportedFromVulkanLoaderLibrary(vulkan_library);
|
||||
|
||||
//调用vulkan接口,加载全局函数指针
|
||||
LoadGlobalLevelFunctions();
|
||||
{
|
||||
//调用全局函数指针,检查实例扩展
|
||||
std::vector<VkExtensionProperties> available_extensions;
|
||||
CheckAvailableInstanceExtensions(available_extensions);
|
||||
}
|
||||
|
||||
std::vector<char const*> desired_extensions;
|
||||
char* application_name = "hello world";
|
||||
VkInstance instance;
|
||||
CreateVulkanInstanceWithWsiExtensionsEnabled(desired_extensions, application_name, instance);
|
||||
|
||||
auto pWnd = new Window(600, 800, "Game Window");
|
||||
WindowParameters window_parameters;
|
||||
VkSurfaceKHR presentation_surface;
|
||||
//presentation_surface.
|
||||
CreatePresentationSurface(instance, window_parameters, presentation_surface);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
66
src/zunicode/utf8.go
Normal file
66
src/zunicode/utf8.go
Normal file
@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"github.com/axgle/mahonia"
|
||||
"github.com/saintfish/chardet"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"zlib/src/zlog"
|
||||
)
|
||||
|
||||
type Decoder = mahonia.Decoder
|
||||
|
||||
var decMap = make(map[string]Decoder)
|
||||
|
||||
func parseAllFiles(root string) []string {
|
||||
var files []string
|
||||
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() {
|
||||
files = append(files, path)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return files
|
||||
}
|
||||
func getDecoder(name string) Decoder {
|
||||
dec := decMap[name]
|
||||
if dec != nil {
|
||||
return dec
|
||||
}
|
||||
dec = mahonia.NewDecoder(name)
|
||||
decMap[name] = dec
|
||||
return dec
|
||||
}
|
||||
func convertFile(file string) {
|
||||
from, _ := os.ReadFile(file)
|
||||
det := chardet.NewTextDetector()
|
||||
result, err := det.DetectBest(from)
|
||||
if err != nil {
|
||||
zlog.Errorf("error DetectBest: %s", err.Error())
|
||||
return
|
||||
}
|
||||
if result.Charset == "UTF-8" || result.Confidence < 80 {
|
||||
return
|
||||
}
|
||||
dec := getDecoder(result.Charset)
|
||||
to := dec.ConvertString(string(from))
|
||||
f, _ := os.OpenFile(file, os.O_WRONLY, 0777)
|
||||
w := bufio.NewWriter(f)
|
||||
w.WriteString(to)
|
||||
w.Flush()
|
||||
zlog.Infof("%d %s %s", result.Confidence, result.Charset, file)
|
||||
}
|
||||
func main() {
|
||||
root := "F:\\zvulkan\\vulkanLearn\\src"
|
||||
files := parseAllFiles(root)
|
||||
for _, file := range files {
|
||||
convertFile(file)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user