forked from pyrex/chameleonic
packed crate representation
don't bother exploding crates into four bools, and then comparing them all individually to a bunch of conditions. absurd bit manipulation bullshit saves cycles and tokens. leaving a crate's movement rule represented as four bits means we can exploit our previous calculation of dx1 and dy1, which must each either be 0x0001 or 0x8FFF, and violently hammer them down to align with this bit-packed representation, giving this glorious little atrocity.
This commit is contained in:
parent
b10447bb86
commit
0fe3b1699f
@ -480,16 +480,18 @@ function _mix(mx,my)
|
||||
return mx..","..my
|
||||
end
|
||||
|
||||
-- crate spec:
|
||||
-- "up" == 1
|
||||
-- "right" == 2
|
||||
-- "down" == 4
|
||||
-- "left" == 8
|
||||
--
|
||||
-- +1+
|
||||
-- 8 2
|
||||
-- +4+
|
||||
function level:_get_cratedef(s)
|
||||
if (s<64 or s>=80) return nil
|
||||
|
||||
local s2=s-64
|
||||
return {
|
||||
up=s2&1!=0,
|
||||
right=s2&2!=0,
|
||||
down=s2&4!=0,
|
||||
left=s2&8!=0
|
||||
}
|
||||
if (s<64 or s>=80) return
|
||||
return s & 0x000F
|
||||
end
|
||||
|
||||
function level:get_latch(dx,dy,px,py)
|
||||
@ -500,12 +502,11 @@ function level:get_latch(dx,dy,px,py)
|
||||
local dx1,dy1=-sgn0(dx),-sgn0(dy)
|
||||
|
||||
if crate then
|
||||
if
|
||||
(crate.def.up and dy>0) or
|
||||
(crate.def.down and dy<0) or
|
||||
(crate.def.left and dx>0) or
|
||||
(crate.def.right and dx<0)
|
||||
then
|
||||
if crate.def & (
|
||||
dy1 >>> 15 |
|
||||
(dy1 & 0x1) << 2 |
|
||||
(dx1 & 0x8000) >>> 12 |
|
||||
(dx1 & 0x1) << 1) ~= 0 then
|
||||
return {
|
||||
el="crate",
|
||||
dx=dx1,dy=dy1,
|
||||
|
Loading…
Reference in New Issue
Block a user