From ee034f268606fe1339d087cfd8a0be81795b2a78 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 6 Sep 2013 00:34:20 +0100 Subject: [PATCH] Refactor|Lumobj: Extracted MapObject from Lumobj Todo for later: Mobj, Polyobj, SoundEmitter, etc... should all use this as their base. --- doomsday/client/client.pro | 3 + doomsday/client/include/MapObject | 1 + doomsday/client/include/render/lumobj.h | 60 ++---------- doomsday/client/include/resource/sprites.h | 4 +- doomsday/client/include/world/map.h | 2 +- doomsday/client/include/world/mapobject.h | 102 +++++++++++++++++++++ doomsday/client/src/render/lumobj.cpp | 42 +-------- doomsday/client/src/world/mapobject.cpp | 66 +++++++++++++ 8 files changed, 186 insertions(+), 94 deletions(-) create mode 100644 doomsday/client/include/MapObject create mode 100644 doomsday/client/include/world/mapobject.h create mode 100644 doomsday/client/src/world/mapobject.cpp diff --git a/doomsday/client/client.pro b/doomsday/client/client.pro index c0156b6f0f..eb13d279e3 100644 --- a/doomsday/client/client.pro +++ b/doomsday/client/client.pro @@ -137,6 +137,7 @@ DENG_CONVENIENCE_HEADERS += \ include/IHPlane \ include/Line \ include/MapElement \ + include/MapObject \ include/Material \ include/MaterialArchive \ include/MaterialContext \ @@ -461,6 +462,7 @@ DENG_HEADERS += \ include/world/linesighttest.h \ include/world/map.h \ include/world/mapelement.h \ + include/world/mapobject.h \ include/world/maputil.h \ include/world/p_intercept.h \ include/world/p_object.h \ @@ -789,6 +791,7 @@ SOURCES += \ src/world/linesighttest.cpp \ src/world/map.cpp \ src/world/mapelement.cpp \ + src/world/mapobject.cpp \ src/world/maputil.cpp \ src/world/p_intercept.cpp \ src/world/p_mobj.cpp \ diff --git a/doomsday/client/include/MapObject b/doomsday/client/include/MapObject new file mode 100644 index 0000000000..bcaf90dce9 --- /dev/null +++ b/doomsday/client/include/MapObject @@ -0,0 +1 @@ +#include "world/mapobject.h" diff --git a/doomsday/client/include/render/lumobj.h b/doomsday/client/include/render/lumobj.h index 329b66938b..2b59ab4ef2 100644 --- a/doomsday/client/include/render/lumobj.h +++ b/doomsday/client/include/render/lumobj.h @@ -21,26 +21,20 @@ #ifndef DENG_CLIENT_RENDER_LUMOBJ_H #define DENG_CLIENT_RENDER_LUMOBJ_H -#include #include +#include "MapObject" #include "Texture" class BspLeaf; -namespace de { -class Map; -} - -class Lumobj +/** + * Luminous object. + * @ingroup render + */ +class Lumobj : public de::MapObject { public: - /// No map is attributed. @ingroup errors - DENG2_ERROR(MissingMapError); - - /// Special identifier used to mark an invalid index. - enum { NoIndex = -1 }; - /// Identifiers for attributing lightmaps for projection (relative surface directions). enum LightmapSemantic { Side, @@ -60,48 +54,8 @@ class Lumobj */ static void consoleRegister(); - static int radiusMax(); static float radiusFactor(); - - /** - * Returns @c true iff a map is attributed to the lumobj. - * - * @see map(), setMap() - */ - bool hasMap() const; - - /** - * Returns the map attributed to the lumobj. - * - * @see hasMap(), setMap() - */ - de::Map &map() const; - - /** - * Change the map attributed to the lumobj. - * - * @param newMap - * - * @see hasMap(), map() - */ - void setMap(de::Map *newMap); - - /** - * Returns the "in-map" index attributed to the lumobj. - * - * @see setIndexInMap() - */ - int indexInMap() const; - - /** - * Change the "in-map" index attributed to the lumobj. - * - * @param newIndex New index to attribute to the lumobj. Use @c NoIndex to - * clear the attribution (not a valid index). - * - * @see indexInMap() - */ - void setIndexInMap(int newIndex = NoIndex); + static int radiusMax(); /** * Translate the origin of the lumobj in map space. diff --git a/doomsday/client/include/resource/sprites.h b/doomsday/client/include/resource/sprites.h index 5d84d832ad..d33d0d8873 100644 --- a/doomsday/client/include/resource/sprites.h +++ b/doomsday/client/include/resource/sprites.h @@ -73,7 +73,7 @@ Material *SpriteFrame_Material(spriteframe_t &sprFrame, angle_t mobjAngle, * * @param sprFrame spriteframe_t instance. * @param rotation Rotation index/identifier to lookup the material for. The - * valid range is [0...SPRITEFRAME_MAX_ANGLES). + * valid range is [0...SPRITEFRAME_MAX_ANGLES) * * Return values: * @param flipX @c true= chosen material should be flipped on the X axis. @@ -103,7 +103,7 @@ spriteframe_t *SpriteDef_Frame(spritedef_t const &sprDef, int frame); * any resultant lumobj are configured in "sprite-local" space. This means that * it will positioned relative to the center of the sprite and must be further * configured before adding to the map (i.e., translated to the origin in map - * space. + * space). * * @param sprDef SpriteDef instance. * @param frame Animation frame to produce a lumobj for. diff --git a/doomsday/client/include/world/map.h b/doomsday/client/include/world/map.h index 6dc0488fbf..389a519260 100644 --- a/doomsday/client/include/world/map.h +++ b/doomsday/client/include/world/map.h @@ -61,7 +61,7 @@ typedef struct cmhash_s { struct clmoinfo_s *first, *last; } cmhash_t; -#define CLIENT_MAX_MOVERS 1024 // Definitely enough! +#define CLIENT_MAX_MOVERS 1024 // Definitely enough! /** * @ingroup world diff --git a/doomsday/client/include/world/mapobject.h b/doomsday/client/include/world/mapobject.h new file mode 100644 index 0000000000..0023a91cf1 --- /dev/null +++ b/doomsday/client/include/world/mapobject.h @@ -0,0 +1,102 @@ +/** @file mapobject.h Base class for all world map objects. + * + * @authors Copyright © 2013 Jaakko Keränen + * @authors Copyright © 2013 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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 + */ + +#ifndef DENG_WORLD_MAPOBJECT_H +#define DENG_WORLD_MAPOBJECT_H + +#include +#include + +namespace de { + +class Map; + +/** + * Base class for all map objects. + * + * While logically relatted to MapElement, a map object is considered a dynamic + * and volatile entity (whereas a map element can be largely considered static). + * + * The lifetime of a map object may varry massively between instances and range + * from only a few milliseconds to a few hours or longer. + * + * @ingroup world + */ +class MapObject +{ + DENG2_NO_COPY (MapObject) + DENG2_NO_ASSIGN(MapObject) + +public: + /// No map is attributed. @ingroup errors + DENG2_ERROR(MissingMapError); + + /// Special identifier used to mark an invalid index. + enum { NoIndex = -1 }; + +public: + MapObject(); + + /** + * Returns @c true iff a map is attributed to the map object. + * + * @see map(), setMap() + */ + bool hasMap() const; + + /** + * Returns the map attributed to the map object. + * + * @see hasMap(), setMap() + */ + Map &map() const; + + /** + * Change the map attributed to the map object. + * + * @param newMap + * + * @see hasMap(), map() + */ + void setMap(Map *newMap); + + /** + * Returns the "in-map" index attributed to the map object. + * + * @see setIndexInMap() + */ + int indexInMap() const; + + /** + * Change the "in-map" index attributed to the map object. + * + * @param newIndex New index to attribute. Use @c NoIndex to clear the + * attribution (not a valid index). + * + * @see indexInMap() + */ + void setIndexInMap(int newIndex = NoIndex); + +private: + DENG2_PRIVATE(d) +}; + +} // namespace de + +#endif // DENG_WORLD_MAPOBJECT_H diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index 19e83aa563..0649b45dd1 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -46,9 +46,7 @@ DENG2_PIMPL_NOREF(Lumobj) Texture *upTex; Instance() - : map (0), - indexInMap (NoIndex), - bspLeaf (0), + : bspLeaf (0), maxDistance(0), radius (256), zOffset (0), @@ -58,9 +56,7 @@ DENG2_PIMPL_NOREF(Lumobj) {} Instance(Instance const &other) - : map (0), // Never copied. - indexInMap (NoIndex), // Never copied. - origin (other.origin), + : origin (other.origin), bspLeaf (other.bspLeaf), maxDistance(other.maxDistance), color (other.color), @@ -72,42 +68,12 @@ DENG2_PIMPL_NOREF(Lumobj) {} }; -Lumobj::Lumobj() : d(new Instance()) +Lumobj::Lumobj() : MapObject(), d(new Instance()) {} -Lumobj::Lumobj(Lumobj const &other) : d(new Instance(*other.d)) +Lumobj::Lumobj(Lumobj const &other) : MapObject(), d(new Instance(*other.d)) {} -bool Lumobj::hasMap() const -{ - return d->map != 0; -} - -Map &Lumobj::map() const -{ - if(d->map) - { - return *d->map; - } - /// @throw MissingMapError Attempted with no map attributed. - throw MissingMapError("Lumobj::map", "No map is attributed"); -} - -void Lumobj::setMap(Map *newMap) -{ - d->map = newMap; -} - -int Lumobj::indexInMap() const -{ - return d->indexInMap; -} - -void Lumobj::setIndexInMap(int newIndex) -{ - d->indexInMap = newIndex; -} - Vector3d const &Lumobj::origin() const { return d->origin; diff --git a/doomsday/client/src/world/mapobject.cpp b/doomsday/client/src/world/mapobject.cpp new file mode 100644 index 0000000000..d6fd63d98e --- /dev/null +++ b/doomsday/client/src/world/mapobject.cpp @@ -0,0 +1,66 @@ +/** @file mapobject.cpp Base class for all map objects. + * + * @authors Copyright © 2013 Jaakko Keränen + * @authors Copyright © 2013 Daniel Swanson + * + * @par License + * GPL: http://www.gnu.org/licenses/gpl.html + * + * 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, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA + */ + +#include "world/map.h" +#include "world/mapobject.h" + +using namespace de; + +DENG2_PIMPL_NOREF(MapObject) +{ + Map *map; + int indexInMap; + + Instance() : map(0), indexInMap(NoIndex) + {} +}; + +MapObject::MapObject() : d(new Instance()) +{} + +bool MapObject::hasMap() const +{ + return d->map != 0; +} + +Map &MapObject::map() const +{ + if(d->map) + { + return *d->map; + } + /// @throw MissingMapError Attempted with no map attributed. + throw MissingMapError("MapObject::map", "No map is attributed"); +} + +void MapObject::setMap(Map *newMap) +{ + d->map = newMap; +} + +int MapObject::indexInMap() const +{ + return d->indexInMap; +} + +void MapObject::setIndexInMap(int newIndex) +{ + d->indexInMap = newIndex; +}