Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

The more things change...

Sign in to follow this  


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.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!