Archive for July, 2010

h1

The pain of threading and bitmap fonts

July 29, 2010

I had forgotten how much i hate using threading. It creates just as many problems as it solves. Although it’s cool that i can load stuff while the game continues to run (and probably just show a loading screen), it has complicated the flow of my code to a fairly unfortunate degree. Ah well, such is the way of things, I guess.

So anyway… my fonts. I have been fighting with these damn fonts for too long now. The mipmaps helped, but ended up making the fonts look quite fuzzy/blurry which, although better that just plain crap, makes you feel like you need to plan a trip to the optometrist to get laser eye correction surgery. I’ve tried a bunch of different filters to create the mipmaps and filter between at render time, but when it boils down to it if you reduce the size of an image, you are losing fidelity and nothing seems to be able to keep it nice and sharp. The best looking the fonts get is when they are rendered at a 1 to 1 ratio, meaning no mipmaps and no filters. 😦 So, my current solution is a sort of mipmap setup but instead of taking the original font image and downscaling that, I’m rendering a number of versions of the font image and different font sizes. My font manager then returns the one that is closest to the size you want. This reduces the amount of mipmapping needed when rendering the font out because you are close to (ideally) a 1 to 1 ratio. Obviously I can’t render out a different texture for every font size possible, but it’s better than it was. I think.

It’s still hardly perfect and I would love to be able to make it better, but as I said I’ve wasted too much time on this thing now. If I really need sharp fonts in my game, I’ll have to make the font images at the sizes I need them. So be it.

Now I’m back onto trying to sort out that whole depth sorting thing with the in game objects.

h1

Fonts and textures

July 25, 2010

Hi guys. Sorry, not much to show this time. I’ve been trying to figure out how to get my in game fonts looking better which has taken me on a really long road. First I tried to get mipmapping to work which proved to be a pain because I either needed to generate them myself or get openGL to do it. It sounded like a better idea to let openGL do it, but that meant I needed to learn how to use openGL extensions (which is basically just how you say “using functionality newer than what was around in 1995”). So, after learning how to get extensions working and make openGL generate my mipmaps, I ended up with really fuzzy text. Yay! Totally worth it. It turns out that openGL generates really crappy and blurry mipmaps, so it was back to the generating the mipmaps myself. My one friend turned me on to FreeImage which is an open source image library. I stuck that into my code base and was able to generate decent mipmaps. Only problem is that it takes a while and stalls the whole program while it’s doing it, which obviously isn’t acceptable. So, I’m currently making my texture loading asynchronous using the threads from the boost library, which will enable me to carry on doing other stuff in game while this is going on… like showing a loading screen or something. (Damn. This is the most third party stuff I’ve ever used in my game programming) Boost is a pain to get up and running, but I finally got it to work right. Now to do the actual texture loading on my brand new thread.

h1

Simple Anims and Some Editing

July 18, 2010

I’ve put some simple animation handling into my actor class to make it look a bit nicer than a white block moving about 🙂 Tried to put some form of depth sorting in the objects, but it turns out that it’s much more complicated than I gave it credit for… especially when there is this “faked” perspective thing going on in the scene. So I’m going to have to make something more intelligent to handle that.

In that line, I’ve begun work on an in-game room editor. It’s going to let me change things about the room in real-time instead of having to close down, change the data a bit, load the game back up, rinse and repeat. Faster iterations mean faster development so… yay.

Here’s a video of the new stuff I’ve added in. Hopefully it’s pretty self explanatory, but just in case, I’m showing:

  • Walking behind the desk
  • trying to walk up the stairs and failing
  • showing the walkable areas
  • adding in a new walkable poly
  • walking in the new poly
  • editing the poly
  • deleting the poly

The program I’m using to capture these videos (fraps) is killing my frame rate which is a bit annoying and makes demoing things fairly painful. Although it did show me a bug in my code that was relying on a certain frame rate. You can see it in the video actually. The editor window comes up too far because I don’t have any checks to make sure it doesn’t shoot past the right height in a single frame. Oh well… swings and round-abouts I guess.

h1

Awww… his first steps

July 17, 2010

I wrote a little Actor class which is going to handle character movement and animation, and hooked it up to my user interaction and pathfinding so I can now move a little white block (my actor) around by clicking in various places on the screen. My code takes the clicked position and finds the closest possible position the actor can get to that location and then the actor begins to move there. I am also able to interrupt the actor’s current path and send him somewhere else which is pretty neat.

Here’s a little video (the first one on this blog. YAY!) of my actor finding his way from the front door to the door behind the desk. It’s the same path (roughly) that you’ve seen in the last post, but I’ve taken all the debug graphics out so that it looks a bit more like a game. I don’t have any depth sorting implemented, so the actor is not going to go behind the desk visually, but you can see how he steers around the desk. (the fraps.com watermark at the top is because I’m too broke to fork out and buy the app that I’m using to capture this video). Enjoy!

h1

Hooray for A*

July 12, 2010

So, things have progressed a bit since I last wrote. I implemented a Djikstra pathfinding algorithm, which isn’t very efficient. Made a smallish change to it, and suddenly it was the A* (pronounced “A star”) algorithm – the bread and butter of game AI programmers. Go figure. I thought there would be a bigger difference than there was.

I ended up with a workable (but not very intelligent) path from A to B.

As you can see, the path (starting on the left) always passes through the centre of the connecting bridge lines (the purple lines). It works, but it’s not the way a thinking person would walk. A person would walk towards a visible end point and then reassess their path. To simulate this behaviour, I’ve written a path smoothing algorithm which produces the following path:

Although it looks similar, there are some key differences. In the first one, the path is made up of 5 points. The second one, has only 4. This may not seem like a big deal, but what has happened is that point on the first bridge wasn’t needed because the path could go straight to the second bridge (based off a bunch or calculations). The less way points there are, the less direction changes there are. One of the things that makes characters look dumb is when they walk to an unnecessary location to get to another one. It’s not that pronounced in this situation, but in others it would be enough to break that vital barrier of suspension of belief, which is want we strive to avoid in game development. The new path is also the shortest route the character could take from point A to point B, which is also something humans do (ie: be lazy :))

The path-smoothing algorithm represents a couple days of head scratching and failed attempts, so I’m pretty stoked that it’s working. There are some inefficiencies (some tests are done more than seems necessary due to the unpredictable nature of the bridge point ordering), but at the moment it’s more than fast enough.

I’m hoping this pathfinding code will stretch to other applications in other game genres, but I guess that’s too long a way off from me to worry about now. I’ve tried to make it extensible and it’s much more than I strictly need for the current game, but it was fun and I’ll be thankful when I want to use it again.

Next… um, I’m not sure. I guess it’ll probably be something to control character movement and animation. I’m going to need to rip myself out of the framework mentality where I try to provide the functionality I’m going to need and actually use the stuff I’ve written in a game. That’s been my biggest weakness to date when it comes to making games. Farting about in the framework and building engines comes easily, but getting down and actually producing something… that’s something I’m still trying to learn :/

h1

It is but a sapling, but will be a strong tree

July 7, 2010

My path finding tree is blooming. Apparently people are actually reading this, so due to popular demand (one person), I’m putting in another picture 🙂 I’m also going give a quick run down of what the picture is showing.

.

The green areas are where the character is going to be able to walk. They will be able to move freely inside the poly that they are currently in. If they want to move to another poly (like say from the front door to behind the front desk) a path will have to be generated to enable the character to walk there without bumping into things. I’ve written an algorithm that takes the walkable areas and generates connections (or bridges) between all the areas (those are the little purple lines you can see along some of the edges of the polys. I’ve also put lines showing the pathfinding graph. Although this graph is not very complicated (since there’s really only one route from one place to another) it should be able to handle a more complex scenario… I’ll have to test that…

I’ve now begun the whole actual finding of the path. Although so far there have been a few hiccups with some of my intersection tests. So, now I get to debug that. Fun.

So, not a very different picture to the last one (Derek), but most of the work I’m doing is more foundational than flash. Sorry. 😉

Oh, alright… here’s a picture of a french bulldog for fun.

h1

Every path starts somewhere, I guess

July 5, 2010

I’ve created the functionality to turn a bunch of polygons into a pathfinding graph. Now the actual pathfinding begins. 🙂

h1

Damn paths!

July 3, 2010

Well, I’ve added the ability to draw circles (-like-things), which required a light-weight matrix class. When I say required, it didn’t really require it, but I was able to do it much easier with matrices and I’m sure they’ll be useful in the future, so probably a good investment.

After struggling to figure out a way to get pathfinding to work in my engine, it finally clicked the other day and I now have what seems to be a workable plan. I’m about to start development on it, so I guess we’ll see if I’m right or not. Here’s hoping…