From c0f5e5cf5bb6bbcb24600e543b28a3d9f5c2daed Mon Sep 17 00:00:00 2001 From: Miloslav Ciz Date: Mon, 20 Jan 2025 21:33:05 +0100 Subject: [PATCH] Start user file --- assets.h | 17 ++++++----------- frontend_sdl.c | 43 +++++++++++++++++++++++++++++++++++++++++-- game.h | 20 ++++++++++++-------- general.h | 6 ++++-- map.h | 6 ++++-- racing.h | 9 ++++++--- renderer.h | 7 +++++-- settings.h | 8 +++++--- 8 files changed, 83 insertions(+), 33 deletions(-) diff --git a/assets.h b/assets.h index ca41aaf..849d032 100644 --- a/assets.h +++ b/assets.h @@ -1,8 +1,12 @@ #ifndef _LCR_ASSETS_H #define _LCR_ASSETS_H -/** - Assets embedded in source code. +/* + Licar: assets + + This file holds assets, resources and other bigger pieces of data that will be + compiled right into the executable. This is so that for a minimal version of + the game a filesystem is not needed. NOTES: - All images are 64x64, stored in an indexed mode (8bits pery pixel), the @@ -84,16 +88,7 @@ static const char *LCR_internalDataFile = ":-k5k0 :f5120" " map end " - "#Mmap2;4321 1 :*H1k0J :,s0s0 :fd190 " "#Rrep1;testmap;482f70f9 00000188:00c1:0089:0111:00b9:0091:0109:0028:0050:00c1:0093:0030:00d1:0069:0041:0020:0071:0013:0012:0023:0022:0050:0032:0020:0022:0060:0024:00bc:0044" - "#Mmap3;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap4;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap5;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap6;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap7;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap8;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap9;4321 1 :*H1k0J :,s0s0 :fd190 " - "#Mmap10;4321 1 :*H1k0J :,s0s0 :fd190 " ; #define LCR_IMAGE_SIZE 64 ///< one-dimension resolution of bitmap image diff --git a/frontend_sdl.c b/frontend_sdl.c index d4fa1ef..96c1af5 100644 --- a/frontend_sdl.c +++ b/frontend_sdl.c @@ -3,6 +3,8 @@ #define LCR_SETTING_LOG_LEVEL 2 +#define DATA_FILE_NAME "data" + #include "game.h" SDL_Window *window; @@ -12,15 +14,44 @@ SDL_Surface *screenSurface; uint16_t screen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y]; FILE *musicFile = 0; +FILE *dataFile = 0; char LCR_getNextDataFileChar(void) { - return 0; + if (!dataFile) + return 0; + + int c = fgetc(dataFile); + + if (c == EOF) + { + rewind(dataFile); + return 0; + } + + return c; } void LCR_appendDataStr(const char *str) { - return; + if (!dataFile) + return; + + if (*str == 0) + rewind(dataFile); + else + { + fclose(dataFile); + + dataFile = fopen(DATA_FILE_NAME,"a"); + + if (dataFile) + { + fprintf(dataFile,"%s",str); + fclose(dataFile); + dataFile = fopen(DATA_FILE_NAME,"r"); + } + } } void audioFillCallback(void *userdata, uint8_t *s, int l) @@ -87,6 +118,11 @@ int main(int argc, char *argv[]) { uint8_t running = 1; + dataFile = fopen(DATA_FILE_NAME,"r"); + + if (!dataFile) + LCR_log("couldn't open data file"); + LCR_log("initializing game"); LCR_gameInit(); @@ -171,6 +207,9 @@ int main(int argc, char *argv[]) if (musicFile) fclose(musicFile); + if (dataFile) + fclose(dataFile); + SDL_PauseAudio(1); SDL_CloseAudio(); diff --git a/game.h b/game.h index 4b4e557..1508f31 100644 --- a/game.h +++ b/game.h @@ -1,15 +1,19 @@ #ifndef _LCR_GAME_H #define _LCR_GAME_H -/** - game: this file implements the backend of a complete, actually playable - game, and is meant to be included and used by specific frontends (which - will handle each platform's hardware details and I/O). +/* + Licar: game module - TODO: more documentation + This file implements the backend of a complete, actually playable game with + graphics, sound etc., and is meant to be included and used by specific + frontends (which will handle each platform's hardware details and I/O). See + the frontend info below for help with porting the game to a new platform. + + The code uses LCR_ (or _LCR) prefix as a kind of namespace preventing + collision with 3rd party identifiers. UNITS: There are various kinds of units used to ensure independence of the - game modules. Here is a summary: + modules. Here is a summary: - LCR_GameUnit: data type, abstract unit of the game (racing module). One map square is LCR_GAME_UNITs long, a full angle is also LCR_GAME_UNITs. @@ -27,7 +31,7 @@ their coordinate system (X right, Y up, Z forward) and rotations (Euler angles, by Z, then by X, then Y). - RESOURCE FILE: The game uses so called data file to store various resources, + DATA FILE: The game uses so called data file to store various resources, mainly maps and replays. There is considered to be one abstract global file which is just a long text string. Internally the global file is composed of a hardcoded internal data file string (stored in assets) with very basic maps, @@ -54,7 +58,7 @@ #define LCR_KEYS_TOTAL 6 /* - FOR FRONTENDS: + FOR FRONTENDS (porting to other platforms): - Implement the below described functions according to their description. - Implement the main program and game loop. - Call the below described functions as described. diff --git a/general.h b/general.h index 29b2391..1e70a90 100644 --- a/general.h +++ b/general.h @@ -1,8 +1,10 @@ #ifndef _LCR_GENERAL_H #define _LCR_GENERAL_H -/** - General resources for all modules. +/* + Licar: general + + This file holds general definitions used by all modules. */ #include diff --git a/map.h b/map.h index 148fde1..d6e4ea4 100644 --- a/map.h +++ b/map.h @@ -1,8 +1,10 @@ #ifndef _LCR_MAP #define _LCR_MAP -/** - The map (track) module for Licar. +/* + Licar: map module + + This implements maps (i.e. tracks, levels, ...). Map coordinates/size: - map size is 64x64x64 blocks diff --git a/racing.h b/racing.h index f7325e5..05e97ce 100644 --- a/racing.h +++ b/racing.h @@ -1,9 +1,12 @@ #ifndef _LCR_RACING_H #define _LCR_RACING_H -/** - Racing module: implements the racing physics and logic as well as replays and - other related things. +/* + Licar: racing module + + This implements the racing physics and logic as well as replays and other + related things. It's possible to use this module alone if one wants to + implement a program that doesn't need graphics, I/O etc. Some comments: - Replays are internally stored as follows: the replay consists of 16 bit diff --git a/renderer.h b/renderer.h index eb7574c..c619ccb 100644 --- a/renderer.h +++ b/renderer.h @@ -1,8 +1,11 @@ #ifndef _LCR_RENDERER_H #define _LCR_RENDERER_H -/** - Renderer: implements 3D and 2D rendering. +/* + Licar: renderer module + + This implements 3D and 2D rendering. It should be possible to replace this + module with another one to get let's say a GPU accelerated OpenGL renderer. Some comments: diff --git a/settings.h b/settings.h index 56c6d57..daf2272 100644 --- a/settings.h +++ b/settings.h @@ -1,9 +1,11 @@ #ifndef _LCR_SETTINGS_H #define _LCR_SETTINGS_H -/** - Settings file, values here may be changed by the user or overriden by frontend - before compilation. +/* + Licar: settings + + Compile times settings file for all modules, values here may be changed by the + user or overriden by frontend before compilation. */ #ifndef LCR_SETTING_RESOLUTION_X