Monday, January 15, 2018

Programming on Accident

In my flurry of flu I attempted to make a little head way doing some much needed replacement of console and POSIX functions. The goal is to get rid of as many dependencies as I can and have Allegro as my core library for input and an output. As I wrote I was bent on getting rid of some very legacy console functions. Namely _kbhit() and _getch(). (Hello there underscore functions!)

It seemed simple. All _kbhit() did was return a 1 if there was a key in the keyboard queue, and a 0 of not. _getch() just grabs the next character in the queue. The problem I was having was I replaced the BIOS keyboard queue with Allegro's to get things functional. However, the new keyboard queue holds MUCH more than just what key was pressed. It also holds, in order, the key down and key up events. So just because something is waiting in the queue, doen't necessarily mean it's a character. I flailed with this for a while, making implementations of _kbhit() and _getch() that worked "good enough" while at the same time goofing up my keyboard queue. I got it to work in my test unit, and then when it was in the game, failed massively.

I was programming on accident.

For those who don't know, this is when you code without any idea what you are doing in hopes that it works. The problem is that if you do this, and the program breaks later, you have no idea what's wrong or how to fix it. It was also frustrating myself as I couldn't seem to get two fairly simple functions to work properly. I was pointed in the right direction with some help on a forum. Turns out I wasn't follow my logic properly. The cool thing was as long as I showed off my example code and made it obvious I was making an effort, people were bending over backwards to help and explain what I was doing wrong. Thumbs up!

The old paperdoll, layered in GIMP.
After I got my mojo back. I got rid of the master timer from time.h and moved that to Allegro's internal timer. I'm trying my best to do "drop in" replacements of the commands. Now I no longer need clock(), clock_t struct, or time.h  and have replaced those with my own functionality  as well.

Moving on I'm now working on the paper dolls that represent the commanders in the game. I'm fixing up the poses and character designs, but keeping the uniforms mostly the same. I'll do some initial character designs on my own, but may need backup if it's a little too time consuming.

No comments:

Post a Comment