From 3f97ebf518db01cc93f84e20edcb074669c58705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 24 Oct 2020 19:10:42 +0200 Subject: [PATCH] Optimize --- game.h | 10 ++++++---- levels.h | 14 +++++++------- main_sdl.c | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/game.h b/game.h index 344697b..9d0adc7 100755 --- a/game.h +++ b/game.h @@ -984,15 +984,17 @@ void SFG_pixelFunc(RCL_PixelInfo *pixel) ); #if SFG_BACKGROUND_BLUR != 0 - -SFG_backgroundBlurIndex = (SFG_backgroundBlurIndex + 1) % 8; -// SFG_backgroundBlurIndex = (SFG_backgroundBlurIndex + 1) % 0x07; + SFG_backgroundBlurIndex = (SFG_backgroundBlurIndex + 1) % 8; #endif #else color = 1; #endif } +#if SFG_RAYCASTING_SUBSAMPLE == 1 + // the other version will probably get optimized to this, but just in case + SFG_setGamePixel(pixel->position.x,pixel->position.y,color); +#else RCL_Unit screenX = pixel->position.x * SFG_RAYCASTING_SUBSAMPLE; for (int_fast8_t i = 0; i < SFG_RAYCASTING_SUBSAMPLE; ++i) @@ -1000,6 +1002,7 @@ SFG_backgroundBlurIndex = (SFG_backgroundBlurIndex + 1) % 8; SFG_setGamePixel(screenX,pixel->position.y,color); screenX++; } +#endif } /** @@ -1254,7 +1257,6 @@ RCL_Unit SFG_floorHeightAt(int16_t x, int16_t y) doorHeight = doorHeight != (0xff & SFG_DOOR_VERTICAL_POSITION_MASK) ? doorHeight * SFG_DOOR_HEIGHT_STEP : RCL_UNITS_PER_SQUARE; - break; } } diff --git a/levels.h b/levels.h index 7028494..e370369 100644 --- a/levels.h +++ b/levels.h @@ -155,16 +155,16 @@ static inline SFG_TileDefinition SFG_getMapTile uint8_t *properties ) { - if (x < 0 || x >= SFG_MAP_SIZE || y < 0 || y >= SFG_MAP_SIZE) + if (x >= 0 && x < SFG_MAP_SIZE && y >= 0 && y < SFG_MAP_SIZE) { - *properties = SFG_TILE_PROPERTY_NORMAL; - return SFG_OUTSIDE_TILE; + uint8_t tile = level->mapArray[y * SFG_MAP_SIZE + x]; + + *properties = tile & 0xc0; + return level->tileDictionary[tile & 0x3f]; } - uint8_t tile = level->mapArray[y * SFG_MAP_SIZE + x]; - - *properties = tile & 0xc0; - return level->tileDictionary[tile & 0x3f]; + *properties = SFG_TILE_PROPERTY_NORMAL; + return SFG_OUTSIDE_TILE; } #define SFG_NUMBER_OF_LEVELS 10 diff --git a/main_sdl.c b/main_sdl.c index 0779d94..b45aba7 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -34,7 +34,7 @@ // #define SFG_TIME_MULTIPLIER 512 // uncomment for perfomance debug -//#define SFG_CPU_LOAD(percent) printf("CPU load: %d%\n",percent); +#define SFG_CPU_LOAD(percent) printf("CPU load: %d%\n",percent); #ifndef __EMSCRIPTEN__ #ifndef GAME_LQ