coastline 0.0.4
Loading...
Searching...
No Matches
ghost.h
Go to the documentation of this file.
1#pragma once
2
7
8#include <cstddef>
9#include <cstdio>
10
11#include "common/rigidbody.h"
12#include "common/vecmath.h"
13#include "common/vehicle.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
20#define GHOST_FRAME_SIZE 24
21
23#define GHOST_RECORDING_COUNT 8
24
26#define GHOST_MAX_FRAMES 65536
27
47
56void PackKeyframeToCompactBuffer(u8 *pBuffer, const KeyframeState *pState);
57
66void DeserializeKeyframeState(KeyframeState *pState, const u8 *pBuffer);
67
79 float fShare,
80 KeyframeState *pFrom,
81 KeyframeState *pTo);
82
95
103
110extern unsigned g_dwGhostRecordingSize;
111
119
126extern float g_fGhostBestRaceTime;
127
134extern float g_fGhostBestLapTime;
135
142extern int g_dwLoadedGhostLapCount;
143
150extern const char g_szGhostSaveMagic[4];
151
157extern const unsigned g_dwGhostFileHeader;
158
167
176
185
195bool ReadGhostFileData(const char *pszPath, bool bAllowFailure);
196
197#if TGR_PLATFORM == TGR_PLATFORM_SDL
205FILE *OpenGhostRecording(const char *pszPath);
206
213const char *NextAttractDemoRecording(void);
214#endif /* TGR_PLATFORM == TGR_PLATFORM_SDL */
215
224bool LoadGhostFile(bool bAllowFailure);
225
233bool SaveGhostFile(void);
234
242
249extern int g_bGhostRecordingActive;
250
259unsigned SetGhostFrameCountFromSize(unsigned dwSize);
260
269
277
286
294
302
310
318
328void FillMemoryPatternBytes(void *pDest, size_t nCount, int nByte);
329
335
345
354void PositionQuaternionToMatrix4x4(f32 matrix[4][4], const QuaternionPose *pPose);
355
365
366#if TGR_PLATFORM == TGR_PLATFORM_WIN
374
382unsigned ApplyRemoteVehicleState(Vehicle *vehicle, int slotIndex);
383#endif /* TGR_PLATFORM == TGR_PLATFORM_WIN */
384
393void ApplyVehicleKeyframe(Vehicle *pVehicle, const KeyframeState *pState);
394
403
412void ApplyGhostKeyframeToVehicle(Vehicle *pVehicle, int nRecording);
413
422
423#ifdef __cplusplus
424}
425#endif
unsigned ApplyRemoteVehicleState(Vehicle *vehicle, int slotIndex)
Apply an interpolated network keyframe to a remote vehicle unless the race is paused.
void UpdateReplayScrubControls(void)
Translate replay controls into playback mode and bounded frame changes.
void MatrixToPositionQuaternion(QuaternionPose *pPose, f32 m[4][4])
Get the orientation of a matrix as a quaternion and its translation as a position.
void ApplyGhostKeyframeToVehicle(Vehicle *pVehicle, int nRecording)
Restore a ghost frame and estimate velocity from the following frame when available.
const unsigned g_dwGhostFileHeader
The zero marker preceding the length in a current ghost file.
void ClearGhostPlaybackState(void)
Reset every ghost playback frame to zero.
void InterpolateKeyframeState(KeyframeState *pOut, float fShare, KeyframeState *pFrom, KeyframeState *pTo)
Interpolate poses and controls, reversing the target quaternion for distant scalar signs.
int IsGhostRecordingActive(void)
Read the ghost recording flag.
void ApplyVehicleKeyframe(Vehicle *pVehicle, const KeyframeState *pState)
Restore sampled motion and effects, then synchronise integration states.
#define GHOST_RECORDING_COUNT
The number of entries of g_adwGhostFrameCount.
Definition ghost.h:23
bool ReadGhostFileData(const char *pszPath, bool bAllowFailure)
Read a current or legacy ghost file and validate its Adler checksum.
int g_dwLoadedGhostLapCount
The lap-count option read from a ghost file.
void StartGhostRecording(void)
Start ghost recording.
unsigned g_adwGhostFrameCount[GHOST_RECORDING_COUNT]
The number of frames of the recordings of the ghost cars.
u8 * GetGhostPlaybackKeyframeBuffer(void)
Get the encoded frames used for ghost playback.
void ResetGhostRecording(void)
Clear the number of frames of the recordings, only the first in time attack and the demonstration and...
void PackKeyframeToCompactBuffer(u8 *pBuffer, const KeyframeState *pState)
Encode a pose and controls into a compact ghost frame, preserving its final two bytes.
void BuildVehicleKeyframe(KeyframeState *pState, Vehicle *pVehicle)
Sample a vehicle pose, wheel motion, and replay effects.
const char * NextAttractDemoRecording(void)
Choose the recording of the next attract demo: the two of the PC release in turn, and then the demo o...
int g_adwGhostPlaybackFrame[GHOST_RECORDING_COUNT]
Current playback frame of each recording.
void RecordVehicleKeyframe(Vehicle *vehicle)
Sample vehicle and send its keyframe as a local network state update.
const char g_szGhostSaveMagic[4]
The four-byte signature of a ghost file.
#define GHOST_FRAME_SIZE
The size of a frame of the recording of a ghost car.
Definition ghost.h:20
unsigned GetGhostKeyframeDataSize(void)
Get the size of the encoded frames of the first recording.
bool SaveGhostFile(void)
Write the ghost recording, times, checksum, menu settings, and slot label to the selected file.
bool LoadGhostFile(bool bAllowFailure)
Read the ghost file selected in the front end.
void ApplyGhostKeyframeForVehicle(Vehicle *pVehicle)
Restore the ghost frame from the recording slot matching a vehicle index.
u8 * GetGhostKeyframeBuffer(void)
Get the encoded frames of the first recording.
void RecordGhostKeyframe(Vehicle *pVehicle)
Record one vehicle frame while recording is active and the race is not paused.
int g_bGhostRecordingActive
Whether a recording of a ghost car is being made.
#define GHOST_MAX_FRAMES
The maximum number of frames in each recording.
Definition ghost.h:26
FILE * OpenGhostRecording(const char *pszPath)
Open a ghost recording: the file itself, such as a saved recording, or the file built from the JSON t...
unsigned SetGhostFrameCountFromSize(unsigned dwSize)
Set the number of frames of the second recording from its size.
float g_fGhostBestLapTime
The best lap time of the ghost, in seconds.
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.
void DeserializeKeyframeState(KeyframeState *pState, const u8 *pBuffer)
Decode a compact ghost frame into pose and controls.
GhostRecordingInfo g_GhostRecordingInfo
The metadata of the ghost recording.
void AdvanceGhostRecordFrame(void)
Advance active recordings and the time attack or demonstration ghost playback.
void PositionQuaternionToMatrix4x4(f32 matrix[4][4], const QuaternionPose *pPose)
Convert a quaternion and position into a matrix, compensating for quaternion magnitude.
unsigned g_dwGhostRecordingSize
The number of metadata bytes written before the frames.
void FillMemoryPatternBytes(void *pDest, size_t nCount, int nByte)
Fill memory with a byte.
The rigid bodies of the physics: their state, forces and inertia, and the quaternion and 3 by 3 matri...
The metadata stored before the frames of a recording.
Definition ghost.h:84
u8 controllerLayout
Definition ghost.h:91
s8 steeringMode
Definition ghost.h:87
u32 reserved[2]
Definition ghost.h:93
s8 transmission
Definition ghost.h:88
s8 suspension
Definition ghost.h:90
s8 track
Definition ghost.h:85
s8 tires
Definition ghost.h:89
s8 car
Definition ghost.h:86
s8 weather
Definition ghost.h:92
Vehicle pose and interpolated controls before compact frame encoding.
Definition ghost.h:29
float fBraking
Definition ghost.h:40
float fSteerAngle
Definition ghost.h:35
Quaternion orientation
Definition ghost.h:30
float afEffectFlags[6]
Definition ghost.h:45
float fReverse
Definition ghost.h:41
float afWheelSurface[4]
Definition ghost.h:38
float fGearControl
Definition ghost.h:39
Vec3f angularVelocity
Definition ghost.h:33
float afWheelAngle[4]
Definition ghost.h:36
float afLight[2]
Definition ghost.h:44
float fProgress
Definition ghost.h:42
Vec3f position
Definition ghost.h:31
float fBodyRollAngle
Definition ghost.h:34
float afWheelContact[4]
Definition ghost.h:37
float fEngineRpm
Definition ghost.h:43
Vec3f linearVelocity
Definition ghost.h:32
The orientation and the position of a vehicle at the start of a key frame.
Definition ghost.h:331
Quaternion orientation
Definition ghost.h:332
Vec3f position
Definition ghost.h:333
A rotation as a unit quaternion.
Definition rigidbody.h:19
A point or direction in space.
Definition vecmath.h:17
A vehicle.
Definition vehicle.h:143
unsigned int u32
Definition ultratypes.h:20
signed char s8
Definition ultratypes.h:23
float f32
Definition ultratypes.h:38
unsigned char u8
Definition ultratypes.h:18
The vector and matrix arithmetic of the game, its arctangent and power, the triangle and segment test...
The vehicles of a race, the cars they are, and their place on the track.