Skip to content

Commit

Permalink
Merge pull request #242 from SleepProgger/remove_component_fix
Browse files Browse the repository at this point in the history
Ensure the entities component_id for removed components is set to -1
  • Loading branch information
Kovak committed Aug 8, 2017
2 parents af0994c + 6c8c87e commit c48a134
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions modules/core/kivent_core/entity.pyx
Expand Up @@ -53,9 +53,9 @@ cdef class Entity(MemComponent):
system = system_manager[name]
cdef unsigned int* pointer = <unsigned int*>self.pointer
cdef unsigned int component_index = pointer[system_index+1]
if component_index == -1:
if component_index == <unsigned int>-1:
raise NoComponentActiveError(
'Entity {ent_id} have no component'
'Entity {ent_id} has no component '
'active for {system_name}'.format(ent_id=str(self._id),
system_name=name))
return system.components[component_index]
Expand Down
4 changes: 4 additions & 0 deletions modules/core/kivent_core/systems/gamesystem.pyx
Expand Up @@ -281,7 +281,11 @@ cdef class GameSystem(CWidget):
Args:
component_index (unsigned int): the component_id to be removed.
'''
entity = self.py_components[component_index]
cdef unsigned int entity_id = entity.entity_id
self.clear_component(component_index)
cdef EntityManager entity_manager = self.gameworld.entity_manager
entity_manager.set_component(entity_id, -1, self.system_index)
self.py_components[component_index] = None
self.free_indices.append(component_index)

Expand Down
9 changes: 7 additions & 2 deletions modules/core/kivent_core/systems/staticmemgamesystem.pyx
Expand Up @@ -16,7 +16,7 @@ from gamesystem cimport GameSystem
from kivent_core.managers.system_manager cimport SystemManager
from cpython cimport bool
from kivent_core.memory_handlers.utils import memrange

from kivent_core.managers.entity_manager cimport EntityManager


cdef class MemComponent:
Expand Down Expand Up @@ -223,8 +223,13 @@ cdef class StaticMemGameSystem(GameSystem):
Overrides the default behavior of GameSystem, passing data handling
duties to the IndexedMemoryZone. **clear_component** will be called
prior to calling **free_slot** on the MemoryZone.'''
self.clear_component(component_index)
cdef MemoryZone memory_zone = self.imz_components.memory_zone
cdef EntityManager entity_manager = self.gameworld.entity_manager
cdef unsigned int *pointer = <unsigned int*>memory_zone.get_pointer(
component_index)
cdef unsigned int entity_id = pointer[0]
self.clear_component(component_index)
entity_manager.set_component(entity_id, -1, self.system_index)
memory_zone.free_slot(component_index)

def init_component(self, unsigned int component_index,
Expand Down

0 comments on commit c48a134

Please sign in to comment.