holesome/src/game/player/player_collection.hpp

53 lines
1.4 KiB
C++
Raw Normal View History

#ifndef HOLESOME_PLAYER_COLLECTION_HPP
#define HOLESOME_PLAYER_COLLECTION_HPP
#include "../game_object.h"
#include "player.hpp"
class PlayerCollection : public GameObject
{
public:
explicit PlayerCollection(int maxPlayerCount = DEFAULT_MAX_PLAYER_NUMBER);
static std::shared_ptr<PlayerCollection> getInstance();
void setSpawnPoints(std::vector<GridCoordinates> newSpawnPoints);
void addPlayer(const std::shared_ptr<Player>& player);
void removePlayer(const std::shared_ptr<Player>& player);
2023-06-28 01:13:10 +02:00
[[nodiscard]] std::vector<std::shared_ptr<Player>> getPlayers() const;
2023-06-21 16:05:11 +02:00
2023-06-28 01:13:10 +02:00
[[nodiscard]] std::shared_ptr<Player> getPlayerById(int playerId) const;
2023-06-28 01:13:10 +02:00
[[nodiscard]] std::vector<std::shared_ptr<Player>> getNewPlayers() const;
[[nodiscard]] std::vector<std::shared_ptr<Player>> getRemovedPlayers() const;
[[nodiscard]] int getMaxPlayerCount() const;
void lateUpdate() override;
void clear();
private:
static inline std::shared_ptr<PlayerCollection> singletonInstance = nullptr;
std::vector<std::shared_ptr<Player>> newPlayerBuffer = {};
std::vector<std::shared_ptr<Player>> removedPlayerBuffer = {};
std::vector<GridCoordinates> spawnPoints;
int nextSpawnPointIndex = 0;
void spawnPlayer(const std::shared_ptr<InputIdentity> &inputIdentity);
int maxPlayerCount;
void updateInputIdentityAllowance() const;
};
#endif //HOLESOME_PLAYER_COLLECTION_HPP