Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libdoomsday: Added ThinkerData and MobjThinkerData
Base classes to be used for all private data of thinkers. The lowest base class provides a Doomsday Script namespace, while the mobj-specific one contains common internal functionality shared by the server and the client.
- Loading branch information
Showing
6 changed files
with
257 additions
and
11 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
doomsday/libdoomsday/include/doomsday/world/mobjthinkerdata.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** @file mobjthinkerdata.h | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @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> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_MOBJTHINKERDATA_H | ||
#define LIBDOOMSDAY_MOBJTHINKERDATA_H | ||
|
||
#include "thinkerdata.h" | ||
#include "mobj.h" | ||
|
||
/** | ||
* Private mobj data common to both client and server. | ||
* | ||
* @todo Game-side IData should be here; eventually the games don't need to add any | ||
* custom members to mobj_s, just to their own private data instance. -jk | ||
*/ | ||
class MobjThinkerData : public ThinkerData | ||
{ | ||
public: | ||
MobjThinkerData(mobj_t *mobj); | ||
MobjThinkerData(MobjThinkerData const &other); | ||
|
||
IData *duplicate() const; | ||
|
||
mobj_t *mobj(); | ||
mobj_t const *mobj() const; | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
}; | ||
|
||
#endif // LIBDOOMSDAY_MOBJTHINKERDATA_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,68 @@ | ||
/** @file thinkerdata.h Base class for thinker private data. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @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> | ||
*/ | ||
|
||
#ifndef LIBDOOMSDAY_THINKERDATA_H | ||
#define LIBDOOMSDAY_THINKERDATA_H | ||
|
||
#include "thinker.h" | ||
|
||
#include <de/Record> | ||
#include <de/Id> | ||
|
||
/** | ||
* Base class for thinker private data. | ||
* | ||
* Contains internal functionality common to all thinkers regardless of their type. | ||
*/ | ||
class LIBDOOMSDAY_PUBLIC ThinkerData : public Thinker::IData | ||
{ | ||
public: | ||
ThinkerData(thinker_s *self); | ||
ThinkerData(ThinkerData const &other); | ||
|
||
IData *duplicate() const; | ||
|
||
thinker_s &thinker(); | ||
thinker_s const &thinker() const; | ||
|
||
de::Record &info(); | ||
de::Record const &info() const; | ||
|
||
private: | ||
DENG2_PRIVATE(d) | ||
|
||
#ifdef DENG2_DEBUG | ||
public: | ||
struct DebugCounter { | ||
de::Id id; | ||
static duint32 total; | ||
|
||
DebugCounter() { total++; } | ||
~DebugCounter() { total--; } | ||
}; | ||
DebugCounter _debugCounter; | ||
|
||
struct DebugValidator { | ||
DebugValidator() { DENG2_ASSERT(DebugCounter::total == 0); } | ||
~DebugValidator() { DENG2_ASSERT(DebugCounter::total == 0); } | ||
}; | ||
#endif | ||
}; | ||
|
||
#endif // LIBDOOMSDAY_THINKERDATA_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,50 @@ | ||
/** @file mobjthinkerdata.cpp | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @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 "doomsday/world/mobjthinkerdata.h" | ||
|
||
using namespace de; | ||
|
||
DENG2_PIMPL_NOREF(MobjThinkerData) | ||
{}; | ||
|
||
MobjThinkerData::MobjThinkerData(mobj_t *mobj) | ||
: ThinkerData(&mobj->thinker) | ||
, d(new Instance) | ||
{} | ||
|
||
MobjThinkerData::MobjThinkerData(MobjThinkerData const &other) | ||
: ThinkerData(other) | ||
, d(new Instance) | ||
{} | ||
|
||
Thinker::IData *MobjThinkerData::duplicate() const | ||
{ | ||
return new MobjThinkerData(*this); | ||
} | ||
|
||
mobj_t *MobjThinkerData::mobj() | ||
{ | ||
return reinterpret_cast<mobj_t *>(&thinker()); | ||
} | ||
|
||
mobj_t const *MobjThinkerData::mobj() const | ||
{ | ||
return reinterpret_cast<mobj_t const *>(&thinker()); | ||
} |
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,74 @@ | ||
/** @file thinkerdata.cpp Base class for thinker private data. | ||
* | ||
* @authors Copyright (c) 2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @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 "doomsday/world/thinkerdata.h" | ||
|
||
using namespace de; | ||
|
||
DENG2_PIMPL(ThinkerData) | ||
{ | ||
thinker_s *think; | ||
Record info; | ||
|
||
Instance(Public *i) : Base(i), think(0) {} | ||
|
||
Instance(Public *i, Instance const &other) | ||
: Base(i) | ||
, think(other.think) | ||
, info(other.info) | ||
{} | ||
}; | ||
|
||
ThinkerData::ThinkerData(thinker_s *self) : d(new Instance(this)) | ||
{ | ||
d->think = self; | ||
} | ||
|
||
ThinkerData::ThinkerData(ThinkerData const &other) : d(new Instance(this, *other.d)) | ||
{} | ||
|
||
Thinker::IData *ThinkerData::duplicate() const | ||
{ | ||
return new ThinkerData(*this); | ||
} | ||
|
||
thinker_s &ThinkerData::thinker() | ||
{ | ||
return *d->think; | ||
} | ||
|
||
thinker_s const &ThinkerData::thinker() const | ||
{ | ||
return *d->think; | ||
} | ||
|
||
Record &ThinkerData::info() | ||
{ | ||
return d->info; | ||
} | ||
|
||
Record const &ThinkerData::info() const | ||
{ | ||
return d->info; | ||
} | ||
|
||
#ifdef DENG2_DEBUG | ||
duint32 ThinkerData::DebugCounter::total = 0; | ||
ThinkerData::DebugValidator ensureAllPrivateDataIsReleased; | ||
#endif |