Compare commits

...

3 Commits

Author SHA1 Message Date
0fe3b1699f
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.
2022-12-22 23:15:03 -08:00
b10447bb86
comment the bullshit
it needs it
2022-12-22 22:50:34 -08:00
fe3a68284f
replace comparisons with bit math bullshit
integers in the range [0, 15] fit entirely in the bit mask 0x000F. integers out of that range will have at least one bit 0x0010 or higher, or will have the sign bit 0x8000 set. so to find out if one of two numbers is out of range [0, 15], we can check the bit mask of their bitwise or.

this saves tokens and cycles. it is also completely illegible. very in the spirit of Pico-8, I love it.
2022-12-22 22:49:27 -08:00

View File

@ -438,7 +438,9 @@ function level:spawn_exit()
if (self:_mget(x,y)!=18) return if (self:_mget(x,y)!=18) return
for nx=x-1,x+1 do for nx=x-1,x+1 do
for ny=y-1,y+1 do for ny=y-1,y+1 do
if nx<0 or ny<0 or nx>15 or ny>15 then -- next check: is at least one of
-- nx or ny out of range [0, 15]?
if (nx | ny) & 0xFFF0 ~= 0 then
self._wins[_mix(nx,ny)]=true self._wins[_mix(nx,ny)]=true
end end
end end
@ -478,16 +480,18 @@ function _mix(mx,my)
return mx..","..my return mx..","..my
end end
-- crate spec:
-- "up" == 1
-- "right" == 2
-- "down" == 4
-- "left" == 8
--
-- +1+
-- 8 2
-- +4+
function level:_get_cratedef(s) function level:_get_cratedef(s)
if (s<64 or s>=80) return nil if (s<64 or s>=80) return
return s & 0x000F
local s2=s-64
return {
up=s2&1!=0,
right=s2&2!=0,
down=s2&4!=0,
left=s2&8!=0
}
end end
function level:get_latch(dx,dy,px,py) function level:get_latch(dx,dy,px,py)
@ -498,12 +502,11 @@ function level:get_latch(dx,dy,px,py)
local dx1,dy1=-sgn0(dx),-sgn0(dy) local dx1,dy1=-sgn0(dx),-sgn0(dy)
if crate then if crate then
if if crate.def & (
(crate.def.up and dy>0) or dy1 >>> 15 |
(crate.def.down and dy<0) or (dy1 & 0x1) << 2 |
(crate.def.left and dx>0) or (dx1 & 0x8000) >>> 12 |
(crate.def.right and dx<0) (dx1 & 0x1) << 1) ~= 0 then
then
return { return {
el="crate", el="crate",
dx=dx1,dy=dy1, dx=dx1,dy=dy1,