From 2345e22792ff4761f1a6a37d9f249e5405840450 Mon Sep 17 00:00:00 2001 From: Nomango Date: Tue, 10 Sep 2019 11:50:19 +0800 Subject: [PATCH 01/29] fix SoundPlayer --- projects/kiwano.vcxproj | 8 +++--- projects/kiwano.vcxproj.filters | 27 ++++++++++--------- src/kiwano-audio/src/Sound.cpp | 4 +-- src/kiwano-audio/src/Sound.h | 8 +++--- src/kiwano-audio/src/SoundPlayer.cpp | 12 ++++----- src/kiwano-audio/src/SoundPlayer.h | 4 +-- src/kiwano-audio/src/Transcoder.cpp | 2 +- src/kiwano-audio/src/Transcoder.h | 1 + src/kiwano-audio/src/audio.cpp | 5 ++-- src/kiwano-audio/src/audio.h | 4 ++- .../{renderer => base}/win32/ComPtr.hpp | 0 src/kiwano/kiwano.h | 6 ++--- src/kiwano/math/Vec2.hpp | 2 +- .../math/{constants.hpp => constants.h} | 0 src/kiwano/math/{ease.hpp => ease.h} | 2 +- src/kiwano/math/math.h | 6 ++--- src/kiwano/math/{scalar.hpp => scalar.h} | 2 +- src/kiwano/renderer/FontCollection.h | 2 +- 18 files changed, 50 insertions(+), 45 deletions(-) rename src/kiwano/{renderer => base}/win32/ComPtr.hpp (100%) rename src/kiwano/math/{constants.hpp => constants.h} (100%) rename src/kiwano/math/{ease.hpp => ease.h} (99%) rename src/kiwano/math/{scalar.hpp => scalar.h} (99%) diff --git a/projects/kiwano.vcxproj b/projects/kiwano.vcxproj index 5471ccdc..38c631e2 100644 --- a/projects/kiwano.vcxproj +++ b/projects/kiwano.vcxproj @@ -12,6 +12,7 @@ + @@ -54,13 +55,13 @@ - - + + - + @@ -77,7 +78,6 @@ - diff --git a/projects/kiwano.vcxproj.filters b/projects/kiwano.vcxproj.filters index 84c50126..00c3e074 100644 --- a/projects/kiwano.vcxproj.filters +++ b/projects/kiwano.vcxproj.filters @@ -40,6 +40,9 @@ {30333461-e9bc-4709-84bd-ce6e0e1a3079} + + {192a47a9-9df6-4f40-a7d3-888eb00c53ac} + @@ -93,12 +96,6 @@ base - - math - - - math - math @@ -108,9 +105,6 @@ math - - math - platform @@ -264,9 +258,6 @@ renderer - - renderer\win32 - renderer\win32 @@ -309,6 +300,18 @@ renderer + + math + + + math + + + math + + + base\win32 + diff --git a/src/kiwano-audio/src/Sound.cpp b/src/kiwano-audio/src/Sound.cpp index e9c3e11c..737dbb23 100644 --- a/src/kiwano-audio/src/Sound.cpp +++ b/src/kiwano-audio/src/Sound.cpp @@ -73,7 +73,7 @@ namespace kiwano return false; } - hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer().format); + hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer()); if (FAILED(hr)) { Close(); @@ -101,7 +101,7 @@ namespace kiwano return false; } - hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer().format); + hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder_.GetBuffer()); if (FAILED(hr)) { Close(); diff --git a/src/kiwano-audio/src/Sound.h b/src/kiwano-audio/src/Sound.h index e3e64fd9..8eda04d3 100644 --- a/src/kiwano-audio/src/Sound.h +++ b/src/kiwano-audio/src/Sound.h @@ -31,7 +31,6 @@ namespace kiwano { KGE_DECLARE_SMART_PTR(Sound); - // ÒôÀÖ¶ÔÏó class KGE_API Sound : public ObjectBase { @@ -87,9 +86,10 @@ namespace kiwano ); protected: - bool opened_; - bool playing_; - Transcoder transcoder_; + bool opened_; + bool playing_; + Transcoder transcoder_; + IXAudio2SourceVoice* voice_; }; } diff --git a/src/kiwano-audio/src/SoundPlayer.cpp b/src/kiwano-audio/src/SoundPlayer.cpp index 7503908c..72932a55 100644 --- a/src/kiwano-audio/src/SoundPlayer.cpp +++ b/src/kiwano-audio/src/SoundPlayer.cpp @@ -38,7 +38,7 @@ namespace kiwano { UInt32 hash_code = file_path.hash(); if (sound_cache_.end() != sound_cache_.find(hash_code)) - return true; + return hash_code; SoundPtr sound = new (std::nothrow) Sound; @@ -48,17 +48,17 @@ namespace kiwano { sound->SetVolume(volume_); sound_cache_.insert(std::make_pair(hash_code, sound)); - return true; + return hash_code; } } - return false; + return 0; } UInt32 SoundPlayer::Load(Resource const& res) { UInt32 hash_code = res.GetId(); if (sound_cache_.end() != sound_cache_.find(hash_code)) - return true; + return hash_code; SoundPtr sound = new (std::nothrow) Sound; @@ -68,10 +68,10 @@ namespace kiwano { sound->SetVolume(volume_); sound_cache_.insert(std::make_pair(hash_code, sound)); - return true; + return hash_code; } } - return false; + return 0; } void SoundPlayer::Play(UInt32 id, Int32 loop_count) diff --git a/src/kiwano-audio/src/SoundPlayer.h b/src/kiwano-audio/src/SoundPlayer.h index 596ea530..dde12648 100644 --- a/src/kiwano-audio/src/SoundPlayer.h +++ b/src/kiwano-audio/src/SoundPlayer.h @@ -97,8 +97,8 @@ namespace kiwano protected: Float32 volume_; - using MusicMap = Map; - MusicMap sound_cache_; + using SoundMap = Map; + SoundMap sound_cache_; }; } } diff --git a/src/kiwano-audio/src/Transcoder.cpp b/src/kiwano-audio/src/Transcoder.cpp index 4204725a..e78a4db1 100644 --- a/src/kiwano-audio/src/Transcoder.cpp +++ b/src/kiwano-audio/src/Transcoder.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include "audio-modules.h" #include "Transcoder.h" diff --git a/src/kiwano-audio/src/Transcoder.h b/src/kiwano-audio/src/Transcoder.h index 9195e0dd..21a8175a 100644 --- a/src/kiwano-audio/src/Transcoder.h +++ b/src/kiwano-audio/src/Transcoder.h @@ -19,6 +19,7 @@ // THE SOFTWARE. #pragma once +#include #include #include #include diff --git a/src/kiwano-audio/src/audio.cpp b/src/kiwano-audio/src/audio.cpp index db0d0b75..d960661a 100644 --- a/src/kiwano-audio/src/audio.cpp +++ b/src/kiwano-audio/src/audio.cpp @@ -74,7 +74,7 @@ namespace kiwano modules::MediaFoundation::Get().MFShutdown(); } - HRESULT Audio::CreateVoice(IXAudio2SourceVoice** voice, const WAVEFORMATEX* wfx) + HRESULT Audio::CreateVoice(IXAudio2SourceVoice** voice, const Transcoder::Buffer& buffer) { KGE_ASSERT(x_audio2_ && "Audio engine hasn't been initialized!"); @@ -89,8 +89,7 @@ namespace kiwano (*voice) = nullptr; } - HRESULT hr = x_audio2_->CreateSourceVoice(voice, wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO); - return hr; + return x_audio2_->CreateSourceVoice(voice, buffer.format, 0, XAUDIO2_DEFAULT_FREQ_RATIO); } void Audio::Open() diff --git a/src/kiwano-audio/src/audio.h b/src/kiwano-audio/src/audio.h index 91ddbf08..b1303a5f 100644 --- a/src/kiwano-audio/src/audio.h +++ b/src/kiwano-audio/src/audio.h @@ -21,6 +21,8 @@ #pragma once #include #include +#include +#include "Transcoder.h" namespace kiwano { @@ -45,7 +47,7 @@ namespace kiwano HRESULT CreateVoice( IXAudio2SourceVoice** voice, - const WAVEFORMATEX* wfx + const Transcoder::Buffer& buffer ); protected: diff --git a/src/kiwano/renderer/win32/ComPtr.hpp b/src/kiwano/base/win32/ComPtr.hpp similarity index 100% rename from src/kiwano/renderer/win32/ComPtr.hpp rename to src/kiwano/base/win32/ComPtr.hpp diff --git a/src/kiwano/kiwano.h b/src/kiwano/kiwano.h index 59d9e3cf..d4283fcc 100644 --- a/src/kiwano/kiwano.h +++ b/src/kiwano/kiwano.h @@ -47,9 +47,9 @@ // math // -#include "math/constants.hpp" -#include "math/scalar.hpp" -#include "math/ease.hpp" +#include "math/constants.h" +#include "math/scalar.h" +#include "math/ease.h" #include "math/Vec2.hpp" #include "math/rand.h" #include "math/Matrix.hpp" diff --git a/src/kiwano/math/Vec2.hpp b/src/kiwano/math/Vec2.hpp index 2cfc622d..aa3d2e22 100644 --- a/src/kiwano/math/Vec2.hpp +++ b/src/kiwano/math/Vec2.hpp @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include "scalar.hpp" +#include "scalar.h" namespace kiwano { diff --git a/src/kiwano/math/constants.hpp b/src/kiwano/math/constants.h similarity index 100% rename from src/kiwano/math/constants.hpp rename to src/kiwano/math/constants.h diff --git a/src/kiwano/math/ease.hpp b/src/kiwano/math/ease.h similarity index 99% rename from src/kiwano/math/ease.hpp rename to src/kiwano/math/ease.h index f1062f6d..e33543a2 100644 --- a/src/kiwano/math/ease.hpp +++ b/src/kiwano/math/ease.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include "scalar.hpp" +#include "scalar.h" namespace kiwano { diff --git a/src/kiwano/math/math.h b/src/kiwano/math/math.h index 720531cf..4b5138dc 100644 --- a/src/kiwano/math/math.h +++ b/src/kiwano/math/math.h @@ -20,9 +20,9 @@ #pragma once #include "..\core\core.h" -#include "constants.hpp" -#include "ease.hpp" -#include "scalar.hpp" +#include "constants.h" +#include "ease.h" +#include "scalar.h" #include "Vec2.hpp" #include "Rect.hpp" #include "Matrix.hpp" diff --git a/src/kiwano/math/scalar.hpp b/src/kiwano/math/scalar.h similarity index 99% rename from src/kiwano/math/scalar.hpp rename to src/kiwano/math/scalar.h index 2320018b..2087717d 100644 --- a/src/kiwano/math/scalar.hpp +++ b/src/kiwano/math/scalar.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include "constants.hpp" +#include "constants.h" #include namespace kiwano diff --git a/src/kiwano/renderer/FontCollection.h b/src/kiwano/renderer/FontCollection.h index 6d154587..1f39db4f 100644 --- a/src/kiwano/renderer/FontCollection.h +++ b/src/kiwano/renderer/FontCollection.h @@ -20,7 +20,7 @@ #pragma once #include "../base/Resource.h" -#include "win32/ComPtr.hpp" +#include "../base/win32/ComPtr.hpp" #include namespace kiwano From ccbaf0573f2c3562e0f830e1448a2e0fa222f499 Mon Sep 17 00:00:00 2001 From: Nomango Date: Tue, 10 Sep 2019 13:17:47 +0800 Subject: [PATCH 02/29] Add RenderComponent & UpdateComponent & EventComponent --- projects/kiwano.vcxproj | 1 + projects/kiwano.vcxproj.filters | 3 ++ src/kiwano-audio/src/audio.h | 11 +++--- src/kiwano-imgui/src/ImGuiModule.h | 4 +- src/kiwano-network/src/HttpClient.h | 2 +- src/kiwano/base/Component.cpp | 51 ++++++++++++++++++++++++ src/kiwano/base/Component.h | 60 ++++++++++++++++++++++++++--- src/kiwano/base/Director.h | 4 +- src/kiwano/base/Input.h | 3 +- src/kiwano/platform/Application.cpp | 51 +++++++++++------------- src/kiwano/platform/Application.h | 12 +++--- src/kiwano/renderer/Renderer.h | 3 +- 12 files changed, 154 insertions(+), 51 deletions(-) create mode 100644 src/kiwano/base/Component.cpp diff --git a/projects/kiwano.vcxproj b/projects/kiwano.vcxproj index 38c631e2..487c448c 100644 --- a/projects/kiwano.vcxproj +++ b/projects/kiwano.vcxproj @@ -115,6 +115,7 @@ + diff --git a/projects/kiwano.vcxproj.filters b/projects/kiwano.vcxproj.filters index 00c3e074..2c0c057d 100644 --- a/projects/kiwano.vcxproj.filters +++ b/projects/kiwano.vcxproj.filters @@ -491,5 +491,8 @@ renderer + + base + \ No newline at end of file diff --git a/src/kiwano-audio/src/audio.h b/src/kiwano-audio/src/audio.h index b1303a5f..a28c03f4 100644 --- a/src/kiwano-audio/src/audio.h +++ b/src/kiwano-audio/src/audio.h @@ -30,15 +30,11 @@ namespace kiwano { class KGE_API Audio : public Singleton