diff --git a/appveyor.yml b/appveyor.yml index c4d1800b..dc89cd0d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,20 +2,27 @@ version: 0.9.{build} skip_tags: true +# fetch repository as zip archive +shallow_clone: true + # pull_requests: # do_not_increment_build_number: true +# Do not build feature branch with open Pull Requests +# skip_branch_with_pr: true + # image: # - Visual Studio 2019 # - Visual Studio 2017 # - Visual Studio 2015 environment: - time_out_mins: 5 - job_to_deploy: 6 # 3(images) * 1(platform) * 2(configuration) - flag_to_deploy: false - APPVEYOR_API_TOKEN: - secure: UJFCbRNHMOqQg3e3Kv/ZnaIqqwXAt+5HDldetaZsZ5E= + global: + time_out_mins: 5 + job_to_deploy: 6 # 3(images) * 1(platform) * 2(configuration) + flag_to_deploy: false + appveyor_api_token: + secure: UJFCbRNHMOqQg3e3Kv/ZnaIqqwXAt+5HDldetaZsZ5E= matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 VS_PLATFORM_TOOLSET: v142 @@ -24,6 +31,12 @@ environment: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 VS_PLATFORM_TOOLSET: v140 +matrix: + fast_finish: true # set this flag to immediately finish build once one of the jobs fails + # allow_failures: + # - platform: x86 + # configuration: Debug + skip_commits: message: /\[chore\]/ @@ -34,14 +47,6 @@ only_commits: - scripts/**/*.ps1 - appveyor.yml -for: -- - branches: - except: - - master - only_commits: - message: /\[build\]/ - configuration: - Debug - Release @@ -62,8 +67,19 @@ build: project: projects/Kiwano.sln verbosity: minimal -after_build: -- ps: .\scripts\appveyor\wait_for_other_jobs.ps1 +for: +- + branches: + except: + - master + only_commits: + message: /\[build\]/ +- + branches: + only: + - master + after_build: + - ps: .\scripts\appveyor\wait_for_other_jobs.ps1 artifacts: - path: projects/output/**/*.lib diff --git a/projects/kiwano.vcxproj b/projects/kiwano.vcxproj index 9d80d8fb..2931f641 100644 --- a/projects/kiwano.vcxproj +++ b/projects/kiwano.vcxproj @@ -1,27 +1,38 @@ + + + + + + + + + + + + + + + + + + + - - - - - - - + - - - - + + @@ -37,7 +48,7 @@ - + @@ -45,17 +56,7 @@ - - - - - - - - - - - + @@ -70,8 +71,12 @@ + + - + + + @@ -80,22 +85,23 @@ - + - - - - - + + + + + + + - - - - + + + + - @@ -106,20 +112,24 @@ - + - + - + + + + + @@ -128,7 +138,7 @@ - + diff --git a/projects/kiwano.vcxproj.filters b/projects/kiwano.vcxproj.filters index f98d06cf..1be66a3b 100644 --- a/projects/kiwano.vcxproj.filters +++ b/projects/kiwano.vcxproj.filters @@ -10,9 +10,6 @@ {07b6d541-4a1b-472a-aae0-daf9d082fe84} - - {86e2d0f2-a9d0-4456-b6a5-d480228bbf82} - {c2654ccc-59f6-4c17-bb6b-99b07fc78702} @@ -34,6 +31,12 @@ {0cae76f7-7016-4a45-bb26-a130fbce8024} + + {9314f30d-5742-48b6-94e5-e3b4284106f6} + + + {86e2d0f2-a9d0-4456-b6a5-d480228bbf82} + @@ -42,42 +45,15 @@ ui - - 2d - - - 2d - - - 2d - - - 2d - - - 2d - - - 2d - 2d 2d - - 2d - 2d - - 2d - - - 2d - 2d @@ -99,21 +75,6 @@ 2d - - common - - - common - - - common - - - common - - - common - base @@ -129,9 +90,6 @@ base - - base - base @@ -153,9 +111,6 @@ renderer - - renderer - renderer @@ -186,9 +141,6 @@ utils - - utils - @@ -200,9 +152,6 @@ base - - base - base @@ -222,9 +171,6 @@ base - - 2d - third-party\StackWalker @@ -240,27 +186,9 @@ 2d - - common - - - common - - - common - - - common - - - common - third-party\tinyxml2 - - 2d - base @@ -270,6 +198,96 @@ 2d + + 2d + + + renderer + + + renderer + + + 2d\action + + + 2d\action + + + 2d\action + + + 2d\action + + + 2d\action + + + 2d\action + + + renderer + + + utils + + + 2d + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + base + + + core + + + 2d + + + 2d + + + renderer + + + 2d\action + + + 2d\action + + + base + + + base + + + renderer + @@ -278,36 +296,12 @@ ui - - 2d - - - 2d - - - 2d - - - 2d - - - 2d - 2d 2d - - 2d - - - 2d - - - 2d - 2d @@ -326,9 +320,6 @@ base - - base - base @@ -344,9 +335,6 @@ renderer - - renderer - renderer @@ -359,15 +347,9 @@ utils - - utils - base - - base - base @@ -383,9 +365,6 @@ base - - 2d - third-party\StackWalker @@ -398,9 +377,6 @@ third-party\tinyxml2 - - 2d - base @@ -410,5 +386,62 @@ 2d + + 2d + + + renderer + + + renderer + + + 2d\action + + + 2d\action + + + 2d\action + + + 2d\action + + + 2d\action + + + renderer + + + utils + + + 2d + + + 2d + + + 2d + + + renderer + + + 2d\action + + + 2d\action + + + base + + + base + + + renderer + \ No newline at end of file diff --git a/src/kiwano-audio/src/Player.h b/src/kiwano-audio/src/Player.h index 42286b8b..290c7de7 100644 --- a/src/kiwano-audio/src/Player.h +++ b/src/kiwano-audio/src/Player.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include "Sound.h" diff --git a/src/kiwano-audio/src/Sound.cpp b/src/kiwano-audio/src/Sound.cpp index 653f7f7d..ddf88d6f 100644 --- a/src/kiwano-audio/src/Sound.cpp +++ b/src/kiwano-audio/src/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 "Sound.h" #include "audio.h" @@ -81,7 +81,7 @@ namespace kiwano return false; } - hr = Audio::Instance()->CreateVoice(&voice_, transcoder.GetWaveFormatEx()); + hr = Audio::GetInstance()->CreateVoice(&voice_, transcoder.GetWaveFormatEx()); if (FAILED(hr)) { if (wave_data_) diff --git a/src/kiwano-audio/src/Sound.h b/src/kiwano-audio/src/Sound.h index 2f982c2e..fa505676 100644 --- a/src/kiwano-audio/src/Sound.h +++ b/src/kiwano-audio/src/Sound.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include #include #include diff --git a/src/kiwano-audio/src/Transcoder.cpp b/src/kiwano-audio/src/Transcoder.cpp index c1b676ec..4d2d7baf 100644 --- a/src/kiwano-audio/src/Transcoder.cpp +++ b/src/kiwano-audio/src/Transcoder.cpp @@ -23,10 +23,10 @@ #endif #include -#include -#include +#include +#include #include -#include +#include #include #include "audio-modules.h" #include "Transcoder.h" @@ -69,7 +69,7 @@ namespace kiwano if (SUCCEEDED(hr)) { - hr = ReadSource(reader.Get(), wave_data, wave_data_size); + hr = ReadSource(reader.get(), wave_data, wave_data_size); } return hr; @@ -100,13 +100,13 @@ namespace kiwano if (SUCCEEDED(hr)) { - hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream); + hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.get(), &byte_stream); } if (SUCCEEDED(hr)) { hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream( - byte_stream.Get(), + byte_stream.get(), nullptr, &reader ); @@ -114,7 +114,7 @@ namespace kiwano if (SUCCEEDED(hr)) { - hr = ReadSource(reader.Get(), wave_data, wave_data_size); + hr = ReadSource(reader.get(), wave_data, wave_data_size); } return hr; @@ -146,7 +146,7 @@ namespace kiwano hr = reader->SetCurrentMediaType( (DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, - partial_type.Get() + partial_type.get() ); } @@ -173,7 +173,7 @@ namespace kiwano { UINT32 size = 0; hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType( - uncompressed_type.Get(), + uncompressed_type.get(), &wave_format_, &size, (DWORD)MFWaveFormatExConvertFlag_Normal diff --git a/src/kiwano-audio/src/audio-modules.cpp b/src/kiwano-audio/src/audio-modules.cpp index 7993ea69..19fb126c 100644 --- a/src/kiwano-audio/src/audio-modules.cpp +++ b/src/kiwano-audio/src/audio-modules.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 "audio-modules.h" namespace kiwano diff --git a/src/kiwano-audio/src/audio.cpp b/src/kiwano-audio/src/audio.cpp index 38fce8ce..b703054a 100644 --- a/src/kiwano-audio/src/audio.cpp +++ b/src/kiwano-audio/src/audio.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 "audio-modules.h" #include "audio.h" diff --git a/src/kiwano-audio/src/audio.h b/src/kiwano-audio/src/audio.h index 5ec3ffe4..91ddbf08 100644 --- a/src/kiwano-audio/src/audio.h +++ b/src/kiwano-audio/src/audio.h @@ -19,7 +19,7 @@ // THE SOFTWARE. #pragma once -#include +#include #include namespace kiwano diff --git a/src/kiwano-imgui/src/ImGuiLayer.cpp b/src/kiwano-imgui/src/ImGuiLayer.cpp index 32029175..63f2b55f 100644 --- a/src/kiwano-imgui/src/ImGuiLayer.cpp +++ b/src/kiwano-imgui/src/ImGuiLayer.cpp @@ -33,8 +33,9 @@ namespace kiwano { } - void ImGuiLayer::OnRender() + void ImGuiLayer::OnRender(Renderer* renderer) { + PrepareRender(renderer); for (const auto& pipeline : pipelines_) { pipeline.second(); diff --git a/src/kiwano-imgui/src/ImGuiLayer.h b/src/kiwano-imgui/src/ImGuiLayer.h index ea84f668..7f057185 100644 --- a/src/kiwano-imgui/src/ImGuiLayer.h +++ b/src/kiwano-imgui/src/ImGuiLayer.h @@ -27,7 +27,7 @@ namespace kiwano { KGE_DECLARE_SMART_PTR(ImGuiLayer); - using ImGuiPipeline = Closure; + using ImGuiPipeline = Function; class ImGuiLayer : public Layer @@ -52,7 +52,7 @@ namespace kiwano void RemoveAllItems(); public: - void OnRender() override; + void OnRender(Renderer* renderer) override; protected: Map pipelines_; diff --git a/src/kiwano-imgui/src/ImGuiModule.cpp b/src/kiwano-imgui/src/ImGuiModule.cpp index a0ca02e1..cd8eca18 100644 --- a/src/kiwano-imgui/src/ImGuiModule.cpp +++ b/src/kiwano-imgui/src/ImGuiModule.cpp @@ -1,11 +1,11 @@ // Copyright (C) 2019 Nomango -#include -#include -#include +#include +#include +#include #include #include -#include +#include #include "ImGuiModule.h" #include "imgui_impl.h" @@ -45,9 +45,9 @@ namespace kiwano //ImGui::StyleColorsClassic(); // Setup Platform/Renderer bindings - Init(Window::Instance()->GetHandle()); + Init(Window::GetInstance()->GetHandle()); - target_window_ = Renderer::Instance()->GetTargetWindow(); + target_window_ = Renderer::GetInstance()->GetTargetWindow(); } void ImGuiModule::DestroyComponent() @@ -64,9 +64,9 @@ namespace kiwano io.DeltaTime = dt.Seconds(); // Read keyboard modifiers inputs - io.KeyCtrl = Input::Instance()->IsDown(KeyCode::Ctrl); - io.KeyShift = Input::Instance()->IsDown(KeyCode::Shift); - io.KeyAlt = Input::Instance()->IsDown(KeyCode::Alt); + io.KeyCtrl = Input::GetInstance()->IsDown(KeyCode::Ctrl); + io.KeyShift = Input::GetInstance()->IsDown(KeyCode::Shift); + io.KeyAlt = Input::GetInstance()->IsDown(KeyCode::Alt); io.KeySuper = false; // io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the WndProc handler below. @@ -106,7 +106,7 @@ namespace kiwano io.KeyMap[ImGuiKey_Y] = KeyCode::Y; io.KeyMap[ImGuiKey_Z] = KeyCode::Z; - ImGui_Impl_Init(Renderer::Instance()); + ImGui_Impl_Init(Renderer::GetInstance()); } void ImGuiModule::BeforeRender() @@ -213,7 +213,7 @@ namespace kiwano KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!"); // Setup display size (every frame to accommodate for window resizing) - Size display_size = Renderer::Instance()->GetOutputSize(); + Size display_size = Renderer::GetInstance()->GetOutputSize(); io.DisplaySize = ImVec2(display_size.x, display_size.y); ImGui::NewFrame(); @@ -238,7 +238,7 @@ namespace kiwano ::SetCursorPos(pos.x, pos.y); } - Point pos = Input::Instance()->GetMousePos(); + Point pos = Input::GetInstance()->GetMousePos(); io.MousePos = ImVec2(pos.x, pos.y); } @@ -260,7 +260,7 @@ namespace kiwano case ImGuiMouseCursor_Hand: cursor = MouseCursor::Hand; break; } - Window::Instance()->SetMouseCursor(cursor); + Window::GetInstance()->SetMouseCursor(cursor); } void ImGuiModule::UpdateGamepads() { diff --git a/src/kiwano-imgui/src/ImGuiModule.h b/src/kiwano-imgui/src/ImGuiModule.h index ae0b0c0b..553afc11 100644 --- a/src/kiwano-imgui/src/ImGuiModule.h +++ b/src/kiwano-imgui/src/ImGuiModule.h @@ -20,7 +20,7 @@ #pragma once #include -#include +#include namespace kiwano { diff --git a/src/kiwano-imgui/src/imgui_impl_dx10.cpp b/src/kiwano-imgui/src/imgui_impl_dx10.cpp index ed6fa680..e0d068fa 100644 --- a/src/kiwano-imgui/src/imgui_impl_dx10.cpp +++ b/src/kiwano-imgui/src/imgui_impl_dx10.cpp @@ -35,7 +35,7 @@ struct VERTEX_CONSTANT_BUFFER float mvp[4][4]; }; -// Render function +// Render Function // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop) void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) { diff --git a/src/kiwano-imgui/src/imgui_impl_dx11.cpp b/src/kiwano-imgui/src/imgui_impl_dx11.cpp index f09218da..d155a40e 100644 --- a/src/kiwano-imgui/src/imgui_impl_dx11.cpp +++ b/src/kiwano-imgui/src/imgui_impl_dx11.cpp @@ -1,6 +1,6 @@ // dear imgui: Renderer for Kiwano (DirectX11) -#include +#include #include "imgui_impl_dx11.h" // DirectX @@ -36,7 +36,7 @@ struct VERTEX_CONSTANT_BUFFER float mvp[4][4]; }; -// Render function +// Render Function // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop) void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) { diff --git a/src/kiwano-network/src/HttpClient.cpp b/src/kiwano-network/src/HttpClient.cpp index d5d01c25..e175d539 100644 --- a/src/kiwano-network/src/HttpClient.cpp +++ b/src/kiwano-network/src/HttpClient.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 "helper.h" #include "HttpRequest.hpp" @@ -105,7 +105,7 @@ namespace } } - bool Init(HttpClient* client, Array const& headers, kiwano::string const& url, kiwano::string* response_data, kiwano::string* response_header, char* error_buffer) + bool Init(HttpClient* client, Vector const& headers, kiwano::string const& url, kiwano::string* response_data, kiwano::string* response_header, char* error_buffer) { if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer)) return false; @@ -171,7 +171,7 @@ namespace public: static inline bool GetRequest( HttpClient* client, - Array const& headers, + Vector const& headers, kiwano::string const& url, long* response_code, kiwano::string* response_data, @@ -186,7 +186,7 @@ namespace static inline bool PostRequest( HttpClient* client, - Array const& headers, + Vector const& headers, kiwano::string const& url, kiwano::string const& request_data, long* response_code, @@ -204,7 +204,7 @@ namespace static inline bool PutRequest( HttpClient* client, - Array const& headers, + Vector const& headers, kiwano::string const& url, kiwano::string const& request_data, long* response_code, @@ -222,7 +222,7 @@ namespace static inline bool DeleteRequest( HttpClient* client, - Array const& headers, + Vector const& headers, kiwano::string const& url, long* response_code, kiwano::string* response_data, @@ -256,7 +256,7 @@ namespace kiwano { ::curl_global_init(CURL_GLOBAL_ALL); - std::thread thread(MakeClosure(this, &HttpClient::NetworkThread)); + std::thread thread(bind_func(this, &HttpClient::NetworkThread)); thread.detach(); } @@ -299,7 +299,7 @@ namespace kiwano response_queue_.push(response); response_mutex_.unlock(); - Application::PreformInMainThread(MakeClosure(this, &HttpClient::DispatchResponseCallback)); + Application::PreformInMainThread(bind_func(this, &HttpClient::DispatchResponseCallback)); } } @@ -314,7 +314,7 @@ namespace kiwano kiwano::string url = convert_to_utf8(request->GetUrl()); kiwano::string data = convert_to_utf8(request->GetData()); - Array headers; + Vector headers; headers.reserve(request->GetHeaders().size()); for (const auto& pair : request->GetHeaders()) { diff --git a/src/kiwano-network/src/HttpClient.h b/src/kiwano-network/src/HttpClient.h index e587d56d..a026705d 100644 --- a/src/kiwano-network/src/HttpClient.h +++ b/src/kiwano-network/src/HttpClient.h @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include #include #include #include diff --git a/src/kiwano-network/src/HttpRequest.hpp b/src/kiwano-network/src/HttpRequest.hpp index a7be4ed9..79335b4f 100644 --- a/src/kiwano-network/src/HttpRequest.hpp +++ b/src/kiwano-network/src/HttpRequest.hpp @@ -19,15 +19,15 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include #include namespace kiwano { namespace network { - typedef Closure ResponseCallback; + typedef Function ResponseCallback; class KGE_API HttpRequest : public Object diff --git a/src/kiwano-network/src/HttpResponse.hpp b/src/kiwano-network/src/HttpResponse.hpp index da51c093..094361b4 100644 --- a/src/kiwano-network/src/HttpResponse.hpp +++ b/src/kiwano-network/src/HttpResponse.hpp @@ -19,8 +19,8 @@ // THE SOFTWARE. #pragma once -#include -#include +#include +#include #include namespace kiwano diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp index 9efd36df..2db554b4 100644 --- a/src/kiwano/2d/Actor.cpp +++ b/src/kiwano/2d/Actor.cpp @@ -19,10 +19,9 @@ // THE SOFTWARE. #include "Actor.h" -#include "Action.h" #include "Stage.h" -#include "../base/logs.h" -#include "../renderer/render.h" +#include "../base/Logger.h" +#include "../renderer/Renderer.h" namespace kiwano { @@ -72,66 +71,70 @@ namespace kiwano OnUpdate(dt); } - if (!children_.IsEmpty()) + if (!children_.is_empty()) { ActorPtr next; - for (auto child = children_.First(); child; child = next) + for (auto child = children_.first_item(); child; child = next) { - next = child->NextItem(); + next = child->next_item(); child->Update(dt); } } } - void Actor::Render() + void Actor::Render(Renderer* renderer) { if (!visible_) return; UpdateTransform(); - if (children_.IsEmpty()) + if (children_.is_empty()) { - PrepareRender(); - OnRender(); + OnRender(renderer); } else { // render children those are less than 0 in Z-Order - Actor* child = children_.First().Get(); + Actor* child = children_.first_item().get(); while (child) { if (child->GetZOrder() >= 0) break; - child->Render(); - child = child->NextItem().Get(); + child->Render(renderer); + child = child->next_item().get(); } - PrepareRender(); - OnRender(); + OnRender(renderer); while (child) { - child->Render(); - child = child->NextItem().Get(); + child->Render(renderer); + child = child->next_item().get(); } } } + void Actor::PrepareRender(Renderer* renderer) + { + renderer->SetTransform(transform_matrix_); + renderer->SetOpacity(displayed_opacity_); + } + void Actor::RenderBorder() { if (show_border_) { Rect bounds = GetBounds(); - auto renderer = Renderer::Instance(); + auto renderer = Renderer::GetInstance(); renderer->SetTransform(transform_matrix_); renderer->FillRectangle(bounds, Color(Color::Red, .4f)); renderer->DrawRectangle(bounds, Color(Color::Red, .8f), 4.f); } - for (auto child = children_.First(); child; child = child->NextItem()) + for (auto child = children_.first_item(); child; child = child->next_item()) { child->RenderBorder(); } @@ -143,9 +146,9 @@ namespace kiwano return; ActorPtr prev; - for (auto child = children_.Last(); child; child = prev) + for (auto child = children_.last_item(); child; child = prev) { - prev = child->PrevItem(); + prev = child->prev_item(); child->Dispatch(evt); } @@ -198,13 +201,13 @@ namespace kiwano EventDispatcher::Dispatch(evt); } - Matrix const & Actor::GetTransformMatrix() const + Matrix3x2 const & Actor::GetTransformMatrix() const { UpdateTransform(); return transform_matrix_; } - Matrix const & Actor::GetTransformInverseMatrix() const + Matrix3x2 const & Actor::GetTransformInverseMatrix() const { UpdateTransform(); if (dirty_transform_inverse_) @@ -225,16 +228,16 @@ namespace kiwano if (is_fast_transform_) { - transform_matrix_ = Matrix::Translation(transform_.position); + transform_matrix_ = Matrix3x2::Translation(transform_.position); } else { // matrix multiplication is optimized by expression template - transform_matrix_ = Matrix::SRT(transform_.position, transform_.scale, transform_.rotation); + transform_matrix_ = Matrix3x2::SRT(transform_.position, transform_.scale, transform_.rotation); if (!transform_.skew.IsOrigin()) { - transform_matrix_ = Matrix::Skewing(transform_.skew) * transform_matrix_; + transform_matrix_ = Matrix3x2::Skewing(transform_.skew) * transform_matrix_; } } @@ -246,7 +249,7 @@ namespace kiwano } // update children's transform - for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get()) + for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) child->dirty_transform_ = true; } @@ -261,7 +264,7 @@ namespace kiwano displayed_opacity_ = opacity_; } - for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get()) + for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { child->UpdateOpacity(); } @@ -272,7 +275,7 @@ namespace kiwano if (scene && stage_ != scene) { stage_ = scene; - for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get()) + for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { child->stage_ = scene; } @@ -285,28 +288,28 @@ namespace kiwano { ActorPtr me = this; - parent_->children_.Remove(me); + parent_->children_.remove_item(me); - Actor* sibling = parent_->children_.Last().Get(); + Actor* sibling = parent_->children_.last_item().get(); if (sibling && sibling->GetZOrder() > z_order_) { - sibling = sibling->PrevItem().Get(); + sibling = sibling->prev_item().get(); while (sibling) { if (sibling->GetZOrder() <= z_order_) break; - sibling = sibling->PrevItem().Get(); + sibling = sibling->prev_item().get(); } } if (sibling) { - parent_->children_.InsertAfter(me, sibling); + parent_->children_.insert_after(me, sibling); } else { - parent_->children_.PushFront(me); + parent_->children_.push_front_item(me); } } } @@ -520,15 +523,15 @@ namespace kiwano #ifdef KGE_DEBUG if (child->parent_) - KGE_ERROR_LOG(L"The node to be added already has a parent"); + KGE_ERROR_LOG(L"The actor to be added already has a parent"); for (Actor* parent = parent_; parent; parent = parent->parent_) if (parent == child) - KGE_ERROR_LOG(L"A node cannot be its own parent"); + KGE_ERROR_LOG(L"A actor cannot be its own parent"); #endif // KGE_DEBUG - children_.PushBack(child); + children_.push_back_item(child); child->parent_ = this; child->SetStage(this->stage_); child->dirty_transform_ = true; @@ -537,11 +540,11 @@ namespace kiwano } } - void Actor::AddChildren(Array const& children) + void Actor::AddChildren(Vector const& children) { - for (const auto& node : children) + for (const auto& actor : children) { - this->AddChild(node); + this->AddChild(actor); } } @@ -555,12 +558,12 @@ namespace kiwano return GetTransformMatrix().Transform(GetBounds()); } - Array Actor::GetChildren(String const& name) const + Vector Actor::GetChildren(String const& name) const { - Array children; + Vector children; size_t hash_code = std::hash{}(name); - for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get()) + for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { if (child->hash_name_ == hash_code && child->IsName(name)) { @@ -574,7 +577,7 @@ namespace kiwano { size_t hash_code = std::hash{}(name); - for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get()) + for (Actor* child = children_.first_item().get(); child; child = child->next_item().get()) { if (child->hash_name_ == hash_code && child->IsName(name)) { @@ -599,27 +602,27 @@ namespace kiwano void Actor::RemoveChild(ActorPtr child) { - RemoveChild(child.Get()); + RemoveChild(child.get()); } void Actor::RemoveChild(Actor * child) { KGE_ASSERT(child && "Actor::RemoveChild failed, NULL pointer exception"); - if (children_.IsEmpty()) + if (children_.is_empty()) return; if (child) { child->parent_ = nullptr; if (child->stage_) child->SetStage(nullptr); - children_.Remove(ActorPtr(child)); + children_.remove_item(ActorPtr(child)); } } void Actor::RemoveChildren(String const& child_name) { - if (children_.IsEmpty()) + if (children_.is_empty()) { return; } @@ -627,9 +630,9 @@ namespace kiwano size_t hash_code = std::hash{}(child_name); Actor* next; - for (Actor* child = children_.First().Get(); child; child = next) + for (Actor* child = children_.first_item().get(); child; child = next) { - next = child->NextItem().Get(); + next = child->next_item().get(); if (child->hash_name_ == hash_code && child->IsName(child_name)) { @@ -640,7 +643,7 @@ namespace kiwano void Actor::RemoveAllChildren() { - children_.Clear(); + children_.clear_items(); } void Actor::SetResponsible(bool enable) @@ -657,12 +660,4 @@ namespace kiwano return GetBounds().ContainsPoint(local); } - - void VisualNode::PrepareRender() - { - auto renderer = Renderer::Instance(); - renderer->SetTransform(transform_matrix_); - renderer->SetOpacity(displayed_opacity_); - } - } diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h index 9f0f5427..55f8f105 100644 --- a/src/kiwano/2d/Actor.h +++ b/src/kiwano/2d/Actor.h @@ -21,13 +21,14 @@ #pragma once #include "include-forwards.h" #include "Transform.hpp" -#include "ActionManager.h" +#include "action/ActionManager.h" #include "../base/TimerManager.h" #include "../base/EventDispatcher.h" namespace kiwano { class Director; + class Renderer; // 角色 class KGE_API Actor @@ -35,14 +36,14 @@ namespace kiwano , public TimerManager , public ActionManager , public EventDispatcher - , public IntrusiveListItem + , public intrusive_list_item { friend class Director; friend class Transition; - friend class IntrusiveList; + friend class intrusive_list; - using Children = IntrusiveList; - using UpdateCallback = Closure; + using Children = intrusive_list; + using UpdateCallback = Function; public: Actor(); @@ -51,7 +52,7 @@ namespace kiwano virtual void OnUpdate(Duration dt) { KGE_UNUSED(dt); } // 渲染角色 - virtual void OnRender() {} + virtual void OnRender(Renderer* renderer) { KGE_UNUSED(renderer); } // 获取显示状态 bool IsVisible() const { return visible_; } @@ -77,7 +78,7 @@ namespace kiwano // 获取 y 坐标 float GetPositionY() const { return transform_.position.y; } - // 获取横向缩放比例 + // 获取缩放比例 Point GetScale() const { return transform_.scale; } // 获取横向缩放比例 @@ -135,16 +136,16 @@ namespace kiwano Transform GetTransform() const { return transform_; } // 获取边框 - Rect GetBounds() const; + virtual Rect GetBounds() const; // 获取外切包围盒 - Rect GetBoundingBox() const; + virtual Rect GetBoundingBox() const; // 获取二维变换矩阵 - Matrix const& GetTransformMatrix() const; + Matrix3x2 const& GetTransformMatrix() const; // 获取二维变换的逆矩阵 - Matrix const& GetTransformInverseMatrix() const; + Matrix3x2 const& GetTransformInverseMatrix() const; // 获取父角色 inline Actor* GetParent() const { return parent_; } @@ -342,11 +343,11 @@ namespace kiwano // 添加多个子角色 void AddChildren( - Array const& children + Vector const& children ); // 获取所有名称相同的子角色 - Array GetChildren( + Vector GetChildren( String const& name ) const; @@ -379,6 +380,9 @@ namespace kiwano // 从父角色移除 void RemoveFromParent(); + // 事件分发 + void Dispatch(Event& evt) override; + // 暂停角色更新 inline void PauseUpdating() { update_pausing_ = true; } @@ -403,16 +407,12 @@ namespace kiwano float anchor_y ); - public: - // 事件分发 - void Dispatch(Event& evt) override; - protected: - virtual void PrepareRender() {} - virtual void Update(Duration dt); - virtual void Render(); + virtual void Render(Renderer* renderer); + + void PrepareRender(Renderer* renderer); void RenderBorder(); @@ -447,17 +447,8 @@ namespace kiwano bool is_fast_transform_; mutable bool dirty_transform_; mutable bool dirty_transform_inverse_; - mutable Matrix transform_matrix_; - mutable Matrix transform_matrix_inverse_; - }; - - - // 可视化角色 - class KGE_API VisualNode - : public Actor - { - public: - virtual void PrepareRender() override; + mutable Matrix3x2 transform_matrix_; + mutable Matrix3x2 transform_matrix_inverse_; }; } diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp index be985f0d..c9f01d1b 100644 --- a/src/kiwano/2d/Canvas.cpp +++ b/src/kiwano/2d/Canvas.cpp @@ -19,9 +19,8 @@ // THE SOFTWARE. #include "Canvas.h" -#include "Image.h" -#include "../base/logs.h" -#include "../renderer/render.h" +#include "../base/Logger.h" +#include "../renderer/Renderer.h" namespace kiwano { @@ -29,7 +28,7 @@ namespace kiwano : cache_expired_(false) , stroke_width_(1.0f) { - auto ctx = Renderer::Instance()->GetD2DDeviceResources()->GetDeviceContext(); + auto ctx = Renderer::GetInstance()->GetD2DDeviceResources()->GetDeviceContext(); ThrowIfFailed( ctx->CreateCompatibleRenderTarget(&render_target_) @@ -52,7 +51,7 @@ namespace kiwano ThrowIfFailed( ITextRenderer::Create( &text_renderer_, - render_target_.Get() + render_target_.get() ) ); @@ -87,7 +86,7 @@ namespace kiwano cache_expired_ = true; } - void Canvas::OnRender() + void Canvas::OnRender(Renderer* renderer) { if (cache_expired_) { @@ -96,8 +95,10 @@ namespace kiwano if (bitmap_cached_) { + PrepareRender(renderer); + Rect bitmap_rect(0.f, 0.f, bitmap_cached_->GetSize().width, bitmap_cached_->GetSize().height); - Renderer::Instance()->DrawBitmap( + renderer->DrawBitmap( bitmap_cached_, bitmap_rect, bitmap_rect @@ -122,7 +123,7 @@ namespace kiwano void Canvas::SetOutlineJoinStyle(StrokeStyle outline_join) { - outline_join_style_ = Renderer::Instance()->GetD2DDeviceResources()->GetStrokeStyle(outline_join); + outline_join_style_ = Renderer::GetInstance()->GetD2DDeviceResources()->GetStrokeStyle(outline_join); } void Canvas::SetTextStyle(Font const& font, TextStyle const & text_style) @@ -136,7 +137,7 @@ namespace kiwano text_style_.outline, DX::ConvertToColorF(text_style_.outline_color), text_style_.outline_width, - Renderer::Instance()->GetD2DDeviceResources()->GetStrokeStyle(text_style_.outline_stroke) + Renderer::GetInstance()->GetD2DDeviceResources()->GetStrokeStyle(text_style_.outline_stroke) ); // clear text format @@ -160,7 +161,7 @@ namespace kiwano return stroke_width_; } - void Canvas::SetBrushTransform(Matrix const & transform) + void Canvas::SetBrushTransform(Matrix3x2 const & transform) { render_target_->SetTransform(DX::ConvertToMatrix3x2F(transform)); } @@ -170,9 +171,9 @@ namespace kiwano render_target_->DrawLine( D2D1::Point2F(begin.x, begin.y), D2D1::Point2F(end.x, end.y), - stroke_brush_.Get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -188,9 +189,9 @@ namespace kiwano radius, radius ), - stroke_brush_.Get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -206,9 +207,9 @@ namespace kiwano radius_x, radius_y ), - stroke_brush_.Get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -222,9 +223,9 @@ namespace kiwano rect.origin.x + rect.size.x, rect.origin.y + rect.size.y ), - stroke_brush_.Get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -242,9 +243,9 @@ namespace kiwano radius_x, radius_y ), - stroke_brush_.Get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -254,11 +255,11 @@ namespace kiwano if (image && image->GetBitmap()) { render_target_->DrawBitmap( - image->GetBitmap().Get(), + image->GetBitmap().get(), D2D1::RectF(0, 0, image->GetWidth(), image->GetHeight()), opacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, - DX::ConvertToRectF(image->GetCropRect()) + D2D1::RectF(0, 0, image->GetWidth(), image->GetHeight()) ); cache_expired_ = true; } @@ -272,7 +273,7 @@ namespace kiwano if (!text_format_) { ThrowIfFailed( - Renderer::Instance()->GetD2DDeviceResources()->CreateTextFormat( + Renderer::GetInstance()->GetD2DDeviceResources()->CreateTextFormat( text_format_, text_font_, text_style_ @@ -283,7 +284,7 @@ namespace kiwano ComPtr text_layout; Size layout_size; ThrowIfFailed( - Renderer::Instance()->GetD2DDeviceResources()->CreateTextLayout( + Renderer::GetInstance()->GetD2DDeviceResources()->CreateTextLayout( text_layout, layout_size, text, @@ -293,7 +294,7 @@ namespace kiwano ); ThrowIfFailed( - text_layout->Draw(nullptr, text_renderer_.Get(), point.x, point.y) + text_layout->Draw(nullptr, text_renderer_.get(), point.x, point.y) ); } @@ -308,7 +309,7 @@ namespace kiwano radius, radius ), - fill_brush_.Get() + fill_brush_.get() ); cache_expired_ = true; } @@ -324,7 +325,7 @@ namespace kiwano radius_x, radius_y ), - fill_brush_.Get() + fill_brush_.get() ); cache_expired_ = true; } @@ -338,7 +339,7 @@ namespace kiwano rect.origin.x + rect.size.x, rect.origin.y + rect.size.y ), - fill_brush_.Get() + fill_brush_.get() ); cache_expired_ = true; } @@ -356,7 +357,7 @@ namespace kiwano radius_x, radius_y ), - fill_brush_.Get() + fill_brush_.get() ); cache_expired_ = true; } @@ -366,7 +367,7 @@ namespace kiwano current_geometry_ = nullptr; ThrowIfFailed( - Renderer::Instance()->GetD2DDeviceResources()->GetFactory()->CreatePathGeometry(¤t_geometry_) + Renderer::GetInstance()->GetD2DDeviceResources()->GetFactory()->CreatePathGeometry(¤t_geometry_) ); ThrowIfFailed( @@ -394,7 +395,7 @@ namespace kiwano current_sink_->AddLine(DX::ConvertToPoint2F(point)); } - void Canvas::AddLines(Array const& points) + void Canvas::AddLines(Vector const& points) { if (current_sink_ && !points.empty()) { @@ -438,10 +439,10 @@ namespace kiwano void Canvas::StrokePath() { render_target_->DrawGeometry( - current_geometry_.Get(), - stroke_brush_.Get(), + current_geometry_.get(), + stroke_brush_.get(), stroke_width_, - outline_join_style_.Get() + outline_join_style_.get() ); cache_expired_ = true; } @@ -449,8 +450,8 @@ namespace kiwano void Canvas::FillPath() { render_target_->FillGeometry( - current_geometry_.Get(), - fill_brush_.Get() + current_geometry_.get(), + fill_brush_.get() ); cache_expired_ = true; } @@ -463,8 +464,7 @@ namespace kiwano ImagePtr Canvas::ExportToImage() const { - auto image = new Image(GetBitmap()); - image->Crop(Rect(Point{}, this->GetSize())); + ImagePtr image = new Image(GetBitmap()); return image; } diff --git a/src/kiwano/2d/Canvas.h b/src/kiwano/2d/Canvas.h index 3af235d2..add2a2c1 100644 --- a/src/kiwano/2d/Canvas.h +++ b/src/kiwano/2d/Canvas.h @@ -22,15 +22,18 @@ #include "Actor.h" #include "Font.hpp" #include "TextStyle.hpp" +#include "../renderer/Image.h" #include "../renderer/TextRenderer.h" -#undef DrawText +#ifdef DrawText +# undef DrawText +#endif namespace kiwano { // 画布 class KGE_API Canvas - : public VisualNode + : public Actor { public: Canvas(); @@ -137,7 +140,7 @@ namespace kiwano // 添加多条线段 void AddLines( - Array const& points + Vector const& points ); // 添加一条三次方贝塞尔曲线 @@ -202,13 +205,13 @@ namespace kiwano // 变换画笔 void SetBrushTransform( - Matrix const& transform + Matrix3x2 const& transform ); // 导出为图片 ImagePtr ExportToImage() const; - void OnRender() override; + void OnRender(Renderer* renderer) override; protected: ComPtr const& GetBitmap() const; diff --git a/src/kiwano/2d/DebugNode.cpp b/src/kiwano/2d/DebugActor.cpp similarity index 85% rename from src/kiwano/2d/DebugNode.cpp rename to src/kiwano/2d/DebugActor.cpp index e0a9e5a4..e7429567 100644 --- a/src/kiwano/2d/DebugNode.cpp +++ b/src/kiwano/2d/DebugActor.cpp @@ -18,9 +18,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -#include "DebugNode.h" +#include "DebugActor.h" #include "Text.h" -#include "../renderer/render.h" +#include "../renderer/Renderer.h" #include #include @@ -28,10 +28,10 @@ namespace kiwano { - DebugNode::DebugNode() + DebugActor::DebugActor() : background_color_(0.0f, 0.0f, 0.0f, 0.7f) { - SetName(L"kiwano-debug-node"); + SetName(L"kiwano-debug-actor"); SetPosition(10, 10); SetResponsible(true); SetCascadeOpacityEnabled(true); @@ -54,13 +54,13 @@ namespace kiwano AddListener(Event::MouseOut, [=](const Event&) { SetOpacity(1.f); }); } - DebugNode::~DebugNode() + DebugActor::~DebugActor() { } - void DebugNode::OnRender() + void DebugActor::OnRender(Renderer* renderer) { - auto renderer = Renderer::Instance(); + PrepareRender(renderer); renderer->GetSolidColorBrush()->SetColor(DX::ConvertToColorF(background_color_)); renderer->GetD2DDeviceResources()->GetDeviceContext()->FillRoundedRectangle( @@ -69,7 +69,7 @@ namespace kiwano ); } - void DebugNode::OnUpdate(Duration dt) + void DebugActor::OnUpdate(Duration dt) { KGE_UNUSED(dt); @@ -89,9 +89,9 @@ namespace kiwano } #endif - ss << "Render: " << Renderer::Instance()->GetStatus().duration.Milliseconds() << "ms" << std::endl; + ss << "Render: " << Renderer::GetInstance()->GetStatus().duration.Milliseconds() << "ms" << std::endl; - ss << "Primitives / sec: " << Renderer::Instance()->GetStatus().primitives * frame_time_.size() << std::endl; + ss << "Primitives / sec: " << Renderer::GetInstance()->GetStatus().primitives * frame_time_.size() << std::endl; PROCESS_MEMORY_COUNTERS_EX pmc; GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); diff --git a/src/kiwano/2d/DebugNode.h b/src/kiwano/2d/DebugActor.h similarity index 89% rename from src/kiwano/2d/DebugNode.h rename to src/kiwano/2d/DebugActor.h index 32988ef7..771758d2 100644 --- a/src/kiwano/2d/DebugNode.h +++ b/src/kiwano/2d/DebugActor.h @@ -23,21 +23,21 @@ namespace kiwano { - class KGE_API DebugNode - : public VisualNode + class KGE_API DebugActor + : public Actor { public: - DebugNode(); + DebugActor(); - virtual ~DebugNode(); + virtual ~DebugActor(); - void OnRender() override; + void OnRender(Renderer* renderer) override; void OnUpdate(Duration dt) override; protected: Color background_color_; TextPtr debug_text_; - Array