11 Commits

Author SHA1 Message Date
e028209adf assert on unrecognized directive
saves four tokens and is more diagnostic.
2023-01-01 14:11:11 -08:00
ce3fc83221 fmt in debugmouse:draw3.
This is literally the reason I implemented fmt in the first place
2023-01-01 13:54:28 -08:00
3e2229be65 use fmt in a commented-out debug logging block 2023-01-01 13:54:28 -08:00
46f1339e19 golf recollide_reanchor
Uses fmt in recollide_reanchor. This has a performance impact in code that is already slow so this might need to be reverted; I think that should be part of a comprehensive optimization pass, however, and making it worse for now as part of a general code cleanup is probably better.
2023-01-01 13:54:28 -08:00
f86e52d3bd tostring golf
this could be golfed further by rewriting the str..= line in terms of fmt, but the performance impact of inserting the extra `fmt` calls and parsing into the tostring recursion seems likely to be a problem.
2023-01-01 13:54:28 -08:00
e6c35dbeda Use fmt on title screen. 2023-01-01 13:54:28 -08:00
3516d2855e fix section before first "%"
oops, need to special-case the first part of the split list.

amusingly, I don't need to special-case zero-length format strings because that will skip the entire loop and output "", which seems correct. (I am also not special-casing zero-length segments because `s[1] == nil` will go into the error handler and that seems fine.
2023-01-01 13:54:28 -08:00
2264349e72 fix double-consume, add %!
I discovered your tostring function for debugging, might as well make it reachable from fmt.  I also realized I forgot to convert to using "p" when I introduced it so I fixed that
2023-01-01 13:54:27 -08:00
93c154f876 fix sprintf and rename to fmt
the "split on %" strategy makes parsing "%%" complicated, so the "actually literally %" placeholder is now "%~" rather than "%%". since thsi resembles a real sprintf even less now I renamed it to "fmt".

also actually closes the `if m == "~"` block. (which was `if m == "%"` before this patch)
2023-01-01 13:54:27 -08:00
3494c48e74 implement fake sprintf
this spends extra tokens to handle "invalid format character" to catch using a % where %% is intended. this is designed to grow with further format chars if needed; I have ideas for not-exactly-POSIX %d, %x, %h, %!, %#, %c, and possibly others but there is absolutely no reason to spend tokens on these things until we need them. (that said, existing debugging output might benefit from some of these other formats, but that debug code is commented out, so maybe nevert.)
2023-01-01 13:54:27 -08:00
e878717c31 Better debug mouse
Debug mouse is now its own module, so it can be separated from the hint system, since it is useful for more than just positioning hints. It now has the following enhancements:

1. Clock-based table cyclng now has a helper function (cycle)
2. Debug mouse color cycling is distinct from hint color cycling, so debug position readout remains legible
3. Debug position readout now stays on screen even when the cursor is near or past the edges
4. Debug cursor cycles between a mouse sprite specifically marking the exact pixel that is being sampled, an "X" for text character sizing, and a "□" for positioning the centered 3x3 characters often used as hint target markers
5. Map cell coordinates (in square brackets) are displayed in addition to pixel coordnates (in parentheses)

Sprite 50 is now the mouse cursor. Color 15 is color cycling for debug readouts.

Debug mouse features can be disabled by commenting out `add(real_modules, debugmouse)`.

I've done a little bit of golfing but this is stiill a token expense. I'm going to write a crappy sprintf function to save tokens everywhere we're assembling strings from their component parts.
2023-01-01 13:44:45 -08:00

View File

@ -26,10 +26,10 @@ function music_off()
menuitem(3, "music: off", music_on)
end
function gsv(s,sep1,sep2)
local ret=split(s,sep1 or "\n")
function gsv(s)
local ret=split(s,"\n")
for i,v in ipairs(ret) do
ret[i] = type(v) == "string" and split(v,sep2 or "`") or {v} end
ret[i] = type(v) == "string" and split(v,"`") or {v} end
return ret
end
@ -38,6 +38,39 @@ function cycle(tbl,period)
return tbl[t()%period*#tbl\period+1]
end
-- fake sprintf function
-- %~ for literal "%"
-- %v for param
-- %! for tostring(param)
-- which dumps tables
function fmt(f, ...)
local out, i = "", 0
for s in all(split(f,"%")) do
if i == 0 then
-- before first format directive
out ..= s
i = 1
else
local m = s[1]
if m == "~" then
out ..= "%"
else
local p = select(i,...)
i+=1
if m == "v" then
out ..= p
elseif m == "!" then
out ..= tostring(p)
else
assert(false, tostr(m).."is not a formatting directive")
end
end
out ..=sub(s,2)
end
end
return out
end
mnames={}
function names(root)
local n=mnames[root]
@ -246,15 +279,13 @@ function kbd:release(i)
end
function tostring(any)
if type(any)=="table" then
if (type(any)!="table") return tostr(any)
local str = "{ "
for k,v in pairs(any) do
str=str..tostring(k).."->"..tostring(v).." "
str..=tostring(k).."->"..tostring(v).." "
end
return str.."}"
end
return tostr(any)
end
-->8
-- title screen
@ -269,7 +300,7 @@ function title:draw()
print("pyrex",32,73,7)
print("[nyeogmi]",62,73,7)
print("kistaro",32,79,7)
local lvlstr = "⬅️ "..start_level.." ➡️"
local lvlstr = fmt("⬅️ %v ➡️",start_level)
print(lvlstr,50,91,1)
print(lvlstr,51,90,blinkcol)
end
@ -298,7 +329,7 @@ function level:init()
end
function level:reinit(n)
self.hintlevel=255
self.hintlevel = 0
self.ix=n
self.todo={}
self.bigx,self.bigy=n%8,n\8
@ -439,8 +470,7 @@ function level:recollide_reanchor()
not self:mcoll(mx1,my0) and
not self:mcoll(mx1,my1)
) then
local key="GEOM"..mx0..","..my0..","..dx..","..dy
anch_new[key]= {
anch_new[fmt("GEOM%v,%v,%v,%v",mx0,my0,dx,dy)]= {
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
}
end
@ -448,10 +478,9 @@ function level:recollide_reanchor()
end
for _,cr in pairs(self._crates) do
local key="CRATE"..cr.id..","..dx..","..dy
local mx0,my0=cr.mx,cr.my
local mx1,my1=mx0+dx,my0+dy
anch_new[key]={
anch_new[fmt("CRATE%v,%v,%v",cr.id,dx,dy)]={
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
}
end
@ -1059,7 +1088,7 @@ function rope:draw(artificial_px,artificial_py)
if (anch.ady>0) y-=1
end
rectfill(x-1,y-1,x+1,y+1,12)
print("ax="..n1.ax..",ay="..n1.ay,72,sy)
print(fmt("ax=%v,ay=%v",n1.ax,n1.ay),72,sy)
sy+=7
local n0=n1.prev
@ -1759,10 +1788,8 @@ end
-- [3] y coord
-- [4] message line 1 (rot13)
-- [5] message llne 2 (rot13)
-- [6] arrow (semicolon separated list: each element is two comma-separated integers)
-- row 5 can be omitted
-- for a 1-line hint
-- row 6 can be omitted if there is no arrow
--
-- multiple hints for the same
-- room are revealed in order
@ -1772,21 +1799,19 @@ add(real_modules,hints)
function hints:init()
local h = gsv[[0`42`57`🅾️ yVPX` ■
0`42`73`❎, ❎ cHYY``69,67;55,67
1`35`33`⁘` cHYY`62,35;41,35
1`79`82`cHYY ■``100,94;100,88
1`42`98`⁘`VTABER`66,99;52,99;52,75;28,75;28,120
2`75`65` `⁘`86,67;76,67;76,71
2`104`73` ■`cHYY`81,75;86,75
2`27`42`⁘``36,16;36,44;31,44
3`51`106`■``52,97;52,104
3`-1`-1```28,78;28,45
3`-1`-1```65,35;83,35
3`-1`-1```97,35;105,35]]
0`42`73`❎, ❎ cHYY
1`35`34`⁘ sVYY
1`99`82`cHYY
1`42`98`⁘`VTABER
2`75`65`i <`⁘
2`104`73` ■`cHYY
2`27`42`⁘
3`51`106`■ cHYY
3`27`81`⁘ HAOYBPX ZR
3`91`33`■ FGNAQ` URER]]
for rec in all(h) do
rec[4]=rot13(rec[4])
if(rec[5]) rec[5]=rot13(rec[5])
if(rec[6]) rec[6]=gsv(rec[6],";",",")
local lh = self[rec[1]]
if lh then
add(lh,rec)
@ -1798,39 +1823,22 @@ function hints:init()
menuitem(2,"hide hints",function() level.hintlevel=0 end)
end
function shdprint(txt,x,y,c)
print(txt,x-1,y+1,1)
print(txt,x,y,c)
end
hintflicker=split"7,10,9,8,8,9,10,7"
function hints:draw2()
pal()
local c=cycle(hintflicker)
local function body()
for i,h in ipairs(self[level.ix]) do
if (i > level.hintlevel) return
local _,x,y,txt,txt2,arrow=unpack(h)
print(txt,x,y)
if (txt2) print(txt2,x,y+8)
if arrow then
line()
local x0,y0,x1,y1
for i=1,#arrow do
x0,y0,x1,y1=x1,y1,unpack(arrow[i])
line(x1,y1)
local _,x,y,txt,txt2=unpack(h)
shdprint(txt,x,y,c)
if (txt2) shdprint(txt2,x,y+8,c)
end
local dir=atan2(x1-x0,y1-y0)
local function _ahead(d,r)
line(x1+r*sgn0(cos(dir+d)),y1+r*sgn0(sin(dir+d)))
end
_ahead(0.375,2) _ahead(0.625,2) _ahead(0,0)
end
end
end
color(7)
camera(1,-1) pal(7,1) body()
camera() pal(7,c) body()
pal()
end
-->8
@ -1846,21 +1854,16 @@ function debugmouse:init()
end
debugflicker=split"5,6,7,15,14,8,2,4,9,10,11,3,12,13"
debugchs = split" ,□,x"
debugchs = split" ,x, ,□"
function debugmouse:draw3()
if (stat(34) == 0) return
pal(15,cycle(debugflicker,1.5))
local x, y, c = stat(32), stat(33), debugchs[stat(34) & 0x3]
if not c or c == " " then
spr(50,x,y)
else
local x, y, c = stat(32), stat(33), cycle(debugchs,2)
if (c == " ") spr(50,x,y)
print(c,x,y,15)
end
print(x..", "..y,
mid(0,x,97),
mid(0, y > 117 and y - 6 or y + 6, 117),
15)
local px, py = mid(0,x,89), mid(0, y > 111 and y - 12 or y + 6, 117)
print(fmt("(%v, %v)\n[%v, %v]",x,y,x\8,y\8),px,py,15)
pal()
end
@ -1962,37 +1965,37 @@ eeee0000cc04405500444400efeeee5e11111111e5eeeefeeeeeeeeeeeeeeeeeffffffffffffffff
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0
00000000000000000000000000000000c0c0c0c0c021c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c021c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c100c0c000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c1002400c1c100c0c0c0c0c0c0c0c0c0c0c0c0c0c000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c00000e300c00000c0c0c0c0c0c0c0c0c0c0c10000c000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c000000000c000c0c0c0c0c0c0c0c0c0c000000000c100c100f3c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
000000000000000000000000000000001000340000c000c0c0c0c0c0c0c0c0c01000c034c1c1c1c100c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c000000000c100f3c0c0c0c0c0c0c0c0c00000000000000000c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000212000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000212000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000313000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000313000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0100000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0
00000000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0
__label__
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
@ -2127,9 +2130,9 @@ __gff__
000000c0c0c0c0c0c0c0c0c0c0c00000000000c0c0c0c0c0c0c0c0c0202020200040c0c0c0c0c0c0c008080800000000404000000808080808080808c0c0c0c000000000080808080808080800000008000000000808080808080808000000000008080808080808080808080000000000080808080808080808080800000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d1203040404050d0d0d0d010d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d0d0d0d0d0d03043e0a00000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0a0d0d0d0d0a0d0304040405140013004f00150d0d0d1400140d0d0d0d0d0d0d0d0d0d0d0d1400140d0d0d0d0d030404040404041700002600000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d033e0404040404050d0d0d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d03042604040404260417000000151400001e0000150304040400040404050d0d0d0d0d03040404050003040404050d130000000000000000001800000000000000000000000000000000000000000000000000000000000000000d0d0d0d0d134400000000001514140d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d1203040404050d0d0d0d010d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d0d0d0d0d0d03043e0a040404050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0a0d0d0d0d0a0d0304040405140013004f00150d0d0d1400140d0d0d0d0d0d0d0d0d0d0d0d1400140d0d0d0d0d0304040404040417000026000000150d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d030404043e050d0d0d0d0d0d033e0404040404050d0d0d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d03042604040404260417000000151400001e0000150304040400040404050d0d0d0d0d03040404050003040404050d1300000000000000000018000000150d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0304041700000000150d0d0d0d0d0d134400000000001514140d0d0d0d0d
0d0d0d0d0d0d0d0d0d0a0d0d0d0d0d0d0d14130018000000001800000000001514141300000015130000000000000015030404040513000000160017000000150d1300000000000000421e00000000150d0d0d0d0d0d0d0d0d0a0d0d0d0d0d0d0d0d1300000000000000150d0d0d0d0d12001d0000000000000003040404050d
0d0d0d0d0d0d0d0d0d260d0d0d0d0d0d010000001e0000004f000000000000150d031700000015130000000000000015130000001513004200001e43000000150d130000000000000000001a000041150d0d0d0d0d0d0d0d0d260d0d0d0d0d0d0d0d13000000001d1d00150d0d0d0d0d0d131c0000000000150013000000150d
0d0d0d0d0d0d0d0d0d260d0d0d0d0d0d0d1413001a000000001a0000000000150d13000000001513000000000000001513001d1d0000000000000000000000150d232424002424240700002600001e150d0d0d0d0d0d0d0d0d260d0d0d0d0d0d0d0d1346062407471c00150d0d0d0d0d0d231c24241d2424250000000000150d