Add frontend helper

This commit is contained in:
Miloslav Ciz 2025-06-01 19:59:09 +02:00
parent 765c742f08
commit 716a3dda38
7 changed files with 105 additions and 173 deletions

View file

@ -9,21 +9,16 @@
#include <stdint.h>
#include <stdio.h>
#define LCR_SETTING_LOG_LEVEL 2
#define DATA_FILE_NAME "data"
//#define LCR_LOADING_COMMAND SDL_PumpEvents();
// #define LCR_FPS_GET_MS SDL_GetTicks() // uncomment for FPS measuring
#include "game.h"
#include "frontend_helper.h"
#define WINDOW_SIZE (LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y)
sfUint32 windowPixels[WINDOW_SIZE * 2];
uint8_t fullscreen = 1;
FILE *musicFile = 0;
FILE *dataFile = 0;
sfClock *clock;
sfRenderWindow* window;
sfSoundStream *sound;
@ -33,36 +28,6 @@ sfSoundStream *sound;
int16_t audioBuffer[AUDIO_BUFFER_SIZE];
uint8_t musicBuffer[AUDIO_BUFFER_SIZE];
char LCR_getNextDataFileChar(void)
{
if (!dataFile)
return 0;
int c = fgetc(dataFile);
if (c == EOF)
{
rewind(dataFile);
return 0;
}
return c;
}
void LCR_appendDataStr(const char *str)
{
fclose(dataFile);
dataFile = fopen(DATA_FILE_NAME,"a");
if (dataFile)
{
fprintf(dataFile,"%s",str);
fclose(dataFile);
dataFile = fopen(DATA_FILE_NAME,"r");
}
}
uint8_t LCR_keyPressed(uint8_t key)
{
#define k(x) sfKeyboard_isKeyPressed(sfKey ## x)
@ -94,11 +59,6 @@ void LCR_drawPixel(unsigned long index, uint16_t color)
(((color << 19) | (color >> 8)) & 0x00f800f8) ;
}
void LCR_log(const char *str)
{
printf("LOG: %s\n",str);
}
void printHelp(void)
{
printf(
@ -147,10 +107,7 @@ int main(int argc, char *argv[])
default: break;
}
dataFile = fopen(DATA_FILE_NAME,"r");
if (!dataFile)
LCR_log("couldn't open data file");
openDataFile();
musicFile = fopen("assets/music","rb");
@ -211,8 +168,7 @@ int main(int argc, char *argv[])
if (musicFile)
fclose(musicFile);
if (dataFile)
fclose(dataFile);
closeDataFile();
sfSoundStream_stop(sound);
sfSoundStream_destroy(sound);