Skip to content

Commit

Permalink
Refactor: Moved logic for updating world state following engine reset…
Browse files Browse the repository at this point in the history
… to World

Also improved Map apidocs.
  • Loading branch information
danij-deng committed Jun 15, 2013
1 parent 03817b9 commit b364bf6
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 124 deletions.
48 changes: 30 additions & 18 deletions doomsday/client/include/world/map.h
Expand Up @@ -136,23 +136,31 @@ class Map
int _ambientLightLevel; // Ambient lightlevel for the current map.

public:
/**
* Construct a new map initially configured in an editable state. Whilst
* editable new map elements can be added, thereby allowing the map to be
* constructed dynamically. When done editing @ref endEditing() should be
* called to switch the map into a non-editable (i.e., playable) state.
*
* @param uri Universal resource identifier to attribute to the map. For
* example, @code "E1M1" @endcode. Note that the scheme is
* presently ignored (unused).
*/
Map(Uri const &uri = Uri());
~Map();

/**
* To be called to register the cvars and ccmds for this module.
* To be called to register the commands and variables of this module.
*/
static void consoleRegister();

/**
* To be called Initializes the dummy element arrays used with the DMU API,
* with a fixed number of @em shared dummies.
* To be called to initialize the dummy element arrays (which are used with
* the DMU API), with a fixed number of @em shared dummies.
*/
static void initDummies();

/**
* This ID is the name of the lump tag that marks the beginning of map
* data, e.g. "MAP03" or "E2M8".
* Returns the universal resource identifier (URI) attributed to the map.
*/
Uri const &uri() const;

Expand Down Expand Up @@ -249,34 +257,38 @@ class Map
inline int bspLeafCount() const { return bspLeafs().count(); }

/**
* Helper function for returning the relevant line side index for @a lineIndex
* and @a backSide.
* Helper function which returns the relevant side index given a @a lineIndex
* and @a side identifier.
*
* Indices are produced as follows:
* @code
* lineIndex / 2 + (backSide? 1 : 0);
* @endcode
*
* @param lineIndex Index of the Line in the map.
* @param backSide If @c =0 the Line::Front else Line::Back
* @param lineIndex Index of the line in the map.
* @param side Side of the line. @c =0 the Line::Front else Line::Back
*
* @return Unique index for the line side.
* @return Unique index for the identified side.
*/
static int toSideIndex(int lineIndex, int backSide);
static int toSideIndex(int lineIndex, int side);

/**
* Returns a pointer to the Line::Side associated with the specified @a index;
* otherwise @c 0.
* Locate a Line::Side in the map by it's unique @a index.
*
* @param index Unique index attributed to the line side.
*
* @return Pointer to the identified Line::Side instance; otherwise @c 0.
*
* @see toSideIndex()
*/
Line::Side *sideByIndex(int index) const;

/**
* Locate a polyobj in the map by unique in-map tag.
* Locate a Polyobj in the map by it's unique in-map tag.
*
* @param tag Tag associated with the polyobj to be located.
* @return Pointer to the referenced polyobj instance; otherwise @c 0.
*
* @return Pointer to the identified Polyobj instance; otherwise @c 0.
*/
Polyobj *polyobjByTag(int tag) const;

Expand Down Expand Up @@ -312,12 +324,12 @@ class Map

/**
* Determine the BSP leaf on the back side of the BS partition that lies
* in front of the specified point within the map's coordinate space.
* in front of the specified point within the map's coordinate space.
*
* @note Always returns a valid BspLeaf although the point may not actually
* lay within it (however it is on the same side of the space partition)!
*
* @param point XY coordinates of the point to test.
* @param point Map space coordinates to determine the BSP leaf for.
*
* @return BspLeaf instance for that BSP node's leaf.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/world/world.h
Expand Up @@ -78,9 +78,9 @@ class World
void clearMap();

/**
* Reset the map cache removing all existing records.
* To be called following an engine reset to update the world state.
*/
void resetMapCache();
void update();

private:
DENG2_PRIVATE(d)
Expand Down
97 changes: 3 additions & 94 deletions doomsday/client/src/render/r_main.cpp
Expand Up @@ -507,82 +507,6 @@ void R_Init()
frameCount = 0;
}

static void R_UpdateMap()
{
if(!App_World().hasMap()) return;
Map &map = App_World().map();

#ifdef __CLIENT__
// Update all world surfaces.
foreach(Sector *sector, map.sectors())
foreach(Plane *plane, sector->planes())
{
plane->surface().markAsNeedingDecorationUpdate();
}

foreach(Line *line, map.lines())
for(int i = 0; i < 2; ++i)
{
Line::Side &side = line->side(i);
if(!side.hasSections()) continue;

side.top().markAsNeedingDecorationUpdate();
side.middle().markAsNeedingDecorationUpdate();
side.bottom().markAsNeedingDecorationUpdate();
}

/// @todo Is this even necessary?
foreach(Polyobj *polyobj, map.polyobjs())
foreach(Line *line, polyobj->lines())
{
line->front().middle().markAsNeedingDecorationUpdate();
}

map.buildSurfaceLists();

#endif

// See what mapinfo says about this map.
de::Uri mapUri = map.uri();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&mapUri));
if(!mapInfo)
{
// Use the default def instead.
de::Uri defaultDefUri = de::Uri(RC_NULL, "*");
mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&defaultDefUri));
}

// Reconfigure the sky
ded_sky_t *skyDef = 0;
if(mapInfo)
{
skyDef = Def_GetSky(mapInfo->skyID);
if(!skyDef) skyDef = &mapInfo->sky;
}
#ifdef __CLIENT__
Sky_Configure(skyDef);
#endif

if(mapInfo)
{
map._globalGravity = mapInfo->gravity;
map._ambientLightLevel = mapInfo->ambient * 255;
}
else
{
// No theMap info found, so set some basic stuff.
map._globalGravity = 1.0f;
map._ambientLightLevel = 0;
}

map._effectiveGravity = map._globalGravity;

#ifdef __CLIENT__
// Recalculate the light range mod matrix.
Rend_UpdateLightModMatrix();
#endif
}

void R_Update()
{
// Reset file IDs so previously seen files can be processed again.
Expand All @@ -597,33 +521,18 @@ void R_Update()
R_UpdateTranslationTables();

Def_PostInit();
#ifdef __CLIENT__
P_UpdateParticleGens(); // Defs might've changed.
#endif

// Reset the archived map cache (the available maps may have changed).
App_World().resetMapCache();

for(uint i = 0; i < DDMAXPLAYERS; ++i)
{
player_t *plr = &ddPlayers[i];
ddplayer_t *ddpl = &plr->shared;
// States have changed, the states are unknown.
ddpl->pSprites[0].statePtr = ddpl->pSprites[1].statePtr = NULL;
}

R_UpdateMap();
App_World().update();

#ifdef __CLIENT__
// The rendering lists have persistent data that has changed during
// the re-initialization.
RL_DeleteLists();

// Update the secondary title and the game status.
//Rend_ConsoleUpdateTitle();
/// @todo fixme: Update the game title and the status.
#endif

#if _DEBUG
#ifdef DENG_DEBUG
Z_CheckHeap();
#endif
}
Expand Down
14 changes: 5 additions & 9 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -198,7 +198,11 @@ DENG2_PIMPL(Map)
qDeleteAll(lines);
qDeleteAll(vertexes);

/// @todo fixme: mobjNodes/lineNodes/lineLinks - free them!
/// @todo fixme: Free all memory we have ownership of.
// Client only data:
// mobjHash/activePlanes/activePolyobjs
// End client only data.
// mobjNodes/lineNodes/lineLinks
}

/**
Expand Down Expand Up @@ -931,14 +935,6 @@ Map::Map(Uri const &uri) : d(new Instance(this, uri))
_ambientLightLevel = 0;
}

/// @todo fixme: Free all memory we have ownership of.
Map::~Map()
{
// Client only data:
// mobjHash/activePlanes/activePolyobjs - free them!
// End client only data.
}

void Map::consoleRegister() // static
{
C_VAR_INT("bsp-factor", &bspSplitFactor, CVF_NO_MAX, 0, 0);
Expand Down
89 changes: 88 additions & 1 deletion doomsday/client/src/world/world.cpp
Expand Up @@ -703,9 +703,96 @@ void World::clearMap()
delete d->map; d->map = 0;
}

void World::resetMapCache()
void World::update()
{
#ifdef __CLIENT__
P_UpdateParticleGens(); // Defs might've changed.
#endif

// Reset the archived map cache (the available maps may have changed).
d->records.clear();

for(uint i = 0; i < DDMAXPLAYERS; ++i)
{
player_t *plr = &ddPlayers[i];
ddplayer_t *ddpl = &plr->shared;
// States have changed, the states are unknown.
ddpl->pSprites[0].statePtr = ddpl->pSprites[1].statePtr = NULL;
}

if(d->map)
{
#ifdef __CLIENT__

// Update all world surfaces.
foreach(Sector *sector, d->map->sectors())
foreach(Plane *plane, sector->planes())
{
plane->surface().markAsNeedingDecorationUpdate();
}

foreach(Line *line, d->map->lines())
for(int i = 0; i < 2; ++i)
{
Line::Side &side = line->side(i);
if(!side.hasSections()) continue;

side.top().markAsNeedingDecorationUpdate();
side.middle().markAsNeedingDecorationUpdate();
side.bottom().markAsNeedingDecorationUpdate();
}

/// @todo Is this even necessary?
foreach(Polyobj *polyobj, d->map->polyobjs())
foreach(Line *line, polyobj->lines())
{
line->front().middle().markAsNeedingDecorationUpdate();
}

d->map->buildSurfaceLists();

#endif // __CLIENT__

// See what mapinfo says about this map.
Uri mapUri = d->map->uri();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&mapUri));
if(!mapInfo)
{
// Use the default def instead.
Uri defaultDefUri = de::Uri(RC_NULL, "*");
mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&defaultDefUri));
}

// Reconfigure the sky
ded_sky_t *skyDef = 0;
if(mapInfo)
{
skyDef = Def_GetSky(mapInfo->skyID);
if(!skyDef) skyDef = &mapInfo->sky;
}
#ifdef __CLIENT__
Sky_Configure(skyDef);
#endif

if(mapInfo)
{
d->map->_globalGravity = mapInfo->gravity;
d->map->_ambientLightLevel = mapInfo->ambient * 255;
}
else
{
// No map info found -- apply defaults.
d->map->_globalGravity = 1.0f;
d->map->_ambientLightLevel = 0;
}

d->map->_effectiveGravity = d->map->_globalGravity;

#ifdef __CLIENT__
// Recalculate the light range mod matrix.
Rend_UpdateLightModMatrix();
#endif
}
}

} // namespace de

0 comments on commit b364bf6

Please sign in to comment.