Skip to content

Commit

Permalink
API: GL fog setup for a map is now handled by the engine
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 12, 2014
1 parent f64dce8 commit c0aa215
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 55 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/include/gl/gl_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ void GL_SetVSync(dd_bool on);
*/
void GL_SetMultisample(dd_bool on);

/**
* Reconfigure GL fog according to the setup defined in the specified @a mapInfo definition.
*/
void GL_SetupFogFromMapInfo(de::Record const *mapInfo);

//void GL_BlendOp(int op);

dd_bool GL_NewList(DGLuint list, int mode);
Expand Down
59 changes: 42 additions & 17 deletions doomsday/client/src/gl/gl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <de/GLInfo>
#include <de/GLState>
#include <de/App>
#include <doomsday/filesys/fs_main.h>

D_CMD(Fog);
D_CMD(SetBPP);
Expand Down Expand Up @@ -582,6 +583,39 @@ void GL_ProjectionMatrix()
glLoadMatrixf(GL_GetProjectionMatrix().values());
}

void GL_SetupFogFromMapInfo(Record const *mapInfo)
{
if(!mapInfo || !(mapInfo->geti("flags") & MIF_FOG))
{
R_SetupFogDefaults();
}
else
{
float fogColor[3];
Vector3f(mapInfo->get("fogColor")).decompose(fogColor);
R_SetupFog(mapInfo->getf("fogStart"), mapInfo->getf("fogEnd"), mapInfo->getf("fogDensity"), fogColor);
}

if(mapInfo)
{
LumpIndex const &lumps = App_FileSystem().nameIndex();
int fadeTable = lumps.findLast(mapInfo->gets("fadeTable") + ".lmp");
if(fadeTable == lumps.findLast("COLORMAP.lmp"))
{
// We don't want fog in this case.
GL_UseFog(false);
}
else
{
// Probably fog ... don't use fullbright sprites.
if(fadeTable == lumps.findLast("FOGMAP.lmp"))
{
GL_UseFog(true);
}
}
}
}

#undef GL_UseFog
DENG_EXTERN_C void GL_UseFog(int yes)
{
Expand Down Expand Up @@ -642,28 +676,19 @@ void GL_TotalRestore()
UI_LoadFonts();
//Con_Resize();

/// @todo fixme: Should this use the default MapInfo def if none found? -ds
defn::MapInfo mapInfo;
// Restore the fog settings.
Record const *mapInfo = 0;
if(App_WorldSystem().hasMap())
{
if(MapDef *mapDef = App_WorldSystem().map().def())
Map &map = App_WorldSystem().map();
mapInfo = defs.mapInfos.tryFind("id", map.def()->composeUri());
if(!mapInfo)
{
int idx = defs.getMapInfoNum(mapDef->composeUri());
if(idx >= 0) mapInfo = defs.mapInfos[idx];
// Use the default def instead.
mapInfo = defs.mapInfos.tryFind("id", de::Uri("Maps", Path("*")));
}
}

// Restore map's fog settings.
if(!mapInfo || !(mapInfo.geti("flags") & MIF_FOG))
{
R_SetupFogDefaults();
}
else
{
Vector3f colorVec(mapInfo.get("fogColor"));
float color[] = { colorVec.x, colorVec.y, colorVec.z };
R_SetupFog(mapInfo.getf("fogStart"), mapInfo.getf("fogEnd"), mapInfo.getf("fogDensity"), color);
}
GL_SetupFogFromMapInfo(mapInfo);

#if _DEBUG
Z_CheckHeap();
Expand Down
4 changes: 4 additions & 0 deletions doomsday/client/src/world/worldsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
# include "Hand"
# include "HueCircle"

# include "gl/gl_main.h"

# include "Lumobj"
# include "render/viewports.h" // R_ResetViewer
# include "render/projector.h"
Expand Down Expand Up @@ -591,6 +593,8 @@ DENG2_PIMPL(WorldSystem)
#endif

#ifdef __CLIENT__
GL_SetupFogFromMapInfo(mapInfo.accessedRecordPtr());

map->initLightGrid();
map->initSkyFix();
map->buildMaterialLists();
Expand Down
38 changes: 0 additions & 38 deletions doomsday/plugins/common/src/p_mapsetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,42 +645,6 @@ static void spawnMapObjects()
P_SpawnPlayers();
}

static void initFog()
{
if(IS_DEDICATED) return;

Record const *mapInfo = COMMON_GAMESESSION->mapInfo();
if(!mapInfo || !(mapInfo->geti("flags") & MIF_FOG))
{
R_SetupFogDefaults();
}
else
{
Vector3f fogColor(mapInfo->get("fogColor"));
float fogColorV1[] = { fogColor.x, fogColor.y, fogColor.z };
R_SetupFog(mapInfo->getf("fogStart"), mapInfo->getf("fogEnd"), mapInfo->getf("fogDensity"), fogColorV1);
}

if(mapInfo)
{
int fadeTable = CentralLumpIndex().findLast(mapInfo->gets("fadeTable") + ".lmp");
if(fadeTable == CentralLumpIndex().findLast("COLORMAP.lmp"))
{
// We don't want fog in this case.
GL_UseFog(false);
}
else
{
// Probably fog ... don't use fullbright sprites
if(fadeTable == CentralLumpIndex().findLast("FOGMAP.lmp"))
{
// Tell the renderer to turn on the fog.
GL_UseFog(true);
}
}
}
}

void P_SetupMap(de::Uri const &mapUri)
{
if(IS_DEDICATED)
Expand Down Expand Up @@ -726,8 +690,6 @@ void P_SetupMap(de::Uri const &mapUri)
exit(1); // Unreachable.
}

initFog();

// Make sure the game is paused for the requested period.
Pause_MapStarted();

Expand Down

0 comments on commit c0aa215

Please sign in to comment.