From 5371a960c9f0665d7de594cc5e274db225620207 Mon Sep 17 00:00:00 2001 From: "George L. Albany" Date: Tue, 24 Jan 2023 20:07:01 -0500 Subject: feat(build): Implement scons building feat(engine): Integrate basic Godot project feat(test): Demonstrate Godot using extension feat(dependency): Add OV2-compiler as deps submodule feat(dependency): Add godot-cpp as a submodule feat(git): Ignore Godot 4 files feat(docs): Updated readme with instructions feat: Can call `TestSingleton.hello_singleton()` from GDScript Adds basic workflow support but that is currently disabled --- extension/src/TestSingleton.cpp | 36 ++++++++++++++++++++++++++++ extension/src/TestSingleton.hpp | 24 +++++++++++++++++++ extension/src/register_types.cpp | 51 ++++++++++++++++++++++++++++++++++++++++ extension/src/register_types.h | 6 +++++ 4 files changed, 117 insertions(+) create mode 100644 extension/src/TestSingleton.cpp create mode 100644 extension/src/TestSingleton.hpp create mode 100644 extension/src/register_types.cpp create mode 100644 extension/src/register_types.h (limited to 'extension/src') diff --git a/extension/src/TestSingleton.cpp b/extension/src/TestSingleton.cpp new file mode 100644 index 0000000..0855a30 --- /dev/null +++ b/extension/src/TestSingleton.cpp @@ -0,0 +1,36 @@ +#include "TestSingleton.hpp" + +#include +#include + +using namespace godot; +using namespace OpenVic2; + +TestSingleton *TestSingleton::singleton = nullptr; + +void TestSingleton::_bind_methods() +{ + ClassDB::bind_method(D_METHOD("hello_singleton"), &TestSingleton::hello_singleton); +} + +TestSingleton *TestSingleton::get_singleton() +{ + return singleton; +} + +TestSingleton::TestSingleton() +{ + ERR_FAIL_COND(singleton != nullptr); + singleton = this; +} + +TestSingleton::~TestSingleton() +{ + ERR_FAIL_COND(singleton != this); + singleton = nullptr; +} + +void TestSingleton::hello_singleton() +{ + UtilityFunctions::print("Hello GDExtension Singleton!"); +} \ No newline at end of file diff --git a/extension/src/TestSingleton.hpp b/extension/src/TestSingleton.hpp new file mode 100644 index 0000000..0a591ac --- /dev/null +++ b/extension/src/TestSingleton.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace OpenVic2 { + class TestSingleton : public godot::Object + { + GDCLASS(TestSingleton, godot::Object); + + static TestSingleton *singleton; + + protected: + static void _bind_methods(); + + public: + static TestSingleton *get_singleton(); + + TestSingleton(); + ~TestSingleton(); + + void hello_singleton(); + }; +} \ No newline at end of file diff --git a/extension/src/register_types.cpp b/extension/src/register_types.cpp new file mode 100644 index 0000000..775e6c3 --- /dev/null +++ b/extension/src/register_types.cpp @@ -0,0 +1,51 @@ +#include "register_types.h" +#include +#include +#include +#include +#include + +#include "TestSingleton.hpp" + +using namespace godot; +using namespace OpenVic2; + +static TestSingleton *_test_singleton; + +void initialize_openvic2_types(ModuleInitializationLevel p_level) +{ + if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + ClassDB::register_class(); + + _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; + } + + Engine::get_singleton()->unregister_singleton("TestSingleton"); + 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(); + } +} \ No newline at end of file diff --git a/extension/src/register_types.h b/extension/src/register_types.h new file mode 100644 index 0000000..860359f --- /dev/null +++ b/extension/src/register_types.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +void initialize_openvic2_types(godot::ModuleInitializationLevel); +void uninitialize_openvic2_types(godot::ModuleInitializationLevel); \ No newline at end of file -- cgit v1.2.3-56-ga3b1