Page 1 of 1

Game Logic

Posted: 20 Apr 2006, 05:58
by rik.schennink
Hello :)

First, thx for all the help thusfar, the way u guys assist developers is just great! :D

Now, I read in the documentation and tutorials that it is best for performance to put the game logic in the zone extension.

Now i came to the point i am going to write the game logic but i cant figure out how to put it in the zone extension instead of the room extension.

I am making a game where the server moves the players around, the players can only define their speed. The zone extension creates dynamic rooms for upcomming games (a game starts every x minutes), clients that have subscribed to that game can join the game, this is all done in the zone extension..

The room extension gets the settings for the game from te database and sents the game data to the clients. Logically i would put the movement and collision detection (all that stuff) in the room extension.. but as i read, for every room an instance of the extension is made, so performance wise it would be ideal to have only once function handling collision detection instead of 5 (if there are 5 rooms)..

The problem is that i cant figure out how the communication between the zone and the room extension would work and how i'm gonna use the game logic for every room if i put it in the zone extension..

Can u please give me some advice?

Posted: 20 Apr 2006, 17:11
by Lapo
Hi,
nice question :)

One of the performance issues you can encounter in attaching a new Room level extension to each game room is that Actionscript extensions need to be compiled into bytecode when it's loaded.

If many rooms are created at the same time on a traffiked server, the compilation time can add too much overhead to the server.

That's why we recommend using Zone level extensions. (if you use Java instead of AS you don't need to compile extensions at runtime, so Java is definitely okay for room extensions)

Anyways the solution is very simple:
you need to keep a list of game rooms and store the data relative to each game in the room objects.

Imagine you have a main list of rooms in your Zone extension:

Code: Select all

var roomList = new Array()
each time you create a new game room you create a new object and add it to the array like this:

Code: Select all

var roomId = roomObj.getId()
var dataObj = {}
dataObj.room = roomObj
roomList[roomId] = dataObj
Now you have an associative array with the id of each room as keys and a generic AS object as value.
In this object you can store the Room object and all the other game properties. (score, game status ...)

Extension requests:
All your game rooms will send game requests to the same Zone level extension.
When you receive the request you always get the id of the room where the message comes from: in other words you will always know which game room you're handling.

Events:
When you get a "roomLost" event you will need to remove the room from your roomList array.

hope it helps :)