#include "gameconfig.h"
#include "net.h"
#include "playernet.h"
#include "obstacle.h"
#include "vector.h"
#include "notice.h"
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for gameconfig.c:
Go to the source code of this file.
Data Structures | |
struct | ConfigFileStackFrame_t |
Contains a stack entry used to track files parsed to load the battle field. More... | |
Defines | |
#define | FILENAMELEN (64 - sizeof(FILE*) - sizeof(int) - 4) |
The maximum length of a file which describes the battle field. | |
#define | MAX_TOKEN_LEN 8 |
The maximum length of tokens in the battle field configuration file. | |
#define | SigErr goto StartLoadConfig_cleanup |
Typedefs | |
typedef ConfigFileStackFrame_t | ConfigFileStackFrame |
Functions | |
void | AddToConfigList (ClientData *client) |
Adds a client to the list of clients waiting for game configuration data. | |
static Bool | CopyAreaData (Vector *input, SDL_Rect **output) |
Copies the specified area data from a temporary vector to a dynamically allocated array. | |
static void | ErrorOut (ConfigFileStackFrame *frame, const rtsa_char *format,...) |
Outputs an error message with a header to stderr, stores it in bfErr for later use by the GUI, and sets the error flag (gameOpts.flags). | |
static Bool | FlagCfgMsg (int max, int index) |
Flags a specific option message as received. | |
Bool | HandleArea (SocketAddr *origin, NetBuffer *buffer, Uint8 *unused, Uint16 noid) |
Handles an incomming message from the network describing the goal and spawn areas. | |
Bool | HandleGameOption (SocketAddr *origin, NetBuffer *buffer, Uint8 *unused, Uint16 noid) |
Handles an incomming message from the network describing the game options. | |
Bool | HandleObstacle (SocketAddr *origin, NetBuffer *buffer, Uint8 *unused, Uint16 noid) |
Handles an incomming message from the network describing the obstacles on the battlefield. | |
Bool | HandleScoreUpdate (SocketAddr *origin, NetBuffer *buffer, Uint8 *unused, Uint16 noid) |
Handles an incomming message from the network with a updated scores. | |
Bool | InitGameConfig (const char *fname) |
Loads in a game configuration and prepares to send the configuration to all clients. | |
static Bool | MakeAreaBuffers (Uint8 *totalAreas, SDL_Rect **areas, Uint8 type) |
Builds a set of messages describing either goal or spawn areas. | |
static Bool | MakeBuffers () |
Creates the set of network messages that will be sent to connecting clients to describe the game configuration. | |
static Bool | OpenFile (ConfigFileStackFrame *frame) |
Opens the named configuration file. | |
static Bool | ReadAreaParams (ConfigFileStackFrame *frame, Vector *areas) |
Reads in the parameters for either a goal or spawn area and records the area within the given array of areas. | |
static Bool | ReadInts (ConfigFileStackFrame *frame, int *array, int flags, int xoff, int yoff) |
Reads in x and y coordinates and/or the width and height parameters. | |
static Bool | ReadToken (ConfigFileStackFrame *frame, char *buff, int loop) |
Reads in a token from the frame's file. | |
void | RemoveFromConfigList (ClientData *client) |
Removes a given client from the list of clients waiting to receive the game configuration if the client is in the list. | |
Bool | SendScoreUpdate (ScoreUpdate *scores, int len) |
Sends a score update to all connected clients. | |
Bool | ServiceGameConfig () |
Handles an iteration of sending game configuration data. | |
static void | StartLoadConfig (const char *fname) |
Loads the game configuration from the specified file. | |
void | UninitGameConfig () |
Destroyes a loaded game configuration and deallocates all memory used to store that configuration. | |
Variables | |
BattleFieldError | bfErr |
The description of the last error to occur while reading a battlefield file. | |
static Vector | cfgMsgBuffVec |
A list of pre-made message buffers that contain the entire game configuration. | |
static const Vector | configInitVec |
The initial values for the vectors used in parsing the battle field file. | |
ClientData * | configListEnd = NULL |
ClientData * | configListStart = NULL |
static Uint16 | destMap [((((32)%(sizeof(Uint16)*8)) > 0)?((int)(32)/(sizeof(Uint16)*8)+1):((int)(32)/(sizeof(Uint16)*8)))] = { 0 } |
The destination map for configuration messages. | |
GameOptions | gameOpts = { 0 } |
The current game's options. | |
SDL_Rect * | goalAreas [TEAM_MAX] |
The lists of CTF goal areas for the game organized by owning team. | |
static Uint32 | lastTransmit = 0 |
The last transmission time. | |
static Uint16 | nextItem = 0 |
The index of the next item to transmit. | |
static Uint32 * | optionMsgFlags = NULL |
A set of flags indicating which option messages have been received from the server. | |
static Uint16 | remainOptionMsgs = 0 |
The number of option messages the client has yet to receive. | |
SDL_Rect * | spawnAreas [TEAM_MAX] |
The lists of spawn areas for the game organized by owning team. |
Copyright (C) 2007 Jeff Jackowski
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Or visit their website at: http://www.gnu.org/
Definition in file gameconfig.c.
#define FILENAMELEN (64 - sizeof(FILE*) - sizeof(int) - 4) |
The maximum length of a file which describes the battle field.
The length is chosen to make the size of ConfigFileStackFrame_t a power of two for more efficient use of memory.
Definition at line 123 of file gameconfig.c.
Referenced by StartLoadConfig().
#define MAX_TOKEN_LEN 8 |
The maximum length of tokens in the battle field configuration file.
Definition at line 57 of file gameconfig.c.
Referenced by ReadAreaParams(), ReadToken(), and StartLoadConfig().
#define SigErr goto StartLoadConfig_cleanup |
Referenced by StartLoadConfig().
typedef struct ConfigFileStackFrame_t ConfigFileStackFrame |
Definition at line 185 of file gameconfig.c.
Copies the specified area data from a temporary vector to a dynamically allocated array.
input | The vector containing all the area data read in from the battlefield file. | |
output | The pointer to an array of rectangles. It will be allocated within this function. |
Definition at line 469 of file gameconfig.c.
References Vector_t::array, ErrorOut(), FALSE, Vector_t::items, obstacles, STRING_ERR_MEM, strings, and TRUE.
Here is the call graph for this function:
static void ErrorOut | ( | ConfigFileStackFrame * | frame, | |
const rtsa_char * | format, | |||
... | ||||
) | [static] |
Outputs an error message with a header to stderr, stores it in bfErr for later use by the GUI, and sets the error flag (gameOpts.flags).
frame | A pointer to the current frame, or NULL if there is no frame. | |
format | A printf style formatting string with the error message. | |
... | The additional data referenced by the formatting string. |
Definition at line 195 of file gameconfig.c.
References bfErr, BFLDERRLEN, BattleFieldError_t::file, ConfigFileStackFrame_t::filename, GameOptions_t::flags, gameOpts, ConfigFileStackFrame_t::line, BattleFieldError_t::line, BattleFieldError_t::msg, OPT_ERROR, prnfile, prnstr, STRING_ERR_READ, strings, vprnstr, and witechar.
Referenced by CopyAreaData(), OpenFile(), ReadAreaParams(), ReadInts(), ReadToken(), and StartLoadConfig().
static Bool FlagCfgMsg | ( | int | max, | |
int | index | |||
) | [static] |
Flags a specific option message as received.
For internal use only.
Definition at line 1316 of file gameconfig.c.
References bitflag, bitindex, FALSE, gameOpts, NETSTATE_CLIENT, networkState, rounddivup, GameOptions_t::totalMsgs, and TRUE.
Referenced by HandleArea(), HandleGameOption(), and HandleObstacle().
static Bool MakeAreaBuffers | ( | Uint8 * | totalAreas, | |
SDL_Rect ** | areas, | |||
Uint8 | type | |||
) | [static] |
Builds a set of messages describing either goal or spawn areas.
totalAreas | A pointer to either gameOpts.goalAreas or gameOpts.spawnAreas. | |
areas | A pointer to either goalAreas or spawnAreas. | |
type | The message type ID, either MSG_TYPE_GOAL or MSG_TYPE_SPAWN. |
Definition at line 883 of file gameconfig.c.
References BufferFree(), BufferNew(), cfgMsgBuffVec, NetBuffer_t::data, FALSE, Vector_t::items, MSG_MAX_SIZE, MSG_WRITE_16, MSG_WRITE_8, and Vector_t::VectorAdd().
Referenced by MakeBuffers().
Here is the call graph for this function:
static Bool MakeBuffers | ( | ) | [static] |
Creates the set of network messages that will be sent to connecting clients to describe the game configuration.
Definition at line 980 of file gameconfig.c.
References Vector_t::array, BufferFree(), BufferNew(), cfgMsgBuffVec, NetBuffer_t::data, GameOptions_t::duration, FALSE, GameOptions_t::flags, gameOpts, goalAreas, GameOptions_t::goalAreas, GameOptions_t::height, Vector_t::items, NetBuffer_t::length, Obstacle_t::loc, MakeAreaBuffers(), MAX_OBSTACLES_PER_MSG, MSG_TYPE_GOAL, MSG_TYPE_OBSTACLE, MSG_TYPE_OPTION, MSG_TYPE_SPAWN, MSG_WRITE_16, MSG_WRITE_16C, MSG_WRITE_32, GameOptions_t::obstacles, obstacles, prnout, GameOptions_t::rcvdMsgs, spawnAreas, GameOptions_t::spawnAreas, STRING_CMPLOPT, strings, GameOptions_t::teamScore, GameOptions_t::totalMsgs, TRUE, Vector_t::VectorAdd(), Vector_t::VectorDestroy(), GameOptions_t::width, and GameOptions_t::winScore.
Referenced by InitGameConfig().
Here is the call graph for this function:
static Bool OpenFile | ( | ConfigFileStackFrame * | frame | ) | [static] |
Opens the named configuration file.
If the file name has a relative path, it may be loaded from one of three different directories checked in the following order:
frame | The stack frame containing the file name that needs to be opened. The file pointer in the stack will be initialized by this function. It is assumed the initial value of the file pointer is undefined and will not attempt to close the file. |
Definition at line 247 of file gameconfig.c.
References ErrorOut(), FALSE, ConfigFileStackFrame_t::file, ConfigFileStackFrame_t::filename, STRING_ERR_BACKSLASH, strings, and TRUE.
Referenced by StartLoadConfig().
Here is the call graph for this function:
static Bool ReadAreaParams | ( | ConfigFileStackFrame * | frame, | |
Vector * | areas | |||
) | [static] |
Reads in the parameters for either a goal or spawn area and records the area within the given array of areas.
frame | The stack frame; used to present information on errors. | |
areas | The array of Vectors that will take the new area. |
Definition at line 414 of file gameconfig.c.
References ErrorOut(), FALSE, MAX_TOKEN_LEN, ReadInts(), ReadToken(), STRING_ERR_BADOWN, STRING_ERR_MEM, strings, TEAM_BLUE, TEAM_RED, TRUE, Vector_t::VectorAdd(), ConfigFileStackFrame_t::xoffset, and ConfigFileStackFrame_t::yoffset.
Referenced by StartLoadConfig().
Here is the call graph for this function:
static Bool ReadInts | ( | ConfigFileStackFrame * | frame, | |
int * | array, | |||
int | flags, | |||
int | xoff, | |||
int | yoff | |||
) | [static] |
Reads in x and y coordinates and/or the width and height parameters.
The range of all parameters are checked for validity, and the current offset is added to the coordinates.
frame | The current stack frame to operate on. | |
array | An array of integers. Starting at index zero, the elemenets are: x, y, w, h. | |
flags | Bit fields that modify the operation.
| |
xoff | The X offset used to modify the x coordinate read in from the file. | |
yoff | The Y offset used to modify the y coordinate read in from the file. |
Definition at line 323 of file gameconfig.c.
References ErrorOut(), FALSE, ConfigFileStackFrame_t::file, ConfigFileStackFrame_t::flipHoriz, ConfigFileStackFrame_t::flipVert, gameOpts, GameOptions_t::height, ConfigFileStackFrame_t::height, STRING_ERR_PARAM, STRING_ERR_WHRANGE, STRING_ERR_XYRANGE, strings, ConfigFileStackFrame_t::transpose, TRUE, GameOptions_t::width, and ConfigFileStackFrame_t::width.
Referenced by ReadAreaParams(), and StartLoadConfig().
Here is the call graph for this function:
static Bool ReadToken | ( | ConfigFileStackFrame * | frame, | |
char * | buff, | |||
int | loop | |||
) | [static] |
Reads in a token from the frame's file.
frame | The stack frame to work upon. | |
buff | The buffer that will hold the data. It is assumed that the buffer is MAX_TOKEN_LEN bytes long. | |
loop | The starting index used with the buffer. |
Definition at line 274 of file gameconfig.c.
References ErrorOut(), FALSE, ConfigFileStackFrame_t::file, ConfigFileStackFrame_t::line, MAX_TOKEN_LEN, STRING_ERR_EOL, STRING_ERR_IO, and strings.
Referenced by ReadAreaParams(), and StartLoadConfig().
Here is the call graph for this function:
static void StartLoadConfig | ( | const char * | fname | ) | [static] |
Loads the game configuration from the specified file.
fname | The name of the file to load. |
Definition at line 488 of file gameconfig.c.
References Vector_t::array, configInitVec, ErrorOut(), ConfigFileStackFrame_t::file, ConfigFileStackFrame_t::filename, FILENAMELEN, ConfigFileStackFrame_t::flags, ConfigFileStackFrame_t::flipHoriz, ConfigFileStackFrame_t::flipVert, gameOpts, ConfigFileStackFrame_t::height, GameOptions_t::height, Vector_t::items, Vector_t::itemSize, ConfigFileStackFrame_t::line, MAX_TOKEN_LEN, OpenFile(), ReadAreaParams(), ReadInts(), ReadToken(), SigErr, STRING_ERR_EOFINC, STRING_ERR_EOFNAME, STRING_ERR_FLDSMALL, STRING_ERR_FOPEN, STRING_ERR_INVLDKEY, STRING_ERR_MEM, STRING_ERR_NAMELONG, strings, TEAM_BLUE, TEAM_MAX, TEAM_RED, ConfigFileStackFrame_t::transpose, TRUE, Vector_t::VectorAdd(), Vector_t::VectorInit(), Vector_t::VectorPop(), ConfigFileStackFrame_t::width, GameOptions_t::width, ConfigFileStackFrame_t::xoffset, and ConfigFileStackFrame_t::yoffset.
Referenced by InitGameConfig().
Here is the call graph for this function:
The description of the last error to occur while reading a battlefield file.
If no error has occured, the data is invalid.
Definition at line 52 of file gameconfig.c.
Referenced by BfldErrResize(), and ErrorOut().
Vector cfgMsgBuffVec [static] |
Initial value:
{ NULL, BufferVecDestr, NULL, sizeof(NetBuffer*), 0, 0, 32 }
Definition at line 63 of file gameconfig.c.
Referenced by InitGameConfig(), MakeAreaBuffers(), MakeBuffers(), and ServiceGameConfig().
const Vector configInitVec [static] |
Initial value:
{
NULL,
NULL,
NULL,
sizeof(SDL_Rect),
0,
0,
64
}
Vector::itemSize is initialized to the size of an SDL_Rect since it is the most common value in this context.
Definition at line 108 of file gameconfig.c.
Referenced by StartLoadConfig().
ClientData * configListEnd = NULL |
Definition at line 45 of file gameconfig.c.
Referenced by AddToConfigList(), RemoveFromConfigList(), and UninitGameConfig().
ClientData* configListStart = NULL |
Definition at line 45 of file gameconfig.c.
Referenced by AddToConfigList(), RemoveFromConfigList(), ServiceGameConfig(), and UninitGameConfig().
Uint16 destMap[((((32)%(sizeof(Uint16)*8)) > 0)?((int)(32)/(sizeof(Uint16)*8)+1):((int)(32)/(sizeof(Uint16)*8)))] = { 0 } [static] |
The destination map for configuration messages.
This is stored so that it only has to be recalculated whenever a client connects, disconnects, or has receieved all the configuration messages rather than every time a message is sent.
Definition at line 101 of file gameconfig.c.
Referenced by HandleAck().
GameOptions gameOpts = { 0 } |
The current game's options.
Definition at line 47 of file gameconfig.c.
Referenced by ErrorOut(), FlagCfgMsg(), GameInit(), GameRun(), HandleArea(), HandleGameOption(), HandleObstacle(), HandleScoreUpdate(), InitGameConfig(), MakeBuffers(), MessageSrvToCli(), MoveShell(), MoveTank(), ObstacleInit(), ObstacleUninit(), ReadInts(), RenderScore(), SendScoreUpdate(), ServiceGameConfig(), SetupScrolling(), SpawnTank(), StartLoadConfig(), and UninitGameConfig().
SDL_Rect* goalAreas[TEAM_MAX] |
The lists of CTF goal areas for the game organized by owning team.
Definition at line 50 of file gameconfig.c.
Referenced by HandleArea(), MakeBuffers(), and UninitGameConfig().
Uint32 lastTransmit = 0 [static] |
Uint16 nextItem = 0 [static] |
Uint32* optionMsgFlags = NULL [static] |
A set of flags indicating which option messages have been received from the server.
Definition at line 77 of file gameconfig.c.
Uint16 remainOptionMsgs = 0 [static] |
The number of option messages the client has yet to receive.
Used to check when all option messages have been read.
Definition at line 93 of file gameconfig.c.
SDL_Rect* spawnAreas[TEAM_MAX] |
The lists of spawn areas for the game organized by owning team.
Definition at line 49 of file gameconfig.c.
Referenced by HandleArea(), MakeBuffers(), SpawnTank(), and UninitGameConfig().