coastline 0.0.4
Loading...
Searching...
No Matches
ghost.h File Reference

The ghost cars of the PC port: the frames of their recordings. More...

#include <cstddef>
#include <cstdio>
#include "common/rigidbody.h"
#include "common/vecmath.h"
#include "common/vehicle.h"
Include dependency graph for ghost.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  KeyframeState
 Vehicle pose and interpolated controls before compact frame encoding. More...
struct  GhostRecordingInfo
 The metadata stored before the frames of a recording. More...
struct  QuaternionPose
 The orientation and the position of a vehicle at the start of a key frame. More...

Macros

#define GHOST_FRAME_SIZE   24
 The size of a frame of the recording of a ghost car.
#define GHOST_RECORDING_COUNT   8
 The number of entries of g_adwGhostFrameCount.
#define GHOST_MAX_FRAMES   65536
 The maximum number of frames in each recording.

Functions

void PackKeyframeToCompactBuffer (u8 *pBuffer, const KeyframeState *pState)
 Encode a pose and controls into a compact ghost frame, preserving its final two bytes.
void DeserializeKeyframeState (KeyframeState *pState, const u8 *pBuffer)
 Decode a compact ghost frame into pose and controls.
void InterpolateKeyframeState (KeyframeState *pOut, float fShare, KeyframeState *pFrom, KeyframeState *pTo)
 Interpolate poses and controls, reversing the target quaternion for distant scalar signs.
u8 * GetGhostKeyframeBuffer (void)
 Get the encoded frames of the first recording.
u8 * GetGhostPlaybackKeyframeBuffer (void)
 Get the encoded frames used for ghost playback.
unsigned GetGhostKeyframeDataSize (void)
 Get the size of the encoded frames of the first recording.
bool ReadGhostFileData (const char *pszPath, bool bAllowFailure)
 Read a current or legacy ghost file and validate its Adler checksum.
FILE * OpenGhostRecording (const char *pszPath)
 Open a ghost recording: the file itself, such as a saved recording, or the file built from the JSON the import converted it to.
const char * NextAttractDemoRecording (void)
 Choose the recording of the next attract demo: the two of the PC release in turn, and then the demo of each imported cartridge.
bool LoadGhostFile (bool bAllowFailure)
 Read the ghost file selected in the front end.
bool SaveGhostFile (void)
 Write the ghost recording, times, checksum, menu settings, and slot label to the selected file.
unsigned SetGhostFrameCountFromSize (unsigned dwSize)
 Set the number of frames of the second recording from its size.
void ResetGhostRecording (void)
 Clear the number of frames of the recordings, only the first in time attack and the demonstration and all of them otherwise, and stop recording.
void StartGhostRecording (void)
 Start ghost recording.
int IsGhostRecordingActive (void)
 Read the ghost recording flag.
void AdvanceGhostRecordFrame (void)
 Advance active recordings and the time attack or demonstration ghost playback.
void ClearGhostPlaybackState (void)
 Reset every ghost playback frame to zero.
void UpdateReplayScrubControls (void)
 Translate replay controls into playback mode and bounded frame changes.
void FillMemoryPatternBytes (void *pDest, size_t nCount, int nByte)
 Fill memory with a byte.
void MatrixToPositionQuaternion (QuaternionPose *pPose, f32 m[4][4])
 Get the orientation of a matrix as a quaternion and its translation as a position.
void PositionQuaternionToMatrix4x4 (f32 matrix[4][4], const QuaternionPose *pPose)
 Convert a quaternion and position into a matrix, compensating for quaternion magnitude.
void BuildVehicleKeyframe (KeyframeState *pState, Vehicle *pVehicle)
 Sample a vehicle pose, wheel motion, and replay effects.
void RecordVehicleKeyframe (Vehicle *vehicle)
 Sample vehicle and send its keyframe as a local network state update.
unsigned ApplyRemoteVehicleState (Vehicle *vehicle, int slotIndex)
 Apply an interpolated network keyframe to a remote vehicle unless the race is paused.
void ApplyVehicleKeyframe (Vehicle *pVehicle, const KeyframeState *pState)
 Restore sampled motion and effects, then synchronise integration states.
void RecordGhostKeyframe (Vehicle *pVehicle)
 Record one vehicle frame while recording is active and the race is not paused.
void ApplyGhostKeyframeToVehicle (Vehicle *pVehicle, int nRecording)
 Restore a ghost frame and estimate velocity from the following frame when available.
void ApplyGhostKeyframeForVehicle (Vehicle *pVehicle)
 Restore the ghost frame from the recording slot matching a vehicle index.

Variables

GhostRecordingInfo g_GhostRecordingInfo
 The metadata of the ghost recording.
unsigned g_dwGhostRecordingSize
 The number of metadata bytes written before the frames.
u8 g_aGhostKeyframes [GHOST_RECORDING_COUNT][GHOST_MAX_FRAMES *GHOST_FRAME_SIZE]
 The encoded frames of all ghost recordings.
float g_fGhostBestRaceTime
 The best race time of the ghost, in seconds.
float g_fGhostBestLapTime
 The best lap time of the ghost, in seconds.
int g_dwLoadedGhostLapCount
 The lap-count option read from a ghost file.
const char g_szGhostSaveMagic [4]
 The four-byte signature of a ghost file.
const unsigned g_dwGhostFileHeader
 The zero marker preceding the length in a current ghost file.
unsigned g_adwGhostFrameCount [GHOST_RECORDING_COUNT]
 The number of frames of the recordings of the ghost cars.
int g_bGhostRecordingActive
 Whether a recording of a ghost car is being made.
int g_adwGhostPlaybackFrame [GHOST_RECORDING_COUNT]
 Current playback frame of each recording.

Detailed Description

The ghost cars of the PC port: the frames of their recordings.

Macro Definition Documentation

◆ GHOST_FRAME_SIZE

#define GHOST_FRAME_SIZE   24

The size of a frame of the recording of a ghost car.

◆ GHOST_RECORDING_COUNT

#define GHOST_RECORDING_COUNT   8

The number of entries of g_adwGhostFrameCount.

◆ GHOST_MAX_FRAMES

#define GHOST_MAX_FRAMES   65536

The maximum number of frames in each recording.

Function Documentation

◆ PackKeyframeToCompactBuffer()

void PackKeyframeToCompactBuffer ( u8 * pBuffer,
const KeyframeState * pState )

Encode a pose and controls into a compact ghost frame, preserving its final two bytes.

Parameters
pBufferDestination frame.
pStatePose and controls.
Ghidra address:
BRD3D: 0x10006bd0
Ghidra address:
BRGlide: 0x10006f40

◆ DeserializeKeyframeState()

void DeserializeKeyframeState ( KeyframeState * pState,
const u8 * pBuffer )

Decode a compact ghost frame into pose and controls.

Velocities and progress are not written.

Parameters
pStateDestination pose and controls.
pBufferEncoded frame.
Ghidra address:
BRD3D: 0x10007730
Ghidra address:
BRGlide: 0x10007aa0

◆ InterpolateKeyframeState()

void InterpolateKeyframeState ( KeyframeState * pOut,
float fShare,
KeyframeState * pFrom,
KeyframeState * pTo )

Interpolate poses and controls, reversing the target quaternion for distant scalar signs.

Parameters
pOutDestination frame.
fShareInterpolation share, clamped from zero to ten.
pFromInitial frame.
pToTarget frame.
Ghidra address:
BRD3D: 0x100079e0
Ghidra address:
BRGlide: 0x10007d50

◆ GetGhostKeyframeBuffer()

u8 * GetGhostKeyframeBuffer ( void )

Get the encoded frames of the first recording.

Returns
The recording buffer.
Ghidra address:
BRD3D: 0x1006ab90
Ghidra address:
BRGlide: 0x10063b40

◆ GetGhostPlaybackKeyframeBuffer()

u8 * GetGhostPlaybackKeyframeBuffer ( void )

Get the encoded frames used for ghost playback.

Returns
The second recording buffer.
Ghidra address:
BRD3D: 0x1006adf0
Ghidra address:
BRGlide: 0x10063da0

◆ GetGhostKeyframeDataSize()

unsigned GetGhostKeyframeDataSize ( void )

Get the size of the encoded frames of the first recording.

Returns
The size in bytes.
Ghidra address:
BRD3D: 0x1006aba0
Ghidra address:
BRGlide: 0x10063b50

◆ ReadGhostFileData()

bool ReadGhostFileData ( const char * pszPath,
bool bAllowFailure )

Read a current or legacy ghost file and validate its Adler checksum.

Parameters
pszPathThe ghost file path.
bAllowFailureWhether a failed load returns success after clearing the metadata and times.
Returns
Whether loading succeeded or a permitted failure occurred.
Ghidra address:
BRD3D: 0x10070af0
Ghidra address:
BRGlide: 0x10069a80

◆ OpenGhostRecording()

FILE * OpenGhostRecording ( const char * pszPath)

Open a ghost recording: the file itself, such as a saved recording, or the file built from the JSON the import converted it to.

Parameters
pszPathThe path of the recording.
Returns
The file, open for reading, or null.

◆ NextAttractDemoRecording()

const char * NextAttractDemoRecording ( void )

Choose the recording of the next attract demo: the two of the PC release in turn, and then the demo of each imported cartridge.

Returns
The path of the recording, relative to the default assets.

◆ LoadGhostFile()

bool LoadGhostFile ( bool bAllowFailure)

Read the ghost file selected in the front end.

Parameters
bAllowFailureWhether a failed load returns success.
Returns
The result of ReadGhostFileData().
Ghidra address:
BRD3D: 0x10070e60
Ghidra address:
BRGlide: 0x10069dc0

◆ SaveGhostFile()

bool SaveGhostFile ( void )

Write the ghost recording, times, checksum, menu settings, and slot label to the selected file.

Returns
Whether the file opened and all checked writes completed.
Ghidra address:
BRD3D: 0x10070e80
Ghidra address:
BRGlide: 0x10069de0

◆ SetGhostFrameCountFromSize()

unsigned SetGhostFrameCountFromSize ( unsigned dwSize)

Set the number of frames of the second recording from its size.

Parameters
dwSizeThe size of the recording in bytes.
Returns
The number of complete frames.
Ghidra address:
BRD3D: 0x1006ae00
Ghidra address:
BRGlide: 0x10063db0

◆ ResetGhostRecording()

void ResetGhostRecording ( void )

Clear the number of frames of the recordings, only the first in time attack and the demonstration and all of them otherwise, and stop recording.

Ghidra address:
BRD3D: 0x1006aa50
Ghidra address:
BRGlide: 0x10063a00

◆ StartGhostRecording()

void StartGhostRecording ( void )

Start ghost recording.

Ghidra address:
BRD3D: 0x1006aa90
Ghidra address:
BRGlide: 0x10063a40

◆ IsGhostRecordingActive()

int IsGhostRecordingActive ( void )

Read the ghost recording flag.

Returns
Recording flag without boolean conversion.
Ghidra address:
BRD3D: 0x1006aaa0
Ghidra address:
BRGlide: 0x10063a50

◆ AdvanceGhostRecordFrame()

void AdvanceGhostRecordFrame ( void )

Advance active recordings and the time attack or demonstration ghost playback.

Ghidra address:
BRD3D: 0x1006ab20
Ghidra address:
BRGlide: 0x10063ad0

◆ ClearGhostPlaybackState()

void ClearGhostPlaybackState ( void )

Reset every ghost playback frame to zero.

Ghidra address:
BRD3D: 0x1006abb0
Ghidra address:
BRGlide: 0x10063b60

◆ UpdateReplayScrubControls()

void UpdateReplayScrubControls ( void )

Translate replay controls into playback mode and bounded frame changes.

Ghidra address:
BRD3D: 0x1006ad10
Ghidra address:
BRGlide: 0x10063cc0

◆ FillMemoryPatternBytes()

void FillMemoryPatternBytes ( void * pDest,
size_t nCount,
int nByte )

Fill memory with a byte.

Parameters
pDestThe memory.
nCountThe bytes to fill.
nByteThe byte, in the low 8 bits.
Ghidra address:
BRD3D: 0x10060780
Ghidra address:
BRGlide: 0x100597f0

◆ MatrixToPositionQuaternion()

void MatrixToPositionQuaternion ( QuaternionPose * pPose,
f32 m[4][4] )

Get the orientation of a matrix as a quaternion and its translation as a position.

Parameters
pPoseReceives the orientation and the position.
mThe matrix.
Ghidra address:
BRD3D: 0x100695a0
Ghidra address:
BRGlide: 0x10062610

◆ PositionQuaternionToMatrix4x4()

void PositionQuaternionToMatrix4x4 ( f32 matrix[4][4],
const QuaternionPose * pPose )

Convert a quaternion and position into a matrix, compensating for quaternion magnitude.

Parameters
matrixDestination matrix.
pPoseQuaternion and position.
Ghidra address:
BRD3D: 0x100695d0
Ghidra address:
BRGlide: 0x10062640

◆ BuildVehicleKeyframe()

void BuildVehicleKeyframe ( KeyframeState * pState,
Vehicle * pVehicle )

Sample a vehicle pose, wheel motion, and replay effects.

Parameters
pStateDestination frame.
pVehicleVehicle to sample.
Ghidra address:
BRD3D: 0x100607b0
Ghidra address:
BRGlide: 0x10059820

◆ RecordVehicleKeyframe()

void RecordVehicleKeyframe ( Vehicle * vehicle)

Sample vehicle and send its keyframe as a local network state update.

Ghidra address:
BRD3D: 0x100609e0
Ghidra address:
BRGlide: 0x10059a50

◆ ApplyRemoteVehicleState()

unsigned ApplyRemoteVehicleState ( Vehicle * vehicle,
int slotIndex )

Apply an interpolated network keyframe to a remote vehicle unless the race is paused.

Returns
Zero if interpolation has no frame, or one when applied or skipped.
Ghidra address:
BRD3D: 0x10060cc0
Ghidra address:
BRGlide: 0x10059d30

◆ ApplyVehicleKeyframe()

void ApplyVehicleKeyframe ( Vehicle * pVehicle,
const KeyframeState * pState )

Restore sampled motion and effects, then synchronise integration states.

Parameters
pVehicleDestination vehicle.
pStateFrame to restore.
Ghidra address:
BRD3D: 0x10060a10
Ghidra address:
BRGlide: 0x10059a80

◆ RecordGhostKeyframe()

void RecordGhostKeyframe ( Vehicle * pVehicle)

Record one vehicle frame while recording is active and the race is not paused.

Parameters
pVehicleVehicle to record.
Ghidra address:
BRD3D: 0x1006aab0
Ghidra address:
BRGlide: 0x10063a60

◆ ApplyGhostKeyframeToVehicle()

void ApplyGhostKeyframeToVehicle ( Vehicle * pVehicle,
int nRecording )

Restore a ghost frame and estimate velocity from the following frame when available.

Parameters
pVehicleDestination vehicle.
nRecordingRecording slot.
Ghidra address:
BRD3D: 0x1006abd0
Ghidra address:
BRGlide: 0x10063b80

◆ ApplyGhostKeyframeForVehicle()

void ApplyGhostKeyframeForVehicle ( Vehicle * pVehicle)

Restore the ghost frame from the recording slot matching a vehicle index.

Parameters
pVehicleDestination vehicle.
Ghidra address:
BRD3D: 0x1006acf0
Ghidra address:
BRGlide: 0x10063ca0

Variable Documentation

◆ g_GhostRecordingInfo

GhostRecordingInfo g_GhostRecordingInfo
extern

The metadata of the ghost recording.

Ghidra address:
BRD3D: 0x10680738
Ghidra address:
BRGlide: 0x105bc8e0

◆ g_dwGhostRecordingSize

unsigned g_dwGhostRecordingSize
extern

The number of metadata bytes written before the frames.

Ghidra address:
BRD3D: 0x10680730
Ghidra address:
BRGlide: 0x105bc8d8

◆ g_aGhostKeyframes

The encoded frames of all ghost recordings.

Ghidra address:
BRD3D: 0x10b50308
Ghidra address:
BRGlide: 0x10b73668

◆ g_fGhostBestRaceTime

float g_fGhostBestRaceTime
extern

The best race time of the ghost, in seconds.

Ghidra address:
BRD3D: 0x10aa28c8
Ghidra address:
BRGlide: 0x10ac5c20

◆ g_fGhostBestLapTime

float g_fGhostBestLapTime
extern

The best lap time of the ghost, in seconds.

Ghidra address:
BRD3D: 0x10aa28cc
Ghidra address:
BRGlide: 0x10ac5c24

◆ g_dwLoadedGhostLapCount

int g_dwLoadedGhostLapCount
extern

The lap-count option read from a ghost file.

Ghidra address:
BRD3D: 0x10ad098c
Ghidra address:
BRGlide: 0x10af3cec

◆ g_szGhostSaveMagic

const char g_szGhostSaveMagic[4]
extern

The four-byte signature of a ghost file.

Ghidra address:
BRD3D: 0x100b5d9c
Ghidra address:
BRGlide: 0x100b55a4

◆ g_dwGhostFileHeader

const unsigned g_dwGhostFileHeader
extern

The zero marker preceding the length in a current ghost file.

Ghidra address:
BRD3D: 0x1008fc1c

◆ g_adwGhostFrameCount

unsigned g_adwGhostFrameCount[GHOST_RECORDING_COUNT]
extern

The number of frames of the recordings of the ghost cars.

Ghidra address:
BRD3D: 0x10b502e8
Ghidra address:
BRGlide: 0x10b73648

◆ g_bGhostRecordingActive

int g_bGhostRecordingActive
extern

Whether a recording of a ghost car is being made.

Ghidra address:
BRD3D: 0x11750308
Ghidra address:
BRGlide: 0x11773668

◆ g_adwGhostPlaybackFrame

int g_adwGhostPlaybackFrame[GHOST_RECORDING_COUNT]
extern

Current playback frame of each recording.

Ghidra address:
BRD3D: 0x11750310
Ghidra address:
BRGlide: 0x11773670