Add some comments

This commit is contained in:
Miloslav Ciz 2025-01-08 22:05:54 +01:00
parent 614741f6e8
commit 33daa484e9
3 changed files with 95 additions and 42 deletions

75
game.h
View file

@ -147,8 +147,6 @@ uint8_t LCR_gameGetNextAudioSample(void);
//------------------------------------------------------------------------------
#include "settings.h"
#define LCR_LOG0(s) ;
#define LCR_LOG1(s) ;
#define LCR_LOG2(s) ;
@ -180,6 +178,30 @@ uint8_t LCR_gameGetNextAudioSample(void);
#define LCR_GAME_STATE_LOADING_MAP 0x04
#define LCR_GAME_STATE_END 0xff
// forward decls of pixel drawing functions for the renderer
/**
Internal pixel drawing function that draws pixel at specified screen coords
without checking for safety (it's faster but can only be done if we know for
sure we're not drawing outside the screen).
*/
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y, uint16_t color);
/**
Internal pixel drawing function that checks for out-of-screen coordinates. Use
this if the pixel can potentially lie of screen (however if you know it won't,
use the normal unsafe function in sake of performance).
*/
static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
uint_fast16_t color);
#include "constants.h"
#include "racing.h"
#include "settings.h"
#include "audio.h"
#include "assets.h"
#include "renderer.h"
struct
{
uint8_t state;
@ -225,22 +247,6 @@ uint8_t LCR_gameMusicOn(void)
#endif
}
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color);
/**
Internal pixel drawing function that checks for out-of-screen coordinates. Use
this if the pixel can potentially lie of screen (however if you know it won't,
use the normal unsafe function in sake of performance).
*/
static inline void LCR_drawPixelXYSafe(unsigned int x, unsigned int y,
uint_fast16_t color);
#include "racing.h"
#include "assets.h"
#include "renderer.h"
#include "audio.h"
void LCR_drawPixelXYUnsafe(unsigned int x, unsigned int y,
uint16_t color)
{
@ -287,6 +293,9 @@ void LCR_gameResetRun(void)
LCR_game.runTimeMS = 0;
}
/**
Rewinds the global resource reading head to the beginning.
*/
void LCR_gameRewindResourceFile(void)
{
LCR_appendResourceStr("");
@ -294,10 +303,10 @@ void LCR_gameRewindResourceFile(void)
}
/**
Reads the next resource file character while merging the internal resource
file with the optional user file. First the internal file will be read,
immediately followed by the user file, then zero char will return and
reading will start over.
Reads the next global resource file character (merged internal resource file
with the optional user file). First the internal file will be read,
immediately followed by the user file, then zero char will be returned and
then reading starts over.
*/
char LCR_gameGetNextResourceFileChar(void)
{
@ -337,7 +346,7 @@ char LCR_gameGetNextResourceFileChar(void)
/**
Similar to LCR_gameGetNextResourceFileChar, but returns 0 instead of the
resource string separator character. This function is means to be used by
resource string separator character. This function is meant to be used by
functions that load something from a string while expecting a zero terminated
string.
*/
@ -453,8 +462,7 @@ void LCR_gameInit(void)
/**
Loads up to LCR_RESOURCE_ITEM_CHUNK items of given type, starting at given
index (among items of the same type). This will also load the menu item
names.
index (among items of the same type). This will also load the menu item names.
*/
void LCR_gameLoadResourceFileChunk(unsigned int startIndex, char magicNumber)
{
@ -499,8 +507,7 @@ void LCR_gameLoadResourceFileChunk(unsigned int startIndex, char magicNumber)
}
else if (i == 1 && state != 255)
{
if (
c == LCR_RESOURCE_FILE_SEPARATOR ||
if (c == LCR_RESOURCE_FILE_SEPARATOR ||
c == LCR_RESOURCE_FILE_SEPARATOR2 ||
state >= 1 + LCR_MENU_STRING_SIZE - 1)
{
@ -622,6 +629,10 @@ void LCR_gameDraw3DView(void)
}
}
/**
Helper subroutine, handles user input during main loop frame, EXCEPT for the
driving input (that is handled in the loop itself).
*/
void LCR_gameHandleInput(void)
{
int tabSwitchedTo = -1;
@ -812,11 +823,10 @@ void LCR_gameHandleInput(void)
uint8_t LCR_gameStep(uint32_t time)
{
uint32_t sleep = 0;
int paused =
LCR_game.state == LCR_GAME_STATE_MENU ||
int paused = LCR_game.state == LCR_GAME_STATE_MENU ||
LCR_game.state == LCR_GAME_STATE_RUN_STARTING;
LCR_LOG2("game step start");
LCR_LOG2("game step (start)");
LCR_game.time = time;
@ -876,6 +886,7 @@ uint8_t LCR_gameStep(uint32_t time)
}
int engineIntensity = LCR_carSpeedKMH() * 2;
LCR_audioSetEngineIntensity(paused ? 0 :
(engineIntensity < 256 ? engineIntensity : 255));
@ -890,7 +901,7 @@ uint8_t LCR_gameStep(uint32_t time)
// handle rendering:
if (time >= LCR_game.nextRenderFrameTime)
{
LCR_LOG2("gonna render next frame");
LCR_LOG2("rendering next frame");
while (time >= LCR_game.nextRenderFrameTime)
LCR_game.nextRenderFrameTime += 1000 / LCR_SETTING_FPS;
@ -935,7 +946,7 @@ uint8_t LCR_gameStep(uint32_t time)
}
LCR_game.frame++;
LCR_LOG2("game step end");
LCR_LOG2("game step (end)");
return LCR_game.state != LCR_GAME_STATE_END;
}