diff --git a/TODO.txt b/TODO.txt index b5f46cd..557e853 100644 --- a/TODO.txt +++ b/TODO.txt @@ -17,12 +17,12 @@ fuck issue trackers :D - error handling (bad map format, bad replay format, items in data file, ...) - valgrind, cppcheck, different compilers, optimization levels, ... - play replay from one platform on another KINDA DID - - profiling + - profiling KINDA DID - gigantic map that fails to fit in RAM DID 1x - replay stretching DID 1x - play all maps a lot DOING - correct saving of replays etc. - - empty and large data file + - empty and large data file KINDA DID - FPS on each platform - try to use the racing module by itself - spellcheck comments KINDA DID diff --git a/assets.h b/assets.h index d8495f5..6b03bb0 100644 --- a/assets.h +++ b/assets.h @@ -7148,7 +7148,7 @@ void LCR_imageChangeBrightness(int up) Samples currently loaded image at given pixels coordinates (with wrapping). This is slower than reading the image pixel by pixel. */ -uint16_t LCR_sampleImage(int_fast32_t x, int_fast32_t y) +uint_fast16_t LCR_sampleImage(int_fast32_t x, int_fast32_t y) { // bottleneck here, optimization will increase rendering performance x = (y % LCR_IMAGE_SIZE) * LCR_IMAGE_SIZE + (x % LCR_IMAGE_SIZE); @@ -7160,7 +7160,7 @@ uint16_t LCR_sampleImage(int_fast32_t x, int_fast32_t y) Gets the next pixel of currently loaded image. This is faster than sampling the image by pixel coordinates. */ -uint16_t LCR_getNextImagePixel(void) +uint_fast16_t LCR_getNextImagePixel(void) { uint16_t r = LCR_currentImage.palette[*LCR_currentImage.pixel]; LCR_currentImage.pixel++; diff --git a/frontend_test.c b/frontend_test.c index 80cf375..933364f 100644 --- a/frontend_test.c +++ b/frontend_test.c @@ -2188,7 +2188,7 @@ void LCR_drawPixel(unsigned long index, uint16_t color) (LCR_game.frame == 1086 && index == 20 && color != 0x4c7a) || (LCR_game.frame == 1624 && index == 1 && color != 0x4c7a)) printf("ERROR: unexpected pixel rendered at frame %d, index %d\n", - LCR_game.frame,(int) index); + (int) LCR_game.frame,(int) index); } int testState( diff --git a/map.h b/map.h index 13e0699..3f64ca4 100644 --- a/map.h +++ b/map.h @@ -275,29 +275,6 @@ void LCR_rampGetDimensions(uint8_t rampType, uint8_t *height4ths, *length6ths = rampType != LCR_BLOCK_RAMP_STEEP ? 6 : 1; } -uint8_t *LCR_getMapBlockAtCoordNumber(uint32_t coord) -{ - // Binary search the block: - - uint16_t a = 0, b = LCR_currentMap.blockCount - 1; - - while (b >= a) - { - uint16_t mid = (a + b) / 2; - uint8_t *block = LCR_currentMap.blocks + mid * LCR_BLOCK_SIZE; - uint32_t coord2 = LCR_mapBlockGetCoordNumber(block); - - if (coord2 == coord) - return block; - else if (coord2 > coord) - b = mid - 1; - else - a = mid + 1; - } - - return 0; -} - /** Adds given block to current map, including possibly deleting a block by adding LCR_BLOCK_NONE. The function handles sorting the block to the right @@ -578,7 +555,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) { case LCR_BLOCK_MIRROR: { - uint8_t x, y, z, mat, transform, type; + uint8_t x, y, z, m, transform, type; uint8_t tmpBlock[LCR_BLOCK_SIZE]; LCR_mapBlockGetCoords(prevBlock,&x,&y,&z); @@ -591,7 +568,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) if (blockIndex >= 0) { - mat = LCR_mapBlockGetMaterial( + m = LCR_mapBlockGetMaterial( LCR_currentMap.blocks + blockIndex * LCR_BLOCK_SIZE); transform = LCR_mapBlockGetTransform( @@ -627,7 +604,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) y2 >= 0 && y2 < LCR_MAP_SIZE_BLOCKS && z2 >= 0 && z2 < LCR_MAP_SIZE_BLOCKS) { - LCR_makeMapBlock(type,x2,y2,z2,mat,t2,tmpBlock); + LCR_makeMapBlock(type,x2,y2,z2,m,t2,tmpBlock); if (!_LCR_mapAddBlock(tmpBlock)) return 0; @@ -642,10 +619,10 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) case LCR_BLOCK_CUBOID_FILL: case LCR_BLOCK_CUBOID_HOLLOW: { - uint8_t x, y, z, mat, transform; + uint8_t x, y, z, m, transform; uint8_t tmpBlock[LCR_BLOCK_SIZE]; - mat = LCR_mapBlockGetMaterial(prevBlock); + m = LCR_mapBlockGetMaterial(prevBlock); transform = LCR_mapBlockGetTransform(prevBlock); LCR_mapBlockGetCoords(prevBlock,&x,&y,&z); @@ -660,7 +637,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) y + j < LCR_MAP_SIZE_BLOCKS && z + k < LCR_MAP_SIZE_BLOCKS)) { - LCR_makeMapBlock(prevBlock[0],x + i,y + j,z + k,mat,transform, + LCR_makeMapBlock(prevBlock[0],x + i,y + j,z + k,m,transform, tmpBlock); if (!_LCR_mapAddBlock(tmpBlock)) diff --git a/renderer.h b/renderer.h index 09d2e15..92a02cf 100644 --- a/renderer.h +++ b/renderer.h @@ -11,15 +11,16 @@ Some comments: - The module uses small3dlib, a tiny software rasterization library. This - module knows nothing about I/O (windows, canvases, ...), it just say where - to draw pixels and what colors they should have. - - The map 3D model is divided into 4x4x4 chunks, i.e. 64 in total, out of - which only 8 are loaded at any time, depending on where the camera is and - where it is looking. This is to save resources, we don't draw the far away - chunks or those behind the camera. + module knows nothing about I/O (windows, canvases, ...), it just says where + to draw pixels and what colors they should be. + - The map 3D model is divided into chunks 4 times in each dimension, i.e. + there are 64 chunks in total, out of which only 8 are loaded at any time, + depending on where the camera is located and where it is looking. This is to + save CPU time, we don't draw the far away chunks or those behind the camera. - Extremely simple LOD of far away chunks is implemented: we keep an 8x8x8 bit array of where there is empty space and where there is "something", then - for far away areas with "something" we just draw some 2D rectangles. + for far away areas with "something" we just draw some 2D rectangles. This + mostly helps orientation in areas where there are no 3D models nearby. - RENDERING IS THE BOTTLENECK OF PERFORMANCE, it takes even much more time than physics simulation, i.e. care should be taken to make code here very optimized, namely the _LCR_pixelFunc3D function, as it is called for every @@ -112,7 +113,7 @@ struct S3L_Model3D models[LCR_RENDERER_MODEL_COUNT]; uint_fast16_t pixelColor; /**< Holds pixel color for _LCR_pixelFunc3D. This - is needed is texture subsampling is on. */ + is needed when texture subsampling is on. */ uint32_t frame; uint8_t loadedChunks[8]; ///< Numbers of loaded map chunks. @@ -523,7 +524,7 @@ void _LCR_pixelFunc3D(S3L_PixelInfo *pixel) for (int i = 0; i < 6; ++i) { LCR_renderer.triUVs[i] = (( - (v[i / 2][i % 2 ? 1 : (type == 1 ? 2 : 0)]) * + (v[i / 2][(i % 2) ? 1 : (type == 1 ? 2 : 0)]) * LCR_IMAGE_SIZE) / LCR_RENDERER_UNIT); if (i % 2) @@ -1597,7 +1598,7 @@ void LCR_rendererDrawSky(int sky, S3L_Unit offsetH, S3L_Unit offsetV) for (int ix = 0; ix < 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE; ix += LCR_SETTING_SKY_SIZE) { - unsigned int color = LCR_getNextImagePixel(); + uint_fast16_t color = LCR_getNextImagePixel(); unsigned long startIndex = pixelIndex; for (int k = 0; k < LCR_SETTING_SKY_SIZE; ++k) @@ -1983,7 +1984,7 @@ void LCR_rendererBlitImage(uint8_t index, unsigned int x, unsigned int y, for (int l = 0; l < LCR_IMAGE_SIZE; ++l) { - uint16_t color = LCR_getNextImagePixel(); + uint_fast16_t color = LCR_getNextImagePixel(); if (color != transparentColor) LCR_gameDrawPixel(i,color); diff --git a/settings.h b/settings.h index cdeaa3b..332df45 100644 --- a/settings.h +++ b/settings.h @@ -214,7 +214,7 @@ #ifndef LCR_SETTING_HORIZON_SHIFT /** Vertical offset of the background sky image in percents. */ - #define LCR_SETTING_HORIZON_SHIFT 180 + #define LCR_SETTING_HORIZON_SHIFT 200 #endif #ifndef LCR_SETTING_TIME_MULTIPLIER diff --git a/tinyphysicsengine.h b/tinyphysicsengine.h index 3b59b28..1ea28ce 100644 --- a/tinyphysicsengine.h +++ b/tinyphysicsengine.h @@ -2102,7 +2102,7 @@ void TPE_worldDebugDraw(TPE_World *world, TPE_DebugDrawFunction drawFunc, TPE_Unit gridHalfSize = (envGridSize * envGridRes) / 2; - TPE_Vec3 center; + TPE_Vec3 center = TPE_vec3(0,0,0); // Licar modification: added init offset %= envGridSize;