microecs 0.2.1__tar.gz → 0.2.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.
- {microecs-0.2.1 → microecs-0.2.2}/PKG-INFO +1 -1
- {microecs-0.2.1 → microecs-0.2.2}/microecs/query_result.py +6 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/world.py +12 -3
- {microecs-0.2.1 → microecs-0.2.2}/microecs.egg-info/PKG-INFO +1 -1
- {microecs-0.2.1 → microecs-0.2.2}/setup.py +1 -1
- {microecs-0.2.1 → microecs-0.2.2}/LICENSE.TXT +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/README.md +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/__init__.py +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/component.py +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/pool.py +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/system.py +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs/utils.py +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs.egg-info/SOURCES.txt +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs.egg-info/dependency_links.txt +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs.egg-info/requires.txt +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/microecs.egg-info/top_level.txt +0 -0
- {microecs-0.2.1 → microecs-0.2.2}/setup.cfg +0 -0
|
@@ -101,6 +101,12 @@ class QueryResult:
|
|
|
101
101
|
return _Field(data[name] or [np.empty((0, *self._field_shapes[name]), self._field_dtypes[name])])
|
|
102
102
|
raise AttributeError(name)
|
|
103
103
|
|
|
104
|
+
def __setattr__(self, name, value):
|
|
105
|
+
if (data := self.__dict__.get("_data")) is not None and name in data:
|
|
106
|
+
getattr(self, name)[:] = value # recarray semantics: assigning a field scatters into it
|
|
107
|
+
return
|
|
108
|
+
super().__setattr__(name, value)
|
|
109
|
+
|
|
104
110
|
def __len__(self):
|
|
105
111
|
return self._len
|
|
106
112
|
|
|
@@ -30,6 +30,7 @@ class World:
|
|
|
30
30
|
self._live_ids: set[EntityId] = set() # 'eager' mode ids so e.g. calling remove_entity twice before update fails
|
|
31
31
|
# command buffer management. {add/remove}_{entity/component} are lazy. Taken into account after update().
|
|
32
32
|
self._command_buffer: list[Callable] = []
|
|
33
|
+
self._cache: dict[PoolKey, QueryResult] = {}
|
|
33
34
|
logger.debug(f"Created scene with components: {self.component_names}")
|
|
34
35
|
|
|
35
36
|
# public api
|
|
@@ -38,7 +39,10 @@ class World:
|
|
|
38
39
|
"""commits the underlying pool changes from the systems between two updates. Should be called in main loop."""
|
|
39
40
|
for fn in self._command_buffer:
|
|
40
41
|
fn()
|
|
41
|
-
|
|
42
|
+
|
|
43
|
+
if len(self._command_buffer) > 0:
|
|
44
|
+
self._command_buffer.clear()
|
|
45
|
+
self._cache.clear()
|
|
42
46
|
|
|
43
47
|
def add_entity(self, components: list[ComponentType], **kwargs) -> EntityId:
|
|
44
48
|
"""Adds an entity to the world based on components (data->kwargs). Returns an entity id. Lazy; call update()"""
|
|
@@ -77,7 +81,10 @@ class World:
|
|
|
77
81
|
|
|
78
82
|
def query_and(self, component_types: list[ComponentType]) -> QueryResult:
|
|
79
83
|
"""returns A QueryResult object with the entities that have all the requested components (entity ids too)."""
|
|
80
|
-
|
|
84
|
+
# Note: we can cache the queries. The only time it can get invalidated (via public API) is at update().
|
|
85
|
+
if (key := self._make_key(component_types)) in self._cache:
|
|
86
|
+
return self._cache[key]
|
|
87
|
+
|
|
81
88
|
res = []
|
|
82
89
|
for archetype_key, archetype_pool in self.pools.items():
|
|
83
90
|
if (archetype_key & key) == key: # key is subset of archetype_key
|
|
@@ -87,7 +94,9 @@ class World:
|
|
|
87
94
|
field_shapes = dict(zip(field_names, sum([self.component_to_shapes[c] for c in component_types], [])))
|
|
88
95
|
field_dtypes = dict(zip(field_names, sum([self.component_to_dtypes[c] for c in component_types], [])))
|
|
89
96
|
entity_ids = np.array(sum((self._pool_ids[p] for p in res), []), dtype="int64")
|
|
90
|
-
|
|
97
|
+
|
|
98
|
+
self._cache[key] = QueryResult(res, field_shapes=field_shapes, field_dtypes=field_dtypes, entity_ids=entity_ids)
|
|
99
|
+
return self._cache[key]
|
|
91
100
|
|
|
92
101
|
# private stuff
|
|
93
102
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|