将Config配置设置改为指针传值
This commit is contained in:
parent
c0acf3a56c
commit
c8e8a38685
|
|
@ -9,13 +9,15 @@ e2d::Game * e2d::Game::_instance = nullptr;
|
||||||
e2d::Game::Game()
|
e2d::Game::Game()
|
||||||
: _ended(false)
|
: _ended(false)
|
||||||
, _paused(false)
|
, _paused(false)
|
||||||
, _config()
|
, _config(nullptr)
|
||||||
{
|
{
|
||||||
CoInitialize(nullptr);
|
CoInitialize(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::Game::~Game()
|
e2d::Game::~Game()
|
||||||
{
|
{
|
||||||
|
GC::safeRelease(_config);
|
||||||
|
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,10 +67,9 @@ void e2d::Game::start(bool cleanup)
|
||||||
// 判断是否达到了刷新状态
|
// 判断是否达到了刷新状态
|
||||||
if (Time::__isReady())
|
if (Time::__isReady())
|
||||||
{
|
{
|
||||||
// 更新配置
|
if (_config->_unconfigured)
|
||||||
if (_config._unconfigured)
|
|
||||||
{
|
{
|
||||||
_config._update();
|
_config->_update();
|
||||||
}
|
}
|
||||||
|
|
||||||
input->update(); // 获取用户输入
|
input->update(); // 获取用户输入
|
||||||
|
|
@ -115,14 +116,21 @@ bool e2d::Game::isPaused()
|
||||||
return _paused;
|
return _paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Game::setConfig(const Config& config)
|
void e2d::Game::setConfig(Config* config)
|
||||||
{
|
{
|
||||||
|
if (config && _config != config)
|
||||||
|
{
|
||||||
|
GC::release(_config);
|
||||||
_config = config;
|
_config = config;
|
||||||
_config._unconfigured = true;
|
_config->_unconfigured = true;
|
||||||
|
GC::retain(_config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::Config e2d::Game::getConfig() const
|
e2d::Config* e2d::Game::getConfig()
|
||||||
{
|
{
|
||||||
|
if (!_config)
|
||||||
|
_config = new (e2d::autorelease) Config();
|
||||||
return _config;
|
return _config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ void e2d::Scene::_render()
|
||||||
{
|
{
|
||||||
_root->_render();
|
_root->_render();
|
||||||
|
|
||||||
if (Game::getInstance()->getConfig().isColliderVisible())
|
if (Game::getInstance()->getConfig()->isColliderVisible())
|
||||||
{
|
{
|
||||||
// 恢复矩阵转换
|
// 恢复矩阵转换
|
||||||
Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
|
Renderer::getInstance()->getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ void e2d::ColliderManager::clearAll()
|
||||||
void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
|
void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
|
||||||
{
|
{
|
||||||
// 判断碰撞监听是否打开
|
// 判断碰撞监听是否打开
|
||||||
if (!Game::getInstance()->getConfig().isCollisionEnabled())
|
if (!Game::getInstance()->getConfig()->isCollisionEnabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Node* pActiveNode = pActiveCollider->_parentNode;
|
Node* pActiveNode = pActiveCollider->_parentNode;
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ e2d::String e2d::Path::getDataPath()
|
||||||
{
|
{
|
||||||
// 设置数据的保存路径
|
// 设置数据的保存路径
|
||||||
String localAppDataPath = Path::getLocalAppDataPath();
|
String localAppDataPath = Path::getLocalAppDataPath();
|
||||||
String gameName = Game::getInstance()->getConfig().getGameName();
|
String gameName = Game::getInstance()->getConfig()->getGameName();
|
||||||
if (!localAppDataPath.isEmpty() && !gameName.isEmpty())
|
if (!localAppDataPath.isEmpty() && !gameName.isEmpty())
|
||||||
{
|
{
|
||||||
_dataPath = localAppDataPath + L"\\Easy2DGameData\\" << gameName << L"\\";
|
_dataPath = localAppDataPath + L"\\Easy2DGameData\\" << gameName << L"\\";
|
||||||
|
|
@ -54,7 +54,7 @@ e2d::String e2d::Path::getTempPath()
|
||||||
{
|
{
|
||||||
// 设置临时文件保存路径
|
// 设置临时文件保存路径
|
||||||
wchar_t path[_MAX_PATH];
|
wchar_t path[_MAX_PATH];
|
||||||
String gameName = Game::getInstance()->getConfig().getGameName();
|
String gameName = Game::getInstance()->getConfig()->getGameName();
|
||||||
|
|
||||||
if (0 != ::GetTempPath(_MAX_PATH, path) && !gameName.isEmpty())
|
if (0 != ::GetTempPath(_MAX_PATH, path) && !gameName.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,11 @@ public:
|
||||||
|
|
||||||
// ÐÞ¸ÄÓÎÏ·ÅäÖÃ
|
// ÐÞ¸ÄÓÎÏ·ÅäÖÃ
|
||||||
void setConfig(
|
void setConfig(
|
||||||
const Config& config
|
Config* config
|
||||||
);
|
);
|
||||||
|
|
||||||
// »ñÈ¡ÓÎÏ·ÅäÖÃ
|
// »ñÈ¡ÓÎÏ·ÅäÖÃ
|
||||||
Config getConfig() const;
|
Config* getConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Game();
|
Game();
|
||||||
|
|
@ -58,7 +58,7 @@ private:
|
||||||
private:
|
private:
|
||||||
bool _ended;
|
bool _ended;
|
||||||
bool _paused;
|
bool _paused;
|
||||||
Config _config;
|
Config* _config;
|
||||||
|
|
||||||
static Game * _instance;
|
static Game * _instance;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -734,7 +734,8 @@ protected:
|
||||||
class Game;
|
class Game;
|
||||||
|
|
||||||
// モホマキナ葷テ
|
// モホマキナ葷テ
|
||||||
class Config
|
class Config :
|
||||||
|
public Ref
|
||||||
{
|
{
|
||||||
friend class Game;
|
friend class Game;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue