Merge remote-tracking branch 'origin' into temp

main
Sara 2024-10-05 22:17:32 +02:00
commit b1d5e5d263
4 changed files with 15 additions and 28 deletions

View File

@ -36,20 +36,20 @@ 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();
this->rng = godot::Ref<godot::RandomNumberGenerator>(memnew(godot::RandomNumberGenerator));
}
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();
}

View File

@ -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.
*

View File

@ -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<gd::InputEvent> const &event) { GDGAMEONLY();
void PlayerInput::_unhandled_input(gd::Ref<gd::InputEvent> const &event) {
if(this->isPrimary && event->is_class("InputEventMouseMotion"))
PlayerInput::lastMouseMotion = gd::Object::cast_to<gd::InputEventMouseMotion>(*event)->get_relative();
for(Listener& listener: this->listeners) {

View File

@ -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);
}
}