Gamestates, diffs and events, oh my.

Posts: 89
Joined: 2005.06
Post: #1


I'm plz writing a multiplayer game k? Need help conceptualizing gamestate (struct, class?) and how 2 send 2 players plz.

For instance, here is an example struct from the game TeeWorlds:
    struct SNAPSTATE
        const NETOBJ_CHARACTER *local_character;
        const NETOBJ_CHARACTER *local_prev_character;
        const NETOBJ_PLAYER_INFO *local_info;
        const NETOBJ_FLAG *flags[2];
        const NETOBJ_GAME *gameobj;

        const NETOBJ_PLAYER_INFO *player_infos[MAX_CLIENTS];
        const NETOBJ_PLAYER_INFO *info_by_score[MAX_CLIENTS];
        int local_cid;
        int num_players;
        int team_size[2];
        bool spectate;
        struct CHARACTERINFO
            bool active;
            // snapshots
            NETOBJ_CHARACTER prev;
            NETOBJ_CHARACTER cur;
            // interpolated position
            vec2 position;
        CHARACTERINFO characters[MAX_CLIENTS];

They only keep one instance of this struct around, so yea um, I guess they don't use diffs? I can't actually find any code relevant to sending this or related information to other clients, but well, obviously it must be in there somewhere. Rather than wasting countless hours trying to sift through some foreign code, I'm wondering if anybody here has any first-hand experience working with states, state diffs and or events. Events seem pretty straight forward, but well, lets face it; state diffs are more robust once in place.

My impression was that both the client and the server kept an array of gamestates, sorted by an ever-increasing (int, long, etc) id and only larger id's (more recent) gamestates were acted upon. I did a sizeof(Player)*CHAR_BIT and saw my player class is 480 bits in size, which is not going to work, but that is fine because I was prepared to only send a limited amount of information across the wire, such as the player ID, player name... other things like that, however... :/

I still don't understand the diffing. I mean, its not like I can diff two integers, or a string of characters, send that across and expect the client to make sense of it. Or, am I supposed to send an entire legit state across the wire, and then just assign all the values to the local state of teh client?

Meh, I just don't see what/how I'm going to do this.

I've of course read:

so, don't "dumb" down your responses Smile

EDIT: Ok, I just re-read the Quake3Networking article. Gave me some good ideas so I've got some things to work off of, but please, if you have experience etc, HOOK ME UP BRO!

Well since everyone else is doing it:
Twilight Coders
Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #2
Since no one else seems to be helping here: Bump. Ninja
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Carbon mouse events blocked by window events krex505 3 4,212 Sep 22, 2006 12:04 AM
Last Post: krex505