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; return GameRoot3D::singleton_instance != nullptr;
} }
void GameRoot3D::_enter_tree() { GDGAMEONLY(); void GameRoot3D::_enter_tree() {
// TODO: Replace this with detecting input devices // TODO: Replace this with detecting input devices
this->player_input_connected(); this->player_input_connected();
this->grab_singleton(); this->grab_singleton();
this->rng = godot::Ref<godot::RandomNumberGenerator>(memnew(godot::RandomNumberGenerator)); this->rng = godot::Ref<godot::RandomNumberGenerator>(memnew(godot::RandomNumberGenerator));
} }
void GameRoot3D::_ready() { GDGAMEONLY(); void GameRoot3D::_ready() {
this->load_level(this->first_boot_level); this->load_level(this->first_boot_level);
// TODO: try load save data from file. // TODO: try load save data from file.
this->game_state = this->game_state_prototype->duplicate(true); this->game_state = this->game_state_prototype->duplicate(true);
} }
void GameRoot3D::_exit_tree() { GDGAMEONLY(); void GameRoot3D::_exit_tree() {
this->release_singleton(); this->release_singleton();
} }

View File

@ -77,19 +77,6 @@
#define GDNODETYPE(Class_) godot::vformat("%s/%s:%s", godot::Variant::OBJECT, godot::PROPERTY_HINT_NODE_TYPE, Class_) #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_) #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_, ...) /*! \def GDENUM(Name_, ...)
* \brief Declare a scoped enum struct. * \brief Declare a scoped enum struct.
* *

View File

@ -74,21 +74,21 @@ gd::Vector2 PlayerInput::get_last_mouse_motion() {
return PlayerInput::lastMouseMotion; return PlayerInput::lastMouseMotion;
} }
void PlayerInput::_enter_tree() { GDGAMEONLY(); void PlayerInput::_enter_tree() {
if(!PlayerInput::primaryExists) { if(!PlayerInput::primaryExists) {
this->isPrimary = true; this->isPrimary = true;
PlayerInput::primaryExists = true; PlayerInput::primaryExists = true;
} }
} }
void PlayerInput::_exit_tree() { GDGAMEONLY(); void PlayerInput::_exit_tree() {
if(this->isPrimary) { if(this->isPrimary) {
this->isPrimary = false; this->isPrimary = false;
PlayerInput::primaryExists = 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")) if(this->isPrimary && event->is_class("InputEventMouseMotion"))
PlayerInput::lastMouseMotion = gd::Object::cast_to<gd::InputEventMouseMotion>(*event)->get_relative(); PlayerInput::lastMouseMotion = gd::Object::cast_to<gd::InputEventMouseMotion>(*event)->get_relative();
for(Listener& listener: this->listeners) { for(Listener& listener: this->listeners) {

View File

@ -9,11 +9,11 @@
namespace utils { namespace utils {
void godot_cpp_utils_register_types() { void godot_cpp_utils_register_types() {
GDREGISTER_CLASS(utils::GameMode); GDREGISTER_RUNTIME_CLASS(utils::GameMode);
GDREGISTER_CLASS(utils::GameRoot3D); GDREGISTER_RUNTIME_CLASS(utils::GameRoot3D);
GDREGISTER_CLASS(utils::GameState); GDREGISTER_CLASS(utils::GameState);
GDREGISTER_CLASS(utils::Level3D); GDREGISTER_RUNTIME_CLASS(utils::Level3D);
GDREGISTER_CLASS(utils::PlayerInput); GDREGISTER_RUNTIME_CLASS(utils::PlayerInput);
GDREGISTER_CLASS(utils::SpawnPoint3D); GDREGISTER_RUNTIME_CLASS(utils::SpawnPoint3D);
} }
} }