Rewrite rope #11
@ -1056,6 +1056,38 @@ function rope:draw(artificial_dx,artificial_dy)
|
|||||||
rectfill(x,y-1,x-1,y-3,color)
|
rectfill(x,y-1,x-1,y-3,color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local n1=self.src
|
||||||
|
local sy=0
|
||||||
|
while true do
|
||||||
|
if (n1==nil) break
|
||||||
|
local x=n1.ax*8
|
||||||
|
local y=n1.ay*8
|
||||||
|
rectfill(x-1,y-1,x+1,y+1,12)
|
||||||
|
--print("ax="..n1.ax..",ay="..n1.ay,0,sy)
|
||||||
|
sy+=7
|
||||||
|
|
||||||
|
local n0=n1.prev
|
||||||
|
local n2=n1.next
|
||||||
|
if n0!=nil and n2!=nil then
|
||||||
|
if n1.associated_with then
|
||||||
|
local _,_,_,adx,ady=would_stick(n0.ax,n0.ay,n1.associated_with,n2.ax,n2.ay)
|
||||||
|
assert(adx==-1 or adx==0 or adx==1)
|
||||||
|
assert(ady==-1 or ady==0 or ady==1)
|
||||||
|
--assert(not (adx==0 and ady==0))
|
||||||
|
|
||||||
|
rectfill(x+2,y+2,x+4,y+4,3)
|
||||||
|
pset(x+adx*2,y,9)
|
||||||
|
pset(x,y+ady*2,9)
|
||||||
|
else
|
||||||
|
rectfill(x+2,y+2,x+4,y+4,2)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
rectfill(x+2,y+2,x+4,y+4,4)
|
||||||
|
end
|
||||||
|
|
||||||
|
n1=n1.next
|
||||||
|
end
|
||||||
|
|
||||||
for _,p in pairs(level._anch) do
|
for _,p in pairs(level._anch) do
|
||||||
pset(p.ax*8,p.ay*8,11)
|
pset(p.ax*8,p.ay*8,11)
|
||||||
pset(p.ax*8+p.adx,p.ay*8,11)
|
pset(p.ax*8+p.adx,p.ay*8,11)
|
||||||
@ -1063,13 +1095,6 @@ function rope:draw(artificial_dx,artificial_dy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
for i=0,#self.ancs+1 do
|
|
||||||
p=self:_anc(i)
|
|
||||||
local c=12
|
|
||||||
if (p.dirty) c=13
|
|
||||||
rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c)
|
|
||||||
print(tostr(p.id)..":"..p.x..","..p.y..","..#p.todo,0,i*8,12)
|
|
||||||
end
|
|
||||||
print("dirty:"..tostr(self.dirty),32,0,9)
|
print("dirty:"..tostr(self.dirty),32,0,9)
|
||||||
print("busy:"..tostr(self:busy()),32,7,9)
|
print("busy:"..tostr(self:busy()),32,7,9)
|
||||||
print("state:"..tostr(self.state.name),32,14,9)
|
print("state:"..tostr(self.state.name),32,14,9)
|
||||||
@ -1111,6 +1136,22 @@ function rope:_relax()
|
|||||||
local x1,y1=n1.ax,n1.ay
|
local x1,y1=n1.ax,n1.ay
|
||||||
local x2,y2=n2.ax,n2.ay
|
local x2,y2=n2.ax,n2.ay
|
||||||
|
|
||||||
|
local would,x1_new,y1_new=would_stick(x0,y0,n1.associated_with,x2,y2)
|
||||||
|
if not would then
|
||||||
|
self:_drag(n1,x1_new,y1_new)
|
||||||
|
n0=n1.prev
|
||||||
|
n2=n1.next
|
||||||
|
n0.next=n2
|
||||||
|
n2.prev=n0
|
||||||
|
n1.next=nil
|
||||||
|
n1.prev=nil
|
||||||
|
else n0=n0.next end
|
||||||
|
else n0=n0.next end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function would_stick(x0,y0,anchor,x2,y2)
|
||||||
|
local x1,y1=anchor.ax,anchor.ay
|
||||||
if (x0>x2) x0,y0,x2,y2=x2,y2,x0,y0
|
if (x0>x2) x0,y0,x2,y2=x2,y2,x0,y0
|
||||||
|
|
||||||
local dx=x2-x0
|
local dx=x2-x0
|
||||||
@ -1134,17 +1175,7 @@ function rope:_relax()
|
|||||||
if (y0<y2) ady=-adx
|
if (y0<y2) ady=-adx
|
||||||
end
|
end
|
||||||
|
|
||||||
if false and (n1.associated_with.adx==-adx or n1.associated_with.ady==-ady) then
|
return anchor.adx!=-adx and anchor.ady!=-ady,x1_new,y1_new,adx,ady
|
||||||
--self:_drag(n1,x1_new,y1_new)
|
|
||||||
n0=n1.prev
|
|
||||||
n2=n1.next
|
|
||||||
n0.next=n2
|
|
||||||
n2.prev=n0
|
|
||||||
n1.next=nil
|
|
||||||
n1.prev=nil
|
|
||||||
else n0=n0.next end
|
|
||||||
else n0=n0.next end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: Upon adding a point, start from there to see if we need another
|
-- TODO: Upon adding a point, start from there to see if we need another
|
||||||
@ -1152,6 +1183,9 @@ end
|
|||||||
function rope:_drag(n1,ax1_new,ay1_new)
|
function rope:_drag(n1,ax1_new,ay1_new)
|
||||||
local function _sweep_radar(ax_pivot,ay_pivot,ax_far0,ay_far0,ax_far1,ay_far1)
|
local function _sweep_radar(ax_pivot,ay_pivot,ax_far0,ay_far0,ax_far1,ay_far1)
|
||||||
if (ax_far0==ax_far1 and ay_far0==ay_far1) return nil
|
if (ax_far0==ax_far1 and ay_far0==ay_far1) return nil
|
||||||
|
local function crossed(x,y)
|
||||||
|
return x!=y
|
||||||
|
end
|
||||||
|
|
||||||
if ax_far0==ax_far1 then
|
if ax_far0==ax_far1 then
|
||||||
local ax_far=ax_far0
|
local ax_far=ax_far0
|
||||||
@ -1161,9 +1195,14 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
|||||||
for ay_far_new in _stepfrom(ay_far0,ay_far1) do
|
for ay_far_new in _stepfrom(ay_far0,ay_far1) do
|
||||||
for _,anchor in level:anchor_points() do
|
for _,anchor in level:anchor_points() do
|
||||||
if
|
if
|
||||||
|
not (anchor.ax==ax_pivot and anchor.ay==ay_pivot) and
|
||||||
|
not (anchor.ax==ax_new and anchor.ay==ay_new) and
|
||||||
(ax0<=anchor.ax and anchor.ax<=ax1) and
|
(ax0<=anchor.ax and anchor.ax<=ax1) and
|
||||||
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_old)!=
|
would_stick(ax_pivot,ay_pivot,anchor,ax_far,ay_far_new) and
|
||||||
|
crossed(
|
||||||
|
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_old),
|
||||||
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_new)
|
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_new)
|
||||||
|
)
|
||||||
then
|
then
|
||||||
return anchor
|
return anchor
|
||||||
end
|
end
|
||||||
@ -1178,11 +1217,14 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
|||||||
for ax_far_new in _stepfrom(ax_far0,ax_far1) do
|
for ax_far_new in _stepfrom(ax_far0,ax_far1) do
|
||||||
for _,anchor in level:anchor_points() do
|
for _,anchor in level:anchor_points() do
|
||||||
if
|
if
|
||||||
-- anchor.ax!=ax_pivot and anchor.ay!=ay_pivot and
|
not (anchor.ax==ax_pivot and anchor.ay==ay_pivot) and
|
||||||
-- anchor.ax!=ax_new and anchor.ay!=ay_new and
|
not (anchor.ax==ax_new and anchor.ay==ay_new) and
|
||||||
|
would_stick(ax_pivot,ay_pivot,anchor,ax_far_new,ay_far) and
|
||||||
(ay0<=anchor.ay and anchor.ay<=ay1) and
|
(ay0<=anchor.ay and anchor.ay<=ay1) and
|
||||||
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_old,ay_far)!=
|
crossed(
|
||||||
|
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_old,ay_far),
|
||||||
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_new,ay_far)
|
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_new,ay_far)
|
||||||
|
)
|
||||||
then
|
then
|
||||||
return anchor
|
return anchor
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user