From 2c13083c099eca7793b1ef6ffdb44c5bc6ecb93a Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Mon, 14 May 2018 22:51:40 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/Animate.cpp | 2 +- core/Action/Loop.cpp | 2 +- core/Action/Sequence.cpp | 2 +- core/Action/Spawn.cpp | 2 +- core/Base/Input.cpp | 8 +++++--- core/Base/Renderer.cpp | 2 +- core/Common/Object.cpp | 2 +- core/Common/String.cpp | 14 +++++++------- core/Manager/ActionManager.cpp | 6 +++--- core/Manager/ColliderManager.cpp | 6 +++--- core/Manager/InputManager.cpp | 2 +- core/Manager/ObjectManager.cpp | 2 +- core/Node/Menu.cpp | 2 +- core/Node/Node.cpp | 14 +++++++------- core/Tool/Music.cpp | 4 ++-- core/Tool/Timer.cpp | 12 ++++++------ 16 files changed, 42 insertions(+), 40 deletions(-) diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp index 68bff3b0..4b1c296a 100644 --- a/core/Action/Animate.cpp +++ b/core/Action/Animate.cpp @@ -65,7 +65,7 @@ void e2d::Animate::_update() } _last += _animation->getInterval(); - _frameIndex++; + ++_frameIndex; if (_frameIndex == frames.size()) { diff --git a/core/Action/Loop.cpp b/core/Action/Loop.cpp index e43baba3..efff147f 100644 --- a/core/Action/Loop.cpp +++ b/core/Action/Loop.cpp @@ -63,7 +63,7 @@ void e2d::Loop::_update() if (_action->_isDone()) { - _times++; + ++_times; Action::reset(); _action->reset(); diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index 82d58c9d..5a5b11b4 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -48,7 +48,7 @@ void e2d::Sequence::_update() if (action->_isDone()) { - _currIndex++; + ++_currIndex; if (_currIndex == _actions.size()) { this->stop(); diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index d92a51d2..e4cb08cb 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -45,7 +45,7 @@ void e2d::Spawn::_update() { if (action->_isDone()) { - doneNum++; + ++doneNum; } else { diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index d29f1ad4..2d644021 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -6,10 +6,12 @@ using namespace e2d; +#define BUFFER_SIZE 256 + static IDirectInput8* s_pDirectInput = nullptr; // DirectInput 接口对象 static IDirectInputDevice8* s_KeyboardDevice = nullptr; // 键盘设备接口 -static char s_KeyBuffer[256] = { 0 }; // 用于保存键盘按键信息缓冲区 -static char s_KeyRecordBuffer[256] = { 0 }; // 键盘消息二级缓冲区 +static char s_KeyBuffer[BUFFER_SIZE] = { 0 }; // 用于保存键盘按键信息缓冲区 +static char s_KeyRecordBuffer[BUFFER_SIZE] = { 0 }; // 键盘消息二级缓冲区 static IDirectInputDevice8* s_MouseDevice = nullptr; // 鼠标设备接口 static DIMOUSESTATE s_MouseState; // 鼠标信息存储结构体 @@ -113,7 +115,7 @@ void Input::__updateDeviceState() } else { - for (int i = 0; i < 256; i++) + for (int i = 0; i < BUFFER_SIZE; ++i) s_KeyRecordBuffer[i] = s_KeyBuffer[i]; s_KeyboardDevice->GetDeviceState(sizeof(s_KeyBuffer), (void**)&s_KeyBuffer); diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index 78903e55..e4805fcf 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -171,7 +171,7 @@ void e2d::Renderer::__render() static double s_fLastRenderTime = 0; static String s_sFpsText; - s_nRenderTimes++; + ++s_nRenderTimes; double fDelay = Time::getTotalTime() - s_fLastRenderTime; if (fDelay >= 0.3) diff --git a/core/Common/Object.cpp b/core/Common/Object.cpp index 70b140da..fbb405b3 100644 --- a/core/Common/Object.cpp +++ b/core/Common/Object.cpp @@ -14,7 +14,7 @@ e2d::Object::~Object() // 引用计数加一 void e2d::Object::retain() { - _refCount++; + ++_refCount; } // 引用计数减一 diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 06772062..11bd1c1e 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -345,7 +345,7 @@ unsigned int e2d::String::getHashCode() const { unsigned int hash = 0; - for (int i = 0; i < getLength(); i++) + for (size_t i = 0, length = _str.size(); i < length; ++i) { hash *= 16777619; hash ^= (unsigned int)towupper(_str[i]); @@ -373,7 +373,7 @@ e2d::String e2d::String::toUpper() const { String str(*this); - for (int i = 0; i < getLength(); i++) + for (size_t i = 0, length = _str.size(); i < length; ++i) str[i] = towupper(str[i]); return std::move(str); @@ -383,7 +383,7 @@ e2d::String e2d::String::toLower() const { e2d::String str(*this); - for (int i = 0; i < getLength(); i++) + for (size_t i = 0, length = _str.size(); i < length; ++i) str[i] = towlower(str[i]); return std::move(str); @@ -391,7 +391,7 @@ e2d::String e2d::String::toLower() const int e2d::String::toInt() const { - if (getLength() == 0) + if (_str.empty()) { return 0; } @@ -400,7 +400,7 @@ int e2d::String::toInt() const double e2d::String::toDouble() const { - if (getLength() == 0) + if (_str.empty()) { return 0.0; } @@ -409,7 +409,7 @@ double e2d::String::toDouble() const bool e2d::String::toBool() const { - if (getLength() == 0) + if (_str.empty()) { return false; } @@ -424,7 +424,7 @@ bool e2d::String::toBool() const e2d::String e2d::String::subtract(int offset, int count) const { String tmp; - int length = getLength(); + int length = static_cast(_str.size()); if (length == 0 || offset >= length) return std::move(tmp); diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index aa6f800a..b379952e 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -11,7 +11,7 @@ void e2d::ActionManager::__update() return; // 循环遍历所有正在运行的动作 - for (size_t i = 0; i < s_vRunningActions.size(); i++) + for (size_t i = 0; i < s_vRunningActions.size(); ++i) { auto action = s_vRunningActions[i]; // 获取动作运行状态 @@ -51,7 +51,7 @@ void e2d::ActionManager::__remove(Action * action) } else { - i++; + ++i; } } } @@ -171,7 +171,7 @@ void e2d::ActionManager::__clearAllBindedWith(Node * target) } else { - i++; + ++i; } } } diff --git a/core/Manager/ColliderManager.cpp b/core/Manager/ColliderManager.cpp index 74cbe03e..ad305f28 100644 --- a/core/Manager/ColliderManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -57,7 +57,7 @@ void e2d::ColliderManager::__update() if (s_vListeners.empty() || Game::isPaused()) return; - for (size_t i = 0; i < s_vListeners.size(); i++) + for (size_t i = 0; i < s_vListeners.size(); ++i) { auto listener = s_vListeners[i]; // 清除已停止的监听器 @@ -88,7 +88,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider) Scene* pCurrentScene = pActiveNode->getParentScene(); // 判断与其他碰撞体的交集情况 - for (size_t i = 0; i < s_vColliders.size(); i++) + for (size_t i = 0; i < s_vColliders.size(); ++i) { auto pPassiveCollider = s_vColliders[i]; // 判断两个碰撞体是否是同一个对象 @@ -242,7 +242,7 @@ void e2d::ColliderManager::__removeCollider(Collider * pCollider) { if (pCollider) { - for (size_t i = 0; i < s_vColliders.size(); i++) + for (size_t i = 0; i < s_vColliders.size(); ++i) { if (s_vColliders[i] == pCollider) { diff --git a/core/Manager/InputManager.cpp b/core/Manager/InputManager.cpp index 79f35af1..50c65206 100644 --- a/core/Manager/InputManager.cpp +++ b/core/Manager/InputManager.cpp @@ -105,7 +105,7 @@ void e2d::InputManager::__update() if (s_vListeners.empty() || Game::isPaused()) return; - for (size_t i = 0; i < s_vListeners.size(); i++) + for (size_t i = 0; i < s_vListeners.size(); ++i) { auto listener = s_vListeners[i]; // 清除已停止的监听器 diff --git a/core/Manager/ObjectManager.cpp b/core/Manager/ObjectManager.cpp index 2111df92..0836d6b0 100644 --- a/core/Manager/ObjectManager.cpp +++ b/core/Manager/ObjectManager.cpp @@ -27,7 +27,7 @@ void e2d::ObjectManager::__update() } else { - iter++; + ++iter; } } } diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index ca4aa46c..85617f87 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -59,7 +59,7 @@ bool e2d::Menu::removeButton(Button * button) if (button) { size_t size = _buttons.size(); - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { if (_buttons[i] == button) { diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index bd4041d2..6adb5535 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -75,7 +75,7 @@ void e2d::Node::_update() // 遍历子节点 size_t size = _children.size(); size_t i; - for (i = 0; i < size; i++) + for (i = 0; i < size; ++i) { auto child = _children[i]; // 访问 Order 小于零的节点 @@ -99,7 +99,7 @@ void e2d::Node::_update() } // 访问剩余节点 - for (; i < size; i++) + for (; i < size; ++i) _children[i]->_update(); } else @@ -126,7 +126,7 @@ void e2d::Node::_render() { size_t size = _children.size(); size_t i; - for (i = 0; i < size; i++) + for (i = 0; i < size; ++i) { auto child = _children[i]; // 访问 Order 小于零的节点 @@ -146,7 +146,7 @@ void e2d::Node::_render() this->onRender(); // 访问剩余节点 - for (; i < size; i++) + for (; i < size; ++i) _children[i]->_render(); } else @@ -725,7 +725,7 @@ bool e2d::Node::removeChild(Node * child) if (child) { size_t size = _children.size(); - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { if (_children[i] == child) { @@ -758,7 +758,7 @@ void e2d::Node::removeChildren(const String& childName) unsigned int hash = childName.getHashCode(); size_t size = _children.size(); - for (size_t i = 0; i < size; i++) + for (size_t i = 0; i < size; ++i) { auto child = _children[i]; if (child->_hashName == hash && child->_name == childName) @@ -859,7 +859,7 @@ std::vector e2d::Node::getActions(const String& strActionName) } else { - iter++; + ++iter; } } return std::move(actions); diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index aa6502b3..d6627e26 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -507,7 +507,7 @@ bool MusicPlayer::_read(BYTE* pBuffer, DWORD dwSizeToRead) _ck.cksize -= cbDataIn; - for (DWORD cT = 0; cT < cbDataIn; cT++) + for (DWORD cT = 0; cT < cbDataIn; ++cT) { // Copy the bytes from the io to the buffer. if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) @@ -521,7 +521,7 @@ bool MusicPlayer::_read(BYTE* pBuffer, DWORD dwSizeToRead) // Actual copy. *((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext); - mmioinfoIn.pchNext++; + ++mmioinfoIn.pchNext; } if (0 != mmioSetInfo(_hmmio, &mmioinfoIn, 0)) diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index 9e64a809..ad83846c 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -24,17 +24,17 @@ public: void update() { - if (this->callback) + if (callback) { - this->callback(); + callback(); } - this->runTimes++; - this->lastTime += this->delay; + ++runTimes; + lastTime += delay; - if (this->runTimes == this->totalTimes) + if (runTimes == totalTimes) { - this->stopped = true; + stopped = true; } }