mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Move assertion up
This commit is contained in:
parent
2ace031fa2
commit
ed1f76f9cd
3 changed files with 15 additions and 5 deletions
|
@ -47,5 +47,9 @@ assert(world:get(opponentId, Health) == 92)
|
|||
|
||||
```
|
||||
125 archetypes, 4 random components queried.
|
||||

|
||||
Can be found under /benches/query.lua
|
||||

|
||||
Can be found under /benches/query.lua
|
||||
|
||||
Inserting 8 components to an entity and updating them over 50 times.
|
||||

|
||||
Can be found under /benches/insertions.lua
|
BIN
image-4.png
Normal file
BIN
image-4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 103 KiB |
12
lib/init.lua
12
lib/init.lua
|
@ -272,15 +272,21 @@ function World.set(world: World, entityId: i53, componentId: i53, data: unknown)
|
|||
local sourceArchetype = record.archetype
|
||||
local destinationArchetype = archetypeTraverseAdd(world, componentId, sourceArchetype)
|
||||
|
||||
if sourceArchetype and not (sourceArchetype == destinationArchetype) then
|
||||
if sourceArchetype == destinationArchetype then
|
||||
local archetypeRecord = destinationArchetype.records[componentId]
|
||||
destinationArchetype.columns[archetypeRecord][record.row] = data
|
||||
return
|
||||
end
|
||||
|
||||
if sourceArchetype then
|
||||
moveEntity(world.entityIndex, entityId, record, destinationArchetype)
|
||||
else
|
||||
-- if it has any components, then it wont be the root archetype
|
||||
if #destinationArchetype.types > 0 then
|
||||
newEntity(entityId, record, destinationArchetype)
|
||||
onNotifyAdd(world, destinationArchetype, sourceArchetype, record.row, { componentId })
|
||||
end
|
||||
end
|
||||
|
||||
local archetypeRecord = destinationArchetype.records[componentId]
|
||||
destinationArchetype.columns[archetypeRecord][record.row] = data
|
||||
end
|
||||
|
@ -433,6 +439,7 @@ function World.query(world: World, ...: i53): any
|
|||
end
|
||||
|
||||
local lastRow
|
||||
local queryOutput = {}
|
||||
|
||||
function preparedQuery:__iter()
|
||||
return function()
|
||||
|
@ -502,7 +509,6 @@ function World.query(world: World, ...: i53): any
|
|||
indices[8][row]
|
||||
end
|
||||
|
||||
local queryOutput = {}
|
||||
for i, componentId in components do
|
||||
queryOutput[i] = indices[i][row]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue