细节优化

This commit is contained in:
Nomango 2018-05-14 22:51:40 +08:00
parent 6d45a70ff2
commit 2c13083c09
16 changed files with 42 additions and 40 deletions

View File

@ -65,7 +65,7 @@ void e2d::Animate::_update()
} }
_last += _animation->getInterval(); _last += _animation->getInterval();
_frameIndex++; ++_frameIndex;
if (_frameIndex == frames.size()) if (_frameIndex == frames.size())
{ {

View File

@ -63,7 +63,7 @@ void e2d::Loop::_update()
if (_action->_isDone()) if (_action->_isDone())
{ {
_times++; ++_times;
Action::reset(); Action::reset();
_action->reset(); _action->reset();

View File

@ -48,7 +48,7 @@ void e2d::Sequence::_update()
if (action->_isDone()) if (action->_isDone())
{ {
_currIndex++; ++_currIndex;
if (_currIndex == _actions.size()) if (_currIndex == _actions.size())
{ {
this->stop(); this->stop();

View File

@ -45,7 +45,7 @@ void e2d::Spawn::_update()
{ {
if (action->_isDone()) if (action->_isDone())
{ {
doneNum++; ++doneNum;
} }
else else
{ {

View File

@ -6,10 +6,12 @@
using namespace e2d; using namespace e2d;
#define BUFFER_SIZE 256
static IDirectInput8* s_pDirectInput = nullptr; // DirectInput 接口对象 static IDirectInput8* s_pDirectInput = nullptr; // DirectInput 接口对象
static IDirectInputDevice8* s_KeyboardDevice = nullptr; // 键盘设备接口 static IDirectInputDevice8* s_KeyboardDevice = nullptr; // 键盘设备接口
static char s_KeyBuffer[256] = { 0 }; // 用于保存键盘按键信息缓冲区 static char s_KeyBuffer[BUFFER_SIZE] = { 0 }; // 用于保存键盘按键信息缓冲区
static char s_KeyRecordBuffer[256] = { 0 }; // 键盘消息二级缓冲区 static char s_KeyRecordBuffer[BUFFER_SIZE] = { 0 }; // 键盘消息二级缓冲区
static IDirectInputDevice8* s_MouseDevice = nullptr; // 鼠标设备接口 static IDirectInputDevice8* s_MouseDevice = nullptr; // 鼠标设备接口
static DIMOUSESTATE s_MouseState; // 鼠标信息存储结构体 static DIMOUSESTATE s_MouseState; // 鼠标信息存储结构体
@ -113,7 +115,7 @@ void Input::__updateDeviceState()
} }
else else
{ {
for (int i = 0; i < 256; i++) for (int i = 0; i < BUFFER_SIZE; ++i)
s_KeyRecordBuffer[i] = s_KeyBuffer[i]; s_KeyRecordBuffer[i] = s_KeyBuffer[i];
s_KeyboardDevice->GetDeviceState(sizeof(s_KeyBuffer), (void**)&s_KeyBuffer); s_KeyboardDevice->GetDeviceState(sizeof(s_KeyBuffer), (void**)&s_KeyBuffer);

View File

@ -171,7 +171,7 @@ void e2d::Renderer::__render()
static double s_fLastRenderTime = 0; static double s_fLastRenderTime = 0;
static String s_sFpsText; static String s_sFpsText;
s_nRenderTimes++; ++s_nRenderTimes;
double fDelay = Time::getTotalTime() - s_fLastRenderTime; double fDelay = Time::getTotalTime() - s_fLastRenderTime;
if (fDelay >= 0.3) if (fDelay >= 0.3)

View File

@ -14,7 +14,7 @@ e2d::Object::~Object()
// 引用计数加一 // 引用计数加一
void e2d::Object::retain() void e2d::Object::retain()
{ {
_refCount++; ++_refCount;
} }
// 引用计数减一 // 引用计数减一

View File

@ -345,7 +345,7 @@ unsigned int e2d::String::getHashCode() const
{ {
unsigned int hash = 0; 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 *= 16777619;
hash ^= (unsigned int)towupper(_str[i]); hash ^= (unsigned int)towupper(_str[i]);
@ -373,7 +373,7 @@ e2d::String e2d::String::toUpper() const
{ {
String str(*this); 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]); str[i] = towupper(str[i]);
return std::move(str); return std::move(str);
@ -383,7 +383,7 @@ e2d::String e2d::String::toLower() const
{ {
e2d::String str(*this); 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]); str[i] = towlower(str[i]);
return std::move(str); return std::move(str);
@ -391,7 +391,7 @@ e2d::String e2d::String::toLower() const
int e2d::String::toInt() const int e2d::String::toInt() const
{ {
if (getLength() == 0) if (_str.empty())
{ {
return 0; return 0;
} }
@ -400,7 +400,7 @@ int e2d::String::toInt() const
double e2d::String::toDouble() const double e2d::String::toDouble() const
{ {
if (getLength() == 0) if (_str.empty())
{ {
return 0.0; return 0.0;
} }
@ -409,7 +409,7 @@ double e2d::String::toDouble() const
bool e2d::String::toBool() const bool e2d::String::toBool() const
{ {
if (getLength() == 0) if (_str.empty())
{ {
return false; return false;
} }
@ -424,7 +424,7 @@ bool e2d::String::toBool() const
e2d::String e2d::String::subtract(int offset, int count) const e2d::String e2d::String::subtract(int offset, int count) const
{ {
String tmp; String tmp;
int length = getLength(); int length = static_cast<int>(_str.size());
if (length == 0 || offset >= length) if (length == 0 || offset >= length)
return std::move(tmp); return std::move(tmp);

View File

@ -11,7 +11,7 @@ void e2d::ActionManager::__update()
return; 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]; auto action = s_vRunningActions[i];
// 获取动作运行状态 // 获取动作运行状态
@ -51,7 +51,7 @@ void e2d::ActionManager::__remove(Action * action)
} }
else else
{ {
i++; ++i;
} }
} }
} }
@ -171,7 +171,7 @@ void e2d::ActionManager::__clearAllBindedWith(Node * target)
} }
else else
{ {
i++; ++i;
} }
} }
} }

View File

@ -57,7 +57,7 @@ void e2d::ColliderManager::__update()
if (s_vListeners.empty() || Game::isPaused()) if (s_vListeners.empty() || Game::isPaused())
return; 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]; auto listener = s_vListeners[i];
// 清除已停止的监听器 // 清除已停止的监听器
@ -88,7 +88,7 @@ void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
Scene* pCurrentScene = pActiveNode->getParentScene(); 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]; auto pPassiveCollider = s_vColliders[i];
// 判断两个碰撞体是否是同一个对象 // 判断两个碰撞体是否是同一个对象
@ -242,7 +242,7 @@ void e2d::ColliderManager::__removeCollider(Collider * pCollider)
{ {
if (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) if (s_vColliders[i] == pCollider)
{ {

View File

@ -105,7 +105,7 @@ void e2d::InputManager::__update()
if (s_vListeners.empty() || Game::isPaused()) if (s_vListeners.empty() || Game::isPaused())
return; 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]; auto listener = s_vListeners[i];
// 清除已停止的监听器 // 清除已停止的监听器

View File

@ -27,7 +27,7 @@ void e2d::ObjectManager::__update()
} }
else else
{ {
iter++; ++iter;
} }
} }
} }

View File

@ -59,7 +59,7 @@ bool e2d::Menu::removeButton(Button * button)
if (button) if (button)
{ {
size_t size = _buttons.size(); 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) if (_buttons[i] == button)
{ {

View File

@ -75,7 +75,7 @@ void e2d::Node::_update()
// 遍历子节点 // 遍历子节点
size_t size = _children.size(); size_t size = _children.size();
size_t i; size_t i;
for (i = 0; i < size; i++) for (i = 0; i < size; ++i)
{ {
auto child = _children[i]; auto child = _children[i];
// 访问 Order 小于零的节点 // 访问 Order 小于零的节点
@ -99,7 +99,7 @@ void e2d::Node::_update()
} }
// 访问剩余节点 // 访问剩余节点
for (; i < size; i++) for (; i < size; ++i)
_children[i]->_update(); _children[i]->_update();
} }
else else
@ -126,7 +126,7 @@ void e2d::Node::_render()
{ {
size_t size = _children.size(); size_t size = _children.size();
size_t i; size_t i;
for (i = 0; i < size; i++) for (i = 0; i < size; ++i)
{ {
auto child = _children[i]; auto child = _children[i];
// 访问 Order 小于零的节点 // 访问 Order 小于零的节点
@ -146,7 +146,7 @@ void e2d::Node::_render()
this->onRender(); this->onRender();
// 访问剩余节点 // 访问剩余节点
for (; i < size; i++) for (; i < size; ++i)
_children[i]->_render(); _children[i]->_render();
} }
else else
@ -725,7 +725,7 @@ bool e2d::Node::removeChild(Node * child)
if (child) if (child)
{ {
size_t size = _children.size(); 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) if (_children[i] == child)
{ {
@ -758,7 +758,7 @@ void e2d::Node::removeChildren(const String& childName)
unsigned int hash = childName.getHashCode(); unsigned int hash = childName.getHashCode();
size_t size = _children.size(); 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]; auto child = _children[i];
if (child->_hashName == hash && child->_name == childName) if (child->_hashName == hash && child->_name == childName)
@ -859,7 +859,7 @@ std::vector<e2d::Action*> e2d::Node::getActions(const String& strActionName)
} }
else else
{ {
iter++; ++iter;
} }
} }
return std::move(actions); return std::move(actions);

View File

@ -507,7 +507,7 @@ bool MusicPlayer::_read(BYTE* pBuffer, DWORD dwSizeToRead)
_ck.cksize -= cbDataIn; _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. // Copy the bytes from the io to the buffer.
if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead) if (mmioinfoIn.pchNext == mmioinfoIn.pchEndRead)
@ -521,7 +521,7 @@ bool MusicPlayer::_read(BYTE* pBuffer, DWORD dwSizeToRead)
// Actual copy. // Actual copy.
*((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext); *((BYTE*)pBuffer + cT) = *((BYTE*)mmioinfoIn.pchNext);
mmioinfoIn.pchNext++; ++mmioinfoIn.pchNext;
} }
if (0 != mmioSetInfo(_hmmio, &mmioinfoIn, 0)) if (0 != mmioSetInfo(_hmmio, &mmioinfoIn, 0))

View File

@ -24,17 +24,17 @@ public:
void update() void update()
{ {
if (this->callback) if (callback)
{ {
this->callback(); callback();
} }
this->runTimes++; ++runTimes;
this->lastTime += this->delay; lastTime += delay;
if (this->runTimes == this->totalTimes) if (runTimes == totalTimes)
{ {
this->stopped = true; stopped = true;
} }
} }