Skip to content

Commit

Permalink
Modify example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Feb 5, 2025
1 parent 44534b7 commit 1937529
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 19 additions & 14 deletions demo/src/StarterPlayer/StarterPlayerScripts/systems/move.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,32 @@ local cts = require(std.components)
local Model = cts.Model
local Transform = cts.Transform

local moving_models = world:query(Transform, Model):cached()
local moved_models = world:query(Model, Transform):cached()
local updated_models = {}
local i = 0
local function processed(n)
i += 1
if i > n then
i = 0
return true
end
return false
end

local function move(dt: number)
for _, transform, model in moving_models do
local cf = transform.new
if cf ~= transform.old then
local part = model.PrimaryPart :: BasePart
local origo = part.CFrame
part.CFrame = origo:Lerp(cf, 1)
transform.old = cf
for entity, model in moved_models do
if updated_models[entity] then
updated_models[entity] = nil
model.PrimaryPart.CFrame = transform
end
end
end

local function syncTransforms()
for _, id, cf in blink.UpdateTransform.Iter() do
local e = ref("server-" .. tostring(id))
local transform = world:get(e, Transform)
if not transform then
continue
end
transform.new = cf
world:set(e, Transform, cf)
moved_models[e] = true
end
end

Expand All @@ -38,4 +43,4 @@ local scheduler = require(std.scheduler)
scheduler.SYSTEM(move)
scheduler.SYSTEM(syncTransforms)

return 0
return 0
3 changes: 2 additions & 1 deletion examples/luau/queries/changetracking.luau
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ local removed = world
:without(Position)
:cached()


local e1 = named(world.entity, "e1")
world:set(e1, Position, vector.create(10, 20, 30))
local e2 = named(world.entity, "e2")
Expand All @@ -39,7 +40,7 @@ end

world:set(e1, Position, vector.create(999, 999, 1998))

for e, new, old in changed do
for _, archetype in changed:archetypes() do
if new ~= old then
print(`{name(e)}'s Position changed from \{{old.x}, {old.y}, {old.z}\} to \{{new.x}, {new.y}, {new.z}\}`)
world:set(e, pair(Previous, Position), new)
Expand Down

0 comments on commit 1937529

Please sign in to comment.