From 4ce27c38c6886de469a30375055dc17cfbb219a4 Mon Sep 17 00:00:00 2001 From: Sara Date: Thu, 30 May 2024 15:42:53 +0200 Subject: [PATCH] feat: documentation updates --- game_mode.hpp | 1 + game_root.cpp | 6 ++++++ game_root.hpp | 58 +++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/game_mode.hpp b/game_mode.hpp index 21f03e3..33e87cd 100644 --- a/game_mode.hpp +++ b/game_mode.hpp @@ -11,6 +11,7 @@ namespace utils { * * Inheriting classes are intended to keep only data that is relevant for the duration of the current session/match. Use GameState instead if you want data to be saved between sessions. * Will be destroyed when a level is loaded that does not match the same game mode class. + * The current active game mode can be gotten from the GameRoot3D singleton instance. */ class GameMode : public gd::Node { GDCLASS(GameMode, gd::Node); diff --git a/game_root.cpp b/game_root.cpp index 6a1b9b4..71729ca 100644 --- a/game_root.cpp +++ b/game_root.cpp @@ -44,6 +44,8 @@ void GameRoot3D::_enter_tree() { GDGAMEONLY(); void GameRoot3D::_ready() { GDGAMEONLY(); 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(); @@ -250,6 +252,10 @@ gd::Ref GameRoot3D::get_game_state_prototype() const { return this->game_state_prototype; } +gd::RandomNumberGenerator &GameRoot3D::get_rng() { + return this->rng; +} + void GameRoot3D::grab_singleton() { if(GameRoot3D::has_singleton()) { this->set_process_mode(PROCESS_MODE_DISABLED); diff --git a/game_root.hpp b/game_root.hpp index 34b2b80..9015ae9 100644 --- a/game_root.hpp +++ b/game_root.hpp @@ -109,6 +109,7 @@ public: gd::Ref get_first_boot_level() const; void set_game_state_prototype(gd::Ref game_state); gd::Ref get_game_state_prototype() const; + gd::RandomNumberGenerator &get_rng(); protected: //! Attempt to make 'this' the current singleton instance. void grab_singleton(); @@ -127,22 +128,57 @@ protected: static bool is_valid_level(gd::Ref &level); private: static GameRoot3D *singleton_instance; - - uint32_t next_player_id{1}; //!< Next available player ID. Default is 1 because 0 is the "invalid" player id. - gd::HashMap> players{}; //!< all players by id by input device. - - gd::RandomNumberGenerator rng{}; //!< Global random number generator. - gd::HashMap levels{}; //!< all currently active levels identified by their resource paths. - gd::Vector spawn_points{}; //!< all currently available spawn points. - GameMode *game_mode{}; //!< current active gamemode. + /*! Next available player ID. + * + * Default is 1 because 0 is the "invalid" player id. + */ + uint32_t next_player_id{1}; + /*! All players by id by input device. + * + * `get_players()` + */ + gd::HashMap> players{}; + /*! Global random number generator. + * + * `&get_rng()` + */ + gd::RandomNumberGenerator rng{}; + /*! All currently active levels. + * + * Each identified by their resource paths. + * + * `&get_levels()` + */ + gd::HashMap levels{}; + /*! All currently available spawn points. + */ + gd::Vector spawn_points{}; + /*! Current active gamemode. + * + * Replaced when a level is loaded that references a different game mode. + * + * `*get_game_mode()` + */ + GameMode *game_mode{}; /*! Active game state. * * Will be assigned loaded save data, or game_state_prototype if no save data is found. + * + * `*get_game_mode()` */ gd::Ref game_state{}; - - gd::Ref first_boot_level{}; //!< The level to boot into on startup. - gd::Ref game_state_prototype{}; //!< The default game state data used for game_state if no save data is available. + /*! The level to boot into on startup. + * + * `get_first_boot_level()` `set_first_boot_level(value)` + */ + gd::Ref first_boot_level{}; + /*! The default game state data. + * + * Duplicated and assigned to game_state if no save data is available. + * + * `get_game_state_prototype()` `set_game_state_prototype(value)` + */ + gd::Ref game_state_prototype{}; }; }