diff --git a/README.md b/README.md index 66af64c..6248ec3 100644 --- a/README.md +++ b/README.md @@ -47,5 +47,9 @@ assert(world:get(opponentId, Health) == 92) ``` 125 archetypes, 4 random components queried. -![Comparison](image-3.png) -Can be found under /benches/query.lua \ No newline at end of file +![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 \ No newline at end of file diff --git a/image-4.png b/image-4.png new file mode 100644 index 0000000..2c739cf Binary files /dev/null and b/image-4.png differ diff --git a/lib/init.lua b/lib/init.lua index 410cb72..c1b74a3 100644 --- a/lib/init.lua +++ b/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