feat: game root now better handles despawned players

stripped
Sara 2024-05-21 11:56:41 +02:00
parent 2344f3f2b6
commit 044164fa4b
4 changed files with 13 additions and 0 deletions

View File

@ -150,6 +150,12 @@ void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) {
player->spawn_at_position(spawn_point->get_global_transform());
}
void GameRoot3D::player_despawned(uint32_t id) {
Pair<PlayerInput*, IPlayer*> &pair = this->players.get(id);
pair.second = nullptr;
pair.first->clear_listeners();
}
void GameRoot3D::set_game_mode(Ref<GameMode> prototype) {
this->remove_all_players();
// allow "unsetting" the gamemode by passing an invalid gamemode
@ -242,6 +248,7 @@ IPlayer *GameRoot3D::spawn_player(uint32_t id) {
player_node->queue_free();
return nullptr;
}
player_node->connect("tree_exited", callable_mp(this, &GameRoot3D::player_despawned).bind(id));
return player;
}

View File

@ -55,6 +55,7 @@ public:
// remove a spawnpoint so it can't be used to spawn players
void unregister_spawn_point(SpawnPoint3D *spawn_point);
void place_player_at_spawnpoint(IPlayer *player);
void player_despawned(uint32_t id);
// ----- getter / setters -----
// override the current gamemode

View File

@ -121,5 +121,9 @@ void PlayerInput::stop_listening(Listener const& listener) {
if(itr != this->listeners.end())
this->listeners.erase(itr);
}
void PlayerInput::clear_listeners() {
this->listeners.clear();
}
}

View File

@ -70,6 +70,7 @@ public:
void listen_to(Listener const& listener);
void stop_listening(Node *node);
void stop_listening(Listener const& listener);
void clear_listeners();
};
}