]> git.localhorst.tv Git - blank.git/blobdiff - src/world/World.hpp
make server aware connected clients' player entity
[blank.git] / src / world / World.hpp
index 7d2c2926a1732ee4ea5f663cd112f3de6dd4335a..9739e21f18415eff4df70010fe9b588d82ba332b 100644 (file)
@@ -5,6 +5,7 @@
 #include "Entity.hpp"
 #include "Generator.hpp"
 
+#include <cstdint>
 #include <list>
 #include <string>
 #include <vector>
@@ -70,7 +71,14 @@ public:
        /// add player with given name
        /// returns nullptr if the name is already taken
        Entity *AddPlayer(const std::string &name);
-       Entity &AddEntity() { entities.emplace_back(); return entities.back(); }
+       /// add player with given name and ID
+       /// returns nullptr if the name or ID is already taken
+       Entity *AddPlayer(const std::string &name, std::uint32_t id);
+       /// add an entity with an autogenerated ID
+       Entity &AddEntity();
+       /// add entity with given ID
+       /// returns nullptr if the ID is already taken
+       Entity *AddEntity(std::uint32_t id);
 
        const std::vector<Entity *> &Players() const noexcept { return players; }
        const std::list<Entity> &Entities() const noexcept { return entities; }
@@ -79,6 +87,10 @@ public:
 
        void Render(Viewport &);
 
+private:
+       using EntityHandle = std::list<Entity>::iterator;
+       EntityHandle RemoveEntity(EntityHandle &);
+
 private:
        Config config;