aboutsummaryrefslogtreecommitdiff
path: root/extension/src/register_types.cpp
blob: 92c25a4fea9eda89fde766259f8776a7ab263474 (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 "GameSingleton.hpp"
#include "LoadLocalisation.hpp"
#include "MapMesh.hpp"

using namespace godot;
using namespace OpenVic;

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

void initialize_openvic_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<GameSingleton>();
   _map_singleton = memnew(GameSingleton);
   Engine::get_singleton()->register_singleton("GameSingleton", GameSingleton::get_singleton());

   ClassDB::register_class<MapMesh>();
}

void uninitialize_openvic_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("GameSingleton");
   memdelete(_map_singleton);
}

extern "C" {
   // Initialization.
   GDExtensionBool GDE_EXPORT openvic_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization* r_initialization) {
      GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);

      init_obj.register_initializer(initialize_openvic_types);
      init_obj.register_terminator(uninitialize_openvic_types);
      init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

      return init_obj.init();
   }
}