The more things change...

Published August 30, 2004
Advertisement
Yesterday I implemented a basic system in Python to allow the flow of control to pass between 2 threads at designated points, so that both threads had simple linear code and synchronisation issues were kept to a minimum. The idea is that the first thread continually updates the screen, but waits each time for the second thread, which is handling AI, to finish doing something, typically moving a creature one step along a path. In other words they take turns at processing, so it renders the screen, the AI moves a character one step, it renders again, and so on.

I didn't want to run the graphics thread as fast as possible as this is a 2D turn-based game and I only need the graphics to be 'fast enough'. An alternative might have been to set the graphics theead to update periodically (eg. 10-20 times a second) but to acquire a global lock first so that there weren't issues with accessing character positions and the like, but that doesn't really affect the implementation of the AI thread which still has to signal every time it's finished moving a single character. But, apart from that signalling, that AI routine is nice and linear, just a few nested for loops. No event queue, no storing paths with the character to be consumed over several frames, just one-dimensional code in the good old style.

And that's when it hit me... implementing this sort of thing would have been trivial back in my BASIC days. Everything would be stored in global variables, so I'd have all the persistence I wanted (ie. no pesky locals going out of scope!) and I could just use goto to switch between the 2 routines at will. Bliss! Of course, I couldn't bring myself to write code like that any more even if I wanted to. I happen to have grown quite attached to object orientation, local variables, and so on. But it's quite interesting how advances in technology make some things easier and others more difficult. For example, it seems like blitting an image to the screen using DirectX is more complex than it was 5 years ago. Yet you'd think these things would be made simpler as time goes on.

I'd be interested in learning how other people handle things like AI turns in turn-based games such as Civilisation etc. The separate thread for AI seems to be a common theme these days so maybe that's what most people do.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Advertisement