Added onscreen errors

This commit is contained in:
Sasha Koshka
2022-04-30 16:49:54 -04:00
parent 87d0bab604
commit 875637627e
3 changed files with 18 additions and 7 deletions

View File

@@ -30,7 +30,6 @@ int
* 6: World editing (renaming etc)
* 7: Join game
* 8: Options
* 9: Error
*/
gameState = 0,
@@ -52,6 +51,7 @@ int
float fov = 90;
char *errorMessage = NULL;
char usernameBuffer[8] = "guest";
InputBuffer username = {
.buffer = usernameBuffer,
@@ -64,6 +64,8 @@ static SDL_Rect backgroundRect;
Player player = { 0 };
Coords playerMovement = { 0.0, 0.0, 0.0 };
int screenshot ();
/* gameLoop_resetGame
* Resets elements of the game such as time and the player position. This will
* also reset the world.
@@ -132,6 +134,15 @@ int gameLoop (
static IntCoords blockRayPosition = { 0 };
static Chunk *chunk;
// If there is an error, show it and stop
if (errorMessage) {
if (state_err(renderer, inputs, errorMessage)) {
errorMessage = NULL;
// TODO: add capability to recover from error:
return 1;
}
}
switch (gameState) {
// A main menu
@@ -784,3 +795,7 @@ int screenshot (SDL_Renderer *renderer) {
return 1;
}
}
void gameLoop_error (char *message) {
errorMessage = message;
}

View File

@@ -8,4 +8,4 @@
int gameLoop (Inputs *inputs, SDL_Renderer *renderer);
void gameLoop_processMovement (Inputs *);
void gameLoop_resetGame ();
int screenshot ();
void gameLoop_error (char *);

View File

@@ -64,11 +64,7 @@ int main (/*int argc, char *argv[]*/) {
//--- initializing modules ---//
int dataInitFailed = data_init();
if (dataInitFailed) {
printf (
"cannot initialize data module, code %i\n",
dataInitFailed);
// TODO: display onscreen error before doing this
return 1;
gameLoop_error("cannot initialize data module");
}
//---- generating assets ----//