diff --git a/include/core/director.h b/include/core/director.h index 31350ab..5ebe532 100644 --- a/include/core/director.h +++ b/include/core/director.h @@ -20,8 +20,8 @@ public: void mainLoop(float dt); void mainLoopParallel(float dt); - Scheduler& sched() { return *sched_; } - SvcMgr& svcs() { return *svcMgr_; } + Scheduler& sched() { return SCHED; } + SvcMgr& svcs() { return SVC_MGR; } float dt() const { return dt_; } float totalTime() const { return totalTime_; } @@ -36,9 +36,6 @@ public: private: Director() = default; - Unique sched_; - Unique svcMgr_; - float dt_ = 0.0f; float totalTime_ = 0.0f; float fixedAccumulator_ = 0.0f; diff --git a/include/core/service.h b/include/core/service.h index bfec1d1..491ac4f 100644 --- a/include/core/service.h +++ b/include/core/service.h @@ -37,6 +37,8 @@ protected: IService() = default; bool inited_ = false; bool enabled_ = true; + + friend class SvcMgr; }; /** diff --git a/src/core/director.cpp b/src/core/director.cpp index 3311a2b..ab37340 100644 --- a/src/core/director.cpp +++ b/src/core/director.cpp @@ -10,9 +10,6 @@ Director& Director::inst() { bool Director::init() { if (inited_) return true; - sched_ = makeUnique(); - svcMgr_ = makeUnique(); - inited_ = true; return true; } @@ -20,11 +17,8 @@ bool Director::init() { void Director::shutdown() { if (!inited_) return; - svcMgr_->shutdownAll(); - sched_->unscheduleAll(); - - svcMgr_.reset(); - sched_.reset(); + SVC_MGR.shutdownAll(); + SCHED.unscheduleAll(); inited_ = false; } @@ -36,17 +30,17 @@ void Director::mainLoop(float dt) { totalTime_ += dt; frameCount_++; - svcMgr_->updateAll(dt); + SVC_MGR.updateAll(dt); fixedAccumulator_ += dt; while (fixedAccumulator_ >= fixedDt_) { - svcMgr_->fixedUpdateAll(fixedDt_); + SVC_MGR.fixedUpdateAll(fixedDt_); fixedAccumulator_ -= fixedDt_; } - sched_->update(dt); + SCHED.update(dt); - svcMgr_->lateUpdateAll(dt); + SVC_MGR.lateUpdateAll(dt); } void Director::mainLoopParallel(float dt) { @@ -56,17 +50,17 @@ void Director::mainLoopParallel(float dt) { totalTime_ += dt; frameCount_++; - svcMgr_->updateAll(dt); + SVC_MGR.updateAll(dt); fixedAccumulator_ += dt; while (fixedAccumulator_ >= fixedDt_) { - svcMgr_->fixedUpdateAll(fixedDt_); + SVC_MGR.fixedUpdateAll(fixedDt_); fixedAccumulator_ -= fixedDt_; } - sched_->updateParallel(dt); + SCHED.updateParallel(dt); - svcMgr_->lateUpdateAll(dt); + SVC_MGR.lateUpdateAll(dt); } void Director::pause() { @@ -78,7 +72,7 @@ void Director::resume() { } void Director::setTimeScale(float scale) { - sched_->setTimeScale(scale); + SCHED.setTimeScale(scale); } } // namespace extra2d