Event Handling In Games.

posted 29 Mar 2012, 07:35 by Robert Stiff   [ updated 31 Mar 2012, 04:24 ]

Being predominantly an applications programmer, I have a different take on things that people in the games dev area might. Event handling is something that one might do quite differently in many different situations. Here are the ideas I've had and the pros and cons:

Provided by the language. 
C#, nowadays, makes extensive use of Funcs, Actions and provides Lambdas to let you do it. Lots of other languages do this too. Even though this is a new concept in some of the higher level languages, only arriving in C# in 2003, C has had this for donkeys years. With C++ probably being the biggest gamedev language this option is widely available for most gamedevs for a long long time, however I have rarely seen it used.

A more application oriented than game oriented way of handling the problem would be to send messages around the game, be they objects or strings or hash tables which contain the relevant information. This gives us the option to trigger an event and then not care about when or where or how it happens. The advantage in application programming is that you don't need to worry about handling the event, other code will. Great for chopping things up, but I have never seen this approach used in a game, EVER.

Ad Hoc Handling
The most common use of event handling that I have seen in games, is just handling it as it comes. I understand that this is nice and simple and logical to have your update method identify that some work needs doing and doing it. But:

  1. This buries your events deep in your update method 
  2. It can make your update method a huge and unwieldy mass of code 
  3. It forces you to process events AS they happen
In a simple game this is probably the easiest option as you don't have to think about it to go down this route. However as your game grows, you will be tied to doing ALL event work in any given update method, regardless of whether it requires immediate attention or not.

I would probably put myself in favour of a Messaging approach, especially if you are doing any networking. If you can make your game a system which passes message around from component to component, then passing messages to a component on a remote system via networking is nothing new.

As such the next game that I work on, I intend to approach it as a messaging exercise to see if it as easy as I suspect to transition from a message based game engine to a remote-messaging based game engine (networking).

Does anybody have a different view on it? Does anybody do anything else?


While looking around today I found a blog entry entitled Service Driven Game Development by Joel Longanecker which talks about services which must communicate and puts down a bunch of code describing a message system.

Max Objects Being Serialised in WCF

posted 29 Mar 2012, 07:14 by Robert Stiff

A while ago I stumbled upon an issue where WFC would fall over, complaining that it couldn't serialise this many objects.

It took me quite a bit of hunting around to find out what the maximum number was, and how I could change it so here I share this information.

The default maximum number of objects which can be serialised in a WCF response is 65535. And this can be changed by setting the maxItemsInObjectGraph attribute on the dataContractSerializer for your behaviour, as below.

      <behavior name="MyServiceBehavior">        
        <dataContractSerializer maxItemsInObjectGraph="65535000" />    

Council Tax Confusion

posted 15 Oct 2010, 07:49 by Robert Stiff

Have you ever spent days struggling, trying to find out how much council tax will be paid on a new property you've thinking of getting? You can't figure out what banding your property is in or who you're supposed to pay council tax to? 

Never fear!! solves all these problems for you. Simply enter your post code and it'll give a list of properties on your street and the annual council tax you will have to pay. 

It even comes with a handy link to the Royal Mail postcode finder just in case you don't know the post code of the property yet. 

Very useful. Thank you, guys from

Re-register an entire network with DNS

posted 5 Oct 2010, 04:59 by Robert Stiff   [ updated 5 Oct 2010, 10:17 ]

Yesterday I ran across are rather frustrating issue. Somehow, every single windows machine on the network at work has become  removed from our DNS server. As such many systems were having trouble finding each other across the network. Gradually they were repopulating the DNS when they went back to the DHCP server for a new IP (as seems to do) but given the length of the DHCP leases, this could take along time to completely repopulate the entire list. So I decided I had to persuade every machine on the network to call "ipconfig /registerdns" to put themselves back in DNS as quickly as possible.

The way I ended up doing this was to knock together a VB script to iterate through all the possible IPs on our network and call psexec (from the Sysinternals PSTools suite) to issue the command on each of the individual windows machines on the network.

The following script was executed using cscript:

' First of all let's create 4 variables to hold the value of each byte of the IP address DIM byte1 DIM byte2 DIM byte3 DIM byte4 ' Given that our example IP range is to we will set the first two bytes to 10 and 0 byte1 = 10 byte2 = 0 ' We'll loop, incrementing the value of byte3 by 1 each time until we reach a value of 5 FOR byte3 = 0 TO 5 ' Each time we loop on byte3, we can loop again on byte4, this time between 1 and 254 FOR byte4 = 1 TO 254 ' Build a string to represent the whole IP for ease DIM ip ip = byte1 & "." & byte2 & "." & byte3 & "." & byte4 ' Create an instance of the shell object so that we can call our external command DIM oshell SET oshell = WScript.CreateObject ("WScript.Shell") ' For reference we can output the command that we will be calling to the screen wscript.echo("psexec \\" & ip & " cmd /c ipconfig /registerdns") ' Call psexec passing it the generated IP and the command to reregister with DNS "psexec \\" & ip & " cmd /c ipconfig /registerdns" SET oshell = nothing NEXT NEXT
This called psexec 1270 times in rapid succession. Fortunately, with a bit of patience all the calls went out and after a short period of time I started to see machines reregistering themselves in our DNS. By the time I returned to work in the morning the entire network had successfully reregistered and the problems of the previous night had been resolved.

IMPORTANT NOTE: Before running this script, run psexec once and agree to the licence agreement. If you don't you'll be presented with 1720 licence agreement windows each begging to be agreed to. That's a lot of button click to get through.

Visual Studio Un-installation Woes

posted 5 Oct 2010, 02:44 by Robert Stiff   [ updated 5 Oct 2010, 04:45 ]

I came to uninstall Visual Studio today from my main PC, just to keep things tidy and make sure that things don't go wrong, the way they are apt to go if you don't keep your PC tidy.

Apparently something DID go wrong, but it's impossible to tell what. When launching the Visual Studio 2008 setup program I get faced this this rather useless error message before even being given the opportunity to uninstall.

(A problem has been encountered while loading the setup components. Canceling setup)

Fortunately Microsoft are aware of this problem have have a VERY handy little MS auto-uninstall tool

Good Luck!


posted 4 Oct 2010, 18:06 by Robert Stiff   [ updated 4 Oct 2010, 18:07 ]


My name is Rob. On this site you can find information about me as well as various projects I am working on personally.

My CV is also available below.

1-6 of 6