I’m working on a gameplay prototype for one of my projects, something i needed (or perhaps really just wanted,) was to be able to draw lines and circles for diagnostic purposes. Turns out what i need for that is “SDL_gfx” a pretty decent collection of routines which has lots of primitives support and also includes a framerate limiter and scale/rotate functions for surfaces. This all sounded simply super, i was excited and went to the website.
You are currently browsing the archive for the Programming category.
I’ve been working on pieces of code over the past couple of weeks that will come together to form a codebase that i intend to work from for future projects, part of that was writing some dual analogue joypad input code. I was pretty miffed at the apparent lack of example code or tutorials on this specific requirement, so I’ve decided to make some example code with just the stuff required to make it work and post it on this site, not just this joypad code, but some other stuff like a simple timer and more like that.
I don’t know when this will be, and i don’t claim to be an expert, but what i have so far works, and if i can keep it free of confusing additional elements, maybe it can help others.
The upshot of my latest efforts, as i suggested previously, is that i have a nice dual analogue joypad routine for AstroLiger
There’s more, but its dull, even to me.
So I did some work on a timer. There’s actually some timer stuff in SDL which I’ve read about and decided not to go for and there is also a timer object in the SDL_gfx lib I’ve been thinking about using, but in the end I thought it would be best if I did what I wanted regardless of everyone’s experience in the matter. How glad I am that I did!
Actually, I’ll probably abandon my timer when it proves to be as shit as I suspect, but I’ll forge along and try it in the game anyway because;
A. it actually does what I intended it to, and
B. the alternative in SDL_gfx is actually fairly straightforward to implement and I think its important to see why mine is a bad idea before abandoning it first.
Why do I think I did a bad job? Well, what I understand of timing is after all the game logic is called, you call the timer, this takes the framerate you desire, works out the fractions of a second this splits into then halts the loop till it hits the next interval this corresponds to.
Looking back, I guess that’s fine, people use this method for a reason and its not like games are a new technology that’s full of unproven concepts, but without a clear understanding of what it was all about, it seemed a waste of computing power. Instead, I came up with this fantastic idea where the computer just runs the game as fast as is possible, and only updates when that fractional timing trigger is fired. This I was sure was the winner and so I set off to implement it. And in fairness, it works exactly as I intended, except obviously its using awe inspiring quantities of cpu time.
I’m in the process of turning my prototype into a class which I can use, one of the nice things about it is that I’ll be able to have multiple timers with different framerates within the code without any real complexity, I’m not sure if there’s any benefit to that at all, its why I’m going to carry on and see what a real-world implementation does.
One thing it did teach me, which makes the whole exercise worthwhile, is how timing in C++ and game programming works, this more than any tutorial I could find was very useful.
I really fancy the idea of adding online gaming to Atoms, of course, i’ve never done any network code before and i’m unsure how to persue this.
A friend (Goldbuick,) advised enet, i’ll certainly take a look, but does anyone know of a really basic networking lib for C++ thats not going to bloat my game and make my head explode? Good tutorials or examples would be a must.
Thanks ![]()