Skip to content

Commit

Permalink
Refactor|Client|Renderer|libdoomsday: Updated DED, MapInfo/Sky access…
Browse files Browse the repository at this point in the history
… (now Records)
  • Loading branch information
danij-deng committed Jul 27, 2014
1 parent 16e7b9b commit 2ced9df
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 102 deletions.
9 changes: 5 additions & 4 deletions doomsday/api/def_share.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file def_share.h
* Shared definition data structures and constants. @ingroup defs
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -119,9 +119,10 @@ typedef struct {
#define MIF_NO_INTERMISSION 0x4 ///< Skip any intermission between maps.
///@}

/// @todo Directly access the engine's DED database instead -ds
typedef struct {
char* name;
char* author;
AutoStr *name;
AutoStr *author;
int music;
int flags; ///< MIF_* flags.
float ambient;
Expand Down
6 changes: 4 additions & 2 deletions doomsday/client/include/de_defs.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2009-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -27,7 +27,9 @@
#include "def_share.h"
#include "def_main.h"
#include <doomsday/defs/ded.h>
#include <doomsday/defs/mapinfo.h>
#include <doomsday/defs/model.h>
#include <doomsday/defs/sky.h>
#include <doomsday/defs/dedfile.h>
#include <doomsday/defs/dedparser.h>

Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/src/dd_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @todo Much of this should be refactored and merged into the App classes.
* @todo The rest should be split into smaller, perhaps domain-specific files.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006-2007 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
Expand Down Expand Up @@ -2480,9 +2480,10 @@ int DD_GetInteger(int ddvalue)
if(MapDef *mapDef = App_WorldSystem().map().def())
{
de::Uri const mapUri = mapDef->composeUri();
if(ded_mapinfo_t *mapInfo = defs.getMapInfoNum(&mapUri))
int idx = defs.getMapInfoNum(&mapUri);
if(idx >= 0)
{
return Def_GetMusicNum(mapInfo->music);
return Def_GetMusicNum(defs.mapInfos[idx].gets("music").toUtf8().constData());
}
}
}
Expand Down
92 changes: 48 additions & 44 deletions doomsday/client/src/def_main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file def_main.cpp Definitions Subsystem.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @par License
Expand Down Expand Up @@ -44,6 +44,7 @@

#include <doomsday/defs/dedfile.h>
#include <doomsday/defs/dedparser.h>
#include <doomsday/defs/sky.h>
#include <de/App>
#include <de/NativePath>
#include <QTextStream>
Expand Down Expand Up @@ -273,6 +274,7 @@ ded_value_t* Def_GetValueByUri(struct uri_s const *_uri)
return defs.getValueByUri(*reinterpret_cast<de::Uri const *>(_uri));
}

#if 0
ded_mapinfo_t* Def_GetMapInfo(struct uri_s const *_uri)
{
return defs.getMapInfoNum(reinterpret_cast<de::Uri const *>(_uri));
Expand All @@ -282,6 +284,7 @@ ded_sky_t* Def_GetSky(char const* id)
{
return defs.getSky(id);
}
#endif

ded_compositefont_t* Def_GetCompositeFont(const char* uri)
{
Expand Down Expand Up @@ -1540,17 +1543,19 @@ void Def_Read()
}

// Map infos.
for(int i = 0; i < defs.mapInfo.size(); ++i)
for(int i = 0; i < defs.mapInfos.size(); ++i)
{
ded_mapinfo_t *mi = &defs.mapInfo[i];
Record &mi = defs.mapInfos[i];

/**
* Historically, the map info flags field was used for sky flags,
* here we copy those flags to the embedded sky definition for
* backward-compatibility.
*/
if(mi->flags & MIF_DRAW_SPHERE)
mi->sky.flags |= SIF_DRAW_SPHERE;
if(mi.geti("flags") & MIF_DRAW_SPHERE)
{
mi.set("sky.flags", mi.geti("sky.flags") | SIF_DRAW_SPHERE);
}
}

// Log a summary of the definition database.
Expand Down Expand Up @@ -1931,10 +1936,8 @@ void Def_CopySectorType(sectortype_t* s, ded_sectortype_t* def)
LOOPi(2) s->ceilInterval[i] = def->ceilInterval[i];
}

int Def_Get(int type, const char* id, void* out)
int Def_Get(int type, char const *id, void *out)
{
int i;

switch(type)
{
case DD_DEF_MOBJ:
Expand All @@ -1958,12 +1961,12 @@ int Def_Get(int type, const char* id, void* out)
case DD_DEF_SOUND_BY_NAME:
return defs.getSoundNumForName(id);

case DD_DEF_SOUND_LUMPNAME:
i = *((long*) id);
case DD_DEF_SOUND_LUMPNAME: {
int i = *((long *) id);
if(i < 0 || i >= runtimeDefs.sounds.size())
return false;
strcpy((char*)out, runtimeDefs.sounds[i].lumpName);
return true;
return true; }

case DD_DEF_MUSIC:
return Def_GetMusicNum(id);
Expand All @@ -1976,32 +1979,34 @@ int Def_Get(int type, const char* id, void* out)
return false;

case DD_DEF_MAP_INFO: {
ddmapinfo_t *mout;
struct uri_s *mapUri = Uri_NewWithPath2(id, RC_NULL);
ded_mapinfo_t *map = Def_GetMapInfo(mapUri);

Uri_Delete(mapUri);
if(!map) return false;

mout = (ddmapinfo_t *) out;
mout->name = map->name;
mout->author = map->author;
mout->music = Def_GetMusicNum(map->music);
mout->flags = map->flags;
mout->ambient = map->ambient;
mout->gravity = map->gravity;
mout->parTime = map->parTime;
mout->fogStart = map->fogStart;
mout->fogEnd = map->fogEnd;
mout->fogDensity = map->fogDensity;
memcpy(mout->fogColor, map->fogColor, sizeof(mout->fogColor));
de::Uri mapUri(id, RC_NULL);
int idx = defs.getMapInfoNum(&mapUri);
if(idx < 0) return false;

Record const &mapInfo = defs.mapInfos[idx];
ddmapinfo_t *mout = (ddmapinfo_t *) out;
mout->name = AutoStr_FromTextStd(mapInfo.gets("title").toUtf8().constData());
mout->author = AutoStr_FromTextStd(mapInfo.gets("author").toUtf8().constData());
mout->music = Def_GetMusicNum(mapInfo.gets("music").toUtf8().constData());
mout->flags = mapInfo.geti("flags");
mout->ambient = mapInfo.getf("ambient");
mout->gravity = mapInfo.getf("gravity");
mout->parTime = mapInfo.getf("parTime");
mout->fogStart = mapInfo.getf("fogStart");
mout->fogEnd = mapInfo.getf("fogEnd");
mout->fogDensity = mapInfo.getf("fogDensity");

Vector3f fogColor(mapInfo.get("fogColor"));
mout->fogColor[0] = fogColor.x;
mout->fogColor[1] = fogColor.y;
mout->fogColor[2] = fogColor.z;
return true; }

case DD_DEF_TEXT:
if(id && id[0])
{
// Read backwards to allow patching.
for(i = defs.text.size() - 1; i >= 0; i--)
for(int i = defs.text.size() - 1; i >= 0; i--)
{
if(stricmp(defs.text[i].id, id)) continue;
if(out) *(char**) out = defs.text[i].text;
Expand Down Expand Up @@ -2035,8 +2040,8 @@ int Def_Get(int type, const char* id, void* out)
return false; }

case DD_DEF_FINALE: { // Find InFine script by ID.
finalescript_t* fin = (finalescript_t*) out;
for(i = defs.finales.size() - 1; i >= 0; i--)
finalescript_t *fin = (finalescript_t *) out;
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(stricmp(defs.finales[i].id, id)) continue;

Expand All @@ -2053,7 +2058,7 @@ int Def_Get(int type, const char* id, void* out)
case DD_DEF_FINALE_BEFORE: {
finalescript_t *fin = (finalescript_t *) out;
de::Uri *uri = new de::Uri(id, RC_NULL);
for(i = defs.finales.size() - 1; i >= 0; i--)
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(!defs.finales[i].before || *defs.finales[i].before != *uri) continue;

Expand All @@ -2072,7 +2077,7 @@ int Def_Get(int type, const char* id, void* out)
case DD_DEF_FINALE_AFTER: {
finalescript_t *fin = (finalescript_t *) out;
de::Uri *uri = new de::Uri(id, RC_NULL);
for(i = defs.finales.size() - 1; i >= 0; i--)
for(int i = defs.finales.size() - 1; i >= 0; i--)
{
if(!defs.finales[i].after || *defs.finales[i].after != *uri) continue;

Expand All @@ -2090,26 +2095,25 @@ int Def_Get(int type, const char* id, void* out)

case DD_DEF_LINE_TYPE: {
int typeId = strtol(id, (char **)NULL, 10);
for(i = defs.lineTypes.size() - 1; i >= 0; i--)
for(int i = defs.lineTypes.size() - 1; i >= 0; i--)
{
if(defs.lineTypes[i].id != typeId) continue;
if(out) Def_CopyLineType((linetype_t*)out, &defs.lineTypes[i]);
return true;
}
return false;
}
return false; }

case DD_DEF_SECTOR_TYPE: {
int typeId = strtol(id, (char **)NULL, 10);
for(i = defs.sectorTypes.size() - 1; i >= 0; i--)
for(int i = defs.sectorTypes.size() - 1; i >= 0; i--)
{
if(defs.sectorTypes[i].id != typeId) continue;
if(out) Def_CopySectorType((sectortype_t*)out, &defs.sectorTypes[i]);
return true;
}
return false;
}
default:
return false;
return false; }

default: return false;
}
}

Expand Down
17 changes: 10 additions & 7 deletions doomsday/client/src/gl/gl_main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @file gl_main.cpp GL-Graphics Subsystem
* @ingroup gl
*
* @authors Copyright &copy; 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright &copy; 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
* @authors Copyright © 2003-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2014 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2006 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -643,24 +643,27 @@ void GL_TotalRestore()
//Con_Resize();

/// @todo fixme: Should this use the default MapInfo def if none found? -ds
ded_mapinfo_t *mapInfo = 0;
defn::MapInfo mapInfo;
if(App_WorldSystem().hasMap())
{
if(MapDef *mapDef = App_WorldSystem().map().def())
{
de::Uri const mapUri = mapDef->composeUri();
mapInfo = defs.getMapInfoNum(&mapUri);
int idx = defs.getMapInfoNum(&mapUri);
if(idx >= 0) mapInfo = &defs.mapInfos[idx];
}
}

// Restore map's fog settings.
if(!mapInfo || !(mapInfo->flags & MIF_FOG))
if(!mapInfo || !(mapInfo.geti("flags") & MIF_FOG))
{
R_SetupFogDefaults();
}
else
{
R_SetupFog(mapInfo->fogStart, mapInfo->fogEnd, mapInfo->fogDensity, mapInfo->fogColor);
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);
}

#if _DEBUG
Expand Down
Loading

0 comments on commit 2ced9df

Please sign in to comment.