Sorta working

This commit is contained in:
Pyrex 2022-12-18 15:18:07 -08:00
parent 581e345e31
commit 97e580e7db

View File

@ -760,6 +760,7 @@ function rope:new(
ancs={}, ancs={},
dst={x=x,y=y,todo={}}, dst={x=x,y=y,todo={}},
state={name="cast",dx=dx,dy=dy}, state={name="cast",dx=dx,dy=dy},
dirty=true,
latch=nil, latch=nil,
latch_frame=0, latch_frame=0,
} }
@ -783,6 +784,14 @@ function rope:busy()
end end
function rope:update() function rope:update()
local was_busy=self:busy()
for i=0,#self.ancs+1 do
local anc=self:_anc(i)
_apply(anc,anc.todo,i)
end
local is_busy=self:busy()
if (was_busy and not is_busy) self.dirty=true
if self.state.name=="cast" then if self.state.name=="cast" then
self:continue_cast() self:continue_cast()
elseif self.state.name=="latched" then elseif self.state.name=="latched" then
@ -791,7 +800,7 @@ function rope:update()
self.latch_frame=10 self.latch_frame=10
end end
self:_make_consistent() if (not is_busy) self:_make_consistent()
elseif self.state.name=="destroy" then -- destroy elseif self.state.name=="destroy" then -- destroy
self.state.frame+=1 self.state.frame+=1
if (self.state.frame>=5) self.state={name="done"} if (self.state.frame>=5) self.state={name="done"}
@ -806,15 +815,8 @@ function rope:destroy()
end end
function rope:_make_consistent() function rope:_make_consistent()
for i=0,#self.ancs+1 do
local anc=self:_anc(i)
_apply(anc,anc.todo,i)
end
if (self.latch==nil) self:destroy() return if (self.latch==nil) self:destroy() return
self:_tidy_up_gen()
if if
self.latch!=nil and self.latch!=nil and
self.latch.rec!=nil self.latch.rec!=nil
@ -830,24 +832,14 @@ function rope:_make_consistent()
end end
end end
end end
local invalid=false self:_tidy_up_gen()
for i=0,#self.ancs do for i=0,#self.ancs do
local a0=self:_anc(i) local a0=self:_anc(i)
local a1=self:_anc(i+1) local a1=self:_anc(i+1)
if not self:_can_stretch(a0,a1) then if not self:_can_stretch(a0,a1) then
invalid=true self:destroy()
break
end end
end end
if (invalid) self:make_dirty() self:_tidy_up_gen()
for i=0,#self.ancs do
local a0=self:_anc(i)
local a1=self:_anc(i+1)
if not self:_can_stretch(a0,a1) then
self:_destroy()
end
end
end end
function rope:continue_cast() function rope:continue_cast()
@ -926,6 +918,9 @@ function rope:draw()
for _,p in pairs(level._anch) do for _,p in pairs(level._anch) do
pset(p.x,p.y,11) pset(p.x,p.y,11)
end end
print("dirty:"..tostr(self.dirty),32,0,9)
print("busy:"..tostr(self:busy()),32,7,9)
print("state:"..tostr(self.state.name),32,14,9)
if self.all_ops!=nil then if self.all_ops!=nil then
for i,o in ipairs(self.all_ops) do for i,o in ipairs(self.all_ops) do
rect(o.mx*8,o.my*8,o.mx*8+7,o.my*8+7,4) rect(o.mx*8,o.my*8,o.mx*8+7,o.my*8+7,4)
@ -976,6 +971,17 @@ function rope:make_dirty()
end end
function rope:_tidy_up_gen() function rope:_tidy_up_gen()
local invalid=false
for i=0,#self.ancs do
local a0=self:_anc(i)
local a1=self:_anc(i+1)
if not self:_can_stretch(a0,a1) then
invalid=true
break
end
end
if (invalid) self:make_dirty()
if (not self:latched()) return if (not self:latched()) return
if (not self.dirty) return if (not self.dirty) return