Skip to content

Commit

Permalink
Refactor|libdoomsday|DED: Store Sky definitions in a DEDRegister
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 27, 2014
1 parent 443d71d commit f71a606
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 27 deletions.
11 changes: 7 additions & 4 deletions doomsday/libdoomsday/include/doomsday/defs/ded.h
Expand Up @@ -76,7 +76,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s
DEDRegister models;

// Skies.
DEDArray<ded_sky_t> skies;
//DEDArray<ded_sky_t> skies;
DEDRegister skies;

// Sounds.
DEDArray<ded_sound_t> sounds;
Expand Down Expand Up @@ -135,6 +136,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s

int addModel();

int addSky();

//ded_flag_t *getFlag(char const *flag) const;

int evalFlags2(char const *ptr) const;
Expand All @@ -157,6 +160,8 @@ struct LIBDOOMSDAY_PUBLIC ded_s

int getModelNum(char const *id) const;

int getSkyNum(char const *id) const;

int getSoundNum(char const *id) const;

/**
Expand All @@ -176,8 +181,6 @@ struct LIBDOOMSDAY_PUBLIC ded_s

ded_mapinfo_t *getMapInfo(de::Uri const *uri) const;

ded_sky_t* getSky(char const* id) const;

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

ded_compositefont_t* getCompositeFont(char const* uriCString) const;
Expand All @@ -204,7 +207,7 @@ int DED_AddLight(ded_t* ded, char const* stateID);
LIBDOOMSDAY_PUBLIC int DED_AddMaterial(ded_t* ded, char const* uri);
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_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);
int DED_AddMapInfo(ded_t* ded, char const* uri);
Expand Down
12 changes: 2 additions & 10 deletions doomsday/libdoomsday/include/doomsday/defs/dedtypes.h
Expand Up @@ -345,6 +345,7 @@ 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 @@ -378,16 +379,6 @@ typedef struct LIBDOOMSDAY_PUBLIC ded_skymodel_s {
}
} ded_skymodel_t;

#define NUM_SKY_LAYERS 2
#define NUM_SKY_MODELS 32

// Sky flags.
#define SIF_DRAW_SPHERE 0x1 ///< Always draw the sky sphere.

#define DEFAULT_SKY_HEIGHT ( .666667f )
#define DEFAULT_SKY_SPHERE_XOFFSET ( 0 )
#define DEFAULT_SKY_SPHERE_FADEOUT_LIMIT ( .3f )

typedef struct LIBDOOMSDAY_PUBLIC ded_sky_s {
ded_stringid_t id;
ded_flags_t flags; // Flags.
Expand All @@ -414,6 +405,7 @@ typedef struct LIBDOOMSDAY_PUBLIC ded_sky_s {
}
}
} ded_sky_t;
#endif

/// @todo These values should be tweaked a bit.
#define DEFAULT_FOG_START 0
Expand Down
70 changes: 70 additions & 0 deletions doomsday/libdoomsday/include/doomsday/defs/sky.h
@@ -0,0 +1,70 @@
/** @file defs/sky.h Model definition accessor.
*
* @authors Copyright © 2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDOOMSDAY_DEFN_SKY_H
#define LIBDOOMSDAY_DEFN_SKY_H

#include "../libdoomsday.h"
#include <de/RecordAccessor>

namespace defn {

// Sky flags.
#define SIF_DRAW_SPHERE 0x1 ///< Always draw the sky sphere.

/**
* Utility for handling sky definitions.
*/
class LIBDOOMSDAY_PUBLIC Sky : public de::RecordAccessor
{
public:
Sky() : RecordAccessor(0), _def(0) {}
Sky(Sky const &other)
: RecordAccessor(other)
, _def(other._def) {}
Sky(de::Record &d) : RecordAccessor(d), _def(&d) {}
Sky(de::Record const &d) : RecordAccessor(d), _def(0) {}

void resetToDefaults();

Sky &operator = (de::Record *d);

operator bool() const;
int order() const;

de::Record &addLayer();

int layerCount() const;
bool hasLayer(int index) const;
de::Record &layer(int index);
de::Record const &layer(int index) const;

de::Record &addModel();

int modelCount() const;
bool hasModel(int index) const;
de::Record &model(int index);
de::Record const &model(int index) const;

private:
de::Record *_def; ///< Modifiable access.
};

} // namespace defn

#endif // LIBDOOMSDAY_DEFN_SKY_H
2 changes: 2 additions & 0 deletions doomsday/libdoomsday/libdoomsday.pro
Expand Up @@ -71,6 +71,7 @@ HEADERS += \
include/doomsday/defs/dedregister.h \
include/doomsday/defs/dedtypes.h \
include/doomsday/defs/model.h \
include/doomsday/defs/sky.h \
include/doomsday/dualstring.h \
include/doomsday/filesys/file.h \
include/doomsday/filesys/filehandle.h \
Expand Down Expand Up @@ -108,6 +109,7 @@ SOURCES += \
src/defs/dedparser.cpp \
src/defs/dedregister.cpp \
src/defs/model.cpp \
src/defs/sky.cpp \
src/dualstring.cpp \
src/filesys/file.cpp \
src/filesys/filehandle.cpp \
Expand Down
42 changes: 30 additions & 12 deletions doomsday/libdoomsday/src/defs/ded.cpp
Expand Up @@ -19,6 +19,7 @@

#include "doomsday/defs/ded.h"
#include "doomsday/defs/model.h"
#include "doomsday/defs/sky.h"

#include <de/ArrayValue>
#include <de/NumberValue>
Expand Down Expand Up @@ -49,10 +50,12 @@ float ded_ptcstage_t::particleRadius(int ptcIDX) const
ded_s::ded_s()
: flags (names.addRecord("flags"))
, models(names.addRecord("models"))
, skies (names.addRecord("skies"))
{
flags.addLookupKey("id");
models.addLookupKey("id", DEDRegister::OnlyFirst);
models.addLookupKey("state");
skies.addLookupKey("id");

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

int ded_s::addSky()
{
Record &def = skies.append();
defn::Sky(def).resetToDefaults();
return def.geti("__order__");
}

void ded_s::release()
{
flags.clear();
Expand Down Expand Up @@ -116,6 +126,7 @@ 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();
Expand All @@ -139,6 +150,7 @@ int DED_AddSky(ded_t* ded, char const* id)

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

int DED_AddState(ded_t* ded, char const* id)
{
Expand Down Expand Up @@ -533,6 +545,24 @@ int ded_s::getModelNum(const char *id) const
return idx;*/
}

int ded_s::getSkyNum(char const *id) const
{
if(Record const *def = skies.tryFind("id", id))
{
return def->geti("__order__");
}
return -1;

/*if(!id || !id[0]) return -1;
for(int i = skies.size() - 1; i >= 0; i--)
{
if(!qstricmp(skies[i].id, id))
return i;
}
return -1;*/
}

int ded_s::getSoundNum(const char *id) const
{
int idx = -1;
Expand Down Expand Up @@ -615,18 +645,6 @@ ded_mapinfo_t *ded_s::getMapInfo(de::Uri const *uri) const
return 0;
}

ded_sky_t* ded_s::getSky(char const* id) const
{
if(!id || !id[0]) return NULL;

for(int i = skies.size() - 1; i >= 0; i--)
{
if(!qstricmp(skies[i].id, id))
return &skies[i];
}
return 0;
}

ded_compositefont_t* ded_s::findCompositeFontDef(de::Uri const& uri) const
{
for(int i = compositeFonts.size() - 1; i >= 0; i--)
Expand Down
3 changes: 2 additions & 1 deletion doomsday/libdoomsday/src/defs/dedparser.cpp
Expand Up @@ -1554,7 +1554,8 @@ DENG2_PIMPL(DEDParser)
}

if(ISTOKEN("Sky"))
{ // A new sky definition.
{
// A new sky definition.
ded_sky_t* sky;
uint sub = 0;

Expand Down

0 comments on commit f71a606

Please sign in to comment.