diff --git a/game_root.cpp b/game_root.cpp index 2b9a753..286c47c 100644 --- a/game_root.cpp +++ b/game_root.cpp @@ -36,19 +36,19 @@ bool GameRoot3D::has_singleton() { return GameRoot3D::singleton_instance != nullptr; } -void GameRoot3D::_enter_tree() { GDGAMEONLY(); +void GameRoot3D::_enter_tree() { // TODO: Replace this with detecting input devices this->player_input_connected(); this->grab_singleton(); } -void GameRoot3D::_ready() { GDGAMEONLY(); +void GameRoot3D::_ready() { this->load_level(this->first_boot_level); // TODO: try load save data from file. this->game_state = this->game_state_prototype->duplicate(true); } -void GameRoot3D::_exit_tree() { GDGAMEONLY(); +void GameRoot3D::_exit_tree() { this->release_singleton(); } diff --git a/godot_macros.hpp b/godot_macros.hpp index d4b82ff..640fc0d 100644 --- a/godot_macros.hpp +++ b/godot_macros.hpp @@ -37,28 +37,28 @@ /*! \def GDFUNCTION(FnName_) * \brief Register a function CLASSNAME::FnName_() to godot. - * + * * Requires setting CLASSNAME as a #define first. */ #define GDFUNCTION(FnName_) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_), &CLASSNAME::FnName_) /*! \def GDFUNCTION_ARGS(FnName_, ...) * \brief Register a function CLASSNAME::FnName_(...) to godot. - * + * * Requires setting CLASSNAME as a #define first. */ #define GDFUNCTION_ARGS(FnName_, ...) godot::ClassDB::bind_method(godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_) /*! \def GDFUNCTION_STATIC(FnName_) * \brief Register a static member function CLASSNAME::FnName_() to godot. - * + * * Requires setting CLASSNAME as a #define first. */ #define GDFUNCTION_STATIC(FnName_) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_), &CLASSNAME::_FnName) /*! \def GDFUNCTION_STATIC_ARGS(FnName_, ...) * \brief Register a static member function CLASSNAME::FnName_(...) to godot. - * + * * Requires setting CLASSNAME as a #define first. */ #define GDFUNCTION_STATIC_ARGS(FnName_, ...) godot::ClassDB::bind_static_method(MACRO_STRING(CLASSNAME), godot::D_METHOD(#FnName_, __VA_ARGS__), &CLASSNAME::FnName_) @@ -77,19 +77,6 @@ #define GDNODETYPE(Class_) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_NODE_TYPE, Class_) #define GDENUMTYPE(EnumString_) godot::vformat("%s/%s:%s", godot::Variant::INT, godot::PROPERTY_HINT_ENUM, EnumString_) -/*! \def GDEDITORONLY() - * \brief Execute the rest of the function only if currently running as editor. - * - * Useful for _ready, _enter/_exit, _process, etc. functions. - */ -#define GDEDITORONLY() if(!godot::Engine::get_singleton()->is_editor_hint()) return; -/*! \def GDGAMEONLY() - * \brief Execute the rest of the function only if currently running as game. - * - * Useful for _ready, _enter/_exit, _process, etc. functions. - */ -#define GDGAMEONLY() if(godot::Engine::get_singleton()->is_editor_hint()) return; - /*! \def GDENUM(Name_, ...) * \brief Declare a scoped enum struct. * diff --git a/player_input.cpp b/player_input.cpp index b544c93..142c2b1 100644 --- a/player_input.cpp +++ b/player_input.cpp @@ -74,21 +74,21 @@ gd::Vector2 PlayerInput::get_last_mouse_motion() { return PlayerInput::lastMouseMotion; } -void PlayerInput::_enter_tree() { GDGAMEONLY(); +void PlayerInput::_enter_tree() { if(!PlayerInput::primaryExists) { this->isPrimary = true; PlayerInput::primaryExists = true; } } -void PlayerInput::_exit_tree() { GDGAMEONLY(); +void PlayerInput::_exit_tree() { if(this->isPrimary) { this->isPrimary = false; PlayerInput::primaryExists = false; } } -void PlayerInput::_unhandled_input(gd::Ref const &event) { GDGAMEONLY(); +void PlayerInput::_unhandled_input(gd::Ref const &event) { if(this->isPrimary && event->is_class("InputEventMouseMotion")) PlayerInput::lastMouseMotion = gd::Object::cast_to(*event)->get_relative(); for(Listener& listener: this->listeners) { diff --git a/register_types.cpp b/register_types.cpp index d867791..7ac8ab6 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -9,11 +9,11 @@ namespace utils { void godot_cpp_utils_register_types() { - GDREGISTER_CLASS(utils::GameMode); - GDREGISTER_CLASS(utils::GameRoot3D); + GDREGISTER_RUNTIME_CLASS(utils::GameMode); + GDREGISTER_RUNTIME_CLASS(utils::GameRoot3D); GDREGISTER_CLASS(utils::GameState); - GDREGISTER_CLASS(utils::Level3D); - GDREGISTER_CLASS(utils::PlayerInput); - GDREGISTER_CLASS(utils::SpawnPoint3D); + GDREGISTER_RUNTIME_CLASS(utils::Level3D); + GDREGISTER_RUNTIME_CLASS(utils::PlayerInput); + GDREGISTER_RUNTIME_CLASS(utils::SpawnPoint3D); } }