aboutsummaryrefslogtreecommitdiff
path: root/extension/src/register_types.cpp
blob: 10ed781957f28b3e12f05e11aa4afc2a39193d5a (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
#include "register_types.h"

#include <godot_cpp/classes/engine.hpp>

#include "Checksum.hpp"
#include "LoadLocalisation.hpp"
#include "MapSingleton.hpp"
#include "MapMesh.hpp"

using namespace godot;
using namespace OpenVic2;

static Checksum* _checksum;
static LoadLocalisation* _load_localisation;
static MapSingleton* _map_singleton;

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

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

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

   ClassDB::register_class<MapMesh>();
}

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

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

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

   Engine::get_singleton()->unregister_singleton("MapSingleton");
   memdelete(_map_singleton);
}

extern "C" {
   // Initialization.
   GDExtensionBool GDE_EXPORT openvic2_library_init(GDExtensionInterface const* 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();
   }
}