Skip to content

Commit

Permalink
add temporary code to objects component ontick
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed Sep 30, 2023
1 parent b3fb252 commit ade6f18
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Server/Components/Objects/objects_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,13 @@ class ObjectComponent final : public IObjectsComponent, public CoreEventHandler,

void release(int index) override
{
auto ptr = storage.get(index);
if (ptr)
auto obj = storage.get(index);
if (obj)
{
static_cast<Object*>(ptr)->destream();
obj->destream();
storage.release(index, false);
processedObjects.erase(obj);
attachedToPlayer.erase(obj);
}
}

Expand Down Expand Up @@ -597,6 +599,7 @@ class PlayerObjectData final : public IPlayerObjectData
obj->destream();
storage.release(index, false);
attachedToPlayer_.erase(obj);
component_.getPlayerProcessedObjects().erase(obj);
}
}

Expand Down
36 changes: 36 additions & 0 deletions Server/Components/Objects/objects_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@

void ObjectComponent::onTick(Microseconds elapsed, TimePoint now)
{
{
std::vector<Object*> debugRemoveObjs;
for (auto it = processedObjects.begin(); it != processedObjects.end();)
{
Object* obj = *(it++);
if (!obj)
{
core->logLn(LogLevel::Error, "ObjectComponent::onTick: processedObjects loop nullptr!");
debugRemoveObjs.push_back(obj);
continue;
}

bool found = false;
for (IObject* obj_interface : storage)
{
Object* pool_obj = static_cast<Object*>(obj_interface);
if(pool_obj == obj)
{
found = true;
break;
}
}

if(!found)
{
core->logLn(LogLevel::Error, "ObjectComponent::onTick: processedObjects loop obj not found in pool!");
debugRemoveObjs.push_back(obj);
continue;
}
}

for (Object* obj : debugRemoveObjs)
{
processedObjects.erase(obj);
}
}
for (auto it = processedObjects.begin(); it != processedObjects.end();)
{
Object* obj = *(it++);
Expand Down

0 comments on commit ade6f18

Please sign in to comment.