Skip to content

Commit

Permalink
Performance|Client|libdoomsday: Various minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Oct 31, 2016
1 parent ffef952 commit 6b42e50
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 62 deletions.
4 changes: 2 additions & 2 deletions doomsday/apps/client/src/client/clientsubsector.cpp
Expand Up @@ -119,7 +119,7 @@ DENG2_PIMPL(ClientSubsector)
{
~EdgeLoops() { clear(); }

void clear()
void clear()
{
qDeleteAll(*this);
QList<ClEdgeLoop *>::clear();
Expand Down Expand Up @@ -201,7 +201,7 @@ DENG2_PIMPL(ClientSubsector)
bool needReverbUpdate = true;

/// Per surface lists of light decoration info and state.
QMap<Surface *, DecoratedSurface> decorSurfaces;
QHash<Surface *, DecoratedSurface> decorSurfaces;

Impl(Public *i) : Base(i)
{}
Expand Down
10 changes: 8 additions & 2 deletions doomsday/apps/client/src/world/base/line.cpp
Expand Up @@ -1048,7 +1048,7 @@ DENG2_PIMPL(Line)
slopetype_t slopeType; ///< Logical line slope (i.e., world angle) classification.
AABoxd bounds; ///< Axis-aligned bounding box.

GeomData(Vertex &from, Vertex &to)
GeomData(Vertex const &from, Vertex const &to)
: direction(to.origin() - from.origin())
, length (direction.length())
, angle (bamsAtan2(dint(direction.y), dint(direction.x)))
Expand All @@ -1057,6 +1057,11 @@ DENG2_PIMPL(Line)
V2d_InitBoxXY (bounds.arvec2, from.x(), from.y());
V2d_AddToBoxXY(bounds.arvec2, to .x(), to .y());
}

static ddouble calcLength(Vertex const &from, Vertex const &to)
{
return (to.origin() - from.origin()).length();
}
};
std::unique_ptr<GeomData> gdata;

Expand Down Expand Up @@ -1259,7 +1264,8 @@ Vector2d const &Line::direction() const

ddouble Line::length() const
{
return d->geom().length;
if (d->gdata) return d->gdata->length;
return Impl::GeomData::calcLength(*d->from, *d->to);
}

slopetype_t Line::slopeType() const
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/world/base/surface.cpp
Expand Up @@ -224,7 +224,7 @@ Material &Surface::material() const

Material *Surface::materialPtr() const
{
return hasMaterial() ? &material() : nullptr;
return d->material;
}

Surface &Surface::setMaterial(Material *newMaterial, bool isMissingFix)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/apps/libdoomsday/include/doomsday/defs/definition.h
Expand Up @@ -59,6 +59,8 @@ class LIBDOOMSDAY_PUBLIC Definition : public de::RecordAccessor
* call this before inserting their own members.
*/
virtual void resetToDefaults();

static de::String const VAR_ORDER; // __order__
};

} // namespace defn
Expand Down
18 changes: 12 additions & 6 deletions doomsday/apps/libdoomsday/include/doomsday/world/mapelement.h
Expand Up @@ -44,9 +44,6 @@ class LIBDOOMSDAY_PUBLIC MapElement
DENG2_NO_ASSIGN(MapElement)

public:
/// No parent map element is configured. @ingroup errors
DENG2_ERROR(MissingParentError);

/// Attempted to configure an invalid parent element. @ingroup errors
DENG2_ERROR(InvalidParentError);

Expand Down Expand Up @@ -85,15 +82,22 @@ class LIBDOOMSDAY_PUBLIC MapElement
*
* @see parent(), setParent()
*/
bool hasParent() const;
inline bool hasParent() const { return _parent != nullptr; }

/**
* Returns the parent of the map element.
*
* @see hasParent(), setParent()
*/
MapElement &parent();
MapElement const &parent() const;
inline MapElement &parent() {
DENG2_ASSERT(_parent);
return *_parent;
}

inline MapElement const &parent() const {
DENG2_ASSERT(_parent);
return *_parent;
}

/**
* Change the parent of the map element.
Expand Down Expand Up @@ -197,6 +201,8 @@ class LIBDOOMSDAY_PUBLIC MapElement

private:
DENG2_PRIVATE(d)

MapElement *_parent = nullptr;
};

} // namespace world
Expand Down
40 changes: 20 additions & 20 deletions doomsday/apps/libdoomsday/src/defs/ded.cpp
Expand Up @@ -101,79 +101,79 @@ int ded_s::addFlag(String const &id, int value)
Record &def = flags.append();
def.addText("id", id);
def.addNumber("value", value);
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addEpisode()
{
Record &def = episodes.append();
defn::Episode(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addThing(String const &id)
{
Record &def = things.append();
defn::Thing(def).resetToDefaults();
def.set("id", id);
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addState(String const &id)
{
Record &def = states.append();
defn::State(def).resetToDefaults();
def.set("id", id);
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addDecoration()
{
Record &def = decorations.append();
defn::Decoration(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addFinale()
{
Record &def = finales.append();
defn::Finale(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addMapInfo()
{
Record &def = mapInfos.append();
defn::MapInfo(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addMaterial()
{
Record &def = materials.append();
defn::Material(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

int ded_s::addModel()
{
Record &def = models.append();
defn::Model(def).resetToDefaults();
return def.geti("__order__");
return def.geti(defn::Definition::VAR_ORDER);
}

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

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

void ded_s::release()
Expand Down Expand Up @@ -362,7 +362,7 @@ int ded_s::getMobjNum(String const &id) const
{
if (Record const *def = things.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
/*
for (i = 0; i < mobjs.size(); ++i)
Expand All @@ -383,7 +383,7 @@ int ded_s::getMobjNumForName(const char *name) const
return i;*/
if (Record const *def = things.tryFind("name", name))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}

return -1;
Expand All @@ -400,7 +400,7 @@ int ded_s::getStateNum(String const &id) const
{
if (Record const *def = states.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1;
}
Expand Down Expand Up @@ -440,7 +440,7 @@ int ded_s::getEpisodeNum(String const &id) const
{
if (Record const *def = episodes.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1;
}
Expand All @@ -449,7 +449,7 @@ int ded_s::getMapInfoNum(de::Uri const &uri) const
{
if (Record const *def = mapInfos.tryFind("id", uri.compose()))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1; // Not found.
}
Expand Down Expand Up @@ -478,7 +478,7 @@ int ded_s::getMaterialNum(de::Uri const &uri) const

if (Record const *def = materials.tryFind("id", uri.compose()))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1; // Not found.
}
Expand All @@ -487,7 +487,7 @@ int ded_s::getModelNum(const char *id) const
{
if (Record const *def = models.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1;

Expand All @@ -506,7 +506,7 @@ int ded_s::getSkyNum(char const *id) const
{
if (Record const *def = skies.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1;

Expand Down Expand Up @@ -572,7 +572,7 @@ int ded_s::getMusicNum(char const *id) const
{
if (Record const *def = musics.tryFind("id", id))
{
return def->geti("__order__");
return def->geti(defn::Definition::VAR_ORDER);
}
return -1;

Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/libdoomsday/src/defs/dedregister.cpp
Expand Up @@ -17,6 +17,7 @@
*/

#include "doomsday/defs/dedregister.h"
#include "doomsday/defs/definition.h"

#include <de/ArrayValue>
#include <de/DictionaryValue>
Expand Down Expand Up @@ -142,7 +143,7 @@ DENG2_PIMPL(DEDRegister)
Record *sub = new Record;

// Let each subrecord know their ordinal.
sub->set("__order__", int(order().size())).setReadOnly();
sub->set(defn::Definition::VAR_ORDER, int(order().size())).setReadOnly();

// Observe what goes into this record.
//sub->audienceForDeletion() += this;
Expand Down
4 changes: 3 additions & 1 deletion doomsday/apps/libdoomsday/src/defs/definition.cpp
Expand Up @@ -24,6 +24,8 @@ using namespace de;

namespace defn {

String const Definition::VAR_ORDER("__order__");

Record &Definition::def()
{
return const_cast<Record &>(accessedRecord());
Expand All @@ -37,7 +39,7 @@ Record const &Definition::def() const
int Definition::order() const
{
if (!accessedRecordPtr()) return -1;
return geti("__order__");
return geti(VAR_ORDER);
}

Definition::operator bool() const
Expand Down
30 changes: 6 additions & 24 deletions doomsday/apps/libdoomsday/src/world/mapelement.cpp
Expand Up @@ -28,7 +28,6 @@ namespace world {
DENG2_PIMPL_NOREF(MapElement)
{
dint type;
MapElement *parent = nullptr;
Map *map = nullptr;
dint indexInMap = NoIndex;
dint indexInArchive = NoIndex;
Expand All @@ -50,49 +49,32 @@ dint MapElement::type() const
return d->type;
}

bool MapElement::hasParent() const
{
return d->parent != nullptr;
}

MapElement &MapElement::parent()
{
return const_cast<MapElement &>(const_cast<MapElement const *>(this)->parent());
}

MapElement const &MapElement::parent() const
{
if (d->parent) return *d->parent;
/// @throw MissingParentError Attempted with no parent element is attributed.
throw MissingParentError("MapElement::parent", "No parent map element is attributed");
}

void MapElement::setParent(MapElement *newParent)
{
if (newParent == this)
{
/// @throw InvalidParentError Attempted to attribute *this* element as parent of itself.
throw InvalidParentError("MapElement::setParent", "Cannot attribute 'this' map element as a parent of itself");
}
d->parent = newParent;
_parent = newParent;
}

bool MapElement::hasMap() const
{
// If a parent is configured this property is delegated to the parent.
if (d->parent)
if (_parent)
{
return d->parent->hasMap();
return _parent->hasMap();
}
return d->map != nullptr;
}

Map &MapElement::map() const
{
// If a parent is configured this property is delegated to the parent.
if (d->parent)
if (_parent)
{
return d->parent->map();
return _parent->map();
}
if (d->map)
{
Expand All @@ -105,7 +87,7 @@ Map &MapElement::map() const
void MapElement::setMap(Map *newMap)
{
// If a parent is configured this property is delegated to the parent.
if (!d->parent)
if (!_parent)
{
d->map = newMap;
return;
Expand Down

0 comments on commit 6b42e50

Please sign in to comment.