mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-15 04:15:28 +07:00
optimize some batch_insert/remove cases
This commit is contained in:
@@ -18,3 +18,4 @@
|
||||
- [ ] add batch vector operations
|
||||
- [ ] add inplace vector operations
|
||||
- [x] cache chunk lists in batch operations
|
||||
- [ ] impl compat.move for 5.1 vanilla lua
|
||||
@@ -9,4 +9,8 @@ compat.unpack = table.unpack or function(list, i, j)
|
||||
return unpack(list, i, j)
|
||||
end
|
||||
|
||||
compat.move = table.move or function(a1, f, e, t, a2)
|
||||
error('compat.move is not implemented yet', 2)
|
||||
end
|
||||
|
||||
return compat
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local compat = require 'evolved.compat'
|
||||
local idpools = require 'evolved.idpools'
|
||||
|
||||
---@class evolved.registry
|
||||
@@ -737,7 +738,12 @@ function registry.batch_insert(query, fragment, component)
|
||||
|
||||
for old_f, old_cs in pairs(old_chunk.__components) do
|
||||
local new_cs = new_chunk.__components[old_f]
|
||||
for i = 1, #old_cs do new_cs[#new_cs + 1] = old_cs[i] end
|
||||
|
||||
if #new_cs == 0 then
|
||||
new_chunk.__components[old_f] = old_cs
|
||||
else
|
||||
compat.move(old_cs, 1, #old_cs, #new_cs + 1, new_cs)
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, entity in ipairs(old_chunk.__entities) do
|
||||
@@ -835,7 +841,12 @@ function registry.batch_remove(query, ...)
|
||||
|
||||
for new_f, new_cs in pairs(new_chunk.__components) do
|
||||
local old_cs = old_chunk.__components[new_f]
|
||||
for i = 1, #old_cs do new_cs[#new_cs + 1] = old_cs[i] end
|
||||
|
||||
if #new_cs == 0 then
|
||||
new_chunk.__components[new_f] = old_cs
|
||||
else
|
||||
compat.move(old_cs, 1, #old_cs, #new_cs + 1, new_cs)
|
||||
end
|
||||
end
|
||||
else
|
||||
for _, entity in ipairs(old_chunk.__entities) do
|
||||
|
||||
Reference in New Issue
Block a user