Whoops, I haven't written what I'm doing for a while lol
Currently, I'm working on a ncurses based action-adventure game. Here's the title screen:
The name "Dungeon" is a prototype name, as I don't really know what to name it yet. Maybe "Vetera Peccata" which is latin for "Old Sins", since that would make sense for the story I have planned, but we'll see.
Achievements So Far:
Portable getopt_long
Annoyingly, getopt_long
is not a portable function, and behaves differently on all platforms, because unlike getopt
,
it's not a POSIX standard. In order to achieve a consistent getopt_long
, I went into the NetBSD source code, and
maybe kind of yoinked ported the code, and created tngetopt.
Since I did not change, well, anything, I made it the same license as NetBSD, which is BSD 2-clause. So thanks to the NetBSD devs! So far, it's tested on Linux, but I want to make sure it works on Windows and Mac eventually...
OOP in C
I've gotten better at doing OOP in C, most things are abstracted behind an object in the code base. It's pretty good to
use outside of having to pass the object itself to the function everytime. So code will look like: obj.add_item(&obj, "item");
but that's a very minor issue.
Learning Vim as my IDE.
In order to wean myself off of relying on auto-completion, I went all in on using an extremely simple vim config.
It only has 1 real plugin, and that's ALE. ALE does some busy work for me, such as
running clang-format and giving me compiler errors while working, but it doesn't auto-complete unless I do CTRL-P
, which is
default Vim behavior.
Getting the hang of XML parsing and creation in C
In a proper OOP language, XML is easy. But in C... yeah, not so much. So a large portion of my time was spend creating an object to abstract the mess that is parsing XML in C. (Credit to libxml2 for making this a little less painful).
For reading the document, I rely on XPath
, which makes querying the XML almost like it's a filesystem. And as for creating
a node, all I do is pass an array of strings to functions such as add_node
or add_attr
and it'll create the node. Then you
just use XPath to set the value.
Not as easy as C#'s XML functions or Vala's libxml2 binding, but hey, I got it working.
Mastering memeory allocation.
One thing i've always been scared by in C, is manual memory management. You want to resize an array? Well, you gotta allocate the memory and initialize it yourself. The first real experiment I did with it was in my Sound sub-system, where I needed to create a table of already loaded sounds, so when a sound is loaded, it's only loaded once, rather than everytime I play the sound.
And past self was not a fan, here's a code snippet. =P
// Resize the table to contain the new entry.
// I HATE IT I HATE IT I HATE IT I HATE IT I HATE IT I HATE IT
SOUND_TAB = realloc(SOUND_TAB, sizeof(_SoundEntry *) * (SOUND_TAB_SIZE + 1));
SOUND_TAB[SOUND_TAB_SIZE - 1] = malloc(sizeof(_SoundEntry));
Embracing (GNU) Make
When I first started making the project, I used Meson, and don't get me wrong, if you're
a large project doing things like: tests, heavy subprojects usage, multi-language projects and building thousands of
source files... you probably want to stick with a build system like Meson or CMake. But for me, I realized all I was
using Meson for, was a glorified and dependency heavy pkg-config
caller. I realized I can just use pkg-config
myself in a standard Makefile. I decided to use GNU Make, since it has some directives I consider pretty useful, and
I like the syntax of it better than BSD Make (Sorry BSD). After reading the docs, and asking Google's Gemini to
help me undestand target dependencies, I had a working Makefile that was pretty portable. From there, I added
some scripts to it to make static linking a lot easier, and also added a pretty ninja-like source counter. I think I may need
make a script for handling some of the other cflags, such as fstack-protector, but we'll see.
Okay, but why C?
I like C, and it's a fun challenge. And since it's a single player offline game, memory safety isn't the biggest deal in the world outside of memory leaks.
Where da source code?
Not public yet, as I want to finish an early alpha before making it public. It's source code will be under an AGPL-3.0 license.
So far, as of writing this, this is the checklist for releasing an alpha:
[x] Handle CLI Options.
[x] Get Sound Working.
[x] Get and Create program directories (~/.config/net.iotib.DungeonV4)
[ ] Get level editor working, and create and load .lvl files as needed. (.lvl files are just xz XML files)
[ ] Create player, and get it working.
[ ] Create basic enemy types.
[ ] Create a demo dungeon.