diff --git a/gd_eos/eos_code_generator.py b/gd_eos/eos_code_generator.py index a3001a4..d9b9b7d 100644 --- a/gd_eos/eos_code_generator.py +++ b/gd_eos/eos_code_generator.py @@ -6,6 +6,9 @@ # TODO: 为有Callable参数的方法生成强类型的回调版本供cpp使用 # TODO: 对RTC的子句柄进行处理,避免硬编码 +# TODO: 对文档提及的成员进行 GDS接口化 +# TODO: 跳过展开结构的无用成员文档 + sdk_include_dir = "thirdparty/eos-sdk/SDK/Include" gen_dir = "gd_eos/gen/" @@ -123,9 +126,8 @@ def generator_eos_interfaces() -> None: gen_all_in_one() print("Generate Completed!") - def preprocess(): - # 除去 eos_base.h 中的 #define EOS_HAS_ENUM_CLASS, 印象枚举的绑定 + # 除去 eos_base.h 中的 #define EOS_HAS_ENUM_CLASS, 影响枚举的绑定 f = open(os.path.join(sdk_include_dir, "eos_base.h"), "r") lines: list[str] = f.readlines() f.close() @@ -197,7 +199,7 @@ def gen_all_in_one(): f"\tgodot::Engine::get_singleton()->register_singleton(godot::eos::{handle_class}::get_class_static(), godot::eos::{handle_class}::get_singleton());\\" ) if handle_type == "EOS_HPlatform": - continue # Pltform 接口必须在最后析构 + continue # Platform 接口必须在最后析构 unregister_singleton_lines.append(f"\tgodot::Engine::get_singleton()->unregister_singleton(godot::eos::{handle_class}::get_class_static());\\") unregister_singleton_lines.append(f"\tmemdelete(godot::eos::{handle_class}::get_singleton());\\") @@ -1595,7 +1597,7 @@ def _gen_packed_result_type( decayed_type: str = _decay_eos_type(arg["type"]) snake_name: str = to_snake_case(arg_name.removeprefix("IntOut").removeprefix("Out").removeprefix("bOut")) if _is_handle_arr_type(arg_type, arg_name): - print("ERROR UNSUPPORT handle arr:", method_name, arg_type) + print("ERROR UNSUPPORTED handle arr:", method_name, arg_type) exit(1) elif _is_handle_type(decayed_type): # Handle 类型需要前向声明 @@ -1626,10 +1628,10 @@ def _gen_packed_result_type( r_cpp_lines.append(f"_DEFINE_SETGET({typename}, {snake_name})") bind_lines.append(f"\t_BIND_PROP({snake_name})") elif _is_str_type(arg_type, arg_name): - print("ERROR: UNSUPPORT") + print("ERROR: UNSUPPORTED") exit(1) elif _is_str_arr_type(arg_type, arg_name): - print("ERROR: UNSUPPORT") + print("ERROR: UNSUPPORTED") exit(1) elif arg_type == "char*" and (i + 1) < len(out_args) and out_args[i + 1]["type"].endswith("int32_t*") and out_args[i + 1]["name"].endswith("Length"): # 配合 _MAX_LENGTH 宏的字符串 @@ -1653,13 +1655,13 @@ def _gen_packed_result_type( bind_lines.append(f"\t_BIND_PROP_BOOL({snake_name})") i += 1 elif _is_arr_field(arg_type, arg_name): - print("ERROR UNSUPPORT arr:", method_name, arg_type) + print("ERROR UNSUPPORTED arr:", method_name, arg_type) exit(1) elif _is_internal_struct_arr_field(arg_type, arg_name): - print("ERROR UNSUPPORT struct arr:", method_name, arg_type) + print("ERROR UNSUPPORTED struct arr:", method_name, arg_type) exit(1) elif _is_audio_frames_type(arg_type, arg_name): - print("ERROR UNSUPPORT struct arr:", method_name, arg_type) + print("ERROR UNSUPPORTED struct arr:", method_name, arg_type) exit(1) elif _is_enum_flags_type(arg_type): members_lines.append(f"\tBitField<{decayed_type}> {snake_name};") @@ -1681,7 +1683,7 @@ def _gen_packed_result_type( if method_info["return"] == "EOS_EResult": r_h_lines.append(f"\tEOS_EResult result_code{{ EOS_EResult::EOS_InvalidParameters }};") else: - print("ERROR unsupport to gen packed result:", method_name) + print("ERROR unsupported to gen packed result:", method_name) r_h_lines += members_lines r_h_lines.append("") r_h_lines.append(f"public:") @@ -1799,7 +1801,7 @@ def _gen_callback( return_type: str = infos["return"] if not __is_struct_type(_decay_eos_type(arg_type)): - print("ERROR unsupport callback:", callback_type) + print("ERROR unsupported callback:", callback_type) exit(1) signal_name = __convert_to_signal_name(callback_type) @@ -1814,7 +1816,7 @@ def _gen_callback( elif len(return_type): if for_gen_signal_binding: return "" - print("ERROR unsupport callback type:", callback_type) + print("ERROR unsupported callback type:", callback_type) exit(1) else: ret = f'_EOS_METHOD_CALLBACK({arg_type}, data, "{signal_name}", {gd_cb_info_type})' @@ -1852,7 +1854,7 @@ def _gen_callback( if len(return_type): if for_gen_signal_binding: return "" - print("ERROR unsupport callback type:", callback_type) + print("ERROR unsupported callback type:", callback_type) exit(1) else: ret = f'\n\t\t_EOS_METHOD_CALLBACK_EXPANDED({arg_type}, data, "{signal_name}"' @@ -1998,7 +2000,7 @@ def __expand_input_struct( r_bind_args: list[str], r_prepare_lines: list[str], r_after_call_lines: list[str], - r_bind_defvals: list[str], + r_bind_def_vals: list[str], r_required_arg_doc: dict[str, list[str]], # 字段 -> 文档 ): decayed_type = _decay_eos_type(arg_type) @@ -2050,7 +2052,7 @@ def __expand_input_struct( elif _is_audio_frames_type(arg_type, arg_name): r_declare_args.append(f"const PackedInt32Array &p_{snake_field}") r_prepare_lines.append(f"\tLocalVector _shadow_{snake_field};") - r_prepare_lines.append(f"\t_packedint32_to_autio_frames(p_{snake_field}, _shadow_{snake_field});") + r_prepare_lines.append(f"\t_packed_int32_to_audio_frames(p_{snake_field}, _shadow_{snake_field});") r_prepare_lines.append(f"\t{arg_name}.{_find_count_field(field, fields.keys())} = _shadow_{snake_field}.size();") r_prepare_lines.append(f"\t{options_field} = _shadow_{snake_field}.ptr();") elif _is_socket_id_type(decay_field_type, field): @@ -2060,7 +2062,7 @@ def __expand_input_struct( f"\tif (ascii_{snake_field}.size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && ascii_{snake_field}.get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) {{" ) r_prepare_lines.append( - f'\t\tERR_PRINT(vformat("EOS: Socket name \\"%s\\"\'s length is greater than %d (in ASCII), will be truncatured.", p_{snake_field}, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1));' + f'\t\tERR_PRINT(vformat("EOS: Socket name \\"%s\\"\'s length is greater than %d (in ASCII), will be truncated.", p_{snake_field}, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1));' ) r_prepare_lines.append(f"\t\tascii_{snake_field}.resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE);") r_prepare_lines.append(f"\t\tascii_{snake_field}.set(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1, 0);") @@ -2085,7 +2087,7 @@ def __expand_input_struct( elif _is_requested_channel_ptr_field(field_type, field): r_declare_args.append(f"{remap_type(field_type, field)} p_{snake_field} = -1") r_prepare_lines.append(f"\t_TO_EOS_FIELD_REQUESTED_CHANNEL({options_field}, p_{snake_field});") - r_bind_defvals.append("DEFVAL(-1)") + r_bind_def_vals.append("DEFVAL(-1)") elif field_type.startswith("Union"): r_declare_args.append(f"const {remap_type(_decay_eos_type(field_type), field)} &p_{snake_field}") if _is_variant_union_type(field_type, field): @@ -2158,7 +2160,7 @@ def __make_packed_result( r_after_call_lines.append(f"\tret->result_code = result_code;") r_after_call_lines.append(f"\tif (result_code == EOS_EResult::EOS_Success) {{") else: - print("Error UNSUPPORT:", method_name) + print("Error UNSUPPORTED:", method_name) exit(1) acl_indents = "\t\t" if has_result_code else "\t" i = begin_idx @@ -2169,7 +2171,7 @@ def __make_packed_result( snake_name: str = to_snake_case(arg_name.removeprefix("InOut").removeprefix("Out").removeprefix("bOut")) if _is_handle_arr_type(arg_type, arg_name): - print("ERROR UNSUPPORT handle arr:", method_name, arg_type) + print("ERROR UNSUPPORTED handle arr:", method_name, arg_type) exit(1) elif _is_handle_type(decayed_type): r_prepare_lines.append(f"\t{decayed_type} {arg_name}{{ nullptr }};") @@ -2219,11 +2221,11 @@ def __make_packed_result( r_after_call_lines.append(f"{acl_indents}{remap_type(decayed_type, arg_name)} ret = {arg_name};") elif arg_type == "char*" and (i + 1) < len(args) and args[i + 1]["type"].endswith("int32_t*") and args[i + 1]["name"].endswith("Length"): r_prepare_lines.append(f"\tchar {arg_name} [{__get_str_result_max_length_macro(method_name)} + 1] {{}};") - initialize_vlaue = "0" + initialize_value = "0" if args[i + 1]["name"].startswith("InOut"): - initialize_vlaue = f"{__get_str_result_max_length_macro(method_name)} + 1" + initialize_value = f"{__get_str_result_max_length_macro(method_name)} + 1" - r_prepare_lines.append(f'\t{_decay_eos_type(args[i+1]["type"])} {args[i+1]["name"]}{{ {initialize_vlaue} }};') + r_prepare_lines.append(f'\t{_decay_eos_type(args[i+1]["type"])} {args[i+1]["name"]}{{ {initialize_value} }};') r_call_args.append(f"&{arg_name}[0]") r_call_args.append(f'&{args[i+1]["name"]}') @@ -2278,17 +2280,17 @@ def __make_packed_result( i += 1 elif _is_arr_field(arg_type, arg_name): - print("ERROR UNSUPPORT arr:", method_name, arg_type) + print("ERROR UNSUPPORTED arr:", method_name, arg_type) exit(1) elif _is_internal_struct_arr_field(arg_type, arg_name): - print("ERROR UNSUPPORT struct arr:", method_name, arg_type) + print("ERROR UNSUPPORTED struct arr:", method_name, arg_type) exit(1) elif _is_struct_ptr(arg_type): - print("ERROR UNSUPPORT struct ptr:", method_name, arg_type) + print("ERROR UNSUPPORTED struct ptr:", method_name, arg_type) exit(1) else: if not arg_type.endswith("*"): - print("ERROR UNSUPPORT out: ", arg_type, arg_name) + print("ERROR UNSUPPORTED out: ", arg_type, arg_name) exit(1) r_prepare_lines.append(f'\t{arg_type.removesuffix("*")} {arg_name};') @@ -2419,7 +2421,7 @@ def _gen_method( static: bool = True i: int = 0 - bind_defvals: list[str] = [] + bind_def_vals: list[str] = [] expended_args_doc: dict[str, list[str]] = {}# 字段 -> doc additional_doc: list[str] = [] @@ -2472,7 +2474,7 @@ def _gen_method( else: call_args.append(f"{_gen_callback(decayed_type, [])}") - bind_defvals.append("DEFVAL(Callable())") + bind_def_vals.append("DEFVAL(Callable())") # 插入回调的文档 expended_args_doc[name] = __make_callback_doc(decayed_type) elif __is_client_data(type, name): @@ -2527,7 +2529,7 @@ def _gen_method( options_input_identifier = f"p_{snake_name} " options_prepare_identifier = f"{name}" # 被展开的输入结构体(Options) - __expand_input_struct(type, name, invalid_arg_return_val, declare_args, call_args, bind_args, prepare_lines, after_call_lines, bind_defvals, expended_args_doc) + __expand_input_struct(type, name, invalid_arg_return_val, declare_args, call_args, bind_args, prepare_lines, after_call_lines, bind_def_vals, expended_args_doc) elif name.startswith("Out") or name.startswith("InOut") or name.startswith("bOut"): # Out 参数 converted_return_type: list[str] = [] @@ -2571,14 +2573,14 @@ def _gen_method( bind_args.append(f'"{snake_name}"') call_args.append(f"to_eos_type<{type}>(p_{snake_name})") elif _is_handle_arr_type(type, name): - print("ERROR: Unsupport handle arr argument:", method_name, type, name) + print("ERROR: Unsupported handle arr argument:", method_name, type, name) exit(1) elif _is_handle_type(decayed_type): declare_args.append(f"const {remap_type(decayed_type, name)} &p_{snake_name}") bind_args.append(f'"{snake_name}"') call_args.append(f"p_{snake_name}.is_valid()? p_{snake_name}->get_handle() : nullptr") elif name.endswith("StringBufferSizeBytes"): - # xxxGetFilname 的字符串 buffer 长度不是使用 InOut 来传入缓冲区大小并传出缓冲区被使用的大小, + # xxxGetFilename 的字符串 buffer 长度不是使用 InOut 来传入缓冲区大小并传出缓冲区被使用的大小, # 而是使用 Out 进行传出 + xxxStringBufferSizeBytes 来传入缓冲区大小 prepare_lines.append(f"\t{type} {name} = {__get_str_result_max_length_macro(method_name)} + 1;") call_args.append(name) @@ -2691,8 +2693,8 @@ def _gen_method( if len(bind_args_text): bind_args_text = ", " + bind_args_text default_val_arg = "" - if len(bind_defvals): - default_val_arg = ", " + ", ".join(bind_defvals) + if len(bind_def_vals): + default_val_arg = ", " + ", ".join(bind_def_vals) bind_prefix: str = "ClassDB::bind_static_method(get_class_static(), " if static else "ClassDB::bind_method(" r_bind_lines.append(f'\t{bind_prefix}D_METHOD("{snake_method_name}"{bind_args_text}), &{handle_klass}::{snake_method_name}{default_val_arg});') @@ -2785,7 +2787,7 @@ def _convert_enum_type(ori: str) -> str: splits.pop(0) return "_".join(splits) else: - print("ERROR: Unsupport:", ori) + print("ERROR: Unsupported:", ori) return ori @@ -2849,12 +2851,12 @@ def _is_need_skip_enum_value(ori_enum_type: str, enum_value: str) -> bool: def _get_enum_owned_interface(ori_enum_type: str) -> str: for infos in generate_infos.values(): if ori_enum_type in infos["enums"]: - print("ERROR UNSUPPORT ENUM:", ori_enum_type) + print("ERROR UNSUPPORTED ENUM:", ori_enum_type) exit(1) for h in infos["handles"]: if ori_enum_type in infos["handles"][h]["enums"]: return _convert_handle_class_name(h) - print("ERROR UNSUPPORT ENUM !:", ori_enum_type) + print("ERROR UNSUPPORTED ENUM !:", ori_enum_type) exit(1) @@ -2895,12 +2897,12 @@ def remap_type(type: str, field: str = "") -> str: return "Callable" if type.startswith("Union") and len(field): - uion_field_map = { + union_field_map = { "ParamValue": "Variant", "Value": "Variant", "AccountId": "String", } - return uion_field_map[field] + return union_field_map[field] todo_types = { # @@ -2951,7 +2953,7 @@ def remap_type(type: str, field: str = "") -> str: "EOS_OnlinePlatformType": "uint32_t", "EOS_IntegratedPlatformType": "String", "Union{EOS_AntiCheatCommon_ClientHandle : ClientHandle, const char* : String, uint32_t : UInt32, in, EOS_AntiCheatCommon_Vec3f : Vec3f, EOS_AntiCheatCommon_Quat : Quat}": "Variant", - "Union{int64_t : AsInt64, double : AsDouble, EOS_Bool : AsBool, const char* : AsUtf8}": "Vaiant", + "Union{int64_t : AsInt64, double : AsDouble, EOS_Bool : AsBool, const char* : AsUtf8}": "Variant", "Union{EOS_EpicAccountId : Epic, const char* : External}": "String", "EOS_AntiCheatCommon_ClientHandle": "EOSAntiCheatCommon_Client *", # @@ -3264,7 +3266,6 @@ def _parse_file(interface_lower: str, fp: str, r_file_lower2infos: dict[str, dic doc.append(f"@see EOS_Platform_Get{interface_type}Interface\n") i = j r_file_lower2infos[interface_lower]["interface_doc"] = doc - print("----", interface_lower, interface_type) break @@ -3414,7 +3415,7 @@ def _parse_file(interface_lower: str, fp: str, r_file_lower2infos: dict[str, dic doc = _extract_doc(lines, i - 1) if line.startswith("union"): # Union - union_fileds = {} + union_fields = {} i += 2 while not lines[i].lstrip("\t").startswith("}"): line = lines[i].lstrip("\t").rstrip("\n") @@ -3427,12 +3428,12 @@ def _parse_file(interface_lower: str, fp: str, r_file_lower2infos: dict[str, dic print(f"-ERROR: {fp}:{i}\n") print(f"{lines[i]}") else: - union_fileds[splits[1]] = splits[0] + union_fields[splits[1]] = splits[0] i += 1 union_type = "Union{" - for union_f in union_fileds.keys(): - union_type += f"{union_fileds[union_f]} : {union_f}, " + for union_f in union_fields.keys(): + union_type += f"{union_fields[union_f]} : {union_f}, " union_type = union_type.rstrip(" ").rstrip(",") + "}" field = lines[i].lstrip("\t").lstrip("}").lstrip(" ").rstrip("\n").rstrip(";") @@ -3593,27 +3594,27 @@ def _is_handle_type(type: str, field: str = "") -> bool: def _find_count_field(field: str, fields: list[str]) -> str: splits = to_snake_case(field).split("_") - similars_fileds: list[str] = [] + similar_fields: list[str] = [] for f in fields: if f == fields: continue if f.endswith("Count") or f.endswith("Size") or f.endswith("Length") or f.endswith("LengthBytes") or f.endswith("SizeBytes"): - fsplited = to_snake_case(f).split("_") + f_splits = to_snake_case(f).split("_") similar = 0 - for i in range(min(2, len(fsplited), len(splits))): - if fsplited[i].removesuffix("s").removesuffix("y") == splits[i].removesuffix("ies").removesuffix("s"): + for i in range(min(2, len(f_splits), len(splits))): + if f_splits[i].removesuffix("s").removesuffix("y") == splits[i].removesuffix("ies").removesuffix("s"): similar += 1 else: break - if similar >= min(2, len(fsplited), len(splits)): + if similar >= min(2, len(f_splits), len(splits)): return f else: if similar > 0: - similars_fileds.append(f) - if len(similars_fileds) == 1: - return similars_fileds[0] + similar_fields.append(f) + if len(similar_fields) == 1: + return similar_fields[0] - print("== error:", field, similars_fileds) + print("== error:", field, similar_fields) print(field, fields) exit(1) @@ -3637,7 +3638,7 @@ def _is_memory_func_type(type: str) -> bool: return type in ["EOS_AllocateMemoryFunc", "EOS_ReallocateMemoryFunc", "EOS_ReleaseMemoryFunc"] -def _is_integreate_platform_init_option(type: str, field: str) -> bool: +def _is_integrated_platform_init_option(type: str, field: str) -> bool: return type == "const void*" and field == "InitOptions" @@ -3702,7 +3703,7 @@ def _gen_struct_v2( if f == field + "Type": variant_union_type_fields.append(f) - addtional_methods_requirements = struct2additional_method_requirements[struct_type] + additional_methods_requirements = struct2additional_method_requirements[struct_type] typename = __convert_to_struct_class(struct_type) @@ -3711,18 +3712,18 @@ def _gen_struct_v2( type: str = fields[field]["type"] snake_field_name: str = to_snake_case(field) decayed_type: str = _decay_eos_type(type) - remaped_type: str = "" + remapped_type: str = "" if not _is_need_skip_struct(decayed_type) and __is_struct_type(decayed_type) and not _is_internal_struct_arr_field(type, field): # 非数组的结构体 - remaped_type = remap_type(decayed_type, field) + remapped_type = remap_type(decayed_type, field) elif _is_nullable_float_pointer_field(type, field): - remaped_type = _decay_eos_type(type) + remapped_type = _decay_eos_type(type) elif _is_handle_type(decayed_type): - # 句柄类型使用Ref作为成员变量,非msvc编译器不支持Ref作为成员时T的前向声明 - remaped_type = "Ref" + # 句柄类型使用Ref作为成员变量,非 msvc 编译器不支持Ref作为成员时T的前向声明 + remapped_type = "Ref" else: - remaped_type = remap_type(type, field) + remapped_type = remap_type(type, field) if is_deprecated_field(field): continue @@ -3744,7 +3745,7 @@ def _gen_struct_v2( continue # 暴露的结构体不再含有 ClientData 字段 elif __is_api_version_field(type, field): continue # 不需要ApiVersion作为成员 - elif remaped_type == "bool": + elif remapped_type == "bool": bind_lines.append(f"\t_BIND_PROP_BOOL({snake_field_name})") member_lines.append(f"\tbool {snake_field_name}{{}};") setget_declare_lines.append(f"\t_DECLARE_SETGET_BOOL({snake_field_name})") @@ -3752,7 +3753,7 @@ def _gen_struct_v2( elif _is_socket_id_type(decayed_type, field): bind_lines.append(f"\t_BIND_PROP_STR({snake_field_name})") setget_declare_lines.append(f"\t_DECLARE_SETGET_STR({snake_field_name})") - if addtional_methods_requirements["set_to"]: + if additional_methods_requirements["set_to"]: member_lines.append(f"\tEOS_P2P_SocketId {snake_field_name};") setget_define_lines.append(f"_DEFINE_SETGET_STR_SOCKET_ID({typename}, {snake_field_name})") else: @@ -3771,7 +3772,7 @@ def _gen_struct_v2( member_lines.append(f"\tLocalVector {snake_field_name};") setget_declare_lines.append(f"\t_DECLARE_SETGET_STR_ARR({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET_STR_ARR({typename}, {snake_field_name})") - if addtional_methods_requirements["to"]: + if additional_methods_requirements["to"]: # 需要转为eos类型的结构体数组才需要的字段 element_type: str = __get_str_arr_element_type(type) if element_type != "const char*": # 如果是C字符串则直接使用CharString @@ -3781,32 +3782,32 @@ def _gen_struct_v2( setget_declare_lines.append(f"\t_DECLARE_SETGET({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})") member_lines.append(f"\tTypedArray {snake_field_name};") - if addtional_methods_requirements["to"]: + if additional_methods_requirements["to"]: # 需要转为eos类型的结构体数组才需要的字段 member_lines.append(f"\tLocalVector<{_decay_eos_type(type)}> _shadow_{snake_field_name}{{}};") elif _is_handle_type(decayed_type): bind_lines.append(f"\t_BIND_PROP_OBJ({snake_field_name}, {_convert_handle_class_name(decayed_type)})") setget_declare_lines.append(f"\t_DECLARE_SETGET_TYPED({snake_field_name}, Ref)") setget_define_lines.append(f"_DEFINE_SETGET_TYPED({typename}, {snake_field_name}, {remap_type(decayed_type, field)})") - member_lines.append(f"\t{remaped_type} {snake_field_name};") + member_lines.append(f"\t{remapped_type} {snake_field_name};") elif _is_struct_ptr(type): bind_lines.append(f"\t_BIND_PROP_STRUCT_PTR({snake_field_name}, {remap_type(type)})") - setget_declare_lines.append(f"\t_DECLARE_SETGET_STRUCT_PTR({remaped_type}, {snake_field_name})") - setget_define_lines.append(f"_DEFINE_SETGET_STRUCT_PTR({typename}, {remaped_type}, {snake_field_name})") + setget_declare_lines.append(f"\t_DECLARE_SETGET_STRUCT_PTR({remapped_type}, {snake_field_name})") + setget_define_lines.append(f"_DEFINE_SETGET_STRUCT_PTR({typename}, {remapped_type}, {snake_field_name})") member_lines.append(f"\t{_decay_eos_type(type)} {snake_field_name}{{}};") elif _is_internal_struct_arr_field(type, field): bind_lines.append(f"\t_BIND_PROP_TYPED_ARR({snake_field_name}, {_convert_handle_class_name(decayed_type)})") setget_declare_lines.append(f"\t_DECLARE_SETGET({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})") - member_lines.append(f"\t{remaped_type} {snake_field_name}{{}};") - if addtional_methods_requirements["to"]: + member_lines.append(f"\t{remapped_type} {snake_field_name}{{}};") + if additional_methods_requirements["to"]: # 需要转为eos类型的结构体数组才需要的字段 member_lines.append(f"\tLocalVector<{_decay_eos_type(type)}> _shadow_{snake_field_name}{{}};") elif __is_struct_type(decayed_type): bind_lines.append(f"\t_BIND_PROP_OBJ({snake_field_name}, {_convert_handle_class_name(decayed_type)})") setget_declare_lines.append(f"\t_DECLARE_SETGET({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})") - member_lines.append(f"\t{remaped_type} {snake_field_name}{{}};") + member_lines.append(f"\t{remapped_type} {snake_field_name}{{}};") elif _is_enum_flags_type(type): bind_lines.append(f"\t_BIND_PROP_FLAGS({snake_field_name})") setget_declare_lines.append(f"\t_DECLARE_SETGET_FLAGS({snake_field_name})") @@ -3822,32 +3823,32 @@ def _gen_struct_v2( bind_lines.append(f"\t_BIND_PROP({snake_field_name})") setget_declare_lines.append(f"\t_DECLARE_SETGET({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})") - member_lines.append(f"\t{remaped_type} {snake_field_name}{{ -1.0 }};") + member_lines.append(f"\t{remapped_type} {snake_field_name}{{ -1.0 }};") elif _is_anticheat_client_handle_type(decayed_type): bind_lines.append(f'\t_BIND_PROP_OBJ({snake_field_name}, {remap_type(type, field).removesuffix("*")})') setget_declare_lines.append(f"\t_DECLARE_SETGET({snake_field_name})") setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})") - member_lines.append(f"\t{remaped_type} {snake_field_name}{{ nullptr }};") - elif remaped_type.startswith("Ref") and not type.startswith("Ref from_eos(const {struct_type} &p_origin);") - if addtional_methods_requirements["set_to"]: + if additional_methods_requirements["set_to"]: lines.append(f"\tvoid set_to_eos({struct_type} &p_origin);") - if addtional_methods_requirements["to"]: + if additional_methods_requirements["to"]: lines.append(f"\t{struct_type} &to_eos() {{set_to_eos(m_eos_data); return m_eos_data;}}") lines.append("protected:") lines.append("\tstatic void _bind_methods();") @@ -3911,7 +3912,7 @@ def _gen_struct_v2( optional_cpp_lines: list[str] = [] - if addtional_methods_requirements["from"]: + if additional_methods_requirements["from"]: r_structs_cpp.append(f"Ref<{typename}> {typename}::from_eos(const {struct_type} &p_origin) {{") r_structs_cpp.append(f"\tRef<{typename}> ret;") r_structs_cpp.append(f"\tret.instantiate();") @@ -3919,7 +3920,7 @@ def _gen_struct_v2( r_structs_cpp.append(f"\treturn ret;") r_structs_cpp.append("}") - if addtional_methods_requirements["set_from"]: + if additional_methods_requirements["set_from"]: r_structs_cpp.append(f"void {typename}::set_from_eos(const {struct_type} &p_origin) {{") for field in fields.keys(): field_type = fields[field]["type"] @@ -3938,7 +3939,7 @@ def _gen_struct_v2( continue # 暴露的结构体不再含有 ClientData 字段 if _is_memory_func_type(field_type): # 内存分配方法不需要成员变量 - print("ERROR Unsupport") + print("ERROR Unsupported") exit(1) if _is_platform_specific_options_field(field): @@ -3954,7 +3955,7 @@ def _gen_struct_v2( print("ERROR:", field) exit(1) elif _is_socket_id_type(_decay_eos_type(field_type), field): - if addtional_methods_requirements["set_to"]: + if additional_methods_requirements["set_to"]: r_structs_cpp.append(f"\tmemcpy(&{to_snake_case(field)}.SocketName[0], &p_origin.{field}.SocketName[0], EOS_P2P_SOCKETID_SOCKETNAME_SIZE);") else: r_structs_cpp.append(f"\t{to_snake_case(field)}.resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE);") @@ -3996,7 +3997,7 @@ def _gen_struct_v2( r_structs_cpp.append(f"\t_FROM_EOS_FIELD({to_snake_case(field)}, p_origin.{field.split('[')[0]});") r_structs_cpp.append("}") - if addtional_methods_requirements["set_to"]: + if additional_methods_requirements["set_to"]: r_structs_cpp.append(f"void {typename}::set_to_eos({struct_type} &p_data) {{") # r_structs_cpp.append(f"\tmemset(&p_data, 0, sizeof(p_data));") @@ -4027,7 +4028,7 @@ def _gen_struct_v2( if __is_api_version_field(field_type, field): r_structs_cpp.append(f"\tp_data.{field} = {__get_api_latest_macro(struct_type)};") elif _is_audio_frames_type(field_type, field): - r_structs_cpp.append(f"\t_packedint32_to_autio_frames({snake_field_name}, _shadow_{snake_field_name});") + r_structs_cpp.append(f"\t_packed_int32_to_audio_frames({snake_field_name}, _shadow_{snake_field_name});") r_structs_cpp.append(f"\tp_data.{field} = _shadow_{snake_field_name}.ptr();") r_structs_cpp.append(f"\tp_data.{_find_count_field(field, fields.keys())} = _shadow_{snake_field_name}.size();") elif _is_struct_ptr(field_type): @@ -4081,7 +4082,7 @@ def _gen_struct_v2( r_structs_cpp.append( f"\t_TO_EOS_FIELD_STRUCT_ARR(p_data.{field}, {snake_field_name}, _shadow_{snake_field_name}, p_data.{_find_count_field(field, fields.keys())});" ) - elif _is_internal_struct_field(field_type, field) or _is_integreate_platform_init_option(field_type, field): + elif _is_internal_struct_field(field_type, field) or _is_integrated_platform_init_option(field_type, field): r_structs_cpp.append(f"\t_TO_EOS_FIELD_STRUCT(p_data.{field}, {snake_field_name});") elif _is_arr_field(field_type, field): r_structs_cpp.append(f"\t_TO_EOS_FIELD_ARR(p_data.{field}, {snake_field_name}, p_data.{_find_count_field(field, fields.keys())});") @@ -4267,7 +4268,7 @@ def _insert_doc_class_description(typename: str, doc: list[str] = []): # 插入 __insert_doc_to(lines, insert_idx, doc, indent_count) # 保存 - __stroe_doc_file(typename=typename, content=lines) + __store_doc_file(typename=typename, content=lines) def _insert_doc_class_brief(typename: str, doc: list[str]): @@ -4300,7 +4301,7 @@ def _insert_doc_class_brief(typename: str, doc: list[str]): # 插入 __insert_doc_to(lines, insert_idx, doc, indent_count) # 保存 - __stroe_doc_file(typename=typename, content=lines) + __store_doc_file(typename=typename, content=lines) def _insert_doc_property(typename: str, prop: str, doc: list[str]): @@ -4333,7 +4334,7 @@ def _insert_doc_property(typename: str, prop: str, doc: list[str]): # 插入 __insert_doc_to(lines, insert_idx, doc, indent_count) # 保存 - __stroe_doc_file(typename=typename, content=lines) + __store_doc_file(typename=typename, content=lines) def _insert_doc_constant(typename: str, constant: str, doc: list[str]): @@ -4368,7 +4369,7 @@ def _insert_doc_constant(typename: str, constant: str, doc: list[str]): # 插入 __insert_doc_to(lines, insert_idx, doc, indent_count) # 保存 - __stroe_doc_file(typename=typename, content=lines) + __store_doc_file(typename=typename, content=lines) def _insert_doc_method(typename: str, method: str, doc: list[str], additional_args_doc: dict[str, list[str]] = {}, additional_doc: list[str] = []): @@ -4439,7 +4440,7 @@ def __insert_doc_method_like(tag: str, typename: str, name: str, doc: list[str], insert_idx += len(additional_doc_copy) # 保存 - __stroe_doc_file(typename=typename, content=lines) + __store_doc_file(typename=typename, content=lines) def __insert_doc_to(lines: list[str], insert_idx: int, doc: list[str], indent_count: int) -> list[str]: @@ -4463,7 +4464,7 @@ def __get_doc_file(typename: str) -> list[str]: return [] -def __stroe_doc_file(typename: str, content: list[str]): +def __store_doc_file(typename: str, content: list[str]): try: f = open(os.path.join("./doc_classes", typename) + ".xml", "w", encoding="utf-8") f.writelines(content) diff --git a/gd_eos/include/core/utils.h b/gd_eos/include/core/utils.h index 4af6447..1c8790d 100644 --- a/gd_eos/include/core/utils.h +++ b/gd_eos/include/core/utils.h @@ -24,11 +24,11 @@ namespace godot::eos::internal { #define _EOS_VERSION_GREATER_THAN_1_6_1 (EOS_MAJOR_VERSION > 1 || (EOS_MAJOR_VERSION == 1 && EOS_MINOR_VERSION > 16) || (EOS_MAJOR_VERSION == 1 && EOS_MINOR_VERSION == 16 && EOS_PATCH_VERSION > 1)) -#define _BIND_ENUM_CONSTANT(enume_type_name, e, e_bind) \ - godot::ClassDB::bind_integer_constant(get_class_static(), godot::_gde_constant_get_enum_name(enume_type_name::e, e_bind), e_bind, enume_type_name::e); +#define _BIND_ENUM_CONSTANT(enum_type_name, e, e_bind) \ + godot::ClassDB::bind_integer_constant(get_class_static(), godot::_gde_constant_get_enum_name(enum_type_name::e, e_bind), e_bind, enum_type_name::e); -#define _BIND_ENUM_BITFIELD_FLAG(enume_type_name, e, e_bind) \ - godot::ClassDB::bind_integer_constant(get_class_static(), godot::_gde_constant_get_bitfield_name(enume_type_name::e, e_bind), e_bind, enume_type_name::e, true); +#define _BIND_ENUM_BITFIELD_FLAG(enum_type_name, e, e_bind) \ + godot::ClassDB::bind_integer_constant(get_class_static(), godot::_gde_constant_get_bitfield_name(enum_type_name::e, e_bind), e_bind, enum_type_name::e, true); #define _BIND_CONSTANT(constant, constant_bind) \ godot::ClassDB::bind_integer_constant(get_class_static(), "", constant_bind, constant); @@ -36,9 +36,9 @@ namespace godot::eos::internal { #define SNAME(sn) []() -> const StringName & {static const StringName ret{sn};return ret; }() #ifdef _MSC_VER // Check if using Microsoft Visual Studio -#define STRNCPY_S(dest, destsz, src, count) strncpy_s(dest, destsz, src, count) +#define STRNCPY_S(dest, dest_size, src, count) strncpy_s(dest, dest_size, src, count) #else -#define STRNCPY_S(dest, destsz, src, count) strncpy(dest, src, count) +#define STRNCPY_S(dest, dest_size, src, count) strncpy(dest, src, count) #endif #define _DECLARE_SETGET(field) \ @@ -65,28 +65,28 @@ namespace godot::eos::internal { String klass::get_##field() const { return String::utf8((char *)field.get_data()); } \ void klass::set_##field(const String &p_val) { field = p_val.utf8(); } -#define _DEFINE_SETGET_STR_SOCKET_ID(klass, field) \ - String klass::get_##field() const { return String(&(field).SocketName[0]); } \ - void klass::set_##field(const String &p_val) { \ - auto ascii = p_val.ascii(); \ - if ((ascii).size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && (ascii).get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) { \ - ERR_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncatured.", p_val, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); \ - (ascii).resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ - (ascii).set(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1, 0); \ - } \ - memset(&(field).SocketName[0], 0, EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ - memcpy(&(field).SocketName[0], ascii.get_data(), MIN(ascii.size(), EOS_P2P_SOCKETID_SOCKETNAME_SIZE)); \ +#define _DEFINE_SETGET_STR_SOCKET_ID(klass, field) \ + String klass::get_##field() const { return String(&(field).SocketName[0]); } \ + void klass::set_##field(const String &p_val) { \ + auto ascii = p_val.ascii(); \ + if ((ascii).size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && (ascii).get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) { \ + ERR_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncated.", p_val, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); \ + (ascii).resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ + (ascii).set(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1, 0); \ + } \ + memset(&(field).SocketName[0], 0, EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ + memcpy(&(field).SocketName[0], ascii.get_data(), MIN(ascii.size(), EOS_P2P_SOCKETID_SOCKETNAME_SIZE)); \ } -#define _DEFINE_SETGET_STR_SOCKET_NAME(klass, field) \ - String klass::get_##field() const { return String((char *)field.get_data()); } \ - void klass::set_##field(const String &p_val) { \ - field = p_val.ascii(); \ - if ((field).size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && (field).get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) { \ - ERR_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncatured.", p_val, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); \ - (field).resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ - (field).set(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1, 0); \ - } \ +#define _DEFINE_SETGET_STR_SOCKET_NAME(klass, field) \ + String klass::get_##field() const { return String((char *)field.get_data()); } \ + void klass::set_##field(const String &p_val) { \ + field = p_val.ascii(); \ + if ((field).size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && (field).get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) { \ + ERR_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncated.", p_val, EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); \ + (field).resize(EOS_P2P_SOCKETID_SOCKETNAME_SIZE); \ + (field).set(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1, 0); \ + } \ } #define _DECLARE_SETGET_STR_ARR(field) \ @@ -314,12 +314,12 @@ PackedInt32Array to_godot_type_arr(const int16_t *p_from, Tint p_count) { return ret; } -inline void _packedint32_to_autio_frames(const PackedInt32Array &p_from, LocalVector &p_to) { +inline void _packed_int32_to_audio_frames(const PackedInt32Array &p_from, LocalVector &p_to) { p_to.clear(); p_to.reserve(p_from.size()); for (int32_t e : p_from) { #ifdef DEBUG_ENABLED - ERR_CONTINUE_MSG(e < INT16_MIN || e > INT16_MAX, "Audio Frme should be a int16_t."); + ERR_CONTINUE_MSG(e < INT16_MIN || e > INT16_MAX, "Audio Frame should be a int16_t."); #endif // DEBUG_ENABLED p_to.push_back(e); } @@ -342,7 +342,7 @@ PackedInt32Array to_godot_type_arr(const uint8_t *p_from, Tint p_count) { return ret; } -// uint32_t* Plaform ID数组使用(不会超过int32 的正值范围) +// uint32_t* Platform ID数组使用(不会超过int32 的正值范围) template PackedInt32Array to_godot_type_arr(const uint32_t *p_from, Tint p_count) { PackedInt32Array ret; @@ -414,7 +414,7 @@ inline void to_eos_type_out(gd_arg_t p_from, To &r_to) { template <> inline void to_eos_type_out(const CharString &p_from, eos_p2p_socketid_socked_name_t &r_to) { if (p_from.size() > (EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) && p_from.get(EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1) != 0) { - WARN_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncatured.", String(p_from), EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); + WARN_PRINT(vformat("EOS: Socket name \"%s\"'s length is greater than %d (in ASCII), will be truncated.", String(p_from), EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); } memset(&r_to[0], 0, EOS_P2P_SOCKETID_SOCKETNAME_SIZE); memcpy(&r_to[0], p_from.ptr(), MIN(p_from.size(), EOS_P2P_SOCKETID_SOCKETNAME_SIZE - 1)); @@ -591,7 +591,7 @@ inline Variant eos_union_to_variant(const EOSUnion &p_union, UnionType p_union_t return String::utf8(p_union.AsUtf8); } break; default: { - ERR_FAIL_V_MSG({}, vformat("Unsuppoert AttributeType: ", (int)p_union_type)); + ERR_FAIL_V_MSG({}, vformat("Unsupported AttributeType: ", (int)p_union_type)); } break; } } @@ -733,7 +733,7 @@ String to_godot_data_union(const FromUnion &p_from, EOS_EMetricsAccountIdType p_ to_eos_data(gd_field, eos_field) template -inline void _conver_to_eos_struct_vector(const TypedArray &p_from, LocalVector &p_to) { +inline void _convert_to_eos_struct_vector(const TypedArray &p_from, LocalVector &p_to) { p_to.resize(p_from.size()); for (decltype(p_from.size()) i = 0; i < p_from.size(); ++i) { auto casted = Object::cast_to(p_from[i]); @@ -743,14 +743,14 @@ inline void _conver_to_eos_struct_vector(const TypedArray &p_from, Local } #define _TO_EOS_FIELD_STRUCT_ARR(eos_field, gd_field, shadow_field, r_eos_field_count) \ - _conver_to_eos_struct_vector(gd_field, shadow_field); \ + _convert_to_eos_struct_vector(gd_field, shadow_field); \ r_eos_field_count = shadow_field.size(); \ eos_field = shadow_field.ptr(); #define _TO_EOS_FIELD_HANDLER(eos_field, gd_field, gd_type_to_cast) \ eos_field = gd_field.is_valid() ? Object::cast_to(gd_field.ptr())->get_handle() : nullptr template -inline void _conver_to_eos_handle_vector(const TypedArray &p_from, LocalVector &p_to) { +inline void _convert_to_eos_handle_vector(const TypedArray &p_from, LocalVector &p_to) { p_to.resize(p_from.size()); for (decltype(p_from.size()) i = 0; i < p_from.size(); ++i) { auto casted = Object::cast_to(p_from[i]); @@ -759,7 +759,7 @@ inline void _conver_to_eos_handle_vector(const TypedArray &p_from, Local } } #define _TO_EOS_FIELD_HANDLER_ARR(eos_field, gd_field, shadow_field, r_eos_field_count) \ - _conver_to_eos_handle_vector(gd_field, shadow_field); \ + _convert_to_eos_handle_vector(gd_field, shadow_field); \ r_eos_field_count = shadow_field.size(); \ eos_field = shadow_field.ptr(); #define _TO_EOS_FIELD_ANTICHEAT_CLIENT_HANDLE(eos_field, gd_field) \ @@ -782,8 +782,8 @@ inline void _conver_to_eos_handle_vector(const TypedArray &p_from, Local #define _MAKE_PROP_INFO_ENUM(m_name, enum_owner, enum_type) PropertyInfo(Variant::INT, #m_name, {}, "", PROPERTY_USAGE_DEFAULT, #enum_owner "." #enum_type) // 展开转换 -template -godot::TypedArray _to_godot_value_struct_arr(EOSArraTy p_eos_arr, TInt p_count) { +template +godot::TypedArray _to_godot_value_struct_arr(EOSArrayTy p_eos_arr, TInt p_count) { godot::TypedArray ret; ret.resize(p_count); for (decltype(p_count) i = 0; i < p_count; ++i) { @@ -799,8 +799,8 @@ godot::Ref _to_godot_handle(EOSHandle p_eos_handle) { ret->set_handle(p_eos_handle); return ret; } -template -godot::TypedArray _to_godot_value_handle_arr(EOSArraTy p_eos_arr, TInt p_count) { +template +godot::TypedArray _to_godot_value_handle_arr(EOSArrayTy p_eos_arr, TInt p_count) { godot::TypedArray ret; ret.resize(p_count); for (decltype(p_count) i = 0; i < p_count; ++i) { @@ -873,21 +873,21 @@ auto _to_godot_val_from_union(EOSUnion &p_eos_union, EOSUnionTypeEnum p_type) { cd.get_handle_wrapper()->emit_signal(SNAME(m_callback_signal), ##__VA_ARGS__); \ } -#define _EOS_USER_PRE_LOGOUT_CALLBACK(m_callback_info_ty, m_callback_identifier, m_callback_signal, m_arg_type) \ - [](m_callback_info_ty m_callback_identifier) { \ - auto cd = (_CallbackClientData *)m_callback_identifier->ClientData; \ - auto cb_data = m_arg_type::from_eos(*m_callback_identifier); \ - auto return_action = EOS_EIntegratedPlatformPreLogoutAction::EOS_IPLA_ProcessLogoutImmediately; \ - if (cd->callback.is_valid()) { \ - auto res = cd->callback.call(cb_data); \ - if (res.get_type() != Variant::INT || (int32_t)res != 0 || (int32_t)res != 1) { \ - ERR_PRINT("Read file data callback should return a Value of IntegreatePlatform.EOS_EIntegratedPlatformPreLogoutAction."); \ - } else { \ - return_action = (EOS_EIntegratedPlatformPreLogoutAction)(res.operator int32_t()); \ - } \ - } \ - cd->handle_wrapper->emit_signal(SNAME(m_callback_signal), cb_data); \ - return return_action; \ +#define _EOS_USER_PRE_LOGOUT_CALLBACK(m_callback_info_ty, m_callback_identifier, m_callback_signal, m_arg_type) \ + [](m_callback_info_ty m_callback_identifier) { \ + auto cd = (_CallbackClientData *)m_callback_identifier->ClientData; \ + auto cb_data = m_arg_type::from_eos(*m_callback_identifier); \ + auto return_action = EOS_EIntegratedPlatformPreLogoutAction::EOS_IPLA_ProcessLogoutImmediately; \ + if (cd->callback.is_valid()) { \ + auto res = cd->callback.call(cb_data); \ + if (res.get_type() != Variant::INT || (int32_t)res != 0 || (int32_t)res != 1) { \ + ERR_PRINT("Read file data callback should return a Value of IntegratedPlatform.EOS_EIntegratedPlatformPreLogoutAction."); \ + } else { \ + return_action = (EOS_EIntegratedPlatformPreLogoutAction)(res.operator int32_t()); \ + } \ + } \ + cd->handle_wrapper->emit_signal(SNAME(m_callback_signal), cb_data); \ + return return_action; \ } // EOS VERSION @@ -907,22 +907,22 @@ auto _to_godot_val_from_union(EOSUnion &p_eos_union, EOSUnionTypeEnum p_type) { return m_handle_identifier == m_other_identifier->get_handle() // Platform tick -#define _EOS_PLATFORM_SETUP_TICK() \ -protected: \ - void tick_internal() { \ - if (m_handle) { \ - EOS_Platform_Tick(m_handle); \ - } \ - } \ - void setup_tick() { \ - MainLoop *main_loop = godot::Engine::get_singleton()->get_main_loop(); \ - ERR_FAIL_COND_MSG(main_loop == nullptr || !main_loop->has_signal("process_frame"), "EOS wraning: Can't tick automatically, please call \"EOSPlatform::tick()\" by youself."); \ - ERR_FAIL_COND(main_loop->connect("process_frame", callable_mp(this, &EOSPlatform::tick_internal)) != OK); \ - } \ - void _notification(int p_what) { \ - if (p_what == NOTIFICATION_POSTINITIALIZE) { \ - callable_mp(this, &EOSPlatform::setup_tick).call_deferred(); \ - } \ +#define _EOS_PLATFORM_SETUP_TICK() \ +protected: \ + void tick_internal() { \ + if (m_handle) { \ + EOS_Platform_Tick(m_handle); \ + } \ + } \ + void setup_tick() { \ + MainLoop *main_loop = godot::Engine::get_singleton()->get_main_loop(); \ + ERR_FAIL_COND_MSG(main_loop == nullptr || !main_loop->has_signal("process_frame"), "EOS warning: Can't tick automatically, please call \"EOSPlatform::tick()\" by yourself."); \ + ERR_FAIL_COND(main_loop->connect("process_frame", callable_mp(this, &EOSPlatform::tick_internal)) != OK); \ + } \ + void _notification(int p_what) { \ + if (p_what == NOTIFICATION_POSTINITIALIZE) { \ + callable_mp(this, &EOSPlatform::setup_tick).call_deferred(); \ + } \ } // Memory diff --git a/gd_eos/include/eos_multiplayer_peer.h b/gd_eos/include/eos_multiplayer_peer.h index f3b24a2..4144e67 100644 --- a/gd_eos/include/eos_multiplayer_peer.h +++ b/gd_eos/include/eos_multiplayer_peer.h @@ -45,7 +45,7 @@ class EOSMultiplayerPeer : public MultiplayerPeerExtension { public: enum Event : uint8_t { EVENT_STORE_PACKET, - EVENT_RECIEVE_PEER_ID, + EVENT_RECEIVE_PEER_ID, EVENT_MESH_CONNECTION_REQUEST }; diff --git a/gd_eos/src/editor/eos_editor_plugin.cpp b/gd_eos/src/editor/eos_editor_plugin.cpp index 64fa7d3..3d46b0e 100644 --- a/gd_eos/src/editor/eos_editor_plugin.cpp +++ b/gd_eos/src/editor/eos_editor_plugin.cpp @@ -38,20 +38,20 @@ void EOSExportPlugin::_export_begin(const PackedStringArray &features, bool is_d String arch; for (const String &feature : features) { if (feature == "arm32") { - ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architechture tags!"); + ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architecture tags!"); arch = feature; } else if (feature == "arm64") { - ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architechture tags!"); + ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architecture tags!"); arch = feature; } else if (feature == "x86_32") { - ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architechture tags!"); + ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architecture tags!"); arch = feature; } else if (feature == "x86_64") { - ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architechture tags!"); + ERR_CONTINUE_MSG(!arch.is_empty(), "Exporting features have multiple architecture tags!"); arch = feature; } } - ERR_FAIL_COND_MSG(arch.is_empty(), "EOS Exporting: Unknown architechture, can't add shared object."); + ERR_FAIL_COND_MSG(arch.is_empty(), "EOS Exporting: Unknown architecture, can't add shared object."); add_shared_object(binary_base_dir.path_join("android").path_join(arch).path_join("libEOSSDK.so"), Array::make(arch), "/"); } } diff --git a/gd_eos/src/eos_multiplayer_peer.cpp b/gd_eos/src/eos_multiplayer_peer.cpp index 916799a..2a9ade6 100644 --- a/gd_eos/src/eos_multiplayer_peer.cpp +++ b/gd_eos/src/eos_multiplayer_peer.cpp @@ -182,7 +182,7 @@ Error EOSMultiplayerPeer::create_client(const String &socket_id, const Ref(data_ptr.ptr() + INDEX_PEER_ID); - if (event == Event::EVENT_RECIEVE_PEER_ID) { - ERR_FAIL_COND_MSG(active_mode == MODE_CLIENT && connection_status == CONNECTION_CONNECTED, "Client has recieved a EVENT_RECIEVE_PEER_ID packet when already connected. This shouldn't have happened!"); + if (event == Event::EVENT_RECEIVE_PEER_ID) { + ERR_FAIL_COND_MSG(active_mode == MODE_CLIENT && connection_status == CONNECTION_CONNECTED, "Client has received a EVENT_RECEIVE_PEER_ID packet when already connected. This shouldn't have happened!"); if (active_mode == MODE_CLIENT && peer_id != 1) { _close(); @@ -1061,7 +1061,7 @@ bool EOSMultiplayerPeer::_is_requesting_connection(EOS_ProductUserId p_remote_us * Parameters: * mode - The transfer mode to convert. * Description: A helper function that converts the given transfer mode to matching packet reliability. - * If TRANSFER_MODE_UNRELIABLE_ORDED is passed, the function returns EOS_PR_ReliableOrdered because EOS + * If TRANSFER_MODE_UNRELIABLE_ORDERED is passed, the function returns EOS_PR_ReliableOrdered because EOS * does not support unreliable ordered ****************************************/ EOS_EPacketReliability EOSMultiplayerPeer::_convert_transfer_mode_to_eos_reliability(TransferMode mode) const { @@ -1122,7 +1122,7 @@ void EOSMultiplayerPeer::_disconnect_remote_user(EOS_ProductUserId remote_user_i * peer who just connected, the socket id that the remote peer connected to, the connection type (which tells * you whether it was a new connection or a re-connection), and the network type (which tells you if it is a direct * connection or a relay server is being used.) When a connection is established for the first time and the instance - * is not a client, a packet will be sent back to the newly connected peer with the EVENT_RECIEVE_PEER_ID event. + * is not a client, a packet will be sent back to the newly connected peer with the EVENT_RECEIVE_PEER_ID event. * This is how servers and mesh instances peers exchange their peer ids with newly connected peers. ****************************************/ void EOSMultiplayerPeer::peer_connection_established_callback(const EOS_P2P_OnPeerConnectionEstablishedInfo *data) { @@ -1130,7 +1130,7 @@ void EOSMultiplayerPeer::peer_connection_established_callback(const EOS_P2P_OnPe active_mode != MODE_CLIENT) { //We're either a server or mesh //Send peer id to connected peer EOSPacket packet; - packet.set_event(EVENT_RECIEVE_PEER_ID); + packet.set_event(EVENT_RECEIVE_PEER_ID); packet.set_channel(CH_RELIABLE); packet.set_reliability(EOS_EPacketReliability::EOS_PR_ReliableUnordered); packet.set_sender_peer_id(unique_id); diff --git a/gd_eos/src/eos_packet_peer_mediator.cpp b/gd_eos/src/eos_packet_peer_mediator.cpp index cb18cd8..2887561 100644 --- a/gd_eos/src/eos_packet_peer_mediator.cpp +++ b/gd_eos/src/eos_packet_peer_mediator.cpp @@ -8,7 +8,7 @@ * The mediator receives packets from the EOS P2P interface every process * frame and sorts those packets according to their destination socket so * that the appropriate multiplayer instance can poll them later. The mediator - * receives EOS notifications and fowards it to the appropriate multiplayer + * receives EOS notifications and forwards it to the appropriate multiplayer * instance according to the socket the notification was received from. * Mediator manages incoming connection requests and forwards them to the * appropriate multiplayer instance according to the socket id of the @@ -52,7 +52,7 @@ void EOSPacketPeerMediator::_bind_methods() { * that it can execute every process frame (see _init()). Checks if there are * any packets available from the incoming packet queue. If there are, receives * the packet and sorts it into separate queues according to it's destination socket. Packets that - * are peer id packets (packets with EVENT_RECIEVE_PEER_ID) and pushed to the front. Packets will + * are peer id packets (packets with EVENT_RECEIVE_PEER_ID) and pushed to the front. Packets will * stop being polled if the queue size limit is reached. ****************************************/ void EOSPacketPeerMediator::_on_process_frame() { @@ -70,11 +70,11 @@ void EOSPacketPeerMediator::_on_process_frame() { packet_size_options.RequestedChannel = nullptr; uint32_t max_packet_size; - EOS_P2P_ReceivePacketOptions recieve_packet_options; - recieve_packet_options.ApiVersion = EOS_P2P_RECEIVEPACKET_API_LATEST; - recieve_packet_options.LocalUserId = local_user_id; - recieve_packet_options.MaxDataSizeBytes = EOS_P2P_MAX_PACKET_SIZE; - recieve_packet_options.RequestedChannel = nullptr; + EOS_P2P_ReceivePacketOptions receive_packet_options; + receive_packet_options.ApiVersion = EOS_P2P_RECEIVEPACKET_API_LATEST; + receive_packet_options.LocalUserId = local_user_id; + receive_packet_options.MaxDataSizeBytes = EOS_P2P_MAX_PACKET_SIZE; + receive_packet_options.RequestedChannel = nullptr; bool next_packet_available = true; EOS_EResult result = EOS_EResult::EOS_Success; @@ -97,7 +97,7 @@ void EOSPacketPeerMediator::_on_process_frame() { uint8_t channel; EOS_P2P_SocketId socket; EOS_ProductUserId remote_user; - result = EOS_P2P_ReceivePacket(EOSP2P::get_singleton()->get_handle(), &recieve_packet_options, &remote_user, &socket, &channel, packet_data.ptrw(), &buffer_size); + result = EOS_P2P_ReceivePacket(EOSP2P::get_singleton()->get_handle(), &receive_packet_options, &remote_user, &socket, &channel, packet_data.ptrw(), &buffer_size); String socket_name = socket.SocketName; ERR_FAIL_COND_MSG(result == EOS_EResult::EOS_InvalidParameters, "Failed to get packet! Invalid parameters."); @@ -112,7 +112,7 @@ void EOSPacketPeerMediator::_on_process_frame() { packet->set_sender(remote_user); uint8_t event = packet->get_data().ptr()[EOSMultiplayerPeer::INDEX_EVENT_TYPE]; - if (event == EOSMultiplayerPeer::EVENT_RECIEVE_PEER_ID) { + if (event == EOSMultiplayerPeer::EVENT_RECEIVE_PEER_ID) { socket_packet_queues[socket_name].push_front(packet); } else { socket_packet_queues[socket_name].push_back(packet); @@ -169,7 +169,7 @@ bool EOSPacketPeerMediator::register_peer(EOSMultiplayerPeer *peer) { * unregister_peer * Parameters: * peer - The peer to be unregistered with the mediator. - * Description: Unregisteres a peer and it's socket with the mediator. + * Description: Unregisters a peer and it's socket with the mediator. * Peers can no longer receive packets, notifications, or connection requests once this is done. * unregistration usually happens when a peer closes. ****************************************/ @@ -308,7 +308,7 @@ bool EOSPacketPeerMediator::next_packet_is_peer_id_packet(const String &socket_i const SharedPtr &packet = socket_packet_queues[socket_id][0]; uint8_t event = packet->get_data().ptr()[EOSMultiplayerPeer::INDEX_EVENT_TYPE]; - return event == EOSMultiplayerPeer::EVENT_RECIEVE_PEER_ID; + return event == EOSMultiplayerPeer::EVENT_RECEIVE_PEER_ID; } /****************************************