mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 09:00:02 +00:00
Modify example
This commit is contained in:
parent
44534b7c81
commit
1937529dcb
2 changed files with 21 additions and 15 deletions
|
@ -9,15 +9,23 @@ 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
|
||||
|
@ -25,11 +33,8 @@ 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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue