mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 20:11:27 +07:00
multi registry.components
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
local evo = require 'evolved.evolved'
|
||||
|
||||
local v2 = evo.vectors.vector2
|
||||
|
||||
local singles = {
|
||||
delta_time = evo.singles.single(0.016),
|
||||
}
|
||||
@@ -10,25 +12,29 @@ local fragments = {
|
||||
}
|
||||
|
||||
local queries = {
|
||||
bodies = evo.registry.query(fragments.position, fragments.velocity),
|
||||
bodies = evo.registry.query(
|
||||
fragments.position,
|
||||
fragments.velocity),
|
||||
}
|
||||
|
||||
do
|
||||
evo.registry.entity()
|
||||
:set(fragments.position, evo.vectors.vector2(512, 50))
|
||||
:set(fragments.velocity, evo.vectors.vector2(math.random(-20, 20), 20))
|
||||
:set(fragments.position, v2(512, 50))
|
||||
:set(fragments.velocity, v2(math.random(-20, 20), 20))
|
||||
end
|
||||
|
||||
do
|
||||
local dt = evo.singles.get(singles.delta_time)
|
||||
local delta_time = evo.singles.get(singles.delta_time)
|
||||
|
||||
for chunk in queries.bodies:execute() do
|
||||
local es = chunk:entities()
|
||||
local ps = chunk:components(fragments.position)
|
||||
local vs = chunk:components(fragments.velocity)
|
||||
local entities = chunk:entities()
|
||||
|
||||
for i = 1, #es do
|
||||
ps[i] = ps[i] + vs[i] * dt
|
||||
local positions, velocities = chunk:components(
|
||||
fragments.position,
|
||||
fragments.velocity)
|
||||
|
||||
for i = 1, #entities do
|
||||
positions[i] = positions[i] + velocities[i] * delta_time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user