Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor|Lumobj: Extracted MapObject from Lumobj
Todo for later: Mobj, Polyobj, SoundEmitter, etc... should all use this as their base.
- Loading branch information
1 parent
3012ed3
commit ee034f2
Showing
8 changed files
with
186 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "world/mapobject.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |