forked from pyrex/chameleonic
can_move also takes a rope operation table
this is approximately token-neutral but performance-saving. each function parameter makes its call cost worse. When can_move is called inside a loop, we already have a table and we unpack to call can_move; moving the unpack into can_move saves us marshalling cost. It requires us to construct a table in a different spot (where we were not previously doing so) but that spot is not in a loop.
This commit is contained in:
parent
b1cc74fe3b
commit
d792831370
@ -633,10 +633,12 @@ end
|
|||||||
|
|
||||||
ropecheck=split"-0.6,0.4,0.4"
|
ropecheck=split"-0.6,0.4,0.4"
|
||||||
|
|
||||||
|
-- argument "o" is a rope operation:
|
||||||
|
-- array of [mx0,my0,dmx,dmy]
|
||||||
function level:can_move(
|
function level:can_move(
|
||||||
is_player,
|
is_player,o,exclude_src,exclude_dst
|
||||||
mx0,my0,dmx,dmy,exclude_src,exclude_dst
|
|
||||||
)
|
)
|
||||||
|
local mx0,my0,dmx,dmy=unpack(o)
|
||||||
local mx1,my1=mx0+dmx,my0+dmy
|
local mx1,my1=mx0+dmx,my0+dmy
|
||||||
if (is_player and self:win_at(mx1,my1)) return true
|
if (is_player and self:win_at(mx1,my1)) return true
|
||||||
if (is_player and self:get_open_pit(mx1,my1)) return wrongbleep:adequately_warned()
|
if (is_player and self:get_open_pit(mx1,my1)) return wrongbleep:adequately_warned()
|
||||||
@ -652,7 +654,8 @@ function level:can_move(
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- argument is array-like: mx0,my0,dmx,dmy
|
-- argument is a rope operation:
|
||||||
|
-- array of [mx0,my0,dmx,dmy]
|
||||||
function level:tug_crate(t)
|
function level:tug_crate(t)
|
||||||
local mx0,my0,dmx,dmy=unpack(t)
|
local mx0,my0,dmx,dmy=unpack(t)
|
||||||
local mxy0=_mix{mx0,my0}
|
local mxy0=_mix{mx0,my0}
|
||||||
@ -736,7 +739,7 @@ function player:update()
|
|||||||
else
|
else
|
||||||
local x,y=self.x,self.y
|
local x,y=self.x,self.y
|
||||||
local function try_move(dx,dy,f)
|
local function try_move(dx,dy,f)
|
||||||
if level:can_move(true,x,y,dx,dy,0,2) then
|
if level:can_move(true,{x,y,dx,dy},0,2) then
|
||||||
self.todo=f
|
self.todo=f
|
||||||
self.cooldown=3
|
self.cooldown=3
|
||||||
local t=f[#f]
|
local t=f[#f]
|
||||||
@ -1604,7 +1607,7 @@ function rope:_tug(hypothetically)
|
|||||||
|
|
||||||
if not invalid_move then
|
if not invalid_move then
|
||||||
local mv = {mx0,my0,dmx,dmy}
|
local mv = {mx0,my0,dmx,dmy}
|
||||||
if level:can_move(false,mx0,my0,dmx,dmy,1,0) then
|
if level:can_move(false,mv,1,0) then
|
||||||
if (hypothetically) return ancs,0,{mv},blocks
|
if (hypothetically) return ancs,0,{mv},blocks
|
||||||
|
|
||||||
level:tug_crate(mv)
|
level:tug_crate(mv)
|
||||||
@ -1693,7 +1696,7 @@ function rope:_calc_push(
|
|||||||
else
|
else
|
||||||
local crate=level:get_crate(mx,my)
|
local crate=level:get_crate(mx,my)
|
||||||
if crate then
|
if crate then
|
||||||
if not level:can_move(false,mx,my,dmx,dmy,0,0) then
|
if not level:can_move(false,o,0,0) then
|
||||||
add(blocked,o)
|
add(blocked,o)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user