top of page
Search

[65] Cancelling My Appointments

  • Writer: Conlan Walker
    Conlan Walker
  • Jan 12, 2023
  • 2 min read

Originally, I was going to dedicate this week to setting up bindings for libmikmod, but I noticed that music modules stop playing when focus is lost, or on a window. I can't really use it until I fix that issue, and I really hope the solution doesn't involve writing my own libmikmod sound driver or module loader.


Though to use libmikmod in the first place, I needed a way to compile it. I don't really have much experience compiling libraries, partially due to the janky nature of how my computer is organized. CMake is a popular tool for creating makefile setups, but I needed some type of make tool first. nmake seemed to be the default one chosen by my installation of CMake, but I needed Visual Studio first. I spent pretty much the entirety of Monday just clearing up some space on my hard drive so I could afford the 4 gigs that seemed to be necessary.

ree

This is approximately the minimum amount of space I needed to give up so that this beached whale Microsoft calls an IDE can do the one thing I wanted it to.

The important thing is it actually worked, and I was able to compile libmikmod. Though, as I said previously, I ran into a hiccup with regard to conflictions with SDL, so I'll focus on other things until I can solve/work around the problem.



After that, I decided to work on event handling, as that would give me the ability to detect keyboard/joystick input, alongside many other things. I decided that a function dedicated to adding elements of an array to a lua table would help out a lot, so I spent a good day making that, and I learned a good deal about type handling, as well as anonymous unions.

Half of that function ( tableFillWithArray() ) is just bringing the last subtable to the top of the stack, so here's the more important half of it:

ree

After that was made, code size for binding stuff shrank, while also being more convenient.

All of that commented out code is replaced with just 2 calls to tableFillWithArray().

ree


The event handling itself took a great deal of time, as I had to become familiar with Lua iterators in the context of the C API, as there is no documentation about that specifically, as well as how C closures are done in Lua, as I wanted to pass an argument to the iterator.

The iterator function is pretty large and confusing to look at, so I'll show a good representative sample. Below is just the keyboard "KeyDown " and "KeyUp" event handler:

(Also, this is the first time that I've used C labels and "goto" before.)

ree

This is inside a switch statement, and most of it is comprised of macros. Here are the definitions of the important ones, which should give a better idea of how this is all structured:

ree

Once the iterator was done, I wanted to show it working, so here's a test that demonstrates "KeyDown" events. Every time a key is pressed, a Tim Allen grunt plays at a random speed:

ree

(Note how many of them can be played at once without issue.)

And here's a video of the above code actually running:



With all of the new stuff added, here's the total size of everything right now:

ree

And that's it for this week.

 
 
 

Comments


bottom of page