Skip to content

Commit

Permalink
World|MapObject: All map objects have a map space origin
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Sep 13, 2013
1 parent e110fdd commit 4b55be5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 80 deletions.
30 changes: 0 additions & 30 deletions doomsday/client/include/render/lumobj.h
Expand Up @@ -99,36 +99,6 @@ class Lumobj : public de::MapObject
*/
void setSource(Source *newSource);

/**
* Translate the origin of the lumobj in map space.
*
* @param delta Movement delta on the XY plane.
*
* @see setOrigin(), origin()
*/
void move(de::Vector3d const &delta);

/**
* Returns the origin of the lumobj in map space.
*
* @see move(), setOrigin(), bspLeafAtOrigin()
*/
de::Vector3d const &origin() const;

/**
* Change the origin of the lumobj in map space.
*
* @param newOrigin New absolute map space origin to apply, in map units.
*
* @see move(), origin()
*/
Lumobj &setOrigin(de::Vector3d const &newOrigin);

/**
* Returns the map BSP leaf at the origin of the lumobj (result cached).
*/
BspLeaf &bspLeafAtOrigin() const;

/**
* Returns the light color/intensity of the lumobj.
*
Expand Down
44 changes: 40 additions & 4 deletions doomsday/client/include/world/mapobject.h
Expand Up @@ -20,8 +20,10 @@
#ifndef DENG_WORLD_MAPOBJECT_H
#define DENG_WORLD_MAPOBJECT_H

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

class BspLeaf;

namespace de {

Expand Down Expand Up @@ -51,17 +53,51 @@ class MapObject
enum { NoIndex = -1 };

public:
MapObject();
MapObject(de::Vector3d const &origin = de::Vector3d());
virtual ~MapObject();

/**
* Returns the map BSP leaf at the origin of the object (result cached).
* Naturally a map must be attributed.
*
* @see setMap(), hasMap()
*/
BspLeaf &bspLeafAtOrigin() const;

/**
* Returns the origin of the object in map space.
*
* @see move(), setOrigin(), bspLeafAtOrigin()
*/
de::Vector3d const &origin() const;

/**
* Change the origin of the object in map space.
*
* @param newOrigin New absolute origin to apply, in map units.
*
* @see move(), origin()
*/
virtual void setOrigin(de::Vector3d const &newOrigin);

/**
* Translate the origin of the object in map space.
*
* @param delta Movement delta.
*
* @see setOrigin(), origin()
*/
virtual void move(de::Vector3d const &delta);

/**
* Returns @c true iff a map is attributed to the map object.
* Returns @c true iff a map is attributed to the object.
*
* @see map(), setMap()
*/
bool hasMap() const;

/**
* Returns the map attributed to the map object.
* Returns the map attributed to the object.
*
* @see hasMap(), setMap()
*/
Expand Down
47 changes: 3 additions & 44 deletions doomsday/client/src/render/lumobj.cpp
Expand Up @@ -40,8 +40,6 @@ float Lumobj::Source::occlusion(Vector3d const &eye) const
DENG2_PIMPL_NOREF(Lumobj)
{
Source *source; ///< Source of the lumobj (if any, not owned).
Vector3d origin; ///< Position in map space.
BspLeaf *bspLeaf; ///< BSP leaf at @ref origin in the map (not owned).
double maxDistance; ///< Used when rendering to limit the number drawn lumobjs.
Vector3f color; ///< Light color/intensity.
double radius; ///< Radius in map space units.
Expand All @@ -56,7 +54,6 @@ DENG2_PIMPL_NOREF(Lumobj)

Instance()
: source (0),
bspLeaf (0),
maxDistance(0),
color (Vector3f(1, 1, 1)),
radius (256),
Expand All @@ -70,8 +67,6 @@ DENG2_PIMPL_NOREF(Lumobj)

Instance(Instance const &other)
: source (other.source),
origin (other.origin),
bspLeaf (other.bspLeaf),
maxDistance(other.maxDistance),
color (other.color),
radius (other.radius),
Expand All @@ -85,57 +80,21 @@ DENG2_PIMPL_NOREF(Lumobj)
};

Lumobj::Lumobj(Vector3d const &origin, double radius, Vector3f const &color)
: MapObject(), d(new Instance())
: MapObject(origin), d(new Instance())
{
setOrigin(origin);
setRadius(radius);
setColor(color);
}

Lumobj::Lumobj(Lumobj const &other) : MapObject(), d(new Instance(*other.d))
Lumobj::Lumobj(Lumobj const &other)
: MapObject(other.origin()), d(new Instance(*other.d))
{}

void Lumobj::setSource(Source *newSource)
{
d->source = newSource;
}

Vector3d const &Lumobj::origin() const
{
return d->origin;
}

Lumobj &Lumobj::setOrigin(Vector3d const &newOrigin)
{
if(d->origin != newOrigin)
{
// When moving on the XY plane; invalidate the BSP leaf.
if(!de::fequal(d->origin.x, newOrigin.x) ||
!de::fequal(d->origin.y, newOrigin.y))
{
d->bspLeaf = 0;
}

d->origin = newOrigin;
}
return *this;
}

void Lumobj::move(Vector3d const &delta)
{
setOrigin(d->origin + delta);
}

BspLeaf &Lumobj::bspLeafAtOrigin() const
{
if(!d->bspLeaf)
{
// Determine this now.
d->bspLeaf = &map().bspLeafAt(origin());
}
return *d->bspLeaf;
}

de::Vector3f const &Lumobj::color() const
{
return d->color;
Expand Down
48 changes: 46 additions & 2 deletions doomsday/client/src/world/mapobject.cpp
Expand Up @@ -27,14 +27,58 @@ DENG2_PIMPL_NOREF(MapObject)
{
Map *map;
int indexInMap;
Vector3d origin; ///< Position in map space.
BspLeaf *bspLeaf; ///< BSP leaf at @ref origin in the map (not owned).

Instance() : map(0), indexInMap(NoIndex)
Instance(Vector3d const &origin)
: map(0),
indexInMap(NoIndex),
origin(origin),
bspLeaf(0)
{}
};

MapObject::MapObject() : d(new Instance())
MapObject::MapObject(Vector3d const &origin) : d(new Instance(origin))
{}

MapObject::~MapObject()
{}

Vector3d const &MapObject::origin() const
{
return d->origin;
}

void MapObject::setOrigin(Vector3d const &newOrigin)
{
if(d->origin != newOrigin)
{
// When moving on the XY plane; invalidate the BSP leaf.
if(!de::fequal(d->origin.x, newOrigin.x) ||
!de::fequal(d->origin.y, newOrigin.y))
{
d->bspLeaf = 0;
}

d->origin = newOrigin;
}
}

void MapObject::move(Vector3d const &delta)
{
setOrigin(d->origin + delta);
}

BspLeaf &MapObject::bspLeafAtOrigin() const
{
if(!d->bspLeaf)
{
// Determine this now.
d->bspLeaf = &map().bspLeafAt(origin());
}
return *d->bspLeaf;
}

bool MapObject::hasMap() const
{
return d->map != 0;
Expand Down

0 comments on commit 4b55be5

Please sign in to comment.