aboutsummaryrefslogtreecommitdiff
path: root/extension/src/register_types.cpp
blob: 4b049ce13fb660fa4e066aa3975426a38b42e675 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "register_types.h"
#include <gdextension_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
#include <godot_cpp/classes/engine.hpp>

#include "TestSingleton.hpp"
#include "Simulation.hpp"

using namespace godot;
using namespace OpenVic2;

static TestSingleton* _test_singleton;
static Simulation* _simulation;

void initialize_openvic2_types(ModuleInitializationLevel p_level)
{
   if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
      return;
   }

   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());

}

void uninitialize_openvic2_types(ModuleInitializationLevel p_level) {
   if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
      return;
   }

   Engine::get_singleton()->unregister_singleton("TestSingleton");
   memdelete(_test_singleton);

   Engine::get_singleton()->unregister_singleton("Simulation");
   memdelete(_test_singleton);
}

extern "C"
{

   // 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);

      return init_obj.init();
   }
}