Blinking Cursors

When having some sort of keyboard input it is always helpful to have a blinking cursor, so that the user knows where he/she/it is typing. This is usually shown by a blinking pipe ‘|’ or underscore ‘_’ symbol. In my current asteroids I didn’t bother with the blinking and simply appended a static underscore to the current input. However I was just reading a nice post about immediate GUIs at http://sol.gfxile.net/imgui/ch01.html (very interesting way of programming a game user interface!), which also had a very nice trick to have a blinking mouse cursor with pretty much no effort. You find it in chapter 7 of that tutorial.

The trick is:

std::string name_output (mPlayerNameInput);
if (SDL_GetTicks() >> 8 & 1)
	name_output += "_";
DrawGLString(xpos, ypos, name_output.c_str());

SDL_GetTicks() is the time function of the SDL library and simply returns the number of milliseconds passed since the initialization of the SDL library. By shifting the value of the function to the right by 8, the resulting expression in line 2 alternates now between true and false each 256 milliseconds. If you want the blinking every half seconds, shift it by 9 bits.

Awesome!

Wolfire Blog and Humble Indie Bundle

I just stumbled over a nice blog called the Wolfire Blog from the independent game studio Wolfire Games. They have finished a shareware game called Lugaru HD that is about kung-fu fighting rabbits and currently they are working on the successor Overgrowth. They also started the Humble Indie Bundle which was a successful fund-raising experiment. In in you can pay as much (or little) money as you like for five games (Aquaria, Gish, Lugaru HDPenumbra, and World of Goo) and if you like you can donate parts of the money to charity organizations. You can do this for 3 more days and is very well spent money.

Oh, I almost forgot what I actually wanted to write: their blog and YouTube Channel are a very nice mixture of humour and gamedev related information. Especially the Game Tech category of their blog gives nice visual descriptions on how some effects are created. Seems to me they also have a very nice animation system and rigging looks very simple in their videos.

So much for that. Asteroids is coming a nice way. I was able to fix that evil bug that appeared when firing excessively onto a group of asteroids and it seems pretty stable so far. At least I didn’t have weird crashes for a long time. I added a few more things (loading different levels, highscore list), but I’ll write more details in a separate post someday.

Premature code and binary LEAKED*!

The worst possible happened: the source code an even a buggy windows version version of my asteroids clone leaked to the internet! It took me quite long to finally get it run under windows and now that hard work simply pops up in the internet… I don’t know what to say. I fear it is probably an evil German hacker, just like in the 2003 leak of the Half-life 2 source. Tough times, I’d say…

Apart from that I am actually quite happy to get it finally run on windows. On the way there I ran into quite a few obstacles. I tried to use portable tools and libraries (CMake, freetype, OpenGL, SDL, libpng, boost), however getting them compiled and correctly linked in Visual Studio Express 2008 took quite some time. I also used a few precompiler #defines that were not supported by the Microsoft compiler (e.g. used __func__ instead of __FUNCTION__). There also was a critical bug that would make my game crash under Windows but not under GNU/Linux which was caused of improper initialization of a variable. The biggest hassle in the end was however getting it compiled so that it can be run on a computer on which it wasn’t compiled as there are some dependancies on the redistributable runtime libraries of Visual C++. I hope this is solved in the uploaded binary.

When you look at the asteroids.rc file you can mess around with some variables of the game (such as ship acceleration, maximum speed, etc.) and also set the controls the way you like it (so far only keyboard). Oh and there is also a very basic console (to access it press F8) with which you can run simple commands such as the ones in the asteroids.rc file.

For those who want to have a look at it here are the official links to the “leaked” versions ;D:

Known issues so far:

  • If you struggle to get it run or receive a “This application has failed to start because the application configuration is incorrect” error you might want to download the Microsoft Visual C++ 2008 SP1 Redistributable Package from here.
  • There are also sometimes crashes when shooting a lot of rockets to a asteroid. Doesn’t show up under GNU/Linux.
  • On a test machine with Windows XP Pro I had a small bug when parts of the exploding ship are drawn. Here are two screenshots that show how it is supposed to look like and the buggy version on the test machine:

explosion of an innocent ship

(buggy) explosion of an innocent ship

*too bad 1st of april has been already 9 days ago

Asteroids: first flying rocks

As I mentioned in my previous post, I decided to get a rather simple game done instead of dreaming of bigger ones. So far I think I was quite successful. I tried to reuse most of the code I already had and it was very helpful to modify my existing code towards a very clear playable game.

The game itself is already playable and I have a basic menu and basic gamelogic (you have 3 lives and once you die you’ll see the game over screen) and I can load and save levels. At first I thought of using 3d models by using the cal3d library which I already use in my research project, however I reminded myself of keeping things simple and created some nice sprites. I added PNG support by using libpng to be able to load sprites with transparency and also added simple animation of sprites. In the background the stars are moving sideways to give a slight 3d effect (looks very nice!).

What is still missing is sound and I need a few more animations (ship exploding, asteroid exploding). Additionally I do not yet count any points and some non-asteroid (maybe some powerups) would be nice to add more fun to the game.

Enough prose – here are some screenshots:

the menu

asteroids in action

game over screen

My game development demons

It’s been now a long time, since I decided to write a certain game and talked a lot about it with friends. However I must confess, now after a few years, I still haven’t managed to finish a game. I wrote a lot of code and both bugs and documentation is so far not the problem. Instead there are a couple of demons that  slow down the process that I would like to introduce to you (you probably know them already):

Efficiency Demon: This one is always in the back of my head. It tries to convince me not to use virtual functions as they are somewhat slower than normal function calls. However this approach makes things a lot more complicated and I spent time to circumvent the usage of “the single most important feature of C++” by using probably less efficient detours. Additionally following strictly the rule: first make it run, then optimize would encourage me to take a deeper look in profilers, which would be definitely a knowledge I wish to possess. There are a couple of nice quotes to this one on the Wikipedia page on program optimization – I guess I am not the only one having this demon.

Engine Demon: Instead of tackling simply completing the game logic/event managing/input handling part, I try to generalize what I just coded and put it into a part that I call “engine”. This “engine” is some kind of container of reusable code that I will most certainly need in the future. The catch is just: I do not yet know what exactly I will be needing in the future. Actually neither whether I need the generalized case nor the specialized I wrote in the first place. There is a very well written article (write-games-not-engines) from Josh Petrie which talks about this one. This demon is sometimes called Premature Generalization.

Beauty Demon: The Beauty Demon is related to the Engine Demon. It makes you want to clean up your mess (a.k.a. code). You just hacked in some features and now you want to polish it a little. So you polish. Then you realize you should add documentation. So you add it (and look at the beautiful caller graphs that Doxygen creates automatically for you). Then you realize that you could create of this feature set a library against which you can link dynamically – oh yeah, this is great, because then you can do this for all the other games you will write and reuse it. Oh, and the build system it got a little messy. How about … Yeah, you get it. You do a lot of things which are actually very useful. However they do not complete your game.

Just-that-feature-and-then-I’m-done Demon: I coded hard. The prototype works. And I am very happy. So I relax and think: Awesome, I’ll be done soon with the whole game and I can finish the rest tomorrow. There is a huge difference between a prototype and putting it into your game. I had a few nice parts, such as an event system and entity management system and so on which worked very well on them selves. But when I actually tried to make a simple game with it, I had to rewrite a lot of it and it was a lot harder than I expected. So unless the code is not in your game don’t think anything is done! (Please note that this is not an argument against writing prototypes – they are very important because you realize what the actual problem is and what kind of difficulties you run into!)

A long time ago, I read this very inspiring article ‘How do I make games?’ A Path to Game Development.When I look back, I must admit, I skipped quite a few steps suggested there. So last week I started to abuse my “engine” to create an Asteroids clone. So far controlling the ship, destroying asteroids and getting killed works, but there are still some areas untouched (menu, game-over screen, etc.). It took me a lot longer than I expected and I currently have a lot of quirks on making things work.

So far it is not efficient, not an engine, not beautiful and there is still a lot of work to be done. But I’ll stay on that rocky road and bring it home.

Thought game development is fun? It is – but getting it done is actually quite hard!

About the View in a Model-View-Controller

I recently bought the third edition of the book “Game Coding Complete” from Mike McShaffry (a.k.a. MrMike) et al. which has been very delightful to read so far. I have been reading a few chapters which gave me a new way of looking at game architecture and other things that I was convinced that I already understood them quite well.

One of them is the famously known Design Pattern: the Model-View-Controller. To me, the Model always was the data that is being modified, the Controller takes care of the input (mouse, keyboard, maybe network, …) sent to the application and the View simply displays the data. If you want to improve graphics – you work on the View. You want to update keybindings in your input system – you’ll modify the Controller. Also the Controller keeps track of the player id that tells us which entity is being controlled by the player. Need a new type of vehicle / weapon? – Go to your Model (and of course, add code to the Controller and View to reflect them).

So far so good.

However in this book Mike gives an overview of a game architecture consisting of three basic parts: the Application Layer, the Game Logic and multiple Game Views. The Application layer hides the platform specific from the game and the Game Logic resembles what is going on in the game. The Game Views represent the game from different perspectives e.g. for a human player or a AI agent.

Game Architecture after Mike McShaffry

At first my head tried to map them onto a Model-View-Controller which failed as they resemble completely different things. Especially the description of the Game View gave me a different way of looking at the View in a Model-View-Controller. The Game View does not only display what is going on in the game, instead it also takes care of the input handling. More specific: the Game Views receive all the input events (key presses, etc.) and communicate with the Game Logic over events.

At first this seems a bit awkward concerning to what I wrote further up concerning the View, but giving the view the ability to receive input and send events has some nice properties. For example it might be “easier” to add a split-screen mechanic as each player has its own Game View (remember: we have multiple Game Views!) and also its own keybindings. Also one could imagine having a GameEditView which has completely different abilities than e.g. a HumanGameView. This gives the View more power as it also contains not only the way how you look at things but also how you interact.

Maybe I got it all mixed up, however I think it one shouldn’t be too strict on saying input is clearly handled in the Controller or that the job of a View is drawing only.

Using txfonts in LaTeX but standard \mathcal{} symbols

I am currently working on my thesis and I am not happy with the standard LaTeX font which looks like this:

regular

I mean it is LaTeX so it still looks nice and readable. However there is a very nice font you can use when adding

\usepackage{txfonts}

at the top of your LaTeX file. This makes it look like this:

txfonts

Which has a higher density and also a bit smaller (might be, that I am just a little overfed with it as I have to look at it currently a lot). But  it has a small drawback as the symbols are very different from the regular LaTeX fonts especially if you look at the A. I was looking around on how to get the standard symbols back into a document using txfonts but couldn’t find any helb. However looking into the txfonts.sty revealed the solution. The trick is, to set the font for the symbols manually which can be done with the \DeclareSymbolFont command. To use the regular symbols use:

\DeclareSymbolFont{symbols}{OMS}{cmsy}{m}{n}

The result:

txfonts_regular_symbols

Yeah! Now I can continue working on my thesis…

What has been happening so far…

It seems as if there haven’t been too many updates here lately. I’ve been quite distracted with studying and getting the simulation of multi body systems into my head. And by doing so I stumbled over a few quite amazing papers and dissertations that seem to cope pretty much everything you need to know for a fully fledged physics engine (assuming you have some spare time).

For example the dissertation of Brian Mirtich (which you should be able to download here or here) covers just about everything from advanced collision detection to collision response. Even the calculation of inertia tensors in 3D is contained and the appendix covers all the math basics such as quaternion arithmacy and a rigid body primer. The whole thing wheighs a bit over 250 pages and is freely available. It still requires a lot of math knowledge, but as a math major I hope I have enough knowledge.

The method he describes in his thesis is the so called impulse based simulation which is stated in contrast to analytical methods as they are used in David Baraffs papers (as far as I understand). Instead of trying to fulfill all constraints simultaneously, instead if a constraint is violated it applies an impulse to the constrained bodies so that the constraint stays fulfilled within the next integration time horizon.

A more recent version of Mirtich’ aproach can be found at the site of Jan Bender (www.impulse-based.de). He also wrote a dissertation over impulse based simulation (however in German) which has less math in it. The best is: his code is available under the zlib license! There is also a lot of documentation in English available, so go check it out!

Oh, and of course I have not just been doing multi body simulation stuff. I was playing around with Blender already for a while to have a nice visualization for my thesis. And I finally made a model for a character in a game I have been planning already for ages. Now I added a little movement to the model. Here you have it:

Be nice, she is a little older (and my first animation). You can get the full resolution version here.

Cheers,

Martin

Welcome stranger!

What is this? This page is dedicated to physic engines and games and hopefully animation. It is a place to keep my work from drifting into the voids between the bits of my hard disk. I want to focus on the programming aspects and not a general discussion about engines and reviews about those.

Where to start? I do have some experience of programming a physics engine but would not consider myself, but I am still climbing up the learning curve (or wall). If you want to get started you definitely have to check out the page of Chris Hecker (http://chrishecker.com/) especially his quite old introduction to Rigid Body Dynamics (http://www.chrishecker.com/Rigid_Body_Dynamics) is a very good place to start.

What’s next? Hopefully some code and examples but don’t expect any regular updates here.

Cheers,

Martin