paths sort of work but not really

figure out why they do not show the expected patterns
This commit is contained in:
2025-07-06 20:02:21 -07:00
parent 6efd05febe
commit 10aef3b1ed

View File

@ -686,21 +686,21 @@ segment = mknew{
-- dest_x, dest_y: stored
-- current destination to
-- figure out approach/depart
-- [1..n]: destinations
-- dests[1..n]: destinations
init = function(x)
x.init = segment.reset
mknew(x)
if not x.mirror then
local mirrored = {mirror=x, init=segment.reset}
for i, v in ipairs(x) do
mirrored[i] = destination.new{
local mdests = {}
for i, v in ipairs(x.dests) do
mdests[i] = destination.new{
anchor_frac=v.anchor_frac,
accel_frac=v.accel_frac,
x_off_frac=-v.x_off_frac,
y_off_frac=v.y_off_frac,
}
end
x.mirror = mknew(x.new(mirrored))
x.mirror = mknew(x.new{mirror=x, init=segment.reset, dests=mdests})
end
end
}
@ -714,7 +714,7 @@ function segment:reset()
end
function segment:target_from(fx, fy)
local rx, ry, af = self[self.current_idx]:target_from(fx, fy)
local rx, ry, af = self.dests[self.current_idx]:target_from(fx, fy)
self.dest_x, self.dest_y = rx, ry
return rx, ry, af
end
@ -725,7 +725,8 @@ function segment:update(x, y)
if (rem > 0) rem -= 1
if self:should_step(x, y) then
if self.current_idx == #self then
self.prev_x, self.prev_y = false, false
if self.current_idx == #self.dests then
self.current_idx = self.loop_idx
if (rem < 0) rem += 1
else
@ -760,22 +761,21 @@ end
path = mknew {
loop_idx = 1,
-- [1..n]: destinations
-- segs[1..n]: segments or subpaths
init=function(x)
if not x.mirror then
local mirrored = {
mirror = x,
loop_idx = x.loop_idx,
}
for i, v in ipairs(x) do
mirrored[i]=v.mirror
local msegs = {}
for i, v in ipairs(x.segs) do
msegs[i]=v.mirror
end
x.mirror = path.new(mirrored)
x.mirror = path.new{mirror=x, loop_idx=x.loop_idx, segs=msegs}
end
x.init = function(y)
for i, v in ipairs(x) do
y[i]=v.new{}
local ysegs = {}
for i, v in ipairs(x.segs) do
ysegs[i]=v.new{}
end
y.segs = ysegs
y:reset()
end
mknew(x)
@ -787,13 +787,13 @@ function path:reset()
end
function path:target_from(fx, fy)
return self[self.current_idx]:target_from(fx, fy)
return self.segs[self.current_idx]:target_from(fx, fy)
end
function path:update(x, y)
local idx = self.current_idx
if self[idx]:update(x, y) then
if idx == #self then
if self.segs[idx]:update(x, y) then
if idx == #self.segs then
self.current_idx = self.loop_idx
return true
else
@ -1498,6 +1498,7 @@ ship_f = mknew(ship_m.new{
})
diamond_loop = segment.new{
dests = {
destination.new{
x_off_frac=0.25
}, destination.new{
@ -1507,6 +1508,14 @@ diamond_loop = segment.new{
}, destination.new {
y_off_frac = -0.25
},
},
}
diamond_bounce = path.new{
segs = {
diamond_loop,
diamond_loop.mirror,
},
}
ship_mook = mknew(ship_f.new{
@ -1530,7 +1539,7 @@ ship_skirmisher = mknew(ship_f.new{
fire_off_y = 7,
xmin = -8,
xmax = 112,
path = diamond_loop,
path = diamond_bounce,
})
function ship_skirmisher:reset_bounds()