Config增加声音开关配置,以及实现下一帧更新配置的功能

This commit is contained in:
Nomango 2018-07-05 01:35:50 +08:00
parent 58ae8dee20
commit 4dc25a606d
6 changed files with 66 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -54,7 +54,7 @@ void e2d::Player::destroyInstance()
}
}
IXAudio2 * e2d::Player::getIXAudio2()
IXAudio2 * e2d::Player::getXAudio2()
{
return _xAudio2;
}

View File

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

View File

@ -247,7 +247,7 @@ public:
void stopAll();
// 获取 IXAudio2 对象
IXAudio2 * getIXAudio2();
IXAudio2 * getXAudio2();
private:
Player();