Server Help

Non-Subspace Related Coding - multiplayer game design (discussion)

Smong - Thu Nov 23, 2006 4:54 pm
Post subject: multiplayer game design (discussion)
I once played some of the Super Monkey Ball 2 party games. I thought they were quite colorful and fun, at least for the short amount of time I played them.

My aim is to recreate the "monkey fight" mini-game and use server authorative features.

Warning: technical area ahead!

I plan to write the game in two parts:
- A core that can connect to asss, handle file transfer, track players and provide chat functions. It will also provide events, graphics, sound and lvz loading.
- Game code and everything that goes with it such as graphics.

I'll probably release all the headers for the core and all the source for the game.

Questions:
- How to seperate the the core from the game code, where would you draw the line when it comes to players? Take into account players can have a lot of game specific information associated with them, but also the core must track some player info to provide chat functions.
- I'm using C, but for the player module I'm wrapping all the data in functions that read/write to parts of it. This is mainly for anti-cheat reasons. Any suggestions on enumerating players and also should I provide separate "faster" functions for working on the user's own player (to save going through GetSelfPid() all the time).
- Text drawing. I want to provide plain text drawing and a lot of extra more advanced text drawing functions such as centered text, wrapped text, colored text (picking a row from the font sheet). These advanced features can all be mixed and matched, but the functions take different numbers of parameters, any ideas how to implement this? I don't want loads of really long function names and lots of copy/pasted code.
- Server confirmed "commands". Things like move forward, rotate left, etc will be sent to the server for confirmation. The client will move/rotate instantly otherwise lag will be noticeable. However if the client doesn't receive a confirmation after a certain amount of time it should revert to the old position. I've been thinking about this and so far I've thought of "undo" states that get saved on every key press. These would get processed on a timeout, also note they are relative undos, not absolute (otherwise you would be jumping everywhere as soon as you lose 1 confirmation to packet loss). Is there any other way to implement the "revert on timeout" thing?

Here are the relevant parts of the player header file:
Code: Show/Hide
struct PlayerPosition
{
   int x, y, xspeed, yspeed, rotation;
};

struct player_stats_t
{
   int points;
   int kills, deaths;
};

int Player_GetSelfPid(void);
int Player_GetSelfTeam(void);

int Player_IsSpectator(int pid);
int Player_IsSelfSpectator(void);

int Player_GetPlayerCount(void);
void Player_GetPlayerName(int pid, char *namebuf, int buflen);
int Player_GetPlayerTeam(int pid);

/* stats */
void Player_SortByPoints(void);
void Player_SortByName(void);
void Player_EnumStats(void (*func)(int pid, struct player_stats_t *stats,
      void *clos), void *clos);

/* position */
/* copies the value of pos to internal storage. */
void Player_SetPlayerPosition(int pid, struct PlayerPosition *pos);
/* copies the internal values to pos */
void Player_GetPlayerPosition(int pid, struct PlayerPosition *pos);
/* pos is a pointer to a read only version of the player's position. you can
* modify it but it won't get saved unless you call Player_SetPlayerPosition.
* note: this only enums players that are in a ship. */
void Player_EnumPositions(void (*func)(int pid, struct PlayerPosition *pos,
      void *clos), void *clos);


Here's the text header file so far. I haven't done all the features yet, but as you can see the function names and number of parameters is starting to get rediculous. Colored text is limited to the format of the ss font sheet, what if a game wanted a color like brown? Is it worth implementing palette swapping to get arbitrary font colors, this would only be flat colours, not a gradient for simplicity.
Code: Show/Hide
/* these settings are ok for one color of an ss font sheet. */
#define TEXT_FRAMES_WIDE 48
#define TEXT_FRAMES_HIGH 2
#define TEXT_START_CHAR ' '
#define TEXT_END_CHAR (TEXT_START_CHAR + TEXT_FRAMES_WIDE * TEXT_FRAMES_HIGH)

/** font colors */
enum
{
   F_WHITE,
   F_GREEN,
   F_BLUE,
   F_RED,
   F_YELLOW,
   F_PURPLE,
   F_ORANGE,
   F_PINK,

   /* the last one */
   F_COUNT
};

/** basic write text to dest at xy using fontsheet font (the font sheet should
* contain only 1 color). */
void GfxText_DrawText(ImageHandle dest, ImageHandle font, int x, int y,
      const char *format, ...);

/* more complex text drawing */

void GfxText_DrawTextCentered(ImageHandle dest, ImageHandle font, int x, int y,
      const char *format, ...);

void GfxText_DrawColoredText(ImageHandle dest, ImageHandle font, int color,
      int x, int y, const char *format, ...);
void GfxText_DrawColoredTextCentered(ImageHandle dest, ImageHandle font,
      int color, int x, int y, const char *format, ...);


-- End of technical stuff. --

I don't mind if you didn't read all of this post. I will upload some demos and screenshots of the game when they are ready icon_biggrin.gif
Witchie NL - Thu Nov 23, 2006 5:09 pm
Post subject:
i dont see why this is in non-subspace related coding? Its supose to connect to a subSpace (Continuum) server.

Anyway. Great. Im looking forward to see some screenshots.
Smong - Thu Nov 23, 2006 5:29 pm
Post subject:
I'm just reusing the network layer. Pretty much everything else will be different. For example in monkey fight the weaon requires "charging" by holding down a key, this will increase the strength of the weapon.
Cyan~Fire - Thu Nov 23, 2006 5:36 pm
Post subject:
For one, why not just a flag for centering text?

About player data, how about the core keeps track of all the information it needs to plus an opaque value that can be a pointer to a custom extra info structure.

The server-confirmed commands seems like it would probably stress the server a little too much. What about Bak's idea of other players checking?
Smong - Thu Nov 23, 2006 6:00 pm
Post subject:
Player data, I suppose I could make the core give each player a pointer to game defined data. Only problem is possible duplication of data (freq/ship can effect the chat colors/formatting) and at which point does the game get to initialise the pointer. The first can be ignored, the second can be solved easily with player enter/leave callbacks.

I think server-confirmed commands should be fine. Looking at online FPS's, bandwidth usage is 10-100x more than ss and the games update 10x faster than SS. So you don't get 400 players per server in FPS, but I doubt that will happen with this game.
Smong - Sat Nov 25, 2006 6:26 am
Post subject:
I just came up with a friction formula with simplicity in mind and it could be adapted to see if it's the same as ball friction in ss (I'll check later):
Code: Show/Hide
#define CFG_MAX_SPEED 3000
#define CFG_FRICTION ((double)10 / CFG_MAX_SPEED)
...
   // per game tick
   pos->xspeed -= pos->xspeed * CFG_FRICTION;
   pos->yspeed -= pos->yspeed * CFG_FRICTION;

This formula has a terminal velocity property. I suggest replacing CFG_MAX_SPEED with SoccerBallSpeed and 10 with SoccerBallFriction (higher numbers do slow it down more with this formula, so at least that bit's correct).
Bak - Sat Nov 25, 2006 10:56 am
Post subject:
powerball acceleration is not constant.
Smong - Sun Nov 26, 2006 5:23 am
Post subject:
Oh well, that'll save me testing it.
hellzlaker - Sun Nov 26, 2006 11:40 am
Post subject:
thats a cool idea -.- are you going to self host it ?
Smong - Mon Nov 27, 2006 4:25 am
Post subject:
I'll probably get phong to host it on one of his linux asss servers.

Current status player-player collisions are done. Player-glove collisions don't seem to work properly, but I can't know for sure until I add support for the new packets to asss.


Quan Chi2 - Wed Nov 29, 2006 2:47 pm
Post subject:
Smong - brilliant. I have the game and I'd love to try this. Great job. Keep up the good work.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group