Skip to content

Commit

Permalink
为WriteFileDataCallbackInfo添加out_data_buffer字段代替原本的out参数(GDE的数组在godot之…
Browse files Browse the repository at this point in the history
…间不是引用传递);为AttributeData添加make静态方法
  • Loading branch information
Daylily-Zeleen committed Apr 19, 2024
1 parent a7831d6 commit fb62bc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions gd_eos/eos_code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3623,6 +3623,29 @@ def _gen_struct_v2(
setget_define_lines.append(f"_DEFINE_SETGET({typename}, {snake_field_name})")
member_lines.append(f"\t{remaped_type} {snake_field_name}{{}};")

# 对某些类型进行特殊处理
if struct_type == "EOS_PlayerDataStorage_WriteFileDataCallbackInfo":
# GDExtension 的数组与 godot 之间不是引用传递,无法以out参数将data_buffer传递给回调,
# 因此为回调信息添加一个 out_data_buffer 字段作为输出- 2024.4.20
member_lines.append(f"\tPackedByteArray out_data_buffer{{}};")
setget_declare_lines.append(f"\t_DECLARE_SETGET(out_data_buffer)")
setget_define_lines.append(f"_DEFINE_SETGET({typename}, out_data_buffer)")
bind_lines.append(f"\t_BIND_PROP(out_data_buffer)")

if struct_type in ["EOS_Lobby_AttributeData", "EOS_Sessions_AttributeData"]:
# 为这两个类提供make方法
setget_declare_lines.append("")
setget_declare_lines.append(f"\tstatic Ref<{typename}> make(const String& p_key, const Variant& p_value);")
setget_define_lines.append("")
setget_define_lines.append(f"Ref<{typename}> {typename}::make(const String& p_key, const Variant& p_value) {{")
setget_define_lines.append(f"\tRef<{typename}> ret; ret.instantiate();")
setget_define_lines.append("\tret->set_key(p_key);")
setget_define_lines.append("\tret->set_value(p_value);")
setget_define_lines.append("\treturn ret;")
setget_define_lines.append("}")
bind_lines.append("")
bind_lines.append(f'\tClassDB::bind_static_method(get_class_static(), D_METHOD("make", "key", "value"), &{typename}::make);')

# h
lines: list[str] = [""]
lines.append(f"class {typename}: public EOSDataClass {{")
Expand Down Expand Up @@ -3910,6 +3933,8 @@ def _gen_struct_v2(

for line in optional_cpp_lines:
r_structs_cpp.insert(insert_idx, line)


return lines


Expand Down
7 changes: 5 additions & 2 deletions gd_eos/include/core/file_transfer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ EOS_PlayerDataStorage_EWriteResult write_file_data_callback(const EOSCallbackInf
ERR_FAIL_COND_V(!file_transfer_data->operation_callback.is_valid(), EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest);

auto data = GDCallbackInfoTy::from_eos(*p_data);
PackedByteArray out_data_buffer;
Variant res = file_transfer_data->operation_callback.call(data, out_data_buffer);
Variant res = file_transfer_data->operation_callback.call(data);
ERR_FAIL_COND_V_MSG(res.get_type() != Variant::INT || (int32_t)res < 1 || (int32_t)res > 4, EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest, "Write file data callback shoul return a Value of PlayerDataStorage.WriteResult.");

EOS_PlayerDataStorage_EWriteResult write_result = (EOS_PlayerDataStorage_EWriteResult)(res.operator int32_t());
if (write_result == EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest || write_result == EOS_PlayerDataStorage_EWriteResult::EOS_WR_CancelRequest) {
return write_result;
}

PackedByteArray out_data_buffer = data->get_out_data_buffer();
ERR_FAIL_COND_V_MSG(out_data_buffer.size() > p_data->DataBufferLengthBytes, EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest, "The out data buffer is too large.");
ERR_FAIL_COND_V_MSG(out_data_buffer.size() <= 0 && write_result == EOS_PlayerDataStorage_EWriteResult::EOS_WR_ContinueWriting, EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest, "The out data buffer is empty.");

ERR_FAIL_COND_V(out_data_buffer.size() > p_data->DataBufferLengthBytes, EOS_PlayerDataStorage_EWriteResult::EOS_WR_FailRequest);
memcpy(r_data_buffer, out_data_buffer.ptr(), out_data_buffer.size());
*r_data_written = out_data_buffer.size();
Expand Down

0 comments on commit fb62bc7

Please sign in to comment.