细节优化

This commit is contained in:
Nomango 2018-07-08 02:48:04 +08:00
parent b7c4c409cb
commit 95392c19c3
4 changed files with 32 additions and 32 deletions

View File

@ -1,10 +1,8 @@
#include "..\e2dcommon.h"
#include "..\e2dbase.h"
#include "..\e2dtool.h"
#include <map>
static std::map<e2d::Resource, ID2D1Bitmap*> s_mBitmapsFromResource;
std::map<e2d::Resource, ID2D1Bitmap*> e2d::Image::_bitmapCache;
e2d::Image::Image()
: _bitmap(nullptr)
@ -62,7 +60,7 @@ bool e2d::Image::open(const Resource& res)
return false;
}
this->_setBitmap(s_mBitmapsFromResource.at(res));
this->_setBitmap(_bitmapCache.at(res));
return true;
}
@ -150,7 +148,7 @@ e2d::Point e2d::Image::getCropPos() const
bool e2d::Image::preload(const Resource& res)
{
if (s_mBitmapsFromResource.find(res) != s_mBitmapsFromResource.end())
if (_bitmapCache.find(res) != _bitmapCache.end())
{
return true;
}
@ -284,7 +282,7 @@ bool e2d::Image::preload(const Resource& res)
if (SUCCEEDED(hr))
{
s_mBitmapsFromResource.insert(std::make_pair(res, pBitmap));
_bitmapCache.insert(std::make_pair(res, pBitmap));
}
// 释放相关资源
@ -298,11 +296,11 @@ bool e2d::Image::preload(const Resource& res)
void e2d::Image::clearCache()
{
for (auto bitmap : s_mBitmapsFromResource)
for (auto bitmap : _bitmapCache)
{
SafeRelease(bitmap.second);
}
s_mBitmapsFromResource.clear();
_bitmapCache.clear();
}
void e2d::Image::_setBitmap(ID2D1Bitmap * bitmap)

View File

@ -13,9 +13,9 @@ e2d::Player::Player()
e2d::Player::~Player()
{
for (auto pair : _resList)
for (auto pair : _musicList)
GC::release(pair.second);
_resList.clear();
_musicList.clear();
if (_masteringVoice)
_masteringVoice->DestroyVoice();
@ -65,7 +65,7 @@ bool e2d::Player::preload(const String& filePath)
bool e2d::Player::preload(const Resource& res)
{
if (_resList.end() != _resList.find(res))
if (_musicList.end() != _musicList.find(res))
return true;
Music * music = new (e2d::autorelease) Music();
@ -74,7 +74,7 @@ bool e2d::Player::preload(const Resource& res)
{
GC::retain(music);
music->setVolume(_volume);
_resList.insert(std::make_pair(res, music));
_musicList.insert(std::make_pair(res, music));
return true;
}
return false;
@ -92,7 +92,7 @@ bool e2d::Player::play(const Resource& res, int nLoopCount)
{
if (Player::preload(res))
{
auto music = _resList[res];
auto music = _musicList[res];
if (music->play(nLoopCount))
{
return true;
@ -111,8 +111,8 @@ void e2d::Player::pause(const String& filePath)
void e2d::Player::pause(const Resource& res)
{
if (_resList.end() != _resList.find(res))
_resList[res]->pause();
if (_musicList.end() != _musicList.find(res))
_musicList[res]->pause();
}
void e2d::Player::resume(const String& filePath)
@ -125,8 +125,8 @@ void e2d::Player::resume(const String& filePath)
void e2d::Player::resume(const Resource& res)
{
if (_resList.end() != _resList.find(res))
_resList[res]->pause();
if (_musicList.end() != _musicList.find(res))
_musicList[res]->pause();
}
void e2d::Player::stop(const String& filePath)
@ -143,8 +143,8 @@ void e2d::Player::stop(const Resource& res)
{
}
if (_resList.end() != _resList.find(res))
_resList[res]->stop();
if (_musicList.end() != _musicList.find(res))
_musicList[res]->stop();
}
bool e2d::Player::isPlaying(const String& filePath)
@ -157,8 +157,8 @@ bool e2d::Player::isPlaying(const String& filePath)
bool e2d::Player::isPlaying(const Resource& res)
{
if (_resList.end() != _resList.find(res))
return _resList[res]->isPlaying();
if (_musicList.end() != _musicList.find(res))
return _musicList[res]->isPlaying();
return false;
}
@ -170,7 +170,7 @@ double e2d::Player::getVolume()
void e2d::Player::setVolume(double volume)
{
_volume = std::min(std::max(float(volume), -224.f), 224.f);
for (auto pair : _resList)
for (auto pair : _musicList)
{
pair.second->setVolume(_volume);
}
@ -178,7 +178,7 @@ void e2d::Player::setVolume(double volume)
void e2d::Player::pauseAll()
{
for (auto pair : _resList)
for (auto pair : _musicList)
{
pair.second->pause();
}
@ -186,7 +186,7 @@ void e2d::Player::pauseAll()
void e2d::Player::resumeAll()
{
for (auto pair : _resList)
for (auto pair : _musicList)
{
pair.second->resume();
}
@ -194,7 +194,7 @@ void e2d::Player::resumeAll()
void e2d::Player::stopAll()
{
for (auto pair : _resList)
for (auto pair : _musicList)
{
pair.second->stop();
}
@ -202,9 +202,9 @@ void e2d::Player::stopAll()
void e2d::Player::clearCache()
{
for (auto pair : _resList)
for (auto pair : _musicList)
{
GC::release(pair.second);
}
_resList.clear();
_musicList.clear();
}

View File

@ -552,10 +552,10 @@ public:
bool operator<= (const Resource &) const;
protected:
bool _isResource;
String _fileName;
int _resNameId;
String _resType;
bool _isResource;
int _resNameId;
String _resType;
String _fileName;
};
@ -675,6 +675,8 @@ protected:
protected:
Rect _cropRect;
ID2D1Bitmap * _bitmap;
static std::map<Resource, ID2D1Bitmap*> _bitmapCache;
};

View File

@ -253,7 +253,7 @@ private:
private:
float _volume;
MusicMap _resList;
MusicMap _musicList;
IXAudio2* _xAudio2;
IXAudio2MasteringVoice* _masteringVoice;