Skip to content

Commit

Permalink
Refactor: Moved DED database and sprite building to libdoomsday
Browse files Browse the repository at this point in the history
Instead of the global variable `defs`, the definitions are now
available via the `DED_Definitions()` function.
  • Loading branch information
skyjake committed Jul 28, 2016
1 parent 6ac789d commit 7996a3f
Show file tree
Hide file tree
Showing 26 changed files with 514 additions and 476 deletions.
1 change: 0 additions & 1 deletion doomsday/apps/client/include/def_main.h
Expand Up @@ -78,7 +78,6 @@ struct Array : public std::vector<PODType>
PODType *_elements;
};

extern ded_t defs; ///< Main definitions database (internal).
struct xgclass_s; ///< @note The actual classes are on game side.

struct sfxinfo_t
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/render/rend_main.h
Expand Up @@ -47,7 +47,7 @@ class Subsector;
#define IS_MUL (dynlightBlend != 1 && !fogParams.usingFog)

#define MTEX_DETAILS_ENABLED (r_detail && useMultiTexDetails && \
defs.details.size() > 0)
DED_Definitions()->details.size() > 0)
#define IS_MTEX_DETAILS (MTEX_DETAILS_ENABLED && numTexUnits > 1)
#define IS_MTEX_LIGHTS (!IS_MTEX_DETAILS && !fogParams.usingFog && useMultiTexLights \
&& numTexUnits > 1 && envModAdd)
Expand Down
1 change: 0 additions & 1 deletion doomsday/apps/client/include/resource/clientresources.h
Expand Up @@ -452,7 +452,6 @@ class ClientResources : public Resources
public: /// @todo Should be private:
void initTextures();
void initSystemTextures();
void initSprites();
#ifdef __CLIENT__
void initModels();
#endif
Expand Down
20 changes: 10 additions & 10 deletions doomsday/apps/client/src/audio/base/system.cpp
Expand Up @@ -1944,7 +1944,7 @@ dint System::stopSoundWithLowerPriority(dint id, mobj_t *emitter, dint defPriori
// Check the priority.
if(defPriority >= 0)
{
dint oldPrio = ::defs.sounds[sbuf.sample->id].priority;
dint oldPrio = DED_Definitions()->sounds[sbuf.sample->id].priority;
if(oldPrio < defPriority) // Old is more important.
{
stopCount = -1;
Expand Down Expand Up @@ -2015,18 +2015,18 @@ dint System::playSound(sfxsample_t *sample, dfloat volume, dfloat freq, mobj_t *
bool const play3D = sfx3D && (emitter || fixedOrigin);

LOG_AS("audio::System");
if(sample->id < 1 || sample->id >= ::defs.sounds.size()) return false;
if(sample->id < 1 || sample->id >= DED_Definitions()->sounds.size()) return false;
if(volume <= 0 || !sample->size) return false;

if(emitter && sfxOneSoundPerEmitter)
{
// Stop any other sounds from the same emitter.
if(stopSoundWithLowerPriority(0, emitter, ::defs.sounds[sample->id].priority) < 0)
if(stopSoundWithLowerPriority(0, emitter, DED_Definitions()->sounds[sample->id].priority) < 0)
{
// Something with a higher priority is playing, can't start now.
LOG_AUDIO_MSG("Not playing soundId:%i (prio:%i) because overridden (emitter id:%i)")
<< sample->id
<< ::defs.sounds[sample->id].priority
<< DED_Definitions()->sounds[sample->id].priority
<< emitter->thinker.id;
return false;
}
Expand Down Expand Up @@ -2428,7 +2428,7 @@ D_CMD(PlaySound)
dint p = 0;

// The sound ID is always first.
dint const id = ::defs.getSoundNum(argv[1]);
dint const id = DED_Definitions()->getSoundNum(argv[1]);

// The second argument may be a volume.
dfloat volume = 1;
Expand Down Expand Up @@ -2490,7 +2490,7 @@ D_CMD(PlayMusic)
if(argc == 2)
{
// Play a file associated with the referenced music definition.
if(Record const *definition = ::defs.musics.tryFind("id", argv[1]))
if(Record const *definition = DED_Definitions()->musics.tryFind("id", argv[1]))
{
return Mus_Start(*definition, looped);
}
Expand Down Expand Up @@ -2663,9 +2663,9 @@ dint S_StartMusicNum(dint musicId, dd_bool looped)
#ifdef __CLIENT__
if(::isDedicated) return true;

if(musicId >= 0 && musicId < ::defs.musics.size())
if(musicId >= 0 && musicId < DED_Definitions()->musics.size())
{
Record const &def = ::defs.musics[musicId];
Record const &def = DED_Definitions()->musics[musicId];
return Mus_Start(def, looped);
}
return false;
Expand All @@ -2678,7 +2678,7 @@ dint S_StartMusicNum(dint musicId, dd_bool looped)
#undef S_StartMusic
dint S_StartMusic(char const *musicId, dd_bool looped)
{
dint idx = ::defs.getMusicNum(musicId);
dint idx = DED_Definitions()->getMusicNum(musicId);
if(idx < 0)
{
if(musicId && !String(musicId).isEmpty())
Expand Down Expand Up @@ -2712,7 +2712,7 @@ dint S_LocalSoundAtVolumeFrom(dint soundIdAndFlags, mobj_t *origin, coord_t *poi
return false;

dint const soundId = (soundIdAndFlags & ~DDSF_FLAG_MASK);
if(soundId <= 0 || soundId >= ::defs.sounds.size())
if(soundId <= 0 || soundId >= DED_Definitions()->sounds.size())
return false;

// Skip if sounds won't be heard.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/audio/s_environ.cpp
Expand Up @@ -51,9 +51,9 @@ AudioEnvironmentId S_AudioEnvironmentId(de::Uri const *uri)
{
if(uri)
{
for(dint i = 0; i < ::defs.textureEnv.size(); ++i)
for(dint i = 0; i < DED_Definitions()->textureEnv.size(); ++i)
{
ded_tenviron_t const *env = &::defs.textureEnv[i];
ded_tenviron_t const *env = &DED_Definitions()->textureEnv[i];
for(dint k = 0; k < env->materials.size(); ++k)
{
de::Uri *ref = env->materials[k].uri;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/audio/sfxchannel.cpp
Expand Up @@ -520,7 +520,7 @@ void Sfx_ChannelDrawer()
(sbuf.flags & SFXBF_REPEAT ) ? 'R' : '.',
(sbuf.flags & SFXBF_RELOAD ) ? 'L' : '.',
sbuf.sample ? sbuf.sample->id : 0,
sbuf.sample ? ::defs.sounds[sbuf.sample->id].id : "",
sbuf.sample ? DED_Definitions()->sounds[sbuf.sample->id].id : "",
sbuf.sample ? sbuf.sample->size : 0,
sbuf.bytes, sbuf.rate / 1000, sbuf.length,
sbuf.cursor, sbuf.written);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/client/cl_sound.cpp
Expand Up @@ -240,7 +240,7 @@ void Cl_Sound()
}

// Is the ID valid?
if (sound < 1 || sound >= ::defs.sounds.size())
if (sound < 1 || sound >= DED_Definitions()->sounds.size())
{
LOGDEV_NET_WARNING("Invalid sound ID %i") << sound;
return;
Expand Down
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/client/cl_world.cpp
Expand Up @@ -89,7 +89,7 @@ void Cl_ReadServerMobjTypeIDs()
// Translate the type IDs to local.
for (dint i = 0; i < StringArray_Size(ar); ++i)
{
xlatMobjType[i] = ::defs.getMobjNum(StringArray_At(ar, i));
xlatMobjType[i] = DED_Definitions()->getMobjNum(StringArray_At(ar, i));
if (xlatMobjType[i] < 0)
{
LOG_NET_WARNING("Could not find '%s' in local thing definitions")
Expand All @@ -114,7 +114,7 @@ void Cl_ReadServerMobjStateIDs()
// Translate the type IDs to local.
for (dint i = 0; i < StringArray_Size(ar); ++i)
{
xlatMobjState[i] = ::defs.getStateNum(StringArray_At(ar, i));
xlatMobjState[i] = DED_Definitions()->getStateNum(StringArray_At(ar, i));
if (xlatMobjState[i] < 0)
{
LOG_NET_WARNING("Could not find '%s' in local state definitions")
Expand Down
19 changes: 10 additions & 9 deletions doomsday/apps/client/src/dd_main.cpp
Expand Up @@ -65,7 +65,8 @@
#include <doomsday/filesys/virtualmappings.h>
#include <doomsday/resource/databundle.h>
#include <doomsday/resource/manifest.h>
#include <doomsday/resource/mapmanifests.h>
#include <doomsday/res/MapManifests>
#include <doomsday/res/Sprites>
#include <doomsday/res/Textures>
#include <doomsday/world/Materials>
#include <doomsday/help.h>
Expand Down Expand Up @@ -785,7 +786,7 @@ int DD_ActivateGameWorker(void *context)
Con_SetProgress(130);
}

resSys.initSprites(); // Fully initialize sprites.
resSys.sprites().initSprites(); // Fully initialize sprites.
#ifdef __CLIENT__
resSys.initModels();
#endif
Expand Down Expand Up @@ -1155,7 +1156,7 @@ static void initialize()

Def_Read();

App_ResourceSystem().initSprites();
App_ResourceSystem().sprites().initSprites();
#ifdef __CLIENT__
App_ResourceSystem().initModels();
#endif
Expand Down Expand Up @@ -1378,7 +1379,7 @@ static dint DD_UpdateEngineStateWorker(void *context)
//
// Rebuild resource data models (defs might've changed).
//
App_ResourceSystem().initSprites();
App_ResourceSystem().sprites().initSprites();
#ifdef __CLIENT__
App_ResourceSystem().clearAllRawTextures();
App_ResourceSystem().initModels();
Expand Down Expand Up @@ -1531,14 +1532,14 @@ ddvalue_t ddValues[DD_LAST_VALUE - DD_FIRST_VALUE - 1] = {
#endif
{&isDedicated, 0},
{&novideo, 0},
{0, 0}, // &defs.mobjs.count.num
{0, 0},
{&gotFrame, 0},
#ifdef __CLIENT__
{&playback, 0},
#else
{0, 0},
#endif
{&::defs.sounds.count.num, 0},
{&DED_Definitions()->sounds.count.num, 0},
{0, 0},
{0, 0},
#ifdef __CLIENT__
Expand Down Expand Up @@ -1591,13 +1592,13 @@ dint DD_GetInteger(dint ddvalue)
#endif

case DD_NUMMOBJTYPES:
return ::defs.things.size();
return DED_Definitions()->things.size();

case DD_MAP_MUSIC:
if (App_World().hasMap())
{
Record const &mapInfo = App_World().map().mapInfo();
return ::defs.getMusicNum(mapInfo.gets("music").toUtf8().constData());
return DED_Definitions()->getMusicNum(mapInfo.gets("music").toUtf8().constData());
}
return -1;

Expand Down Expand Up @@ -1721,7 +1722,7 @@ void *DD_GetVariable(dint ddvalue)
return &valueT;

case DD_DEFS:
return &defs;
return DED_Definitions();

default: break;
}
Expand Down

0 comments on commit 7996a3f

Please sign in to comment.