Skip to content

Commit

Permalink
libcommon|Refactor: Began commonizing G_DoWorldDone()
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 12, 2012
1 parent 7154658 commit e9b67ff
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 165 deletions.
11 changes: 11 additions & 0 deletions doomsday/plugins/common/include/p_actor.h
Expand Up @@ -29,8 +29,19 @@
#ifndef LIBCOMMON_P_ACTOR_H
#define LIBCOMMON_P_ACTOR_H

/**
* Removes the given mobj from the world.
*
* @param mo The mobj to be removed.
* @param noRespawn Disable the automatical respawn which occurs
* with mobjs of certain type(s) (also dependant on
* the current gamemode).
* Generally this should be @c false.
*/
void P_MobjRemove(mobj_t* mo, boolean noRespawn);

void P_RemoveAllPlayerMobjs(void);

void P_MobjUnsetOrigin(mobj_t* mo);
void P_MobjSetOrigin(mobj_t* mo);

Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/common/include/p_map.h
Expand Up @@ -72,6 +72,8 @@ boolean P_TryMoveXY(mobj_t* thing, coord_t x, coord_t y);

boolean P_TeleportMove(mobj_t* thing, coord_t x, coord_t y, boolean alwaysStomp);

void P_TelefragMobjsTouchingPlayers(void);

void P_SlideMove(mobj_t* mo);

void P_UseLines(player_t* player);
Expand Down
17 changes: 16 additions & 1 deletion doomsday/plugins/common/include/p_saveg.h
Expand Up @@ -143,7 +143,22 @@ boolean SV_LoadGame(int slot);

#if __JHEXEN__
void SV_HxInitBaseSlot(void);
void SV_HxMapTeleport(uint map, uint position);
void SV_HxSaveClusterMap(void);
void SV_HxLoadClusterMap(void);

typedef struct {
player_t player;
uint numInventoryItems[NUM_INVENTORYITEM_TYPES];
inventoryitemtype_t readyItem;
} playerbackup_t;

void SV_HxBackupPlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS]);

/**
* @param playerBackup Player state backup.
* @param entryPoint Logical identifier for the entry point used to enter the map.
*/
void SV_HxRestorePlayersInCluster(playerbackup_t playerBackup[MAXPLAYERS], uint entryPoint);
#endif

#if !__JHEXEN__
Expand Down
91 changes: 80 additions & 11 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -73,6 +73,7 @@
#include "x_hair.h"
#include "p_player.h"
#include "r_common.h"
#include "p_map.h"
#include "p_mapspec.h"
#include "p_start.h"
#include "p_inventory.h"
Expand Down Expand Up @@ -1291,12 +1292,13 @@ static void initFogForMap(ddmapinfo_t* mapInfo)
#endif
}

static int G_LoadMapWorker(void* params)
static int G_LoadMap(loadmap_params_t* p)
{
loadmap_params_t* p = (loadmap_params_t*) params;
boolean hasMapInfo = false;
ddmapinfo_t mapInfo;

DENG_ASSERT(p);

// Is MapInfo data available for this map?
{ ddstring_t* mapUriStr = Uri_Compose(p->mapUri);
if(mapUriStr)
Expand All @@ -1307,18 +1309,21 @@ static int G_LoadMapWorker(void* params)

P_SetupMap(p->mapUri, p->episode, p->map);
initFogForMap(hasMapInfo? &mapInfo : 0);

BusyMode_WorkerEnd();
/// @todo Fixme: Do not assume!
return 0; // Assume success.
}

void G_DoLoadMap(loadmap_params_t* p)
static int G_LoadMapWorker(void* params)
{
DENG_ASSERT(p);

G_LoadMapWorker(p);
loadmap_params_t* p = (loadmap_params_t*) params;
int result = G_LoadMap(p);
BusyMode_WorkerEnd();
return result;
}

void G_DoLoadMap(loadmap_params_t* p)
{
G_LoadMap(p);
// Wrap up, map loading is now complete.
G_SetGameAction(GA_NONE);
}
Expand All @@ -1334,7 +1339,6 @@ int G_DoLoadMapAndMaybeStartBriefing(void* parameters)
hasBrief = G_BriefingEnabled(p->episode, p->map, &fin);

G_LoadMapWorker(p);

// Wrap up, map loading is now complete.
G_SetGameAction(GA_NONE);

Expand Down Expand Up @@ -2482,11 +2486,76 @@ static int G_SaveStateWorker(void* parameters)
return result;
}

#if __JHEXEN__
static void mapTeleport(uint map, uint entryPoint)
{
playerbackup_t playerBackup[MAXPLAYERS];
boolean revisit;
boolean oldRandomClassParm;

/**
* First, determine whether we've been to this map previously and if so,
* whether we need to load the archived map state.
*/
revisit = SV_HxHaveMapSaveForSlot(BASE_SLOT, map+1);
if(deathmatch) revisit = false;

if(!deathmatch)
{
if(P_GetMapCluster(gameMap) == P_GetMapCluster(map))
{
// Same cluster; save current map.
SV_HxSaveClusterMap();
}
else
{
// Entering new cluster - clear base slot.
SV_ClearSlot(BASE_SLOT);
}
}

// Take a copy of the player objects (they will be cleared in the process
// of calling G_InitNew() and we need to restore them after).
SV_HxBackupPlayersInCluster(playerBackup);

// Disable class randomization (all players must spawn as their existing class).
oldRandomClassParm = randomClassParm;
randomClassParm = false;

// We don't want to see a briefing if we've already visited this map.
if(revisit) briefDisabled = true;

G_InitNew(gameSkill, gameEpisode, map);

if(revisit)
{
SV_HxLoadClusterMap();
}
else // First visit.
{
// Destroy all freshly spawned players.
P_RemoveAllPlayerMobjs();
}

SV_HxRestorePlayersInCluster(playerBackup, entryPoint);

// Restore the random class option.
randomClassParm = oldRandomClassParm;

// Launch waiting scripts.
if(!deathmatch)
{
P_CheckACSStore(gameMap);
}

rebornPosition = entryPoint;
}
#endif

void G_DoWorldDone(void)
{
#if __JHEXEN__
SV_HxMapTeleport(nextMap, nextMapEntryPoint);
rebornPosition = nextMapEntryPoint;
mapTeleport(nextMap, nextMapEntryPoint);
#else
loadmap_params_t p;
boolean hasBrief;
Expand Down
22 changes: 13 additions & 9 deletions doomsday/plugins/common/src/p_actor.c
Expand Up @@ -107,15 +107,6 @@ void P_SpawnTelefog(mobj_t* mo, void* context)
# endif
}

/**
* Removes the given mobj from the world.
*
* @param mo The mobj to be removed.
* @param noRespawn Disable the automatical respawn which occurs
* with mobjs of certain type(s) (also dependant on
* the current gamemode).
* Generally this should be @c false.
*/
void P_MobjRemove(mobj_t* mo, boolean noRespawn)
{
if(mo->ddFlags & DDMF_REMOTE) goto justDoIt;
Expand Down Expand Up @@ -157,6 +148,19 @@ void P_MobjRemove(mobj_t* mo, boolean noRespawn)
P_MobjDestroy(mo);
}

void P_RemoveAllPlayerMobjs(void)
{
uint i;
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
if(!ddplr->inGame) continue;

P_MobjRemove(ddplr->mo, true);
}
}

/**
* Called after a move to link the mobj back into the world.
*/
Expand Down
13 changes: 13 additions & 0 deletions doomsday/plugins/common/src/p_map.c
Expand Up @@ -350,6 +350,19 @@ boolean P_TeleportMove(mobj_t* thing, coord_t x, coord_t y, boolean alwaysStomp)
return true;
}

void P_TelefragMobjsTouchingPlayers(void)
{
uint i;
for(i = 0; i < MAXPLAYERS; ++i)
{
player_t* plr = players + i;
ddplayer_t* ddplr = plr->plr;
if(!ddplr->inGame) continue;

P_TeleportMove(ddplr->mo, ddplr->mo->origin[VX], ddplr->mo->origin[VY], true);
}
}

/**
* Checks to see if a start->end trajectory line crosses a blocking line.
* Returns false if it does.
Expand Down

0 comments on commit e9b67ff

Please sign in to comment.