Navigation Menu

Skip to content

Commit

Permalink
Refactor|Lumobj: Extracted MapObject from Lumobj
Browse files Browse the repository at this point in the history
Todo for later: Mobj, Polyobj, SoundEmitter, etc... should all use
this as their base.
  • Loading branch information
danij-deng committed Sep 5, 2013
1 parent 3012ed3 commit ee034f2
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 94 deletions.
3 changes: 3 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -137,6 +137,7 @@ DENG_CONVENIENCE_HEADERS += \
include/IHPlane \
include/Line \
include/MapElement \
include/MapObject \
include/Material \
include/MaterialArchive \
include/MaterialContext \
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/MapObject
@@ -0,0 +1 @@
#include "world/mapobject.h"
60 changes: 7 additions & 53 deletions doomsday/client/include/render/lumobj.h
Expand Up @@ -21,26 +21,20 @@
#ifndef DENG_CLIENT_RENDER_LUMOBJ_H
#define DENG_CLIENT_RENDER_LUMOBJ_H

#include <de/Error>
#include <de/Vector>

#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,
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/include/resource/sprites.h
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/world/map.h
Expand Up @@ -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
Expand Down
102 changes: 102 additions & 0 deletions 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 <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 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 DENG_WORLD_MAPOBJECT_H
#define DENG_WORLD_MAPOBJECT_H

#include <de/libdeng2.h>
#include <de/Error>

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
42 changes: 4 additions & 38 deletions doomsday/client/src/render/lumobj.cpp
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions 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 <jaakko.keranen@iki.fi>
* @authors Copyright © 2013 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, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#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;
}

0 comments on commit ee034f2

Please sign in to comment.