Skip to content

Commit

Permalink
inline gameplay variables (closes #63)
Browse files Browse the repository at this point in the history
LaraItem and Camera are used by sound routines.
  • Loading branch information
rr- committed Mar 18, 2021
1 parent 8a6e040 commit de3b790
Show file tree
Hide file tree
Showing 27 changed files with 583 additions and 331 deletions.
30 changes: 15 additions & 15 deletions src/3dsystem/3d_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@

void phd_GenerateW2V(PHD_3DPOS *viewpos)
{
PhdMatrixPtr = &MatrixStack;
PhdMatrixPtr = &MatrixStack[0];
int32_t sx = phd_sin(viewpos->x_rot);
int32_t cx = phd_cos(viewpos->x_rot);
int32_t sy = phd_sin(viewpos->y_rot);
int32_t cy = phd_cos(viewpos->y_rot);
int32_t sz = phd_sin(viewpos->z_rot);
int32_t cz = phd_cos(viewpos->z_rot);

MatrixStack._00 = TRIGMULT3(sx, sy, sz) + TRIGMULT2(cy, cz);
MatrixStack._01 = TRIGMULT2(cx, sz);
MatrixStack._02 = TRIGMULT3(sx, cy, sz) - TRIGMULT2(sy, cz);
MatrixStack._10 = TRIGMULT3(sx, sy, cz) - TRIGMULT2(cy, sz);
MatrixStack._11 = TRIGMULT2(cx, cz);
MatrixStack._12 = TRIGMULT3(sx, cy, cz) + TRIGMULT2(sy, sz);
MatrixStack._20 = TRIGMULT2(cx, sy);
MatrixStack._21 = -sx;
MatrixStack._22 = TRIGMULT2(cx, cy);
MatrixStack._03 = viewpos->x;
MatrixStack._13 = viewpos->y;
MatrixStack._23 = viewpos->z;
W2VMatrix = MatrixStack;
MatrixStack[0]._00 = TRIGMULT3(sx, sy, sz) + TRIGMULT2(cy, cz);
MatrixStack[0]._01 = TRIGMULT2(cx, sz);
MatrixStack[0]._02 = TRIGMULT3(sx, cy, sz) - TRIGMULT2(sy, cz);
MatrixStack[0]._10 = TRIGMULT3(sx, sy, cz) - TRIGMULT2(cy, sz);
MatrixStack[0]._11 = TRIGMULT2(cx, cz);
MatrixStack[0]._12 = TRIGMULT3(sx, cy, cz) + TRIGMULT2(sy, sz);
MatrixStack[0]._20 = TRIGMULT2(cx, sy);
MatrixStack[0]._21 = -sx;
MatrixStack[0]._22 = TRIGMULT2(cx, cy);
MatrixStack[0]._03 = viewpos->x;
MatrixStack[0]._13 = viewpos->y;
MatrixStack[0]._23 = viewpos->z;
W2VMatrix = MatrixStack[0];
}

void phd_LookAt(
Expand Down Expand Up @@ -355,7 +355,7 @@ void phd_InitWindow(
PhdRight = PhdWinMaxX;
PhdBottom = PhdWinMaxY;

PhdMatrixPtr = &MatrixStack;
PhdMatrixPtr = &MatrixStack[0];
}

void AlterFOV(PHD_ANGLE fov)
Expand Down
13 changes: 7 additions & 6 deletions src/game/ai/pierre.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

BITE_INFO PierreGun1 = { 60, 200, 0, 11 };
BITE_INFO PierreGun2 = { -57, 200, 0, 14 };
int16_t PierreItemNum = NO_ITEM;

void SetupPierre(OBJECT_INFO *obj)
{
Expand All @@ -36,11 +37,11 @@ void PierreControl(int16_t item_num)
{
ITEM_INFO *item = &Items[item_num];

if (PierreItem == NO_ITEM) {
PierreItem = item_num;
} else if (PierreItem != item_num) {
if (PierreItemNum == NO_ITEM) {
PierreItemNum = item_num;
} else if (PierreItemNum != item_num) {
if (item->flags & IF_ONESHOT) {
KillItem(PierreItem);
KillItem(PierreItemNum);
} else {
KillItem(item_num);
}
Expand Down Expand Up @@ -199,7 +200,7 @@ void PierreControl(int16_t item_num)
item->hit_points = DONT_TARGET;
DisableBaddieAI(item_num);
KillItem(item_num);
PierreItem = NO_ITEM;
PierreItemNum = NO_ITEM;
}
}

Expand All @@ -209,6 +210,6 @@ void PierreControl(int16_t item_num)
item->hit_points = DONT_TARGET;
DisableBaddieAI(item_num);
KillItem(item_num);
PierreItem = NO_ITEM;
PierreItemNum = NO_ITEM;
}
}
1 change: 1 addition & 0 deletions src/game/ai/pierre.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum {
PIERRE_SHOOT = 7,
} PIERRE_ANIM;

extern int16_t PierreItemNum;
extern BITE_INFO PierreGun1;
extern BITE_INFO PierreGun2;

Expand Down
26 changes: 14 additions & 12 deletions src/game/cinema.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include "util.h"

static int32_t OldSoundIsActive;
static const int32_t CinematicAnimationRate = 0x8000;

int32_t StartCinematic(int32_t level_num)
{
CinematicLevel = level_num;
if (!InitialiseLevel(level_num, GFL_CUTSCENE)) {
return END_ACTION;
}
Expand Down Expand Up @@ -73,8 +73,10 @@ void InitCinematicRooms()

int32_t DoCinematic(int32_t nframes)
{
CinematicFrameCount += CinematicAnimationRate * nframes;
while (CinematicFrameCount >= 0) {
static int32_t frame_count = 0;

frame_count += CinematicAnimationRate * nframes;
while (frame_count >= 0) {
S_UpdateInput();
if (Input & IN_OPTION) {
return 1;
Expand Down Expand Up @@ -113,7 +115,7 @@ int32_t DoCinematic(int32_t nframes)
return 1;
}

CinematicFrameCount -= 0x10000;
frame_count -= 0x10000;
}

return 0;
Expand Down Expand Up @@ -200,15 +202,15 @@ void InGameCinematicCamera()
int16_t fov = ptr[6];
int16_t roll = ptr[7];

int32_t c = phd_cos(CinematicPosition.y_rot);
int32_t s = phd_sin(CinematicPosition.y_rot);
int32_t c = phd_cos(CinePosition.y_rot);
int32_t s = phd_sin(CinePosition.y_rot);

Camera.target.x = CinematicPosition.x + ((c * tx + s * tz) >> 14);
Camera.target.y = CinematicPosition.y + ty;
Camera.target.z = CinematicPosition.z + ((c * tz - s * tx) >> 14);
Camera.pos.x = CinematicPosition.x + ((s * cz + c * cx) >> 14);
Camera.pos.y = CinematicPosition.y + cy;
Camera.pos.z = CinematicPosition.z + ((c * cz - s * cx) >> 14);
Camera.target.x = CinePosition.x + ((c * tx + s * tz) >> 14);
Camera.target.y = CinePosition.y + ty;
Camera.target.z = CinePosition.z + ((c * tz - s * tx) >> 14);
Camera.pos.x = CinePosition.x + ((s * cz + c * cx) >> 14);
Camera.pos.y = CinePosition.y + cy;
Camera.pos.z = CinePosition.z + ((c * cz - s * cx) >> 14);

AlterFOV(fov);

Expand Down
2 changes: 1 addition & 1 deletion src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ void LaraBaddieCollision(ITEM_INFO *lara_item, COLL_INFO *coll)
Lara.hit_frame = 0;
}

InventoryChosen = -1;
InvChosen = -1;
}

void EffectSpaz(ITEM_INFO *lara_item, COLL_INFO *coll)
Expand Down
4 changes: 3 additions & 1 deletion src/game/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define ONE_SECOND 30
#define HALF_SECOND 15

#define MAX_MATRICES 40
#define MAX_NESTED_MATRICES 32
#define MAX_REQLINES 16
#define MAX_SAMPLES 256
#define MAX_SAVE_SLOTS 16
Expand All @@ -26,7 +28,7 @@
#define MAX_SPRITES 512
#define MAX_FLIP_MAPS 10
#define DEMO_COUNT_MAX 9000
#define NUMBER_ITEMS 256
#define MAX_ITEMS 256
#define MAX_SECRETS 16
#define MAX_SAVEGAME_BUFFER (10 * 1024)
#define GRAVITY 6
Expand Down
15 changes: 9 additions & 6 deletions src/game/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <stddef.h>

static const int32_t AnimationRate = 0x8000;

void CheckCheatMode()
{
static int32_t cheat_mode = 0;
Expand Down Expand Up @@ -127,13 +129,14 @@ void CheckCheatMode()

int32_t ControlPhase(int32_t nframes, int32_t demo_mode)
{
static int32_t frame_count = 0;
int32_t return_val = 0;
if (nframes > MAX_FRAMES) {
nframes = MAX_FRAMES;
}

FrameCount += AnimationRate * nframes;
while (FrameCount >= 0) {
frame_count += AnimationRate * nframes;
while (frame_count >= 0) {
if (CDTrack > 0) {
S_CDLoop();
}
Expand Down Expand Up @@ -197,11 +200,11 @@ int32_t ControlPhase(int32_t nframes, int32_t demo_mode)

OverlayFlag = 1;
if (return_val != GF_NOP) {
if (InventoryExtraData[0] != 1) {
if (InvExtraData[0] != 1) {
return return_val;
}
if (CurrentLevel == GF.gym_level_num) {
switch (InventoryExtraData[1]) {
switch (InvExtraData[1]) {
case 0:
SaveGame.bonus_flag = 0;
break;
Expand All @@ -220,7 +223,7 @@ int32_t ControlPhase(int32_t nframes, int32_t demo_mode)
}

CreateSaveGameInfo();
S_SaveGame(&SaveGame, InventoryExtraData[1]);
S_SaveGame(&SaveGame, InvExtraData[1]);
S_WriteUserSettings();
}
}
Expand Down Expand Up @@ -263,7 +266,7 @@ int32_t ControlPhase(int32_t nframes, int32_t demo_mode)
}
}

FrameCount -= 0x10000;
frame_count -= 0x10000;
}

return GF_NOP;
Expand Down
15 changes: 9 additions & 6 deletions src/game/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "util.h"

static int16_t InterpolatedBounds[6];

int32_t DrawPhaseCinematic()
{
S_InitialisePolyList();
Expand Down Expand Up @@ -107,7 +109,7 @@ void GetRoomBounds(int16_t room_num)

int32_t SetRoomBounds(int16_t *objptr, int16_t room_num, ROOM_INFO *parent)
{
// TODO: the way the game passes the objptr is dangerous and relies on
// XXX: the way the game passes the objptr is dangerous and relies on
// layout of DOOR_INFO

if ((objptr[0] * (parent->x + objptr[3] - W2VMatrix._03))
Expand All @@ -117,6 +119,7 @@ int32_t SetRoomBounds(int16_t *objptr, int16_t room_num, ROOM_INFO *parent)
return 0;
}

DOOR_VBUF door_vbuf[4];
int32_t left = parent->right;
int32_t right = parent->left;
int32_t top = parent->bottom;
Expand All @@ -134,9 +137,9 @@ int32_t SetRoomBounds(int16_t *objptr, int16_t room_num, ROOM_INFO *parent)
+ mptr->_12 * objptr[2] + mptr->_13;
int32_t zv = mptr->_20 * objptr[0] + mptr->_21 * objptr[1]
+ mptr->_22 * objptr[2] + mptr->_23;
DoorVBuf[i].xv = xv;
DoorVBuf[i].yv = yv;
DoorVBuf[i].zv = zv;
door_vbuf[i].xv = xv;
door_vbuf[i].yv = yv;
door_vbuf[i].zv = zv;
objptr += 3;

if (zv > 0) {
Expand Down Expand Up @@ -176,8 +179,8 @@ int32_t SetRoomBounds(int16_t *objptr, int16_t room_num, ROOM_INFO *parent)
}

if (z_behind > 0) {
DOOR_VBUF *dest = &DoorVBuf[0];
DOOR_VBUF *last = &DoorVBuf[3];
DOOR_VBUF *dest = &door_vbuf[0];
DOOR_VBUF *last = &door_vbuf[3];
for (int i = 0; i < 4; i++) {
if ((dest->zv < 0) ^ (last->zv < 0)) {
if (dest->xv < 0 && last->xv < 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ int32_t StopGame()
}

S_FadeToBlack();
if (!InventoryChosen) {
if (!InvChosen) {
return GF_EXIT_TO_TITLE;
}

if (InventoryExtraData[0] == 0) {
return GF_START_SAVED_GAME | InventoryExtraData[1];
} else if (InventoryExtraData[0] == 1) {
if (InvExtraData[0] == 0) {
return GF_START_SAVED_GAME | InvExtraData[1];
} else if (InvExtraData[0] == 1) {
return GF_START_GAME | GF.first_level_num;
} else {
return GF_EXIT_TO_TITLE;
Expand Down
11 changes: 7 additions & 4 deletions src/game/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define MAX_PICKUP_COLUMNS 4
#define MAX_PICKUPS 16

TEXTSTRING *AmmoText = NULL;
static DISPLAYPU Pickups[MAX_PICKUPS];

void DrawGameInfo()
Expand All @@ -33,6 +34,8 @@ void DrawGameInfo()

void DrawHealthBar()
{
static int32_t old_hit_points = 0;

for (int i = 0; i < 6; i++) {
BarOffsetY[i] = 0;
}
Expand All @@ -44,8 +47,8 @@ void DrawHealthBar()
hit_points = LARA_HITPOINTS;
}

if (OldHitPoints != hit_points) {
OldHitPoints = hit_points;
if (old_hit_points != hit_points) {
old_hit_points = hit_points;
HealthBarTimer = 40;
}

Expand Down Expand Up @@ -197,9 +200,9 @@ void InitialisePickUpDisplay()

void DrawPickups()
{
int32_t old_game_timer = OldGameTimer;
OldGameTimer = SaveGame.timer;
static int32_t old_game_timer = 0;
int16_t time = SaveGame.timer - old_game_timer;
old_game_timer = SaveGame.timer;

if (time > 0 && time < 60) {
int32_t sprite_height = MIN(PhdWinWidth, PhdWinHeight * 320 / 200) / 10;
Expand Down
4 changes: 4 additions & 0 deletions src/game/health.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#ifndef T1M_GAME_HEALTH_H
#define T1M_GAME_HEALTH_H

#include "game/types.h"

#include <stdint.h>

extern TEXTSTRING *AmmoText;

void MakeAmmoString(char *string);
void DrawAmmoInfo();
void DrawGameInfo();
Expand Down
3 changes: 3 additions & 0 deletions src/game/inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

#include <stdint.h>

extern TEXTSTRING *InvItemText[2];
extern TEXTSTRING *InvRingText;

int32_t Display_Inventory(int inv_mode);
void Construct_Inventory();
void SelectMeshes(INVENTORY_ITEM *inv_item);
Expand Down
Loading

0 comments on commit de3b790

Please sign in to comment.