Skip to content

Commit

Permalink
monster and aoi
Browse files Browse the repository at this point in the history
  • Loading branch information
liuhaopen committed Apr 8, 2019
1 parent 1cedd61 commit 331f51e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
38 changes: 16 additions & 22 deletions EntityDataManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ function EntityDataManager:Exists( entity )
local index = entity.Index
self:ValidateEntity(entity)
local versionMatches = self.m_Entities.Version[index] == entity.Version
local hasChunk = self.m_Entities.ChunkData[index].Chunk ~= nil
local hasChunk = self.m_Entities.ChunkData[index] and self.m_Entities.ChunkData[index].Chunk ~= nil
return versionMatches and hasChunk
end

function EntityDataManager:AssertEntityHasComponent( entity, com_type_name )
-- if self:HasComponent(entity, componentType) then
-- return
-- end
-- if not self:Exists(entity) then
-- assert(false, "The Entity does not exist")
-- end
-- if self:HasComponent(entity, componentType.TypeIndex) then
-- assert(false, "The component exists on the entity but the exact type {componentType} does not")
if not self:Exists(entity) then
assert(false, "The Entity does not exist")
end
if self:HasComponent(entity, com_type_name) then
return
end
-- if not self:HasComponent(entity, com_type_name) then
-- assert(false, "The component exists on the entity but the exact type {componentType} does not")
-- end
-- assert(false, "component has not been added to the entity.")
assert(false, "component has not been added to the entity.")
end

function EntityDataManager:GetComponentDataWithTypeRO( entity, typeIndex )
Expand Down Expand Up @@ -358,11 +358,6 @@ function EntityDataManager:AllocateEntities( arch, chunk, baseIndex, count, outp
outputEntities[i].Version = entityVersion

ECS.ChunkDataUtility.WriteComponentInChunk(chunk.Buffer + (baseIndex + i - 1)*self.entity_size_in_chunk, ECS.Entity.Name, {Index=self.m_EntitiesFreeIndex, Version=entityVersion})
-- ECSCore.WriteNumber(entityInChunkStart, i+0, self.m_EntitiesFreeIndex)
-- ECSCore.WriteNumber(entityInChunkStart, i+ECS.CoreHelper.GetIntegerSize(), entityVersion)
-- local entityInChunk = entityInChunkStart + i
-- entityInChunk.Index = self.m_EntitiesFreeIndex
-- entityInChunk.Version = entityVersion

self.m_Entities.ChunkData[self.m_EntitiesFreeIndex].IndexInChunk = baseIndex + i - 1
self.m_Entities.Archetype[self.m_EntitiesFreeIndex] = arch
Expand Down Expand Up @@ -397,16 +392,15 @@ function EntityDataManager:SetCapacity( value )
return
end

local newEntities = self:CreateEntityData(value)
CopyEntityData(newEntities, self.m_Entities, self.m_EntitiesCapacity)
self.m_Entities = {}
-- local newEntities = self:CreateEntityData(value)
-- CopyEntityData(newEntities, self.m_Entities, self.m_EntitiesCapacity)
-- self.m_Entities = nil

local startNdx = self.m_EntitiesCapacity - 1
self.m_Entities = newEntities
-- self.m_Entities = newEntities
local startNdx = self.m_EntitiesCapacity
self.m_EntitiesCapacity = value

self:InitializeAdditionalCapacity(startNdx)
self.Capacity = value
-- self.Capacity = value
end

function EntityDataManager:CreateEntityData( newCapacity )
Expand Down
12 changes: 2 additions & 10 deletions EntityManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ end

function EntityManager:SetComponentData( entity, componentTypeName, componentData )
local typeIndex = ECS.TypeManager.GetTypeIndexByName(componentTypeName)
-- self.Entities:AssertEntityHasComponent(entity, typeIndex)
self.Entities:AssertEntityHasComponent(entity, componentTypeName)
-- ComponentJobSafetyManager.CompleteReadAndWriteDependency(typeIndex)
local ptr = self.Entities:GetComponentDataWithTypeRW(entity, typeIndex, self.Entities.GlobalSystemVersion)
ECS.ChunkDataUtility.WriteComponentInChunk(ptr, componentTypeName, componentData)
Expand All @@ -124,7 +124,7 @@ end

function EntityManager:GetComponentData( entity, componentTypeName )
local typeIndex = ECS.TypeManager.GetTypeIndexByName(componentTypeName)
self.Entities:AssertEntityHasComponent(entity, typeIndex)
self.Entities:AssertEntityHasComponent(entity, componentTypeName)
local ptr = self.Entities:GetComponentDataWithTypeRO(entity, typeIndex)
local data = ECS.ChunkDataUtility.ReadComponentFromChunk(ptr, componentTypeName)
return data
Expand Down Expand Up @@ -161,12 +161,4 @@ function EntityManager:GetArchetypeChunkComponentType( comp_type_name, isReadOnl
return ArchetypeChunkComponentType.New(comp_type_name, isReadOnly, self.GlobalSystemVersion)
end

-- local EntityArchetypeQuery = {
-- Any = {}, None = {}, All = {},
-- }

-- local EntityArchetype = {

-- }

return EntityManager
1 change: 1 addition & 0 deletions Tests/TestEntityManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function TestEntityManager:TestIncreaseEntityCapacity( )
local array = self.m_Manager:CreateEntitiesByArcheType(archetype, count)
for i=1,count do
lu.assertEquals(array[i].Index, i)
lu.assertTrue(self.m_Manager:Exists(array[i]))
end
end

Expand Down

0 comments on commit 331f51e

Please sign in to comment.