2024-03-13 15:08:37 +00:00
|
|
|
#ifndef GAME_ROOT_HPP
|
|
|
|
#define GAME_ROOT_HPP
|
|
|
|
|
|
|
|
#include <godot_cpp/classes/packed_scene.hpp>
|
|
|
|
#include <godot_cpp/classes/node.hpp>
|
|
|
|
#include <godot_cpp/templates/hash_map.hpp>
|
|
|
|
#include <godot_cpp/templates/hash_set.hpp>
|
|
|
|
#include <godot_cpp/templates/pair.hpp>
|
|
|
|
#include <godot_cpp/templates/vector.hpp>
|
|
|
|
#include <godot_cpp/templates/pair.hpp>
|
|
|
|
#include "game_mode.hpp"
|
|
|
|
#include "level.hpp"
|
|
|
|
|
|
|
|
namespace godot {
|
|
|
|
class PlayerInput;
|
|
|
|
class IPlayer;
|
|
|
|
class SpawnPoint3D;
|
|
|
|
|
|
|
|
class GameRoot : public Node {
|
|
|
|
GDCLASS(GameRoot, Node);
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
static GameRoot *get_singleton();
|
|
|
|
static bool has_singleton();
|
|
|
|
|
|
|
|
virtual void _enter_tree() override;
|
|
|
|
virtual void _exit_tree() override;
|
|
|
|
|
|
|
|
void player_connected();
|
2024-03-16 19:56:26 +00:00
|
|
|
void player_disconnected(uint32_t player_id);
|
2024-03-16 12:02:36 +00:00
|
|
|
bool initialize_player(IPlayer *player, uint32_t id);
|
2024-03-13 15:08:37 +00:00
|
|
|
|
|
|
|
void reset_game_mode();
|
|
|
|
protected:
|
|
|
|
void grab_singleton();
|
|
|
|
void release_singleton();
|
2024-03-16 12:02:36 +00:00
|
|
|
uint32_t find_empty_player_slot() const;
|
|
|
|
void set_game_mode(Ref<GameMode> prototype);
|
|
|
|
virtual IPlayer *spawn_player(uint32_t id);
|
2024-03-13 15:08:37 +00:00
|
|
|
protected:
|
|
|
|
static GameRoot *singleton_instance;
|
|
|
|
|
2024-03-16 12:02:36 +00:00
|
|
|
uint32_t next_player_id{1}; // 0 is the "invalid" player id
|
2024-03-13 15:08:37 +00:00
|
|
|
HashMap<uint32_t, Pair<PlayerInput*, IPlayer*>> players{};
|
|
|
|
Ref<GameMode> game_mode{};
|
|
|
|
};
|
|
|
|
|
|
|
|
class GameRoot3D : public GameRoot {
|
|
|
|
GDCLASS(GameRoot3D, GameRoot);
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
virtual void _ready() override;
|
|
|
|
Level3D *load_level(Ref<PackedScene> level);
|
|
|
|
Level3D *load_level_at(Ref<PackedScene> level, Transform3D at);
|
|
|
|
|
|
|
|
void register_spawn_point(SpawnPoint3D *spawn_point);
|
|
|
|
void unregister_spawn_point(SpawnPoint3D *spawn_point);
|
|
|
|
|
|
|
|
void set_first_boot_level(Ref<PackedScene> level);
|
|
|
|
Ref<PackedScene> get_first_boot_level() const;
|
2024-03-16 12:02:36 +00:00
|
|
|
protected:
|
|
|
|
virtual IPlayer *spawn_player(uint32_t id) override;
|
2024-03-13 15:08:37 +00:00
|
|
|
private:
|
|
|
|
static bool is_valid_level(Ref<PackedScene> &level);
|
|
|
|
private:
|
|
|
|
HashMap<StringName, Level3D*> levels{};
|
|
|
|
HashSet<SpawnPoint3D*> spawn_points{};
|
|
|
|
|
|
|
|
Ref<PackedScene> first_boot_level{};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !GAME_ROOT_HPP
|