diff --git a/projects/kiwano-audio.vcxproj b/projects/kiwano-audio.vcxproj
index 0deda3e8..fdaf9844 100644
--- a/projects/kiwano-audio.vcxproj
+++ b/projects/kiwano-audio.vcxproj
@@ -4,14 +4,14 @@
-
+
-
+
diff --git a/projects/kiwano-audio.vcxproj.filters b/projects/kiwano-audio.vcxproj.filters
index 62e0774b..b6974b55 100644
--- a/projects/kiwano-audio.vcxproj.filters
+++ b/projects/kiwano-audio.vcxproj.filters
@@ -8,15 +8,15 @@
src
-
- src
-
src
src
+
+ src
+
@@ -25,15 +25,15 @@
src
-
- src
-
src
src
+
+ src
+
diff --git a/src/kiwano-audio/kiwano-audio.h b/src/kiwano-audio/kiwano-audio.h
index 8f6e027a..02ca2f43 100644
--- a/src/kiwano-audio/kiwano-audio.h
+++ b/src/kiwano-audio/kiwano-audio.h
@@ -22,4 +22,4 @@
#include "src/audio.h"
#include "src/Sound.h"
-#include "src/Player.h"
+#include "src/SoundPlayer.h"
diff --git a/src/kiwano-audio/src/Sound.cpp b/src/kiwano-audio/src/Sound.cpp
index 04bc7920..30d64e84 100644
--- a/src/kiwano-audio/src/Sound.cpp
+++ b/src/kiwano-audio/src/Sound.cpp
@@ -22,7 +22,6 @@
#include
#include "Sound.h"
#include "audio.h"
-#include "Transcoder.h"
namespace kiwano
{
@@ -32,12 +31,16 @@ namespace kiwano
Sound::Sound()
: opened_(false)
, playing_(false)
- , size_(0)
- , wave_data_(nullptr)
, voice_(nullptr)
{
}
+ Sound::Sound(String const& file_path)
+ : Sound()
+ {
+ Load(file_path);
+ }
+
Sound::Sound(Resource const& res)
: Sound()
{
@@ -51,21 +54,19 @@ namespace kiwano
bool Sound::Load(String const& file_path)
{
- if (opened_)
- {
- Close();
- }
-
-#if defined(KGE_DEBUG)
if (!FileUtil::ExistsFile(file_path))
{
KGE_WARNING_LOG(L"Media file '%s' not found", file_path.c_str());
return false;
}
-#endif
+
+ if (opened_)
+ {
+ Close();
+ }
Transcoder transcoder;
- HRESULT hr = transcoder.LoadMediaFile(file_path, &wave_data_, &size_);
+ HRESULT hr = transcoder.LoadMediaFile(file_path);
if (FAILED(hr))
{
@@ -73,14 +74,11 @@ namespace kiwano
return false;
}
- hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder.GetWaveFormatEx());
+ hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder.GetBuffer().format);
if (FAILED(hr))
{
- if (wave_data_)
- {
- delete[] wave_data_;
- wave_data_ = nullptr;
- }
+ Close();
+
KGE_ERROR_LOG(L"Create source voice failed with HRESULT of %08X", hr);
return false;
}
@@ -97,7 +95,7 @@ namespace kiwano
}
Transcoder transcoder;
- HRESULT hr = transcoder.LoadMediaResource(res, &wave_data_, &size_);
+ HRESULT hr = transcoder.LoadMediaResource(res);
if (FAILED(hr))
{
@@ -105,14 +103,11 @@ namespace kiwano
return false;
}
- hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder.GetWaveFormatEx());
+ hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder.GetBuffer().format);
if (FAILED(hr))
{
- if (wave_data_)
- {
- delete[] wave_data_;
- wave_data_ = nullptr;
- }
+ Close();
+
KGE_ERROR_LOG(L"Create source voice failed with HRESULT of %08X", hr);
return false;
}
@@ -140,10 +135,12 @@ namespace kiwano
// clamp loop count
loop_count = (loop_count < 0) ? XAUDIO2_LOOP_INFINITE : std::min(loop_count, XAUDIO2_LOOP_INFINITE - 1);
+ auto wave_buffer = transcoder_.GetBuffer();
+
XAUDIO2_BUFFER buffer = { 0 };
- buffer.pAudioData = wave_data_;
+ buffer.pAudioData = wave_buffer.data;
buffer.Flags = XAUDIO2_END_OF_STREAM;
- buffer.AudioBytes = size_;
+ buffer.AudioBytes = wave_buffer.size;
buffer.LoopCount = static_cast(loop_count);
HRESULT hr = voice_->SubmitSourceBuffer(&buffer);
@@ -202,11 +199,7 @@ namespace kiwano
voice_ = nullptr;
}
- if (wave_data_)
- {
- delete[] wave_data_;
- wave_data_ = nullptr;
- }
+ transcoder_.ClearBuffer();
opened_ = false;
playing_ = false;
diff --git a/src/kiwano-audio/src/Sound.h b/src/kiwano-audio/src/Sound.h
index bff2118c..e3e64fd9 100644
--- a/src/kiwano-audio/src/Sound.h
+++ b/src/kiwano-audio/src/Sound.h
@@ -23,6 +23,7 @@
#include
#include
#include
+#include "Transcoder.h"
namespace kiwano
{
@@ -86,11 +87,10 @@ namespace kiwano
);
protected:
- bool opened_;
- bool playing_;
- UInt32 size_;
- BYTE* wave_data_;
- IXAudio2SourceVoice* voice_;
+ bool opened_;
+ bool playing_;
+ Transcoder transcoder_;
+ IXAudio2SourceVoice* voice_;
};
}
}
diff --git a/src/kiwano-audio/src/Player.cpp b/src/kiwano-audio/src/SoundPlayer.cpp
similarity index 83%
rename from src/kiwano-audio/src/Player.cpp
rename to src/kiwano-audio/src/SoundPlayer.cpp
index 5e696ec0..7503908c 100644
--- a/src/kiwano-audio/src/Player.cpp
+++ b/src/kiwano-audio/src/SoundPlayer.cpp
@@ -18,23 +18,23 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include "Player.h"
+#include "SoundPlayer.h"
namespace kiwano
{
namespace audio
{
- Player::Player()
+ SoundPlayer::SoundPlayer()
: volume_(1.f)
{
}
- Player::~Player()
+ SoundPlayer::~SoundPlayer()
{
ClearCache();
}
- UInt32 Player::Load(String const& file_path)
+ UInt32 SoundPlayer::Load(String const& file_path)
{
UInt32 hash_code = file_path.hash();
if (sound_cache_.end() != sound_cache_.find(hash_code))
@@ -54,7 +54,7 @@ namespace kiwano
return false;
}
- UInt32 Player::Load(Resource const& res)
+ UInt32 SoundPlayer::Load(Resource const& res)
{
UInt32 hash_code = res.GetId();
if (sound_cache_.end() != sound_cache_.find(hash_code))
@@ -74,35 +74,35 @@ namespace kiwano
return false;
}
- void Player::Play(UInt32 id, Int32 loop_count)
+ void SoundPlayer::Play(UInt32 id, Int32 loop_count)
{
auto iter = sound_cache_.find(id);
if (sound_cache_.end() != iter)
iter->second->Play(loop_count);
}
- void Player::Pause(UInt32 id)
+ void SoundPlayer::Pause(UInt32 id)
{
auto iter = sound_cache_.find(id);
if (sound_cache_.end() != iter)
iter->second->Pause();
}
- void Player::Resume(UInt32 id)
+ void SoundPlayer::Resume(UInt32 id)
{
auto iter = sound_cache_.find(id);
if (sound_cache_.end() != iter)
iter->second->Resume();
}
- void Player::Stop(UInt32 id)
+ void SoundPlayer::Stop(UInt32 id)
{
auto iter = sound_cache_.find(id);
if (sound_cache_.end() != iter)
iter->second->Stop();
}
- bool Player::IsPlaying(UInt32 id)
+ bool SoundPlayer::IsPlaying(UInt32 id)
{
auto iter = sound_cache_.find(id);
if (sound_cache_.end() != iter)
@@ -110,12 +110,12 @@ namespace kiwano
return false;
}
- Float32 Player::GetVolume() const
+ Float32 SoundPlayer::GetVolume() const
{
return volume_;
}
- void Player::SetVolume(Float32 volume)
+ void SoundPlayer::SetVolume(Float32 volume)
{
volume_ = std::min(std::max(volume, -224.f), 224.f);
for (const auto& pair : sound_cache_)
@@ -124,7 +124,7 @@ namespace kiwano
}
}
- void Player::PauseAll()
+ void SoundPlayer::PauseAll()
{
for (const auto& pair : sound_cache_)
{
@@ -132,7 +132,7 @@ namespace kiwano
}
}
- void Player::ResumeAll()
+ void SoundPlayer::ResumeAll()
{
for (const auto& pair : sound_cache_)
{
@@ -140,7 +140,7 @@ namespace kiwano
}
}
- void Player::StopAll()
+ void SoundPlayer::StopAll()
{
for (const auto& pair : sound_cache_)
{
@@ -148,7 +148,7 @@ namespace kiwano
}
}
- void Player::ClearCache()
+ void SoundPlayer::ClearCache()
{
sound_cache_.clear();
}
diff --git a/src/kiwano-audio/src/Player.h b/src/kiwano-audio/src/SoundPlayer.h
similarity index 89%
rename from src/kiwano-audio/src/Player.h
rename to src/kiwano-audio/src/SoundPlayer.h
index 7e33e2d0..596ea530 100644
--- a/src/kiwano-audio/src/Player.h
+++ b/src/kiwano-audio/src/SoundPlayer.h
@@ -27,23 +27,23 @@ namespace kiwano
{
namespace audio
{
- KGE_DECLARE_SMART_PTR(Player);
+ KGE_DECLARE_SMART_PTR(SoundPlayer);
// 音乐播放器
- class KGE_API Player
+ class KGE_API SoundPlayer
: protected ObjectBase
{
public:
- Player();
+ SoundPlayer();
- ~Player();
+ ~SoundPlayer();
- // 加载本地音频文件, 返回该资源标识符
+ // 加载本地音频文件, 返回该资源的标识符
UInt32 Load(
String const& file_path
);
- // 加载音乐资源, 返回该资源标识符
+ // 加载音乐资源, 返回该资源的标识符
UInt32 Load(
Resource const& res /* 音乐资源 */
);
@@ -51,7 +51,7 @@ namespace kiwano
// 播放音乐
void Play(
UInt32 id, /* 标识符 */
- Int32 loop_count = 0 /* 播放循环次数 (-1 为循环播放) */
+ Int32 loop_count = 0 /* 播放循环次数 (-1 为循环播放) */
);
// 暂停音乐
diff --git a/src/kiwano-audio/src/Transcoder.cpp b/src/kiwano-audio/src/Transcoder.cpp
index a07dca56..4204725a 100644
--- a/src/kiwano-audio/src/Transcoder.cpp
+++ b/src/kiwano-audio/src/Transcoder.cpp
@@ -38,24 +38,39 @@ namespace kiwano
Transcoder::Transcoder()
: wave_format_(nullptr)
+ , wave_data_(nullptr)
+ , wave_size_(0)
{
}
Transcoder::~Transcoder()
+ {
+ ClearBuffer();
+ }
+
+ Transcoder::Buffer Transcoder::GetBuffer() const
+ {
+ return Buffer{ wave_data_, wave_size_, wave_format_ };
+ }
+
+ void Transcoder::ClearBuffer()
{
if (wave_format_)
{
::CoTaskMemFree(wave_format_);
wave_format_ = nullptr;
}
+
+ if (wave_data_)
+ {
+ delete[] wave_data_;
+ wave_data_ = nullptr;
+ }
+
+ wave_size_ = 0;
}
- const WAVEFORMATEX* Transcoder::GetWaveFormatEx() const
- {
- return wave_format_;
- }
-
- HRESULT Transcoder::LoadMediaFile(String const& file_path, BYTE** wave_data, UInt32* wave_data_size)
+ HRESULT Transcoder::LoadMediaFile(String const& file_path)
{
HRESULT hr = S_OK;
@@ -69,13 +84,13 @@ namespace kiwano
if (SUCCEEDED(hr))
{
- hr = ReadSource(reader.get(), wave_data, wave_data_size);
+ hr = ReadSource(reader.get());
}
return hr;
}
- HRESULT Transcoder::LoadMediaResource(Resource const& res, BYTE** wave_data, UInt32* wave_data_size)
+ HRESULT Transcoder::LoadMediaResource(Resource const& res)
{
HRESULT hr = S_OK;
@@ -87,7 +102,7 @@ namespace kiwano
if (!data) { return E_FAIL; }
stream = kiwano::modules::Shlwapi::Get().SHCreateMemStream(
- static_cast(data.buffer),
+ static_cast(data.buffer),
static_cast(data.size)
);
@@ -113,13 +128,13 @@ namespace kiwano
if (SUCCEEDED(hr))
{
- hr = ReadSource(reader.get(), wave_data, wave_data_size);
+ hr = ReadSource(reader.get());
}
return hr;
}
- HRESULT Transcoder::ReadSource(IMFSourceReader* reader, BYTE** wave_data, UInt32* wave_data_size)
+ HRESULT Transcoder::ReadSource(IMFSourceReader* reader)
{
HRESULT hr = S_OK;
DWORD max_stream_size = 0;
@@ -194,7 +209,7 @@ namespace kiwano
LONGLONG duration = prop.uhVal.QuadPart;
max_stream_size = static_cast(
(duration * wave_format_->nAvgBytesPerSec) / 10000000 + 1
- );
+ );
PropVariantClear(&prop);
}
@@ -203,7 +218,7 @@ namespace kiwano
{
DWORD flags = 0;
DWORD position = 0;
- BYTE* data = new (std::nothrow) BYTE[max_stream_size];
+ Byte* data = new (std::nothrow) Byte[max_stream_size];
ComPtr sample;
ComPtr buffer;
@@ -236,7 +251,7 @@ namespace kiwano
if (SUCCEEDED(hr))
{
- BYTE* audio_data = nullptr;
+ Byte* audio_data = nullptr;
DWORD sample_buffer_length = 0;
hr = buffer->Lock(
@@ -245,7 +260,7 @@ namespace kiwano
&sample_buffer_length
);
- if (SUCCEEDED(hr))
+ if (SUCCEEDED(hr) && sample_buffer_length <= max_stream_size)
{
for (DWORD i = 0; i < sample_buffer_length; i++)
{
@@ -263,8 +278,8 @@ namespace kiwano
if (SUCCEEDED(hr))
{
- *wave_data = data;
- *wave_data_size = position;
+ wave_data_ = data;
+ wave_size_ = position;
}
}
}
diff --git a/src/kiwano-audio/src/Transcoder.h b/src/kiwano-audio/src/Transcoder.h
index 9bc02cb4..9195e0dd 100644
--- a/src/kiwano-audio/src/Transcoder.h
+++ b/src/kiwano-audio/src/Transcoder.h
@@ -31,31 +31,36 @@ namespace kiwano
class KGE_API Transcoder
{
public:
+ struct Buffer
+ {
+ Byte* data;
+ UInt32 size;
+ const WAVEFORMATEX* format;
+ };
+
Transcoder();
~Transcoder();
- const WAVEFORMATEX* GetWaveFormatEx() const;
+ Buffer GetBuffer() const;
+
+ void ClearBuffer();
HRESULT LoadMediaFile(
- String const& file_path,
- BYTE** wave_data,
- UInt32* wave_data_size
+ String const& file_path
);
HRESULT LoadMediaResource(
- Resource const& res,
- BYTE** wave_data,
- UInt32* wave_data_size
+ Resource const& res
);
HRESULT ReadSource(
- IMFSourceReader* reader,
- BYTE** wave_data,
- UInt32* wave_data_size
+ IMFSourceReader* reader
);
private:
+ Byte* wave_data_;
+ UInt32 wave_size_;
WAVEFORMATEX* wave_format_;
};
}
diff --git a/src/kiwano-audio/src/audio.cpp b/src/kiwano-audio/src/audio.cpp
index b703054a..db0d0b75 100644
--- a/src/kiwano-audio/src/audio.cpp
+++ b/src/kiwano-audio/src/audio.cpp
@@ -76,9 +76,17 @@ namespace kiwano
HRESULT Audio::CreateVoice(IXAudio2SourceVoice** voice, const WAVEFORMATEX* wfx)
{
+ KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!");
+
if (voice == nullptr)
{
- return E_UNEXPECTED;
+ return E_INVALIDARG;
+ }
+
+ if (*voice)
+ {
+ (*voice)->DestroyVoice();
+ (*voice) = nullptr;
}
HRESULT hr = x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO);
@@ -87,11 +95,15 @@ namespace kiwano
void Audio::Open()
{
+ KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!");
+
x_audio2_->StartEngine();
}
void Audio::Close()
{
+ KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!");
+
x_audio2_->StopEngine();
}
}
diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h
index ccad06d9..7cb3c254 100644
--- a/src/kiwano/2d/Actor.h
+++ b/src/kiwano/2d/Actor.h
@@ -432,7 +432,7 @@ namespace kiwano
bool update_pausing_;
bool cascade_opacity_;
bool show_border_;
- Int32 z_order_;
+ Int32 z_order_;
Float32 opacity_;
Float32 displayed_opacity_;
Actor* parent_;
@@ -444,9 +444,9 @@ namespace kiwano
UpdateCallback cb_update_;
Transform transform_;
- bool is_fast_transform_;
- mutable bool dirty_transform_;
- mutable bool dirty_transform_inverse_;
+ bool is_fast_transform_;
+ mutable bool dirty_transform_;
+ mutable bool dirty_transform_inverse_;
mutable Matrix3x2 transform_matrix_;
mutable Matrix3x2 transform_matrix_inverse_;
};
diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h
index 6a875591..13ada9e6 100644
--- a/src/kiwano/2d/GifSprite.h
+++ b/src/kiwano/2d/GifSprite.h
@@ -62,7 +62,7 @@ namespace kiwano
);
// 设置 GIF 动画循环次数
- inline void SetLoopCount(Int32 loops) { total_loop_count_ = loops; }
+ inline void SetLoopCount(Int32 loops) { total_loop_count_ = loops; }
// 设置 GIF 动画每次循环结束回调函数
inline void SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; }
@@ -100,8 +100,8 @@ namespace kiwano
protected:
bool animating_;
- Int32 total_loop_count_;
- Int32 loop_count_;
+ Int32 total_loop_count_;
+ Int32 loop_count_;
UInt32 next_index_;
Duration frame_delay_;
Duration frame_elapsed_;
diff --git a/src/kiwano/2d/action/Action.h b/src/kiwano/2d/action/Action.h
index 6becb2e3..fed487c2 100644
--- a/src/kiwano/2d/action/Action.h
+++ b/src/kiwano/2d/action/Action.h
@@ -62,7 +62,7 @@ namespace kiwano
inline void SetDelay(Duration delay) { delay_ = delay; }
// 设置循环次数 (-1 为永久循环)
- inline void SetLoops(Int32 loops) { loops_ = loops; }
+ inline void SetLoops(Int32 loops) { loops_ = loops; }
// 动作结束时移除目标角色
inline void RemoveTargetWhenDone() { detach_target_ = true; }
@@ -89,7 +89,7 @@ namespace kiwano
inline bool IsRemoveable() const { return status_ == Status::Removeable; }
- inline Int32 GetLoops() const { return loops_; }
+ inline Int32 GetLoops() const { return loops_; }
inline Duration GetDelay() const { return delay_; }
@@ -114,8 +114,8 @@ namespace kiwano
Status status_;
bool running_;
bool detach_target_;
- Int32 loops_;
- Int32 loops_done_;
+ Int32 loops_;
+ Int32 loops_done_;
Duration delay_;
Duration elapsed_;
ActionCallback cb_done_;
diff --git a/src/kiwano/2d/action/ActionHelper.h b/src/kiwano/2d/action/ActionHelper.h
index b44bfd41..f6c73ed9 100644
--- a/src/kiwano/2d/action/ActionHelper.h
+++ b/src/kiwano/2d/action/ActionHelper.h
@@ -64,7 +64,7 @@ namespace kiwano
inline TweenHelper& SetDuration(Duration dur) { base->SetDuration(dur); return (*this); }
// 设置循环次数
- inline TweenHelper& SetLoops(Int32 loops) { base->SetLoops(loops); return (*this); }
+ inline TweenHelper& SetLoops(Int32 loops) { base->SetLoops(loops); return (*this); }
// 设置缓动函数
inline TweenHelper& SetEaseFunc(EaseFunc ease) { base->SetEaseFunc(ease); return (*this); }
@@ -118,7 +118,7 @@ namespace kiwano
Duration dur,
Point const& pos, /* 目的坐标 */
Float32 height, /* 跳跃高度 */
- Int32 jumps = 1) /* 跳跃次数 */
+ Int32 jumps = 1) /* 跳跃次数 */
{
return TweenHelper(new kiwano::ActionJumpBy(dur, pos, height, jumps));
}
@@ -128,7 +128,7 @@ namespace kiwano
Duration dur,
Point const& pos, /* 目的坐标 */
Float32 height, /* 跳跃高度 */
- Int32 jumps = 1) /* 跳跃次数 */
+ Int32 jumps = 1) /* 跳跃次数 */
{
return TweenHelper(new kiwano::ActionJumpTo(dur, pos, height, jumps));
}
diff --git a/src/kiwano/2d/action/ActionTween.h b/src/kiwano/2d/action/ActionTween.h
index 4b52f091..70146a2e 100644
--- a/src/kiwano/2d/action/ActionTween.h
+++ b/src/kiwano/2d/action/ActionTween.h
@@ -166,7 +166,7 @@ namespace kiwano
Duration duration, /* 持续时长 */
Point const& vec, /* 跳跃距离 */
Float32 height, /* 跳跃高度 */
- Int32 jumps = 1, /* 跳跃次数 */
+ Int32 jumps = 1, /* 跳跃次数 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -199,7 +199,7 @@ namespace kiwano
Duration duration, /* 持续时长 */
Point const& pos, /* 目的坐标 */
Float32 height, /* 跳跃高度 */
- Int32 jumps = 1, /* 跳跃次数 */
+ Int32 jumps = 1, /* 跳跃次数 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -234,8 +234,8 @@ namespace kiwano
ActionScaleBy(
Duration duration, /* 持续时长 */
- Float32 scale_x, /* 横向缩放相对变化值 */
- Float32 scale_y, /* 纵向缩放相对变化值 */
+ Float32 scale_x, /* 横向缩放相对变化值 */
+ Float32 scale_y, /* 纵向缩放相对变化值 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -271,8 +271,8 @@ namespace kiwano
ActionScaleTo(
Duration duration, /* 持续时长 */
- Float32 scale_x, /* 横向缩放目标值 */
- Float32 scale_y, /* 纵向缩放目标值 */
+ Float32 scale_x, /* 横向缩放目标值 */
+ Float32 scale_y, /* 纵向缩放目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -302,7 +302,7 @@ namespace kiwano
public:
ActionFadeTo(
Duration duration, /* 持续时长 */
- Float32 opacity, /* 目标值 */
+ Float32 opacity, /* 目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -361,7 +361,7 @@ namespace kiwano
public:
ActionRotateBy(
Duration duration, /* 持续时长 */
- Float32 rotation, /* 相对变化值 */
+ Float32 rotation, /* 相对变化值 */
EaseFunc func = nullptr /* 速度变化 */
);
@@ -389,7 +389,7 @@ namespace kiwano
public:
ActionRotateTo(
Duration duration, /* 持续时长 */
- Float32 rotation, /* 目标值 */
+ Float32 rotation, /* 目标值 */
EaseFunc func = nullptr /* 速度变化 */
);
diff --git a/src/kiwano/base/Resource.cpp b/src/kiwano/base/Resource.cpp
index a6b2e336..fb0a8dc8 100644
--- a/src/kiwano/base/Resource.cpp
+++ b/src/kiwano/base/Resource.cpp
@@ -31,7 +31,7 @@ namespace kiwano
}
- Resource::Resource(UInt32 id, LPCWSTR type)
+ Resource::Resource(UInt32 id, const WChar* type)
: id_(id)
, type_(type)
{
diff --git a/src/kiwano/base/Resource.h b/src/kiwano/base/Resource.h
index 0b5acb61..114c1202 100644
--- a/src/kiwano/base/Resource.h
+++ b/src/kiwano/base/Resource.h
@@ -49,8 +49,8 @@ namespace kiwano
Resource();
Resource(
- UInt32 id, /* 资源名称 */
- LPCWSTR type /* 资源类型 */
+ UInt32 id, /* 资源 ID */
+ const WChar* type /* 资源类型 */
);
// 获取二进制数据
@@ -58,11 +58,12 @@ namespace kiwano
inline UInt32 GetId() const { return id_; }
- inline LPCWSTR GetType() const { return type_; }
+ inline const WChar* GetType() const { return type_; }
private:
- UInt32 id_;
- LPCWSTR type_;
+ UInt32 id_;
+ const WChar* type_;
+
mutable Resource::Data data_;
};
}
diff --git a/src/kiwano/base/Timer.h b/src/kiwano/base/Timer.h
index 20d066af..5d3b4d62 100644
--- a/src/kiwano/base/Timer.h
+++ b/src/kiwano/base/Timer.h
@@ -48,7 +48,7 @@ namespace kiwano
explicit Timer(
Callback const& func, /* 执行函数 */
Duration delay, /* 时间间隔(秒) */
- Int32 times = -1, /* 执行次数(设 -1 为永久执行) */
+ Int32 times = -1, /* 执行次数(设 -1 为永久执行) */
String const& name = L"" /* 任务名称 */
);
@@ -68,8 +68,8 @@ namespace kiwano
protected:
bool running_;
- Int32 run_times_;
- Int32 total_times_;
+ Int32 run_times_;
+ Int32 total_times_;
Duration delay_;
Duration delta_;
Callback callback_;
diff --git a/src/kiwano/base/Window.cpp b/src/kiwano/base/Window.cpp
index c2027c29..296f4257 100644
--- a/src/kiwano/base/Window.cpp
+++ b/src/kiwano/base/Window.cpp
@@ -66,7 +66,7 @@ namespace kiwano
}
}
- void Window::Init(String const& title, Int32 width, Int32 height, LPCWSTR icon, bool fullscreen, WNDPROC proc)
+ void Window::Init(String const& title, Int32 width, Int32 height, UInt32 icon, bool fullscreen, WNDPROC proc)
{
HINSTANCE hinst = GetModuleHandleW(nullptr);
WNDCLASSEX wcex = { 0 };
@@ -84,7 +84,7 @@ namespace kiwano
if (icon)
{
- wcex.hIcon = (HICON)::LoadImageW(hinst, icon, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
+ wcex.hIcon = (HICON)::LoadImageW(hinst, MAKEINTRESOURCE(icon), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
}
::RegisterClassExW(&wcex);
@@ -216,14 +216,14 @@ namespace kiwano
return static_cast(height_);
}
- void Window::SetIcon(LPCWSTR icon_resource)
+ void Window::SetIcon(UInt32 icon_resource)
{
if (handle_)
{
HINSTANCE hinstance = GetModuleHandle(nullptr);
HICON icon = (HICON)::LoadImage(
hinstance,
- icon_resource,
+ MAKEINTRESOURCE(icon_resource),
IMAGE_ICON,
0,
0,
diff --git a/src/kiwano/base/Window.h b/src/kiwano/base/Window.h
index 8c649f74..b0c791e6 100644
--- a/src/kiwano/base/Window.h
+++ b/src/kiwano/base/Window.h
@@ -48,7 +48,7 @@ namespace kiwano
void SetTitle(String const& title);
// 设置窗口图标
- void SetIcon(LPCWSTR icon_resource);
+ void SetIcon(UInt32 icon_resource);
// 重设窗口大小
void Resize(Int32 width, Int32 height);
@@ -62,9 +62,9 @@ namespace kiwano
public:
void Init(
String const& title,
- Int32 width,
- Int32 height,
- LPCWSTR icon,
+ Int32 width,
+ Int32 height,
+ UInt32 icon,
bool fullscreen,
WNDPROC proc
);
@@ -85,11 +85,11 @@ namespace kiwano
~Window();
private:
- HWND handle_;
- bool is_fullscreen_;
+ HWND handle_;
+ bool is_fullscreen_;
Int32 width_;
Int32 height_;
- WCHAR* device_name_;
- MouseCursor mouse_cursor_;
+ WCHAR* device_name_;
+ MouseCursor mouse_cursor_;
};
}
diff --git a/src/kiwano/core/types.h b/src/kiwano/core/types.h
index 85f23f2a..a7d74bd9 100644
--- a/src/kiwano/core/types.h
+++ b/src/kiwano/core/types.h
@@ -28,6 +28,7 @@ namespace kiwano
KGE_DEFINE_NUMERIC_TYPE(Char, signed char);
KGE_DEFINE_NUMERIC_TYPE(UChar, unsigned char);
KGE_DEFINE_NUMERIC_TYPE(WChar, wchar_t);
+ KGE_DEFINE_NUMERIC_TYPE(Byte, UChar);
KGE_DEFINE_NUMERIC_TYPE(Int8, std::int8_t);
KGE_DEFINE_NUMERIC_TYPE(Int16, std::int16_t);
diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp
index 0fe4bd50..8c75ca79 100644
--- a/src/kiwano/platform/Application.cpp
+++ b/src/kiwano/platform/Application.cpp
@@ -43,7 +43,7 @@ namespace kiwano
Queue functions_to_perform_;
}
- Options::Options(String const& title, Int32 width, Int32 height, LPCWSTR icon, Color clear_color, bool vsync, bool fullscreen, bool debug)
+ Options::Options(String const& title, Int32 width, Int32 height, UInt32 icon, Color clear_color, bool vsync, bool fullscreen, bool debug)
: title(title)
, width(width)
, height(height)
diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h
index d42cb0b0..613b5658 100644
--- a/src/kiwano/platform/Application.h
+++ b/src/kiwano/platform/Application.h
@@ -30,23 +30,23 @@ namespace kiwano
struct Options
{
String title; // 标题
- Int32 width; // 宽度
- Int32 height; // 高度
- LPCWSTR icon; // 图标
+ Int32 width; // 宽度
+ Int32 height; // 高度
+ UInt32 icon; // 图标资源 ID
Color clear_color; // 清屏颜色
bool vsync; // 垂直同步
bool fullscreen; // 全屏模式
bool debug; // 调试模式
Options(
- String const& title = L"Kiwano Game",
- Int32 width = 640,
- Int32 height = 480,
- LPCWSTR icon = nullptr,
- Color clear_color = Color::Black,
- bool vsync = true,
- bool fullscreen = false,
- bool debug = false
+ String const& title = L"Kiwano Game",
+ Int32 width = 640,
+ Int32 height = 480,
+ UInt32 icon = 0,
+ Color clear_color = Color::Black,
+ bool vsync = true,
+ bool fullscreen = false,
+ bool debug = false
);
};
diff --git a/src/kiwano/renderer/GifImage.cpp b/src/kiwano/renderer/GifImage.cpp
index e4b6655e..bb8b3453 100644
--- a/src/kiwano/renderer/GifImage.cpp
+++ b/src/kiwano/renderer/GifImage.cpp
@@ -191,7 +191,7 @@ namespace kiwano
HRESULT GifImage::GetBackgroundColor(ComPtr metadata_reader)
{
- BYTE bg_index = 0;
+ UChar bg_index = 0;
WICColor bgcolors[256];
UInt32 colors_copied = 0;
ComPtr wic_palette;
diff --git a/src/kiwano/renderer/win32/FontCollectionLoader.cpp b/src/kiwano/renderer/win32/FontCollectionLoader.cpp
index d896e7ac..94c41e4d 100644
--- a/src/kiwano/renderer/win32/FontCollectionLoader.cpp
+++ b/src/kiwano/renderer/win32/FontCollectionLoader.cpp
@@ -948,7 +948,7 @@ namespace kiwano
if (fileOffset <= resourceSize_ &&
fragmentSize <= resourceSize_ - fileOffset)
{
- *fragmentStart = static_cast(resourcePtr_) + static_cast(fileOffset);
+ *fragmentStart = static_cast(resourcePtr_) + static_cast(fileOffset);
*fragmentContext = NULL;
return S_OK;
}