Skip to content

Commit

Permalink
Merge pull request #101 from OpenDriver2/develop-SoapyMan
Browse files Browse the repository at this point in the history
Beta finalize
  • Loading branch information
SoapyMan authored May 18, 2021
2 parents 0dcc54c + aad351f commit e19f22b
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 21 deletions.
Binary file modified data/DRIVER2/REPLAYS/ReChases/CUT11_N.R
Binary file not shown.
Binary file modified data/DRIVER2/REPLAYS/ReChases/CUT19_N.R
Binary file not shown.
3 changes: 1 addition & 2 deletions src_rebuild/Game/C/civ_ai.c
Original file line number Diff line number Diff line change
Expand Up @@ -1927,7 +1927,6 @@ int dy = 0; // offset 0xAAB44
int dz = 0; // offset 0xAAB48

// [D] [T] [A] - some register is not properly decompiled
// TODO: store pings
int PingInCivCar(int minPingInDist)
{
int model;
Expand Down Expand Up @@ -1990,7 +1989,7 @@ int PingInCivCar(int minPingInDist)
return 0;
}

if (maxCivCars - 1 <= numCivCars && gInGameChaseActive == 0)
if (numCivCars >= maxCivCars - 1 && gInGameChaseActive == 0)
{
PingOutCivsOnly = 1;
return 0;
Expand Down
142 changes: 134 additions & 8 deletions src_rebuild/Game/C/cutrecorder.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifdef PSX
#error This file is not applicable for PSX build
#endif

#ifdef CUTSCENE_RECORDER

#include "driver2.h"
Expand All @@ -18,21 +19,52 @@
#include "replays.h"
#include "state.h"
#include "system.h"
#include "pause.h"
#include "pres.h"
#include "players.h"

#include "../utils/ini.h"

typedef struct AutoTestStats
{
int numHitCars;
int numHitWalls;
int stuck;
};

AutoTestStats gAutoTestStats[15];

int gCutsceneChaseAutoTest = 0;
int gChaseStuckTimer = 0;

int gCutsceneAsReplay = 0;
int gCutsceneAsReplay_PlayerId = 0;
int gCutsceneAsReplay_PlayerChanged = 0;
int gCutsceneAsReplay_ReserveSlots = 2;
char gCutsceneRecorderPauseText[64] = { 0 };
char gCurrentChasePauseText[64] = { 0 };

extern int gDieWithFade;

int CutRec_LoadCutsceneAsReplayFromBuffer(char* buffer);
void InitCutsceneRecorder(char* configFilename);
int LoadCutsceneAsReplay(int subindex);

void CutRec_Reset()
{
if (gCutsceneChaseAutoTest != 0 && gCutsceneChaseAutoTest < 15)
{
gAutoTestStats[gCutsceneChaseAutoTest].numHitCars = 0;
gAutoTestStats[gCutsceneChaseAutoTest].numHitWalls = 0;
gAutoTestStats[gCutsceneChaseAutoTest].stuck = 0;
gChaseStuckTimer = 0;

return;
}

gCutsceneChaseAutoTest = 0;
gCutsceneAsReplay = 0;

gCutsceneAsReplay_PlayerId = 0;
gCutsceneAsReplay_PlayerChanged = 0;
gCutsceneAsReplay_ReserveSlots = 2;
Expand All @@ -54,9 +86,88 @@ void CutRec_NextChase(int dir)
sprintf(gCurrentChasePauseText, "Chase ID: %d", gChaseNumber);
}

void CutRec_Step()
{
if (!pauseflag)
{
if(gCutsceneChaseAutoTest != 0)
{
int carId = player[gCutsceneAsReplay_PlayerId].playerCarId;

if (car_data[carId].hd.speed < 5)
gChaseStuckTimer++;
else
gChaseStuckTimer = 0;

if(gChaseStuckTimer > 45)
{
gAutoTestStats[gCutsceneChaseAutoTest].stuck = 1;
gChaseStuckTimer = 0;
}
}

return;
}

if(gCutsceneChaseAutoTest != 0 && gCutsceneChaseAutoTest < 15 &&
NoPlayerControl && ReplayParameterPtr->RecordingEnd - 2 < CameraCnt || gDieWithFade)
{
gCutsceneChaseAutoTest++;

// load next replay and restart
if (gCutsceneChaseAutoTest < 15 &&
LoadCutsceneAsReplay(gCutsceneChaseAutoTest))
{
State_GameComplete(NULL);

gDrawPauseMenus = 0;
gLoadedReplay = 1;
CurrentGameMode = GAMEMODE_REPLAY;

SetState(STATE_GAMELAUNCH);
}
else
{
printInfo("------- AUTOTEST RESULTS -------\n");
for(int i = 0; i < 15; i++)
printInfo(" chase %d - hit cars: %d, stuck: %d\n", i, gAutoTestStats[i].numHitCars, gAutoTestStats[i].stuck);
printInfo("------- ---------------- -------\n");
}
}
}

void CutRec_Draw()
{
char text[64];

if (gCutsceneAsReplay == 0)
return;

SetTextColour(128, 128, 128);

if(gCutsceneChaseAutoTest)
{
sprintf(text, "Chase: %d - frame %d of %d", gCutsceneChaseAutoTest, CameraCnt, ReplayParameterPtr->RecordingEnd);
PrintString(text, 5, 120);
}

if (gAutoTestStats[gCutsceneChaseAutoTest].numHitCars > 0)
SetTextColour(128, 0, 0);

sprintf(text, "Hit cars: %d", gAutoTestStats[gCutsceneChaseAutoTest].numHitCars);
PrintString(text, 5, 140);

if(gAutoTestStats[gCutsceneChaseAutoTest].stuck)
{
SetTextColour(128, 0, 0);

sprintf(text, "Car is stuck!");
PrintString(text, 5, 60);
}
}

void CutRec_ReserveSlots()
{
// [A] reserve slots to avoid their use for chases
if (gCutsceneAsReplay == 0)
return;

Expand Down Expand Up @@ -104,10 +215,14 @@ int LoadCutsceneAsReplay(int subindex)
CUTSCENE_HEADER header;
char filename[64];

if (gCutsceneAsReplay < 21)
sprintf(filename, "REPLAYS\\CUT%d.R", gCutsceneAsReplay);
else
sprintf(filename, "REPLAYS\\A\\CUT%d.R", gCutsceneAsReplay);
//sprintf(filename, "REPLAYS\\ReChases\\CUT%d_N.R", gCutsceneAsReplay);
//if(!FileExists(filename))
{
if (gCutsceneAsReplay < 21)
sprintf(filename, "REPLAYS\\CUT%d.R", gCutsceneAsReplay);
else
sprintf(filename, "REPLAYS\\A\\CUT%d.R", gCutsceneAsReplay);
}

if (FileExists(filename))
{
Expand All @@ -118,8 +233,6 @@ int LoadCutsceneAsReplay(int subindex)
offset = header.data[subindex].offset * 4;
size = header.data[subindex].size;

printWarning("cutscene size: %d\n", size);

LoadfileSeg(filename, (char*)_other_buffer, offset, size);

int result = CutRec_LoadCutsceneAsReplayFromBuffer((char*)_other_buffer);
Expand All @@ -133,6 +246,12 @@ int LoadCutsceneAsReplay(int subindex)
return 0;
}

void InitChaseAutoTest(char* configFilename)
{
gCutsceneChaseAutoTest = 2;
InitCutsceneRecorder(configFilename);
}

void InitCutsceneRecorder(char* configFilename)
{
ini_t* config;
Expand Down Expand Up @@ -163,6 +282,11 @@ void InitCutsceneRecorder(char* configFilename)

if (loadExistingCutscene)
{
if(gCutsceneChaseAutoTest != 0)
{
subindex = gCutsceneChaseAutoTest;
}

if (!LoadCutsceneAsReplay(subindex))
{
ini_free(config);
Expand Down Expand Up @@ -255,6 +379,8 @@ void CutRec_CheckInvalidatePing(int carId, int howHard)
if (howHard < 60000)
return;

gAutoTestStats[gCutsceneChaseAutoTest].numHitCars++;

pos = PingBufferPos;

while (pos >= 0)
Expand All @@ -275,7 +401,7 @@ int CutRec_InitPlayers()
{
if (gCutsceneAsReplay == 0)
return 0;

for (int i = 0; i < NumReplayStreams; i++)
{
PlayerStartInfo[i] = &ReplayStreams[i].SourceType;
Expand Down
7 changes: 7 additions & 0 deletions src_rebuild/Game/C/cutrecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ extern int gCutsceneAsReplay_ReserveSlots;
extern char gCutsceneRecorderPauseText[64];
extern char gCurrentChasePauseText[64];

extern void InitChaseAutoTest(char* configFilename);
extern void InitCutsceneRecorder(char* configFilename);

extern void CutRec_Reset();
extern void CutRec_Step();
extern void CutRec_Draw();
extern int CutRec_StorePingInfo(int cookieCount, int carId);
extern void CutRec_CheckInvalidatePing(int carId, int howHard);
extern void CutRec_NextChase(int dir);
Expand All @@ -24,6 +27,8 @@ extern int CutRec_SaveReplayToFile(char* filename);
#ifdef CUTSCENE_RECORDER

#define _CutRec_IsOn() (gCutsceneAsReplay != 0)
#define _CutRec_Step() CutRec_Step()
#define _CutRec_Draw() CutRec_Draw()
#define _CutRec_Reset() CutRec_Reset()
#define _CutRec_StorePingInfo(a,b) CutRec_StorePingInfo(a,b)
#define _CutRec_CheckInvalidatePing(a,b) CutRec_CheckInvalidatePing(a, b)
Expand All @@ -37,6 +42,8 @@ extern int CutRec_SaveReplayToFile(char* filename);
#else

#define _CutRec_IsOn() (0)
#define _CutRec_Step() (0)
#define _CutRec_Draw() (0)
#define _CutRec_Reset() (0)
#define _CutRec_StorePingInfo(a,b) (0)
#define _CutRec_CheckInvalidatePing(a,b) (0)
Expand Down
15 changes: 10 additions & 5 deletions src_rebuild/Game/C/cutscene.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void TriggerInGameCutscene(int cutscene)
}

// [A] Function detects user chases and re-chases
void SelectCutsceneFile(char* filename, int init, int subindex)
int SelectCutsceneFile(char* filename, int init, int subindex)
{
filename[0] = '\0';

Expand Down Expand Up @@ -439,6 +439,8 @@ void SelectCutsceneFile(char* filename, int init, int subindex)
else
sprintf(filename, "REPLAYS\\A\\CUT%d.R", gCurrentMissionNumber);
}

return FileExists(filename);
}

// [D] [T]
Expand All @@ -449,13 +451,16 @@ int CalcInGameCutsceneSize(void)

if (NewLevel)
{
ClearMem((char*)&CutsceneHeader, sizeof(CUTSCENE_HEADER));
ClearMem((char*)&ChaseHeader, sizeof(CUTSCENE_HEADER));

// init user/re-chases and load cutscene file header
SelectCutsceneFile(filename, 1, 0);
LoadfileSeg(filename, (char*)&CutsceneHeader, 0, sizeof(CUTSCENE_HEADER));
if(SelectCutsceneFile(filename, 1, 0))
LoadfileSeg(filename, (char*)&CutsceneHeader, 0, sizeof(CUTSCENE_HEADER));

// load re-chase file header
SelectCutsceneFile(filename, 0, 2);
LoadfileSeg(filename, (char*)&ChaseHeader, 0, sizeof(CUTSCENE_HEADER));
if(SelectCutsceneFile(filename, 0, 2))
LoadfileSeg(filename, (char*)&ChaseHeader, 0, sizeof(CUTSCENE_HEADER));

maxSize = 0;
for (i = 2; i < 15; i++)
Expand Down
15 changes: 15 additions & 0 deletions src_rebuild/Game/C/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,14 @@ void State_GameLoop(void* param)
while (--cnt >= 0)
StepGame();

_CutRec_Draw();
DrawGame();
#endif

if (game_over)
SetState(STATE_GAMECOMPLETE);

_CutRec_Step();
}

// TODO: DRAW.C?
Expand Down Expand Up @@ -1776,6 +1780,7 @@ void PrintCommandLineArguments()
" -replay <filename.d2rp> : starts replay from file\n"
#ifdef CUTSCENE_RECORDER
" -recordcutscene <filename> : starts cutscene recording session. Specify INI filename with it\n"
" -chaseautotest <filename> : starts chase autotesting. Specify INI filename with it\n"
#endif
" -nointro : disable intro screens\n"
" -nofmv : disable all FMVs\n";
Expand Down Expand Up @@ -2107,6 +2112,16 @@ int redriver2_main(int argc, char** argv)
i++;
}
#ifdef CUTSCENE_RECORDER
else if (!strcmp(argv[i], "-chaseautotest"))
{
SetFEDrawMode();

gInFrontend = 0;
AttractMode = 0;

InitChaseAutoTest(argv[i+1]);
i++;
}
else if (!strcmp(argv[i], "-recordcutscene"))
{
SetFEDrawMode();
Expand Down
8 changes: 2 additions & 6 deletions src_rebuild/Game/C/replays.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,15 @@ char GetPingInfo(char *cookieCount)
}

PingBufferPos++;

return retCarId;
}

return -1;
return retCarId;
}

// [A] returns 1 if can use ping buffer
int IsPingInfoAvailable()
{
// [A] loaded replays pings temporarily disabled...

if (gUseStoredPings == 0 || gInGameChaseActive == 0)// && gLoadedReplay == 0)
if (!_CutRec_IsOn() && (gUseStoredPings == 0 || gInGameChaseActive == 0))// && gLoadedReplay == 0)
return 0;

return PingBuffer != NULL && PingBufferPos < MAX_REPLAY_PINGS;
Expand Down
21 changes: 21 additions & 0 deletions src_rebuild/PsyX/src/psx/LIBETC.C
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,24 @@ long GetVideoMode()
{
return g_vmode;
}

void PadInit(int mode)
{
PSYX_UNIMPLEMENTED();

// TODO: call PadInitDirect
}

u_long PadRead(int id)
{
PSYX_UNIMPLEMENTED();

// TODO: return pad data as u_long
}

void PadStop(void)
{
PSYX_UNIMPLEMENTED();

// TODO: stop pad reads
}

0 comments on commit e19f22b

Please sign in to comment.