[RTYPE] Server / Client Game synchronization

This is a discussion on [RTYPE] Server / Client Game synchronization within the Game Programming forums, part of the General Programming Boards category; Hello everyone, As part of a University project, I'm developing a RTYPE-like game. Although, we are pretty much free to ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    69

    [RTYPE] Server / Client Game synchronization

    Hello everyone,

    As part of a University project, I'm developing a RTYPE-like game. Although, we are pretty much free to do it as we like, there are Platform and Library constraints. For example, the program must work in both Unix and Windows. For the server, it has to be multi-threaded and no libraries are allowed (So we have to write our own, Thread Abstraction library, Socket library, etc).

    Here are my questions:

    [1] The game is multiplayer based. You have have up to 4 players in an instance of a game. Is it possible for the server to handle the collisions between players/enemies? I'm having a hard time finding out if it is possible or not, because I don't see how the server can have a world synchronized with that of the players. (The same time-step / etc). Is it even worth doing or should the client handle his own collisions and notify the server when there is one? (So that the server can dispatch the message to other clients). Any good articles on the topic?

    [2] Communication is UDP only. There will be one listening socket. Since each instance of a game will probably be a different thread, when I receive socket information, what is the best way to dispatch it to the other threads? I see two solutions:
    - Create a buffer for each instance of a game. When the main loop receives info it locks the buffer, puts the information there, and unlocks it. The thread is then notified of available info (thread_cond? Something more elegant?) and locks/copies/erases/unlocks the buffer.
    - Create localhost sockets, for each instance of a game. The main loop will get information from the main UDP socket and dispatches it to the new "local" socket that is different for each instance.
    Anything I've missed?

    Thank you for your time.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    Is it possible for the server to handle the collisions between players/enemies?
    Yes, but not wise.

    Is it even worth doing or should the client handle his own collisions and notify the server when there is one? (So that the server can dispatch the message to other clients).
    Essentially, yes. 'Play' the game on the client and when something happens that affects some other object in the game, notify the server which will then notify it's listening client that has that object.

    Any good articles on the topic?
    Amazon has several good books about building multi-player games.

    [2] Communication is UDP only. There will be one listening socket. Since each instance of a game will probably be a different thread, when I receive socket information, what is the best way to dispatch it to the other threads? I see two solutions:
    - Create a buffer for each instance of a game. When the main loop receives info it locks the buffer, puts the information there, and unlocks it. The thread is then notified of available info (thread_cond? Something more elegant?) and locks/copies/erases/unlocks the buffer.
    - Create localhost sockets, for each instance of a game. The main loop will get information from the main UDP socket and dispatches it to the new "local" socket that is different for each instance.
    Anything I've missed?
    Since your server is the one listening and normally (in most servers) constantly listening for new players or connections it should be able to maintain a map of sorts that maps from ip to specific thread or something along those lines. Broadcasting a message is a simple matter of iterating the list/map and calling a function that those IGameThread objects must implement.

    IE: One of a million ways to do it
    Code:
    class IGameThreadListener
    {
        public:
          virtual ~IGameThreadListener() { }
          virtual void NotifyThreadEvent(unsigned int event) = 0;
          .....
    };
    
    class Game : public IGameThreadListener
    {
        public:
          ...
          virtual void NotifyThreadEvent(unsigned int event);
          static void ThreadMain();    //Called by Thread object
    
       private:
         Thread *m_pThread;    //your custom thread object
    };
    
    void Game::NotifyThreadEvent(unsigned int event)
    {
       //respond to event
    }
    Obviously I haven't gone through a design meeting or anything to come up with this so I'm sure it has many shortcomings but it is an example of one way to go about doing it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to Send Mac Address From Client to Server
    By Lieyza197 in forum C Programming
    Replies: 2
    Last Post: 05-27-2009, 09:58 AM
  2. Programming chat client, need some help (sockets & threads)
    By lalilulelo17 in forum Linux Programming
    Replies: 1
    Last Post: 04-19-2008, 04:01 AM
  3. c program client server
    By steve1_rm in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-24-2008, 09:33 AM
  4. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  5. Replies: 40
    Last Post: 09-01-2006, 12:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21