]> git.localhorst.tv Git - blank.git/blobdiff - src/world/World.cpp
better control over entity update transmission
[blank.git] / src / world / World.cpp
index 3ff7da341e3e52f2d6989a2bf67969f896d51b98..505cbbb70f3838c0b89e0a27d5d18a2d41b752df 100644 (file)
@@ -114,6 +114,26 @@ Entity *World::AddEntity(std::uint32_t id) {
        return &*entity;
 }
 
+Entity &World::ForceAddEntity(std::uint32_t id) {
+       if (entities.empty() || entities.back().ID() < id) {
+               entities.emplace_back();
+               entities.back().ID(id);
+               return entities.back();
+       }
+
+       auto position = entities.begin();
+       auto end = entities.end();
+       while (position != end && position->ID() < id) {
+               ++position;
+       }
+       if (position != end && position->ID() == id) {
+               return *position;
+       }
+       auto entity = entities.emplace(position);
+       entity->ID(id);
+       return *entity;
+}
+
 
 namespace {