From 2a84afa9815276e8ee11283a75b04a48d16b12a1 Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Mon, 3 Feb 2025 18:57:53 +0100 Subject: [PATCH] Add quit block --- TODO.txt | 16 +++---- game.h | 138 ++++++++++++++++++++++++++--------------------------- map.h | 5 ++ settings.h | 12 ++--- 4 files changed, 85 insertions(+), 86 deletions(-) diff --git a/TODO.txt b/TODO.txt index 747226c..094536d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,14 +6,6 @@ - replay stretching works - replay with input not occuring for more that LCR_SETTING_GHOST_STEP - replay validation -- add argc/argv to gameInit? could be used to quickly start maps, verify - replays etc. Options: - -sN: sound (0/1) - -mN: music (0/1) - -cN: set camera - -M: load last map in resource files (good for making maps) - -R: load last replay in resource files (good for making TASes) - -P: load and play against last replay in resource files - maybe each map could have a target time embedded: when beaten, the map would be marked as such - player name (modifiable via resource file) @@ -33,6 +25,14 @@ =========== HANDLED ============== - allow stopping car rotation in air like in Trackmania +- add argc/argv to gameInit? could be used to quickly start maps, verify + replays etc. Options: + -sN: sound (0/1) + -mN: music (0/1) + -cN: set camera + -M: load last map in resource files (good for making maps) + -R: load last replay in resource files (good for making TASes) + -P: load and play against last replay in resource files - bug: background horizon position depends on resolution! fix - option to disable crash sounds (and so code that detects crashes) - drawing dithered transparent objects fills z-buffer in the transparent parts diff --git a/game.h b/game.h index 11f900d..362b7cb 100644 --- a/game.h +++ b/game.h @@ -798,6 +798,75 @@ void LCR_gameLoadMainMenuItems(void) LCR_game.menu.itemCount = 4; } +/** + 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. +*/ +void LCR_gameLoadDataFileChunk(unsigned int startIndex, char magicNumber) +{ + char c; + unsigned char state = 0; + + LCR_gameEraseMenuItemNames(); + + LCR_game.dataFile.firstItemIndex = startIndex; + LCR_game.dataFile.itemsTotal = 0; + + LCR_gameRewindDataFile(); + + /* 3 iterations: in first we seek to the start index, in second we load the + names, in third we just read the rest to get the total count. */ + for (int i = 0; i < 3; ++i) + { + while (1) + { + if (i == 0 && !startIndex) + break; + + c = LCR_gameGetNextDataFileChar(); + + if (c == 0) + return; + + if (state == 0) // second magic char + { + state = 255; + + if (c == magicNumber) + { + LCR_game.dataFile.itemsTotal++; + + if (i == 0) + startIndex--; + else if (i == 1) + state = 1; + } + + } + else if (i == 1 && state != 255) + { + if (c == LCR_RESOURCE_FILE_SEPARATOR || + c == LCR_RESOURCE_FILE_SEPARATOR2 || + state >= 1 + LCR_MENU_STRING_SIZE - 1) + { + state = 255; + LCR_game.menu.itemCount++; + + if (LCR_game.menu.itemCount >= LCR_RESOURCE_ITEM_CHUNK) + break; + } + else + LCR_game.menu.itemNames[LCR_game.menu.itemCount][state - 1] = c; + + state++; + } + + if (c == LCR_RESOURCE_FILE_SEPARATOR) + state = 0; + } + } +} + void LCR_gameInit(int argc, const char **argv) { LCR_LOG0("initializing"); @@ -871,75 +940,6 @@ void LCR_gameInit(int argc, const char **argv) } } -/** - 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. -*/ -void LCR_gameLoadDataFileChunk(unsigned int startIndex, char magicNumber) -{ - char c; - unsigned char state = 0; - - LCR_gameEraseMenuItemNames(); - - LCR_game.dataFile.firstItemIndex = startIndex; - LCR_game.dataFile.itemsTotal = 0; - - LCR_gameRewindDataFile(); - - /* 3 iterations: in first we seek to the start index, in second we load the - names, in third we just read the rest to get the total count. */ - for (int i = 0; i < 3; ++i) - { - while (1) - { - if (i == 0 && !startIndex) - break; - - c = LCR_gameGetNextDataFileChar(); - - if (c == 0) - return; - - if (state == 0) // second magic char - { - state = 255; - - if (c == magicNumber) - { - LCR_game.dataFile.itemsTotal++; - - if (i == 0) - startIndex--; - else if (i == 1) - state = 1; - } - - } - else if (i == 1 && state != 255) - { - if (c == LCR_RESOURCE_FILE_SEPARATOR || - c == LCR_RESOURCE_FILE_SEPARATOR2 || - state >= 1 + LCR_MENU_STRING_SIZE - 1) - { - state = 255; - LCR_game.menu.itemCount++; - - if (LCR_game.menu.itemCount >= LCR_RESOURCE_ITEM_CHUNK) - break; - } - else - LCR_game.menu.itemNames[LCR_game.menu.itemCount][state - 1] = c; - - state++; - } - - if (c == LCR_RESOURCE_FILE_SEPARATOR) - state = 0; - } - } -} - /** Assumes maps are loaded in menu items, checks (in the resource file) which ones have been marked as beaten and marks corresponding menu items as such. diff --git a/map.h b/map.h index 73543dc..c3d7a82 100644 --- a/map.h +++ b/map.h @@ -129,6 +129,8 @@ but makes a hollow one */ #define LCR_BLOCK_START '*' ///< specifies start block position +#define LCR_BLOCK_QUIT 'e' /**< special block, ends reading the + map (useful when creating maps) */ /* TODO: - bigger structures like a loop, sloped road etc? @@ -436,6 +438,9 @@ uint8_t LCR_mapLoadFromStr(char (*getNextCharFunc)(void), const char *name) uint8_t mat = 0; int coords[3]; + if (block == LCR_BLOCK_QUIT) + break; + for (int i = 0; i < 3; ++i) { c = getNextCharFunc(); diff --git a/settings.h b/settings.h index c77d1e1..3fbedff 100644 --- a/settings.h +++ b/settings.h @@ -10,17 +10,19 @@ */ #ifndef LCR_SETTING_RESOLUTION_X + /** Horizontal rendering resolution in pixels. */ #define LCR_SETTING_RESOLUTION_X 1024 #endif #ifndef LCR_SETTING_RESOLUTION_Y + /** Vertical rendering resolution in pixels. */ #define LCR_SETTING_RESOLUTION_Y 768 #endif #ifndef LCR_SETTING_RESOLUTION_SUBDIVIDE /** Subdivides the whole game resolution by this amount by making each pixel this number of times bigger. */ - #define LCR_SETTING_RESOLUTION_SUBDIVIDE 2 + #define LCR_SETTING_RESOLUTION_SUBDIVIDE 1 #endif #ifndef LCR_SETTING_FPS @@ -39,14 +41,6 @@ #define LCR_SETTING_FREE_CAMERA_TURN_SPEED 180 #endif -#ifndef LCR_SETTING_SKY_ROLL_MULTIPLIER_V - #define LCR_SETTING_SKY_ROLL_MULTIPLIER_V 8 -#endif - -#ifndef LCR_SETTING_SKY_ROLL_MULTIPLIER_H - #define LCR_SETTING_SKY_ROLL_MULTIPLIER_H 4 -#endif - #ifndef LCR_SETTING_MAX_MAP_VERTICES /** Maximum number of vertices for 3D rendering. Lower number will decrease RAM usage but will prevent larger maps from being loaded. */