diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index a7bbb637..b9b5e70d 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -68,6 +68,12 @@ void e2d::Game::start(bool cleanup) // 判断是否达到了刷新状态 if (Time::__isReady()) { + // 更新配置 + if (_config && _config->_unconfigured) + { + _config->_update(); + } + input->__update(); // 获取用户输入 Timer::__update(); // 更新定时器 actionManager->__update(); // 更新动作管理器 @@ -122,9 +128,13 @@ bool e2d::Game::isPaused() void e2d::Game::setConfig(Config * config) { - GC::release(_config); - _config = config; - GC::retain(_config); + if (_config != config && config) + { + GC::release(_config); + _config = config; + _config->_unconfigured = true; + GC::retain(_config); + } } e2d::Config * e2d::Game::getConfig() diff --git a/core/Common/Config.cpp b/core/Common/Config.cpp index 72411c5b..572cc1af 100644 --- a/core/Common/Config.cpp +++ b/core/Common/Config.cpp @@ -1,12 +1,14 @@ #include "..\e2dbase.h" - +#include "..\e2dtool.h" e2d::Config::Config() : _gameName() , _nodeDefPivot() + , _soundEnabled(true) , _collisionEnabled(false) , _colliderVisiable(false) , _nodeDefColliderType(Collider::Type::None) + , _unconfigured(true) { } @@ -19,6 +21,15 @@ void e2d::Config::setGameName(const String & name) _gameName = name; } +void e2d::Config::setSoundEnabled(bool enabled) +{ + if (_soundEnabled != enabled) + { + _soundEnabled = enabled; + _unconfigured = true; + } +} + void e2d::Config::setCollisionEnabled(bool enabled) { _collisionEnabled = enabled; @@ -47,6 +58,11 @@ e2d::String e2d::Config::getGameName() const return _gameName; } +bool e2d::Config::isSoundEnabled() const +{ + return _soundEnabled; +} + bool e2d::Config::isCollisionEnabled() const { return _collisionEnabled; @@ -66,3 +82,17 @@ bool e2d::Config::isColliderVisiable() const { return _colliderVisiable; } + +void e2d::Config::_update() +{ + _unconfigured = false; + + if (_soundEnabled) + { + Player::getInstance()->getXAudio2()->StartEngine(); + } + else + { + Player::getInstance()->getXAudio2()->StopEngine(); + } +} diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index 19f4afe7..de34d591 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -128,7 +128,7 @@ bool e2d::Music::open(const e2d::String& filePath) } // 创建音源 - HRESULT hr = Player::getInstance()->getIXAudio2()->CreateSourceVoice( + HRESULT hr = Player::getInstance()->getXAudio2()->CreateSourceVoice( &_voice, _wfx, 0, @@ -208,7 +208,7 @@ bool e2d::Music::open(int resNameId, const e2d::String& resType) } // 创建音源 - HRESULT hr = Player::getInstance()->getIXAudio2()->CreateSourceVoice( + HRESULT hr = Player::getInstance()->getXAudio2()->CreateSourceVoice( &_voice, _wfx, 0, diff --git a/core/Tool/Player.cpp b/core/Tool/Player.cpp index 96c3581b..7229ca72 100644 --- a/core/Tool/Player.cpp +++ b/core/Tool/Player.cpp @@ -54,7 +54,7 @@ void e2d::Player::destroyInstance() } } -IXAudio2 * e2d::Player::getIXAudio2() +IXAudio2 * e2d::Player::getXAudio2() { return _xAudio2; } diff --git a/core/e2dcommon.h b/core/e2dcommon.h index ddf16e87..1f8b9896 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -635,11 +635,6 @@ public: // 获取根节点 Node * getRoot() const; - // 开启或关闭节点轮廓渲染 - void showCollider( - bool visiable = true - ); - // 销毁对象 virtual void onDestroy() override; @@ -745,10 +740,14 @@ protected: }; +class Game; + // 游戏配置 class Config : public Object { + friend class Game; + public: Config(); @@ -760,6 +759,12 @@ public: const String& name ); + // 打开或关闭声音 + // 默认:打开 + void setSoundEnabled( + bool enabled + ); + // 打开或关闭碰撞监听 // 默认:关闭 void setCollisionEnabled( @@ -787,6 +792,9 @@ public: // 获取游戏名称 String getGameName() const; + // 获取声音打开状态 + bool isSoundEnabled() const; + // 获取碰撞监听状态 bool isCollisionEnabled() const; @@ -800,6 +808,11 @@ public: bool isColliderVisiable() const; protected: + virtual void _update(); + +protected: + bool _unconfigured; + bool _soundEnabled; bool _collisionEnabled; bool _colliderVisiable; String _gameName; diff --git a/core/e2dtool.h b/core/e2dtool.h index bea5b649..bc8fbbaa 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -247,7 +247,7 @@ public: void stopAll(); // 获取 IXAudio2 对象 - IXAudio2 * getIXAudio2(); + IXAudio2 * getXAudio2(); private: Player();