Added onscreen errors
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@
|
||||
int gameLoop (Inputs *inputs, SDL_Renderer *renderer);
|
||||
void gameLoop_processMovement (Inputs *);
|
||||
void gameLoop_resetGame ();
|
||||
int screenshot ();
|
||||
void gameLoop_error (char *);
|
||||
|
||||
@@ -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 ----//
|
||||
|
||||
Reference in New Issue
Block a user