#include namespace extra2d { Director& Director::inst() { static Director instance; return instance; } bool Director::init() { if (inited_) return true; sched_ = makeUnique(); svcMgr_ = makeUnique(); inited_ = true; return true; } void Director::shutdown() { if (!inited_) return; svcMgr_->shutdownAll(); sched_->unscheduleAll(); svcMgr_.reset(); sched_.reset(); inited_ = false; } void Director::mainLoop(float dt) { if (paused_) return; dt_ = dt; totalTime_ += dt; frameCount_++; svcMgr_->updateAll(dt); fixedAccumulator_ += dt; while (fixedAccumulator_ >= fixedDt_) { svcMgr_->fixedUpdateAll(fixedDt_); fixedAccumulator_ -= fixedDt_; } sched_->update(dt); svcMgr_->lateUpdateAll(dt); } void Director::mainLoopParallel(float dt) { if (paused_) return; dt_ = dt; totalTime_ += dt; frameCount_++; svcMgr_->updateAll(dt); fixedAccumulator_ += dt; while (fixedAccumulator_ >= fixedDt_) { svcMgr_->fixedUpdateAll(fixedDt_); fixedAccumulator_ -= fixedDt_; } sched_->updateParallel(dt); svcMgr_->lateUpdateAll(dt); } void Director::pause() { paused_ = true; } void Director::resume() { paused_ = false; } void Director::setTimeScale(float scale) { sched_->setTimeScale(scale); } } // namespace extra2d