diff --git a/doomsday/apps/client/src/client/clientsubsector.cpp b/doomsday/apps/client/src/client/clientsubsector.cpp index 59a721f54f..5630f2ec35 100644 --- a/doomsday/apps/client/src/client/clientsubsector.cpp +++ b/doomsday/apps/client/src/client/clientsubsector.cpp @@ -119,7 +119,7 @@ DENG2_PIMPL(ClientSubsector) { ~EdgeLoops() { clear(); } - void clear() + void clear() { qDeleteAll(*this); QList::clear(); @@ -201,7 +201,7 @@ DENG2_PIMPL(ClientSubsector) bool needReverbUpdate = true; /// Per surface lists of light decoration info and state. - QMap decorSurfaces; + QHash decorSurfaces; Impl(Public *i) : Base(i) {} diff --git a/doomsday/apps/client/src/world/base/line.cpp b/doomsday/apps/client/src/world/base/line.cpp index 1800055168..282ca3dcd6 100644 --- a/doomsday/apps/client/src/world/base/line.cpp +++ b/doomsday/apps/client/src/world/base/line.cpp @@ -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))) @@ -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 gdata; @@ -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 diff --git a/doomsday/apps/client/src/world/base/surface.cpp b/doomsday/apps/client/src/world/base/surface.cpp index 7e91f48397..a318c5ae2d 100644 --- a/doomsday/apps/client/src/world/base/surface.cpp +++ b/doomsday/apps/client/src/world/base/surface.cpp @@ -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) diff --git a/doomsday/apps/libdoomsday/include/doomsday/defs/definition.h b/doomsday/apps/libdoomsday/include/doomsday/defs/definition.h index e54e9ac60d..02ed15276d 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/defs/definition.h +++ b/doomsday/apps/libdoomsday/include/doomsday/defs/definition.h @@ -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 diff --git a/doomsday/apps/libdoomsday/include/doomsday/world/mapelement.h b/doomsday/apps/libdoomsday/include/doomsday/world/mapelement.h index 16441cc591..bad5875d7d 100644 --- a/doomsday/apps/libdoomsday/include/doomsday/world/mapelement.h +++ b/doomsday/apps/libdoomsday/include/doomsday/world/mapelement.h @@ -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); @@ -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. @@ -197,6 +201,8 @@ class LIBDOOMSDAY_PUBLIC MapElement private: DENG2_PRIVATE(d) + + MapElement *_parent = nullptr; }; } // namespace world diff --git a/doomsday/apps/libdoomsday/src/defs/ded.cpp b/doomsday/apps/libdoomsday/src/defs/ded.cpp index dc6857259b..8b315e55a4 100644 --- a/doomsday/apps/libdoomsday/src/defs/ded.cpp +++ b/doomsday/apps/libdoomsday/src/defs/ded.cpp @@ -101,14 +101,14 @@ 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) @@ -116,7 +116,7 @@ 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) @@ -124,56 +124,56 @@ 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() @@ -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) @@ -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; @@ -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; } @@ -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; } @@ -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. } @@ -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. } @@ -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; @@ -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; @@ -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; diff --git a/doomsday/apps/libdoomsday/src/defs/dedregister.cpp b/doomsday/apps/libdoomsday/src/defs/dedregister.cpp index 24e750f9b5..85f56cd7ee 100644 --- a/doomsday/apps/libdoomsday/src/defs/dedregister.cpp +++ b/doomsday/apps/libdoomsday/src/defs/dedregister.cpp @@ -17,6 +17,7 @@ */ #include "doomsday/defs/dedregister.h" +#include "doomsday/defs/definition.h" #include #include @@ -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; diff --git a/doomsday/apps/libdoomsday/src/defs/definition.cpp b/doomsday/apps/libdoomsday/src/defs/definition.cpp index a8454cbd1d..8a9f7eb602 100644 --- a/doomsday/apps/libdoomsday/src/defs/definition.cpp +++ b/doomsday/apps/libdoomsday/src/defs/definition.cpp @@ -24,6 +24,8 @@ using namespace de; namespace defn { +String const Definition::VAR_ORDER("__order__"); + Record &Definition::def() { return const_cast(accessedRecord()); @@ -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 diff --git a/doomsday/apps/libdoomsday/src/world/mapelement.cpp b/doomsday/apps/libdoomsday/src/world/mapelement.cpp index 26fc376c80..e5f10c2e93 100644 --- a/doomsday/apps/libdoomsday/src/world/mapelement.cpp +++ b/doomsday/apps/libdoomsday/src/world/mapelement.cpp @@ -28,7 +28,6 @@ namespace world { DENG2_PIMPL_NOREF(MapElement) { dint type; - MapElement *parent = nullptr; Map *map = nullptr; dint indexInMap = NoIndex; dint indexInArchive = NoIndex; @@ -50,23 +49,6 @@ dint MapElement::type() const return d->type; } -bool MapElement::hasParent() const -{ - return d->parent != nullptr; -} - -MapElement &MapElement::parent() -{ - return const_cast(const_cast(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) @@ -74,15 +56,15 @@ void MapElement::setParent(MapElement *newParent) /// @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; } @@ -90,9 +72,9 @@ bool MapElement::hasMap() const 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) { @@ -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; diff --git a/doomsday/apps/plugins/dehread/src/dehreader.cpp b/doomsday/apps/plugins/dehread/src/dehreader.cpp index c0ba85330b..65b1004ed0 100644 --- a/doomsday/apps/plugins/dehread/src/dehreader.cpp +++ b/doomsday/apps/plugins/dehread/src/dehreader.cpp @@ -796,7 +796,7 @@ class DehReader { LOG_AS("parseThing"); - int const thingNum = mobj.geti("__order__"); + int const thingNum = mobj.geti(defn::Definition::VAR_ORDER); bool hadHeight = false, checkHeight = false; for(; lineInCurrentSection(); skipToNextLine()) @@ -1043,7 +1043,7 @@ class DehReader void parseFrame(defn::State state, bool ignore = false) { LOG_AS("parseFrame"); - int const stateNum = state.geti("__order__"); + int const stateNum = state.geti(defn::Definition::VAR_ORDER); for(; lineInCurrentSection(); skipToNextLine()) { @@ -1390,7 +1390,7 @@ class DehReader void parsePointer(defn::State state, bool ignore) { LOG_AS("parsePointer"); - int const stateNum = state.geti("__order__"); + int const stateNum = state.geti(defn::Definition::VAR_ORDER); for(; lineInCurrentSection(); skipToNextLine()) { diff --git a/doomsday/sdk/libcore/src/data/record.cpp b/doomsday/sdk/libcore/src/data/record.cpp index 650bae3a1f..238b789c9e 100644 --- a/doomsday/sdk/libcore/src/data/record.cpp +++ b/doomsday/sdk/libcore/src/data/record.cpp @@ -185,8 +185,6 @@ DENG2_PIMPL(Record), public Lockable Variable const *findMemberByPath(String const &name) const { - DENG2_GUARD(this); - // Path notation allows looking into subrecords. int pos = name.indexOf('.'); if (pos >= 0) @@ -198,6 +196,8 @@ DENG2_PIMPL(Record), public Lockable return self[subName].value().dereference().d->findMemberByPath(remaining); } + DENG2_GUARD(this); + Members::const_iterator found = members.constFind(name); if (found != members.constEnd()) {