diff --git a/doomsday/client/include/client/clplanemover.h b/doomsday/client/include/client/clplanemover.h index 8e02c3dfed..cd8706acc9 100644 --- a/doomsday/client/include/client/clplanemover.h +++ b/doomsday/client/include/client/clplanemover.h @@ -51,9 +51,6 @@ class ClPlaneMover : public ThinkerData * @return The mover thinker. Ownership retained by the Plane's Map. */ static thinker_s *newThinker(Plane &plane, coord_t dest, float speed); - -protected: - static void thinkerFunc(thinker_s *mover); }; #endif // DENG_CLIENT_PLANEMOVER_H diff --git a/doomsday/client/include/client/clpolymover.h b/doomsday/client/include/client/clpolymover.h index 6a37468751..985ae639ce 100644 --- a/doomsday/client/include/client/clpolymover.h +++ b/doomsday/client/include/client/clpolymover.h @@ -42,9 +42,6 @@ class ClPolyMover : public ThinkerData void think(); static thinker_s *newThinker(Polyobj &polyobj, bool moving, bool rotating); - -protected: - static void thinkerFunc(thinker_s *mover); }; #endif // DENG_CLIENT_POLYMOVER_H diff --git a/doomsday/client/include/world/polyobjdata.h b/doomsday/client/include/world/polyobjdata.h index ba59a5bc7e..5696b62f50 100644 --- a/doomsday/client/include/world/polyobjdata.h +++ b/doomsday/client/include/world/polyobjdata.h @@ -47,6 +47,7 @@ class PolyobjData : public Thinker::IData ~PolyobjData(); void setThinker(thinker_s *thinker); + void think(); IData *duplicate() const; #ifdef __CLIENT__ diff --git a/doomsday/client/src/client/clplanemover.cpp b/doomsday/client/src/client/clplanemover.cpp index 731f5c029e..125a7cf682 100644 --- a/doomsday/client/src/client/clplanemover.cpp +++ b/doomsday/client/src/client/clplanemover.cpp @@ -33,7 +33,6 @@ using namespace de; thinker_s *ClPlaneMover::newThinker(Plane &plane, coord_t dest, float speed) // static { Thinker th(Thinker::AllocateMemoryZone); - th.function = (thinkfunc_t) thinkerFunc; th.setData(new ClPlaneMover(plane, dest, speed)); // Add to the map. @@ -142,8 +141,3 @@ void ClPlaneMover::think() } } } - -void ClPlaneMover::thinkerFunc(thinker_s *mover) // static -{ - THINKER_DATA(*mover, ClPlaneMover).think(); -} diff --git a/doomsday/client/src/client/clpolymover.cpp b/doomsday/client/src/client/clpolymover.cpp index 98e4afd2f9..27eb22353f 100644 --- a/doomsday/client/src/client/clpolymover.cpp +++ b/doomsday/client/src/client/clpolymover.cpp @@ -41,7 +41,6 @@ thinker_s *ClPolyMover::newThinker(Polyobj &polyobj, bool moving, bool rotating) } Thinker th(Thinker::AllocateMemoryZone); - th.function = (thinkfunc_t) thinkerFunc; th.setData(new ClPolyMover(polyobj, moving, rotating)); thinker_s *ptr = th.take(); @@ -125,8 +124,3 @@ void ClPolyMover::think() _polyobj->map().thinkers().remove(thinker()); // we get deleted } } - -void ClPolyMover::thinkerFunc(thinker_s *mover) -{ - THINKER_DATA(*mover, ClPolyMover).think(); -} diff --git a/doomsday/client/src/world/polyobjdata.cpp b/doomsday/client/src/world/polyobjdata.cpp index 5386dfbbd9..748761d89a 100644 --- a/doomsday/client/src/world/polyobjdata.cpp +++ b/doomsday/client/src/world/polyobjdata.cpp @@ -43,6 +43,11 @@ void PolyobjData::setThinker(thinker_s *thinker) _polyobj = (Polyobj *) thinker; } +void PolyobjData::think() +{ + // nothing to do; public thinker does all +} + Thinker::IData *PolyobjData::duplicate() const { return new PolyobjData(*this); diff --git a/doomsday/client/src/world/thinkers.cpp b/doomsday/client/src/world/thinkers.cpp index a1e5ccd75b..51400bc763 100644 --- a/doomsday/client/src/world/thinkers.cpp +++ b/doomsday/client/src/world/thinkers.cpp @@ -443,7 +443,11 @@ static int runThinker(thinker_t *th, void * /*context*/) initPrivateData(th); } + // Public thinker callback. th->function(th); + + // Private thinking. + if(th->d) THINKER_DATA(*th, Thinker::IData).think(); } return false; // Continue iteration. diff --git a/doomsday/libdoomsday/include/doomsday/world/thinker.h b/doomsday/libdoomsday/include/doomsday/world/thinker.h index be3eeb6d97..9acb20c9e2 100644 --- a/doomsday/libdoomsday/include/doomsday/world/thinker.h +++ b/doomsday/libdoomsday/include/doomsday/world/thinker.h @@ -67,6 +67,12 @@ LIBDOOMSDAY_PUBLIC dd_bool Thinker_InStasis(thinker_t const *thinker); */ LIBDOOMSDAY_PUBLIC void Thinker_SetStasis(thinker_t *thinker, dd_bool on); +/** + * Generic thinker function that does nothing. This can be used if the private + * data does all the thinking. + */ +LIBDOOMSDAY_PUBLIC void Thinker_NoOperation(void *thinker); + #ifdef __cplusplus } // extern "C" #endif @@ -123,6 +129,7 @@ class LIBDOOMSDAY_PUBLIC Thinker public: virtual ~IData() {} virtual void setThinker(thinker_s *thinker) = 0; + virtual void think() = 0; virtual IData *duplicate() const = 0; DENG2_AS_IS_METHODS() diff --git a/doomsday/libdoomsday/include/doomsday/world/thinkerdata.h b/doomsday/libdoomsday/include/doomsday/world/thinkerdata.h index f39f27b95a..d6375c9228 100644 --- a/doomsday/libdoomsday/include/doomsday/world/thinkerdata.h +++ b/doomsday/libdoomsday/include/doomsday/world/thinkerdata.h @@ -40,6 +40,7 @@ class LIBDOOMSDAY_PUBLIC ThinkerData : public Thinker::IData ThinkerData(ThinkerData const &other); void setThinker(thinker_s *thinker); + void think(); IData *duplicate() const; thinker_s &thinker(); diff --git a/doomsday/libdoomsday/src/world/thinker.cpp b/doomsday/libdoomsday/src/world/thinker.cpp index fe54736090..26e316f15c 100644 --- a/doomsday/libdoomsday/src/world/thinker.cpp +++ b/doomsday/libdoomsday/src/world/thinker.cpp @@ -111,12 +111,18 @@ DENG2_PIMPL_NOREF(Thinker) Thinker::Thinker(dsize sizeInBytes, IData *data) : d(new Instance(AllocateStandard, sizeInBytes, data)) , STRUCT_MEMBER_ACCESSORS() -{} +{ + // Default to no public thinker callback. + function = Thinker_NoOperation; +} Thinker::Thinker(AllocMethod alloc, dsize sizeInBytes, Thinker::IData *data) : d(new Instance(alloc, sizeInBytes, data)) , STRUCT_MEMBER_ACCESSORS() -{} +{ + // Default to no public thinker callback. + function = Thinker_NoOperation; +} Thinker::Thinker(Thinker const &other) : d(new Instance(*other.d)) @@ -275,3 +281,7 @@ void Thinker_SetStasis(thinker_t *thinker, dd_bool on) } } +void Thinker_NoOperation(void *) +{ + // do nothing +} diff --git a/doomsday/libdoomsday/src/world/thinkerdata.cpp b/doomsday/libdoomsday/src/world/thinkerdata.cpp index ffec23c3df..dc87e84cf2 100644 --- a/doomsday/libdoomsday/src/world/thinkerdata.cpp +++ b/doomsday/libdoomsday/src/world/thinkerdata.cpp @@ -58,6 +58,11 @@ void ThinkerData::setThinker(thinker_s *thinker) d->think = thinker; } +void ThinkerData::think() +{ + /// @todo If there is a think function in the Record, call it now. -jk +} + Thinker::IData *ThinkerData::duplicate() const { return new ThinkerData(*this);