mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2024-11-17 04:44:23 +00:00
Remove world.entityCount and world.entityList.
This commit is contained in:
parent
83d806011b
commit
80bb6b8d31
32
tiny.lua
32
tiny.lua
@ -434,14 +434,9 @@ function tiny.world(...)
|
|||||||
-- Set of Entities
|
-- Set of Entities
|
||||||
entities = {},
|
entities = {},
|
||||||
|
|
||||||
-- List of Entities
|
|
||||||
entityList = {},
|
|
||||||
|
|
||||||
-- Number of Entities in World
|
|
||||||
entityCount = 0,
|
|
||||||
|
|
||||||
-- List of Systems
|
-- List of Systems
|
||||||
systems = {}
|
systems = {}
|
||||||
|
|
||||||
}, worldMetaTable)
|
}, worldMetaTable)
|
||||||
|
|
||||||
tiny_add(ret, ...)
|
tiny_add(ret, ...)
|
||||||
@ -533,7 +528,7 @@ function tiny_manageSystems(world)
|
|||||||
world.systemsToAdd = {}
|
world.systemsToAdd = {}
|
||||||
world.systemsToRemove = {}
|
world.systemsToRemove = {}
|
||||||
|
|
||||||
local worldEntityList = world.entityList
|
local worldEntityList = world.entities
|
||||||
local systems = world.systems
|
local systems = world.systems
|
||||||
|
|
||||||
-- Remove Systems
|
-- Remove Systems
|
||||||
@ -625,19 +620,16 @@ function tiny_manageEntities(world)
|
|||||||
world.entitiesToRemove = {}
|
world.entitiesToRemove = {}
|
||||||
|
|
||||||
local entities = world.entities
|
local entities = world.entities
|
||||||
local entityList = world.entityList
|
|
||||||
local systems = world.systems
|
local systems = world.systems
|
||||||
local entityCount = world.entityCount
|
|
||||||
|
|
||||||
-- Change Entities
|
-- Change Entities
|
||||||
for i = 1, #e2c do
|
for i = 1, #e2c do
|
||||||
local entity = e2c[i]
|
local entity = e2c[i]
|
||||||
-- Add if needed
|
-- Add if needed
|
||||||
if not entities[entity] then
|
if not entities[entity] then
|
||||||
local index = #entityList + 1
|
local index = #entities + 1
|
||||||
entities[entity] = index
|
entities[entity] = index
|
||||||
entityList[index] = entity
|
entities[index] = entity
|
||||||
entityCount = entityCount + 1
|
|
||||||
end
|
end
|
||||||
for j = 1, #systems do
|
for j = 1, #systems do
|
||||||
local system = systems[j]
|
local system = systems[j]
|
||||||
@ -681,12 +673,11 @@ function tiny_manageEntities(world)
|
|||||||
local listIndex = entities[entity]
|
local listIndex = entities[entity]
|
||||||
if listIndex then
|
if listIndex then
|
||||||
-- Remove Entity from world state
|
-- Remove Entity from world state
|
||||||
local lastEntity = entityList[#entityList]
|
local lastEntity = entities[#entities]
|
||||||
entities[lastEntity] = listIndex
|
entities[lastEntity] = listIndex
|
||||||
entities[entity] = nil
|
entities[entity] = nil
|
||||||
entityList[listIndex] = lastEntity
|
entities[listIndex] = lastEntity
|
||||||
entityList[#entityList] = nil
|
entities[#entities] = nil
|
||||||
entityCount = entityCount - 1
|
|
||||||
-- Remove from cached systems
|
-- Remove from cached systems
|
||||||
for j = 1, #systems do
|
for j = 1, #systems do
|
||||||
local system = systems[j]
|
local system = systems[j]
|
||||||
@ -710,9 +701,6 @@ function tiny_manageEntities(world)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update Entity count
|
|
||||||
world.entityCount = entityCount
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Manages Entities and Systems marked for deletion or addition. Call this
|
--- Manages Entities and Systems marked for deletion or addition. Call this
|
||||||
@ -801,7 +789,7 @@ end
|
|||||||
|
|
||||||
--- Removes all Entities from the World.
|
--- Removes all Entities from the World.
|
||||||
function tiny.clearEntities(world)
|
function tiny.clearEntities(world)
|
||||||
local el = world.entityList
|
local el = world.entities
|
||||||
for i = 1, #el do
|
for i = 1, #el do
|
||||||
tiny_removeEntity(world, el[i])
|
tiny_removeEntity(world, el[i])
|
||||||
end
|
end
|
||||||
@ -817,12 +805,12 @@ end
|
|||||||
|
|
||||||
--- Gets number of Entities in the World.
|
--- Gets number of Entities in the World.
|
||||||
function tiny.getEntityCount(world)
|
function tiny.getEntityCount(world)
|
||||||
return world.entityCount
|
return #world.entities
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Gets number of Systems in World.
|
--- Gets number of Systems in World.
|
||||||
function tiny.getSystemCount(world)
|
function tiny.getSystemCount(world)
|
||||||
return #(world.systems)
|
return #world.systems
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Sets the index of a System in the World, and returns the old index. Changes
|
--- Sets the index of a System in the World, and returns the old index. Changes
|
||||||
|
Loading…
Reference in New Issue
Block a user