Jump to content

  • Log In with Google      Sign In   
  • Create Account


2D Racing game server architecture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 dburner   Members   -  Reputation: 151

Like
0Likes
Like

Posted 07 September 2012 - 06:45 PM

Hi, I'm currently working on a 2D Racing online game. I'm working on this game only because I want to practice my networking skills and for the fun of it, so the game wont actually be published(well who knows I might end up posting it somewhere) or played intensively but I want to make a strong design that could theoretically hold around 150-200players mabye more.


The game and server are written in C#. I am using async TCP sockets on both client and server components.
So far I made the gamedesign like this:
Client side:
  • client connects to the server and sends his nickname (multiple clients may have the same nickname doesn't really matter)
  • the client can chat with all the players connected to the server
  • the client can join or create a game room (set room name, set the max players, track, password)
  • the owner of the game room can start the game
  • and then the racing happens

Server side (the tricky part):
  • a basic client gets data asynchronously and puts it into a message queue
  • made a base class named NetRoom for 3 different room types : UnnamedLobby, MainLobby, GameRoom
  • a room may contain more clients
  • a NetRoom has a OnTick method and a OnMessageReceived method called by the OnTick that retrives a complete message from a client
  • when a client connects it is added to the UnnamedLobby until the server receives the client name, then the client is moved in the MainLobby (and I think I am going to get rid of this Room because client sends the name just after it connects)
  • in the MainLobby the clients can create GameRooms
  • the GameRoom handles clock sync, actual race game data, etc.
Here is the question: how do I call each room's OnTick method?
a) one thread, one loop parsing all rooms and calling their OnTick
b) one thread for each room
c) one thread, one loop parsing all rooms BUT the OnTick calls the OnMessageReceived using ThreadPool
d) on the ReceiveCallback from the client class call OnDataReceived using ThreadPool

Also if anyone thinks there is room for improvement please tell me. Some of this stuff isn't coded yet(only 2 days of coding).

EDIT: A game room should normally hold 4-8 players. And I want my server to be able to handle 30 game rooms simultaneous.
EDIT2: Added d)

Edited by dburner, 08 September 2012 - 08:46 AM.


Sponsor:

#2 hplus0603   Moderators   -  Reputation: 4966

Like
0Likes
Like

Posted 08 September 2012 - 04:27 PM

Keeping some number of threads that pull tasks from a work queue and work on them is a good way of using more than one core on a computer. Similarly, having separate threads that call OnTick() on each game room might be useful, if there isn't a lot of cross-synchronization. I would worry most about the network-to-rooms hand-off of data, which is likely to need some kind of locking, unless you can get away with a lockless queue.

The "UnnamedRoom" could later do authorization/login if you want passwords for persistent accounts (say, for leaderboards etc.) Thus, it seems like a reasonable thing to keep.

enum Bool { True, False, FileNotFound };

#3 dburner   Members   -  Reputation: 151

Like
0Likes
Like

Posted 16 September 2012 - 02:50 PM

I've thought about what you said and coded a bit further(implemented like 99% of the lobby functions) and decided I'l just use the threads from the async methods because the only locks I think I will need are those on the playersList in the NetRoom when adding or removing clients. Since joining and leaving rooms are not very frequent(I think) those locks shouldn't cause many problems.
Parsing the messages so far take very little time so I guess I dont have to worry about blocking the async threads too much. If I will get in trouble I will change the methods of calling the parsing functions quite easy. I still got the OnTick methods but they are kinda useless now.

Thanks for the answer hplus0603Posted Image

Edited by dburner, 16 September 2012 - 02:51 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS