Config增加声音开关配置,以及实现下一帧更新配置的功能
This commit is contained in:
parent
58ae8dee20
commit
4dc25a606d
|
|
@ -68,6 +68,12 @@ void e2d::Game::start(bool cleanup)
|
||||||
// 判断是否达到了刷新状态
|
// 判断是否达到了刷新状态
|
||||||
if (Time::__isReady())
|
if (Time::__isReady())
|
||||||
{
|
{
|
||||||
|
// 更新配置
|
||||||
|
if (_config && _config->_unconfigured)
|
||||||
|
{
|
||||||
|
_config->_update();
|
||||||
|
}
|
||||||
|
|
||||||
input->__update(); // 获取用户输入
|
input->__update(); // 获取用户输入
|
||||||
Timer::__update(); // 更新定时器
|
Timer::__update(); // 更新定时器
|
||||||
actionManager->__update(); // 更新动作管理器
|
actionManager->__update(); // 更新动作管理器
|
||||||
|
|
@ -121,11 +127,15 @@ bool e2d::Game::isPaused()
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::Game::setConfig(Config * config)
|
void e2d::Game::setConfig(Config * config)
|
||||||
|
{
|
||||||
|
if (_config != config && config)
|
||||||
{
|
{
|
||||||
GC::release(_config);
|
GC::release(_config);
|
||||||
_config = config;
|
_config = config;
|
||||||
|
_config->_unconfigured = true;
|
||||||
GC::retain(_config);
|
GC::retain(_config);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e2d::Config * e2d::Game::getConfig()
|
e2d::Config * e2d::Game::getConfig()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
#include "..\e2dbase.h"
|
#include "..\e2dbase.h"
|
||||||
|
#include "..\e2dtool.h"
|
||||||
|
|
||||||
e2d::Config::Config()
|
e2d::Config::Config()
|
||||||
: _gameName()
|
: _gameName()
|
||||||
, _nodeDefPivot()
|
, _nodeDefPivot()
|
||||||
|
, _soundEnabled(true)
|
||||||
, _collisionEnabled(false)
|
, _collisionEnabled(false)
|
||||||
, _colliderVisiable(false)
|
, _colliderVisiable(false)
|
||||||
, _nodeDefColliderType(Collider::Type::None)
|
, _nodeDefColliderType(Collider::Type::None)
|
||||||
|
, _unconfigured(true)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,6 +21,15 @@ void e2d::Config::setGameName(const String & name)
|
||||||
_gameName = name;
|
_gameName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::Config::setSoundEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
if (_soundEnabled != enabled)
|
||||||
|
{
|
||||||
|
_soundEnabled = enabled;
|
||||||
|
_unconfigured = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::Config::setCollisionEnabled(bool enabled)
|
void e2d::Config::setCollisionEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
_collisionEnabled = enabled;
|
_collisionEnabled = enabled;
|
||||||
|
|
@ -47,6 +58,11 @@ e2d::String e2d::Config::getGameName() const
|
||||||
return _gameName;
|
return _gameName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool e2d::Config::isSoundEnabled() const
|
||||||
|
{
|
||||||
|
return _soundEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
bool e2d::Config::isCollisionEnabled() const
|
bool e2d::Config::isCollisionEnabled() const
|
||||||
{
|
{
|
||||||
return _collisionEnabled;
|
return _collisionEnabled;
|
||||||
|
|
@ -66,3 +82,17 @@ bool e2d::Config::isColliderVisiable() const
|
||||||
{
|
{
|
||||||
return _colliderVisiable;
|
return _colliderVisiable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::Config::_update()
|
||||||
|
{
|
||||||
|
_unconfigured = false;
|
||||||
|
|
||||||
|
if (_soundEnabled)
|
||||||
|
{
|
||||||
|
Player::getInstance()->getXAudio2()->StartEngine();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Player::getInstance()->getXAudio2()->StopEngine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,
|
&_voice,
|
||||||
_wfx,
|
_wfx,
|
||||||
0,
|
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,
|
&_voice,
|
||||||
_wfx,
|
_wfx,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ void e2d::Player::destroyInstance()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IXAudio2 * e2d::Player::getIXAudio2()
|
IXAudio2 * e2d::Player::getXAudio2()
|
||||||
{
|
{
|
||||||
return _xAudio2;
|
return _xAudio2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -635,11 +635,6 @@ public:
|
||||||
// 获取根节点
|
// 获取根节点
|
||||||
Node * getRoot() const;
|
Node * getRoot() const;
|
||||||
|
|
||||||
// 开启或关闭节点轮廓渲染
|
|
||||||
void showCollider(
|
|
||||||
bool visiable = true
|
|
||||||
);
|
|
||||||
|
|
||||||
// 销毁对象
|
// 销毁对象
|
||||||
virtual void onDestroy() override;
|
virtual void onDestroy() override;
|
||||||
|
|
||||||
|
|
@ -745,10 +740,14 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Game;
|
||||||
|
|
||||||
// 游戏配置
|
// 游戏配置
|
||||||
class Config :
|
class Config :
|
||||||
public Object
|
public Object
|
||||||
{
|
{
|
||||||
|
friend class Game;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Config();
|
Config();
|
||||||
|
|
||||||
|
|
@ -760,6 +759,12 @@ public:
|
||||||
const String& name
|
const String& name
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 打开或关闭声音
|
||||||
|
// 默认:打开
|
||||||
|
void setSoundEnabled(
|
||||||
|
bool enabled
|
||||||
|
);
|
||||||
|
|
||||||
// 打开或关闭碰撞监听
|
// 打开或关闭碰撞监听
|
||||||
// 默认:关闭
|
// 默认:关闭
|
||||||
void setCollisionEnabled(
|
void setCollisionEnabled(
|
||||||
|
|
@ -787,6 +792,9 @@ public:
|
||||||
// 获取游戏名称
|
// 获取游戏名称
|
||||||
String getGameName() const;
|
String getGameName() const;
|
||||||
|
|
||||||
|
// 获取声音打开状态
|
||||||
|
bool isSoundEnabled() const;
|
||||||
|
|
||||||
// 获取碰撞监听状态
|
// 获取碰撞监听状态
|
||||||
bool isCollisionEnabled() const;
|
bool isCollisionEnabled() const;
|
||||||
|
|
||||||
|
|
@ -800,6 +808,11 @@ public:
|
||||||
bool isColliderVisiable() const;
|
bool isColliderVisiable() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void _update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool _unconfigured;
|
||||||
|
bool _soundEnabled;
|
||||||
bool _collisionEnabled;
|
bool _collisionEnabled;
|
||||||
bool _colliderVisiable;
|
bool _colliderVisiable;
|
||||||
String _gameName;
|
String _gameName;
|
||||||
|
|
|
||||||
|
|
@ -247,7 +247,7 @@ public:
|
||||||
void stopAll();
|
void stopAll();
|
||||||
|
|
||||||
// 获取 IXAudio2 对象
|
// 获取 IXAudio2 对象
|
||||||
IXAudio2 * getIXAudio2();
|
IXAudio2 * getXAudio2();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Player();
|
Player();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue