tinyecs 0.5.1__tar.gz → 0.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tinyecs-0.5.1/src/tinyecs.egg-info → tinyecs-0.5.2}/PKG-INFO +1 -1
- {tinyecs-0.5.1 → tinyecs-0.5.2}/pyproject.toml +1 -1
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs/__init__.py +28 -17
- {tinyecs-0.5.1 → tinyecs-0.5.2/src/tinyecs.egg-info}/PKG-INFO +1 -1
- {tinyecs-0.5.1 → tinyecs-0.5.2}/tests/test_tinyecs.py +17 -16
- {tinyecs-0.5.1 → tinyecs-0.5.2}/LICENSE +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/README.rst +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/setup.cfg +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs/tutorial.py +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs.egg-info/SOURCES.txt +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs.egg-info/dependency_links.txt +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs.egg-info/requires.txt +0 -0
- {tinyecs-0.5.1 → tinyecs-0.5.2}/src/tinyecs.egg-info/top_level.txt +0 -0
|
@@ -44,7 +44,7 @@ eidx = {} # entity index
|
|
|
44
44
|
cidx = {} # component id index
|
|
45
45
|
sidx = {} # system index
|
|
46
46
|
didx = {} # domain index
|
|
47
|
-
oidx = defaultdict(
|
|
47
|
+
oidx = defaultdict(list) # object index
|
|
48
48
|
plist = defaultdict(set) # entity property lists
|
|
49
49
|
archetype = {}
|
|
50
50
|
|
|
@@ -226,6 +226,8 @@ def add_component(eid: EntityID, cid: ComponentID, comp: Component) -> Component
|
|
|
226
226
|
if cid not in cidx:
|
|
227
227
|
cidx[cid] = {}
|
|
228
228
|
|
|
229
|
+
t = (eid, cid)
|
|
230
|
+
|
|
229
231
|
# Make sure, when replacing a component, the the old one is removed from
|
|
230
232
|
# oidx for this entity.
|
|
231
233
|
try:
|
|
@@ -234,15 +236,19 @@ def add_component(eid: EntityID, cid: ComponentID, comp: Component) -> Component
|
|
|
234
236
|
pass
|
|
235
237
|
else:
|
|
236
238
|
old_comp_id = id(old_comp)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
239
|
+
try:
|
|
240
|
+
oidx[old_comp_id].remove(t)
|
|
241
|
+
except ValueError:
|
|
242
|
+
pass
|
|
243
|
+
else:
|
|
244
|
+
if not oidx[old_comp_id]:
|
|
245
|
+
del oidx[old_comp_id]
|
|
246
|
+
if hasattr(old_comp, 'shutdown_'):
|
|
247
|
+
old_comp.shutdown_()
|
|
242
248
|
|
|
243
249
|
cidx[cid][eid] = comp
|
|
244
250
|
eidx[eid][cid] = comp
|
|
245
|
-
oidx[id(comp)].
|
|
251
|
+
oidx[id(comp)].append(t)
|
|
246
252
|
|
|
247
253
|
add_to_archetype(eid)
|
|
248
254
|
|
|
@@ -283,17 +289,22 @@ def remove_component(eid: EntityID, *cids: ComponentID) -> None:
|
|
|
283
289
|
# Also, no need to try each on their own
|
|
284
290
|
try:
|
|
285
291
|
obj = cidx[cid][eid]
|
|
286
|
-
obj_id = id(obj)
|
|
287
|
-
del cidx[cid][eid]
|
|
288
|
-
del eidx[eid][cid]
|
|
289
|
-
oidx[obj_id].discard(eid)
|
|
290
|
-
if not oidx[obj_id]:
|
|
291
|
-
del oidx[id(obj)]
|
|
292
292
|
except KeyError:
|
|
293
|
+
continue
|
|
294
|
+
|
|
295
|
+
obj_id = id(obj)
|
|
296
|
+
del cidx[cid][eid]
|
|
297
|
+
del eidx[eid][cid]
|
|
298
|
+
try:
|
|
299
|
+
oidx[obj_id].remove((eid, cid))
|
|
300
|
+
except ValueError:
|
|
293
301
|
pass
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
302
|
+
|
|
303
|
+
if not oidx[obj_id]:
|
|
304
|
+
del oidx[id(obj)]
|
|
305
|
+
|
|
306
|
+
if hasattr(obj, 'shutdown_'):
|
|
307
|
+
obj.shutdown_()
|
|
297
308
|
|
|
298
309
|
|
|
299
310
|
def add_system(fn: SystemFunction, *cids: ComponentID) -> None:
|
|
@@ -505,7 +516,7 @@ def eid_of_comp(comp: Component) -> set[EntityID]:
|
|
|
505
516
|
:return: A set of all entity IDs that contain the given component.
|
|
506
517
|
"""
|
|
507
518
|
|
|
508
|
-
return oidx
|
|
519
|
+
return [_[0] for _ in oidx[id(comp)]]
|
|
509
520
|
|
|
510
521
|
|
|
511
522
|
def cid_of_comp(eid: EntityID, comp: Component) -> ComponentID:
|
|
@@ -249,16 +249,16 @@ def test_eid_of_comp():
|
|
|
249
249
|
oid = id(shared)
|
|
250
250
|
|
|
251
251
|
ecs.add_component(e1, 'shared', shared)
|
|
252
|
-
assert ecs.eid_of_comp(shared) ==
|
|
253
|
-
assert ecs.oidx[oid] ==
|
|
252
|
+
assert ecs.eid_of_comp(shared) == [e1]
|
|
253
|
+
assert ecs.oidx[oid] == [(e1, 'shared')]
|
|
254
254
|
|
|
255
255
|
ecs.add_component(e2, 'shared', shared)
|
|
256
|
-
assert ecs.eid_of_comp(shared) ==
|
|
257
|
-
assert ecs.oidx[oid] ==
|
|
256
|
+
assert ecs.eid_of_comp(shared) == [e1, e2]
|
|
257
|
+
assert ecs.oidx[oid] == [(e1, 'shared'), (e2, 'shared')]
|
|
258
258
|
|
|
259
259
|
ecs.remove_component(e1, 'shared')
|
|
260
|
-
assert ecs.eid_of_comp(shared) ==
|
|
261
|
-
assert ecs.oidx[oid] ==
|
|
260
|
+
assert ecs.eid_of_comp(shared) == [e2]
|
|
261
|
+
assert ecs.oidx[oid] == [(e2, 'shared')]
|
|
262
262
|
|
|
263
263
|
ecs.remove_component(e2, 'shared')
|
|
264
264
|
assert oid not in ecs.oidx
|
|
@@ -338,21 +338,22 @@ def test_eid_has():
|
|
|
338
338
|
def test_shutdown():
|
|
339
339
|
ecs.reset()
|
|
340
340
|
|
|
341
|
-
class
|
|
341
|
+
class ShutdownComp():
|
|
342
|
+
shutdown_called = False
|
|
342
343
|
|
|
343
|
-
class ShutdownEntity():
|
|
344
344
|
def shutdown_(self):
|
|
345
|
-
|
|
345
|
+
self.shutdown_called = True
|
|
346
346
|
|
|
347
347
|
eid = ecs.create_entity()
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
ecs.add_component(eid, 'shutdown-test', ShutdownEntity())
|
|
351
|
-
assert e.type == HasShutdown
|
|
348
|
+
comp_with_shutdown = ShutdownComp()
|
|
349
|
+
ecs.add_component(eid, 'shutdown-test', comp_with_shutdown)
|
|
352
350
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
assert
|
|
351
|
+
new_comp_with_shutdown = ShutdownComp()
|
|
352
|
+
ecs.add_component(eid, 'shutdown-test', new_comp_with_shutdown)
|
|
353
|
+
assert comp_with_shutdown.shutdown_called
|
|
354
|
+
|
|
355
|
+
ecs.remove_entity(eid)
|
|
356
|
+
assert new_comp_with_shutdown.shutdown_called
|
|
356
357
|
|
|
357
358
|
|
|
358
359
|
def test_cid_of_comp():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|