tinyecs 0.5.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyecs
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: The teeniest, tiniest ECS system
5
5
  Author-email: Michael Lamertz <michael.lamertz@gmail.com>
6
6
  License-Expression: MIT
@@ -21,11 +21,8 @@ Provides-Extra: patternengine
21
21
  Requires-Dist: tinyecs-compsys-patternengine; extra == "patternengine"
22
22
  Provides-Extra: sdl2
23
23
  Requires-Dist: tinyecs-compsys-sdl2; extra == "sdl2"
24
- Provides-Extra: demos
25
- Requires-Dist: tinyecs[base,dynamics,sdl2]; extra == "demos"
26
- Requires-Dist: tinyecs-demos; extra == "demos"
27
24
  Provides-Extra: all
28
- Requires-Dist: tinyecs[base,demos,dynamics,patternengine,sdl2]; extra == "all"
25
+ Requires-Dist: tinyecs[base,dynamics,patternengine,sdl2]; extra == "all"
29
26
  Dynamic: license-file
30
27
 
31
28
  Introduction
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "tinyecs"
3
3
  description = "The teeniest, tiniest ECS system"
4
- version = "0.5.0"
4
+ version = "0.5.2"
5
5
  readme = "README.rst"
6
6
 
7
7
  authors = [
@@ -25,11 +25,7 @@ base = ["tinyecs-compsys-base"]
25
25
  dynamics = ["tinyecs-compsys-dynamics"]
26
26
  patternengine = ["tinyecs-compsys-patternengine"]
27
27
  sdl2 = ["tinyecs-compsys-sdl2"]
28
- demos = [
29
- "tinyecs[base,dynamics,sdl2]",
30
- "tinyecs-demos",
31
- ]
32
- all = ["tinyecs[base,dynamics,sdl2,patternengine,demos]"]
28
+ all = ["tinyecs[base,dynamics,sdl2,patternengine]"]
33
29
 
34
30
  [project.urls]
35
31
  homepage = "https://github.com/dickerdackel/tinyecs"
@@ -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(set) # object index
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
- oidx[old_comp_id].discard(eid)
238
- if not oidx[old_comp_id]:
239
- del oidx[old_comp_id]
240
- if hasattr(old_comp, 'shutdown_'):
241
- old_comp.shutdown_()
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)].add(eid)
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
- else:
295
- if hasattr(obj, 'shutdown_'):
296
- obj.shutdown_()
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.get(id(comp), set())
519
+ return [_[0] for _ in oidx[id(comp)]]
509
520
 
510
521
 
511
522
  def cid_of_comp(eid: EntityID, comp: Component) -> ComponentID:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinyecs
3
- Version: 0.5.0
3
+ Version: 0.5.2
4
4
  Summary: The teeniest, tiniest ECS system
5
5
  Author-email: Michael Lamertz <michael.lamertz@gmail.com>
6
6
  License-Expression: MIT
@@ -21,11 +21,8 @@ Provides-Extra: patternengine
21
21
  Requires-Dist: tinyecs-compsys-patternengine; extra == "patternengine"
22
22
  Provides-Extra: sdl2
23
23
  Requires-Dist: tinyecs-compsys-sdl2; extra == "sdl2"
24
- Provides-Extra: demos
25
- Requires-Dist: tinyecs[base,dynamics,sdl2]; extra == "demos"
26
- Requires-Dist: tinyecs-demos; extra == "demos"
27
24
  Provides-Extra: all
28
- Requires-Dist: tinyecs[base,demos,dynamics,patternengine,sdl2]; extra == "all"
25
+ Requires-Dist: tinyecs[base,dynamics,patternengine,sdl2]; extra == "all"
29
26
  Dynamic: license-file
30
27
 
31
28
  Introduction
@@ -1,14 +1,10 @@
1
1
 
2
2
  [all]
3
- tinyecs[base,demos,dynamics,patternengine,sdl2]
3
+ tinyecs[base,dynamics,patternengine,sdl2]
4
4
 
5
5
  [base]
6
6
  tinyecs-compsys-base
7
7
 
8
- [demos]
9
- tinyecs[base,dynamics,sdl2]
10
- tinyecs-demos
11
-
12
8
  [dynamics]
13
9
  tinyecs-compsys-dynamics
14
10
 
@@ -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) == {e1}
253
- assert ecs.oidx[oid] == {e1}
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) == {e1, e2}
257
- assert ecs.oidx[oid] == {e1, e2}
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) == {e2}
261
- assert ecs.oidx[oid] == {e2}
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 HasShutdown(Exception): ...
341
+ class ShutdownComp():
342
+ shutdown_called = False
342
343
 
343
- class ShutdownEntity():
344
344
  def shutdown_(self):
345
- raise HasShutdown()
345
+ self.shutdown_called = True
346
346
 
347
347
  eid = ecs.create_entity()
348
- ecs.add_component(eid, 'shutdown-test', ShutdownEntity())
349
- with pytest.raises(HasShutdown) as e:
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
- with pytest.raises(HasShutdown) as e:
354
- ecs.remove_entity(eid)
355
- assert e.type == HasShutdown
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