When I was still at EA, I learned about a technique that was used developing the Sims. Behaviors, as it turned out, were attached to the objects and not the player. This method was used so that new objects and behaviors could be added easily. For example, a refrigerator could be added that addressed the hunger need and the animations for opening the fridge would be included. The refrigerator could then be dropped into the game and all the relevant behaviors would automatically function.

When addressing a recent issue wherein the network was timing out during large data transfers, I had to put a system into place to break the files up into smaller packets for transfer. This meant that the required behaviors couldn’t occur until after complete data was received. For example, if a character is being sent then the character loading functions can’t fire until all of the packets have been transferred.

Rather than initiating a character transfer and stalling the client until the character has been received. I added a data type to the packets. Once all of the packets have been reassembled, the appropriate function is called on the client based on the data type. In the character example, blind data is sent to the client in packets. Once the packets are put together, a check is made to see what type of data it is. Since it’s a character, the load character functions are now called.

The advantage? All data transfers now use the same functions and new data types can easily be added. It really helped clean up the code and it’s nice to have asynchronous, fire-and-forget sending of data.