From 6050d356788c7ed2e34133fa0d05d235acccf8f3 Mon Sep 17 00:00:00 2001 From: Ashton Meuser Date: Thu, 13 Jun 2024 09:02:51 -0700 Subject: [PATCH] Godot 3 compatibility with target IDs Fix defines Update test project --- examples/wasm-test/project.godot | 6 ++++++ src/defs.h | 7 ++++--- src/godot-library.cpp | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/wasm-test/project.godot b/examples/wasm-test/project.godot index 793c31a..cac02b2 100644 --- a/examples/wasm-test/project.godot +++ b/examples/wasm-test/project.godot @@ -14,6 +14,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://utils/GodotWasmTestSuite.gd" }, { +"base": "Object", +"class": "ImportTarget", +"language": "GDScript", +"path": "res://utils/ImportTarget.gd" +}, { "base": "Node", "class": "TestRunner", "language": "GDScript", @@ -41,6 +46,7 @@ _global_script_classes=[ { } ] _global_script_class_icons={ "GodotWasmTestSuite": "", +"ImportTarget": "", "TestRunner": "", "TestSuite": "", "Utils": "", diff --git a/src/defs.h b/src/defs.h index 325568f..5d5ac6e 100644 --- a/src/defs.h +++ b/src/defs.h @@ -22,7 +22,7 @@ Useful for minimizing changes to implementation files between targets e.g. GDExt #define PRINT_ERROR(message) print_error("Godot Wasm: " + String(message)) #define godot_error Error #define INSTANCE_FROM_ID(id) ObjectDB::get_instance(id) - #define INSTANCE_VALIDATE(id) VariantUtilityFunctions::is_instance_valid(id) + #define INSTANCE_VALIDATE(id) ObjectDB::instance_validate(id) #define REGISTRATION_METHOD _bind_methods #define RANDOM_BYTES(n) Crypto::create()->generate_random_bytes(n) #else @@ -34,8 +34,9 @@ Useful for minimizing changes to implementation files between targets e.g. GDExt #define ERR_PARAMETER_RANGE_ERROR GODOT_ERR_PARAMETER_RANGE_ERROR #define PRINT(message) Godot::print(String(message)) #define PRINT_ERROR(message) Godot::print_error("Godot Wasm: " + String(message), __func__, __FILE__, __LINE__) - #define INSTANCE_FROM_ID(id) ObjectDB::get_instance(id) - #define INSTANCE_VALIDATE(id) UtilityFunctions::is_instance_valid(id) + #define ObjectID int64_t + #define INSTANCE_FROM_ID(id) godot::core_1_2_api->godot_instance_from_id(id) == nullptr ? nullptr : godot::detail::get_wrapper(godot::core_1_2_api->godot_instance_from_id(id)) + #define INSTANCE_VALIDATE(id) godot::core_1_1_api->godot_is_instance_valid((godot_object*)id) #define GDCLASS GODOT_CLASS #define REGISTRATION_METHOD _register_methods #define RANDOM_BYTES(n) Crypto::_new()->generate_random_bytes(n) diff --git a/src/godot-library.cpp b/src/godot-library.cpp index 2fa2630..d03b238 100644 --- a/src/godot-library.cpp +++ b/src/godot-library.cpp @@ -1,6 +1,6 @@ #ifndef GODOT_MODULE -#include "godot-wasm.h" +#include "wasm.h" #include "wasm-memory.h" extern "C" void GDN_EXPORT wasm_gdnative_init(godot_gdnative_init_options *o) {