Move assertion up (#9)

This commit is contained in:
Marcus 2024-04-30 17:52:44 +02:00 committed by GitHub
parent 2ace031fa2
commit 275aa6ec6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View file

@ -47,5 +47,9 @@ assert(world:get(opponentId, Health) == 92)
```
125 archetypes, 4 random components queried.
![Comparison](image-3.png)
![Queries](image-3.png)
Can be found under /benches/query.lua
Inserting 8 components to an entity and updating them over 50 times.
![Insertions](image-4.png)
Can be found under /benches/insertions.lua

BIN
image-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

View file

@ -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