mirror of
https://github.com/OpenDriver2/REDRIVER2.git
synced 2024-11-22 10:22:48 +01:00
- reduce stack memory usage by refactoring game into states
This commit is contained in:
parent
acf4291916
commit
12c44bf17a
@ -34,14 +34,12 @@ POLYCOORD polycoords[6] =
|
||||
void ShowHiresScreens(char **names, int delay, int wait)
|
||||
{
|
||||
int timedelay;
|
||||
char *filename;
|
||||
char* filename;
|
||||
|
||||
filename = *names;
|
||||
|
||||
do {
|
||||
if (!filename)
|
||||
return;
|
||||
|
||||
while (filename)
|
||||
{
|
||||
FadeInHiresScreen(filename);
|
||||
|
||||
timedelay = delay-1;
|
||||
@ -59,7 +57,7 @@ void ShowHiresScreens(char **names, int delay, int wait)
|
||||
FadeOutHiresScreen();
|
||||
|
||||
filename = *(++names);
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
|
@ -1,8 +1,6 @@
|
||||
#include "driver2.h"
|
||||
#include "glaunch.h"
|
||||
|
||||
|
||||
|
||||
#include "system.h"
|
||||
#include "main.h"
|
||||
#include "E3stuff.h"
|
||||
@ -13,9 +11,9 @@
|
||||
#include "gamesnd.h"
|
||||
#include "camera.h"
|
||||
#include "fmvplay.h"
|
||||
#include "state.h"
|
||||
#include "Frontend/FEmain.h"
|
||||
|
||||
|
||||
#include "LIBETC.H"
|
||||
#include "STRINGS.H"
|
||||
|
||||
@ -116,13 +114,26 @@ int gFurthestMission = 0;
|
||||
|
||||
int gWantNight = 0;
|
||||
|
||||
// [D] [T]
|
||||
void GameStart(void)
|
||||
{
|
||||
int oldVibrationMode;
|
||||
int SurvivalCopSettingsBackup;
|
||||
ACTIVE_CHEATS CheatsBackup;
|
||||
int gOldVibrationMode;
|
||||
int gSurvivalCopSettingsBackup;
|
||||
ACTIVE_CHEATS gCheatsBackup;
|
||||
|
||||
void RestoreGameVars()
|
||||
{
|
||||
#ifdef CUTSCENE_RECORDER
|
||||
extern int gCutsceneAsReplay;
|
||||
gCutsceneAsReplay = 0;
|
||||
#endif
|
||||
|
||||
gLoadedReplay = 0;
|
||||
gVibration = gOldVibrationMode;
|
||||
gCopDifficultyLevel = gSurvivalCopSettingsBackup;
|
||||
ActiveCheats = gCheatsBackup;
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void State_GameStart(void* param)
|
||||
{
|
||||
if (GameType != GAME_CONTINUEMISSION &&
|
||||
GameType != GAME_MISSION &&
|
||||
GameType != GAME_REPLAYMISSION)
|
||||
@ -133,17 +144,17 @@ void GameStart(void)
|
||||
DrawSync(0);
|
||||
VSync(0);
|
||||
|
||||
FreeXM();
|
||||
SsSetSerialVol(0, 0, 0);
|
||||
|
||||
gInFrontend = 0;
|
||||
AttractMode = 0;
|
||||
|
||||
FreeXM();
|
||||
|
||||
SsSetSerialVol(0, 0, 0);
|
||||
|
||||
SurvivalCopSettingsBackup = gCopDifficultyLevel;
|
||||
CheatsBackup = ActiveCheats;
|
||||
NewLevel = 1;
|
||||
|
||||
gOldVibrationMode = gVibration;
|
||||
gSurvivalCopSettingsBackup = gCopDifficultyLevel;
|
||||
gCheatsBackup = ActiveCheats;
|
||||
|
||||
switch (GameType)
|
||||
{
|
||||
case GAME_MISSION:
|
||||
@ -158,35 +169,28 @@ void GameStart(void)
|
||||
|
||||
gCurrentMissionNumber += GameLevel * 2 + gWantNight + gSubGameNumber * 440;
|
||||
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_IDLEDEMO:
|
||||
oldVibrationMode = gVibration;
|
||||
|
||||
if (LoadAttractReplay(gCurrentMissionNumber))
|
||||
{
|
||||
gVibration = 0;
|
||||
CurrentGameMode = GAMEMODE_DEMO;
|
||||
gLoadedReplay = 1;
|
||||
|
||||
LaunchGame();
|
||||
|
||||
gLoadedReplay = 0;
|
||||
gVibration = oldVibrationMode;
|
||||
|
||||
gCopDifficultyLevel = SurvivalCopSettingsBackup;
|
||||
ActiveCheats = CheatsBackup;
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
}
|
||||
|
||||
break;
|
||||
case GAME_PURSUIT:
|
||||
gCurrentMissionNumber = 70 + GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_GETAWAY:
|
||||
gCurrentMissionNumber = 102 + GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_GATERACE:
|
||||
@ -196,7 +200,8 @@ void GameStart(void)
|
||||
gCurrentMissionNumber = 164;
|
||||
|
||||
gCurrentMissionNumber += GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_CHECKPOINT:
|
||||
if (NumPlayers == 1)
|
||||
@ -205,12 +210,12 @@ void GameStart(void)
|
||||
gCurrentMissionNumber = 228;
|
||||
|
||||
gCurrentMissionNumber += GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_TRAILBLAZER:
|
||||
gCurrentMissionNumber = GameLevel * 8 + 260 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_SURVIVAL:
|
||||
@ -223,28 +228,25 @@ void GameStart(void)
|
||||
|
||||
gCurrentMissionNumber += GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
|
||||
LaunchGame();
|
||||
|
||||
gCopDifficultyLevel = SurvivalCopSettingsBackup;
|
||||
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
break;
|
||||
case GAME_REPLAYMISSION:
|
||||
GameType = GAME_MISSION;
|
||||
|
||||
if (FindMissionLadderPos(gCurrentMissionNumber) != 0)
|
||||
if (FindMissionLadderPos(gCurrentMissionNumber))
|
||||
RunMissionLadder(0);
|
||||
|
||||
GameType = GAME_REPLAYMISSION;
|
||||
//GameType = GAME_REPLAYMISSION;
|
||||
|
||||
break;
|
||||
case GAME_COPSANDROBBERS:
|
||||
gCurrentMissionNumber = 420 + GameLevel * 8 + gWantNight * 4 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_CAPTURETHEFLAG:
|
||||
gCurrentMissionNumber = 352 + GameLevel * 8 + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_SECRET:
|
||||
@ -254,7 +256,7 @@ void GameStart(void)
|
||||
gCurrentMissionNumber = 484;
|
||||
|
||||
gCurrentMissionNumber += gWantNight + gSubGameNumber;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
case GAME_CONTINUEMISSION:
|
||||
@ -267,33 +269,30 @@ void GameStart(void)
|
||||
gLoadedReplay = 1;
|
||||
GameType = StoredGameType;
|
||||
|
||||
LaunchGame();
|
||||
|
||||
gLoadedReplay = 0;
|
||||
|
||||
gCopDifficultyLevel = SurvivalCopSettingsBackup;
|
||||
ActiveCheats = CheatsBackup;
|
||||
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
wantedCar[1] = -1;
|
||||
wantedCar[0] = -1;
|
||||
// [A]
|
||||
wantedWeather = -1;
|
||||
wantedTimeOfDay = -1;
|
||||
|
||||
gHaveStoredData = 0;
|
||||
|
||||
ReInitFrontend();
|
||||
}
|
||||
|
||||
void State_InitFrontEnd(void* param)
|
||||
{
|
||||
if ((int)param)
|
||||
{
|
||||
InitFrontendDisplay();
|
||||
InitFrontend();
|
||||
}
|
||||
else
|
||||
ReInitFrontend();
|
||||
|
||||
SetState(STATE_FRONTEND);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void StartRender(int renderNum)
|
||||
void State_FMVPlay(void* param)
|
||||
{
|
||||
PlayFMV(renderNum);
|
||||
ReInitFrontend();
|
||||
PlayFMV((int)param);
|
||||
SetState(STATE_INITFRONTEND);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
@ -304,6 +303,14 @@ void ReInitFrontend(void)
|
||||
old_camera_change = 0;
|
||||
camera_change = 0;
|
||||
|
||||
wantedCar[1] = -1;
|
||||
wantedCar[0] = -1;
|
||||
|
||||
wantedWeather = -1;
|
||||
wantedTimeOfDay = -1;
|
||||
|
||||
gHaveStoredData = 0;
|
||||
|
||||
EnableDisplay();
|
||||
DrawSync(0);
|
||||
VSync(0);
|
||||
@ -325,6 +332,8 @@ void ReInitFrontend(void)
|
||||
Loadfile("FRONTEND.BIN", 0x801C0000);
|
||||
#endif // PSX
|
||||
|
||||
// switch to state STATE_INITFRONTEND
|
||||
|
||||
SetFEDrawMode();
|
||||
DrawSync(0);
|
||||
EnableDisplay();
|
||||
@ -333,8 +342,10 @@ void ReInitFrontend(void)
|
||||
ClearImage(&rect, 0, 0, 0);
|
||||
|
||||
DrawSync(0);
|
||||
|
||||
LoadFrontendScreens(1);
|
||||
ReInitScreens();
|
||||
|
||||
DrawSync(0);
|
||||
VSync(0);
|
||||
|
||||
@ -343,20 +354,18 @@ void ReInitFrontend(void)
|
||||
|
||||
SetDispMask(1);
|
||||
|
||||
//LoadedLevel = 0xff;
|
||||
bRedrawFrontend = 1;
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void RunMissionLadder(int newgame)
|
||||
void State_MissionLadder(void* param)
|
||||
{
|
||||
bool quit;
|
||||
int quit;
|
||||
int newgame;
|
||||
MISSION_STEP* CurrentStep;
|
||||
RENDER_ARGS RenderArgs;
|
||||
|
||||
quit = false;
|
||||
if (newgame != 0)
|
||||
gMissionLadderPos = 0;
|
||||
newgame = (int)param;
|
||||
quit = 0;
|
||||
|
||||
RenderArgs.nRenders = 0;
|
||||
CurrentStep = MissionLadder + gMissionLadderPos;
|
||||
@ -401,8 +410,6 @@ void RunMissionLadder(int newgame)
|
||||
SetPleaseWait(NULL);
|
||||
}
|
||||
|
||||
gMissionLadderPos = CurrentStep - MissionLadder;
|
||||
|
||||
if (CurrentStep->flags == 2)
|
||||
{
|
||||
if (RenderArgs.nRenders != 0)
|
||||
@ -414,17 +421,20 @@ void RunMissionLadder(int newgame)
|
||||
|
||||
SetPleaseWait(NULL);
|
||||
gCurrentMissionNumber = CurrentStep->data;
|
||||
LaunchGame();
|
||||
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
quit = 1;
|
||||
|
||||
/*
|
||||
if (WantedGameMode == GAMEMODE_NEXTMISSION)
|
||||
{
|
||||
if (gFurthestMission < gCurrentMissionNumber)
|
||||
if (gCurrentMissionNumber > gFurthestMission)
|
||||
gFurthestMission = gCurrentMissionNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
quit = true;
|
||||
}
|
||||
quit = 1;
|
||||
}*/
|
||||
}
|
||||
else if (CurrentStep->flags == 1)
|
||||
{
|
||||
@ -446,14 +456,25 @@ void RunMissionLadder(int newgame)
|
||||
|
||||
SetPleaseWait(NULL);
|
||||
|
||||
quit = true;
|
||||
quit = 1;
|
||||
AvailableCheats.cheat5 = true;
|
||||
}
|
||||
|
||||
CurrentStep++;
|
||||
gMissionLadderPos = CurrentStep - MissionLadder;
|
||||
|
||||
} while (!quit);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void RunMissionLadder(int newgame)
|
||||
{
|
||||
if (newgame)
|
||||
gMissionLadderPos = 0;
|
||||
|
||||
SetState(STATE_LADDER, (void*)newgame);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void GetRandomChase(void)
|
||||
{
|
||||
@ -504,7 +525,6 @@ int FindPrevMissionFromLadderPos(int pos)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fakeOtherPlayer = 0;
|
||||
int gMissionCompletionState = 0;
|
||||
char NoPlayerControl = 0;
|
||||
|
||||
@ -517,13 +537,12 @@ MISSION_DATA MissionStartData;
|
||||
MISSION_DATA MissionEndData;
|
||||
|
||||
// [D] [T]
|
||||
void LaunchGame(void)
|
||||
void State_LaunchGame(void* param)
|
||||
{
|
||||
int quit;
|
||||
RECT16 rect{ 0, 0, 512, 512 };
|
||||
|
||||
fakeOtherPlayer = 0;
|
||||
|
||||
|
||||
// STATE_GAMELAUNCH
|
||||
|
||||
ResetGraph(1);
|
||||
SetVideoMode(video_mode);
|
||||
|
||||
@ -542,98 +561,119 @@ void LaunchGame(void)
|
||||
AttractMode = 0;
|
||||
NoPlayerControl = 1;
|
||||
}
|
||||
else if (CurrentGameMode == GAMEMODE_REPLAY)
|
||||
{
|
||||
AttractMode = 0;
|
||||
NoPlayerControl = 1;
|
||||
quick_replay = 1;
|
||||
}
|
||||
else if (CurrentGameMode == GAMEMODE_DEMO)
|
||||
{
|
||||
AttractMode = 1;
|
||||
NoPlayerControl = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
AttractMode = 0;
|
||||
NoPlayerControl = 0;
|
||||
|
||||
if (CurrentGameMode < GAMEMODE_NEXTMISSION)
|
||||
{
|
||||
if (CurrentGameMode == GAMEMODE_REPLAY)
|
||||
{
|
||||
AttractMode = 0;
|
||||
NoPlayerControl = 1;
|
||||
quick_replay = 1;
|
||||
}
|
||||
}
|
||||
else if (CurrentGameMode == GAMEMODE_DEMO)
|
||||
{
|
||||
AttractMode = 1;
|
||||
NoPlayerControl = 1;
|
||||
}
|
||||
}
|
||||
|
||||
AutoDirect = 0;
|
||||
NewLevel = 1;
|
||||
|
||||
quit = 0;
|
||||
// switch to STATE_GAMEINIT
|
||||
SetState(STATE_GAMEINIT);
|
||||
}
|
||||
|
||||
do {
|
||||
GameInit();
|
||||
GameLoop();
|
||||
// [A] state function
|
||||
void State_GameComplete(void* param)
|
||||
{
|
||||
GameStates nextState;
|
||||
int stateParam;
|
||||
RECT16 rect;
|
||||
|
||||
switch (WantedGameMode)
|
||||
// restart is default
|
||||
nextState = STATE_GAMEINIT;
|
||||
stateParam = 0;
|
||||
|
||||
switch (WantedGameMode)
|
||||
{
|
||||
case GAMEMODE_NORMAL:
|
||||
case GAMEMODE_QUIT:
|
||||
case GAMEMODE_DEMO:
|
||||
{
|
||||
case GAMEMODE_NORMAL:
|
||||
case GAMEMODE_QUIT:
|
||||
case GAMEMODE_DEMO:
|
||||
{
|
||||
FadeScreen(255);
|
||||
quit = 1;
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_RESTART:
|
||||
{
|
||||
FadeScreen(255);
|
||||
|
||||
NoPlayerControl = 0;
|
||||
quick_replay = 0;
|
||||
AutoDirect = 0;
|
||||
WantedGameMode = GAMEMODE_NORMAL;
|
||||
NewLevel = 0;
|
||||
|
||||
GetRandomChase();
|
||||
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_REPLAY:
|
||||
case GAMEMODE_DIRECTOR:
|
||||
{
|
||||
if (CurrentGameMode < GAMEMODE_NEXTMISSION)
|
||||
FadeScreen(255);
|
||||
|
||||
NoPlayerControl = 1;
|
||||
AutoDirect = (WantedGameMode == GAMEMODE_REPLAY);
|
||||
quick_replay = (WantedGameMode == GAMEMODE_REPLAY);
|
||||
NewLevel = 0;
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_NEXTMISSION:
|
||||
{
|
||||
MissionStartData = MissionEndData;
|
||||
gHaveStoredData = 1;
|
||||
|
||||
FadeScreen(255);
|
||||
quit = 1;
|
||||
|
||||
NoPlayerControl = 0;
|
||||
quick_replay = 0;
|
||||
AutoDirect = 0;
|
||||
}
|
||||
FadeScreen(255);
|
||||
nextState = STATE_INITFRONTEND;
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_RESTART:
|
||||
{
|
||||
FadeScreen(255);
|
||||
|
||||
CurrentGameMode = WantedGameMode;
|
||||
} while (!quit);
|
||||
NoPlayerControl = 0;
|
||||
quick_replay = 0;
|
||||
AutoDirect = 0;
|
||||
WantedGameMode = GAMEMODE_NORMAL;
|
||||
NewLevel = 0;
|
||||
|
||||
lead_car = 0;
|
||||
NoPlayerControl = 0;
|
||||
SetDispMask(0);
|
||||
EnableDisplay();
|
||||
GetRandomChase();
|
||||
|
||||
ClearImage(&rect, 0, 0, 0);
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_REPLAY:
|
||||
case GAMEMODE_DIRECTOR:
|
||||
{
|
||||
if (CurrentGameMode < GAMEMODE_NEXTMISSION)
|
||||
FadeScreen(255);
|
||||
|
||||
DrawSync(0);
|
||||
SetDispMask(1);
|
||||
NoPlayerControl = 1;
|
||||
AutoDirect = (WantedGameMode == GAMEMODE_REPLAY);
|
||||
quick_replay = (WantedGameMode == GAMEMODE_REPLAY);
|
||||
NewLevel = 0;
|
||||
break;
|
||||
}
|
||||
case GAMEMODE_NEXTMISSION:
|
||||
{
|
||||
MissionStartData = MissionEndData;
|
||||
gHaveStoredData = 1;
|
||||
|
||||
FadeScreen(255);
|
||||
|
||||
if(GameType == GAME_MISSION)
|
||||
{
|
||||
nextState = STATE_LADDER;
|
||||
stateParam = 2; // don't do recap
|
||||
}
|
||||
else
|
||||
nextState = STATE_INITFRONTEND;
|
||||
|
||||
NoPlayerControl = 0;
|
||||
quick_replay = 0;
|
||||
AutoDirect = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CurrentGameMode = WantedGameMode;
|
||||
|
||||
SetState(nextState, (void*)stateParam);
|
||||
|
||||
if(nextState == STATE_INITFRONTEND)
|
||||
{
|
||||
RestoreGameVars();
|
||||
|
||||
lead_car = 0;
|
||||
NoPlayerControl = 0;
|
||||
|
||||
SetDispMask(0);
|
||||
EnableDisplay();
|
||||
|
||||
setRECT(&rect, 0, 0, 512, 512);
|
||||
|
||||
ClearImage(&rect, 0, 0, 0);
|
||||
|
||||
DrawSync(0);
|
||||
SetDispMask(1);
|
||||
}
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
|
@ -33,9 +33,13 @@ extern int quick_replay;
|
||||
extern MISSION_DATA MissionStartData;
|
||||
extern MISSION_DATA MissionEndData;
|
||||
|
||||
extern void GameStart(); // 0x00052A28
|
||||
extern void State_InitFrontEnd(void* param);
|
||||
extern void State_GameStart(void* param); // 0x00052A28
|
||||
extern void State_GameComplete(void* param);
|
||||
extern void State_MissionLadder(void* param);
|
||||
extern void State_LaunchGame(void* param); // 0x000532B8
|
||||
|
||||
extern void StartRender(int renderNum); // 0x000536B0
|
||||
extern void State_FMVPlay(void* param); // 0x000536B0
|
||||
|
||||
extern void ReInitFrontend(); // 0x00052E98
|
||||
|
||||
@ -45,8 +49,6 @@ extern void GetRandomChase(); // 0x000535D8
|
||||
|
||||
extern int FindPrevMissionFromLadderPos(int pos); // 0x000536D8
|
||||
|
||||
extern void LaunchGame(); // 0x000532B8
|
||||
|
||||
extern int FindMissionLadderPos(int mission); // 0x00053740
|
||||
|
||||
|
||||
|
@ -402,7 +402,8 @@ void GlobalTimeStep(void)
|
||||
{
|
||||
RKstep = 0;
|
||||
|
||||
for (RKstep = 0; RKstep < 2; RKstep++) {
|
||||
for (RKstep = 0; RKstep < 2; RKstep++)
|
||||
{
|
||||
for (i = 0; i < num_active_cars; i++)
|
||||
{
|
||||
cp = active_car_list[i];
|
||||
|
@ -429,13 +429,13 @@ void DrawFadePoly(void)
|
||||
// [D] [T]
|
||||
void DisplayMissionTitle(void)
|
||||
{
|
||||
if (bWantFade != 0 && CameraCnt == 1)
|
||||
if (bWantFade && CameraCnt == 1)
|
||||
{
|
||||
bWantFade = 0;
|
||||
bMissionTitleFade = CameraCnt;
|
||||
}
|
||||
|
||||
if (bMissionTitleFade != 0 && pauseflag == 0)
|
||||
if (bMissionTitleFade && !pauseflag)
|
||||
{
|
||||
fadeVal -= 6;
|
||||
|
||||
|
@ -68,6 +68,7 @@
|
||||
#include "STRINGS.H"
|
||||
|
||||
#include "INLINE_C.H"
|
||||
#include "state.h"
|
||||
|
||||
int levelstartpos[8][4] = {
|
||||
{ 4785, -1024, -223340, 0},
|
||||
@ -468,7 +469,7 @@ void LoadGameLevel(void)
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void GameInit(void)
|
||||
void State_GameInit(void* param)
|
||||
{
|
||||
STREAM_SOURCE* plStart;
|
||||
int i, musicType;
|
||||
@ -653,8 +654,7 @@ void GameInit(void)
|
||||
InitDrivingGames();
|
||||
InitThrownBombs();
|
||||
|
||||
i = 0;
|
||||
while (i < numPlayersToCreate)
|
||||
for (i = 0; i < numPlayersToCreate; i++)
|
||||
{
|
||||
plStart = PlayerStartInfo[i];
|
||||
padid = -i;
|
||||
@ -680,8 +680,6 @@ void GameInit(void)
|
||||
|
||||
car_data[i].ap.needsDenting = 1;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// FIXME: need to change streams properly
|
||||
@ -744,11 +742,8 @@ void GameInit(void)
|
||||
|
||||
if (gTimeOfDay == 2)
|
||||
{
|
||||
i = 0;
|
||||
do {
|
||||
for ( i = 0; i < MAX_CARS; i++)
|
||||
lightsOnDelay[i] = (i * 11);
|
||||
i++;
|
||||
} while (i < MAX_CARS);
|
||||
}
|
||||
|
||||
tracking_car = 1;
|
||||
@ -796,6 +791,9 @@ void GameInit(void)
|
||||
}
|
||||
|
||||
xa_timeout = 0;
|
||||
|
||||
// switch to STATE_GAMELOOP
|
||||
SetState(STATE_GAMELOOP);
|
||||
}
|
||||
|
||||
extern short paddp;
|
||||
@ -1291,7 +1289,7 @@ void StepSim(void)
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void GameLoop(void)
|
||||
void State_GameLoop(void* param)
|
||||
{
|
||||
int i;
|
||||
static POLY_FT3 buffer[2];
|
||||
@ -1362,6 +1360,7 @@ void GameLoop(void)
|
||||
DrawPrim(null);
|
||||
DrawSync(0);
|
||||
}
|
||||
|
||||
CheckForPause();
|
||||
}
|
||||
|
||||
@ -1375,11 +1374,14 @@ void GameLoop(void)
|
||||
StopAllChannels();
|
||||
FreeXM();
|
||||
|
||||
if (XAPrepared() != 0)
|
||||
if (XAPrepared())
|
||||
{
|
||||
StopXA();
|
||||
UnprepareXA();
|
||||
}
|
||||
|
||||
// switch to STATE_GAMECOMPLETE
|
||||
SetState(STATE_GAMECOMPLETE);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
@ -1772,6 +1774,8 @@ void SsSetSerialVol(short s_num, short voll, short volr)
|
||||
SpuSetCommonAttr(&attr);
|
||||
}
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
#ifndef PSX
|
||||
#include <SDL_messagebox.h>
|
||||
void PrintCommandLineArguments()
|
||||
@ -1909,11 +1913,11 @@ int redriver2_main(int argc, char** argv)
|
||||
// initializes sound system
|
||||
LoadSoundBankDynamic(NULL, 0, 0);
|
||||
|
||||
// load frontend bank
|
||||
LoadBankFromLump(1, 0);
|
||||
|
||||
InitialiseScoreTables();
|
||||
|
||||
// by default go to frontend
|
||||
SetState(STATE_INITFRONTEND, (void*)1);
|
||||
|
||||
#ifndef PSX
|
||||
LoadCurrentProfile();
|
||||
|
||||
@ -2007,7 +2011,7 @@ int redriver2_main(int argc, char** argv)
|
||||
i++;
|
||||
|
||||
GameType = GAME_TAKEADRIVE;
|
||||
LaunchGame();
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
}
|
||||
#endif // _DEBUG_OPTIONS
|
||||
else if (!strcmp(argv[i], "-replay"))
|
||||
@ -2041,10 +2045,8 @@ int redriver2_main(int argc, char** argv)
|
||||
{
|
||||
CurrentGameMode = GAMEMODE_REPLAY;
|
||||
gLoadedReplay = 1;
|
||||
|
||||
LaunchGame();
|
||||
|
||||
gLoadedReplay = 0;
|
||||
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2081,8 +2083,7 @@ int redriver2_main(int argc, char** argv)
|
||||
}
|
||||
#endif // PSX
|
||||
|
||||
// now run the frontend
|
||||
DoFrontEnd();
|
||||
DoStateLoop();
|
||||
|
||||
#ifndef PSX
|
||||
SaveCurrentProfile();
|
||||
@ -2104,7 +2105,7 @@ void FadeScreen(int end_value)
|
||||
|
||||
do {
|
||||
RenderGame();
|
||||
} while (FadingScreen != 0);
|
||||
} while (FadingScreen);
|
||||
|
||||
DrawSync(0);
|
||||
SetDispMask(0);
|
||||
|
@ -30,10 +30,12 @@ extern int ObjectDrawnCounter;
|
||||
extern int Havana3DLevelDraw;
|
||||
|
||||
extern void SsSetSerialVol(short s_num, short voll, short volr); // TEMPORARY
|
||||
extern void GameInit(); // 0x00059330
|
||||
|
||||
extern void State_GameInit(void* param); // 0x00059330
|
||||
extern void State_GameLoop(void* param); // 0x0005A8DC
|
||||
|
||||
extern void StepSim(); // 0x00059A44
|
||||
extern void GameLoop(); // 0x0005A8DC
|
||||
|
||||
extern void StepGame(); // 0x0005AB28
|
||||
extern void DrawGame(); // 0x0005C458
|
||||
|
||||
|
@ -10,10 +10,12 @@
|
||||
#include "director.h"
|
||||
#include "camera.h"
|
||||
#include "civ_ai.h"
|
||||
#include "state.h"
|
||||
|
||||
#include "STRINGS.H"
|
||||
#include "RAND.H"
|
||||
|
||||
|
||||
char AnalogueUnpack[16] = {
|
||||
0, -51, -63, -75, -87, -99, -111, -123,
|
||||
0, 51, 63, 75, 87, 99, 111, 123
|
||||
@ -363,10 +365,7 @@ void LoadCutsceneRecorder(char* configFilename)
|
||||
CameraCnt = 0;
|
||||
ini_free(config);
|
||||
|
||||
LaunchGame();
|
||||
|
||||
gLoadedReplay = 0;
|
||||
gCutsceneAsReplay = 0;
|
||||
SetState(STATE_GAMELAUNCH);
|
||||
}
|
||||
|
||||
#endif // CUTSCENE_RECORDER
|
||||
|
45
src_rebuild/Game/C/state.c
Normal file
45
src_rebuild/Game/C/state.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include "driver2.h"
|
||||
#include "state.h"
|
||||
#include "main.h"
|
||||
#include "glaunch.h"
|
||||
#include "Frontend/FEmain.h"
|
||||
|
||||
//-------------------------------------------
|
||||
|
||||
typedef void (*StateFn)(void*);
|
||||
|
||||
StateFn gStates[] = {
|
||||
NULL,
|
||||
State_InitFrontEnd,
|
||||
State_FrontEnd,
|
||||
State_GameStart,
|
||||
State_LaunchGame,
|
||||
State_MissionLadder,
|
||||
State_GameInit,
|
||||
State_GameLoop,
|
||||
State_GameComplete,
|
||||
State_FMVPlay,
|
||||
};
|
||||
|
||||
GameStates gCurrentState = STATE_NONE;
|
||||
void* gCurrentStateParam = NULL;
|
||||
|
||||
// the main loop of the game
|
||||
void DoStateLoop()
|
||||
{
|
||||
do
|
||||
{
|
||||
StateFn stateFn = gStates[gCurrentState];
|
||||
|
||||
if (!stateFn)
|
||||
break;
|
||||
|
||||
stateFn(gCurrentStateParam);
|
||||
} while (true);
|
||||
}
|
||||
|
||||
void SetState(GameStates newState, void* param)
|
||||
{
|
||||
gCurrentState = newState;
|
||||
gCurrentStateParam = param;
|
||||
}
|
19
src_rebuild/Game/C/state.h
Normal file
19
src_rebuild/Game/C/state.h
Normal file
@ -0,0 +1,19 @@
|
||||
enum GameStates
|
||||
{
|
||||
STATE_NONE = 0,
|
||||
STATE_INITFRONTEND,
|
||||
STATE_FRONTEND,
|
||||
STATE_GAMESTART,
|
||||
STATE_GAMELAUNCH, // launch single game
|
||||
STATE_LADDER, // launch a mission ladder
|
||||
STATE_GAMEINIT,
|
||||
STATE_GAMELOOP,
|
||||
STATE_GAMECOMPLETE,
|
||||
STATE_FMVPLAY,
|
||||
};
|
||||
|
||||
// changes the state
|
||||
extern void SetState(GameStates newState, void* param = NULL);
|
||||
|
||||
// does the state loop
|
||||
extern void DoStateLoop();
|
@ -20,9 +20,10 @@
|
||||
#include "C/debris.h"
|
||||
#include "C/E3stuff.h"
|
||||
#include "C/fmvplay.h"
|
||||
#include "C/gamesnd.h"
|
||||
#include "C/scores.h"
|
||||
#include "C/loadsave.h"
|
||||
|
||||
#include "C/state.h"
|
||||
|
||||
|
||||
struct PSXBUTTON
|
||||
@ -499,11 +500,11 @@ void SetVariable(int var)
|
||||
{
|
||||
StoredGameType = GameType;
|
||||
GameType = GAME_LOADEDREPLAY;
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReInitFrontend();
|
||||
SetState(STATE_INITFRONTEND);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -511,7 +512,7 @@ void SetVariable(int var)
|
||||
// [A] load configuration
|
||||
LoadCurrentProfile();
|
||||
|
||||
ReInitFrontend();
|
||||
SetState(STATE_INITFRONTEND);
|
||||
SetMasterVolume(gMasterVolume);
|
||||
SetXMVolume(gMusicVolume);
|
||||
}
|
||||
@ -532,7 +533,7 @@ void SetVariable(int var)
|
||||
if(LoadCurrentGame())
|
||||
{
|
||||
GameType = GAME_CONTINUEMISSION;
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1388,7 +1389,7 @@ int HandleKeyPress(void)
|
||||
|
||||
ScreenNames[ScreenDepth] = pCurrButton->Name;
|
||||
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
@ -1605,7 +1606,7 @@ void SetFEDrawMode(void)
|
||||
PutDrawEnv(¤t->draw);
|
||||
}
|
||||
|
||||
// [A] - was inlined in DoFrontEnd
|
||||
// [A] - was inlined in State_FrontEnd
|
||||
void InitFrontend(void)
|
||||
{
|
||||
FEInitCdIcon();
|
||||
@ -1622,10 +1623,13 @@ void InitFrontend(void)
|
||||
|
||||
SetupBackgroundPolys();
|
||||
SetupScreenSprts(&PsxScreens[0]);
|
||||
|
||||
// load frontend bank
|
||||
LoadBankFromLump(SOUND_BANK_SFX, 0);
|
||||
}
|
||||
|
||||
// [A] - was inlined in DoFrontEnd
|
||||
void InitDisplay(void)
|
||||
// [A] - was inlined in State_FrontEnd
|
||||
void InitFrontendDisplay(void)
|
||||
{
|
||||
SetDispMask(0);
|
||||
ResetGraph(0);
|
||||
@ -1653,73 +1657,73 @@ void InitDisplay(void)
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
void DoFrontEnd(void)
|
||||
void State_FrontEnd(void* param)
|
||||
{
|
||||
InitFrontend();
|
||||
InitDisplay();
|
||||
PadChecks();
|
||||
|
||||
do
|
||||
if (currPlayer == 2)
|
||||
{
|
||||
PadChecks();
|
||||
|
||||
if (currPlayer == 2) {
|
||||
if (Pads[1].type < 2) {
|
||||
feNewPad = ((feNewPad & 0x10) != 0) ? 0x10 : 0;
|
||||
}
|
||||
else {
|
||||
feNewPad = Pads[1].mapnew;
|
||||
}
|
||||
}
|
||||
|
||||
if (HandleKeyPress())
|
||||
if (Pads[1].type < 2)
|
||||
{
|
||||
if (pNewScreen != NULL)
|
||||
{
|
||||
SetupScreenSprts(pNewScreen);
|
||||
bRedrawFrontend = 1;
|
||||
}
|
||||
feNewPad = ((feNewPad & 0x10) != 0) ? 0x10 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
feNewPad = Pads[1].mapnew;
|
||||
}
|
||||
}
|
||||
|
||||
if (HandleKeyPress())
|
||||
{
|
||||
if (pNewScreen != NULL)
|
||||
{
|
||||
SetupScreenSprts(pNewScreen);
|
||||
bRedrawFrontend = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef PSX
|
||||
DrawScreen(pCurrScreen);
|
||||
DrawScreen(pCurrScreen);
|
||||
#else
|
||||
if (bRedrawFrontend)
|
||||
{
|
||||
DrawScreen(pCurrScreen);
|
||||
EndFrame();
|
||||
if (bRedrawFrontend)
|
||||
{
|
||||
DrawScreen(pCurrScreen);
|
||||
EndFrame();
|
||||
|
||||
NewSelection(0);
|
||||
NewSelection(0);
|
||||
|
||||
bRedrawFrontend = 0;
|
||||
}
|
||||
bRedrawFrontend = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((VSync(-1) - idle_timer) > 1800)
|
||||
if ((VSync(-1) - idle_timer) > 1800)
|
||||
{
|
||||
if (ScreenDepth == 0)
|
||||
{
|
||||
if (ScreenDepth == 0)
|
||||
{
|
||||
GameType = GAME_IDLEDEMO;
|
||||
GameType = GAME_IDLEDEMO;
|
||||
|
||||
gCurrentMissionNumber = gIdleReplay + 400;
|
||||
|
||||
if (++gIdleReplay == 4)
|
||||
gIdleReplay = 0;
|
||||
gCurrentMissionNumber = gIdleReplay + 400;
|
||||
|
||||
if (++gIdleReplay == 4)
|
||||
gIdleReplay = 0;
|
||||
|
||||
pScreenStack[0] = pCurrScreen;
|
||||
pButtonStack[0] = pCurrButton;
|
||||
ScreenNames[0] = pCurrButton->Name;
|
||||
pScreenStack[0] = pCurrScreen;
|
||||
pButtonStack[0] = pCurrButton;
|
||||
ScreenNames[0] = pCurrButton->Name;
|
||||
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
|
||||
pCurrScreen = pScreenStack[0];
|
||||
pCurrScreen = pScreenStack[0];
|
||||
|
||||
bRedrawFrontend = 1;
|
||||
ScreenDepth = 0; // fail-safe?
|
||||
}
|
||||
|
||||
idle_timer = VSync(-1);
|
||||
bRedrawFrontend = 1;
|
||||
ScreenDepth = 0; // fail-safe?
|
||||
}
|
||||
} while (bQuitToSystem != 2);
|
||||
|
||||
idle_timer = VSync(-1);
|
||||
}
|
||||
|
||||
if(bQuitToSystem == 2)
|
||||
SetState(STATE_NONE);
|
||||
}
|
||||
|
||||
// [D] [T]
|
||||
@ -2281,7 +2285,8 @@ int MissionSelectScreen(int bSetup)
|
||||
LoadBackgroundFile("DATA\\CITYBACK.RAW");
|
||||
}
|
||||
|
||||
if (feVariableSave[0] != -1) {
|
||||
if (feVariableSave[0] != -1)
|
||||
{
|
||||
currMission = feVariableSave[0];
|
||||
currSelIndex = feVariableSave[1];
|
||||
currCity = feVariableSave[2];
|
||||
@ -2675,9 +2680,9 @@ int CutSceneSelectScreen(int bSetup)
|
||||
feVariableSave[0] = cutSelection;
|
||||
|
||||
ScreenNames[ScreenDepth] = pCurrButton->Name;
|
||||
StartRender(feVariableSave[0] + CutAmountsTotal[feVariableSave[1]] + 1);
|
||||
SetState(STATE_FMVPLAY, (void*)(feVariableSave[0] + CutAmountsTotal[feVariableSave[1]] + 1));
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (cutSelection == CutAmounts[currCity + 1] - 1 || cutUnlock[gFurthestMission] <= cutSelection + CutAmountsTotal[currCity] + 1)
|
||||
@ -2818,11 +2823,7 @@ int CutSceneCitySelectScreen(int bSetup)
|
||||
lastCity = -1;
|
||||
lastCutCity = GameLevel;
|
||||
|
||||
if (GameLevel != 4)
|
||||
{
|
||||
lastCity = -1;
|
||||
}
|
||||
else
|
||||
if (GameLevel == 4)
|
||||
{
|
||||
bReturnToMain = 0;
|
||||
|
||||
@ -2833,7 +2834,12 @@ int CutSceneCitySelectScreen(int bSetup)
|
||||
|
||||
feVariableSave[0] = currCity;
|
||||
|
||||
StartRender(0x60);
|
||||
SetState(STATE_FMVPLAY, (void*)96);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastCity = -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -3764,11 +3770,11 @@ int UserReplaySelectScreen(int bSetup)
|
||||
{
|
||||
StoredGameType = GameType;
|
||||
GameType = GAME_LOADEDREPLAY;
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReInitFrontend();
|
||||
SetState(STATE_INITFRONTEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3900,7 +3906,8 @@ int DemoScreen(int bSetup)
|
||||
gWantNight = 0;
|
||||
gSubGameNumber = 0;
|
||||
|
||||
GameStart();
|
||||
SetState(STATE_GAMESTART);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,11 @@
|
||||
extern int gInFrontend;
|
||||
extern int bRedrawFrontend;
|
||||
|
||||
extern void DoFrontEnd(); // 0x001C296C
|
||||
extern void InitFrontendDisplay();
|
||||
extern void InitFrontend();
|
||||
|
||||
extern void State_FrontEnd(void* param); // 0x001C296C
|
||||
|
||||
extern void SetFEDrawMode();
|
||||
extern void LoadFrontendScreens(int full);
|
||||
extern void ReInitScreens();
|
||||
|
Loading…
Reference in New Issue
Block a user