From 72cb01f5a3ac9b92e75a74108fc67277b9f56081 Mon Sep 17 00:00:00 2001 From: Emmanuel Leblond Date: Sat, 12 Nov 2022 02:09:43 +0100 Subject: [PATCH] Add proper test project --- .github/workflows/ci.yml | 5 ++ test/.gitignore | 25 ++++++ test/CMakeLists.txt | 150 ++++++++++++++++++++++++++++++++++ test/README.md | 34 ++++++++ test/SConstruct | 32 ++++++++ test/demo/default_env.tres | 7 ++ test/demo/example.gdextension | 22 +++++ test/demo/icon.png | Bin 0 -> 3305 bytes test/demo/icon.png.import | 34 ++++++++ test/demo/main.gd | 27 ++++++ test/demo/main.tscn | 10 +++ test/demo/project.godot | 24 ++++++ test/src/example.cpp | 74 +++++++++++++++++ test/src/example.h | 53 ++++++++++++ test/src/register_types.cpp | 41 ++++++++++ test/src/register_types.h | 14 ++++ 16 files changed, 552 insertions(+) create mode 100644 test/.gitignore create mode 100644 test/CMakeLists.txt create mode 100644 test/README.md create mode 100644 test/SConstruct create mode 100644 test/demo/default_env.tres create mode 100644 test/demo/example.gdextension create mode 100644 test/demo/icon.png create mode 100644 test/demo/icon.png.import create mode 100644 test/demo/main.gd create mode 100644 test/demo/main.tscn create mode 100644 test/demo/project.godot create mode 100644 test/src/example.cpp create mode 100644 test/src/example.h create mode 100644 test/src/register_types.cpp create mode 100644 test/src/register_types.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4665ed94a1..6a9db4347e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,6 +109,11 @@ jobs: run: | scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} + - name: Build example without rebuilding godot-cpp (debug) + run: | + cd example + scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} build_library=no + - name: Build test without rebuilding godot-cpp (debug) run: | cd test diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000000..c6d839430d --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,25 @@ +# Generated directories with binaries +build +bin + +# Godot 4+ specific ignores +.godot/ + +# Godot-specific ignores +.import/ +export.cfg +export_presets.cfg +# Dummy HTML5 export presets file for continuous integration +!.github/dist/export_presets.cfg + +# Imported translations (automatically generated from CSV files) +*.translation + +# Mono-specific ignores +.mono/ +data_*/ +mono_crash.*.json + +# System/tool-specific ignores +.directory +*~ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000000..f229253edb --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,150 @@ +project(godot-cpp-test) +cmake_minimum_required(VERSION 3.6) + +set(GODOT_HEADERS_PATH ../godot-headers/ CACHE STRING "Path to Godot headers") +set(CPP_BINDINGS_PATH ../ CACHE STRING "Path to C++ bindings") + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(TARGET_PATH x11) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(TARGET_PATH win64) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(TARGET_PATH macos) +else() + message(FATAL_ERROR "Not implemented support for ${CMAKE_SYSTEM_NAME}") +endif() + +# Change the output directory to the bin directory +set(BUILD_PATH ${CMAKE_SOURCE_DIR}/bin/${TARGET_PATH}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BUILD_PATH}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BUILD_PATH}") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BUILD_PATH}") +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}") +SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}") +SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}") +SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}") +SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG "${BUILD_PATH}") +SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE "${BUILD_PATH}") + +# Set the c++ standard to c++17 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +set(GODOT_COMPILE_FLAGS ) +set(GODOT_LINKER_FLAGS ) + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # using Visual Studio C++ + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /EHsc /WX") # /GF /MP + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /DTYPED_METHOD_BIND") + + if(CMAKE_BUILD_TYPE MATCHES Debug) + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MDd") # /Od /RTC1 /Zi + else() + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /MD /O2") # /Oy /GL /Gy + STRING(REGEX REPLACE "/RTC(su|[1su])" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) + endif(CMAKE_BUILD_TYPE MATCHES Debug) + + # Disable conversion warning, truncation, unreferenced var, signed mismatch + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} /wd4244 /wd4305 /wd4101 /wd4018 /wd4267") + + add_definitions(-DNOMINMAX) + + # Unkomment for warning level 4 + #if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + # string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + #endif() + +else() + +#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # using Clang +#elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + # using GCC and maybe MinGW? + + set(GODOT_LINKER_FLAGS "-static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN'") + + # Hmm.. maybe to strikt? + set(GODOT_COMPILE_FLAGS "-fPIC -g -Wwrite-strings") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wchar-subscripts -Wcomment -Wdisabled-optimization") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wformat -Wformat=2 -Wformat-security -Wformat-y2k") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wimport -Winit-self -Winline -Winvalid-pch -Werror") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-braces -Wmissing-format-attribute") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wmissing-include-dirs -Wmissing-noreturn -Wpacked -Wpointer-arith") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wredundant-decls -Wreturn-type -Wsequence-point") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wswitch -Wswitch-enum -Wtrigraphs") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunused-label") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wunused-value -Wvariadic-macros -Wvolatile-register-var -Wno-error=attributes") + + # -Wshadow -Wextra -Wall -Weffc++ -Wfloat-equal -Wstack-protector -Wunused-parameter -Wsign-compare -Wunused-variable -Wcast-align + # -Wunused-function -Wstrict-aliasing -Wstrict-aliasing=2 -Wmissing-field-initializers + + if(NOT CMAKE_SYSTEM_NAME STREQUAL "Android") + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -Wno-ignored-attributes") + endif() + + if(CMAKE_BUILD_TYPE MATCHES Debug) + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -fno-omit-frame-pointer -O0") + else() + set(GODOT_COMPILE_FLAGS "${GODOT_COMPILE_FLAGS} -O3") + endif(CMAKE_BUILD_TYPE MATCHES Debug) +endif() + +# Get Sources +file(GLOB_RECURSE SOURCES src/*.c**) +file(GLOB_RECURSE HEADERS include/*.h**) + +# Define our godot-cpp library +add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS}) + +target_include_directories(${PROJECT_NAME} SYSTEM + PRIVATE + ${CPP_BINDINGS_PATH}/include + ${CPP_BINDINGS_PATH}/gen/include + ${GODOT_HEADERS_PATH} +) + +# Create the correct name (godot.os.build_type.system_bits) +# Synchronized with godot-cpp's CMakeLists.txt + +set(BITS 32) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(BITS 64) +endif(CMAKE_SIZEOF_VOID_P EQUAL 8) + +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(GODOT_CPP_BUILD_TYPE Debug) +else() + set(GODOT_CPP_BUILD_TYPE Release) +endif() + +string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME) +string(TOLOWER ${GODOT_CPP_BUILD_TYPE} BUILD_TYPE) + +if(ANDROID) + # Added the android abi after system name + set(SYSTEM_NAME ${SYSTEM_NAME}.${ANDROID_ABI}) +endif() + +if(CMAKE_VERSION VERSION_GREATER "3.13") + target_link_directories(${PROJECT_NAME} + PRIVATE + ${CPP_BINDINGS_PATH}/bin/ + ) + + target_link_libraries(${PROJECT_NAME} + godot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$>:.${BITS}> + ) +else() + target_link_libraries(${PROJECT_NAME} + ${CPP_BINDINGS_PATH}/bin/libgodot-cpp.${SYSTEM_NAME}.${BUILD_TYPE}$<$>:.${BITS}>.a + ) +endif() + +# Add the compile flags +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${GODOT_COMPILE_FLAGS}) +set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS ${GODOT_LINKER_FLAGS}) + +set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_NAME "gdexample") diff --git a/test/README.md b/test/README.md new file mode 100644 index 0000000000..ac8554bc13 --- /dev/null +++ b/test/README.md @@ -0,0 +1,34 @@ +# godot-cpp example / integration test + +This project is used to perform integration testing of the godot-cpp +extension, to validate PRs and implemented APIs. + +It can also be used as a quick example of how to set up a godot-cpp +project, both on the C++ side and in the Godot project itself. + +## License + +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/test/SConstruct b/test/SConstruct new file mode 100644 index 0000000000..72527bb641 --- /dev/null +++ b/test/SConstruct @@ -0,0 +1,32 @@ +#!/usr/bin/env python +import os +import sys + +env = SConscript("../SConstruct") + +# For the reference: +# - CCFLAGS are compilation flags shared between C and C++ +# - CFLAGS are for C-specific compilation flags +# - CXXFLAGS are for C++-specific compilation flags +# - CPPFLAGS are for pre-processor flags +# - CPPDEFINES are for pre-processor defines +# - LINKFLAGS are for linking flags + +# tweak this if you want to use different folders, or more folders, to store your source code in. +env.Append(CPPPATH=["src/"]) +sources = Glob("src/*.cpp") + +if env["platform"] == "macos": + library = env.SharedLibrary( + "demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format( + env["platform"], env["target"], env["platform"], env["target"] + ), + source=sources, + ) +else: + library = env.SharedLibrary( + "demo/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]), + source=sources, + ) + +Default(library) diff --git a/test/demo/default_env.tres b/test/demo/default_env.tres new file mode 100644 index 0000000000..770cd85377 --- /dev/null +++ b/test/demo/default_env.tres @@ -0,0 +1,7 @@ +[gd_resource type="Environment" load_steps=2 format=3 uid="uid://dtd3q2x2ulcsi"] + +[sub_resource type="Sky" id="1"] + +[resource] +background_mode = 2 +sky = SubResource( "1" ) diff --git a/test/demo/example.gdextension b/test/demo/example.gdextension new file mode 100644 index 0000000000..6d53405673 --- /dev/null +++ b/test/demo/example.gdextension @@ -0,0 +1,22 @@ +[configuration] + +entry_symbol = "example_library_init" + +[libraries] + +macos.debug = "res://bin/libgdexample.macos.template_debug.framework" +macos.release = "res://bin/libgdexample.macos.template_release.framework" +windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll" +windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll" +windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll" +windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll" +linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so" +linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so" +linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so" +linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so" +linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so" +linux.release.rv64 = "res://bin/libgdexample.linux.template_release.rv64.so" +android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so" +android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so" +android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so" +android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so" diff --git a/test/demo/icon.png b/test/demo/icon.png new file mode 100644 index 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al 0 HcmV?d00001 diff --git a/test/demo/icon.png.import b/test/demo/icon.png.import new file mode 100644 index 0000000000..36d7be2790 --- /dev/null +++ b/test/demo/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cswr8vy4lt7dt" +path="res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.png" +dest_files=["res://.godot/imported/icon.png-487276ed1e3a0c39cad0279d744ee560.ctex"] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/bptc_ldr=0 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/test/demo/main.gd b/test/demo/main.gd new file mode 100644 index 0000000000..92d82c449c --- /dev/null +++ b/test/demo/main.gd @@ -0,0 +1,27 @@ +extends Node + +var signal_emitted = false + +func _ready(): + var ret = $Example.my_method("Arg", FOO) + assert(ret == "ArgFoo") + var ret = $Example.my_method("Arg", BAR) + assert(ret == "ArgBar") + + var ret = $Example.my_varargs_method(Null, 1, 2, "3") + assert(ret == 4) + + var ret = $Example.my_static_method(1, 2) + assert(ret == 3) + + $Example.my_prop = Vector2(1, 2) + assert($Example.my_prop == Vector2(1, 2)) + + $Example.emit_signal("my_signal", 42) + assert(signal_emitted == true) + + # All good, exiting ;-) + get_tree().quit(0) + +func _on_Example_my_signal(signal_name, value): + signal_emitted = value == 42 diff --git a/test/demo/main.tscn b/test/demo/main.tscn new file mode 100644 index 0000000000..7598ae4046 --- /dev/null +++ b/test/demo/main.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://dmx2xuigcpvt4"] + +[ext_resource type="Script" path="res://main.gd" id="1_c326s"] + +[node name="Node" type="Node"] +script = ExtResource( "1_c326s" ) + +[node name="Example" type="Example" parent="."] + +[connection signal="my_signal" from="Example" to="." method="_on_Example_my_signal"] diff --git a/test/demo/project.godot b/test/demo/project.godot new file mode 100644 index 0000000000..cd174d2fc0 --- /dev/null +++ b/test/demo/project.godot @@ -0,0 +1,24 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="GDExtension Test Project" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.0") +config/icon="res://icon.png" + +[native_extensions] + +paths=["res://example.gdextension"] + +[rendering] + +environment/defaults/default_environment="res://default_env.tres" diff --git a/test/src/example.cpp b/test/src/example.cpp new file mode 100644 index 0000000000..244897db59 --- /dev/null +++ b/test/src/example.cpp @@ -0,0 +1,74 @@ +/* godot-cpp integration testing project. + * + * This is free and unencumbered software released into the public domain. + */ + +#include + +#include "example.h" + +int Example::my_static_method(int p_a, int p_b) { + return p_a + p_b; +} + +void Example::_bind_methods() { + // Methods. + godot::ClassDB::bind_method(godot::D_METHOD("my_method"), &Example::my_method); + + { + godot::MethodInfo mi; + mi.arguments.push_back(godot::PropertyInfo(godot::Variant::STRING, "some_argument")); + mi.name = "my_varargs_method"; + godot::ClassDB::bind_vararg_method(godot::METHOD_FLAGS_DEFAULT, "my_varargs_method", &Example::my_varargs_method, mi); + } + + godot::ClassDB::bind_static_method("Example", godot::D_METHOD("my_static_method", "a", "b"), &Example::my_static_method); + + // Properties. + ADD_GROUP("Test group", "group_"); + ADD_SUBGROUP("Test subgroup", "group_subgroup_"); + + godot::ClassDB::bind_method(godot::D_METHOD("get_my_prop"), &Example::get_my_prop); + godot::ClassDB::bind_method(godot::D_METHOD("set_my_prop", "position"), &Example::set_my_prop); + ADD_PROPERTY(godot::PropertyInfo(godot::Variant::VECTOR2I, "group_subgroup_my_prop"), "set_my_prop", "get_my_prop"); + + // Signals. + ADD_SIGNAL(godot::MethodInfo("my_signal", godot::PropertyInfo(godot::Variant::STRING, "name"), godot::PropertyInfo(godot::Variant::INT, "value"))); + godot::ClassDB::bind_method(godot::D_METHOD("emit_my_signal", "name", "value"), &Example::emit_my_signal); + + // Constants. + BIND_ENUM_CONSTANT(FOO); + BIND_ENUM_CONSTANT(BAR); +} + +Example::Example() { +} + +Example::~Example() { +} + +// Methods. +godot::String Example::my_method(const godot::String &base, const Constants arg) { + if (arg == Constants::FOO) { + return base + "Foo"; + } else { + return base + "Bar"; + } +} + +godot::Variant Example::my_varargs_method(const godot::Variant **args, GDNativeInt arg_count, GDNativeCallError &error) { + return arg_count; +} + +void Example::emit_my_signal(const godot::String &name, int value) { + emit_signal("my_signal", name, value); +} + +// Properties. +void Example::set_my_prop(const godot::Vector2 &pos) { + my_prop = pos; +} + +godot::Vector2 Example::get_my_prop() const { + return my_prop; +} diff --git a/test/src/example.h b/test/src/example.h new file mode 100644 index 0000000000..16ef41f70a --- /dev/null +++ b/test/src/example.h @@ -0,0 +1,53 @@ +/* godot-cpp integration testing project. + * + * This is free and unencumbered software released into the public domain. + */ + +#ifndef EXAMPLE_CLASS_H +#define EXAMPLE_CLASS_H + +// We don't need windows.h in this example plugin but many others do, and it can +// lead to annoying situations due to the ton of macros it defines. +// So we include it and make sure CI warns us if we use something that conflicts +// with a Windows define. +#ifdef WIN32 +#include +#endif + +#include + +class Example : public godot::Object { + GDCLASS(Example, godot::Object); + +protected: + static void _bind_methods(); + +private: + godot::Vector2i my_prop; + +public: + // Constants. + enum Constants { + FOO, + BAR, + }; + + Example(); + ~Example(); + + // Functions. + godot::String my_method(const godot::String &base, const Constants arg); + godot::Variant my_varargs_method(const godot::Variant **args, GDNativeInt arg_count, GDNativeCallError &error); + void emit_my_signal(const godot::String &name, int value); + + // Property. + void set_my_prop(const godot::Vector2 &pos); + godot::Vector2 get_my_prop() const; + + // Static method. + static int my_static_method(int p_a, int p_b); +}; + +VARIANT_ENUM_CAST(Example, Constants); + +#endif // EXAMPLE_CLASS_H diff --git a/test/src/register_types.cpp b/test/src/register_types.cpp new file mode 100644 index 0000000000..b5e8651505 --- /dev/null +++ b/test/src/register_types.cpp @@ -0,0 +1,41 @@ +/* godot-cpp integration testing project. + * + * This is free and unencumbered software released into the public domain. + */ + +#include "register_types.h" + +#include + +#include +#include +#include + +#include "example.h" + +void initialize_example_module(godot::ModuleInitializationLevel p_level) { + if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } + + godot::ClassDB::register_class(); +} + +void uninitialize_example_module(godot::ModuleInitializationLevel p_level) { + if (p_level != godot::MODULE_INITIALIZATION_LEVEL_SCENE) { + return; + } +} + +extern "C" { +// Initialization. +GDNativeBool GDN_EXPORT example_library_init(const GDNativeInterface *p_interface, const GDNativeExtensionClassLibraryPtr p_library, GDNativeInitialization *r_initialization) { + godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization); + + init_obj.register_initializer(initialize_example_module); + init_obj.register_terminator(uninitialize_example_module); + init_obj.set_minimum_library_initialization_level(godot::MODULE_INITIALIZATION_LEVEL_SCENE); + + return init_obj.init(); +} +} diff --git a/test/src/register_types.h b/test/src/register_types.h new file mode 100644 index 0000000000..0611c25d8f --- /dev/null +++ b/test/src/register_types.h @@ -0,0 +1,14 @@ +/* godot-cpp integration testing project. + * + * This is free and unencumbered software released into the public domain. + */ + +#ifndef EXAMPLE_REGISTER_TYPES_H +#define EXAMPLE_REGISTER_TYPES_H + +#include + +void initialize_example_module(godot::ModuleInitializationLevel p_level); +void uninitialize_example_module(godot::ModuleInitializationLevel p_level); + +#endif // EXAMPLE_REGISTER_TYPES_H