diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index 88056f9c..1587901f 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -66,7 +66,7 @@ void e2d::Game::start() } else { - // ID2D1HwndRenderTarget 在渲染时会等待显示器刷新,即开启了垂直同步, + // ID2D1HwndRenderTarget 开启了垂直同步,在渲染时会等待显示器刷新, // 它起到了非常稳定的延时作用,所以大部分时候不需要手动挂起线程进行延时。 // 下面的代码仅在一些情况下(例如窗口最小化时)挂起线程,防止占用过高 CPU 。 int wait = minInterval - dur.milliseconds(); diff --git a/core/Tool/Task.cpp b/core/Tool/Task.cpp index 1d1984e4..17b1a53c 100644 --- a/core/Tool/Task.cpp +++ b/core/Tool/Task.cpp @@ -23,18 +23,18 @@ e2d::Task::Task(const Function & func, float delay, int times, const String & na { } -void e2d::Task::pause() +void e2d::Task::start() +{ + _running = true; + _lastTime = Time::now(); +} + +void e2d::Task::stop() { _running = false; } -void e2d::Task::resume() -{ - _running = true; - updateTime(); -} - -void e2d::Task::update() +void e2d::Task::_update() { if (_totalTimes == 0) { @@ -57,7 +57,7 @@ void e2d::Task::update() } } -bool e2d::Task::isReady() const +bool e2d::Task::_isReady() const { if (_running) { @@ -82,8 +82,3 @@ e2d::String e2d::Task::getName() const { return _name; } - -void e2d::Task::updateTime() -{ - _lastTime = Time::now(); -} diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index 91beddc1..a7e72f82 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -35,30 +35,30 @@ void e2d::Timer::addTask(Task * task) if (iter == _tasks.end()) { task->retain(); - task->updateTime(); + task->_lastTime = Time::now(); _tasks.push_back(task); } } } -void e2d::Timer::pauseTasks(const String& name) +void e2d::Timer::stopTasks(const String& name) { for (auto task : _tasks) { if (task->getName() == name) { - task->pause(); + task->stop(); } } } -void e2d::Timer::resumeTasks(const String& name) +void e2d::Timer::startTasks(const String& name) { for (auto task : _tasks) { if (task->getName() == name) { - task->resume(); + task->start(); } } } @@ -74,19 +74,19 @@ void e2d::Timer::removeTasks(const String& name) } } -void e2d::Timer::pauseAllTasks() +void e2d::Timer::stopAllTasks() { for (auto task : _tasks) { - task->pause(); + task->stop(); } } -void e2d::Timer::resumeAllTasks() +void e2d::Timer::startAllTasks() { for (auto task : _tasks) { - task->resume(); + task->start(); } } @@ -126,13 +126,13 @@ void e2d::Timer::update() } else { - // 更新定时器 - if (task->isReady()) - { - task->update(); - } - ++i; + + // 更新定时器 + if (task->_isReady()) + { + task->_update(); + } } } } @@ -141,6 +141,6 @@ void e2d::Timer::updateTime() { for (auto task : _tasks) { - task->updateTime(); + task->_lastTime = Time::now(); } } diff --git a/core/e2dtool.h b/core/e2dtool.h index 686f3997..352b24f3 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -245,14 +245,11 @@ public: const String& name = L"" /* 任务名称 */ ); - // 暂停任务 - void pause(); + // 启动任务 + void start(); - // 继续任务 - void resume(); - - // 任务是否就绪 - bool isReady() const; + // 停止任务 + void stop(); // 任务是否正在执行 bool isRunning() const; @@ -260,11 +257,12 @@ public: // 获取任务名称 String getName() const; +protected: // 执行任务 - void update(); + void _update(); - // 刷新任务计时 - void updateTime(); + // 任务是否就绪 + bool _isReady() const; private: bool _running; @@ -293,13 +291,13 @@ public: Task * task ); - // 继续任务 - void resumeTasks( + // 启动任务 + void startTasks( const String& taskName ); - // 暂停任务 - void pauseTasks( + // 停止任务 + void stopTasks( const String& taskName ); @@ -308,11 +306,11 @@ public: const String& taskName ); - // 继续所有任务 - void resumeAllTasks(); + // 启动所有任务 + void startAllTasks(); - // 暂停所有任务 - void pauseAllTasks(); + // 停止所有任务 + void stopAllTasks(); // 移除所有任务 void removeAllTasks();