feat: game root now better handles despawned players
parent
2344f3f2b6
commit
044164fa4b
|
@ -150,6 +150,12 @@ void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) {
|
||||||
player->spawn_at_position(spawn_point->get_global_transform());
|
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) {
|
void GameRoot3D::set_game_mode(Ref<GameMode> prototype) {
|
||||||
this->remove_all_players();
|
this->remove_all_players();
|
||||||
// allow "unsetting" the gamemode by passing an invalid gamemode
|
// allow "unsetting" the gamemode by passing an invalid gamemode
|
||||||
|
@ -242,6 +248,7 @@ IPlayer *GameRoot3D::spawn_player(uint32_t id) {
|
||||||
player_node->queue_free();
|
player_node->queue_free();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
player_node->connect("tree_exited", callable_mp(this, &GameRoot3D::player_despawned).bind(id));
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
// remove a spawnpoint so it can't be used to spawn players
|
// remove a spawnpoint so it can't be used to spawn players
|
||||||
void unregister_spawn_point(SpawnPoint3D *spawn_point);
|
void unregister_spawn_point(SpawnPoint3D *spawn_point);
|
||||||
void place_player_at_spawnpoint(IPlayer *player);
|
void place_player_at_spawnpoint(IPlayer *player);
|
||||||
|
void player_despawned(uint32_t id);
|
||||||
|
|
||||||
// ----- getter / setters -----
|
// ----- getter / setters -----
|
||||||
// override the current gamemode
|
// override the current gamemode
|
||||||
|
|
|
@ -121,5 +121,9 @@ void PlayerInput::stop_listening(Listener const& listener) {
|
||||||
if(itr != this->listeners.end())
|
if(itr != this->listeners.end())
|
||||||
this->listeners.erase(itr);
|
this->listeners.erase(itr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerInput::clear_listeners() {
|
||||||
|
this->listeners.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
void listen_to(Listener const& listener);
|
void listen_to(Listener const& listener);
|
||||||
void stop_listening(Node *node);
|
void stop_listening(Node *node);
|
||||||
void stop_listening(Listener const& listener);
|
void stop_listening(Listener const& listener);
|
||||||
|
void clear_listeners();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue