godot-cpp-utils
A collection of utility classes, functions and macros for use with Godot and GDExtension.
Loading...
Searching...
No Matches
utils::GameRoot3D Class Reference

The root of a game. More...

#include <game_root.hpp>

Inheritance diagram for utils::GameRoot3D:

Public Member Functions

void player_input_connected ()
 Instantiate a new PlayerInput.
 
void remove_player (uint32_t player_id)
 Force-disconnect a player.
 
bool initialize_player (IPlayer *player, uint32_t id)
 Initialize and register a player instance.
 
void reset_game_mode ()
 Un-set game mode.
 
Level3Dload_level (gd::Ref< gd::PackedScene > level)
 shorthand for load_level(level, Transform3D())
 
Level3Dload_level_at (gd::Ref< gd::PackedScene > level, gd::Transform3D at)
 Load a level, only works if 'level' is a valid scene where the root Node can cast to 'Level3D'.
 
void unload_all_levels ()
 Unload all currently loaded levels.
 
void replace_levels (gd::Ref< gd::PackedScene > level)
 Replace all currently loaded levels with a new level.
 
void register_spawn_point (SpawnPoint3D *spawn_point)
 Register a spawnpoint for use when spawning players.
 
void set_game_mode (gd::Ref< gd::PackedScene > prototype)
 Override the current gamemode.
 
GameModeget_game_mode () const
 get the current active game mode.
 
GameStateget_game_state () const
 Get the current active game state.
 
gd::HashMap< gd::StringName, Level3D * > & get_levels ()
 Returns all currently active levels.
 
IPlayerget_player (uint32_t id)
 Get the player instance associated with id.
 
gd::Vector< IPlayer * > get_players ()
 Get all players in a list.
 

Static Public Member Functions

static GameRoot3Dget_singleton ()
 get the current active singleton instance of GameRoot
 
static bool has_singleton ()
 returns true if there is currently a singleton active for GameRoot
 

Protected Member Functions

void grab_singleton ()
 Attempt to make 'this' the current singleton instance.
 
void release_singleton ()
 Attempt to stop being the active singleton instance.
 
uint32_t find_empty_player_slot () const
 Find a Player Input device not yet associated with a player.
 
IPlayerspawn_player (uint32_t id)
 Spawn a player to be associated with id.
 
void level_unloaded (gd::StringName scene_path)
 Callback for a level exiting the tree.
 

Static Protected Member Functions

static bool is_valid_level (gd::Ref< gd::PackedScene > &level)
 Check if a scene is a valid level.
 

Private Attributes

uint32_t next_player_id {1}
 Next available player ID.
 
gd::HashMap< uint32_t, gd::Pair< PlayerInput *, IPlayer * > > players {}
 All players by id by input device.
 
gd::RandomNumberGenerator rng {}
 Global random number generator.
 
gd::HashMap< gd::StringName, Level3D * > levels {}
 All currently active levels.
 
gd::Vector< SpawnPoint3D * > spawn_points {}
 All currently available spawn points.
 
GameModegame_mode {}
 Current active gamemode.
 
gd::Ref< GameStategame_state {}
 Active game state.
 
gd::Ref< gd::PackedScene > first_boot_level {}
 The level to boot into on startup.
 
gd::Ref< GameStategame_state_prototype {}
 The default game state data.
 

Detailed Description

The root of a game.

A game root node that manages levels and input devices. Can be loaded at any point in a game's life, but suggested is setting this as the root of the boot scene.

Member Function Documentation

◆ get_levels()

gd::HashMap< gd::StringName, Level3D * > & utils::GameRoot3D::get_levels ( )

Returns all currently active levels.

Levels are identified by their packed scene path.

References levels.

◆ initialize_player()

bool utils::GameRoot3D::initialize_player ( IPlayer player,
uint32_t  id 
)

Initialize and register a player instance.

The player will be added to the tree and AFTER setup_player_input will be called. This way the player can initialize before setting up input

References players, utils::IPlayer::setup_player_input(), and utils::IPlayer::to_node().

◆ load_level_at()

Level3D * utils::GameRoot3D::load_level_at ( gd::Ref< gd::PackedScene >  level,
gd::Transform3D  at 
)

Load a level, only works if 'level' is a valid scene where the root Node can cast to 'Level3D'.

Parameters
atSets the root node's global transform.

References game_mode, is_valid_level(), level_unloaded(), levels, players, and set_game_mode().

◆ player_input_connected()

void utils::GameRoot3D::player_input_connected ( )

Instantiate a new PlayerInput.

Does not automatically spawn a new player, but does notify game mode.

References next_player_id, and players.

◆ release_singleton()

void utils::GameRoot3D::release_singleton ( )
protected

Attempt to stop being the active singleton instance.

Only works if the current singleton is 'this'.

◆ remove_player()

void utils::GameRoot3D::remove_player ( uint32_t  player_id)

Force-disconnect a player.

Calls queue_free on the IPlayer instance

References players.

◆ replace_levels()

void utils::GameRoot3D::replace_levels ( gd::Ref< gd::PackedScene >  level)

Replace all currently loaded levels with a new level.

Shorthand for

load_level(level);
void unload_all_levels()
Unload all currently loaded levels.
Definition game_root.cpp:137
Level3D * load_level(gd::Ref< gd::PackedScene > level)
shorthand for load_level(level, Transform3D())
Definition game_root.cpp:104

References load_level(), and unload_all_levels().

◆ reset_game_mode()

void utils::GameRoot3D::reset_game_mode ( )

Un-set game mode.

Shorthand for set_game_mode(Ref<PackedScene>())

References set_game_mode().

◆ set_game_mode()

void utils::GameRoot3D::set_game_mode ( gd::Ref< gd::PackedScene >  prototype)

Override the current gamemode.

Replaces game mode requires destroying and respawning all players

References find_empty_player_slot(), game_mode, initialize_player(), and spawn_player().

Member Data Documentation

◆ first_boot_level

gd::Ref<gd::PackedScene> utils::GameRoot3D::first_boot_level {}
private

The level to boot into on startup.

get_first_boot_level() set_first_boot_level(value)

◆ game_mode

GameMode* utils::GameRoot3D::game_mode {}
private

Current active gamemode.

Replaced when a level is loaded that references a different game mode.

*get_game_mode()

◆ game_state

gd::Ref<GameState> utils::GameRoot3D::game_state {}
private

Active game state.

Will be assigned loaded save data, or game_state_prototype if no save data is found.

*get_game_mode()

◆ game_state_prototype

gd::Ref<GameState> utils::GameRoot3D::game_state_prototype {}
private

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)

◆ levels

gd::HashMap<gd::StringName, Level3D*> utils::GameRoot3D::levels {}
private

All currently active levels.

Each identified by their resource paths.

&get_levels()

◆ next_player_id

uint32_t utils::GameRoot3D::next_player_id {1}
private

Next available player ID.

Default is 1 because 0 is the "invalid" player id.

◆ players

gd::HashMap<uint32_t, gd::Pair<PlayerInput*, IPlayer*> > utils::GameRoot3D::players {}
private

All players by id by input device.

get_players()

◆ rng

gd::RandomNumberGenerator utils::GameRoot3D::rng {}
private

Global random number generator.

&get_rng()


The documentation for this class was generated from the following files: