mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Merge with main
This commit is contained in:
commit
219d0e08c4
1 changed files with 38 additions and 34 deletions
|
@ -777,16 +777,12 @@ local function diff(a, b)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local ChangeTracker: <T>(world: World, component: Entity<T>) -> Tracker<T>
|
local function ChangeTracker<T>(world, T: Entity<T>): Tracker<T>
|
||||||
|
local PreviousT = jecs.pair(jecs.Rest, T)
|
||||||
do
|
local add = {}
|
||||||
local world
|
|
||||||
local T
|
|
||||||
local PreviousT
|
|
||||||
local add
|
|
||||||
local is_trivial
|
|
||||||
local added
|
local added
|
||||||
local removed
|
local removed
|
||||||
|
local is_trivial
|
||||||
|
|
||||||
local function changes_added()
|
local function changes_added()
|
||||||
added = true
|
added = true
|
||||||
|
@ -797,16 +793,7 @@ do
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_trivial == nil then
|
is_trivial = typeof(data) ~= "table"
|
||||||
is_trivial = typeof(data) ~= "table"
|
|
||||||
<<<<<<< HEAD
|
|
||||||
end
|
|
||||||
|
|
||||||
if not is_trivial then
|
|
||||||
data = table.clone(data)
|
|
||||||
=======
|
|
||||||
>>>>>>> af8e15ef45d312ac36eb925a41d05863d707bbfe
|
|
||||||
end
|
|
||||||
|
|
||||||
add[id] = data
|
add[id] = data
|
||||||
|
|
||||||
|
@ -824,12 +811,11 @@ do
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_trivial and new ~= old then
|
if not is_trivial then
|
||||||
<<<<<<< HEAD
|
if diff(new, old) then
|
||||||
=======
|
break
|
||||||
break
|
end
|
||||||
>>>>>>> af8e15ef45d312ac36eb925a41d05863d707bbfe
|
elseif new ~= old then
|
||||||
elseif diff(new, old) then
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -884,17 +870,8 @@ do
|
||||||
|
|
||||||
local tracker = { track = track }
|
local tracker = { track = track }
|
||||||
|
|
||||||
function ChangeTracker<T>(worldToTrack, component: Entity<T>): Tracker<T>
|
return tracker
|
||||||
world = worldToTrack
|
|
||||||
T = component
|
|
||||||
-- We just use jecs.Rest because people will probably not use it anyways
|
|
||||||
PreviousT = jecs.pair(jecs.Rest, T)
|
|
||||||
add = {}
|
|
||||||
|
|
||||||
return tracker
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
TEST("changetracker:track()", function()
|
TEST("changetracker:track()", function()
|
||||||
local world = jecs.World.new()
|
local world = jecs.World.new()
|
||||||
|
|
||||||
|
@ -978,6 +955,33 @@ TEST("changetracker:track()", function()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "multiple change trackers"
|
||||||
|
local A = world:component()
|
||||||
|
local B = world:component()
|
||||||
|
local trackerA = ChangeTracker(world, A)
|
||||||
|
local trackerB = ChangeTracker(world, B)
|
||||||
|
|
||||||
|
local e1 = world:entity()
|
||||||
|
world:set(e1, A, "a1")
|
||||||
|
local e2 = world:entity()
|
||||||
|
world:set(e2, B, "b1")
|
||||||
|
|
||||||
|
trackerA.track(function() end)
|
||||||
|
trackerB.track(function() end)
|
||||||
|
|
||||||
|
world:set(e2, B, "b2")
|
||||||
|
trackerA.track(function(changes)
|
||||||
|
for _, old, new in changes.changed() do
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
trackerB.track(function(changes)
|
||||||
|
for _, old, new in changes.changed() do
|
||||||
|
CHECK(new == "b2")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
FINISH()
|
FINISH()
|
||||||
|
|
Loading…
Reference in a new issue