Fix horizon offset

This commit is contained in:
Miloslav Ciz 2025-02-03 12:58:42 +01:00
parent f24db847ce
commit 7f00b5aa5f
7 changed files with 34 additions and 40 deletions

View file

@ -1,6 +1,5 @@
=========== GENERAL ============== =========== GENERAL ==============
- bug: background horizon position depends on resolution! fix
- make a small txt game menual - make a small txt game menual
- test: - test:
- long replay - long replay
@ -34,6 +33,7 @@
=========== HANDLED ============== =========== HANDLED ==============
- allow stopping car rotation in air like in Trackmania - allow stopping car rotation in air like in Trackmania
- bug: background horizon position depends on resolution! fix
- option to disable crash sounds (and so code that detects crashes) - option to disable crash sounds (and so code that detects crashes)
- drawing dithered transparent objects fills z-buffer in the transparent parts - drawing dithered transparent objects fills z-buffer in the transparent parts
and then the geometry behind it isn't drawn <- PARTIALLY FIXED, LOOKS GOOD and then the geometry behind it isn't drawn <- PARTIALLY FIXED, LOOKS GOOD

18
audio.h
View file

@ -11,15 +11,15 @@
file, left to be optionally loaded and played by the frontend). file, left to be optionally loaded and played by the frontend).
*/ */
#define LCR_SOUND_NONE 0 #define LCR_SOUND_NONE 0
#define LCR_SOUND_CLICK 1 #define LCR_SOUND_CLICK 1
#define LCR_SOUND_CRASH_SMALL 2 #define LCR_SOUND_CRASH_SMALL 2
#define LCR_SOUND_CRASH_BIG 3 #define LCR_SOUND_CRASH_BIG 3
#define LCR_SOUND_ACCELERATOR 4 #define LCR_SOUND_ACCELERATOR 4
#define LCR_SOUND_FAN 5 #define LCR_SOUND_FAN 5
#define LCR_AUDIO_CRASH_SOUND_LEN 2048 #define LCR_AUDIO_CRASH_SOUND_LEN 2048
#define LCR_AUDIO_FAN_SOUND_LEN 4096 #define LCR_AUDIO_FAN_SOUND_LEN 4096
struct struct
{ {
@ -178,7 +178,7 @@ uint8_t LCR_audioGetNextSample(void)
else if (LCR_audio.engineIntensity) else if (LCR_audio.engineIntensity)
{ {
LCR_audio.engineOsc += LCR_audio.engineInc ? (((_LCR_audioNoise() % 256) < LCR_audio.engineOsc += LCR_audio.engineInc ? (((_LCR_audioNoise() % 256) <
(10 + LCR_audio.engineIntensity))) : -31; (10 + LCR_audio.engineIntensity))) : -31;
if (LCR_audio.engineInc && LCR_audio.engineOsc > if (LCR_audio.engineInc && LCR_audio.engineOsc >
(90 + (LCR_audio.engineIntensity / 8))) (90 + (LCR_audio.engineIntensity / 8)))

7
game.h
View file

@ -850,22 +850,25 @@ void LCR_gameInit(int argc, const char **argv)
} }
} }
LCR_gameLoadMainMenuItems();
if (quickLoad == 1) if (quickLoad == 1)
{ {
LCR_gameLoadMap(LCR_countData('M') - 1); LCR_gameLoadMap(LCR_countData('M') - 1);
LCR_gameSetState(LCR_GAME_STATE_LOADING); LCR_gameSetState(LCR_GAME_STATE_LOADING);
LCR_game.menu.selectedTab = 1; LCR_game.menu.selectedTab = 1;
LCR_gameLoadDataFileChunk(0,'M');
} }
else if (quickLoad == 2 || quickLoad == 3) else if (quickLoad == 2 || quickLoad == 3)
{ {
LCR_gameLoadReplay(LCR_countData('R') - 1); LCR_gameLoadReplay(LCR_countData('R') - 1);
LCR_gameSetState(LCR_GAME_STATE_LOADING); LCR_gameSetState(LCR_GAME_STATE_LOADING);
LCR_game.menu.selectedTab = quickLoad; LCR_game.menu.selectedTab = quickLoad;
LCR_gameLoadDataFileChunk(0,'R');
} }
else else
{
LCR_gameLoadMainMenuItems();
LCR_gameSetState(LCR_GAME_STATE_MENU); LCR_gameSetState(LCR_GAME_STATE_MENU);
}
} }
/** /**

View file

@ -3,5 +3,5 @@
clear clear
clear clear
gcc -std=c99 -g -Wall -Wextra -pedantic -O1 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers `sdl2-config --libs --static-libs` -o game frontend_sdl.c && ./game $@ gcc -std=c99 -g -Wall -Wextra -pedantic -O1 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -o game frontend_sdl.c `sdl2-config --libs --static-libs` && ./game $@

View file

@ -1245,8 +1245,6 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.carBody.joints[LCR_CAR_JOINTS - 1].velocity[j]; LCR_racing.carBody.joints[LCR_CAR_JOINTS - 1].velocity[j];
} }
// TODO: magic constants
if (input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK)) if (input & (LCR_RACING_INPUT_FORW | LCR_RACING_INPUT_BACK))
{ {
LCR_GameUnit rotateBy = LCR_GameUnit rotateBy =
@ -1336,7 +1334,7 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.carBody.joints[i].velocity[2] = jv.z; LCR_racing.carBody.joints[i].velocity[2] = jv.z;
} }
driftFriction /= 4; driftFriction /= 4; // divide by 4 wheels
if ((!LCR_racing.carDrifting) && if ((!LCR_racing.carDrifting) &&
driftFriction > LCR_CAR_DRIFT_THRESHOLD_1) driftFriction > LCR_CAR_DRIFT_THRESHOLD_1)
@ -1411,7 +1409,7 @@ uint32_t LCR_racingStep(unsigned int input)
LCR_racing.carBody.joints[4].position, LCR_racing.carBody.joints[4].position,
LCR_racing.carBody.joints[0].position))); LCR_racing.carBody.joints[0].position)));
if (angle < TPE_F / 64) // TODO: magic constant if (angle < TPE_F / 64) // TPE_F / 64 is a magic constant
{ {
LCR_LOG2("roof squeezed, applying anti force") LCR_LOG2("roof squeezed, applying anti force")
@ -1559,8 +1557,7 @@ uint32_t LCR_racingStep(unsigned int input)
Draws a simple 3D debug overlap of the physics world. Draws a simple 3D debug overlap of the physics world.
*/ */
void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2], void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],
LCR_GameUnit camFov, LCR_GameUnit camFov, void (*drawPixel)(uint16_t, uint16_t, uint8_t))
void (*drawPixel)(uint16_t, uint16_t, uint8_t))
{ {
#if LCR_SETTING_DEBUG_PHYSICS_DRAW #if LCR_SETTING_DEBUG_PHYSICS_DRAW
LCR_LOG2("drawing physics debug"); LCR_LOG2("drawing physics debug");
@ -1581,11 +1578,6 @@ void LCR_physicsDebugDraw(LCR_GameUnit camPos[3], LCR_GameUnit camRot[2],
TPE_worldDebugDraw(&(LCR_racing.physicsWorld),drawPixel, TPE_worldDebugDraw(&(LCR_racing.physicsWorld),drawPixel,
cPos,cRot,cView,16,LCR_PHYSICS_UNIT / 4,LCR_racing.tick * 4); cPos,cRot,cView,16,LCR_PHYSICS_UNIT / 4,LCR_racing.tick * 4);
/*
TPE_worldDebugDraw(&(LCR_racing.physicsWorld),_LCR_drawPhysicsDebugPixel,
cPos,cRot,cView,16,LCR_PHYSICS_UNIT / 4,LCR_racing.tick * 4);
*/
#endif #endif
} }

View file

@ -41,8 +41,8 @@
// NOTE: ^ S3L_F sometimes makes some triangles bug, S3L_F/2 seems to fix it // NOTE: ^ S3L_F sometimes makes some triangles bug, S3L_F/2 seems to fix it
// but it's more jerky, maybe try to apply anti-overflow in S3L? // but it's more jerky, maybe try to apply anti-overflow in S3L?
#define LCR_RENDERER_CHUNK_RESOLUTION 4 // do not change #define LCR_RENDERER_CHUNK_RESOLUTION 4 // do not change
#define LCR_RENDERER_LOD_BLOCKS 64 // do not change #define LCR_RENDERER_LOD_BLOCKS 64 // do not change
#define LCR_RENDERER_CHUNK_SIZE_HORIZONTAL \ #define LCR_RENDERER_CHUNK_SIZE_HORIZONTAL \
((LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT) / LCR_RENDERER_CHUNK_RESOLUTION) ((LCR_MAP_SIZE_BLOCKS * LCR_RENDERER_UNIT) / LCR_RENDERER_CHUNK_RESOLUTION)
@ -1346,19 +1346,16 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV)
LCR_loadImage(sky + 3); LCR_loadImage(sky + 3);
bottomColor = LCR_sampleImage(LCR_IMAGE_SIZE - 1,LCR_IMAGE_SIZE - 1); bottomColor = LCR_sampleImage(LCR_IMAGE_SIZE - 1,LCR_IMAGE_SIZE - 1);
anchorPoint[0] = ((LCR_EFFECTIVE_RESOLUTION_X * offsetH) anchorPoint[0] = ((LCR_EFFECTIVE_RESOLUTION_X * offsetH) / S3L_F) %
/ S3L_F) %
(2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE); (2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE);
if (anchorPoint[0] < 0) if (anchorPoint[0] < 0)
anchorPoint[0] += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; anchorPoint[0] += 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
anchorPoint[1] = anchorPoint[1] = LCR_EFFECTIVE_RESOLUTION_Y / 2 - (LCR_EFFECTIVE_RESOLUTION_Y
(LCR_EFFECTIVE_RESOLUTION_Y) / 2 - // 3: we place the center a bit more up * offsetV) / S3L_F - ((LCR_IMAGE_SIZE * LCR_SETTING_HORIZON_SHIFT) / 100 *
(LCR_SETTING_HORIZON_SHIFT * LCR_EFFECTIVE_RESOLUTION_Y) / 100 - LCR_SETTING_SKY_SIZE);
(LCR_EFFECTIVE_RESOLUTION_Y * offsetV) / S3L_F
- LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
pixelIndex = 0; pixelIndex = 0;
y = anchorPoint[1] < 0 ? anchorPoint[1] : 0; y = anchorPoint[1] < 0 ? anchorPoint[1] : 0;

View file

@ -17,16 +17,18 @@
#define LCR_SETTING_RESOLUTION_Y 768 #define LCR_SETTING_RESOLUTION_Y 768
#endif #endif
#ifndef LCR_SETTING_RESOLUTION_SUBDIVIDE
/** Subdivides the whole game resolution by this amount by making each pixel
this number of times bigger. */
#define LCR_SETTING_RESOLUTION_SUBDIVIDE 2
#endif
#ifndef LCR_SETTING_FPS #ifndef LCR_SETTING_FPS
/** Rendering frames per second. Note this only applies to graphics, NOT /** Rendering frames per second. Note this only applies to graphics, NOT
physics. */ physics. */
#define LCR_SETTING_FPS 30 #define LCR_SETTING_FPS 30
#endif #endif
#ifndef LCR_SETTING_RESOLUTION_SUBDIVIDE
#define LCR_SETTING_RESOLUTION_SUBDIVIDE 1
#endif
#ifndef LCR_SETTING_FREE_CAMERA_SPEED #ifndef LCR_SETTING_FREE_CAMERA_SPEED
/** Move speed of free camera, in 1/8ths of block length. */ /** Move speed of free camera, in 1/8ths of block length. */
#define LCR_SETTING_FREE_CAMERA_SPEED 50 #define LCR_SETTING_FREE_CAMERA_SPEED 50
@ -197,8 +199,8 @@
#endif #endif
#ifndef LCR_SETTING_HORIZON_SHIFT #ifndef LCR_SETTING_HORIZON_SHIFT
/** Vertical offset of the background horizon in percents of screen height. */ /** Vertical offset of the background sky image in percents. */
#define LCR_SETTING_HORIZON_SHIFT 30 #define LCR_SETTING_HORIZON_SHIFT 180
#endif #endif
#ifndef LCR_SETTING_TIME_MULTIPLIER #ifndef LCR_SETTING_TIME_MULTIPLIER