From 0ec39403426ef918db0e2f983d9a707e4098c861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 7 Oct 2019 02:07:10 +0200 Subject: [PATCH] Fix visual bug --- TODO.txt | 2 +- main.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/TODO.txt b/TODO.txt index db8de58..de29ea5 100644 --- a/TODO.txt +++ b/TODO.txt @@ -16,8 +16,8 @@ bugs: - sprite positioning inccuracy - done: - texture coords of floor walls should start from the floor? NO, CAUSES ISSUES +- vertical visual noise when standing on elevator diff --git a/main.c b/main.c index 40b3726..da9ca29 100755 --- a/main.c +++ b/main.c @@ -347,7 +347,6 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel) SFG_TRANSPARENT_COLOR; shadow = pixel->hit.direction >> 1; - } else { @@ -541,6 +540,8 @@ RCL_Unit SFG_movingWallHeight low + halfHeight + (RCL_sinInt(sinArg) * halfHeight) / RCL_UNITS_PER_SQUARE; } +uint32_t SFG_frameTime; ///< Keeps a constant time (in ms) during a frame + RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y) { uint8_t properties; @@ -568,7 +569,7 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y) return SFG_movingWallHeight( SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP, SFG_TILE_CEILING_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP, - SFG_getTimeMs() - SFG_currentLevel.timeStart); + SFG_frameTime - SFG_currentLevel.timeStart); } return SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP - @@ -595,7 +596,7 @@ RCL_Unit SFG_ceilingHeightAt(int16_t x, int16_t y) SFG_TILE_FLOOR_HEIGHT(tile) * SFG_WALL_HEIGHT_STEP, (SFG_TILE_CEILING_HEIGHT(tile) + SFG_TILE_FLOOR_HEIGHT(tile)) * SFG_WALL_HEIGHT_STEP, - SFG_getTimeMs() - SFG_currentLevel.timeStart); + SFG_frameTime - SFG_currentLevel.timeStart); } uint32_t SFG_gameFrame; @@ -671,10 +672,10 @@ void SFG_setAndInitLevel(const SFG_Level *level) SFG_initPlayer(); -SFG_player.camera.position.x = 13185; -SFG_player.camera.position.y = 4395; -SFG_player.camera.direction = 846; -SFG_player.camera.height = 3360; +SFG_player.camera.position.x = 5674; +SFG_player.camera.position.y = 19257; +SFG_player.camera.direction = 352; +SFG_player.camera.height = 8480; } @@ -931,6 +932,8 @@ void SFG_mainLoopBody() uint32_t timeNow = SFG_getTimeMs(); uint32_t timeNextFrame = SFG_lastFrameTimeMs + SFG_MS_PER_FRAME; + SFG_frameTime = timeNow; + if (timeNow >= timeNextFrame) { uint32_t timeSinceLastFrame = timeNow - SFG_lastFrameTimeMs;