Skip to content

Commit

Permalink
Refactor: Moved logic for updating map state following engine reset t…
Browse files Browse the repository at this point in the history
…o Map
  • Loading branch information
danij-deng committed Jun 17, 2013
1 parent 00b2daf commit 3384e2d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 82 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/include/world/map.h
Expand Up @@ -657,6 +657,11 @@ class Map

#endif // __CLIENT__

/**
* To be called following an engine reset to update the map state.
*/
void update();

public: /// @todo Make private:

/**
Expand Down
75 changes: 75 additions & 0 deletions doomsday/client/src/world/map.cpp
Expand Up @@ -32,6 +32,7 @@
#include "de_platform.h"
#include "de_base.h"
#include "de_console.h" // Con_GetInteger
#include "de_defs.h"
#include "m_nodepile.h"

#include "BspLeaf"
Expand All @@ -56,6 +57,9 @@
#include "world/world.h"

#include "render/r_main.h" // validCount
#ifdef __CLIENT__
# include "render/sky.h"
#endif

#include "world/map.h"

Expand Down Expand Up @@ -2478,6 +2482,77 @@ void Map::updateMissingMaterialsForLinesOfSector(Sector const &sec)

#endif // __CLIENT__

void Map::update()
{
#ifdef __CLIENT__
// Update all surfaces.
foreach(Sector *sector, d->sectors)
foreach(Plane *plane, sector->planes())
{
plane->surface().markAsNeedingDecorationUpdate();
}

foreach(Line *line, d->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->polyobjs)
foreach(Line *line, polyobj->lines())
{
line->front().middle().markAsNeedingDecorationUpdate();
}

// Rebuild the surface lists.
buildSurfaceLists();

#endif // __CLIENT__

// Reapply values defined in MapInfo (they may have changed).
ded_mapinfo_t *mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&d->uri));
if(!mapInfo)
{
// Use the default def instead.
Uri defaultDefUri(RC_NULL, "*");
mapInfo = Def_GetMapInfo(reinterpret_cast<uri_s *>(&defaultDefUri));
}

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

_effectiveGravity = _globalGravity;

#ifdef __CLIENT__
// Reconfigure the sky.
/// @todo Sky needs breaking up into multiple components. There should be
/// a representation on server side and a logical entity which the renderer
/// visualizes. We also need multiple concurrent skies for BOOM support.
ded_sky_t *skyDef = 0;
if(mapInfo)
{
skyDef = Def_GetSky(mapInfo->skyID);
if(!skyDef) skyDef = &mapInfo->sky;
}
Sky_Configure(skyDef);
#endif
}

/// Runtime map editing -----------------------------------------------------

/// Used when sorting vertex line owners.
Expand Down
100 changes: 18 additions & 82 deletions doomsday/client/src/world/world.cpp
Expand Up @@ -351,41 +351,40 @@ DENG2_PIMPL(World)
<< TABBED("BSP Leafs", map->bspLeafCount())
<< TABBED("Segments", map->segmentCount());

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

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

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

map->_effectiveGravity = map->_globalGravity;

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

// Init the thinker lists (public and private).
map->thinkers().initLists(0x1 | 0x2);

Expand Down Expand Up @@ -516,7 +515,7 @@ DENG2_PIMPL(World)

// Run the special map setup command, which the user may alias to do
// something useful.
String cmd = "init-" + mapUri.resolved();
String cmd = "init-" + map->uri().resolved();
if(Con_IsValidCommand(cmd.toUtf8().constData()))
{
Con_Executef(CMDS_SCRIPT, false, "%s", cmd.toUtf8().constData());
Expand Down Expand Up @@ -645,73 +644,10 @@ void World::update()
ddpl->pSprites[0].statePtr = ddpl->pSprites[1].statePtr = 0;
}

// Update the current map too.
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;
d->map->update();
}
}

Expand Down

0 comments on commit 3384e2d

Please sign in to comment.