introduce local player
This commit is contained in:
+11
-2
@@ -20,10 +20,19 @@ Player* Players::get(int64_t id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
Player* Players::create() {
|
||||
Player* Players::create(int64_t id) {
|
||||
int64_t& nextPlayerID = level.getWorld()->getInfo().nextPlayerId;
|
||||
if (id == NONE) {
|
||||
id = nextPlayerID++;
|
||||
} else {
|
||||
if (auto player = get(id)) {
|
||||
return player;
|
||||
}
|
||||
nextPlayerID = std::max(id + 1, nextPlayerID);
|
||||
}
|
||||
auto playerPtr = std::make_unique<Player>(
|
||||
level,
|
||||
level.getWorld()->getInfo().nextPlayerId++,
|
||||
id,
|
||||
"",
|
||||
glm::vec3(0, DEF_PLAYER_Y, 0),
|
||||
DEF_PLAYER_SPEED,
|
||||
|
||||
@@ -14,6 +14,9 @@ class Level;
|
||||
class Player;
|
||||
|
||||
class Players : public Serializable {
|
||||
public:
|
||||
static inline int64_t NONE = -1;
|
||||
private:
|
||||
Level& level;
|
||||
std::unordered_map<int64_t, std::unique_ptr<Player>> players;
|
||||
|
||||
@@ -23,7 +26,7 @@ public:
|
||||
|
||||
Player* get(int64_t id) const;
|
||||
|
||||
Player* create();
|
||||
Player* create(int64_t id=NONE);
|
||||
|
||||
void suspend(int64_t id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user