mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
perf: batch springs
This commit is contained in:
parent
e115372e6b
commit
6ce4d25081
1 changed files with 25 additions and 22 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
local batch = require "./batch"
|
||||||
local graph = require "./graph"
|
local graph = require "./graph"
|
||||||
type Node<T> = graph.Node<T>
|
type Node<T> = graph.Node<T>
|
||||||
type SourceNode<T> = graph.SourceNode<T>
|
type SourceNode<T> = graph.SourceNode<T>
|
||||||
|
|
@ -263,31 +264,33 @@ local function step_springs(dt: number)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_spring_sources()
|
local function update_spring_sources()
|
||||||
for data, output in springs do
|
graph.bump_update_id()
|
||||||
local x0_123, x1_123, v_123,
|
batch(function()
|
||||||
x0_456, x1_456, v_456 =
|
for data, output in springs do
|
||||||
data.x0_123, data.x1_123, data.v_123,
|
local x0_123, x1_123, v_123,
|
||||||
data.x0_456, data.x1_456, data.v_456
|
x0_456, x1_456, v_456 =
|
||||||
|
data.x0_123, data.x1_123, data.v_123,
|
||||||
|
data.x0_456, data.x1_456, data.v_456
|
||||||
|
|
||||||
local max_difference = vector.max(
|
local max_difference = vector.max(
|
||||||
vector.abs(x0_123 - x1_123 :: any),
|
vector.abs(x0_123 - x1_123 :: any),
|
||||||
vector.abs(x0_456 - x1_456 :: any),
|
vector.abs(x0_456 - x1_456 :: any),
|
||||||
vector.abs(v_123 :: any),
|
vector.abs(v_123 :: any),
|
||||||
vector.abs(v_456 :: any),
|
vector.abs(v_456 :: any),
|
||||||
TOLERANCE_VECTOR
|
TOLERANCE_VECTOR
|
||||||
)
|
)
|
||||||
|
|
||||||
if max_difference == TOLERANCE_VECTOR then
|
if max_difference == TOLERANCE_VECTOR then
|
||||||
-- close enough to target, unshedule spring and set value to target
|
-- close enough to target, unshedule spring and set value to target
|
||||||
springs[data] = nil
|
springs[data] = nil
|
||||||
output.cache = data.source_value
|
output.cache = data.source_value
|
||||||
else
|
else
|
||||||
output.cache = vec6_to_type[typeof(data.source_value)](x0_123, x0_456)
|
output.cache = vec6_to_type[typeof(data.source_value)](x0_123, x0_456)
|
||||||
|
end
|
||||||
|
|
||||||
|
update_descendants(output)
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
graph.bump_update_id()
|
|
||||||
update_descendants(output)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return function()
|
return function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue