Log In  
Log In  

@Felice

Follow
Follow

derp.

I'm a prematurely-retired professional video game programmer. I have some health problems that ruin my concentration and keep me from doing the kind of programming people will pay you for. PICO-8 is really nice for me, because the limited scope of the platform tends to keep the scope of problems and solutions limited enough for my limited concentration to cope with. I don't think I'll ever manage to produce a game for PICO-8, but it sure is fun just to play with.

(If I've just handed you some ideas or advice, probably for the fifth time this week, and you're getting sick of my doing that, then I have a couple of things I should say: first of all, you should let me know, because I know unwelcome advice is annoying and I don't want to be annoying; but also, second, try not to be too irritated with me, because giving advice is the only way I still feel like I can be a productive member of the video game developer community. I mean well, I swear.)

Oh, and about the avatar... once upon a time, I chose a nice little image of Miku in glasses for my avatar, purely because it struck me as adorable. However, I kept it because I discovered it kept away those useless people who would judge a book by its cover. This is that avatar, but hand-pixeled into low-res, pico-8 palette format.

@zep

If I type this:

Look at my `inline code` please.

I get this, which I'm just going to let the BBS handle, so it might look right to anyone reading this after it's fixed:

Look at my inline code please.

The second backtick isn't closing the inline code.

As an aside, I personally would prefer it if inline code were simply a monospaced font, and not inverted as it is now. It makes using inline code very ugly and hard on the eyes. :/

I do like the old-printer-paper code block format though. :)

P#59801 2018-12-07 14:05 ( Edited 2018-12-07 17:34)

@zep

I notice Benjamin Soulé's username doesn't show up right, even after your emoji fix.

See here:

https://lexaloffle.com/bbs/?tid=3421

Looks like this at my end:

It seems to work fine inside this post's text though.

Edit: Yeah, there's some kind of encoding issue, not a font issue, because if I copy and paste it here, it still comes out "Benjamin Soul´┐Ż", even though I was able to write it correctly above.

P#59792 2018-12-07 09:17 ( Edited 2018-12-07 09:21)

Re: https://twitter.com/johanpeitz/status/1024750757944410112

Cart [#54585#] | 2018-08-02 | No License | Embed

P#54586 2018-08-01 20:25 ( Edited 2018-08-02 00:25)

I've seen a lot of threads where people talk about using mini JSON (JavaScript Object Notation) parsers, but there are always caveats about the differences betwen JS and Lua.

I've prototyped a little parser for what I call LTN (Lua Table Notation, pronounced "loot'n"), which effectively gives you the ability to specify a Lua table's contents, in Lua source format, inside a string. For instance, if you had this:

player=
{
    name="lone wanderer",
    desc="alone.\nwandering.\n",
    x=123,
    y=456,
    attrs=
    {
        str=5,per=3,edr=5,chr=3,int=4,agi=3,lck=4,
        hp=100,mp=20
    }
}

You could swap out the outer curlies for Lua's multi-line string braces ("[[ ... ]]") and add a call to my parser, omitting the parens since it's a single string param and Lua lets you do that:

player=ltn
[[
    name="lone wanderer",
    desc="alone.\nwandering.\n",
    x=123,
    y=456,
    attrs=
    {
        str=5,per=3,edr=5,chr=3,int=4,agi=3,lck=4,
        hp=100,mp=20
    }
]]

This particular case saves 41 tokens.

Problem is, Lua's a bit squidgy as a language, so parsing its format, even with the assumption that everything is cleanly formatted and with support for comments and "[literal]=value" notation not included, costs about 310 tokens. (It's about 350-390 tokens with those, if you need either/both of them, but I think most people wouldn't.)

Would that be a decent quality-of-life tradeoff for anyone, allowing you just to swap Lua init code for a string representing it like that, but at the cost of 310+ tokens? It feels like a lot of tokens for a table parser, but on the other hand, sometimes you can afford to be a little spendy as long as it saves enough tokens overall AND saves you time reformatting the data.

Should I work on this further to clean it up and make it worthy of release? Or nah?


Technical notes:

One reason why my parser assumes everything is cleanly formatted is because you can test the formatting by swapping ltn[[]] back to {} and running it directly to test. I do have a version with error-checking, but again, it adds a lot of tokens to do that.

Also, I could probably make it a little smaller if I removed the option to specify a simple array table like this:

count_to_five_array=ltn[[1,2,3,4,5]]

Depends on whether a person needs to initialize arrays or just objects.

P#53817 2018-06-26 13:46 ( Edited 2018-06-27 17:58)

In the expandable textarea you get when you click Code under a cart, tabs are defaulting to 8 spaces, which is really ugly and rapidly pushes off of the right.

I found info here on how to fix it. If we assume that you're setting tabs to a default of 2 spaces in 0.1.12, then you'd want to do this for the code textarea:

style: -moz-tab-size: 2; -o-tab-size: 2; tab-size: 2;

Because intarwebz haz standardz. I mean, look at that crap. Not just three versions, but two start with hyphens. WTF.

You should also do this for the div surrounding [code]...[/code] regions of posts.

PS: Remember also to fix the broken glyph translation in the textarea.

P#53425 2018-06-09 16:36 ( Edited 2018-06-10 11:52)

I've noticed that with palt() you can leave off the boolean argument and it will default to true, letting you say "palt(11)" if you want index 11 to be transparent. Edit: Uh, turns out I was wrong about this, but the rest of this is still a good suggestion, and as I say below, it'd actually be nice if palt(x) did work this way as well.

There's no equivalent for pal() though. If you leave off the second argument, it acts like you didn't give any arguments and resets the entire palette.

Suggestion: It'd be nice if pal(x) simply acted like pal(x,x), a quick way to reset a single entry to default.

P#53303 2018-06-05 20:49 ( Edited 2018-06-07 04:08)

(Hoping to catch you before you finalize 0.1.12)

Similar to how I felt ceil() was missing from the fundamental math toolset in PICO-8, I feel like there are a couple of fundamentals missing from the table toolset.

Would it be reasonable to add these to the built-in table operators?

function ins(table, index, elem)
  local temp = elem
  while temp ~= nil do
    table[index],temp = temp,table[index]
    index = index + 1
  end
  return elem
end

function pop(table)
  local elem = table[#table]
  table[#table] = nil
  return elem
end

-- (and possibly this alias, just for the sake of being symmetrical with pop)
push = add

(Note that I was tempted to suggest an extension to add() where we simply append an optional index, but I've looked at the underlying code you have for add(), and I think the additional code to check for that optional index could slow down existing games too much, so it's probably better to have a new, bespoke ins() function instead.)

With just these two (and a half) additions, it becomes much more intuitive and simple to use tables as stacks, queues, and sets. I think that would be a real boon to both budding and established programmers without really taking the API to a higher level of abstraction.

P#53035 2018-05-26 11:44 ( Edited 2018-05-26 16:33)

I discovered tonight that the modulo (%) operator is treating the nadir value, 0x8000, as if it is positive, whereas other math ops treat it as negative:

> ?0x7ffe/10
3276.6
> ?0x7fff/10
3276.7
> ?0x8000/10
-3276.8            <-- as expected, -32768/10 == -3276.8
> ?0x8001/10
-3276.7
> ?0x8002/10
-3276.6

> ?0x7ffe%10
6
> ?0x7fff%10
7
> ?0x8000%10
8                  <-- unexpected, -32768%10 should be 2
> ?0x8001%10
3
> ?0x8002%10
4

I'm guessing this is an edge-case side effect of whatever you do to make modulo not flip directions at 0 (which I'm very glad you do).

P#52738 2018-05-14 14:57 ( Edited 2018-05-14 19:02)

Cabledragon was talking to me about perlin and simplex noise generation, and we were looking at various web pages on the subject. One of them was a novel implementation of a simplex noise generator, written by Kurt Spencer, a game dev who did not wish to be subject to Perlin's patent on his own version of simplex noise:

http://uniblock.tumblr.com/post/97868843242/noise

With a public-domain javascript implementation of 2D, 3D, and 4D noise here:

https://gist.github.com/kdotjpg/b1270127455a94ac5d19

The 3D and especially the 4D code is rather long and spaghettilike, though I suspect for good reason, but I noticed the 2D code was not too bad, really, so I took a pair of Lua shears to it and made it fit on our little platform.

It performs pretty well. It looks good, and while you can't efficiently use it to set every pixel on your screen, it's quite adequate for caching your terrain at app launch, or even for real-time generation of the area immediately around you, if you can be somewhat economical with how many times you sample the noise.

Note that, as mentioned in the code, the shell I wrote around this adaptation isn't particularly useful. It's just a custom-made and optimized-to-the-point-of-being-ugly viewer for the noise generator.

The generator code is on the second tab, and that's what you'll want to look at if you want to use it yourself.

Usage of the generator code is simple:

os2d_noise(seed)

  • Initializes the noise generator with the given seed. Different seeds produce different noise patterns.

os2d_eval(x,y)

  • Evaluate the noise pattern at x,y, returning a fraction between -1 and +1.

Edit: It's probably worth noting that the noise repeats, cleanly, at the length of the seed array generated by os2d_noise(). For larger fields, you'd want to increase the size of the array and accommodate that by adjusting the index masking that's done when referencing the array. I might actually make this configurable at some point.


Edit: Note that this demo is set up to show off the results as slickly as possible, not as a sample. If you want to see a sample usage case, where I also add multiple layers of noise for a more crinkly look, see a later comment below.

Here's the demo. Use ⬅️/➡️ to change the seed, ⬆️/⬇️ to change zoom, ❎ to cycle colors, 🅾️ for help. Note that it's slowly caching the zoomed images in the background, so zooming in quickly might produce some tearing at first.

Cart [#52171#] | 2018-04-30 | No License | Embed
15

V1.1: Turned off color cycling due to a complaint and put a toggle on X.

V1.2: Caching indicator, because communicating with the 0 users who run this is important!

P#52128 2018-04-29 05:16 ( Edited 2018-08-27 07:02)

So you've told us we can suppress the system pause menu with this:

poke(0x5f30,1)

And that works great. However, I wanted to write something that allows you to access both the game pause and the system pause, by using short presses for game pause and long presses for system pause. Unfortunately, there's a bug/misfeature/oversight that prevents this:

You're still debouncing the button at the system level, even if the system menu is disabled, so if the button is held down, it's only reported down on the first frame. This prevents me from detecting a long press.

I'm guessing this is just because you check the menu-suppression flag after you've recognized and absorbed the button press, rather than wrapping the button check as well.

Any chance of a fix in the next version? :)

P#52014 2018-04-25 14:19 ( Edited 2018-04-26 02:01)

I seem to recall that you said you might break some elements of backwards-compatibility in 0.2. If so, I have a request. I'm not sure it'd even break anything, to be honest.

Current PICO-8 executables allow the use of // instead of -- for comments. This has the unfortunate side effect of preventing us from using lua's // operator, which is the 'idiv' operator, e.g. a//b == flr(a/b).

I have never seen anyone upload code that uses "//" comments, so I think it might not even break anything. You'd probably know better, since you presumably have all of the uploaded carts in some kind of database. If nothing else, maybe you could disable it based on the version number you added to files recently?

It'd just be nice sometimes to use that operator, and if it's already supported but masked by the alternate comment form, I'd hope it wouldn't be a big chore to unmask it.

Thanks...

P#50570 2018-03-18 16:21 ( Edited 2018-03-21 12:48)

Converting shr() safely to simple math:

shr(v, 16) ==> v * 0x.0001
shr(v, 15) ==> v * 0x.0002
...
shr(v,  2) ==> v * 0x.4000 (or 0.25)
shr(v,  1) ==> v * 0x.8000 (or 0.5)

Multiplying by the fraction avoids a hazard where a negative number can go to 0 when dividing by numbers greater than 1, which destroys the sign-extending upper bits you expect to keep with shr().

It also allows shifts up to 16, whereas dividing only allows shifts up to 14. This is because PICO-8 can't represent any powers of 2 larger then 16384.

Similarly, because it is safe to divide by a fractional number less than 1, you can use the same idea to shift left up to 16 bits:

shl(v, 16) ==> v / 0x.0001
shl(v, 15) ==> v / 0x.0002
...
shl(v,  2) ==> v / 0x.4000 (or 0.25)
shl(v,  1) ==> v / 0x.8000 (or 0.5)

In this case, it's down to style or the need to shift by more than 14. Unlike dividing, multiplying by values greater than 1 is safe, so you can also obviously just convert shl(v,2) to v*4. PICO-8 performs divides as fast as multiplies, so performance is the same either way.

Basically, your safe bet is always to use the fractional power of two, whether dividing or multiplying. If you want to be sure, start your constant with "0x." and you'll always get it the right way around. :)

The reason some of us want to do this, rather than the more-intuitive shift calls, is that it saves one token per shift. That can add up quickly in a program heavy with binary math.

P#50047 2018-03-07 08:10 ( Edited 2018-03-07 15:32)

On yonder thread, where you wisely noted we should stop polluting its subject, you responded to me and said:

Static preprocessors like cpp are a weird fit for dynamic languages like Lua. For example, cpp-style includes have no order-dependent side effects in the languages they're used for (other than in the preprocessor macro language itself, I think?), so they can more simply insert code at first mention. This is not the case in Lua. Lua modules make the handling of side effects in the code explicit, so there's no confusion as to what a require() is expected to do. I'm very interested to know why a Pico-8 developer would prefer an #include-like to a require() because I can't think of a reason, as long as require() is implemented correctly.

Re: defines and such, I think what we actually want, especially in the context of Pico-8, is build-time constant folding and dead code elimination.

But we should take build tool discussion somewhere else, so people can use this thread to discuss Compos. :)

Well, I'm a C/C++ programmer at heart, and while I've certainly warmed to a lot of the dynamic aspects of non-static languages like python and Lua, I'm also aware of a lot of the inherent costs that zep tends to hide from us. I like to adhere to practices that wouldn't be suicidal, perf-wise, in a normal context, so long as they aren't detrimental in this context.

Abstraction and modularity have their uses, but when your resources are limited, sometimes they get in the way. The importance of being super flexible is only as important as the width of the path you're walking. Like, consider tweetcarts... a very narrow path, no use for flexibility, just have to walk the exact line the cart needs to walk, or you'll fall off.

A lot of senior programmers are very quick to mutter about premature optimization, and they're right to, but I think there needs to be a lot more muttering about premature generalization. I said to someone recently that you don't create an object to represent every pixel, with a getter and a setter, so obviously there's a point somewhere between reading the user's input and putting pixels on the screen where you stop trying to create general, re-usable solutions and start making specific, one-off solutions that will work best in the context.

Anyway, the most direct answer as to why I'd prefer an #include-like solution is that it simply has the least overhead in the final executable. I'm very good about being modular in terms of keeping things in separate files and independent, because I do like re-usability, but that means that there's a non-negligible token cost (as in dozens, easily) to having a function wrapped around every require()d file.

Oh, and yeah, constant folding would be amazing, but I won't hold my breath for zep to add that. He's clearly not going to upgrade the lua engine embedded in PICO-8. I'd love to have far more than just the folding. Actual binary ops (rather than functions) would be awesome, among other things. But I don't see it happening. So I thought I'd hit you up for more stopgap measures. :)

I also wish for something along the lines of inlining. Just the ability to express something as a function, when it should be a function, rather than having to manually inline it all over because each inlined instance is one or two tokens fewer than calling it, due to the simplicity of the function.

Hm, think that covers it.

BTW, I only put pizza in the title because I wanted another 'P' word. As it happens, I personally prefer pepperoni pizza.

P#49977 2018-03-05 14:35 ( Edited 2018-03-08 01:00)

Pretty sure when you originally added _update60(), you compensated for the doubled frame rate when returning time() values, but these days time() is running at double speed when you have _update60() instead of _update().

I noticed this when playing with a simple seven-segment-display demo. Here's one that uses update() and updates once per second as expected:

Cart [#49956#] | 2018-03-05 | License: CC4-BY-NC-SA | Embed

And this is the same cart, but switched to _update60() and runs twice as fast:

Cart [#49957#] | 2018-03-05 | License: CC4-BY-NC-SA | Embed

P#49958 2018-03-05 09:23 ( Edited 2018-03-05 14:24)

Adapting a solution found ca. page 180 of this white paper:

https://support.amd.com/TechDocs/25112.PDF

I finagled it into this PICO-8-specific form, which counts every bit (including fractional bits) in constant and pretty-brief time:

function popcount(v)
  v-=band(v*.5,0x5555.5555)
  v=band(v,0x3333.3333)+band(v*.25,0x3333.3333)
  return band((band(v+v*.0625,0x0f0f.0f0f)*0x0101.0101)*256,255)
end

It's a bit uglier than it would be in C/C++, but it's mostly the same operations, with a minor adaptation for the 16-bit shifts inherent in 16.16 fixed-point multiplies.

Just leaving it here in case anyone ever needs it.

PS: Apparently it's commonly called "popcount" or "popcnt", after an SSE instruction that does it. Basically, it's the population-of-1's count. Had no idea it had a name.

P#49855 2018-03-02 03:29 ( Edited 2018-03-02 08:29)

It's system/kernel/gpu time. Basically, it's all of the CPU time spent in code you can't see directly in the PICO-8 source editor.

If you have an app that does nothing but call cls() around 68 times, then both stat(1) and stat(2) will be around 1.0 at the end of your _draw() function.

If you have an app with an empty loop that iterates around 69905 times, and does nothing else, then stat(1) will be around 1.0 at the end of your _draw() function, but stat(2) will still be close to 0.

I can't believe it took me this long to work that out. :)

Caveat: I don't know exactly where the system/user border lies. Like, I haven't looked to see if what we think of as intrinsics, like abs() or flr(), are system time for the few cycles you're inside, or if they're considered user mode. Similarly, longer functions like sqrt()... could be system, could be user. I'll probably go through and figure them out at some point.

Honestly, it's not a very useful piece of information for practically anyone... even me... but it's been bugging me for aaaaages and I'm so glad I finally got a little 3-watt lightbulb over my head about it.

P#49660 2018-02-25 09:49 ( Edited 2018-02-25 14:51)

So if you've been around for a while, you've probably discovered that the PICO-8 call mid(a,b,c) can be used for clamping values to a range. The middle value in a set of (lo,val,hi) once you put them in order will either be val if it's between lo and hi, or if it's beyond, either lo or hi will be the middle. That's a clamp.

-- change volume but keep it in range
volume = mid(0, volume + volume_adj, 1)

It's convenient, if a little unintuitive. Some folks might alias the function to make it read better:

clamp = mid

-- change volume but keep it in range
volume = clamp(0, volume + volume_adj, 1)

Problem is, it's three args and each arg slows you down a bit. In most cases, one end of the range is 0. If you're writing a really tight inner loop, sometimes it'd be nice if you just had a function that assumed 0 for the top or bottom, instead of you having to pass it.

But wait! A useful bit of info is that PICO-8 API calls usually accept nil, or a missing arg, as if it were 0. For instance, x=cos() sets x to cos(0), or 1. Not useful for sin/cos, but...

Since mid() doesn't care what order the arguments are in, we can just leave off the third argument to implicitly pass it a 0 that way:

-- change volume but keep it in range
volume = mid(volume + volume_adj, 1)

For cycle counters out there, mid() with two local variables passed as args costs 5 cycles, vs 6 cycles with three.

And remember, it doesn't have to be the bottom end. If you're clamping -1..0, that works too:

-- change the decay rate
decay = mid(-1, decay + decay_adj)

Following on from this, if you know your value is moving towards 0, but must stop AT 0, then you can use the same trick with min() and max():

-- slow down until we stop (velocity==0)
velocity = max(velocity - friction)

-- swim back to the surface
depth = min(depth + desperation)

In both cases, you're implicitly passing a '0' as the second argument. This, again, saves you 1 cycle in each case, with single-arg min and max being 4 cycles instead of 5 for double-args.

P#49652 2018-02-25 05:46 ( Edited 2018-03-01 18:05)

So, while it might be inconvenient for use in proper math, I've really come to love tho 0-360° → 0-1 units on PICO-8 for trig functions (sin, cos).

I've never been sure what to call them, though. They're not degrees, they're not radians, they're not gradians, etc.

I think I came up with a good name.

A "radian" is called that because the angle is expressed as how many radiuses of a unit circle you have to move around that circle's circumference to get to the desired angle. Like, on a circle of any given radius, you have to literally move a distance of 2*pi radiuses around the circle to go a full 360° and end up where you started. A radian is such a distance, but specifically on a circle of radius 1.

So if a radian is an expression of how many radiuses we move around the circle, and PICO-8's units represent how much of the circumference (or how many circumferences) we've moved around the circle, then the unit should be named something to do with the circumference.

"Circumferans" and "circians" don't really work for me. I also considered twopidians, but that's also kinda awkward.

But then, I remembered my discovery of how much better it usually is to use tau in most trig math. Tau, if you don't know, is just another name for 2*pi. One tau is basically one trip around the circle. Tau usually produces cleaner math because it doesn't involve that pesky constant.

(For more on tau, see this classic piece by Vi Hart: https://www.youtube.com/watch?v=jG7vhMMXagQ)

Thus, I propose: taudians

I think it works. Feels okay, it's actually kinda cute, and it's literally a correct way to describe the unit.

Thoughts? :)

( @zep?)

P#49352 2018-02-16 23:49 ( Edited 2018-02-17 20:51)

Would you mind tweaking the token counter so that these two statements...

x = -1
y =  1

...use the same number of tokens each?

It's frustrating that we lose a token to the unary minus on number literals.

I could rewrite that code with hex to save a token...

x = 0xffff
y = 1

...but that's ugly, non-portable code.

Basically, just elide any unary minus token if it's being applied to a number literal.

Please?

P#49267 2018-02-13 22:19 ( Edited 2018-02-15 00:12)

I suspect this is to do with how lua thinks it can trust numbers vs. how the pico-8 fixed-point numbers are limited, but I'm not sure that's actually the reason. See the end of this post for why I think so.

A for loop will fail, hard, if the end point is -32768 (0x8000.0000), which is a valid (albeit icky) value in PICO-8's fixed-point system:

> for i=-32766,-32768,-1 do print(i) end
-32766
-32767
-32768
32767
32766
32765
... this is the loop that never ends, it just goes on and on my friend ...

This works correctly when hitting the upper bound:

> for i=32766,32767 do print(i) end
32766
32767
> _

If you reverse the params to for, it also fails, but in a different way:

> for i=-32768,-32766 do print(i) end
> _

The same loop works if it starts one higher:

> for i=-32767,-32766 do print(i) end
-32767
-32766
> _

What's weird is that the wrapping of fixed-point values doesn't hurt the loop at the top end, so I'm not clear on why it fails at the bottom end. If it was just a wrapping issue it ought to happen at both ends. That's why I'm not sure it's about lua expecting to be safe doing math beyond the endpoint. Maybe you treat 0x8000 in special ways?

I hope you'll know what's up here, @zep.

P#49152 2018-02-11 02:39 ( Edited 2018-02-11 07:51)

View Older Posts
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-12-12 13:08 | 0.100s | 4194k | Q:86