aboutsummaryrefslogtreecommitdiff
path: root/extension/src/register_types.cpp
diff options
context:
space:
mode:
author Robert Clarke <clarke.john.robert@gmail.com>2023-02-12 09:44:39 +0100
committer Robert Clarke <clarke.john.robert@gmail.com>2023-02-12 09:44:39 +0100
commitd45323cadee9044d8536f7eb9827a43b36e4bdff (patch)
tree6e2a8aa1d7d2c7e69df8eb6d5a18524b8e8ffa00 /extension/src/register_types.cpp
parente7ee0ddbefa8f6696aa7b5a001b3a04eb046ba0d (diff)
Everything necessary to register a C++ class with internal state for access within Godot
Diffstat (limited to 'extension/src/register_types.cpp')
-rw-r--r--extension/src/register_types.cpp51
1 files changed, 30 insertions, 21 deletions
diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp
index 775e6c3..4b049ce 100644
--- a/extension/src/register_types.cpp
+++ b/extension/src/register_types.cpp
@@ -6,46 +6,55 @@
#include <godot_cpp/classes/engine.hpp>
#include "TestSingleton.hpp"
+#include "Simulation.hpp"
using namespace godot;
using namespace OpenVic2;
-static TestSingleton *_test_singleton;
+static TestSingleton* _test_singleton;
+static Simulation* _simulation;
void initialize_openvic2_types(ModuleInitializationLevel p_level)
{
- if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
- return;
- }
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
- ClassDB::register_class<TestSingleton>();
+ ClassDB::register_class<TestSingleton>();
+ _test_singleton = memnew(TestSingleton);
+ Engine::get_singleton()->register_singleton("TestSingleton", TestSingleton::get_singleton());
+
+ ClassDB::register_class<Simulation>();
+ _simulation = memnew(Simulation);
+ Engine::get_singleton()->register_singleton("Simulation", Simulation::get_singleton());
- _test_singleton = memnew(TestSingleton);
- Engine::get_singleton()->register_singleton("TestSingleton", TestSingleton::get_singleton());
}
void uninitialize_openvic2_types(ModuleInitializationLevel p_level) {
- if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
- return;
- }
+ if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
+ return;
+ }
+
+ Engine::get_singleton()->unregister_singleton("TestSingleton");
+ memdelete(_test_singleton);
- Engine::get_singleton()->unregister_singleton("TestSingleton");
- memdelete(_test_singleton);
+ Engine::get_singleton()->unregister_singleton("Simulation");
+ memdelete(_test_singleton);
}
extern "C"
{
- // Initialization.
+ // Initialization.
- GDExtensionBool GDE_EXPORT openvic2_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
- {
- GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
+ GDExtensionBool GDE_EXPORT openvic2_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
+ {
+ GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
- init_obj.register_initializer(initialize_openvic2_types);
- init_obj.register_terminator(uninitialize_openvic2_types);
- init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
+ init_obj.register_initializer(initialize_openvic2_types);
+ init_obj.register_terminator(uninitialize_openvic2_types);
+ init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
- return init_obj.init();
- }
+ return init_obj.init();
+ }
} \ No newline at end of file