dhostin [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=28327 Benchmarking virtual sprite with lru cache <p>Hey !</p> <p>You may have already heard about virtual sprite from <a href="https://freds72.itch.io/poom/devlog/241700/journey-to-poom">Poom devlog</a> (<a href="https://www.lexaloffle.com/bbs/?uid=25532"> <a href="https://www.lexaloffle.com/bbs/?uid=25532"> @freds72</a></a>) and one <a href="https://www.lexaloffle.com/bbs/?tid=45769">high memory implementation</a> from <a href="https://www.lexaloffle.com/bbs/?uid=27691"> @pancelor</a>. Here is my take.</p> <p> <table><tr><td> <a href="/bbs/?pid=111157#p"> <img src="/bbs/thumbs/pico8_vsprbench-3.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=111157#p"> vsprbench</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=111157#p"> [Click to Play]</a> </td></tr></table> </p> <p>As a reminder, the principle of virtual sprite is to have a kind of &quot;palette of sprite&quot; which allow to draw more sprite than the 256 native built-in ones. </p> <p>The cartridge contains 4 PX9 compressed spritesheet that are unpacked when the cartridge boot. Then a bunch of benchmark are launched to test the LRU Cache with differents configurations.</p> <h2>Implementation overview</h2> <p>I implement two types of LRU cache and a benchmark to challenge implementations. With LRU cache, the oldest sprite are replaced by the new ones when cache is full. Easier to say than to do ! To keep track of sprite age, I use an queue, implemented with LUA tables.</p> <p>I use a 2 implementations of the lru age queue, one with the native <code>del</code>, <code>deli</code>, <code>add</code> function, and one with customs <code>ldel</code>, <code>laddlast</code> function relying on queue/linkedlist principle. My goal with linked list is to avoid shifting all table elements and reduce cpu cost of <code>del</code>/<code>deli</code> function. These two additionnal functions costs 134 tokens, maybe it can be improved...</p> <p>I also implement one type of cache that handle 8x8 sprites, (256 in spritesheet and 1024 virtuals) and another with 16x16 sprites (64 in spritesheet and 256 virtual).<br /> 8x8 sprites exactly match what pico8 can do with spr function but it has to deal with heavier table to handle sprite age in cache. 16x16 sprites are... bigger which can be a pros or a cons, but in both case they reduce the size of the cache and should reduce overhead to handle them. It is the choice that <a href="https://www.lexaloffle.com/bbs/?uid=25532"> <a href="https://www.lexaloffle.com/bbs/?uid=25532"> @freds72</a></a> has made in poom.</p> <p>Finally, I added a FIFO policy to the cache, which has the advantage of being simple and needs low cpu. We can see if this is an interesting approach.</p> <h2>Results</h2> <p>To comment the results, I would say that 16x16 sprites are handled better, because even if pico8 draw less sprites per sec, each sprite is 4 times bigger. That said you can multiply the number of sprite per second and you will have more 8x8 sprites.<br /> We can also see that with 16x16 sprites, the overhead of native del function is not to much of a problem.<br /> With 8x8 sprites, you have a huge gain with linked list queue, because we never shift the whole 1023 elements in the age queue. So if can you afford the 134 tokens and have to deal with 8x8 sprites, this choice is interesting.<br /> The worst choice to make is to deal with 8x8 sprites and native <code>del</code> function to handle lru cache. I think in this case the overhead simply discard the benefits of the cache.</p> <p><strong>EDIT:</strong> With the vspr function provided by <a href="https://www.lexaloffle.com/bbs/?uid=42638"> @JadeLombax</a>, we can see that LRU implementation overhead never provide better results. Even with high cache hit ratio, it barely reach the performance with cache. It means that sprite copy is already fast, so if we want to handle a kind of cache to avoid double copy for each sprite drawing, we need a low overhead cache mechanic. So I try a FIFO cache.</p> <h2>If you want to test your own functions</h2> <p>On tab 2, there is a table for benchmark declaration. The table <code>benchs</code> contain entries where :</p> <ul> <li><code>n</code> is the name of benchmark, </li> <li><code>f</code> the function to call to draw a sprite from high memory. The Function as 3 parameters, fun(sprite_nb,x,y). Sprite number is the absolute number of sprite among the 4 highmemory bank, with 8x8 sprite, it can be 0-1023.</li> <li><code>d</code> is the data preset. I use 4 presets, randomly populated 32767 sprite index at boot time.<br /> <code>ben8</code> and <code>ben8f</code> are for 8x8 sprite. ben8 can have sprite with index 0 to 1023, which imply a ~25% hit ratio as it is pure random. <code>ben8f</code> only have 0 to 255 sprite index, which implies 100% hit ratio.<br /> <code>ben16</code> and <code>ben16f</code> are the same for 16x16 sprite. <code>ben16</code> has ~25% hit ratio and <code>ben16f</code> ~100%</li> </ul> <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 benchs={ {n=&quot;jadelombax&quot;,f=vspr,d=ben8}, {n=&quot;vspr8memcpy&quot;,f=vspr8nc,d=ben8}, {n=&quot;vspr8lru &quot;,f=vspr8,d=ben8}, {n=&quot;vspr8fifo&quot;,f=vspr8fifo,d=ben8}, {n=&quot;vspr8lru &quot;,f=vspr8,d=ben8f}, {n=&quot;vspr8fifo&quot;,f=vspr8fifo,d=ben8f}, {n=&quot;vspr16lru&quot;,f=vspr16,d=ben16}, {n=&quot;vspr16fifo&quot;,f=vspr16fifo,d=ben16}, {n=&quot;vspr16lru&quot;,f=vspr16,d=ben16f}, {n=&quot;vspr16fifo&quot;,f=vspr16fifo,d=ben16f}, {n=&quot;vspr16nc &quot;,f=vspr16nc,d=ben16}, }</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>So you can add your function and declare it in the benchs, it should work :)</p> https://www.lexaloffle.com/bbs/?tid=47621 https://www.lexaloffle.com/bbs/?tid=47621 Sun, 01 May 2022 22:21:19 UTC Race no sun - Tweettweetjam 3 <p> <table><tr><td> <a href="/bbs/?pid=69968#p"> <img src="/bbs/thumbs/pico8_racenosun_560-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=69968#p"> racenosun_560</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=69968#p"> [Click to Play]</a> </td></tr></table> <br /> Looks like I finally made something with voxelspace terrain recent studies <a href="https://www.lexaloffle.com/bbs/?tid=35654">https://www.lexaloffle.com/bbs/?tid=35654</a></p> <p>This Race The Sun partial demake is my first entry to <a href="https://itch.io/jam/tweettweetjam-3">#TweetTweetJam N&deg;3</a>, in Pico8 with a 560 characters limit !</p> <h2>The Goal</h2> <p>You must go as far as possible, with no sun :D</p> <h2>Controls</h2> <p>Use &lt; / &gt; arrow to move your ship</p> <p>Ctrl + R to restart after crashing</p> <p>Good luck and have fun !</p> https://www.lexaloffle.com/bbs/?tid=35950 https://www.lexaloffle.com/bbs/?tid=35950 Sun, 17 Nov 2019 14:50:08 UTC Voxelspace experiments <p>At first, I saw a demo where a student implement a voxelspace algorithm with compute shaders. Voxelspace is a tech invented in the '90s by Kyle Freeman at Novalogic to render landscape. Games like Comanche, Deltaforce used it. It was based on heightmap and voxels, not polygon. I don't know much about shaders, but I know it is better at rendering polygons. So... I try to understand how all this work and here is the result: my voxelspace implementation on Pico 8</p> <p>With freds72 optimization<br /> <table><tr><td> <a href="/bbs/?pid=68841#p"> <img src="/bbs/thumbs/pico8_voxelspace_ykk-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=68841#p"> voxelspace_ykk</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=68841#p"> [Click to Play]</a> </td></tr></table> <br /> first release<br /> <table><tr><td> <a href="/bbs/?pid=68841#p"> <img src="/bbs/thumbs/pico8_voxelspace_ykk-1.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=68841#p"> voxelspace_ykk</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=68841#p"> [Click to Play]</a> </td></tr></table> </p> <p>Here is an implementation of voxelspace rendering algorithm, with a little perlin noise map generation. Features :</p> <ul> <li>Generate a 128x128 height map in memory,</li> <li>Generate a color map base on height with some noise (I could also use height difference to better show cliffs and flat grounds, maybe latter),</li> <li>colors fadding with distance</li> <li>We can move, with player one controls, zoom map with X (or M), strafe with player 2 left and right (s,f)</li> </ul> <p>I don't know where it will go, or if it will become a game, but here is my work :D Have fun tweaking or exploring !</p> <p>for a more advance experience, you can check electricgryphon work <a href="https://www.lexaloffle.com/bbs/?uid=10844">https://www.lexaloffle.com/bbs/?uid=10844</a></p> https://www.lexaloffle.com/bbs/?tid=35654 https://www.lexaloffle.com/bbs/?tid=35654 Sun, 13 Oct 2019 19:50:29 UTC Pico Cyberbank <p> <table><tr><td> <a href="/bbs/?pid=63785#p"> <img src="/bbs/thumbs/pico8_picocyberbank_100-3.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=63785#p"> picocyberbank_100</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=63785#p"> [Click to Play]</a> </td></tr></table> </p> <p>PicoCyberbank is a cyberpunk remake of West Bank / Bank Panic by Damien Hostin, on twitter <a href="https://twitter.com/yourykiki">yourykiki </a> (<a href="http://youry.kiki.free.fr/blog">The Lurking Engine</a>)</p> <h2>Goal :</h2> <p>you must help the bank collect the credchips by shooting the baddies and survive 9 days ! Beware some people are not as they seem to be at first !</p> <h2>Controls - keyboard or gamepad :</h2> <p>Use arrows to shoot left center or right<br /> Use button 1 (x) or 2 (c) to change the doors you are looking</p> <h2>Behind the scene</h2> <p>This project was less complicated than Brutal Pico Race, I designed it to work with my kids... But actually, it was way too complicated for my little beginners, and they gave up after coding the open/close system for the doors :D It is also why there is a lot of functions in french. They came back for beta testing !</p> <p>I keep some interesting parts for myself, such as the plasma doors, using the PX8 compression and a coroutine queue to load people graphics at runtime, a bunch of sprite picked up randomly to build the people, and little hidden surprises on the intro scene to reflect how far you went in the game !</p> <p><strong> Once again, great thanks to the pico 8 community ! </strong></p> <p>Have fun !</p> https://www.lexaloffle.com/bbs/?tid=33979 https://www.lexaloffle.com/bbs/?tid=33979 Sun, 21 Apr 2019 21:58:39 UTC Brutal Pico Race <p> <table><tr><td> <a href="/bbs/?pid=54001#p"> <img src="/bbs/thumbs/pico8_brutalpicorace_104-0.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=54001#p"> Brutal Pico Race 1.0.4</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=54001#p"> [Click to Play]</a> </td></tr></table> </p> <p>Brutal Pico Race is a fast and raw futurist racing game on Pico8 by me, Damien Hostin, on twitter <a href="https://twitter.com/yourykiki">yourykiki </a> (<a href="http://youry.kiki.free.fr/blog">The Lurking Engine</a>)</p> <p>I wrote a little insight on my blog in two parts, you can find it <a href="http://youry.kiki.free.fr/blog/?p=418&amp;amp;lang=en">here</a> and <a href="http://youry.kiki.free.fr/blog/?p=467&amp;amp;lang=en">here</a></p> <p>Choose one ship out of three class, choose a track and try to finish first ! You can also challenge a friend, alone or with AI, in split-screen mode !<br /> Brutal Pico Race features :</p> <p><strong>Single player or two players in splitscreen</strong></p> <ul> <li>3 class of ships -heavy -normal -light with different speed curve</li> <li>6 tracks</li> <li>3 AI levels</li> </ul> <p><strong>Controls - keyboard or gamepad :</strong><br /> <em>Menu</em></p> <p>Use arrows to choose your ship / track / AI level<br /> Z/C/N to start<br /> When 2 players is selected, the second player can choose his own ship directly with S/F</p> <p><em>Game</em></p> <p><span style="text-decoration: underline;">Player 1</span> </p> <ul> <li>steering : arrow LEFT, arrow RIGHT</li> <li>accelerate Z/C/N, break V/X/M</li> <li>boost arrow UP</li> </ul> <p><span style="text-decoration: underline;">Player 2</span></p> <ul> <li>steering : S, F</li> <li>accelerate TAB/Z, brake Q</li> <li>boost E </li> </ul> <p><span style="text-decoration: underline;">after race</span></p> <ul> <li>up/down to see the other ships running</li> </ul> <p>Great thanks to the pico 8 community (<a href="https://twitter.com/lexaloffle">Zep</a>, <a href="https://twitter.com/p01"><a href="https://www.lexaloffle.com/bbs/?uid=28958"> <a href="https://www.lexaloffle.com/bbs/?uid=28958"> @p01</a></a></a>, <a href="https://twitter.com/FSouchu">@FSouchu</a>, <a href="https://twitter.com/Felice_Enellen">@Felice_Enellen</a>, <a href="https://twitter.com/CasualEffects">Morgan</a>...), all the followers who help me on the project ! And many thanks to my wife and children for the playtests and ships/tracks contribution !</p> <p>If you like this game, don't hesitate to <a href="https://yourykiki.itch.io/brutal-pico-race">support it</a> ! This will help me doing more ;)</p> <p>Changelog</p> <p>1.0.4 : (with pico8 0.2.1)</p> <ul> <li>@fsouchu subpixel polygon filling</li> <li>slightly better drawing distance in 2 players mode, 12 road blocks instead of 9 </li> <li>drafting, stay long enough behind an opponent and get a boost</li> <li>Satisfying HUD design : <ul> <li>formatting lap time correctly</li> <li>reduce health, boost and speed bar to center the pilot face :)</li> </ul></li> </ul> <p>1.0.3 :</p> <ul> <li>We can finally die !</li> <li>Fix live rank</li> <li>Fix a bug where boost had not influence on centrifugal force, so now be carefull with boost spamming !</li> <li>Add chronometer and timeboard (best race time per track and per AI skill)​</li> <li>Add 3 tracks</li> <li>Add a 2 channels music for single player race</li> <li>Add controls helps</li> <li>Adaptive difficulty on boost, AI use less often boost when you're last or 3rd</li> <li>Change ship names<br /> <table><tr><td> <a href="/bbs/?pid=54001#p"> <img src="/bbs/thumbs/pico54369.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=54001#p"> Brutal Pico Race 1.0.3</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=54001#p"> [Click to Play]</a> </td></tr></table> </li> </ul> <p>1.0.2 :</p> <ul> <li>Increase difficulty </li> <li>3 kinds of bots</li> <li>Better end screen </li> <li>Changing camera after race</li> <li>Other ship progress on left</li> <li>Cooldown for ships collision damage</li> <li>Changing track loader, room for 3 new tracks</li> <li>Better boost visual fx</li> <li>Fix boost sound fx in splitscreen</li> <li>Change morgan3d heapsort with triplefox's shellsort</li> </ul> <p> <table><tr><td> <a href="/bbs/?pid=54001#p"> <img src="/bbs/thumbs/pico54182.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=54001#p"> Brutal Pico Race 1.0.2</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=54001#p"> [Click to Play]</a> </td></tr></table> </p> <p>1.0.1 :</p> <ul> <li>first public</li> <li>Changed rasterizer for <a href="https://www.lexaloffle.com/bbs/?uid=28958"> <a href="https://www.lexaloffle.com/bbs/?uid=28958"> @p01</a></a></li> </ul> <p> <table><tr><td> <a href="/bbs/?pid=54001#p"> <img src="/bbs/thumbs/pico54000.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=54001#p"> Brutal Pico Race 1.0.1</a><br><br> by <a href="/bbs/?uid=28327"> dhostin</a> <br><br><br> <a href="/bbs/?pid=54001#p"> [Click to Play]</a> </td></tr></table> </p> <p>1.0 :</p> <ul> <li>Initial version</li> </ul> https://www.lexaloffle.com/bbs/?tid=31490 https://www.lexaloffle.com/bbs/?tid=31490 Sun, 08 Jul 2018 04:53:35 UTC