- Ara gamestate_sequence llig les sequències en format text.

- Llevades totes les sequències en format binari.
This commit is contained in:
2023-10-13 12:15:13 +02:00
parent c905e5be1f
commit f9103548cf
9 changed files with 55 additions and 94 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -19,30 +19,9 @@ namespace gamestate
{ {
namespace sequence namespace sequence
{ {
int num_diapositives = 0; FILE *sequence_file = nullptr;
char *sequence_file = nullptr;
char *sfpointer = nullptr;
uint32_t wait_until = 0; uint32_t wait_until = 0;
uint8_t getByte()
{
return *(sequence_file++);
}
uint16_t getWord()
{
return getByte() + (getByte() << 8);
}
std::string getString()
{
uint8_t tamanyCadena = getByte();
char filename[256];
for (int i=0; i<tamanyCadena; i++) filename[i] = getByte();
filename[tamanyCadena] = '\0';
return std::string(filename);
}
void drawPic(std::string filename) void drawPic(std::string filename)
{ {
draw::surface *pic = draw::loadSurface(filename, true); draw::surface *pic = draw::loadSurface(filename, true);
@@ -82,13 +61,15 @@ namespace gamestate
{ {
if (!draw::isfading() && (input::anyKeyPressed() || input::mouseBtn(1))) { if (!draw::isfading() && (input::anyKeyPressed() || input::mouseBtn(1))) {
wait_until=0; wait_until=0;
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) num_diapositives=0; if (input::keyPressed(SDL_SCANCODE_ESCAPE)) fseek(sequence_file, 0, SEEK_END);
} else { } else {
draw::render(); draw::render();
return true; return true;
} }
} }
if (num_diapositives==0) { if (feof(sequence_file))
{
fclose(sequence_file);
const int fase = game::getConfig("fase"); const int fase = game::getConfig("fase");
if ( fase == -1 || fase == 30) { if ( fase == -1 || fase == 30) {
gamestate::menu::init(); gamestate::menu::init();
@@ -96,70 +77,52 @@ namespace gamestate
gamestate::prefase::init(); gamestate::prefase::init();
} }
free(sfpointer);
return true; return true;
}
const char tipo_diapositiva = *(sequence_file++); } else {
switch ( tipo_diapositiva )
char text[100];
int x, y, val;
int res = fscanf(sequence_file, "%s", text);
if (res==1)
{ {
case DIAPO_ESPERAR: std::string command(text);
{
const uint16_t time = getWord(); if (command=="ESPERAR") {
wait_until = SDL_GetTicks() + time; int res = fscanf(sequence_file, "%i", &val);
printf("- Esperar(%i)\n", time); wait_until = SDL_GetTicks() + val;
break;
} } else if (command=="FADEIN") {
case DIAPO_FADEIN: int res = fscanf(sequence_file, " '%[^']'", text);
{ drawPic(text);
std::string filename = getString();
drawPic(filename);
draw::fadein(); draw::fadein();
draw::render(); draw::render();
wait_until = SDL_GetTicks() + 500; wait_until = SDL_GetTicks() + 500;
printf("- FadeIn('%s')\n", filename.c_str());
break; } else if (command=="SHOW") {
} int res = fscanf(sequence_file, " '%[^']'", text);
case DIAPO_SHOW: drawPic(text);
{
std::string filename = getString();
drawPic(filename);
draw::render(); draw::render();
printf("- Show('%s')\n", filename.c_str());
break; } else if (command=="PRINT") {
} int res = fscanf(sequence_file, " %i %i %i '%[^']'", &x, &y, &val, text);
case DIAPO_PRINT: drawText(x, y, val, text);
{
const uint16_t x = getWord(); } else if (command=="PLAYMUSIC") {
const uint16_t y = getWord(); int res = fscanf(sequence_file, " '%[^']'", text);
const uint8_t col = getByte(); audio::playMusic(audio::loadMusic(text));
std::string text = getString();
drawText(x, y, col, text); } else if (command=="FADEOUT") {
printf("- Print(%i, %i, %i, '%s')\n", x, y, col, text.c_str());
break;
}
case DIAPO_MUSICA:
{
std::string filename = getString();
audio::playMusic(audio::loadMusic(filename));
printf("- PlayMusic('%s')\n", filename.c_str());
break;
}
case DIAPO_FADEOUT:
{
draw::fadeout(); draw::fadeout();
wait_until = SDL_GetTicks() + 500; wait_until = SDL_GetTicks() + 500;
printf("- FadeOut()\n");
break; } else if (command=="FADEOUTMUSIC") {
}
case DIAPO_FADEMUSIC:
draw::fadeout(); draw::fadeout();
audio::fadeoutMusic(); audio::fadeoutMusic();
wait_until = SDL_GetTicks() + 500; wait_until = SDL_GetTicks() + 500;
printf("- FadeOutMusic()\n");
break;
} }
num_diapositives--; }
}
return true; return true;
} }
@@ -171,20 +134,18 @@ namespace gamestate
switch (fase) switch (fase)
{ {
case -1: filename = "seqIN.seq"; break; case -1: filename = "seqIN.txt"; break;
case 0: filename = "seq00.seq"; break; case 0: filename = "seq00.txt"; break;
case 5: filename = "seq05.seq"; break; case 5: filename = "seq05.txt"; break;
case 10: filename = "seq10.seq"; break; case 10: filename = "seq10.txt"; break;
case 15: filename = "seq15.seq"; break; case 15: filename = "seq15.txt"; break;
case 20: filename = "seq20.seq"; break; case 20: filename = "seq20.txt"; break;
case 25: filename = "seq25.seq"; break; case 25: filename = "seq25.txt"; break;
case 30: filename = "seq30.seq"; break; case 30: filename = "seq30.txt"; break;
} }
int filesize; int filesize;
sequence_file = file::getFileBuffer(filename, filesize); sequence_file = file::getFilePointer(filename, filesize);
sfpointer = sequence_file;
num_diapositives = *(sequence_file++);
game::setState(&gamestate::sequence::loop); game::setState(&gamestate::sequence::loop);
} }