细节优化

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();
_frameIndex++;
++_frameIndex;
if (_frameIndex == frames.size())
{

View File

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

View File

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

View File

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

View File

@ -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);

View File

@ -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)

View File

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

View File

@ -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<int>(_str.size());
if (length == 0 || offset >= length)
return std::move(tmp);

View File

@ -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;
}
}
}

View File

@ -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)
{

View File

@ -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];
// 清除已停止的监听器

View File

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

View File

@ -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)
{

View File

@ -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::Action*> e2d::Node::getActions(const String& strActionName)
}
else
{
iter++;
++iter;
}
}
return std::move(actions);

View File

@ -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))

View File

@ -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;
}
}