aboutsummaryrefslogtreecommitdiff
path: root/extension/src/register_types.cpp
blob: d1613a5eb226c89ab18e0b3311ce53612a7d2d2a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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"
#include "Checksum.hpp"
#include "LoadLocalisation.hpp"

using namespace godot;
using namespace OpenVic2;

static TestSingleton* _test_singleton;
static Simulation* _simulation;
static Checksum* _checksum;
static LoadLocalisation* _load_localisation;

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

   ClassDB::register_class<Checksum>();
   _checksum = memnew(Checksum);
   Engine::get_singleton()->register_singleton("Checksum", Checksum::get_singleton());

   ClassDB::register_class<LoadLocalisation>();
   _load_localisation = memnew(LoadLocalisation);
   Engine::get_singleton()->register_singleton("LoadLocalisation", LoadLocalisation::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(_simulation);

   Engine::get_singleton()->unregister_singleton("Checksum");
   memdelete(_checksum);

   Engine::get_singleton()->unregister_singleton("LoadLocalisation");
   memdelete(_load_localisation);
}

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