Sunday, April 30, 2006

Sunny days ahead...

We had a day in the garden yesterday, giving the grass its first cut - which as usual takes a couple of hours, and doing some odds and ends. The kids and I also painted the wendy house a nice bright blue. I couldn't find the colours I was after at B&Q so we just mixed what they had, came out pretty good. Im going to draw some puffy clouds around the base and paint them white which should look fairly nice. The kids had great fun painting it with me. Im not sure what ended up more blue, the shed or them.
They were off at Grandads today, and he picked up gran as well and they all went to the beach. I put down some weedkiller and kicked back and watched some T.V. After a full day out and about yesterday I felt like a relaxing day before I head into work tomorrow. Everyone else is off on holiday, but I dont have the days to spare so...
Should be good fund tomorrow, as I start on the threading stuff for real. I was laying the ground work and rearanging the code a bit on Friday, so now I can actually start coding it.
I asked Russ to do a mini code-review on Andrews code as I suspect that his opinion will be respected more than mine. The problem with not being "Mr C++" is that not many people respect your code, which I find irritating beyond belief. In fact it pisses me off quite a bit, probably because the people who tend to do that, usually don't code in the real world, and are too deep into whats "proper" rather than whats right and what's best. At my review Luke said that my code wasn't designed properly and wasn't maintainable, which I personally find to be rubbish, since I've always managed to maintain my code and do whatever I need with it. The review was done ages ago and still pee's me off a bit, and Im not sure if its over the stuff that was right, or the stuff thats was wrong.

Friday, April 28, 2006

Multi-tasking a "yuck"

I've been feeling a bit crap past couple of days, so never got around to updating here. Oh well.

I've started looking at threading my application at work, and have been trying to come up with the best way of doing it. Theres lots of ways you can thread an application, the simplest being you simply decided to run a bit of code on the other thread and it sleeps when its no busy. This is fine, and for tools usually what you need sine the other threads tend to be worker threads. But in games, you want to try and load balance a bit more - kind-of like what windows does, but a bit better.
So, I've come up with a way of using a thread pool that allows me to spawn off many tasks in the game as I come to them, this means that processes may switch back and forth from CPU to CPU, but allows the system to load balance it.

So how does this work in practice. Well, if you have 2 CPU's, you'll have 2 main running threads the second is synced to the first and will only start once its told to - it could even be a thread in the thread pool itself. These 2 threads then start ticking through the list of processes in their own time, meaning that if one slows down on a complex bit of processing, then other can pick up the slack. If something comes along that will block the thread - file or networking, then these are passed off to the threadpool but the file or network manager, and the main 2 threads carry on as normal.

It should work fairly well, and should allow for almost transparent use of multiple CPU's on the system. In theory.... However, if your application spends 95% of the time on one thing, then your still stuffed no matter what you do; you should learn to code better!

I love doing multi-threaded stuff, its greatfun seeing all your processes getting dished out and seeing all the available CPU's doing something. I have an old (very old) 12 processor SGI at home, and watching all the processor activity bars on the front being used to the fullest is very cool.

Tuesday, April 25, 2006

POD casting....

I was playing with C++ POD types today (which stands for "plain old data"). These are funny little classes that are only a single item, and this item is enough to fit inside a CPU's register. Theres some limits to these classes, but if you use them right, they're quite cool and ideal for things like Handles, CRCs, IDs, Indexes and the like. It must be public, and you cant have any constructors or overloaded == operators. Aside from that, its a fairly normal class. Very neat.
This was all part of my drive to understand templates, and in doing this, Russell and I figured out how to use these POD types correctly. He had thought he was using them right before, but it turns out that although he'd tested it, he had then added stuff that made it a plain old class again. Problem is, the compiler doesn't tell you it just switches, and the only way to know for sure is to disassemble the code and see what its using!
Anyway, I'm starting to get the hang of templates on a rudimentary level at least and while I'm still a long way off from using them in anger, at least I can now follow code that does use them - almost.

Monday, April 24, 2006

Ben Nevis

We had a drive yesterday up to Fort William since the weather was finally improving and there wasn't a chance of getting caught up in a blizzard. The road up was fairly bland; well, compared to the road back that is. Fort William is a nice enough place, very pretty but pretty empty for a day out. If you're staying there then you theres lots to do in terms of walks, and water sports. BenNevis is impressive I guess, but the road back down between the three sisters and Glencoe has to be the most impressive countryside I've ever seen. It's almosy like an alien landscape, and theres virtually no sense of scale. You look up at these huge mountains, and only when you spot someone climbing them do you truly start to get how big they are. The problem with BenNevis itself, is that its really just a bump; theres nothing spectacular about it except its size. These otheres are amazing though, and since you drive right at the base of them, its breathtaking.

I've been busy playing with templates and STL today and it's starting to come together I guess. It's a bit strange and I know that it's going to take time to actually use correctly, but I guess I'll manage okay. I did dig a little deeper into the STL stuff, and didn't like it. I don't mind the interface and all the rest but I don't like the complexity of the STL library. Even in release mode it generates a lot of code, much of it I think unnessasary by most coders and the features it adds I dont think should be up to STL but the programmer to wrap it.
Still, it must be said, for the average programmer doing normal sized programs STL is fine, and easy to use. However, I worry about using STL and large programs, the memory footprint and fragmentaion isn't very good and the ammount of code bloat with many unique classes can be nasty, particually when used with other templates.

Saturday, April 22, 2006

To STL or not STL...THAT is the question...

I spent yesterday afternoon chatting to Russell about templates and the standard library stuff, and have almost found what I was looking for; a reason to use it. Templates are very nice at giving a standard interface to multiple objects via its iterators, and from someone that writes API's for others to use, I like that - even though I don't yet like the code you have to use. But, you get used to these things, and so I started talking to Russell about templates, and he suggested doing some simple linked list stuff. Good idea.

So, here I am at home playing with linked list templates and trying to figure out what STL is all about. Its odd really, to be good at your job you have to be able to do things properly, an quickly. But whenever you have to learn something new, one half of that won't be true anymore. You'll either do it quickly and wrong, or slowly and right. This is one of the things that grates me about learning new stuff, particually something as complex as templates. Yes, the basics of templates are easy enough, but to get the best use out of them, you have to be more clever than that.

STL is a case in point. when you decided you want to include a list, its easy enough: list< class > var;. And your done. And this is usually as far as most programmers get. But I'm not most coders, I want to understand whats going on under the hood to see why I should use STL, rather than just being told its a good idea. And under the STL hood, theres a demon waiting to escape - its horrible. From this, I can now see why windows slows down with each iteration, and it frightens me that most coders just dont know what its doing, burning away your time and memory without you realising it.

A small example... everytime you decided to "push_back()" a new object, you have to figure in a few more things.

1) You're allocation of the object itself.
2) a small class that now links the objects together. (around about 16 bytes for a list)
3) 2 memory block headers that malloc() will allocate for each bit of memory you've allocated.
4) a Critical section In/Out each time you add (I'm guessing this is an implementation detail that some might not use, and possibly only in debug as well - I've yet to find out).

Thats a hell of a lot of work to add a link. If your dealing with thousands of links (or tens of thousands) then this is slow and memory consuming work; and most programmers will never understand why. In the C++ book there are 2 very good bits of advice. 1) Don't reinvent the wheel, and 2) Don't believe in magic, understand the libraries and what they do, and how.

Good advice.

Thursday, April 20, 2006

I'm off today awaiting the arrival of my new Telewest TVDrive. Basically a new style Tivo complete with 3 tunners so you can watch something while taping 2 other things! Very cool indeed. It also has HiDef out which is neat so I'm now looking at some LCD HiDef TV's. of course, this joins the long line of things to buy... but its great fun looking!

I've been doing some SQL Database stuff reciently, and it's pretty easy but good fun. Its kind-a like HTTP, TELNET etc. where you send simple strings and deal with the result, and I've been dealing specifically with updating my database dynamically. This is pretty basic stuff I guess, but its fundemental to what I'm doing so I have to make it "nice" as it were.

Oh well... off the get the kids from school, so much for a holiday; once you have kids all that goes out the window, but I wouldn't trade it for anything.

Tuesday, April 18, 2006

One of the things I hate most in the world, is changing code that you can only check once its ALL been done. Its rare that this ever happens (with me at least), but I prefer to make small changes that can be built and tested in easy steps. Didn't happen today though! I spent the whole day typing away and making sweeping changes to the code. It probably wouldn't have worried me quite so much, but I've been changing it BACK into what I did have! When I joined Realtime Worlds I tried to follow the coding standard they have there, but when Russell joined, he set about making a standard for our project. This involves using the standard I normally use. Typical.

Still, A whole day of typing and it worked first time! The only other time I rememebr doing this was way (WAY!) back in 1992(ish) when I was doing Lemmings 2 on the SNES, I spent a week writing a single (although complex) routine that let me draw graphics onto the screen. It worked more or less first time too. Perhaps I should take the hint and write all my code this way, you seem to read it more before you run it and hence spend less time debugging the bugger.

A passing comment from Russell had me fizzing inside again; I remember telling Dave that one of the things I won't have, is being told I'm wrong. Now don't get me wrong, Russell knows what he's doing and I respect his judgement over most peoples, but he mentioned that something I did was badly designed, and I almost screamed. Part of the problem with learning new stuff is that you hardly ever use it correctly at first, and the "badly designed" part was a suggestion from someone else. I didn't want to do it that way in the first place. Every job I've worked, at somepoint someone has told me I'm wrong about something Im doing, and over the years I've come to notice that in the stuff I do, I'm usually not - not if its something I've sat down and thought about. I told Dave there were a couple of things that would make me leave. First one was being told I'm wrong all the time, 2nd was not enjoying my job or not being allowed to do the job I want. It'll be interesting to see if any of these come true here...

Looks like we might have mice again... I really need to move the rabbit hutchs so they dont attract mice and rats. We had rats a couple of months ago (well a rat - but it was big enough), and it ate everything in sight!

*sigh* its never easy.

Monday, April 17, 2006

I was listening to Pinks new album, and one song in particular struck a cord: Dear Mr President. The main reason is that it goes on about a hard day's work, and I have to begin to think about what would happen should I leave the game industry. It's true that being a coder, I've never truly known a hard day in my life. Sure, we have some "crunch times" where we might work a full 24 or even 36 hour day, and we might never get any overtime, or a life after work - but when all is said and done, its easy work; enjoyable even.


I know if I worked 9 to 5 in McDonalds it would probably feel like a living hell, very few people actually really enjoy that kind of work. So have have to feel lucky in the position that Im in, even if I'm unsure as to what the future of that might be, at least I know what involved, and love my work. I come home at night and do more with out a second thought, I can't see people in shops or McDonalds doing that.


I've been having more woes with the new Visual Studio 2005, its really nice overall, but has some very irritating little quirks. Ever since Microsoft had security problems with buffer overruns, it seems that they've been at pains to force everyone to learn from their mistakes. It never seemed to occur to them that we might not make that mistake in the first place, but VS2005 almost forces you to use these new functions - even if you dont want to!

Saturday, April 15, 2006

We've just been out to look at some garden toys for the kids; swings, slides and the like. I'm fed up having a hudge garden that I have to cut only for it to be under used, so this year I plan to deck it out in stuff for them to do. These things aren't cheap either, and thats a bit of a rip off, since its only a few bits of wood and bolts, but I guess at least we know its been through some safty inspection - which would be more than my attempts.

I lost my mum to cancer last August, and I'm still kind of struggling with it. Before it happened I alwasy wonder how people manaed, and assumed that you'd just get over it since people don't cry forever. But after its happened to you, you begin to realise you never ever get over it, you simply start to accept it. Now not a day goes by when I don't think of her, and whenever I'm watching TV and theres a death of some kind, I'm almost in tears all over again. I think the main thing is that you can think about them in the past and as long as you dont dwell on you feelings or theirs, you manage - just, but as soon as you start to really think about them and what they're missing, thats it, you're in tears again. I don't think people are designed to lose ones they love, and its one of the (many) reasons I think my religion helps me.

Anyway.... Luca has been emailing me asking about my retro project again.(http://xeo3.plus4.net) so it's probably time to start that up again. It would be nice to get it finished, its only taken 6 years so far!!! Thats the problem with doing games, you just cant be bothered doing them when you come home again.

Thursday, April 13, 2006

I'm currently sitting here cleaning up my code before sending it off. It's actually very theraputic, probably because as a games programmer you never get the chance to do this kind of thing. You always start off doing really nice code, but as a project goes on it gets shabbier and shabbier due to time pressures, not to mention last minute design changes that are fudged in. So it's nice to be able to go back through code and clean it up. I always think programming can be very artistic - not profesional progamming, thats a mess - but the kind of programming where you have the chance to sculpt you work just like any artist would do.

Course... thats not to say my codes perfect, its a prototype so by its very nature some of its just not going to be right until its rewitten; but it does allow it to look as pretty as is possible under the circumstances - which is a good thing.