snowkittykira [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=93843 picotron error explorer 0.0.6 - interactive stack trace on error <p>hi, i wrote an interactive error screen for picotron! on error, it lets you explore the stack, local variables, and shows the source location where the error occurred. use arrows to go up and down the stack, the mouse wheel to scroll, and click on table variables to expand them. you can also press <code>space</code> or <code>x</code> to toggle small-font mode.</p> <p> <table><tr><td> <a href="/bbs/?pid=147383#p"> <img src="/bbs/thumbs/pico64_error_explorer_example-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=147383#p"> error_explorer_example</a><br><br> by <a href="/bbs/?uid=93843"> snowkittykira</a> <br><br><br> <a href="/bbs/?pid=147383#p"> [Click to Play]</a> </td></tr></table> </p> <p>download: <a href="https://github.com/snowkittykira/picotron-error-explorer">https://github.com/snowkittykira/picotron-error-explorer</a></p> <p>to use it, download <code>error_explorer.lua</code> and <code>include</code> it after defining your <code>_init</code>, <code>_update</code> and <code>_draw</code> functions.</p> <p>it replaces these functions which wrappers that call them in a coroutine, so that when errors happen the coroutine can be inspected. on error, it does its best to reset the graphics state, but there might still be cases where this fails so let me know if you run into any issues!</p> <p>it relies on the following functions from lua's debug library, so i hope they will continue to be available:</p> <ul> <li><code>debug.traceback</code></li> <li><code>debug.getinfo</code></li> <li><code>debug.getlocal</code></li> <li><code>debug.getupvalue</code></li> </ul> <p>(note: please use the github version and not the one in the example cart, as it'll be more up to date)</p> https://www.lexaloffle.com/bbs/?tid=141978 https://www.lexaloffle.com/bbs/?tid=141978 Fri, 26 Apr 2024 17:36:36 UTC minor bug report: calling clip() during _init() crashes picotron <p>this crashes picotron when run:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function _init () clip() end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141980 https://www.lexaloffle.com/bbs/?tid=141980 Fri, 26 Apr 2024 17:12:11 UTC coroutine.resume weirdness <p>hi, i'm loving picotron so far! i just wanted to report some issues using coroutines.</p> <p>when using coroutine.resume, it can sometimes return early when the coroutine runs for a while due to how picotron does timeslicing. from reading head.lua, i learned that using coresume instead of coroutine.resume fixes this, which makes me think maybe coroutine.resume should be replaced with it. another more minor issue is that coresume only returns the first value of a multiple-value return/yield from the coroutine, and not any more.</p> <p>here's a simple test case:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>local function long_running_coroutine () for i = 1, 100 do cls() end return 1, 2 end function working () local c = coroutine.create (long_running_coroutine) coresume (c) assert (coroutine.status(c) == 'dead', 'this works') end function not_working () local c = coroutine.create (long_running_coroutine) coroutine.resume (c) assert (coroutine.status(c) == 'dead', 'this doesn\'t work') end function also_not_working () local c = coroutine.create (long_running_coroutine) local a, b, c = coresume (c) assert (a) assert (b) assert (c, 'only one coroutine return value returned') end function _draw () working () not_working () also_not_working () end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141914 https://www.lexaloffle.com/bbs/?tid=141914 Tue, 23 Apr 2024 22:47:18 UTC globals set in terminal.lua <p>hi! when i use lua i usually use a library that prevents me from accidentally using/setting globals that aren't already defined, in order to cut down on typos. i've collected a small whitelist of globals that need to be available for picotron. i noticed in terminal.lua there's a comment saying it's not supposed to set any globals, so i thought i'd report them in case they should be fixed.</p> <p>here's what i have so far in my whitelist:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>-- terminal.lua cproj_draw cproj_update _ _is_terminal_command k res -- gui.lua drag_t</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>and here's the full script i'm using to protect globals in case it's helpful:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>-- if you're using include(), include this after including everything else, -- since most included modules will need to assign global variables on load -- these globals are needed by picotron _init = _init or false _draw = _draw or false _update = _update or false -- these are used by the picotron terminal cproj_draw = cproj_draw or false cproj_update = cproj_update or false _ = _ or false _is_terminal_command = _is_terminal_command or false k = k or false res = res or false -- gui needs these drag_t = drag_t or false local function unknown_variable (t, k) error (debug.traceback ('unknown variable ' .. tostring (k), 2)) end setmetatable (_G, { __index = unknown_variable, __newindex = unknown_variable, })</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>it's probably a good idea not to use it in finished carts because then changes to picotron might break them</p> https://www.lexaloffle.com/bbs/?tid=141868 https://www.lexaloffle.com/bbs/?tid=141868 Sun, 21 Apr 2024 17:21:35 UTC picobloc - userdata-based ecs library <p>I've been writing an archetype-based ecs (entity-component-system) library for picotron and i put it up on github! </p> <p><a href="https://github.com/snowkittykira/picobloc">https://github.com/snowkittykira/picobloc</a></p> <p>It keeps component values in picotron userdata so that for simple cases like velocity / acceleration, you can use userdata operations to make it very fast! As a result it is probably slightly harder to use than the other ecs libraries available for picotron right now (which use tables to represent entities), but should allow some pretty good optimizations.</p> <p>you can see the example from the readme running here:</p> <p><a href="https://www.lexaloffle.com/bbs/?tid=141824">https://www.lexaloffle.com/bbs/?tid=141824</a></p> <p>and my plink cart also uses it, though it doesn't really need the optimization:</p> <p><a href="https://www.lexaloffle.com/bbs/?tid=141789">https://www.lexaloffle.com/bbs/?tid=141789</a></p> https://www.lexaloffle.com/bbs/?tid=141833 https://www.lexaloffle.com/bbs/?tid=141833 Sat, 20 Apr 2024 00:13:54 UTC waterfall demo <p> <table><tr><td> <a href="/bbs/?pid=146970#p"> <img src="/bbs/thumbs/pico64_ecs_waterfall-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=146970#p"> ecs_waterfall</a><br><br> by <a href="/bbs/?uid=93843"> snowkittykira</a> <br><br><br> <a href="/bbs/?pid=146970#p"> [Click to Play]</a> </td></tr></table> </p> <p>a little demo of an ecs system i'm working on that uses userdata to store component fields</p> <p>it's 4k particles, hold the '`' key to see cpu usage for update and draw (edit: oops this key only works on desktop apparently, but it's currently at 16% update and 33% draw)</p> https://www.lexaloffle.com/bbs/?tid=141824 https://www.lexaloffle.com/bbs/?tid=141824 Fri, 19 Apr 2024 19:29:26 UTC plink <p> <table><tr><td> <a href="/bbs/?pid=146845#p"> <img src="/bbs/thumbs/pico64_plink-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=146845#p"> plink</a><br><br> by <a href="/bbs/?uid=93843"> snowkittykira</a> <br><br><br> <a href="/bbs/?pid=146845#p"> [Click to Play]</a> </td></tr></table> </p> <p>playing around with physics and note()</p> <p><del>(sound is pretty borked on the bbs, so download it with <code>load #plink</code>)</del> sound seems fixed yay!</p> https://www.lexaloffle.com/bbs/?tid=141789 https://www.lexaloffle.com/bbs/?tid=141789 Wed, 17 Apr 2024 21:54:22 UTC userdata:copy issues <p>i'm trying to use :copy when growing a userdata:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>local a = vec(1, 1) local b = vec(0, 0, 0) a:copy (b) print(b) -- b is still zero</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>i figured maybe the vectors needed to be the same size but neither of these work either:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>local a = vec(1, 1) local b = vec(0, 0) local c = vec(0, 0) a:add (0, b) a:copy (c) print(a) print(b) print(c)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141775 https://www.lexaloffle.com/bbs/?tid=141775 Tue, 16 Apr 2024 21:53:16 UTC segmentation fault on left-multiplying userdata <p>just noting that the following crashes picotron:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function _draw () print (tostring (1 * vec(1, 1, 1))) end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141322 https://www.lexaloffle.com/bbs/?tid=141322 Sun, 31 Mar 2024 20:44:47 UTC color table indices swapped? <p>not sure if this is a bug in picotron or just in the docs, but in the gfx pipeline doc it says that the colour tables are accessed like this:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>out_col = peek(0x8000+coltab*0x1000 + target_col*64 + draw_col)</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>but to get the colour table working properly in practice i have to swap the target and draw colours like this:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function c_set_table (draw_color, target_color, result) poke (0x8000 + 64 * draw_color + target_color, result) end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141281 https://www.lexaloffle.com/bbs/?tid=141281 Sat, 30 Mar 2024 17:00:09 UTC simple dither patterns <p> <table><tr><td> <a href="/bbs/?pid=145139#p"> <img src="/bbs/thumbs/pico64_simple_dither-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=145139#p"> simple_dither</a><br><br> by <a href="/bbs/?uid=93843"> snowkittykira</a> <br><br><br> <a href="/bbs/?pid=145139#p"> [Click to Play]</a> </td></tr></table> </p> <p>thought i'd post a demonstration of generating simple dither patterns for fillp in case it was useful to anyone!</p> <p>feel free to use under the CC license or mit license or public domain</p> <p>dither.lua:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>-- threshold map from https://en.wikipedia.org/wiki/Ordered_dithering local threshold_map = { 0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5, } local function make_mask (value) local mask = 0 for i = 1, 16 do mask = mask * 2 if threshold_map [i] &gt;= value then mask = mask + 1 end end return mask end local dither_masks = {} for i = 0, 16 do dither_masks[i] = make_mask (i) end -- value 0-1 function dither_mask (value) return dither_masks [mid (0, math.floor (value * 16 + 0.5), 16)] end </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>main.lua:</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>include 'dither.lua' local W, H = 480, 270 local color1 = 9 local color2 = 30 function _draw () for i = 0, H-1 do fillp (dither_mask (i/H)) rectfill (0, i, W, i, (color1 &lt;&lt; 8) | color2) end fillp () end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=141280 https://www.lexaloffle.com/bbs/?tid=141280 Sat, 30 Mar 2024 16:39:31 UTC