Add new records plus comments

This commit is contained in:
Miloslav Ciz 2025-06-08 15:33:43 +02:00
parent 8d9abb6eda
commit 89da509806
8 changed files with 82 additions and 69 deletions

View file

@ -5,62 +5,64 @@
Licar: racing module
This implements the racing physics and logic as well as replays and other
related stuff. It's possible to use this module alone if one wants to
implement a program that doesn't need graphics, I/O etc.
This file implements the racing physics and logic as well as replays and other
stuff related to racing itself. It's possible to use this module alone if one
wants to implement a program that doesn't need graphics, I/O etc.
Some comments:
- This module uses tinyphysicsengine, a small and simple physics engine that
uses "balls and springs" to model bodies (here the car) and kind of
"signed distance functions" to model environment (the map). The car is
strictly a soft body, but it's very "stiff" so that it behaves almost like
a rigid body.
- This module uses tinyphysicsengine (TPE), a small and simple physics engine
that uses "balls and springs" to model bodies (here the car) and kind of
"signed distance functions" to model the static environment (the map). The
car is strictly a soft body, but it's very "stiff" so that it behaves almost
like a rigid body. The car body consists of 5 joints (4 wheels and the
body), the top down views looks like this:
front
(2)---(3) r
l |\ /| i
e | (4) | g
f |/ \| h
t (0)---(1) t
rear
- Replays are internally stored as follows: the replay consists of 16 bit
words representing changes in input at specific frame. In lowest 4 bits the
new input state is recorded, the remaining 12 bits record physics frame
offset against the previous input change. If the 12 bits don't suffice
because the offset is too big (input didn't change for more than 2^12
frames), there must simply be inserted an extra word that just copies the
ticks), there must simply be inserted an extra word that just copies the
current input state.
- Replay text format: first there are two characters saying the physics
engine version, then immediately the name of the map terminated by ';', then
hexadecimal hash of the map follows (exactly 8 characters), then blank
character follows, then achieved time as a series of decimal digits
expressing the physics frame at which the run finished, then the replay
data, i.e. the series of 16 bit words in hexadecimal, each preceded by ':'.
The events (but nothing else) may otherwise be preceeded or followed by
other characters (possible comments). All hexadecimal letters must be
lowercase. The word 00000000 may optinally be used to terminate the replay,
the rest of the string will be ignored.
expressing the physics tick at which the run finished, then the replay data,
i.e. the series of 16 bit words in hexadecimal, each preceded by ':'. The
events (but nothing else) may otherwise be preceded or followed by other
characters (possible comments). All hexadecimal letters must be lowercase.
The word 00000000 may optinally be used to terminate the replay, the rest of
the string will be ignored.
- Physics engine version: LCR_RACING_VERSION1 and LCR_RACING_VERSION2 define
a two-character version string of this module that determines compatibility
of replays. Whenever a change is made to this module that changes the
behavior of physics, the version string must be changed because replays
will stop being compatible. It's still possible to make other changes to
this module (such as optimizations or comments) without having to change
physics version.
- The physics car body has joints numbered like this:
front
l (2)---(3) r
e |\ /| i
f | (4) | g
t |/ \| h
(0)---(1) t
rear
behavior of physics, the version string must be changed because replays will
stop being compatible. It's still possible to make other changes to this
module (such as optimizations or comments) without having to change physics
version.
*/
typedef int32_t LCR_GameUnit; ///< abstract game unit
typedef int32_t LCR_GameUnit; ///< Abstract game unit.
#define LCR_RACING_FPS 30 /**< Physics FPS, i.e. the number of
physics ticks per second. */
#define LCR_RACING_TICK_MS \
(100000 / (LCR_RACING_FPS * LCR_SETTING_TIME_MULTIPLIER))
#define LCR_RACING_VERSION1 '0' ///< first part of physics eng. version
#define LCR_RACING_VERSION2 '0' ///< second part of physics eng. version
#define LCR_RACING_VERSION1 '0' ///< First part of physics eng. version.
#define LCR_RACING_VERSION2 '0' ///< Second part of physics eng. version.
#define LCR_GAME_UNIT 2048 ///< length of map square in LCR_GameUnits
#define LCR_GAME_UNIT 2048 ///< Length of map square in LCR_GameUnits.
#define LCR_RACING_INPUT_FORW 0x01
#define LCR_RACING_INPUT_RIGHT 0x02
@ -74,7 +76,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_RACING_EVENT_ACCELERATOR 0x0010
#define LCR_RACING_EVENT_FAN 0x0020
#define LCR_PHYSICS_UNIT 4096 ///< len. of square for phys. engine
#define LCR_PHYSICS_UNIT 4096 ///< Len. of square for phys. engine.
/* The combination of values TPE_RESHAPE_TENSION_LIMIT and
TPE_RESHAPE_ITERATIONS has crucial effect on the bugginess and feel of car
@ -95,6 +97,12 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_MODULE_NAME "race"
/*
What follows are carefully chosen and tuned physics constants, don't change
them unless with a very good reason, as replay compatibility will be broken
and bugs may start to appear. If physics changes, LCR_RACING_VERSION1 and
LCR_RACING_VERSION2 must be changed to indicate the change.
*/
#define LCR_GRAVITY (LCR_PHYSICS_UNIT / 160)
#define LCR_FAN_FORCE 4
#define LCR_FAN_FORCE_DECREASE 6
@ -107,8 +115,8 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_ACCELERATION (LCR_PHYSICS_UNIT / 9)
#define LCR_CAR_STEER_MAX (LCR_GAME_UNIT / 2)
#define LCR_CAR_STEER_SPEED 50 ///< 0 to 64, lower is faster
#define LCR_CAR_STEER_SLOWDOWN 64 ///< slows down steering at higher speeds
#define LCR_CAR_STEER_SPEED 50 ///< 0 to 64, lower is faster.
#define LCR_CAR_STEER_SLOWDOWN 64 ///< Slows down steering at higher speeds.
#define LCR_CAR_ACCELERATOR_FACTOR 2
#define LCR_CAR_WHEEL_AIR_ROTATION_SPEED (LCR_GAME_UNIT / 32)
@ -121,7 +129,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_GRASS_FACTOR 5
#define LCR_CAR_DIRT_FACTOR 3
#define LCR_CAR_ICE_FACTOR 1
#define LCR_CAR_DRIFT_FACTOR 2 ///< only affects steering friction
#define LCR_CAR_DRIFT_FACTOR 2 ///< Only affects steering friction.
#define LCR_CAR_DRIFT_THRESHOLD_1 (LCR_GAME_UNIT / 10)
#define LCR_CAR_DRIFT_THRESHOLD_0 (LCR_GAME_UNIT / 227)
@ -129,7 +137,7 @@ typedef int32_t LCR_GameUnit; ///< abstract game unit
#define LCR_CAR_JOINTS 5
#define LCR_CAR_CONNECTIONS 10
#define LCR_REPLAY_EVENT_END 0xff ///< special event fed to replay at the end
#define LCR_REPLAY_EVENT_END 0xff ///< Special event fed to replay at the end.
struct
{
@ -964,7 +972,7 @@ void _LCR_racingUpdateCarPosRot(void)
}
/**
Initializes new run.
Initializes a new run.
*/
void LCR_racingRestart(uint8_t replay)
{