Skip to content

Commit

Permalink
Network|Client|libcommon: Reset game side local world state when leav…
Browse files Browse the repository at this point in the history
…ing a server
  • Loading branch information
danij-deng committed Apr 13, 2014
1 parent 2592791 commit ec4fc37
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
6 changes: 6 additions & 0 deletions doomsday/plugins/common/include/p_mapsetup.h
Expand Up @@ -46,6 +46,12 @@ void P_FinalizeMapChange(Uri const *uri);
*/
void P_SetupMap(Uri const *uri);

/**
* To be called to reset the local world state (e.g., when leaving a networked game).
* Note that @ref P_SetupMap() calls this automatically when the current map changes.
*/
void P_ResetWorldState();

/**
* @param mapUri Identifier of the map to lookup the author of. Can be @c 0 in which
* case the author for the @em current map will be returned (if set).
Expand Down
13 changes: 9 additions & 4 deletions doomsday/plugins/common/src/d_net.cpp
Expand Up @@ -25,6 +25,7 @@
#include "gamesession.h"
#include "player.h"
#include "hu_menu.h"
#include "p_mapsetup.h"
#include "p_start.h"
#include "fi_lib.h"

Expand Down Expand Up @@ -182,21 +183,25 @@ int D_NetConnect(int before)

int D_NetDisconnect(int before)
{
if(before) return true;
if(before)
{
// Free PU_MAP, Zone-allocated storage for the local world state.
P_ResetWorldState();
return true;
}

D_NetClearBuffer();

// Start demo.
COMMON_GAMESESSION->endAndBeginTitle();

// Restore normal game state.
GameRuleset newRules(COMMON_GAMESESSION->rules());
/*GameRuleset newRules(COMMON_GAMESESSION->rules());
newRules.deathmatch = false;
newRules.noMonsters = false;
#if __JHEXEN__
newRules.randomClasses = false;
#endif
COMMON_GAMESESSION->applyNewRules(newRules);
COMMON_GAMESESSION->applyNewRules(newRules);*/

return true;
}
Expand Down
29 changes: 12 additions & 17 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Expand Up @@ -46,8 +46,6 @@
# define TOLIGHTIDX(c) (!((c) >> 8)? 0 : ((c) - 0x100) + 1)
#endif

static void P_ResetWorldState(void);

// Our private map data structures
xsector_t *xsectors;
xline_t *xlines;
Expand Down Expand Up @@ -706,9 +704,19 @@ void P_SetupMap(Uri const *mapUri)
// It begins...
mapSetup = true;

::timerGame = 0;
if(COMMON_GAMESESSION->rules().deathmatch)
{
int parm = CommandLine_Check("-timer");
if(parm && parm < CommandLine_Count() - 1)
{
::timerGame = atoi(CommandLine_At(parm + 1)) * 35 * 60;
}
}

P_ResetWorldState();

// Initialize The Logical Sound Manager.
// Initialize the logical sound manager.
S_MapChange();

AutoStr *mapUriStr = Uri_Compose(mapUri);
Expand Down Expand Up @@ -1013,10 +1021,7 @@ void P_FinalizeMapChange(Uri const *uri)
#endif
}

/**
* Called during map setup when beginning to load a new map.
*/
static void P_ResetWorldState()
void P_ResetWorldState()
{
#if __JHEXEN__
static int firstFragReset = 1;
Expand Down Expand Up @@ -1054,16 +1059,6 @@ static void P_ResetWorldState()
#endif
}

timerGame = 0;
if(COMMON_GAMESESSION->rules().deathmatch)
{
int parm = CommandLine_Check("-timer");
if(parm && parm < CommandLine_Count() - 1)
{
timerGame = atoi(CommandLine_At(parm + 1)) * 35 * 60;
}
}

for(int i = 0; i < MAXPLAYERS; ++i)
{
player_t *plr = &players[i];
Expand Down

0 comments on commit ec4fc37

Please sign in to comment.