Skip to content

Commit

Permalink
Began unravelling R_SetupLevel now that map load is handled engine-si…
Browse files Browse the repository at this point in the history
…de there is no need to use setup flags internally.

Fixed issue with HOMs appearing after loading a saved game.
  • Loading branch information
danij committed Sep 2, 2006
1 parent 6cbd348 commit d80917e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 78 deletions.
14 changes: 3 additions & 11 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -732,17 +732,9 @@ extern "C" {
} ddvertexf_t;

// SetupLevel flags.
#define DDSLF_POLYGONIZE 0x1 // Create sector floor/ceiling triangles.
#define DDSLF_DONT_CLIP 0x2 /* Don't clip sector polys: use subsectors
as they are (use with DDSLF_POLYGONIZE). */
#define DDSLF_FIX_SKY 0x4 // Fix walls between sky-ceiling sectors.
#define DDSLF_REVERB 0x8 // Calculate sector reverbs.
#define DDSLF_NO_SERVER 0x10 // Do not initialize server.
#define DDSLF_SERVER_ONLY 0x20 // Server init only, nothing else.
#define DDSLF_AFTER_LOADING 0x40 // After loading a savegame...
#define DDSLF_INIT_LINKS 0x80 // Init linelinks.
#define DDSLF_FINALIZE 0x100 // After everything else is done.
#define DDSLF_INITIALIZE 0x200 // Before anything else if done.
#define DDSLF_AFTER_LOADING 0x1 // After loading a savegame...
#define DDSLF_FINALIZE 0x2 // After everything else is done.
#define DDSLF_INITIALIZE 0x4 // Before anything else if done.

enum // Sector reverb data indices.
{
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/p_arch.h
Expand Up @@ -104,5 +104,6 @@ typedef struct mapdatalumpinfo_s {
} mapdatalumpinfo_t;

void P_InitMapDataFormats(void);
boolean P_LoadMapData(char *levelId);
boolean P_LoadMapData(char *levelId);
boolean P_GLNodeDataPresent(void);
#endif
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/r_world.h
Expand Up @@ -35,6 +35,7 @@ const char *R_GetUniqueLevelID(void);
const byte *R_GetSectorLightColor(sector_t *sector);
boolean R_IsSkySurface(surface_t *surface);
void R_SetupLevel(char *level_id, int flags);
void R_InitLinks(void);
void R_SetupFog(void);
void R_SetupSky(void);
void R_SetSectorLinks(sector_t *sec);
Expand Down
25 changes: 10 additions & 15 deletions doomsday/engine/portable/src/p_arch.c
Expand Up @@ -1278,6 +1278,14 @@ boolean P_GetMapFormat(void)
}
}

/**
* Return <code>true</code> if gl node data is present for the CURRENT map.
*/
boolean P_GLNodeDataPresent(void)
{
return glNodeData;
}

/*
* Do any final initialization of map data members.
*
Expand Down Expand Up @@ -1398,7 +1406,6 @@ static void SetCurrentMap(gamemap_t* map)
*/
boolean P_LoadMapData(char *levelId)
{
int setupflags = DDSLF_POLYGONIZE | DDSLF_FIX_SKY | DDSLF_REVERB;
int lumpNumbers[2];
gamemap_t* newmap;

Expand Down Expand Up @@ -1500,26 +1507,14 @@ boolean P_LoadMapData(char *levelId)
M_Free(newmap);

// Must be called before any mobjs are spawned.
Con_Message("Init links\n");
R_SetupLevel(levelId, DDSLF_INIT_LINKS);

// DJS - TODO:
// This needs to be sorted out. R_SetupLevel should be called from the
// engine but in order to move it there we need to decide how polyobject
// init/setup is going to be handled.
R_InitLinks();

// It's imperative that this is called!
// - dlBlockLinks initialized
// - necessary GL data generated
// - sky fix
// - map info setup

// Server can't be initialized before PO_Init is done, but PO_Init
// can't be done until SetupLevel is called...
if(glNodeData)
setupflags |= DDSLF_DONT_CLIP;

R_SetupLevel(levelId, setupflags | DDSLF_NO_SERVER);
R_SetupLevel(levelId, 0);

return true;
}
Expand Down
97 changes: 54 additions & 43 deletions doomsday/engine/portable/src/r_world.c
Expand Up @@ -1907,6 +1907,25 @@ void R_InitLineNeighbors(void)
#endif
}

void R_InitLinks(void)
{
int i;

Con_Message("R_InitLinks: Initializing\n");

// Init polyobj blockmap.
P_InitPolyBlockMap();

// Initialize node piles and line rings.
NP_Init(&thingnodes, 256); // Allocate a small pile.
NP_Init(&linenodes, numlines + 1000);

// Allocate the rings.
linelinks = Z_Malloc(sizeof(*linelinks) * numlines, PU_LEVEL, 0);
for(i = 0; i < numlines; i++)
linelinks[i] = NP_New(&linenodes, NP_ROOT_NODE);
}

/*
* This routine is called from the Game to polygonize the current
* level. Creates floors and ceilings and fixes the adjacent sky
Expand All @@ -1931,35 +1950,35 @@ void R_SetupLevel(char *level_id, int flags)
Con_StartupInit();
return;
}

// First check for some special tasks.
if(flags & DDSLF_INIT_LINKS)
{
// Init polyobj blockmap.
P_InitPolyBlockMap();

// Initialize node piles and line rings.
NP_Init(&thingnodes, 256); // Allocate a small pile.
NP_Init(&linenodes, numlines + 1000);

// Allocate the rings.
linelinks = Z_Malloc(sizeof(*linelinks) * numlines, PU_LEVEL, 0);
for(i = 0; i < numlines; i++)
linelinks[i] = NP_New(&linenodes, NP_ROOT_NODE);
return; // Do nothing else.
}
if(flags & DDSLF_SERVER_ONLY)
{
// Only init server data.
Sv_InitPools();
return;
}
if(flags & DDSLF_AFTER_LOADING)
{
side_t *side;
sideinfo_t *sinfo;

// Loading a game usually destroys all thinkers. Until a proper
// savegame system handled by the engine is introduced we'll have
// to resort to re-initializing the most important stuff.
P_SpawnTypeParticleGens();

// Update everything again. Its possible that after loading we
// now have more HOMs to fix, etc..

R_SkyFix(true, true); // fix floors and ceilings.

// Update all sectors. Set intial values of various tracked
// and interpolated properties (lighting, smoothed planes etc).
for(i = 0; i < numsectors; ++i)
R_UpdateSector(SECTOR_PTR(i), false);

// Do the same for side surfaces.
for(i = 0; i < numsides; ++i)
{
side = SIDE_PTR(i);
sinfo = SIDE_INFO(side);
R_UpdateSurface(&side->top, &sinfo->oldtop, false);
R_UpdateSurface(&side->middle, &sinfo->oldmiddle, false);
R_UpdateSurface(&side->bottom, &sinfo->oldbottom, false);
}
return;
}
if(flags & DDSLF_FINALIZE)
Expand All @@ -1970,6 +1989,9 @@ void R_SetupLevel(char *level_id, int flags)
if(loadInStartupMode)
Con_StartupDone();

// Init server data.
Sv_InitPools();

// Recalculate the light range mod matrix.
Rend_CalcLightRangeModMatrix(NULL);

Expand Down Expand Up @@ -2057,13 +2079,11 @@ void R_SetupLevel(char *level_id, int flags)
Con_Progress(10, 0);

// Polygonize.
if(flags & DDSLF_POLYGONIZE)
{
if(flags & DDSLF_DONT_CLIP)
R_PolygonizeWithoutCarving();
else
R_CreateFloorsAndCeilings(numnodes - 1, 0, NULL);
}
if(P_GLNodeDataPresent())
R_PolygonizeWithoutCarving();
else
R_CreateFloorsAndCeilings(numnodes - 1, 0, NULL);

Con_Progress(10, 0);

// Init Particle Generator links.
Expand Down Expand Up @@ -2094,13 +2114,10 @@ void R_SetupLevel(char *level_id, int flags)

Con_Progress(10, 0);

if(flags & DDSLF_FIX_SKY)
{
R_InitSkyFix();
R_SkyFix(true, true); // fix floors and ceilings.
}
if(flags & DDSLF_REVERB)
S_CalcSectorReverbs();
R_InitSkyFix();
R_SkyFix(true, true); // fix floors and ceilings.

S_CalcSectorReverbs();

DL_InitLinks();

Expand Down Expand Up @@ -2149,12 +2166,6 @@ void R_SetupLevel(char *level_id, int flags)
// Texture animations should begin from their first step.
R_ResetAnimGroups();

// Do network init: Initialize Delta Pools.
if(!(flags & DDSLF_NO_SERVER))
{
Sv_InitPools();
}

// Tell shadow bias to initialize the bias light sources.
SB_InitForLevel(R_GetUniqueLevelID());

Expand Down
8 changes: 1 addition & 7 deletions doomsday/plugins/common/src/p_mapsetup.c
Expand Up @@ -315,17 +315,11 @@ void P_SetupLevel(int episode, int map, int playermask, skill_t skill)
// FIXME: Custom map data format support
PO_Init(W_GetNumForName(levelId) + 1 /*ML_THINGS*/); // Initialize the polyobjs

// Now we can init the server.
Con_Message("Init server\n");
R_SetupLevel(levelId, DDSLF_SERVER_ONLY);

Con_Message("Load ACS scripts\n");
// FIXME: Custom map data format support
P_LoadACScripts(W_GetNumForName(levelId) + 11 /*ML_BEHAVIOR*/); // ACS object code
#else
// Now we can init the server.
R_SetupLevel(levelId, DDSLF_SERVER_ONLY);
#endif

P_DealPlayerStarts(0);
P_SpawnPlayers();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/p_saveg.c
Expand Up @@ -2610,7 +2610,7 @@ int SV_LoadGame(char *filename)
// In netgames, the server tells the clients about this.
NetSv_LoadGame(hdr.gameid);

// Spawn particle generators.
// Spawn particle generators, fix HOMS etc, etc...
R_SetupLevel("", DDSLF_AFTER_LOADING);
return true;
}
Expand Down

0 comments on commit d80917e

Please sign in to comment.