lib/baku/entity_manager.rb in baku-0.2.3 vs lib/baku/entity_manager.rb in baku-0.2.4

- old
+ new

@@ -7,10 +7,15 @@ def initialize @entities_by_component_mask = {} @entities_by_tag = {} end + def dispose + @entities_by_component_mask.clear + @entities_by_tag.clear + end + def register_component_mask(component_mask) @entities_by_component_mask[component_mask] = [] end def add_entity(entity) @@ -43,16 +48,16 @@ end end end def get_entities(component_mask) - @entities_by_component_mask[component_mask] + @entities_by_component_mask[component_mask] || [] end def get_entities_by_tag(tag) - @entities_by_tag[tag] + @entities_by_tag[tag] || [] end - + private def add_entity_to_matching_component_lists(entity) @entities_by_component_mask.each do |component_mask, entities| component_mask_match = component_mask.matches?(entity.component_mask)