Skip to content

Commit

Permalink
Refactor|libdoomsday|DED: Store Music definitions in a DEDRegister
Browse files Browse the repository at this point in the history
Also, Music definitions may now be copied.
  • Loading branch information
danij-deng committed Aug 10, 2014
1 parent 198af7c commit ba3e72a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 130 deletions.
21 changes: 11 additions & 10 deletions doomsday/libdoomsday/include/doomsday/defs/ded.h
Expand Up @@ -86,7 +86,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s
DEDArray<ded_sound_t> sounds;

// Music.
DEDArray<ded_music_t> music;
//DEDArray<ded_music_t> music;
DEDRegister musics;

// Map information.
//DEDArray<ded_mapinfo_t> mapInfo;
Expand Down Expand Up @@ -144,6 +145,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s

int addModel();

int addMusic();

int addSky();

//ded_flag_t *getFlag(char const *flag) const;
Expand Down Expand Up @@ -181,19 +184,17 @@ struct LIBDOOMSDAY_PUBLIC ded_s
* @param name Sound name.
* @return If the name is not found, returns the NULL sound index (zero).
*/
int getSoundNumForName(const char* name) const;

ded_music_t *getMusic(char const *id) const;
int getSoundNumForName(char const *name) const;

int getMusicNum(const char* id) const;
int getMusicNum(char const *id) const;

ded_value_t* getValueById(char const* id) const;
ded_value_t *getValueById(char const *id) const;

ded_value_t* getValueByUri(de::Uri const &uri) const;
ded_value_t *getValueByUri(de::Uri const &uri) const;

ded_compositefont_t* findCompositeFontDef(de::Uri const& uri) const;
ded_compositefont_t *findCompositeFontDef(de::Uri const &uri) const;

ded_compositefont_t* getCompositeFont(char const* uriCString) const;
ded_compositefont_t *getCompositeFont(char const *uriCString) const;

protected:
void release();
Expand All @@ -219,7 +220,7 @@ LIBDOOMSDAY_PUBLIC int DED_AddMaterialLayerStage(ded_material_layer_t *ml);
int DED_AddMaterialDecorationStage(ded_material_decoration_t *li);
//int DED_AddSky(ded_t* ded, char const* id);
int DED_AddSound(ded_t* ded, char const* id);
LIBDOOMSDAY_PUBLIC int DED_AddMusic(ded_t* ded, char const* id);
//LIBDOOMSDAY_PUBLIC int DED_AddMusic(ded_t* ded, char const* id);
//int DED_AddMapInfo(ded_t* ded, char const* uri);
int DED_AddText(ded_t* ded, char const* id);
int DED_AddTextureEnv(ded_t* ded, char const* id);
Expand Down
6 changes: 2 additions & 4 deletions doomsday/libdoomsday/include/doomsday/defs/dedtypes.h
Expand Up @@ -46,7 +46,7 @@ typedef ded_stringid_t ded_string_t;
typedef ded_stringid_t ded_mobjid_t;
typedef ded_stringid_t ded_stateid_t;
typedef ded_stringid_t ded_soundid_t;
typedef ded_stringid_t ded_musicid_t;
//typedef ded_stringid_t ded_musicid_t;
typedef ded_stringid_t ded_funcid_t;
typedef char ded_func_t[DED_FUNC_LEN + 1];
typedef int ded_flags_t;
Expand Down Expand Up @@ -331,6 +331,7 @@ typedef struct LIBDOOMSDAY_PUBLIC ded_sound_s {
}
} ded_sound_t;

#if 0
typedef struct LIBDOOMSDAY_PUBLIC ded_music_s {
ded_musicid_t id; // ID of this piece of music.
ded_string_t lumpName; // Lump name.
Expand All @@ -345,7 +346,6 @@ typedef struct LIBDOOMSDAY_PUBLIC ded_music_s {
}
} ded_music_t;

#if 0
typedef struct LIBDOOMSDAY_PUBLIC ded_skylayer_s {
ded_flags_t flags;
de::Uri* material;
Expand Down Expand Up @@ -405,9 +405,7 @@ typedef struct LIBDOOMSDAY_PUBLIC ded_sky_s {
}
}
} ded_sky_t;
#endif

#if 0
typedef struct LIBDOOMSDAY_PUBLIC ded_mapinfo_s {
de::Uri* uri; // ID of the map (e.g. E2M3 or MAP21).
ded_string_t name; // Name of the map.
Expand Down
125 changes: 20 additions & 105 deletions doomsday/libdoomsday/src/defs/ded.cpp
Expand Up @@ -21,6 +21,7 @@
#include "doomsday/defs/episode.h"
#include "doomsday/defs/mapinfo.h"
#include "doomsday/defs/model.h"
#include "doomsday/defs/music.h"
#include "doomsday/defs/sky.h"

#include <de/ArrayValue>
Expand Down Expand Up @@ -54,13 +55,15 @@ ded_s::ded_s()
, episodes(names.addRecord("episodes"))
, mapInfos(names.addRecord("mapInfos"))
, models (names.addRecord("models"))
, musics (names.addRecord("musics"))
, skies (names.addRecord("skies"))
{
flags.addLookupKey("id");
episodes.addLookupKey("id");
mapInfos.addLookupKey("id");
models.addLookupKey("id", DEDRegister::OnlyFirst);
models.addLookupKey("state");
musics.addLookupKey("id", DEDRegister::OnlyFirst);
skies.addLookupKey("id");

clear();
Expand Down Expand Up @@ -105,6 +108,13 @@ int ded_s::addModel()
return def.geti("__order__");
}

int ded_s::addMusic()
{
Record &def = musics.append();
defn::Music(def).resetToDefaults();
return def.geti("__order__");
}

int ded_s::addSky()
{
Record &def = skies.append();
Expand All @@ -122,7 +132,7 @@ void ded_s::release()
lights.clear();
models.clear();
sounds.clear();
music.clear();
musics.clear();
mapInfos.clear();
skies.clear();
details.clear();
Expand All @@ -147,32 +157,6 @@ int DED_AddMobj(ded_t* ded, char const* idstr)
return ded->mobjs.indexOf(mo);
}

#if 0
int DED_AddSky(ded_t* ded, char const* id)
{
ded_sky_t *sky = ded->skies.append();
int i;

strcpy(sky->id, id);
sky->height = DEFAULT_SKY_HEIGHT;
for(i = 0; i < NUM_SKY_LAYERS; ++i)
{
sky->layers[i].offset = DEFAULT_SKY_SPHERE_XOFFSET;
sky->layers[i].colorLimit = DEFAULT_SKY_SPHERE_FADEOUT_LIMIT;
}
for(i = 0; i < NUM_SKY_MODELS; ++i)
{
sky->models[i].frameInterval = 1;
sky->models[i].color[0] = 1;
sky->models[i].color[1] = 1;
sky->models[i].color[2] = 1;
sky->models[i].color[3] = 1;
}

return ded->skies.indexOf(sky);
}
#endif

int DED_AddState(ded_t* ded, char const* id)
{
ded_state_t *st = ded->states.append();
Expand Down Expand Up @@ -225,54 +209,6 @@ int DED_AddSound(ded_t* ded, char const* id)
return ded->sounds.indexOf(snd);
}

int DED_AddMusic(ded_t* ded, char const* id)
{
ded_music_t* mus = ded->music.append();
strcpy(mus->id, id);
return ded->music.indexOf(mus);
}

#if 0
int DED_AddMapInfo(ded_t* ded, char const* uri)
{
ded_mapinfo_t* inf = ded->mapInfo.append();
int i;

if(uri)
{
inf->uri = new de::Uri(uri, RC_NULL);
if(inf->uri->scheme().isEmpty())
inf->uri->setScheme("Maps");
}
inf->gravity = 1;
inf->parTime = -1; // unknown

inf->fogColor[0] = DEFAULT_FOG_COLOR_RED;
inf->fogColor[1] = DEFAULT_FOG_COLOR_GREEN;
inf->fogColor[2] = DEFAULT_FOG_COLOR_BLUE;
inf->fogDensity = DEFAULT_FOG_DENSITY;
inf->fogStart = DEFAULT_FOG_START;
inf->fogEnd = DEFAULT_FOG_END;

inf->sky.height = DEFAULT_SKY_HEIGHT;
for(i = 0; i < NUM_SKY_LAYERS; ++i)
{
inf->sky.layers[i].offset = DEFAULT_SKY_SPHERE_XOFFSET;
inf->sky.layers[i].colorLimit = DEFAULT_SKY_SPHERE_FADEOUT_LIMIT;
}
for(i = 0; i < NUM_SKY_MODELS; ++i)
{
inf->sky.models[i].frameInterval = 1;
inf->sky.models[i].color[0] = 1;
inf->sky.models[i].color[1] = 1;
inf->sky.models[i].color[2] = 1;
inf->sky.models[i].color[3] = 1;
}

return ded->mapInfo.indexOf(inf);
}
#endif

int DED_AddText(ded_t* ded, char const* id)
{
ded_text_t* txt = ded->text.append();
Expand Down Expand Up @@ -509,20 +445,6 @@ int ded_s::getStateNum(char const *id) const
return idx;
}

/*
ded_flag_t *ded_s::getFlag(char const *flag) const
{
if(!flag || !flag[0]) return 0;
for(int i = flags.size() - 1; i >= 0; i--)
{
if(!qstricmp(flags[i].id, flag))
return &flags[i];
}
return 0;
}*/

int ded_s::evalFlags2(char const *ptr) const
{
LOG_AS("Def_EvalFlags");
Expand Down Expand Up @@ -636,30 +558,23 @@ int ded_s::getSoundNumForName(const char *name) const
return 0;
}

ded_music_t *ded_s::getMusic(char const *id) const
int ded_s::getMusicNum(const char* id) const
{
if(id && id[0] && music.size())
if(Record const *def = musics.tryFind("id", id))
{
for(int i = 0; i < music.size(); ++i)
{
if(!qstricmp(music[i].id, id))
return &music[i];
}
return def->geti("__order__");
}
return 0;
}
return -1;

int ded_s::getMusicNum(const char* id) const
{
int idx = -1;
if(id && id[0] && music.size())
/*int idx = -1;
if(id && id[0] && musics.size())
{
int i = 0;
do {
if(!qstricmp(music[i].id, id)) idx = i;
} while(idx == -1 && ++i < music.size());
if(!qstricmp(musics[i].id, id)) idx = i;
} while(idx == -1 && ++i < musics.size());
}
return idx;
return idx;*/
}

ded_value_t* ded_s::getValueById(char const* id) const
Expand Down
30 changes: 19 additions & 11 deletions doomsday/libdoomsday/src/defs/dedparser.cpp
Expand Up @@ -43,6 +43,7 @@
#include "doomsday/defs/mapgraphnode.h"
#include "doomsday/defs/mapinfo.h"
#include "doomsday/defs/model.h"
#include "doomsday/defs/music.h"
#include "doomsday/defs/sky.h"
#include "doomsday/filesys/fs_main.h"
#include "doomsday/filesys/fs_util.h"
Expand Down Expand Up @@ -775,6 +776,7 @@ DENG2_PIMPL(DEDParser)
int prevMaterialDefIdx = -1; // For "Copy".
int prevModelDefIdx = -1; // For "Copy".
int prevMapInfoDefIdx = -1; // For "Copy".
int prevMusicDefIdx = -1; // For "Copy".
int prevSkyDefIdx = -1; // For "Copy".
int prevDetailDefIdx = -1; // For "Copy".
int prevGenDefIdx = -1; // For "Copy".
Expand Down Expand Up @@ -1731,25 +1733,31 @@ DENG2_PIMPL(DEDParser)
}

if(ISTOKEN("Music"))
{ // A new music.
ded_music_t* mus;
{
// New musics are appended to the end of the list.
idx = ded->addMusic();
Record &mus = ded->musics[idx];

idx = DED_AddMusic(ded, "");
mus = &ded->music[idx];
if(prevMusicDefIdx >= 0)
{
if(bCopyNext) ded->musics.copy(prevMusicDefIdx, mus);
}

FINDBEGIN;
for(;;)
forever
{
READLABEL;
RV_STR("ID", mus->id)
RV_STR("Lump", mus->lumpName)
RV_URI("File name", &mus->path, "Music")
RV_URI("File", &mus->path, "Music")
RV_URI("Ext", &mus->path, "Music") // Both work.
RV_INT("CD track", mus->cdTrack)
RV_STR("ID", mus["id"])
RV_STR("Lump", mus["lumpName"])
RV_URI("File name", mus["path"], "Music")
RV_URI("File", mus["path"], "Music")
RV_URI("Ext", mus["path"], "Music") // Both work.
RV_INT("CD track", mus["cdTrack"])
RV_END
CHECKSC;
}

prevMusicDefIdx = idx;
}

if(ISTOKEN("Sky"))
Expand Down

0 comments on commit ba3e72a

Please sign in to comment.