Add frontend helper
This commit is contained in:
parent
765c742f08
commit
716a3dda38
7 changed files with 105 additions and 173 deletions
|
@ -6,7 +6,6 @@
|
|||
#include <SDL2/SDL.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
|
||||
|
@ -21,6 +20,7 @@
|
|||
#endif
|
||||
|
||||
#include "game.h"
|
||||
#include "frontend_helper.h"
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
@ -37,57 +37,6 @@ uint16_t
|
|||
screen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y];
|
||||
|
||||
FILE *musicFile = 0;
|
||||
FILE *dataFile = 0;
|
||||
|
||||
char LCR_getNextDataFileChar(void)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
return 0;
|
||||
#else
|
||||
if (!dataFile)
|
||||
return 0;
|
||||
|
||||
int c = fgetc(dataFile);
|
||||
|
||||
if (c == EOF)
|
||||
{
|
||||
rewind(dataFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return c;
|
||||
#endif
|
||||
}
|
||||
|
||||
void LCR_appendDataStr(const char *str)
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (!dataFile)
|
||||
return;
|
||||
|
||||
if (str == 0 || *str == 0)
|
||||
rewind(dataFile);
|
||||
else
|
||||
{
|
||||
#if LCR_SETTING_LOG_LEVEL > 1
|
||||
printf("SDL: appending data \"%s\"\n",str);
|
||||
#endif
|
||||
|
||||
fclose(dataFile);
|
||||
|
||||
dataFile = fopen(DATA_FILE_NAME,"a");
|
||||
|
||||
if (dataFile)
|
||||
{
|
||||
fprintf(dataFile,"%s",str);
|
||||
fclose(dataFile);
|
||||
dataFile = fopen(DATA_FILE_NAME,"r");
|
||||
}
|
||||
}
|
||||
#else
|
||||
printf("%s",str);
|
||||
#endif
|
||||
}
|
||||
|
||||
void audioFillCallback(void *userdata, uint8_t *s, int l)
|
||||
{
|
||||
|
@ -153,11 +102,6 @@ void LCR_drawPixel(unsigned long index, uint16_t color)
|
|||
screen[index] = color;
|
||||
}
|
||||
|
||||
void LCR_log(const char *str)
|
||||
{
|
||||
printf("LOG: %s\n",str);
|
||||
}
|
||||
|
||||
void printHelp(void)
|
||||
{
|
||||
printf(
|
||||
|
@ -216,10 +160,8 @@ int main(int argc, char *argv[])
|
|||
#ifdef __EMSCRIPTEN__
|
||||
fullscreen = 0;
|
||||
#else
|
||||
dataFile = fopen(DATA_FILE_NAME,"r");
|
||||
|
||||
if (!dataFile)
|
||||
LCR_log("couldn't open data file");
|
||||
openDataFile();
|
||||
|
||||
musicFile = fopen("assets/music","rb");
|
||||
|
||||
|
@ -311,10 +253,7 @@ int main(int argc, char *argv[])
|
|||
if (musicFile)
|
||||
fclose(musicFile);
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (dataFile)
|
||||
fclose(dataFile);
|
||||
#endif
|
||||
closeDataFile();
|
||||
|
||||
SDL_PauseAudio(1);
|
||||
SDL_CloseAudio();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue