Skip to main content

News

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Fat Cerberus

1
This sounds pretty much like the first few text-based games I ever wrote in QBasic.  Variables?  Functions?  What are they?  It was pretty much just a long string of IF..THEN and GOTO for each relevant input :P

Of course mine weren't roguelikes.  To code a whole roguelike like that... that's impressive.
2
The first proof of concept of Oozaru is up (running the Spectacles battle engine), check it out:


Consider this Alpha 1.  I won't call it a beta, since it's not quite feature-complete yet; sizeable portions of the Sphere v2 API are completely missing and/or inoperable.  Like, the Joystick class exists, but all methods are no-ops.  And almost the entire FS API is missing... that kind of thing.
3
Programming / Re: So I wrote a monad tutorial...
Well, I mean, I do expect people reading a monad tutorial to have existing programming background, that goes without saying.  I will say that I think imperative programmers are better equipped to understand them than functional programmers actually, since we're the ones writing all the boilerplate in the first place.  Think of your Link.js library and the problem it solves :)

Programmer-to-programmer: the thing is, the monad concept itself is not actually complicated, people just make it seem that way - sure, individual monad types are complex (promises, e.g.), but the monad interface is ridiculously simple:

Code: [Select]
// entangle/unit/pure/return
let arr = Array.of(1, 2, 3);
let m = new Maybe("foo");
let prom = Promise.resolve(812);

// map
arr = arr.map(x => x * 2);  // we know what this does
m = m.map(s => s + "bar");  // maybe it has a value, maybe not - it's a no-op if not
prom = prom.then(value => newValue);  // just map to new value, no async shenanigans

// flatmap/chain/bind/thru
prom.then(result => new Promise(...));  // promise chaining
m.thru(value => new Maybe(result)); /* alternatively, Maybe.Empty */);  // maybe it can fail
arr.flatMap(elem => Array.of(...));  // one-to-many mapping

That's it.  If you implement that interface and satisfy the identity laws, it's a monad.  Literally.  That's all that's required.  It doesn't matter what kind of abstraction it's an interface *to* (promises, arrays, maybes, eaty pigs...), you just need to implement the interface.  The main thing is that the pattern this interface represents already exists in "nature"--you have to train yourself to recognize it though, and that's the actual hard part.
4
Programming / So I wrote a monad tutorial...
I recently learned what monads are, and predictably, had just as much trouble "getting it" as everyone else.  But they're not actually cursed; it's an extremely simple concept, it's just that everyone either 1) Tries to explain the mathematical background, which is not necessary (You don't need to know anything about set theory to add two numbers!), 2) Uses a bunch of Haskell code which is gibberish to imperative/OOP programmers, or 3) Starts with a box metaphor, which is just in medias res non-sequitur: you have to explain why the boxes are there first!

Long story short, I'm pretty sure I can break the curse.  Here's my monad tutorial:
https://gist.github.com/fatcerberus/beae4d15842071eab24fca2f0740c2ef
5
Hellos and Byes / Re: Happy 2019!
Funny enough, when I wrote that "new years pig" comment I didn't actually realize that 2019 is the Year of the Pig according to the Chinese zodiac.  Yay hilarious coincidences!
6
Sphere General / Re: What is SFXR?
I didn't write that mp3 decoder, that was from this project:
https://github.com/audiocogs/mp3.js

SoundStream itself is really simple to use, you just specify your sample rate and feed it raw PCM audio.  Here's the API:
https://github.com/fatcerberus/minisphere/blob/master/docs/sphere2-core-api.txt#L2012-L2062
7
Hellos and Byes / Re: Happy 2019!
Happy New Year!  Hopefully nobody gets eaten by the new years pig (it's like the baby new year but eatier). :tada: :confetti_ball: :pig_nose:
8
Sphere General / Re: What is SFXR?
I think at this point, now that we're using ChakraCore instead of Duktape, I would probably want to implement something like this in JavaScript, on top of SoundStream, rather than bloating the Core API with what is really high-level functionality.  Then it would even work in Oozaru (which also implements SoundStream) without further code changes.
9
Engine Development / Re: miniSphere 5.3.0
miniSphere 5.3.0 has just been released and is now available for download.  This version brings a ton of new APIs, a brand-new, faster version of from.js rewritten from the ground up, bumps the API level to 2, brings back support for 32-bit versions of Windows in the official release, adjusts script-loading semantics to allow using .js for modules (it's like a long lost friend coming back home :P), and so much more.

Be extra sure to check out the Release Notes for this release before getting started, as there are several potentially breaking changes due to modified semantics in a few places (the Core API remains backward compatible, as promised by the mS 5.0.0 API freeze).  And for Windows users, as always with milestone releases, uninstall your previous version of miniSphere before installing 5.3.0 to ensure all stale files get removed.

Merry Christmas everybody!
:santa: :christmas_tree::gift:
10
Engine Development / Re: miniSphere 5.3.0 RC1
miniSphere 5.3.0 RC1 is now available for download!  This is a release candidate, which means the code is essentially frozen; no further changes will be made other than bug fixes for 5.3.  If no major issues are reported, this exact build will become the final version of miniSphere 5.3.0.

There's way too much new stuff to list here (5.3 ended up way bigger than I originally planned), so just check out the release notes on GitHub:
https://github.com/fatcerberus/minisphere/releases/tag/v5.3rc1
11
miniSphere 5.3 release is very close - just a few more API kinks I have to work out but otherwise everything is ready to go.

I even made a last-minute API addition: you'll be able to create custom BlendOps to have better control over the blending stage of the graphics pipeline.  This is something that can't be handled in the fragment shader at all--blending is still fixed-function even on modern hardware.
12
So when I said above that from queries would be blazing fast, I meant it, and to prove it I've done a quick benchmark of other similar solutions:
Code: (javascript) [Select]
let fromQuery = new Query()
.where(it => it % 2 === 0)
.take(10000)
.select(it => it + 1)
.reduce((a, it) => a + it, 0);
Code: [Select]
 event                    count   time (us)   % run  avg (us)    % avg |
------------------------------------------------------------------------
 Array method chain       1,001   3,605,798  34.1 %     3,602   34.3 % |
 Underscore chain         1,001   2,065,016  19.5 %     2,062   19.6 % |
 Lodash chain             1,001   1,168,390  11.0 %     1,167   11.1 % |
 from.js 1.0              1,001     903,805   8.5 %       902    8.6 % |
 from.ts (Oozaru)         1,001     875,786   8.3 %       874    8.3 % |
 Link.js query            1,001     475,447   4.5 %       474    4.5 % |
 Link.js query (NR)       1,001     325,084   3.1 %       324    3.1 % |
 from.js 2.0              1,001     319,423   3.0 %       319    3.0 % |
 Lazy.js sequence         1,001     270,130   2.6 %       269    2.6 % |
 Sphere from() query      1,001     205,757   1.9 %       205    2.0 % |
 Sphere Query object      1,001     188,966   1.8 %       188    1.8 % |
 handwritten 'for' loop   1,001     119,092   1.1 %       118    1.1 % |

Sphere from() query and Sphere Query object is us!  All timings are for running a chain equivalent to the above query 1,000 times with the respective library over an array of 100,000 random integers between 0 and 1000.

Special thanks to @Radnen for (indirectly) giving me the idea - Link.js was touted as a replacement for writing repetitive for loops, which got me to thinking... what if I just compile the query to an actual for loop...

This is really incredible that I was able to get so close to native loop performance and is a big win for code readability.  Query chains remain understandable even with 10+ query operators chained together, but throw together a couple filters and mappings plus a sort (or two!) and the set of for loops you need to write to match it can get pretty gnarly.  Lodash is proof people are willing to sacrifice a great deal of performance to get more readable code (see benchmark results above), even in tight loops where it matters most, but it's even better if you don't have to. :smiley_cat:
13
Starting in miniSphere 5.3, from() will be built into the Core API without the need to import the "from" module.  Like @Radnen 's Link.js library that came before it, from() queries are often incredibly useful in battle engines, and now I've written some code in the engine to compile these queries directly to JS for super-fast performance.

Code: (JavaScript) [Select]
let dinnerAmount = from(worldPopulation)
    .where(it => pig.isHungryFor(it))
    .besides(it => pig.devour(it))
    .reduce((a, it) => a + it.weight, 0);
SSj.log(`the pig just gained ${dinnerAmount} lbs.`);
14
Engine Development / Re: Oozaru: Sphere for the Web
I finally got SoundStream working today!  It took me forever to get it right and in the process I had to learn how to do sample rate conversion, but now Oozaru can run the sphere-mp3 demo (with a couple small code tweaks to accommodate for the lack of synchronous file loading).

Next I'm going to see about getting this thing to work in other browsers besides just Chrome.  This isn't the late 90s/early 2000s after all. :P
15
Engine Development / Re: Oozaru: Sphere for the Web
What kind of functions do you have in mind?