Run cppcheck

This commit is contained in:
Miloslav Ciz 2025-06-24 21:12:01 +02:00
parent bc55e84d5b
commit d57a07edb8
7 changed files with 25 additions and 47 deletions

View file

@ -17,12 +17,12 @@ fuck issue trackers :D
- error handling (bad map format, bad replay format, items in data file, ...) - error handling (bad map format, bad replay format, items in data file, ...)
- valgrind, cppcheck, different compilers, optimization levels, ... - valgrind, cppcheck, different compilers, optimization levels, ...
- play replay from one platform on another KINDA DID - play replay from one platform on another KINDA DID
- profiling - profiling KINDA DID
- gigantic map that fails to fit in RAM DID 1x - gigantic map that fails to fit in RAM DID 1x
- replay stretching DID 1x - replay stretching DID 1x
- play all maps a lot DOING - play all maps a lot DOING
- correct saving of replays etc. - correct saving of replays etc.
- empty and large data file - empty and large data file KINDA DID
- FPS on each platform - FPS on each platform
- try to use the racing module by itself - try to use the racing module by itself
- spellcheck comments KINDA DID - spellcheck comments KINDA DID

View file

@ -7148,7 +7148,7 @@ void LCR_imageChangeBrightness(int up)
Samples currently loaded image at given pixels coordinates (with wrapping). Samples currently loaded image at given pixels coordinates (with wrapping).
This is slower than reading the image pixel by pixel. 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 // bottleneck here, optimization will increase rendering performance
x = (y % LCR_IMAGE_SIZE) * LCR_IMAGE_SIZE + (x % LCR_IMAGE_SIZE); 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 Gets the next pixel of currently loaded image. This is faster than sampling
the image by pixel coordinates. 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]; uint16_t r = LCR_currentImage.palette[*LCR_currentImage.pixel];
LCR_currentImage.pixel++; LCR_currentImage.pixel++;

View file

@ -2188,7 +2188,7 @@ void LCR_drawPixel(unsigned long index, uint16_t color)
(LCR_game.frame == 1086 && index == 20 && color != 0x4c7a) || (LCR_game.frame == 1086 && index == 20 && color != 0x4c7a) ||
(LCR_game.frame == 1624 && index == 1 && color != 0x4c7a)) (LCR_game.frame == 1624 && index == 1 && color != 0x4c7a))
printf("ERROR: unexpected pixel rendered at frame %d, index %d\n", printf("ERROR: unexpected pixel rendered at frame %d, index %d\n",
LCR_game.frame,(int) index); (int) LCR_game.frame,(int) index);
} }
int testState( int testState(

35
map.h
View file

@ -275,29 +275,6 @@ void LCR_rampGetDimensions(uint8_t rampType, uint8_t *height4ths,
*length6ths = rampType != LCR_BLOCK_RAMP_STEEP ? 6 : 1; *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 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 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: 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]; uint8_t tmpBlock[LCR_BLOCK_SIZE];
LCR_mapBlockGetCoords(prevBlock,&x,&y,&z); LCR_mapBlockGetCoords(prevBlock,&x,&y,&z);
@ -591,7 +568,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name)
if (blockIndex >= 0) if (blockIndex >= 0)
{ {
mat = LCR_mapBlockGetMaterial( m = LCR_mapBlockGetMaterial(
LCR_currentMap.blocks + blockIndex * LCR_BLOCK_SIZE); LCR_currentMap.blocks + blockIndex * LCR_BLOCK_SIZE);
transform = LCR_mapBlockGetTransform( transform = LCR_mapBlockGetTransform(
@ -627,7 +604,7 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name)
y2 >= 0 && y2 < LCR_MAP_SIZE_BLOCKS && y2 >= 0 && y2 < LCR_MAP_SIZE_BLOCKS &&
z2 >= 0 && z2 < 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)) if (!_LCR_mapAddBlock(tmpBlock))
return 0; 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_FILL:
case LCR_BLOCK_CUBOID_HOLLOW: 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]; uint8_t tmpBlock[LCR_BLOCK_SIZE];
mat = LCR_mapBlockGetMaterial(prevBlock); m = LCR_mapBlockGetMaterial(prevBlock);
transform = LCR_mapBlockGetTransform(prevBlock); transform = LCR_mapBlockGetTransform(prevBlock);
LCR_mapBlockGetCoords(prevBlock,&x,&y,&z); 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 && y + j < LCR_MAP_SIZE_BLOCKS &&
z + k < 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); tmpBlock);
if (!_LCR_mapAddBlock(tmpBlock)) if (!_LCR_mapAddBlock(tmpBlock))

View file

@ -11,15 +11,16 @@
Some comments: Some comments:
- The module uses small3dlib, a tiny software rasterization library. This - The module uses small3dlib, a tiny software rasterization library. This
module knows nothing about I/O (windows, canvases, ...), it just say where module knows nothing about I/O (windows, canvases, ...), it just says where
to draw pixels and what colors they should have. to draw pixels and what colors they should be.
- The map 3D model is divided into 4x4x4 chunks, i.e. 64 in total, out of - The map 3D model is divided into chunks 4 times in each dimension, i.e.
which only 8 are loaded at any time, depending on where the camera is and there are 64 chunks in total, out of which only 8 are loaded at any time,
where it is looking. This is to save resources, we don't draw the far away depending on where the camera is located and where it is looking. This is to
chunks or those behind the camera. 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 - 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 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 - 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 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 optimized, namely the _LCR_pixelFunc3D function, as it is called for every
@ -112,7 +113,7 @@ struct
S3L_Model3D models[LCR_RENDERER_MODEL_COUNT]; S3L_Model3D models[LCR_RENDERER_MODEL_COUNT];
uint_fast16_t pixelColor; /**< Holds pixel color for _LCR_pixelFunc3D. This 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; uint32_t frame;
uint8_t loadedChunks[8]; ///< Numbers of loaded map chunks. 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) for (int i = 0; i < 6; ++i)
{ {
LCR_renderer.triUVs[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); LCR_IMAGE_SIZE) / LCR_RENDERER_UNIT);
if (i % 2) 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; for (int ix = 0; ix < 2 * LCR_IMAGE_SIZE * LCR_SETTING_SKY_SIZE;
ix += LCR_SETTING_SKY_SIZE) ix += LCR_SETTING_SKY_SIZE)
{ {
unsigned int color = LCR_getNextImagePixel(); uint_fast16_t color = LCR_getNextImagePixel();
unsigned long startIndex = pixelIndex; unsigned long startIndex = pixelIndex;
for (int k = 0; k < LCR_SETTING_SKY_SIZE; ++k) 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) for (int l = 0; l < LCR_IMAGE_SIZE; ++l)
{ {
uint16_t color = LCR_getNextImagePixel(); uint_fast16_t color = LCR_getNextImagePixel();
if (color != transparentColor) if (color != transparentColor)
LCR_gameDrawPixel(i,color); LCR_gameDrawPixel(i,color);

View file

@ -214,7 +214,7 @@
#ifndef LCR_SETTING_HORIZON_SHIFT #ifndef LCR_SETTING_HORIZON_SHIFT
/** Vertical offset of the background sky image in percents. */ /** Vertical offset of the background sky image in percents. */
#define LCR_SETTING_HORIZON_SHIFT 180 #define LCR_SETTING_HORIZON_SHIFT 200
#endif #endif
#ifndef LCR_SETTING_TIME_MULTIPLIER #ifndef LCR_SETTING_TIME_MULTIPLIER

View file

@ -2102,7 +2102,7 @@ void TPE_worldDebugDraw(TPE_World *world, TPE_DebugDrawFunction drawFunc,
TPE_Unit gridHalfSize = (envGridSize * envGridRes) / 2; TPE_Unit gridHalfSize = (envGridSize * envGridRes) / 2;
TPE_Vec3 center; TPE_Vec3 center = TPE_vec3(0,0,0); // Licar modification: added init
offset %= envGridSize; offset %= envGridSize;