Move in bigger hops while dragging

This commit is contained in:
Pyrex 2022-12-17 13:52:37 -08:00
parent 29d86556ca
commit 770b952fe4

View File

@ -586,7 +586,6 @@ function rope:_make_consistent()
)
if #self.latch.rec.todo==0 then
self:_tidy_up_gen()
for i=0,#self.ancs do
local a0=self:_anc(i)
local a1=self:_anc(i+1)
@ -676,23 +675,25 @@ function rope:drag(
i,x,y
)
local anc=self:_anc(i())
for x,y in self:_rast(
anc.x,anc.y,x,y
local busy=self:busy()
for x,y in self:_rastn(
anc.x,anc.y,x,y,2,2
) do
local a=self:_anc(i())
if not (_point_eq(a,{x=x,y=y})) then
a.x=x
a.y=y
a.dirty=true
self:_tidy_up_gen()
self.dirty=true
if (not busy) self:_tidy_up_gen()
end
end
end
function rope:_tidy_up_gen()
if (self:busy()) return
if (self.under_destruction) return
if (not self.dirty) return
local settled=true
local touched={}
@ -744,13 +745,13 @@ function rope:_tidy_up_gen()
for a=0,#self.ancs+1,1 do
local anc=self:_anc(a)
if anc.seen then
anc.dirty=anc.changed
end
if (anc.seen) anc.dirty=anc.changed
end
if (settled) break
end
self.dirty=false
end
function rope:_find_needed_anchors(i)
@ -861,7 +862,7 @@ function rope:_can_move_midpoint(a0,a1_0,a1_1,a2)
if not self:_can_stretch(a1_1,a2) then
return false
end
for x,y in self:_rastm(a1_0.x,a1_0.y,a1_1.x,a1_1.y) do
for x,y in self:_rastn(a1_0.x,a1_0.y,a1_1.x,a1_1.y,8,8) do
local tm={x=x,y=y}
if not self:_can_stretch(a0,tm) then
return false
@ -936,7 +937,7 @@ function rope:_can_stretch(
if (level:pcoll(p2.x,p2.y)) return false
local res=true
for x,y in self:_rastm(p1.x,p1.y,p2.x,p2.y) do
for x,y in self:_rastn(p1.x,p1.y,p2.x,p2.y,8,8) do
if level:pcoll(x,y) then
res=false
break
@ -946,8 +947,8 @@ function rope:_can_stretch(
return res
end
function rope:_rastm(
x0,y0,x1,y1
function rope:_rastn(
x0,y0,x1,y1,dx,dy
)
-- todo: more optimized implementation?
local iter=self:_rast(x0,y0,x1,y1)
@ -960,8 +961,8 @@ function rope:_rastm(
if (x==nil) done=true return x1, y1
local x8 = x\8
local y8 = y\8
local x8 = x\dx
local y8 = y\dy
if not (x8==prevx and y8==prevy) then
prevx,prevy=x8,y8
return x,y
@ -1080,6 +1081,7 @@ function rope:_tug()
if force or not level:pcoll(x,y) then
s.x=x
s.y=y
self.dirty=true
end
return true
end}
@ -1132,6 +1134,8 @@ function rope:_tug()
mx0,my0,
dmx,dmy
)
-- be busy for 4 ticks while the crate moves
self:_anc(0).todo={{},{},{},{}}
end
end
end