From 1b2909688613eed64339963ffb1735c392a47a3d Mon Sep 17 00:00:00 2001 From: Daylily-Zeleen Date: Sat, 29 Jul 2023 12:16:51 +0800 Subject: [PATCH] fix static checks --- .gitignore | 2 +- README.md | 32 ++++++++-------- README_zh_cn.md | 20 +++++----- build_tool.py => build.py | 13 ++----- demo/.gitignore | 2 +- demo/README.md | 32 ++++++++-------- demo/README_zh_cn.md | 20 +++++----- .../GUS_benchmark.gd | 36 +++++++++--------- .../README.md | 32 ++++++++-------- .../README_zh_cn.md | 20 +++++----- .../libgus.windows.template_debug.x86_64.dll | Bin 805376 -> 805376 bytes ...libgus.windows.template_release.x86_64.dll | Bin 803840 -> 803840 bytes .../gus.gdextension | 4 +- misc/scripts/header_guards.sh | 11 ++++-- src/dserializer.gdany.hpp | 2 +- src/dserializer.gdbase.hpp | 2 +- src/dserializer.hpp | 2 +- src/gus.h | 8 ++-- src/register_types.h | 2 +- 19 files changed, 121 insertions(+), 119 deletions(-) rename build_tool.py => build.py (95%) diff --git a/.gitignore b/.gitignore index da3f700..a226331 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,4 @@ CMakeLists.txt resource.h *.pdb -*.obj \ No newline at end of file +*.obj diff --git a/README.md b/README.md index 3520bd4..25521de 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,14 @@ [中文文档](README_zh_cn.md) <- 点击这里。 -A Godot's universal serializer for size optimization. +A Godot's universal serializer for size optimization. Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 4.x. # Feature: 1. Without losing type information. Need not type detection and forced typce conversion in cross end transfer,just like local parameter transfer. 2. Integer are variable length serialization. 3. The serialized data size is smaller than JSON text to utf8 and the native serialization method `var_to_bytes()`.GUS is especially suitable for the serialization of structured small data transfer in multiplayer games. - 4. GDExtension plugin, high performance. + 4. GDExtension plugin, high performance. You can run the `EditorScript` which named `GUS_benchmark.gd` to view the contrast between `GUS`, `Native`, and `JSON`. @@ -23,7 +23,7 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 1. Download released plugin, install ~~and enable~~ this plugin just like other plugin( If the version is not match, please compile by yourselves). 2. ~~Modify properties of autoload which named `GUS` as you require.~~ 3. Pass variable which without `Object`, `OID`, `Callable`, `Signal` into `GUS.var_to_bytes()` and get the serialized data, than send to network peer. - 3. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. + 4. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. # Be careful: @@ -32,8 +32,8 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 3. ~~The properties of autoload `GUS` between all network peers should keep the same.~~ 4. ~~Currently unsupport Godot 4.x which compiled with `typeof double real_t`.~~ 5. ~~Currently just support platform `windows`.~~ - - + + # TODO: 1. ~~If I find the way to bind static method for `GDScript`, I will get rid of the autoload `GUS`.~~ 2. ~~Compile `linux` and `osx` version.~~ @@ -44,35 +44,35 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot # How to compile: 1. Follow [offical tutorial](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html) to set up you develop enviroment. 2. Clone this repository (with submodule). - 3. You must generate bindings and build library of `godot-cpp` at least once. - - You can use generate and build manully by steps below: - a. Navigate to `godot-cpp` folder. - b. Run command: + 3. You must generate bindings and build library of `godot-cpp` at least once. + - You can use generate and build manully by steps below: + a. Navigate to `godot-cpp` folder. + b. Run command: ``` scons generate_bindings=yes build_library=yes ``` - c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. + c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. - - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. - Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. + - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. + Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. Don't worry, generate bindings and build library of `godot-cpp` would not take many time if the compile conditions have not change. 4. Here is a little different from `godot-cpp` to compile `GUS` (of course, you can use `scons` to compile, too). To do some post process, I use a tool script to compile `GUS`. Navigate to root folder, run command as below to compile `GUS`: ``` - python build_tool.py + python build.py ``` You can add arguments like to build `godot-cpp` at this stage. To learn more arguments detail, run this command. ``` - python build_tool.py -h + python build.py -h ``` Specially, if you not specify the argument `target`, this tool will build both `target=template_debug` and `target=template_release`. - 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. + 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. (Notice: if your use `scons` instead of `python build_tool`, you can only get dynamic library at `bin` folder.) # Benchmark 2.1.5: @@ -675,4 +675,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/README_zh_cn.md b/README_zh_cn.md index a43cea2..e30d126 100644 --- a/README_zh_cn.md +++ b/README_zh_cn.md @@ -23,7 +23,7 @@ 1. 下载发布的插件包,像其他插件一样安装~~和启用~~即可(如果版本不匹配,请自行编译)。 2. ~~根据你的需求代码修改名为`GUS`的Autoload的属性.~~ 3. 传递不包含`Object`、 `OID`、 `Callable`以及 `Signal`的变量给 `GUS.var_to_bytes()`并获取序列化后数据,然后发送给其他网络对等体。 - 3. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 + 4. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 # 注意: @@ -32,7 +32,8 @@ 3. ~~不同端的`GUS`属性必须保持一致才能正确反序列化。~~ 4. ~~当前不支持`typeof double real_t`的自定义构建Godot 4.x版本。~~ 5. ~~当前仅支持`windows`.~~ - + + # TODO: 1. ~~如果我找到绑定静态方法给`GDScript`的办法,我将抛弃自动加载`GUS`, 改为静态方法的方式去实现功能。~~ 2. ~~编译`linux`和`osx`版本。~~ @@ -40,11 +41,12 @@ 4. ~~处理 `Object`、`RID`、`Callable`以及`Signal`。~~ 5. 处理大小端。 + # 如何编译: 1. 根据[官方文档](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html)搭建你的编译环境。 2. 克隆这个仓库(以递归方式克隆,以包含子模块)。 - 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 - - 你可以手动生成并构建: + 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 + - 你可以手动生成并构建: a. 导航到`godot-cpp`文件夹。 b. 运行以下命令。 ``` @@ -52,18 +54,18 @@ ``` c. 完成以后,您需要在下个步骤的命令中添加参数`generate_bindings=no build_library=no`来避免重复构建`GUS`时重复生成`godot-cpp`的绑定与`godot-cpp`的库。 - - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 + - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 别担心,只要编译条件没有变化,重复生成与构建不会占用您太多时间。 - 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: + 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: 导航到根目录,运行以下命令 ``` - python build_tool.py + python build.py ``` 你可以像在编译`godot-cpp`一样对改命令添加其他参数。 你可以使用以下命令来查看更多参数详情: ``` - python build_tool.py -h + python build.py -h ``` 特别的,如果你没有明确`taget`参数,该脚本工具会同时编译`target=template_debug`和 `target=template_release`两种版本。 @@ -669,4 +671,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/build_tool.py b/build.py similarity index 95% rename from build_tool.py rename to build.py index c6b040a..9d1d52c 100644 --- a/build_tool.py +++ b/build.py @@ -1,17 +1,12 @@ -import os +#!/usr/bin/env python + import sys +import os import zipfile import shutil from os.path import join as path_join -build_debug = True -build_release = True - -arg1 = "" -arg2 = "" - - def main(): args = "scons" debug_and_relaese = True @@ -23,7 +18,7 @@ def main(): if arg.startswith("python"): continue - if arg.count("build_tool.py") > 0: + if arg == sys.argv[0]: continue if arg.count("scons") > 0: print("Should not use \"scons\" argument, skip it.") diff --git a/demo/.gitignore b/demo/.gitignore index cfc3a13..c7e22f3 100644 --- a/demo/.gitignore +++ b/demo/.gitignore @@ -6,4 +6,4 @@ export_presets.cfg # Mono-specific ignores .mono/ -data_*/ \ No newline at end of file +data_*/ diff --git a/demo/README.md b/demo/README.md index 3520bd4..25521de 100644 --- a/demo/README.md +++ b/demo/README.md @@ -8,14 +8,14 @@ [中文文档](README_zh_cn.md) <- 点击这里。 -A Godot's universal serializer for size optimization. +A Godot's universal serializer for size optimization. Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 4.x. # Feature: 1. Without losing type information. Need not type detection and forced typce conversion in cross end transfer,just like local parameter transfer. 2. Integer are variable length serialization. 3. The serialized data size is smaller than JSON text to utf8 and the native serialization method `var_to_bytes()`.GUS is especially suitable for the serialization of structured small data transfer in multiplayer games. - 4. GDExtension plugin, high performance. + 4. GDExtension plugin, high performance. You can run the `EditorScript` which named `GUS_benchmark.gd` to view the contrast between `GUS`, `Native`, and `JSON`. @@ -23,7 +23,7 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 1. Download released plugin, install ~~and enable~~ this plugin just like other plugin( If the version is not match, please compile by yourselves). 2. ~~Modify properties of autoload which named `GUS` as you require.~~ 3. Pass variable which without `Object`, `OID`, `Callable`, `Signal` into `GUS.var_to_bytes()` and get the serialized data, than send to network peer. - 3. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. + 4. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. # Be careful: @@ -32,8 +32,8 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 3. ~~The properties of autoload `GUS` between all network peers should keep the same.~~ 4. ~~Currently unsupport Godot 4.x which compiled with `typeof double real_t`.~~ 5. ~~Currently just support platform `windows`.~~ - - + + # TODO: 1. ~~If I find the way to bind static method for `GDScript`, I will get rid of the autoload `GUS`.~~ 2. ~~Compile `linux` and `osx` version.~~ @@ -44,35 +44,35 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot # How to compile: 1. Follow [offical tutorial](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html) to set up you develop enviroment. 2. Clone this repository (with submodule). - 3. You must generate bindings and build library of `godot-cpp` at least once. - - You can use generate and build manully by steps below: - a. Navigate to `godot-cpp` folder. - b. Run command: + 3. You must generate bindings and build library of `godot-cpp` at least once. + - You can use generate and build manully by steps below: + a. Navigate to `godot-cpp` folder. + b. Run command: ``` scons generate_bindings=yes build_library=yes ``` - c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. + c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. - - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. - Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. + - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. + Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. Don't worry, generate bindings and build library of `godot-cpp` would not take many time if the compile conditions have not change. 4. Here is a little different from `godot-cpp` to compile `GUS` (of course, you can use `scons` to compile, too). To do some post process, I use a tool script to compile `GUS`. Navigate to root folder, run command as below to compile `GUS`: ``` - python build_tool.py + python build.py ``` You can add arguments like to build `godot-cpp` at this stage. To learn more arguments detail, run this command. ``` - python build_tool.py -h + python build.py -h ``` Specially, if you not specify the argument `target`, this tool will build both `target=template_debug` and `target=template_release`. - 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. + 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. (Notice: if your use `scons` instead of `python build_tool`, you can only get dynamic library at `bin` folder.) # Benchmark 2.1.5: @@ -675,4 +675,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/demo/README_zh_cn.md b/demo/README_zh_cn.md index a43cea2..e30d126 100644 --- a/demo/README_zh_cn.md +++ b/demo/README_zh_cn.md @@ -23,7 +23,7 @@ 1. 下载发布的插件包,像其他插件一样安装~~和启用~~即可(如果版本不匹配,请自行编译)。 2. ~~根据你的需求代码修改名为`GUS`的Autoload的属性.~~ 3. 传递不包含`Object`、 `OID`、 `Callable`以及 `Signal`的变量给 `GUS.var_to_bytes()`并获取序列化后数据,然后发送给其他网络对等体。 - 3. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 + 4. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 # 注意: @@ -32,7 +32,8 @@ 3. ~~不同端的`GUS`属性必须保持一致才能正确反序列化。~~ 4. ~~当前不支持`typeof double real_t`的自定义构建Godot 4.x版本。~~ 5. ~~当前仅支持`windows`.~~ - + + # TODO: 1. ~~如果我找到绑定静态方法给`GDScript`的办法,我将抛弃自动加载`GUS`, 改为静态方法的方式去实现功能。~~ 2. ~~编译`linux`和`osx`版本。~~ @@ -40,11 +41,12 @@ 4. ~~处理 `Object`、`RID`、`Callable`以及`Signal`。~~ 5. 处理大小端。 + # 如何编译: 1. 根据[官方文档](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html)搭建你的编译环境。 2. 克隆这个仓库(以递归方式克隆,以包含子模块)。 - 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 - - 你可以手动生成并构建: + 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 + - 你可以手动生成并构建: a. 导航到`godot-cpp`文件夹。 b. 运行以下命令。 ``` @@ -52,18 +54,18 @@ ``` c. 完成以后,您需要在下个步骤的命令中添加参数`generate_bindings=no build_library=no`来避免重复构建`GUS`时重复生成`godot-cpp`的绑定与`godot-cpp`的库。 - - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 + - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 别担心,只要编译条件没有变化,重复生成与构建不会占用您太多时间。 - 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: + 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: 导航到根目录,运行以下命令 ``` - python build_tool.py + python build.py ``` 你可以像在编译`godot-cpp`一样对改命令添加其他参数。 你可以使用以下命令来查看更多参数详情: ``` - python build_tool.py -h + python build.py -h ``` 特别的,如果你没有明确`taget`参数,该脚本工具会同时编译`target=template_debug`和 `target=template_release`两种版本。 @@ -669,4 +671,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/GUS_benchmark.gd b/demo/addons/com.daylily_zeleen.godot_universal_serializer/GUS_benchmark.gd index bdbbd24..149ef5e 100644 --- a/demo/addons/com.daylily_zeleen.godot_universal_serializer/GUS_benchmark.gd +++ b/demo/addons/com.daylily_zeleen.godot_universal_serializer/GUS_benchmark.gd @@ -4,11 +4,9 @@ extends EditorScript func _run() -> void: randomize() GUS.set_color_encode_type(GUS.COLOR_ENCODE_TYPE_RAW) -# _print_result("ignore", null) - _test(get_editor_interface().get_base_control()) - - + + var tree:SceneTree func _test(inside_tree_node:Node)->void: tree = inside_tree_node.get_tree() if inside_tree_node and inside_tree_node.is_inside_tree() else null @@ -55,7 +53,7 @@ func _test(inside_tree_node:Node)->void: } dict[532] = [574,-21.0, Vector2(-423,46.8005), Color.AQUA,"acxx"] _print_result("Dictionary",dict) - + # 池化数组测试 var byte_arr := PackedByteArray() var int32_arr := PackedInt32Array() @@ -66,9 +64,9 @@ func _test(inside_tree_node:Node)->void: var vector2_arr := PackedVector2Array() var vector3_arr:= PackedVector3Array() var color_arr:= PackedColorArray() - + _print_result("Empty Array", []) - _print_result("Empty Dictionary", {}) + _print_result("Empty Dictionary", {}) _print_result("Empty PackedByteArray",byte_arr) _print_result("Empty PackedInt32Array",int32_arr) _print_result("Empty PackedInt64Array",int64_arr) @@ -78,7 +76,7 @@ func _test(inside_tree_node:Node)->void: _print_result("Empty PackedVector2Array",vector2_arr) _print_result("Empty PackedVector3Array",vector3_arr) _print_result("Empty PackedColorArray",color_arr) - + var i := 4096 while i>0: byte_arr.push_back(randi()%256) @@ -91,7 +89,7 @@ func _test(inside_tree_node:Node)->void: vector3_arr.push_back(Vector3(i*randf(),i*randf(),i*randf())) color_arr.push_back(Color(randf(),randf(),randf(),randf())) i-=1 - + _print_result("PackedByteArray",byte_arr) _print_result("PackedInt32Array",int32_arr) _print_result("PackedInt64Array",int64_arr) @@ -101,7 +99,7 @@ func _test(inside_tree_node:Node)->void: _print_result("PackedVector2Array",vector2_arr) _print_result("PackedVector3Array",vector3_arr) _print_result("PackedColorArray",color_arr) - + # 类型化数组 var typed_arr_bool :Array[bool] = [] var typed_arr_int :Array[int] = [] @@ -170,7 +168,7 @@ func _test(inside_tree_node:Node)->void: _print_result("Empty Array[PackedVector2Array]", typed_arr_vector2_arr) _print_result("Empty Array[PackedVector3Array]", typed_arr_vector3_arr) _print_result("Empty Array[PackedColorArray]", typed_arr_color_arr) - + i = 4096 while i>0: typed_arr_bool.push_back(randi()%2==0) @@ -220,7 +218,7 @@ func _test(inside_tree_node:Node)->void: typed_arr_vector3_arr.push_back(PackedVector3Array([rand_vec3(),rand_vec3(),rand_vec3(),rand_vec3()])) typed_arr_color_arr.push_back(PackedColorArray([rand_color(), rand_color(), rand_color(), rand_color(), rand_color()])) i-=1 - + _print_result("Array[bool]", typed_arr_bool) _print_result("Array[int]", typed_arr_int) _print_result("Array[float]", typed_arr_float) @@ -272,9 +270,9 @@ func _print_result(title_name:String, v)->void: json_ser_time = Time.get_ticks_usec() - json_ser_time var json_deser_time := Time.get_ticks_usec() json.parse(json_bytes.get_string_from_utf8()) - var json_deser = json.get_data() - json_deser_time = Time.get_ticks_usec() - json_deser_time - + var json_deser = json.get_data() + json_deser_time = Time.get_ticks_usec() - json_deser_time + # GUS var gus_ser_time := Time.get_ticks_usec() var gus_bytes := GUS.var_to_bytes(v) # GUS 序列化后数据 @@ -282,7 +280,7 @@ func _print_result(title_name:String, v)->void: var gus_deser_time := Time.get_ticks_usec() var gus_deser = GUS.bytes_to_var(gus_bytes) gus_deser_time = Time.get_ticks_usec() - gus_deser_time - + # Native var native_ser_time := Time.get_ticks_usec() var native_bytes := var_to_bytes(v) @@ -290,18 +288,18 @@ func _print_result(title_name:String, v)->void: var native_deser_time := Time.get_ticks_usec() var native_deser = convert(bytes_to_var(native_bytes),type) native_deser_time = Time.get_ticks_usec() - native_deser_time - + if typeof(v) == typeof(gus_deser) and str(v) == str(gus_deser): # 检查序列化前后的类型和具体值是否相同 if typeof(v) >TYPE_ARRAY or (v is Array and v.is_typed()): # 池化数组不打印具体值(打印溢出 print("%s - Size:%d\n\t[GUS]: \t\t%d bytes \t\tser %d usec \t\tdeser %d usec\n\t[Native]: \t%d bytes \t\tser %d usec \t\tdeser %d usec\n\t[JSON]:\t\t%d bytes \t\tser %d usec \t\tdeser %d usec"%[ - title_name, v.size(), + title_name, v.size(), gus_bytes.size(), gus_ser_time, gus_deser_time , native_bytes.size() , native_ser_time, native_deser_time, json_bytes.size(), json_ser_time, json_deser_time]) else: print("%s - value:%s\n\t[GUS]: \t\t%d bytes \t\tser %d usec \t\tdeser %d usec\n\t[Native]: \t%d bytes \t\tser %d usec \t\tdeser %d usec\n\t[JSON]:\t\t%d bytes \t\tser %d usec \t\tdeser %d usec"%[ - title_name, str(v), + title_name, str(v), gus_bytes.size(), gus_ser_time, gus_deser_time , native_bytes.size() , native_ser_time, native_deser_time, json_bytes.size(), json_ser_time, json_deser_time]) diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/README.md b/demo/addons/com.daylily_zeleen.godot_universal_serializer/README.md index 3520bd4..25521de 100644 --- a/demo/addons/com.daylily_zeleen.godot_universal_serializer/README.md +++ b/demo/addons/com.daylily_zeleen.godot_universal_serializer/README.md @@ -8,14 +8,14 @@ [中文文档](README_zh_cn.md) <- 点击这里。 -A Godot's universal serializer for size optimization. +A Godot's universal serializer for size optimization. Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 4.x. # Feature: 1. Without losing type information. Need not type detection and forced typce conversion in cross end transfer,just like local parameter transfer. 2. Integer are variable length serialization. 3. The serialized data size is smaller than JSON text to utf8 and the native serialization method `var_to_bytes()`.GUS is especially suitable for the serialization of structured small data transfer in multiplayer games. - 4. GDExtension plugin, high performance. + 4. GDExtension plugin, high performance. You can run the `EditorScript` which named `GUS_benchmark.gd` to view the contrast between `GUS`, `Native`, and `JSON`. @@ -23,7 +23,7 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 1. Download released plugin, install ~~and enable~~ this plugin just like other plugin( If the version is not match, please compile by yourselves). 2. ~~Modify properties of autoload which named `GUS` as you require.~~ 3. Pass variable which without `Object`, `OID`, `Callable`, `Signal` into `GUS.var_to_bytes()` and get the serialized data, than send to network peer. - 3. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. + 4. After the remote network peer obtains the serialized data, passe it into `GUS.bytes_to_var()` to get the same variable as before serialization. # Be careful: @@ -32,8 +32,8 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot 3. ~~The properties of autoload `GUS` between all network peers should keep the same.~~ 4. ~~Currently unsupport Godot 4.x which compiled with `typeof double real_t`.~~ 5. ~~Currently just support platform `windows`.~~ - - + + # TODO: 1. ~~If I find the way to bind static method for `GDScript`, I will get rid of the autoload `GUS`.~~ 2. ~~Compile `linux` and `osx` version.~~ @@ -44,35 +44,35 @@ Support all data types except `Object`, `RID`, `Callable` and `Signal` in Godot # How to compile: 1. Follow [offical tutorial](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html) to set up you develop enviroment. 2. Clone this repository (with submodule). - 3. You must generate bindings and build library of `godot-cpp` at least once. - - You can use generate and build manully by steps below: - a. Navigate to `godot-cpp` folder. - b. Run command: + 3. You must generate bindings and build library of `godot-cpp` at least once. + - You can use generate and build manully by steps below: + a. Navigate to `godot-cpp` folder. + b. Run command: ``` scons generate_bindings=yes build_library=yes ``` - c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. + c. Now you can add `generate_bindings=no build_library=no` at next stage to avoid generate bindings and build library every time when compiling `GUS`. - - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. - Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. + - (Recommand) Generate bindings and build library every time when compiling `GUS`, to keep the compiling condition of `godot-cpp` same as `GUS`. + Just skip this stage and add `generate_bindings=yes build_library=yes` or ignore these command arguments. Don't worry, generate bindings and build library of `godot-cpp` would not take many time if the compile conditions have not change. 4. Here is a little different from `godot-cpp` to compile `GUS` (of course, you can use `scons` to compile, too). To do some post process, I use a tool script to compile `GUS`. Navigate to root folder, run command as below to compile `GUS`: ``` - python build_tool.py + python build.py ``` You can add arguments like to build `godot-cpp` at this stage. To learn more arguments detail, run this command. ``` - python build_tool.py -h + python build.py -h ``` Specially, if you not specify the argument `target`, this tool will build both `target=template_debug` and `target=template_release`. - 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. + 5. Now, you can get the addon which be located at `\demo\addons\com.daylily_zeleen.godot_universal_serializer\`, or get the packed addon at `bin\com.daylily_zeleen.godot_universal_serializer.zip`. (Notice: if your use `scons` instead of `python build_tool`, you can only get dynamic library at `bin` folder.) # Benchmark 2.1.5: @@ -675,4 +675,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/README_zh_cn.md b/demo/addons/com.daylily_zeleen.godot_universal_serializer/README_zh_cn.md index a43cea2..e30d126 100644 --- a/demo/addons/com.daylily_zeleen.godot_universal_serializer/README_zh_cn.md +++ b/demo/addons/com.daylily_zeleen.godot_universal_serializer/README_zh_cn.md @@ -23,7 +23,7 @@ 1. 下载发布的插件包,像其他插件一样安装~~和启用~~即可(如果版本不匹配,请自行编译)。 2. ~~根据你的需求代码修改名为`GUS`的Autoload的属性.~~ 3. 传递不包含`Object`、 `OID`、 `Callable`以及 `Signal`的变量给 `GUS.var_to_bytes()`并获取序列化后数据,然后发送给其他网络对等体。 - 3. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 + 4. 远端的网络对等体获取到序列化后数据,传递给`GUS.bytes_to_var()`,即可获得与序列化前相同的变量。 # 注意: @@ -32,7 +32,8 @@ 3. ~~不同端的`GUS`属性必须保持一致才能正确反序列化。~~ 4. ~~当前不支持`typeof double real_t`的自定义构建Godot 4.x版本。~~ 5. ~~当前仅支持`windows`.~~ - + + # TODO: 1. ~~如果我找到绑定静态方法给`GDScript`的办法,我将抛弃自动加载`GUS`, 改为静态方法的方式去实现功能。~~ 2. ~~编译`linux`和`osx`版本。~~ @@ -40,11 +41,12 @@ 4. ~~处理 `Object`、`RID`、`Callable`以及`Signal`。~~ 5. 处理大小端。 + # 如何编译: 1. 根据[官方文档](https://docs.godotengine.org/zh_CN/stable/development/compiling/index.html)搭建你的编译环境。 2. 克隆这个仓库(以递归方式克隆,以包含子模块)。 - 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 - - 你可以手动生成并构建: + 3. 你必须至少生成一次`godot-cpp`的绑定,并且至少构建一次它的库。 + - 你可以手动生成并构建: a. 导航到`godot-cpp`文件夹。 b. 运行以下命令。 ``` @@ -52,18 +54,18 @@ ``` c. 完成以后,您需要在下个步骤的命令中添加参数`generate_bindings=no build_library=no`来避免重复构建`GUS`时重复生成`godot-cpp`的绑定与`godot-cpp`的库。 - - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 + - (推荐方式)在每次构建`GUS`时重复生成`godot-cpp`的绑定与构建其库,直接跳该步骤,在下个步骤的命令中添加参数`generate_bindings=yes build_library=yes`来显式要求该操作,或忽略这些参数以默认方式工作。 别担心,只要编译条件没有变化,重复生成与构建不会占用您太多时间。 - 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: + 4. 编译`GUS`与编译`godot-cpp`有一点小区别(当然你也可以继续使用`scons`命令进行构建),为了执行一些后处理,我使用一个简单的工具脚本进行编译: 导航到根目录,运行以下命令 ``` - python build_tool.py + python build.py ``` 你可以像在编译`godot-cpp`一样对改命令添加其他参数。 你可以使用以下命令来查看更多参数详情: ``` - python build_tool.py -h + python build.py -h ``` 特别的,如果你没有明确`taget`参数,该脚本工具会同时编译`target=template_debug`和 `target=template_release`两种版本。 @@ -669,4 +671,4 @@ Array[PackedColorArray] - Size:4096 [GUS]: 331459 bytes ser 2359 usec deser 6938 usec [Native]: 360136 bytes ser 2229 usec deser 5728 usec [JSON]: 698894 bytes ser 248205 usec deser 59321 usec -``` \ No newline at end of file +``` diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/bin/libgus.windows.template_debug.x86_64.dll b/demo/addons/com.daylily_zeleen.godot_universal_serializer/bin/libgus.windows.template_debug.x86_64.dll index d3211fe7bf26db82a94ac4051a3e8097cf53fd1b..969ec6531f95edc5ed1f6a010c2890759d65646c 100644 GIT binary patch delta 84 zcmZpeV%RXnaKaDfqG?Aq{;plbD7U$C@nb$lx#rkS?XjB}ftU%1nSq!Eh*^P{ZF}q{ b_VhN8j`rgg96-zo#9Tnkz5TcakEI|0Ka(S= delta 84 zcmZpeV%RXnaKaB}#_HW0f7dQzl;2#r_%R=&d~@uk_Sj8~K+FWh%s|Wn#H>Kfwmo(e bdwLs4NBeOL4j|?PVlE)&-hSMI$5Idg1~?*t diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/bin/libgus.windows.template_release.x86_64.dll b/demo/addons/com.daylily_zeleen.godot_universal_serializer/bin/libgus.windows.template_release.x86_64.dll index a7ee53f1989a24cec74644cc01d4f2ca2d6cb439..c69652f73a6f2e006f36eefad0f5ecadb4c4cff5 100644 GIT binary patch delta 84 zcmZqZFl^{BobZFWdfJhVzjfy^%5B!1|Co diff --git a/demo/addons/com.daylily_zeleen.godot_universal_serializer/gus.gdextension b/demo/addons/com.daylily_zeleen.godot_universal_serializer/gus.gdextension index 6772412..73df076 100644 --- a/demo/addons/com.daylily_zeleen.godot_universal_serializer/gus.gdextension +++ b/demo/addons/com.daylily_zeleen.godot_universal_serializer/gus.gdextension @@ -18,6 +18,6 @@ linux.release.arm64 = "bin/libgus.linux.template_release.arm64.so" linux.debug.rv64 = "bin/libgus.linux.template_debug.rv64.so" linux.release.rv64 = "bin/libgus.linux.template_release.rv64.so" android.debug.x86_64 = "bin/libgus.android.template_debug.x86_64.so" -android.release.x86_64 = "bsin/libgus.android.template_release.x86_64.so" +android.release.x86_64 = "bin/libgus.android.template_release.x86_64.so" android.debug.arm64 = "bin/libgus.android.template_debug.arm64.so" -android.release.arm64 = "bin/libgus.android.template_release.arm64.so" \ No newline at end of file +android.release.arm64 = "bin/libgus.android.template_release.arm64.so" diff --git a/misc/scripts/header_guards.sh b/misc/scripts/header_guards.sh index 7cea339..b27adb2 100644 --- a/misc/scripts/header_guards.sh +++ b/misc/scripts/header_guards.sh @@ -15,12 +15,12 @@ for file in $(find . -name "*.hpp" -print); do bname=$(basename $file .hpp) - # NOTE: The "GODOT_CPP_" prefix is already used by the generated - # bindings, so we can't use that. We'll use "GODOT_" instead. - prefix="GODOT_" + # We needn't prefix. + prefix="" # ^^ is bash builtin for UPPERCASE. guard="${prefix}${bname^^}_HPP" + guard=${guard//./_} # Replaces guards to use computed name. # We also add some \n to make sure there's a proper separation. @@ -30,6 +30,11 @@ for file in $(find . -name "*.hpp" -print); do # Removes redundant \n added before, if they weren't needed. sed -i $file -e "/^$/N;/^\n$/D" + # Skip if has "#pragma once" + pragma_once_line=$(grep -n -m 1 "pragma once" $file | sed 's/\([0-9]*\).*/\1/') + echo -e "$pragma_once_line" + if [[ "$pragma_once_line" != "-1" ]]; then continue; fi + # Check that first ifndef (should be header guard) is at the expected position. # If not it can mean we have some code before the guard that should be after. # "31" is the expected line with the copyright header. diff --git a/src/dserializer.gdany.hpp b/src/dserializer.gdany.hpp index 7be1c6e..d637130 100644 --- a/src/dserializer.gdany.hpp +++ b/src/dserializer.gdany.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "dserializer.gdbase.hpp" diff --git a/src/dserializer.gdbase.hpp b/src/dserializer.gdbase.hpp index 55234d1..342d140 100644 --- a/src/dserializer.gdbase.hpp +++ b/src/dserializer.gdbase.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "dserializer.hpp" diff --git a/src/dserializer.hpp b/src/dserializer.hpp index 0753fde..26d3c37 100644 --- a/src/dserializer.hpp +++ b/src/dserializer.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include diff --git a/src/gus.h b/src/gus.h index 8c636e2..80ffb90 100644 --- a/src/gus.h +++ b/src/gus.h @@ -1,4 +1,4 @@ -/** +/** * @file godot_universal_serialzer.h * @author 忘忧の - DaylilyZeleen (735170336@qq.com) * @brief Godot 4.x 的通用序列化器 - GUS 2.0 @@ -17,8 +17,8 @@ * @copyright Copyright (c) 2022 * MIT License */ -#ifndef GODOT_UNIVERSAL_SERIALIZER_H -#define GODOT_UNIVERSAL_SERIALIZER_H + +#pragma once #include #include @@ -103,5 +103,3 @@ class GUS : public Object { GUS::ColorEncodeType GUS::color_encode_type = GUS::COLOR_ENCODE_TYPE_RAW; VARIANT_ENUM_CAST(GUS::ColorEncodeType); - -#endif \ No newline at end of file diff --git a/src/register_types.h b/src/register_types.h index 1218cf6..4e8e0e7 100644 --- a/src/register_types.h +++ b/src/register_types.h @@ -5,4 +5,4 @@ using namespace godot; void initialize_gus_module(ModuleInitializationLevel p_level); -void uninitialize_gus_module(ModuleInitializationLevel p_level); \ No newline at end of file +void uninitialize_gus_module(ModuleInitializationLevel p_level);