Allow to exit Game when a connection drops
This commit is contained in:
parent
4a4f1ecb0e
commit
265a322535
6 changed files with 96 additions and 11 deletions
|
@ -10,6 +10,11 @@
|
|||
#include "SaveLoad.h"
|
||||
#include "Network.h"
|
||||
|
||||
#define STALL_TIME 120
|
||||
|
||||
int stallCounter;
|
||||
bool stallAreYouSure;
|
||||
|
||||
//generates stairs up and creates compass data
|
||||
void generatePass2() {
|
||||
int level, x, y;
|
||||
|
@ -120,6 +125,8 @@ void startGame(bool load, char *filename) {
|
|||
for(int i=0; i<playerCount; i++) {
|
||||
initMiniMap(players+i);
|
||||
}
|
||||
|
||||
stallCounter = 0;
|
||||
}
|
||||
|
||||
void syncedTick() {
|
||||
|
@ -194,7 +201,7 @@ void syncedTick() {
|
|||
|
||||
//for every active level
|
||||
for(level = 0; level < 6; level++) {
|
||||
if(level==5 && !dungeonActive()) return;
|
||||
if(level==5 && !dungeonActive()) continue;
|
||||
|
||||
bool hasPlayer = false;
|
||||
for(i=0; i<playerCount; i++) {
|
||||
|
@ -224,10 +231,47 @@ void syncedTick() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
stallCounter = 0;
|
||||
}
|
||||
|
||||
void tickGame() {
|
||||
synchronizerTick(&syncedTick);
|
||||
|
||||
|
||||
if(synchronizerIsRunning()) {
|
||||
stallCounter++;
|
||||
//game stalled -> most likely a player disconnected -> present option to exit game
|
||||
if(stallCounter>=STALL_TIME) {
|
||||
if(stallCounter==STALL_TIME) stallAreYouSure = false;
|
||||
|
||||
//scan local inputs, because synchronizer only updates them when not stalled
|
||||
hidScanInput();
|
||||
tickKeys(&localInputs, hidKeysHeld(), hidKeysDown());
|
||||
|
||||
if (localInputs.k_accept.clicked) {
|
||||
if(stallAreYouSure) {
|
||||
//create backup save
|
||||
if(playerLocalID==0) {
|
||||
char backupSaveFileName[256+32];
|
||||
backupSaveFileName[0] = '\0';
|
||||
|
||||
strncat(backupSaveFileName, currentFileName, strlen(currentFileName)-4);
|
||||
strcat(backupSaveFileName, ".exit.msv");
|
||||
|
||||
saveWorld(backupSaveFileName, &eManager, &worldData, players, playerCount);
|
||||
}
|
||||
|
||||
exitGame();
|
||||
} else {
|
||||
stallAreYouSure = true;
|
||||
}
|
||||
}
|
||||
if (localInputs.k_decline.clicked) {
|
||||
stallAreYouSure = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//for rendering -> move to a better place
|
||||
|
@ -278,6 +322,36 @@ void renderGame() {
|
|||
ingameMenuRender(getLocalPlayer(), getLocalPlayer()->ingameMenu);
|
||||
}
|
||||
|
||||
//game stalled -> most likely a player disconnected -> present option to exit game
|
||||
if(stallCounter>STALL_TIME) {
|
||||
renderFrame(1,1,24,14,0xFF1010AF);
|
||||
drawText("Waiting for a long time", (400 - (23 * 12))/2, 32);
|
||||
|
||||
char text[50];
|
||||
sprintf(text, "Last response %is ago", stallCounter/60);
|
||||
drawText(text, (400 - (strlen(text) * 12))/2, 64);
|
||||
|
||||
if(playerLocalID==0) {
|
||||
drawText("Press to leave the game", (400 - (25 * 12))/2, 160);
|
||||
renderButtonIcon(localInputs.k_accept.input & -localInputs.k_accept.input, 120, 157, 1);
|
||||
|
||||
drawText("A backup save will be created", (400 - (29 * 12))/2, 192);
|
||||
} else {
|
||||
drawText("Press to leave the game", (400 - (25 * 12))/2, 192);
|
||||
renderButtonIcon(localInputs.k_accept.input & -localInputs.k_accept.input, 120, 189, 1);
|
||||
}
|
||||
|
||||
if(stallAreYouSure){
|
||||
renderFrame(6,5,19,10,0xFF10108F);
|
||||
|
||||
drawText("Are you sure?",122,96);
|
||||
drawText(" Yes", 164, 117);
|
||||
renderButtonIcon(localInputs.k_accept.input & -localInputs.k_accept.input, 166, 114, 1);
|
||||
drawText(" No", 170, 133);
|
||||
renderButtonIcon(localInputs.k_decline.input & -localInputs.k_decline.input, 166, 130, 1);
|
||||
}
|
||||
}
|
||||
|
||||
sf2d_end_frame();
|
||||
|
||||
sf2d_start_frame(GFX_BOTTOM, GFX_LEFT);
|
||||
|
@ -290,3 +364,13 @@ void renderGame() {
|
|||
sf2d_end_frame();
|
||||
}
|
||||
|
||||
void exitGame() {
|
||||
networkDisconnect();
|
||||
synchronizerReset();
|
||||
|
||||
sf2d_set_clear_color(0xFF);
|
||||
currentSelection = 0;
|
||||
currentMenu = MENU_TITLE;
|
||||
|
||||
playMusic(&music_menu);
|
||||
}
|
||||
|
|
|
@ -5,3 +5,5 @@
|
|||
void startGame(bool load, char *filename);
|
||||
void tickGame();
|
||||
void renderGame();
|
||||
|
||||
void exitGame();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "Globals.h"
|
||||
#include "Menu.h"
|
||||
#include "Ingame.h"
|
||||
#include "Player.h"
|
||||
#include "SaveLoad.h"
|
||||
#include "Synchronizer.h"
|
||||
|
@ -47,14 +48,7 @@ void ingameMenuTick(PlayerData *pd, int menu) {
|
|||
pd->ingameMenuAreYouSure = false;
|
||||
pd->ingameMenuAreYouSureSave = false;
|
||||
|
||||
networkDisconnect();
|
||||
synchronizerReset();
|
||||
|
||||
sf2d_set_clear_color(0xFF);
|
||||
currentSelection = 0;
|
||||
currentMenu = MENU_TITLE;
|
||||
|
||||
playMusic(&music_menu);
|
||||
exitGame();
|
||||
} else if (pd->inputs.k_decline.clicked){
|
||||
pd->ingameMenuAreYouSure = false;
|
||||
pd->ingameMenuAreYouSureSave = false;
|
||||
|
|
|
@ -1166,7 +1166,7 @@ void renderMenu(int menu,int xscr,int yscr){
|
|||
memset(text, 0, (50+8+1) * sizeof(char));
|
||||
networkGetNodeName(j, text);
|
||||
|
||||
drawText(text,(400-(strlen(text)*12))/2,i*32+32);
|
||||
drawText(text,(400-(strlen(text)*12))/2,i*26+32);
|
||||
|
||||
free(text);
|
||||
lastj = j;
|
||||
|
@ -1234,7 +1234,7 @@ void renderMenu(int menu,int xscr,int yscr){
|
|||
memset(text, 0, (50+8+1) * sizeof(char));
|
||||
networkGetNodeName(j, text);
|
||||
|
||||
drawText(text,(400-(strlen(text)*12))/2,i*32+32);
|
||||
drawText(text,(400-(strlen(text)*12))/2,i*26+32);
|
||||
|
||||
free(text);
|
||||
lastj = j;
|
||||
|
|
|
@ -217,6 +217,10 @@ void synchronizerReset() {
|
|||
synchronizerCurrentTicks = 0;
|
||||
}
|
||||
|
||||
bool synchronizerIsRunning() {
|
||||
return synchronizerRunning;
|
||||
}
|
||||
|
||||
// helpers for random numbers
|
||||
#define PI 3.141592654
|
||||
double gaussrand(bool reset)
|
||||
|
|
|
@ -12,6 +12,7 @@ void synchronizerSetPlayerUID(int playerID, u32 uid);
|
|||
void synchronizerSendIfReady();
|
||||
void synchronizerSetPlayerReady(int playerID);
|
||||
bool synchronizerAllReady();
|
||||
bool synchronizerIsRunning();
|
||||
|
||||
void synchronizerStart();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue