Files | |
file | game.c |
Game specific code. | |
file | game.h |
Interface to game specific code. | |
Defines | |
#define | BatchBit(pid) (1 << ((pid) & 0x1F)) |
Computes the bit of a player's flag at the corresponding index of the batch flags. | |
#define | BatchIndex(pid) ((pid) >> 5) |
Computes the index of a player's flag within the batch flags. | |
#define | QueuePlaceName(pid) batchNameDraw[BatchIndex(pid)] |= BatchBit(pid) |
Sets the flag that indicates the given player's name label needs to be redrawn. | |
#define | QueuePlaceName __func_QueuePlaceName |
Sets the flag that indicates the given player's name label needs to be redrawn. | |
#define | QueuePlaceShell(pid) batchShellDraw[BatchIndex(pid)] |= BatchBit(pid) |
Sets the flag that indicates the given player's shell needs to be redrawn. | |
#define | QueuePlaceShell __func_QueuePlaceShell |
Sets the flag that indicates the given player's shell needs to be redrawn. | |
#define | QueuePlaceTank(pid) batchTankDraw[BatchIndex(pid)] |= BatchBit(pid) |
Sets the flag that indicates the given player's tank needs to be redrawn. | |
#define | QueuePlaceTank __func_QueuePlaceTank |
Sets the flag that indicates the given player's tank needs to be redrawn. | |
Typedefs | |
typedef void(*) | PlacementFunc (void *data) |
The function prototype used to place tanks, shells, and names whenever they change or move. | |
Functions | |
static void | BatchRender (Uint32 *batch, PlacementFunc placement, long offset) |
Renders the player's items who's flags are set using the given function. | |
void | DisablePlayerLabels () |
Disables the display of labels showing player names. | |
void | EnablePlayerLabels () |
Enables the display of labels showing player names. | |
void | HandleInput (Uint8 *eventState) |
Responds to the collected user input by changing data for the local player. | |
void | MoveShell (Player *p) |
Moves a player's shell. | |
void | MoveTank (Player *p, int factor) |
Moves a player's tank. | |
void | PlacePlayerLabel (Player *p) |
Puts the label for the player in the correct position. | |
void | QueuePlaceName (Uint8 pid) |
Sets the flag that indicates the given player's name label needs to be redrawn. | |
void | QueuePlaceShell (Uint8 pid) |
Sets the flag that indicates the given player's shell needs to be redrawn. | |
void | QueuePlaceTank (Uint8 pid) |
Sets the flag that indicates the given player's tank needs to be redrawn. | |
void | RemoveShell (Uint8 pid) |
Removes the flag that indicates the given player's shell needs to be redrawn. | |
void | RenderGame () |
static void | RotateTank (Player *p, Sint16 rot) |
Roates a player's tank. | |
void | SpawnTank (Player *p) |
Spawns the given tank. | |
void | UpdatePlayers (Uint32 time) |
Updates all player data to the present time. | |
Variables | |
static Uint32 | batchNameDraw [((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } |
A set of bit flags indicating which player's name labels need to be placed by the renderer. | |
static Uint32 | batchShellDraw [((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } |
A set of bit flags indicating which player's shells need to be placed by the renderer. | |
static Uint32 | batchTankDraw [((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } |
A set of bit flags indicating which player's tanks need to be placed by the renderer. | |
static const Sint32 | motionTable [16][2] |
A table containing the x and y movement deltas based on the rotation value. | |
static const float | normalTable [16][2] |
A table containing normal vectors based on the rotation value. |
#define BatchBit | ( | pid | ) | (1 << ((pid) & 0x1F)) |
Computes the bit of a player's flag at the corresponding index of the batch flags.
For internal use only.
if (batchTankDraw[BatchIndex(p->pid)] & BatchBit(p->pid)) { // the flag for player p is set }
pid | The player's ID. |
Definition at line 279 of file game.c.
Referenced by MoveShell(), QueuePlaceName(), QueuePlaceShell(), QueuePlaceTank(), RemoveShell(), and UpdatePlayers().
#define BatchIndex | ( | pid | ) | ((pid) >> 5) |
Computes the index of a player's flag within the batch flags.
For internal use only.
batchTankDraw[BatchIndex(p->pid)]; // the correct element with the flag // for player p
pid | The player's ID. |
Definition at line 264 of file game.c.
Referenced by MoveShell(), QueuePlaceName(), QueuePlaceShell(), QueuePlaceTank(), RemoveShell(), and UpdatePlayers().
#define QueuePlaceName | ( | pid | ) | batchNameDraw[BatchIndex(pid)] |= BatchBit(pid) |
#define QueuePlaceName __func_QueuePlaceName |
Sets the flag that indicates the given player's name label needs to be redrawn.
For internal use only.
pid | The player's ID. |
Definition at line 309 of file game.c.
Referenced by MoveTank(), and SpawnTank().
#define QueuePlaceShell | ( | pid | ) | batchShellDraw[BatchIndex(pid)] |= BatchBit(pid) |
#define QueuePlaceShell __func_QueuePlaceShell |
Sets the flag that indicates the given player's shell needs to be redrawn.
For internal use only.
pid | The player's ID. |
Definition at line 298 of file game.c.
Referenced by MoveShell(), and ReadPlayer().
#define QueuePlaceTank | ( | pid | ) | batchTankDraw[BatchIndex(pid)] |= BatchBit(pid) |
#define QueuePlaceTank __func_QueuePlaceTank |
Sets the flag that indicates the given player's tank needs to be redrawn.
For internal use only.
pid | The player's ID. |
Definition at line 288 of file game.c.
Referenced by AddPlayer(), MoveTank(), ReadPlayer(), RotateTank(), and SpawnTank().
typedef void(*) PlacementFunc(void *data) |
static void BatchRender | ( | Uint32 * | batch, | |
PlacementFunc | placement, | |||
long | offset | |||
) | [static] |
Renders the player's items who's flags are set using the given function.
For internal use only.
batch | A pointer to the flags to inspect. All flags will be cleared by this function. | |
placement | The function to call that will cause the item to be rendered. It will be passed a pointer to an element within the corresponding Player struct. | |
offset | The offset into the Player struct of the item to pass to the placement function. |
Definition at line 335 of file game.c.
References MAX_PLAYERS, players, and rounddivup.
Referenced by RenderGame().
void DisablePlayerLabels | ( | ) |
Disables the display of labels showing player names.
Definition at line 212 of file game.c.
References ClearRenderItem(), RenderItem_t::enableDraw, Player_t::flags, Player_t::labelName, MAX_PLAYERS, PLAYER_ACTIVE, and players.
Referenced by GameRun().
Here is the call graph for this function:
void EnablePlayerLabels | ( | ) |
Enables the display of labels showing player names.
Definition at line 197 of file game.c.
References RenderItem_t::enableDraw, Player_t::flags, Player_t::labelName, MAX_PLAYERS, PlaceRenderItem(), PLAYER_ACTIVE, PLAYER_DEAD, players, and RenderItem_t::renderer.
Here is the call graph for this function:
void HandleInput | ( | Uint8 * | eventState | ) |
Responds to the collected user input by changing data for the local player.
eventState | An array of input states. The array is indexed by EVENT_TYPES. |
Definition at line 555 of file game.c.
References DEAD_TIME, Player_t::deadTime, EC_BACKWARD, EC_FIRE, EC_FORWARD, EC_ROTLEFT, EC_ROTRIGHT, Player_t::flags, localPlayer, NETSTATE_SERVER, networkState, oldClosest, PLAYER_BACKWARD, PLAYER_DEAD, PLAYER_FORWARD, PLAYER_ROTLEFT, PLAYER_ROTRIGHT, PLAYER_SHOT, PLAYER_STARTROTLEFT, PLAYER_STARTROTRIGHT, PLAYER_UPDATE_SHELL, PLAYER_UPDATE_TANK, players, PlaySound(), SendSpawnRequest(), Player_t::shellDist, SND_CH_LOCALSHOOT, SND_CH_TANK, SND_IDLE, SND_SHOOT, and SpawnTank().
Referenced by GameRun().
Here is the call graph for this function:
void MoveShell | ( | Player * | p | ) |
Moves a player's shell.
Respomsible for removing shells that have traveled their maximum distance.
p | A pointer to the player who's shell must be moved. |
Definition at line 429 of file game.c.
References BatchBit, BatchIndex, batchShellDraw, ClearRenderItem(), dInfo, Player_t::flags, gameOpts, GameOptions_t::height, RenderItem_t::loc, DisplayInfo_t::luh, MOTION_SHELL_FACTOR, motionTable, Player_t::pid, PLAYER_PONG, PLAYER_SHOT, QueuePlaceShell, Player_t::rot, Player_t::shell, SHELL_GUIDED_DIST, SHELL_PONG_DIST, Player_t::shellDist, shellInitLoc, Player_t::shellRot, Player_t::shellX, Player_t::shellY, GameOptions_t::width, Player_t::x, and Player_t::y.
Here is the call graph for this function:
void MoveTank | ( | Player * | p, | |
int | factor | |||
) |
Moves a player's tank.
The direction moved is the facing of the player. Sets the player's dirty flag if the visible position changes.
p | A pointer to the player to move. | |
factor | A factor multiplied to the distance to move. Negative values move the tank backwards and are divided by two. Zero maintains the currently set location and will redarw if needed -- use this when the tank is moved by command of the server. |
Definition at line 386 of file game.c.
References dInfo, gameOpts, GameOptions_t::height, RenderItem_t::loc, DisplayInfo_t::luh, DisplayInfo_t::luw, motionTable, Player_t::pid, QueuePlaceName, QueuePlaceTank, Player_t::rot, Player_t::tank, GameOptions_t::width, Player_t::x, and Player_t::y.
Referenced by FixTankCollision(), and ReadPlayer().
void PlacePlayerLabel | ( | Player * | p | ) |
Puts the label for the player in the correct position.
The tank must already be positioned onscreen with PlaceRenderItem() prior to calling this function. Call this function every time a tank moves whether or not the player labels are displayed.
p | The player who's label must be placed for display. |
Definition at line 157 of file game.c.
References ClearRenderItem(), ClipRectToWH, dInfo, RenderItem_t::enableDraw, Player_t::labelName, RenderItem_t::loc, DisplayInfo_t::luh, DisplayInfo_t::luw, Layer_t::offX, Layer_t::offY, RenderItem_t::parent, DisplayInfo_t::ph, RenderItem_t::physDest, RenderItem_t::physLocY, PlaceRenderItem(), DisplayInfo_t::pw, RenderItem_t::renderer, RenderWillRenderAll(), DisplayInfo_t::showLabels, and Player_t::tank.
Referenced by AddPlayer(), GameInit(), and RenderGame().
Here is the call graph for this function:
void QueuePlaceName | ( | Uint8 | pid | ) |
Sets the flag that indicates the given player's name label needs to be redrawn.
pid | The player's ID. |
Definition at line 994 of file game.c.
References BatchBit, BatchIndex, and batchNameDraw.
void QueuePlaceShell | ( | Uint8 | pid | ) |
Sets the flag that indicates the given player's shell needs to be redrawn.
pid | The player's ID. |
Definition at line 986 of file game.c.
References BatchBit, and BatchIndex.
void QueuePlaceTank | ( | Uint8 | pid | ) |
Sets the flag that indicates the given player's tank needs to be redrawn.
pid | The player's ID. |
Definition at line 982 of file game.c.
References BatchBit, BatchIndex, and batchTankDraw.
void RemoveShell | ( | Uint8 | pid | ) |
Removes the flag that indicates the given player's shell needs to be redrawn.
pid | The player's ID. |
Definition at line 990 of file game.c.
References BatchBit, and BatchIndex.
Referenced by ReadPlayer().
void RenderGame | ( | ) |
Definition at line 372 of file game.c.
References batchNameDraw, BatchRender(), batchShellDraw, batchTankDraw, dInfo, PlacePlayerLabel(), PlaceRenderItem(), and DisplayInfo_t::showLabels.
Here is the call graph for this function:
static void RotateTank | ( | Player * | p, | |
Sint16 | rot | |||
) | [static] |
Roates a player's tank.
Sets the player's dirty flag if the visible rotation changes.
p | A pointer to the player to rotate. | |
rot | A delta that will be applied to the player's rotation. |
Definition at line 484 of file game.c.
References Player_t::flags, Player_t::pid, RenderItem_t::placed, PLAYER_PONG, PLAYER_SHOT, QueuePlaceTank, Player_t::rot, Player_t::shellRot, and Player_t::tank.
Referenced by FixTankCollision(), and UpdatePlayers().
void SpawnTank | ( | Player * | p | ) |
Spawns the given tank.
p | A pointer to the player to spawn. |
Definition at line 503 of file game.c.
References Player_t::deadTime, dInfo, FALSE, Player_t::flags, gameOpts, IsCollidingTank(), RenderItem_t::loc, DisplayInfo_t::luh, DisplayInfo_t::luw, MAX_PLAYERS, NETSTATE_SERVER, networkState, Player_t::pid, PLAYER_ACTIVE, PLAYER_DEAD, PLAYER_UPDATE_DFS, PLAYER_UPDATE_TANK, players, QueuePlaceName, QueuePlaceTank, RandNum(), Player_t::rot, spawnAreas, GameOptions_t::spawnAreas, Player_t::tank, Player_t::team, TRUE, Player_t::x, and Player_t::y.
Referenced by HandleInput(), and HandlePlayerSpawn().
Here is the call graph for this function:
void UpdatePlayers | ( | Uint32 | time | ) |
Updates all player data to the present time.
Definition at line 699 of file game.c.
References BatchBit, BatchIndex, batchTankDraw, ClearRenderItem(), DEAD_TIME, Player_t::deadTime, Player_t::flags, FRAME_DURATION, Player_t::labelName, localPlayer, Player_t::localUpdate, MAX_PLAYERS, Player_t::pid, PLAYER_ACTIVE, PLAYER_DEAD, players, RotateTank(), scores, and Player_t::tank.
Referenced by ProcessNetworkMessages().
Here is the call graph for this function:
Uint32 batchNameDraw[((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } [static] |
A set of bit flags indicating which player's name labels need to be placed by the renderer.
For internal use only.
Definition at line 251 of file game.c.
Referenced by QueuePlaceName(), and RenderGame().
Uint32 batchShellDraw[((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } [static] |
A set of bit flags indicating which player's shells need to be placed by the renderer.
For internal use only.
Definition at line 242 of file game.c.
Referenced by MoveShell(), and RenderGame().
Uint32 batchTankDraw[((((32)%(32)) > 0)?((int)(32)/(32)+1):((int)(32)/(32)))] = { 0 } [static] |
A set of bit flags indicating which player's tanks need to be placed by the renderer.
For internal use only.
Definition at line 233 of file game.c.
Referenced by QueuePlaceTank(), RenderGame(), and UpdatePlayers().
const Sint32 motionTable[16][2] [static] |
A table containing the x and y movement deltas based on the rotation value.
The first dimension is the rotation value, the second contains the x and y offsets.
Definition at line 70 of file game.c.
Referenced by MoveShell(), and MoveTank().
const float normalTable[16][2] [static] |
A table containing normal vectors based on the rotation value.
The first dimension is the rotation value, the second contains the x and y offsets.