Show HN: Lyceum – An MMO game built with Zig and Erlang (github.com)
Hey HN, this is a small project myself and closer friends have been building on our free time (https://github.com/Dr-Nekoma/lyceum), it finally reached 0.1.0, we are open to feedback!
The original idea was to experiment with Zig + Raylib, eventually we wrote a small server in Erlang as well. We started by first interacting with Erlang via its C bindings, but this eventually led to some of us to prototyping our own tooling to better integrate Zig types with Erlang, we called such tool "zerl" as its avaliable here https://github.com/dont-rely-on-nulls/zerl.
Most of the developers are NixOS users, so the tooling heavily relies on Nix as well, including a Postgres running our devshell as well.
71 comments
[ 4.3 ms ] story [ 141 ms ] threadWhat does "supercharged" mean here? I'd guess raylib simply does all the rendering and input handling, what is it "supercharging" here?
https://www.youtube.com/watch?v=ejYcWRERetM&t=2758s
Here's what the game consists rn
I can't give feedback on the code/technology, but on the writing on the lore section, I would try to simplify the writing. For instance the following:
> The reverberations of the trumpet stirred the knights from their deep repose, igniting a tumultuous awakening. With swords unsheathed and hearts ablaze, they clashed in a thunderous symphony of war, each seeking to claim dominance over the waking realm.
Feels too ornate (purple prose) and could be more directly put as:
> The trumpet’s call jolted the knights from their rest. Swords drawn and hearts alight, they clashed in a fierce battle, each striving for dominance.
I'm not an author or anything, but a little bit of copy writing could help - although this might just be me as it's probably a matter of personal taste!
I've thought about this before when I revisited fantasy after years of being in the CS domain which helped me abhor ornate writing. I definitely think there is such thing as TOO ornate but dead-simple language also feels bad. It feels wrong to just say its an exception with fantasy - simplicity is good because it conveys the same thing more clearly and with less effort. I would think that transcends all domains. Still not sure how I feel about this. I guess there is a baseline non-styled language that is all about communicating raw info and then there is style that can be applied to writing which makes it feel more natural in different domains.
Having said all this, I actually do like your example more.
Although not-ornate doesn't necessarily mean dead-simple or bad. For instance compare the following:
> The reverberations of the trumpet stirred the knights from their deep repose, igniting a tumultuous awakening.
With a very similar sentence from Tolkein:
> At that moment, among the trees nearby, a horn rang out. It rent the night like fire on a hill-top. Awake! Fear! Fire! Foes! Awake!
This is much less ornate, with simpler language, yet easier to parse and the image is much more vivid.
> The reverberations of the trumpet stirred the knights from their deep repose, igniting a tumultuous awakening. With swords unsheathed and hearts ablaze, they clashed in a thunderous symphony of war, each seeking to claim dominance over the waking realm.
there's a distinct feeling of disconnect, I guess? That language feels much more appropriate, when say, you're on top of a mountain and admiring the beautiful landscape around you. Tolkein's words capture the urgency and adrenaline of war with his simpler sentences.
I suppose I'd need to see the context behind the original quote; in a historical lore recap, I'm more happy with that quote.
(Not going to pretend like I know precisely what's different as it's all subjective, but I suspect the mood you're trying to go for heavily impacts your writing choice)
Therefore for not-so-important details like “the knight woke up” that are just about giving the reader necessary info to follow along, it’s generally better to put less weight and emphasis by stating it plainly. This way when you do add emphasis to make the reader visualize a crucial scene or situation, or describe emotional states at these moments etc, they will jump out as being special rather than just more of the same.
In my experience, every great writer follows this pattern, though they begin at different baselines. It’s fundamental to good writing, just like creating attention hierarchy is fundamental to good graphic design.
In addition, each one must be described in detail, including a potted life story of the blacksmith that created it; when, why, and for whom; metallurgical observations; history of actual use; any supernatural blessings whether apocryphal or actual; the litany of families that have retained it as an heirloom & their subsequent social or political fates; details of any inscription or filigree; and a nickname. This remains true for both the swords and the trumpet. Additional remarks concerning a scabbard or case are optional but highly regarded.
I'm curious about Erlang server, do you see any advantage or features that Erlang provides, compared to for example if the server was running in Python via multiple instances?
Given the experience so far, it seems that using Erlang was the correct choice, not only because of the above, but also because Erlang made the server implementation way easier than we thought.
In my experience the issues with Erlang come with working with data structures, records are not flexible and there is not much one can do to abstract the boilerplate.
I gotta say though that lack of infix custom operators for the monadic bind is a pain.
Also, Elixir supports macros and infix operator overloading - have you considered using it? If you know Erlang's stdlib and BEAM, switching to Elixir (and back) is almost painless. Not sure which monads you needed, but `with` macro is built-in, and it's a monadic bind for Option types (well, more or less). Adapting it for other monads shouldn't be hard.
As far as I can tell, this is not possible at all; the serialization layer (Zerl) cannot send arbitrary code to another node. Now, assuming we implement this, I also think this is not possible due to how the server is designed; based on supervisors and child processes for user sessions.
We recently became aware that you can indeed send tuples that have fixed effects when using the supervisor behavior, so it may be totally possible and probable that one could exploit this vulnerability to some degree in our server. We plan to investigate more about it as we continue to learn more about OTP and the BEAM.
With stock OTP dist, there is no barrier between nodes. Stock OTP runs an rpc server that you can use to send function calls to run, which can include BEAM code to load (or file I/O to do); and even if that's disabled, you can spawn a process to run a function with arguments on a remote node without needing an rpc server at all.
It'd be much simpler to put together a custom protocol to communicate between the client and server. You could use Erlang's External Term Format to exchange data if you want, in which case you'd want to do binary_to_term(Binary, [safe]) to prevent creation of new atoms and new function references which can fill up tables and also consider that just because deserializing is safe for the runtime doesn't mean you can trust the client.
Erlang makes it pretty easy to parse sensible things off of network sockets, if you want to go more custom, too. Binary pattern matching is lovely.
[1] https://erlangforums.com/t/rfc-erlang-dist-security-filterin...
Additional applications for dist have been explored over the years, but most of them involve clustering servers; where a security barrier isn't necessary; although it might be desirable --- I've used dist clusters where some people had access to only certain types of nodes; bypassing access control using dist clustering was certainly a possibility. Bolting security onto something designed without it often is pretty challenging. Especially if you want to keep all the existing applications working.
For example, several of the gRPC libs I've used for Erlang/Elixir are pretty low-cognitive-overhead to use, and they come with all the added gRPC goodies: RPC semantics are described in one place rather than ad-hoc throughout code, protobufs have at least a documented (if not actually good) process for upgrades and backwards compatibility, multilanguage gets easier (even if your second language is just a tiny sliver of "dump protobufs into a database/Jupyter notebook/Rust program occasionally for offline reporting").
To be clear, this isn't a paean to gRPC; most of those features are table stakes for an IDL-driven protocol definition. Just saying that you do get some things in return for giving up the convenience of OTP, if you pick the right tools.
Indeed a malicious client can craft an brutal kill message as long as it knows the PID a process (either a worker or a supervisor) for instance.
How do you feel about devenv vs stock Nix? How are you getting devenv to work, as I don't see a devenv.nix file. I'm still a Nix beginner and would like to find ways of integrating it more into my development and improving my current techniques.[0]
[0] https://mtlynch.io/notes/nix-dev-environment/
It's great if you like local-first development experience.
I now see that you're using devenv from within your flake.nix, which I didn't realize you could do.[0] Neat!
I'm going to give that a spin in my projects, as my current solution for pinning versions of Go, Zig, etc. is to use nixhub to look up which commit of nixpkgs corresponds to which version of Go (e.g., Go 1.23.2 is nixpkgs version 4ae2e647537bcdbb82265469442713d066675275). That's obviously a pain to look up and performs poorly, so I'm curious to see how devenv goes.
Thanks for sharing the source!
[0] https://github.com/Dr-Nekoma/lyceum/blob/1b0acf2d4bf295135bb...
I've actually written about the process that led us to use the following flake here: https://mtrsk.github.io/blog/2024/experiments-with-erlang-an...
Edit: currently with the game running at 60fps, there is no bottleneck from the server side. And we call it every 16ms! I should also mention that Erlang's choice has a learning purpose; we want to try to use the game as a way to learn more about OTP and the BEAM.
Hot loading is pretty nice too.
Maybe you could simulate different parts of the game world on different physical servers.
I think this is something like what the Very Large MMOs do, but with Erlang it might be easier.
You can also check it out a little demo: https://www.youtube.com/watch?v=ejYcWRERetM&t=2758s