[65] Cancelling My Appointments
- 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.

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:

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().

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.)

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:

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:

(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:

And that's it for this week.

![[158] Most Important Brick in the Least Important Wall](https://static.wixstatic.com/media/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg/v1/fill/w_980,h_410,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_f70be6ae4318455fbbc605cd1069c6ee~mv2.jpg)
![[157] Mail Order Sacrifice](https://static.wixstatic.com/media/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png/v1/fill/w_980,h_382,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_e284fa6c51b04524bab9d3cf9f1f6441~mv2.png)
![[156] Moat of Babble](https://static.wixstatic.com/media/df100d_091e451794b14aecb494a16c15c966c3~mv2.png/v1/fill/w_980,h_705,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/df100d_091e451794b14aecb494a16c15c966c3~mv2.png)
Comments