diff --git a/projects/kiwano-audio/kiwano-audio.vcxproj b/projects/kiwano-audio/kiwano-audio.vcxproj index dd9b4bb5..8cc7bd78 100644 --- a/projects/kiwano-audio/kiwano-audio.vcxproj +++ b/projects/kiwano-audio/kiwano-audio.vcxproj @@ -2,7 +2,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -110,4 +110,4 @@ - + \ No newline at end of file diff --git a/projects/kiwano-audio/kiwano-audio.vcxproj.filters b/projects/kiwano-audio/kiwano-audio.vcxproj.filters index a842f4fe..f3d328d0 100644 --- a/projects/kiwano-audio/kiwano-audio.vcxproj.filters +++ b/projects/kiwano-audio/kiwano-audio.vcxproj.filters @@ -2,17 +2,17 @@ - + - + \ No newline at end of file diff --git a/projects/kiwano-network/kiwano-network.vcxproj b/projects/kiwano-network/kiwano-network.vcxproj index e79a83ee..51202a6b 100644 --- a/projects/kiwano-network/kiwano-network.vcxproj +++ b/projects/kiwano-network/kiwano-network.vcxproj @@ -1,7 +1,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/projects/kiwano-network/kiwano-network.vcxproj.filters b/projects/kiwano-network/kiwano-network.vcxproj.filters index 6b32af09..387c6f9e 100644 --- a/projects/kiwano-network/kiwano-network.vcxproj.filters +++ b/projects/kiwano-network/kiwano-network.vcxproj.filters @@ -2,12 +2,12 @@ - + - + \ No newline at end of file diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj index ddad3882..e07983f0 100644 --- a/projects/kiwano/kiwano.vcxproj +++ b/projects/kiwano/kiwano.vcxproj @@ -39,7 +39,7 @@ - + @@ -116,7 +116,7 @@ - + diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters index f1c594c4..daf84566 100644 --- a/projects/kiwano/kiwano.vcxproj.filters +++ b/projects/kiwano/kiwano.vcxproj.filters @@ -42,9 +42,6 @@ 2d - - core - core @@ -303,6 +300,9 @@ core + + core + @@ -386,9 +386,6 @@ core - - core - utils @@ -512,5 +509,8 @@ render + + core + \ No newline at end of file diff --git a/src/3rd-party/curl/curl.h b/src/3rd-party/curl/curl.h index 55df17e4..5b4ae469 100644 --- a/src/3rd-party/curl/curl.h +++ b/src/3rd-party/curl/curl.h @@ -2312,7 +2312,7 @@ typedef enum { /***************************************************************************** - * SetupComponent defines, protos etc for the sharing stuff. + * Setup defines, protos etc for the sharing stuff. */ /* Different data locks for a single share */ diff --git a/src/kiwano-audio/AudioEngine.cpp b/src/kiwano-audio/AudioModule.cpp similarity index 86% rename from src/kiwano-audio/AudioEngine.cpp rename to src/kiwano-audio/AudioModule.cpp index 146b3f32..5db90bca 100644 --- a/src/kiwano-audio/AudioEngine.cpp +++ b/src/kiwano-audio/AudioModule.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include #include #include @@ -27,15 +27,15 @@ namespace kiwano { namespace audio { -AudioEngine::AudioEngine() +AudioModule::AudioModule() : x_audio2_(nullptr) , mastering_voice_(nullptr) { } -AudioEngine::~AudioEngine() {} +AudioModule::~AudioModule() {} -void AudioEngine::SetupComponent() +void AudioModule::SetupModule() { KGE_SYS_LOG("Creating audio resources"); @@ -54,7 +54,7 @@ void AudioEngine::SetupComponent() ThrowIfFailed(hr, "Create audio resources failed"); } -void AudioEngine::DestroyComponent() +void AudioModule::DestroyModule() { KGE_SYS_LOG("Destroying audio resources"); @@ -73,9 +73,9 @@ void AudioEngine::DestroyComponent() dlls::MediaFoundation::Get().MFShutdown(); } -bool AudioEngine::CreateSound(Sound& sound, const Transcoder::Buffer& buffer) +bool AudioModule::CreateSound(Sound& sound, const Transcoder::Buffer& buffer) { - KGE_ASSERT(x_audio2_ && "AudioEngine hasn't been initialized!"); + KGE_ASSERT(x_audio2_ && "AudioModule hasn't been initialized!"); HRESULT hr = S_OK; @@ -109,17 +109,17 @@ bool AudioEngine::CreateSound(Sound& sound, const Transcoder::Buffer& buffer) return true; } -void AudioEngine::Open() +void AudioModule::Open() { - KGE_ASSERT(x_audio2_ && "AudioEngine hasn't been initialized!"); + KGE_ASSERT(x_audio2_ && "AudioModule hasn't been initialized!"); if (x_audio2_) x_audio2_->StartEngine(); } -void AudioEngine::Close() +void AudioModule::Close() { - KGE_ASSERT(x_audio2_ && "AudioEngine hasn't been initialized!"); + KGE_ASSERT(x_audio2_ && "AudioModule hasn't been initialized!"); if (x_audio2_) x_audio2_->StopEngine(); diff --git a/src/kiwano-audio/AudioEngine.h b/src/kiwano-audio/AudioModule.h similarity index 84% rename from src/kiwano-audio/AudioEngine.h rename to src/kiwano-audio/AudioModule.h index c41aa2b7..48ef9321 100644 --- a/src/kiwano-audio/AudioEngine.h +++ b/src/kiwano-audio/AudioModule.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include namespace kiwano @@ -32,7 +32,7 @@ namespace audio /** * \~chinese - * \defgroup Audio 音频引擎 + * \defgroup Audio 音频模块 */ /** @@ -42,13 +42,13 @@ namespace audio /** * \~chinese - * @brief 音频引擎 + * @brief 音频模块 */ -class KGE_API AudioEngine - : public Singleton - , public ComponentBase +class KGE_API AudioModule + : public Singleton + , public Module { - friend Singleton; + friend Singleton; public: /// \~chinese @@ -64,14 +64,14 @@ public: bool CreateSound(Sound& sound, const Transcoder::Buffer& buffer); public: - void SetupComponent() override; + void SetupModule() override; - void DestroyComponent() override; + void DestroyModule() override; private: - AudioEngine(); + AudioModule(); - ~AudioEngine(); + ~AudioModule(); private: IXAudio2* x_audio2_; diff --git a/src/kiwano-audio/Sound.cpp b/src/kiwano-audio/Sound.cpp index 9ac35722..56e25674 100644 --- a/src/kiwano-audio/Sound.cpp +++ b/src/kiwano-audio/Sound.cpp @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include +#include #include #include #include @@ -83,7 +83,7 @@ bool Sound::Load(String const& file_path) return false; } - if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) + if (!AudioModule::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) { Close(); return false; @@ -107,7 +107,7 @@ bool Sound::Load(Resource const& res) return false; } - if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) + if (!AudioModule::GetInstance().CreateSound(*this, transcoder_.GetBuffer())) { Close(); return false; diff --git a/src/kiwano-audio/Sound.h b/src/kiwano-audio/Sound.h index ab17bbf4..21c79e41 100644 --- a/src/kiwano-audio/Sound.h +++ b/src/kiwano-audio/Sound.h @@ -29,7 +29,7 @@ namespace kiwano { namespace audio { -class AudioEngine; +class AudioModule; KGE_DECLARE_SMART_PTR(Sound); @@ -44,7 +44,7 @@ KGE_DECLARE_SMART_PTR(Sound); */ class KGE_API Sound : public virtual ObjectBase { - friend class AudioEngine; + friend class AudioModule; public: /// \~chinese diff --git a/src/kiwano-audio/kiwano-audio.h b/src/kiwano-audio/kiwano-audio.h index 975d92e1..f4b025f7 100644 --- a/src/kiwano-audio/kiwano-audio.h +++ b/src/kiwano-audio/kiwano-audio.h @@ -20,6 +20,6 @@ #pragma once -#include +#include #include #include diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp index ae1f7b1f..3a7dbba2 100644 --- a/src/kiwano-imgui/ImGuiModule.cpp +++ b/src/kiwano-imgui/ImGuiModule.cpp @@ -18,7 +18,7 @@ ImGuiModule::ImGuiModule() { } -void ImGuiModule::SetupComponent() +void ImGuiModule::SetupModule() { // Setup Dear ImGui context IMGUI_CHECKVERSION(); @@ -58,7 +58,7 @@ void ImGuiModule::SetupComponent() ImGui_Impl_Init(); } -void ImGuiModule::DestroyComponent() +void ImGuiModule::DestroyModule() { ImGui_Impl_Shutdown(); ImGui::DestroyContext(); diff --git a/src/kiwano-imgui/ImGuiModule.h b/src/kiwano-imgui/ImGuiModule.h index 700826e1..0a5c34aa 100644 --- a/src/kiwano-imgui/ImGuiModule.h +++ b/src/kiwano-imgui/ImGuiModule.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { @@ -33,18 +33,18 @@ namespace imgui */ class ImGuiModule : public Singleton - , public RenderComponent - , public UpdateComponent - , public EventComponent + , public RenderModule + , public UpdateModule + , public EventModule { friend Singleton; public: ImGuiModule(); - void SetupComponent() override; + void SetupModule() override; - void DestroyComponent() override; + void DestroyModule() override; void BeforeRender() override; diff --git a/src/kiwano-network/HttpClient.cpp b/src/kiwano-network/HttpModule.cpp similarity index 92% rename from src/kiwano-network/HttpClient.cpp rename to src/kiwano-network/HttpModule.cpp index fb2a1b59..b1edbdc3 100644 --- a/src/kiwano-network/HttpClient.cpp +++ b/src/kiwano-network/HttpModule.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include <3rd-party/curl/curl.h> // CURL namespace @@ -67,7 +67,7 @@ public: } } - bool Init(HttpClient* client, Vector const& headers, String const& url, String* response_data, + bool Init(HttpModule* client, Vector const& headers, String const& url, String* response_data, String* response_header, char* error_buffer) { if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer)) @@ -132,7 +132,7 @@ public: } public: - static inline bool GetRequest(HttpClient* client, Vector const& headers, String const& url, + static inline bool GetRequest(HttpModule* client, Vector const& headers, String const& url, long* response_code, String* response_data, String* response_header, char* error_buffer) { @@ -141,7 +141,7 @@ public: && curl.SetOption(CURLOPT_FOLLOWLOCATION, true) && curl.Perform(response_code); } - static inline bool PostRequest(HttpClient* client, Vector const& headers, String const& url, + static inline bool PostRequest(HttpModule* client, Vector const& headers, String const& url, String const& request_data, long* response_code, String* response_data, String* response_header, char* error_buffer) { @@ -151,7 +151,7 @@ public: && curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code); } - static inline bool PutRequest(HttpClient* client, Vector const& headers, String const& url, + static inline bool PutRequest(HttpModule* client, Vector const& headers, String const& url, String const& request_data, long* response_code, String* response_data, String* response_header, char* error_buffer) { @@ -162,7 +162,7 @@ public: && curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code); } - static inline bool DeleteRequest(HttpClient* client, Vector const& headers, String const& url, + static inline bool DeleteRequest(HttpModule* client, Vector const& headers, String const& url, long* response_code, String* response_data, String* response_header, char* error_buffer) { @@ -182,26 +182,26 @@ namespace kiwano { namespace network { -HttpClient::HttpClient() +HttpModule::HttpModule() : timeout_for_connect_(30000 /* 30 seconds */) , timeout_for_read_(60000 /* 60 seconds */) { } -void HttpClient::SetupComponent() +void HttpModule::SetupModule() { ::curl_global_init(CURL_GLOBAL_ALL); - std::thread thread(Closure(this, &HttpClient::NetworkThread)); + std::thread thread(Closure(this, &HttpModule::NetworkThread)); thread.detach(); } -void HttpClient::DestroyComponent() +void HttpModule::DestroyModule() { ::curl_global_cleanup(); } -void HttpClient::Send(HttpRequestPtr request) +void HttpModule::Send(HttpRequestPtr request) { if (!request) return; @@ -213,7 +213,7 @@ void HttpClient::Send(HttpRequestPtr request) sleep_condition_.notify_one(); } -void HttpClient::NetworkThread() +void HttpModule::NetworkThread() { while (true) { @@ -235,11 +235,11 @@ void HttpClient::NetworkThread() response_queue_.push(response); response_mutex_.unlock(); - Application::GetInstance().PreformInMainThread(Closure(this, &HttpClient::DispatchResponseCallback)); + Application::GetInstance().PreformInMainThread(Closure(this, &HttpModule::DispatchResponseCallback)); } } -void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response) +void HttpModule::Perform(HttpRequestPtr request, HttpResponsePtr response) { bool ok = false; long response_code = 0; @@ -273,7 +273,7 @@ void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response) ok = Curl::DeleteRequest(this, headers, url, &response_code, &response_data, &response_header, error_message); break; default: - KGE_ERROR("HttpClient: unknown request type, only GET, POST, PUT or DELETE is supported"); + KGE_ERROR("HttpModule: unknown request type, only GET, POST, PUT or DELETE is supported"); return; } @@ -291,7 +291,7 @@ void HttpClient::Perform(HttpRequestPtr request, HttpResponsePtr response) } } -void HttpClient::DispatchResponseCallback() +void HttpModule::DispatchResponseCallback() { HttpResponsePtr response; diff --git a/src/kiwano-network/HttpClient.h b/src/kiwano-network/HttpModule.h similarity index 82% rename from src/kiwano-network/HttpClient.h rename to src/kiwano-network/HttpModule.h index 7cd5dcb0..8450fa0c 100644 --- a/src/kiwano-network/HttpClient.h +++ b/src/kiwano-network/HttpModule.h @@ -21,7 +21,7 @@ #pragma once #include #include -#include +#include #include namespace kiwano @@ -40,13 +40,13 @@ namespace network /** * \~chinese - * @brief HTTP客户端 + * @brief HTTP模块 */ -class KGE_API HttpClient - : public Singleton - , public ComponentBase +class KGE_API HttpModule + : public Singleton + , public Module { - friend Singleton; + friend Singleton; public: /// \~chinese @@ -80,12 +80,12 @@ public: String const& GetSSLVerification() const; public: - virtual void SetupComponent() override; + virtual void SetupModule() override; - virtual void DestroyComponent() override; + virtual void DestroyModule() override; private: - HttpClient(); + HttpModule(); void NetworkThread(); @@ -110,32 +110,32 @@ private: /** @} */ -inline void HttpClient::SetTimeoutForConnect(Duration timeout) +inline void HttpModule::SetTimeoutForConnect(Duration timeout) { timeout_for_connect_ = timeout; } -inline Duration HttpClient::GetTimeoutForConnect() const +inline Duration HttpModule::GetTimeoutForConnect() const { return timeout_for_connect_; } -inline void HttpClient::SetTimeoutForRead(Duration timeout) +inline void HttpModule::SetTimeoutForRead(Duration timeout) { timeout_for_read_ = timeout; } -inline Duration HttpClient::GetTimeoutForRead() const +inline Duration HttpModule::GetTimeoutForRead() const { return timeout_for_read_; } -inline void HttpClient::SetSSLVerification(String const& root_certificate_path) +inline void HttpModule::SetSSLVerification(String const& root_certificate_path) { ssl_verification_ = root_certificate_path; } -inline String const& HttpClient::GetSSLVerification() const +inline String const& HttpModule::GetSSLVerification() const { return ssl_verification_; } diff --git a/src/kiwano-network/kiwano-network.h b/src/kiwano-network/kiwano-network.h index 47b8801f..75060033 100644 --- a/src/kiwano-network/kiwano-network.h +++ b/src/kiwano-network/kiwano-network.h @@ -22,4 +22,4 @@ #include #include -#include +#include diff --git a/src/kiwano/core/Director.h b/src/kiwano/core/Director.h index da744ea6..a15b037e 100644 --- a/src/kiwano/core/Director.h +++ b/src/kiwano/core/Director.h @@ -22,7 +22,7 @@ #include #include #include -#include +#include namespace kiwano { @@ -34,9 +34,9 @@ namespace kiwano */ class KGE_API Director : public Singleton - , public UpdateComponent - , public RenderComponent - , public EventComponent + , public UpdateModule + , public RenderModule + , public EventModule { friend Singleton; @@ -92,9 +92,9 @@ public: void ClearStages(); public: - void SetupComponent() override {} + void SetupModule() override {} - void DestroyComponent() override {} + void DestroyModule() override {} void OnUpdate(Duration dt) override; diff --git a/src/kiwano/core/Component.cpp b/src/kiwano/core/Module.cpp similarity index 68% rename from src/kiwano/core/Component.cpp rename to src/kiwano/core/Module.cpp index 720ecdb1..38a3182b 100644 --- a/src/kiwano/core/Component.cpp +++ b/src/kiwano/core/Module.cpp @@ -18,39 +18,29 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include - -#define KGE_DEFINE_COMPONENT_FLAG(OFFSET) (0x01 << (OFFSET % 32)) +#include namespace kiwano { -const int RenderComponent::flag = KGE_DEFINE_COMPONENT_FLAG(0); -const int UpdateComponent::flag = KGE_DEFINE_COMPONENT_FLAG(1); -const int EventComponent::flag = KGE_DEFINE_COMPONENT_FLAG(2); -ComponentBase::ComponentBase() +Module::Module() : flag_(0) { } -bool ComponentBase::Check(const int flag) +RenderModule::RenderModule() { - return !!(flag_ & flag); + flag_ |= ModuleFlag::value; } -RenderComponent::RenderComponent() +UpdateModule::UpdateModule() { - flag_ |= flag; + flag_ |= ModuleFlag::value; } -UpdateComponent::UpdateComponent() +EventModule::EventModule() { - flag_ |= flag; -} - -EventComponent::EventComponent() -{ - flag_ |= flag; + flag_ |= ModuleFlag::value; } } // namespace kiwano diff --git a/src/kiwano/core/Component.h b/src/kiwano/core/Module.h similarity index 65% rename from src/kiwano/core/Component.h rename to src/kiwano/core/Module.h index d1c8f45e..bad0e010 100644 --- a/src/kiwano/core/Component.h +++ b/src/kiwano/core/Module.h @@ -20,32 +20,40 @@ #pragma once #include -#include namespace kiwano { class RenderContext; class Event; +template +struct ModuleFlag; + /** * \~chinese - * @brief 基础功能组件 + * @brief 基础模块 */ -class KGE_API ComponentBase +class KGE_API Module { public: /// \~chinese - /// @brief 启动组件 - virtual void SetupComponent() = 0; + /// @brief 启动模块 + virtual void SetupModule() {} /// \~chinese - /// @brief 销毁组件 - virtual void DestroyComponent() = 0; + /// @brief 销毁模块 + virtual void DestroyModule() {} - bool Check(const int flag); + template + _CompTy* Cast() + { + if (flag_ & ModuleFlag<_CompTy>::value) + return dynamic_cast<_CompTy*>(this); + return nullptr; + } protected: - ComponentBase(); + Module(); protected: int flag_; @@ -53,9 +61,9 @@ protected: /** * \~chinese - * @brief 渲染支持组件 + * @brief 渲染模块 */ -class KGE_API RenderComponent : public virtual ComponentBase +class KGE_API RenderModule : public virtual Module { public: /// \~chinese @@ -72,16 +80,14 @@ public: virtual void AfterRender() {} public: - static const int flag; - - RenderComponent(); + RenderModule(); }; /** * \~chinese - * @brief 更新支持组件 + * @brief 更新模块 */ -class KGE_API UpdateComponent : public virtual ComponentBase +class KGE_API UpdateModule : public virtual Module { public: /// \~chinese @@ -98,16 +104,14 @@ public: virtual void AfterUpdate() {} public: - static const int flag; - - UpdateComponent(); + UpdateModule(); }; /** * \~chinese - * @brief 事件支持组件 + * @brief 事件模块 */ -class KGE_API EventComponent : public virtual ComponentBase +class KGE_API EventModule : public virtual Module { public: /// \~chinese @@ -116,8 +120,29 @@ public: virtual void HandleEvent(Event* evt) {} public: - static const int flag; - - EventComponent(); + EventModule(); }; + +#define KGE_DEFINE_COMPONENT_FLAG(OFFSET) (0x01 << (OFFSET % 32)) + +template <> +struct ModuleFlag +{ + static constexpr int value = KGE_DEFINE_COMPONENT_FLAG(0); +}; + +template <> +struct ModuleFlag +{ + static constexpr int value = KGE_DEFINE_COMPONENT_FLAG(1); +}; + +template <> +struct ModuleFlag +{ + static constexpr int value = KGE_DEFINE_COMPONENT_FLAG(2); +}; + +#undef KGE_DEFINE_COMPONENT_FLAG + } // namespace kiwano diff --git a/src/kiwano/core/Time.h b/src/kiwano/core/Time.h index 3a9bde50..85458384 100644 --- a/src/kiwano/core/Time.h +++ b/src/kiwano/core/Time.h @@ -20,7 +20,6 @@ #pragma once #include -#include namespace kiwano { diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 91dd7a81..c3a3498d 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -32,19 +32,19 @@ Application::Application() : quiting_(false) , time_scale_(1.f) { - Use(&Renderer::GetInstance()); - Use(&Input::GetInstance()); - Use(&Director::GetInstance()); + Use(Renderer::GetInstance()); + Use(Input::GetInstance()); + Use(Director::GetInstance()); } Application::~Application() {} void Application::Run(Runner& runner, bool debug) { - // Setup all components - for (auto c : comps_) + // Setup all modules + for (auto c : modules_) { - c->SetupComponent(); + c->SetupModule(); } if (debug) @@ -100,35 +100,22 @@ void Application::Destroy() ResourceCache::GetInstance().Clear(); TextureCache::GetInstance().Clear(); - for (auto iter = comps_.rbegin(); iter != comps_.rend(); ++iter) + for (auto iter = modules_.rbegin(); iter != modules_.rend(); ++iter) { - (*iter)->DestroyComponent(); + (*iter)->DestroyModule(); } } -void Application::Use(ComponentBase* component) +void Application::Use(Module& module) { - if (component) - { - #if defined(KGE_DEBUG) - if (std::find(comps_.begin(), comps_.end(), component) != comps_.end()) - { - KGE_ASSERT(false && "Component already exists!"); - } + if (std::find(modules_.begin(), modules_.end(), &module) != modules_.end()) + { + KGE_ASSERT(false && "Module already exists!"); + } #endif - comps_.push_back(component); - - if (component->Check(RenderComponent::flag)) - render_comps_.push_back(dynamic_cast(component)); - - if (component->Check(UpdateComponent::flag)) - update_comps_.push_back(dynamic_cast(component)); - - if (component->Check(EventComponent::flag)) - event_comps_.push_back(dynamic_cast(component)); - } + modules_.push_back(&module); } void Application::SetTimeScale(float scale_factor) @@ -139,9 +126,12 @@ void Application::SetTimeScale(float scale_factor) void Application::Update() { // Before update - for (auto c : update_comps_) + for (auto comp : modules_) { - c->BeforeUpdate(); + if (auto update_comp = comp->Cast()) + { + update_comp->BeforeUpdate(); + } } // perform functions @@ -171,16 +161,22 @@ void Application::Update() last_update_time_ = now; - for (auto c : update_comps_) + for (auto comp : modules_) { - c->OnUpdate(dt); + if (auto update_comp = comp->Cast()) + { + update_comp->OnUpdate(dt); + } } } // After update - for (auto rit = update_comps_.rbegin(); rit != update_comps_.rend(); ++rit) + for (auto rit = modules_.rbegin(); rit != modules_.rend(); ++rit) { - (*rit)->AfterUpdate(); + if (auto update_comp = (*rit)->Cast()) + { + update_comp->AfterUpdate(); + } } } @@ -190,23 +186,32 @@ void Application::Render() renderer.Clear(); // Before render - for (auto c : render_comps_) + for (auto comp : modules_) { - c->BeforeRender(); + if (auto render_comp = comp->Cast()) + { + render_comp->BeforeRender(); + } } // Rendering renderer.BeginDraw(); - for (auto c : render_comps_) + for (auto comp : modules_) { - c->OnRender(renderer.GetContext()); + if (auto render_comp = comp->Cast()) + { + render_comp->OnRender(renderer.GetContext()); + } } renderer.EndDraw(); // After render - for (auto rit = render_comps_.rbegin(); rit != render_comps_.rend(); ++rit) + for (auto rit = modules_.rbegin(); rit != modules_.rend(); ++rit) { - (*rit)->AfterRender(); + if (auto render_comp = (*rit)->Cast()) + { + render_comp->AfterRender(); + } } renderer.Present(); @@ -214,9 +219,12 @@ void Application::Render() void Application::DispatchEvent(Event* evt) { - for (auto c : event_comps_) + for (auto comp : modules_) { - c->HandleEvent(evt); + if (auto event_comp = comp->Cast()) + { + event_comp->HandleEvent(evt); + } } } diff --git a/src/kiwano/platform/Application.h b/src/kiwano/platform/Application.h index 36e36fad..090aff07 100644 --- a/src/kiwano/platform/Application.h +++ b/src/kiwano/platform/Application.h @@ -21,7 +21,7 @@ #pragma once #include #include -#include +#include #include #include #include @@ -67,10 +67,10 @@ public: /** * \~chinese - * @brief 添加功能组件 - * @param[in] component 功能组件 + * @brief 添加模块 + * @param[in] module 模块 */ - void Use(ComponentBase* component); + void Use(Module& module); /** * \~chinese @@ -84,7 +84,7 @@ public: /** * \~chinese * @brief 分发事件 - * @details 将事件分发给所有事件功能组件 + * @details 将事件分发给所有事件功能模块 * @param evt 事件 */ void DispatchEvent(Event* evt); @@ -100,26 +100,23 @@ public: private: /** * \~chinese - * @brief 更新所有组件 + * @brief 更新所有模块 */ void Update(); /** * \~chinese - * @brief 渲染所有组件 + * @brief 渲染所有模块 */ void Render(); private: - bool quiting_; - float time_scale_; - Time last_update_time_; - Vector comps_; - Vector render_comps_; - Vector update_comps_; - Vector event_comps_; - std::mutex perform_mutex_; - Queue> functions_to_perform_; + bool quiting_; + float time_scale_; + Time last_update_time_; + List modules_; + std::mutex perform_mutex_; + Queue> functions_to_perform_; }; } // namespace kiwano diff --git a/src/kiwano/platform/Input.h b/src/kiwano/platform/Input.h index e4854c56..494d7f21 100644 --- a/src/kiwano/platform/Input.h +++ b/src/kiwano/platform/Input.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include #include #include #include @@ -34,8 +34,8 @@ namespace kiwano */ class KGE_API Input : public Singleton - , public UpdateComponent - , public EventComponent + , public UpdateModule + , public EventModule { friend Singleton; @@ -103,9 +103,9 @@ public: Point GetMousePos() const; public: - void SetupComponent() override {} + void SetupModule() override {} - void DestroyComponent() override {} + void DestroyModule() override {} void AfterUpdate() override; diff --git a/src/kiwano/render/DirectX/RendererImpl.cpp b/src/kiwano/render/DirectX/RendererImpl.cpp index 90b2c40b..494bdc91 100644 --- a/src/kiwano/render/DirectX/RendererImpl.cpp +++ b/src/kiwano/render/DirectX/RendererImpl.cpp @@ -46,7 +46,7 @@ RendererImpl::RendererImpl() render_ctx_ = new RenderContextImpl; } -void RendererImpl::SetupComponent() +void RendererImpl::SetupModule() { KGE_SYS_LOG("Creating device resources"); @@ -115,7 +115,7 @@ void RendererImpl::SetupComponent() ThrowIfFailed(hr, "Create render resources failed"); } -void RendererImpl::DestroyComponent() +void RendererImpl::DestroyModule() { KGE_SYS_LOG("Destroying device resources"); diff --git a/src/kiwano/render/DirectX/RendererImpl.h b/src/kiwano/render/DirectX/RendererImpl.h index 2ca69e6d..2c010a2d 100644 --- a/src/kiwano/render/DirectX/RendererImpl.h +++ b/src/kiwano/render/DirectX/RendererImpl.h @@ -103,9 +103,9 @@ public: ID3DDeviceResources* GetD3DDeviceResources(); public: - void SetupComponent() override; + void SetupModule() override; - void DestroyComponent() override; + void DestroyModule() override; void HandleEvent(Event* evt) override; diff --git a/src/kiwano/render/Renderer.h b/src/kiwano/render/Renderer.h index 5e921baa..85c1f906 100644 --- a/src/kiwano/render/Renderer.h +++ b/src/kiwano/render/Renderer.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include @@ -43,7 +43,7 @@ namespace kiwano * \~chinese * @brief 渲染器 */ -class KGE_API Renderer : public EventComponent +class KGE_API Renderer : public EventModule { public: /// \~chinese