Skip to content

Commit ff95939

Browse files
committed
remove events on entity components
1 parent 0b007c2 commit ff95939

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

sources/include/cage-core/entities.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ namespace cage
6767
CAGE_FORCE_INLINE uint32 count() const { return numeric_cast<uint32>(entities().size()); }
6868

6969
void destroy(); // destroy all entities with this component
70-
71-
EventDispatcher<bool(Entity *)> entityAdded;
72-
EventDispatcher<bool(Entity *)> entityRemoved;
7370
};
7471

7572
class CAGE_CORE_API Entity : private Immovable

sources/libcore/entities.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ namespace cage
342342
ComponentImpl *ci = (ComponentImpl *)component;
343343
if (impl->comp(ci->definitionIndex) == nullptr)
344344
return;
345-
ci->entityRemoved.dispatch(this);
346345
ci->componentEntities.erase(this);
347346
ci->desVal(impl->comp(ci->definitionIndex));
348347
impl->comp(ci->definitionIndex) = nullptr;
@@ -379,7 +378,6 @@ namespace cage
379378
c = ci->newVal();
380379
detail::memcpy(c, +ci->prototype, ci->typeSize);
381380
ci->componentEntities.insert(this);
382-
ci->entityAdded.dispatch(this);
383381
}
384382
return c;
385383
}

sources/libengine/gui/gui.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ namespace cage
3232

3333
memory = newMemoryAllocatorStream({});
3434

35-
ttRemovedListener.attach(entityMgr->component<GuiTooltipMarkerComponent>()->entityRemoved);
36-
ttRemovedListener.bind([this](Entity *e) { return this->tooltipRemoved(e); });
35+
ttRemovedListener.attach(entityMgr->entityRemoved);
36+
ttRemovedListener.bind(
37+
[this](Entity *e)
38+
{
39+
if (e->has<GuiTooltipMarkerComponent>())
40+
return this->tooltipRemoved(e);
41+
});
3742
}
3843

3944
GuiImpl::~GuiImpl()

sources/test-core/entities.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,13 @@ namespace
164164
addListener.bind([&](Entity *) { added++; });
165165
removeListener.bind([&](Entity *) { removed++; });
166166
}
167-
} manCbs, posCbs, oriCbs;
167+
} manCbs;
168168

169169
Holder<EntityManager> man = newEntityManager();
170170
manCbs.addListener.attach(man->entityAdded);
171171
manCbs.removeListener.attach(man->entityRemoved);
172-
173172
EntityComponent *pos = man->defineComponent(Vec3());
174-
posCbs.addListener.attach(pos->entityAdded);
175-
posCbs.removeListener.attach(pos->entityRemoved);
176-
177173
EntityComponent *ori = man->defineComponent(Quat());
178-
oriCbs.addListener.attach(ori->entityAdded);
179-
oriCbs.removeListener.attach(ori->entityRemoved);
180174

181175
for (uint32 i = 0; i < 100; i++)
182176
{
@@ -189,19 +183,11 @@ namespace
189183

190184
CAGE_TEST(manCbs.added == 100);
191185
CAGE_TEST(manCbs.removed == 0);
192-
CAGE_TEST(posCbs.added == 34);
193-
CAGE_TEST(posCbs.removed == 0);
194-
CAGE_TEST(oriCbs.added == 20);
195-
CAGE_TEST(oriCbs.removed == 0);
196186

197187
ori->destroy();
198188

199189
CAGE_TEST(manCbs.added == 100);
200190
CAGE_TEST(manCbs.removed == 20);
201-
CAGE_TEST(posCbs.added == 34);
202-
CAGE_TEST(posCbs.removed == 7);
203-
CAGE_TEST(oriCbs.added == 20);
204-
CAGE_TEST(oriCbs.removed == 20);
205191
}
206192

207193
void randomizedTests()

0 commit comments

Comments
 (0)