1#ifndef UTILS_GAME_ROOT_HPP
2#define UTILS_GAME_ROOT_HPP
4#include "game_mode.hpp"
5#include "game_state.hpp"
7#include <godot_cpp/classes/node.hpp>
8#include <godot_cpp/classes/packed_scene.hpp>
9#include <godot_cpp/classes/random_number_generator.hpp>
10#include <godot_cpp/templates/hash_map.hpp>
11#include <godot_cpp/templates/hash_set.hpp>
12#include <godot_cpp/templates/pair.hpp>
13#include <godot_cpp/templates/pair.hpp>
14#include <godot_cpp/templates/vector.hpp>
30 static void _bind_methods();
37 virtual void _enter_tree()
override;
38 virtual void _ready()
override;
39 virtual void _exit_tree()
override;
52 void remove_all_players();
87 void place_player_at_spawnpoint(
IPlayer *player);
88 void player_despawned(uint32_t
id);
103 gd::HashMap<gd::StringName, Level3D *> &
get_levels();
108 void set_first_boot_level(gd::Ref<gd::PackedScene> level);
109 gd::Ref<gd::PackedScene> get_first_boot_level()
const;
110 void set_game_state_prototype(gd::Ref<GameState>
game_state);
111 gd::Ref<GameState> get_game_state_prototype()
const;
112 gd::RandomNumberGenerator &get_rng();
140 gd::HashMap<uint32_t, gd::Pair<PlayerInput*, IPlayer*>>
players{};
145 gd::RandomNumberGenerator
rng{};
152 gd::HashMap<gd::StringName, Level3D*>
levels{};
Stores session-relevant data.
Definition game_mode.hpp:16
The root of a game.
Definition game_root.hpp:28
void grab_singleton()
Attempt to make 'this' the current singleton instance.
Definition game_root.cpp:259
GameState * get_game_state() const
Get the current active game state.
Definition game_root.cpp:209
gd::Vector< SpawnPoint3D * > spawn_points
All currently available spawn points.
Definition game_root.hpp:155
static bool has_singleton()
returns true if there is currently a singleton active for GameRoot
Definition game_root.cpp:35
void register_spawn_point(SpawnPoint3D *spawn_point)
Register a spawnpoint for use when spawning players.
Definition game_root.cpp:150
IPlayer * get_player(uint32_t id)
Get the player instance associated with id.
Definition game_root.cpp:217
IPlayer * spawn_player(uint32_t id)
Spawn a player to be associated with id.
Definition game_root.cpp:285
void unload_all_levels()
Unload all currently loaded levels.
Definition game_root.cpp:137
void replace_levels(gd::Ref< gd::PackedScene > level)
Replace all currently loaded levels with a new level.
Definition game_root.cpp:145
gd::RandomNumberGenerator rng
Global random number generator.
Definition game_root.hpp:145
GameMode * game_mode
Current active gamemode.
Definition game_root.hpp:162
static bool is_valid_level(gd::Ref< gd::PackedScene > &level)
Check if a scene is a valid level.
Definition game_root.cpp:309
gd::HashMap< gd::StringName, Level3D * > levels
All currently active levels.
Definition game_root.hpp:152
void player_input_connected()
Instantiate a new PlayerInput.
Definition game_root.cpp:55
bool initialize_player(IPlayer *player, uint32_t id)
Initialize and register a player instance.
Definition game_root.cpp:86
GameMode * get_game_mode() const
get the current active game mode.
Definition game_root.cpp:205
void remove_player(uint32_t player_id)
Force-disconnect a player.
Definition game_root.cpp:62
void set_game_mode(gd::Ref< gd::PackedScene > prototype)
Override the current gamemode.
Definition game_root.cpp:179
gd::HashMap< gd::StringName, Level3D * > & get_levels()
Returns all currently active levels.
Definition game_root.cpp:213
uint32_t find_empty_player_slot() const
Find a Player Input device not yet associated with a player.
Definition game_root.cpp:276
gd::Ref< gd::PackedScene > first_boot_level
The level to boot into on startup.
Definition game_root.hpp:174
Level3D * load_level(gd::Ref< gd::PackedScene > level)
shorthand for load_level(level, Transform3D())
Definition game_root.cpp:104
gd::HashMap< uint32_t, gd::Pair< PlayerInput *, IPlayer * > > players
All players by id by input device.
Definition game_root.hpp:140
static GameRoot3D * get_singleton()
get the current active singleton instance of GameRoot
Definition game_root.cpp:31
Level3D * 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'.
Definition game_root.cpp:108
gd::Ref< GameState > game_state_prototype
The default game state data.
Definition game_root.hpp:181
void release_singleton()
Attempt to stop being the active singleton instance.
Definition game_root.cpp:268
void reset_game_mode()
Un-set game mode.
Definition game_root.cpp:100
gd::Vector< IPlayer * > get_players()
Get all players in a list.
Definition game_root.cpp:221
void level_unloaded(gd::StringName scene_path)
Callback for a level exiting the tree.
Definition game_root.cpp:305
uint32_t next_player_id
Next available player ID.
Definition game_root.hpp:135
gd::Ref< GameState > game_state
Active game state.
Definition game_root.hpp:169
Parent class for saved game state.
Definition game_state.hpp:11
Interface required for player nodes.
Definition player.hpp:19
3D level root to be used with GameRoot3D.
Definition level.hpp:14
A location in the game world that the player can spawn at.
Definition spawn_point.hpp:13