refactor core module

This commit is contained in:
Nomango 2019-08-13 21:16:38 +08:00
parent 222b09f166
commit ed034750fe
100 changed files with 6150 additions and 6089 deletions

View File

@ -9,8 +9,18 @@
<ClInclude Include="..\src\kiwano\2d\action\Animation.h" /> <ClInclude Include="..\src\kiwano\2d\action\Animation.h" />
<ClInclude Include="..\src\kiwano\2d\Frame.h" /> <ClInclude Include="..\src\kiwano\2d\Frame.h" />
<ClInclude Include="..\src\kiwano\2d\GifSprite.h" /> <ClInclude Include="..\src\kiwano\2d\GifSprite.h" />
<ClInclude Include="..\src\kiwano\base\ComPtr.hpp" />
<ClInclude Include="..\src\kiwano\base\Director.h" /> <ClInclude Include="..\src\kiwano\base\Director.h" />
<ClInclude Include="..\src\kiwano\base\types.h" /> <ClInclude Include="..\src\kiwano\base\types.h" />
<ClInclude Include="..\src\kiwano\core\basic_json.hpp" />
<ClInclude Include="..\src\kiwano\core\function.hpp" />
<ClInclude Include="..\src\kiwano\core\core.h" />
<ClInclude Include="..\src\kiwano\core\intrusive_list.hpp" />
<ClInclude Include="..\src\kiwano\core\intrusive_ptr.hpp" />
<ClInclude Include="..\src\kiwano\core\noncopyable.hpp" />
<ClInclude Include="..\src\kiwano\core\singleton.hpp" />
<ClInclude Include="..\src\kiwano\core\string.hpp" />
<ClInclude Include="..\src\kiwano\core\vector.hpp" />
<ClInclude Include="..\src\kiwano\kiwano.h" /> <ClInclude Include="..\src\kiwano\kiwano.h" />
<ClInclude Include="..\src\kiwano\config.h" /> <ClInclude Include="..\src\kiwano\config.h" />
<ClInclude Include="..\src\kiwano\macros.h" /> <ClInclude Include="..\src\kiwano\macros.h" />
@ -45,16 +55,6 @@
<ClInclude Include="..\src\kiwano\base\TimerManager.h" /> <ClInclude Include="..\src\kiwano\base\TimerManager.h" />
<ClInclude Include="..\src\kiwano\base\time.h" /> <ClInclude Include="..\src\kiwano\base\time.h" />
<ClInclude Include="..\src\kiwano\base\window.h" /> <ClInclude Include="..\src\kiwano\base\window.h" />
<ClInclude Include="..\src\kiwano\common\Array.hpp" />
<ClInclude Include="..\src\kiwano\common\Closure.hpp" />
<ClInclude Include="..\src\kiwano\common\ComPtr.hpp" />
<ClInclude Include="..\src\kiwano\common\helper.h" />
<ClInclude Include="..\src\kiwano\common\IntrusiveList.hpp" />
<ClInclude Include="..\src\kiwano\common\IntrusivePtr.hpp" />
<ClInclude Include="..\src\kiwano\common\Json.hpp" />
<ClInclude Include="..\src\kiwano\common\Noncopyable.hpp" />
<ClInclude Include="..\src\kiwano\common\Singleton.hpp" />
<ClInclude Include="..\src\kiwano\common\String.hpp" />
<ClInclude Include="..\src\kiwano\math\constants.hpp" /> <ClInclude Include="..\src\kiwano\math\constants.hpp" />
<ClInclude Include="..\src\kiwano\math\ease.hpp" /> <ClInclude Include="..\src\kiwano\math\ease.hpp" />
<ClInclude Include="..\src\kiwano\math\helper.h" /> <ClInclude Include="..\src\kiwano\math\helper.h" />

View File

@ -10,9 +10,6 @@
<Filter Include="ui"> <Filter Include="ui">
<UniqueIdentifier>{07b6d541-4a1b-472a-aae0-daf9d082fe84}</UniqueIdentifier> <UniqueIdentifier>{07b6d541-4a1b-472a-aae0-daf9d082fe84}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="common">
<UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier>
</Filter>
<Filter Include="platform"> <Filter Include="platform">
<UniqueIdentifier>{c2654ccc-59f6-4c17-bb6b-99b07fc78702}</UniqueIdentifier> <UniqueIdentifier>{c2654ccc-59f6-4c17-bb6b-99b07fc78702}</UniqueIdentifier>
</Filter> </Filter>
@ -37,6 +34,9 @@
<Filter Include="2d\action"> <Filter Include="2d\action">
<UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier> <UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="core">
<UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\src\kiwano\ui\Button.h"> <ClInclude Include="..\src\kiwano\ui\Button.h">
@ -78,21 +78,6 @@
<ClInclude Include="..\src\kiwano\2d\Transition.h"> <ClInclude Include="..\src\kiwano\2d\Transition.h">
<Filter>2d</Filter> <Filter>2d</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\kiwano\common\ComPtr.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\helper.h">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\IntrusiveList.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\IntrusivePtr.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\Singleton.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\base\Component.h"> <ClInclude Include="..\src\kiwano\base\Component.h">
<Filter>base</Filter> <Filter>base</Filter>
</ClInclude> </ClInclude>
@ -213,21 +198,6 @@
<ClInclude Include="..\src\kiwano\2d\GifSprite.h"> <ClInclude Include="..\src\kiwano\2d\GifSprite.h">
<Filter>2d</Filter> <Filter>2d</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\kiwano\common\Closure.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\Noncopyable.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\String.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\Json.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\common\Array.hpp">
<Filter>common</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\third-party\tinyxml2\tinyxml2.h"> <ClInclude Include="..\src\kiwano\third-party\tinyxml2\tinyxml2.h">
<Filter>third-party\tinyxml2</Filter> <Filter>third-party\tinyxml2</Filter>
</ClInclude> </ClInclude>
@ -279,6 +249,36 @@
<ClInclude Include="..\src\kiwano\2d\FrameSequence.h"> <ClInclude Include="..\src\kiwano\2d\FrameSequence.h">
<Filter>2d</Filter> <Filter>2d</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\kiwano\core\basic_json.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\function.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\intrusive_list.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\intrusive_ptr.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\noncopyable.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\singleton.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\string.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\vector.hpp">
<Filter>core</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\base\ComPtr.hpp">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\core\core.h">
<Filter>core</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\kiwano\ui\Button.cpp"> <ClCompile Include="..\src\kiwano\ui\Button.cpp">

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/IntrusivePtr.hpp> #include <kiwano/core/intrusive_ptr.hpp>
#include <kiwano/base/Object.h> #include <kiwano/base/Object.h>
#include "Sound.h" #include "Sound.h"

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/IntrusivePtr.hpp> #include <kiwano/core/intrusive_ptr.hpp>
#include <kiwano/base/Object.h> #include <kiwano/base/Object.h>
#include <kiwano/base/Resource.h> #include <kiwano/base/Resource.h>
#include <xaudio2.h> #include <xaudio2.h>

View File

@ -23,8 +23,8 @@
#endif #endif
#include <kiwano/macros.h> #include <kiwano/macros.h>
#include <kiwano/common/ComPtr.hpp> #include <kiwano/core/string.hpp>
#include <kiwano/common/String.hpp> #include <kiwano/base/ComPtr.hpp>
#include <kiwano/base/Resource.h> #include <kiwano/base/Resource.h>
#include <kiwano/base/logs.h> #include <kiwano/base/logs.h>
#include <kiwano/platform/modules.h> #include <kiwano/platform/modules.h>
@ -69,7 +69,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ReadSource(reader.Get(), wave_data, wave_data_size); hr = ReadSource(reader.get(), wave_data, wave_data_size);
} }
return hr; return hr;
@ -100,13 +100,13 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream); hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.get(), &byte_stream);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream( hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream(
byte_stream.Get(), byte_stream.get(),
nullptr, nullptr,
&reader &reader
); );
@ -114,7 +114,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ReadSource(reader.Get(), wave_data, wave_data_size); hr = ReadSource(reader.get(), wave_data, wave_data_size);
} }
return hr; return hr;
@ -146,7 +146,7 @@ namespace kiwano
hr = reader->SetCurrentMediaType( hr = reader->SetCurrentMediaType(
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, (DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
0, 0,
partial_type.Get() partial_type.get()
); );
} }
@ -173,7 +173,7 @@ namespace kiwano
{ {
UINT32 size = 0; UINT32 size = 0;
hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType( hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType(
uncompressed_type.Get(), uncompressed_type.get(),
&wave_format_, &wave_format_,
&size, &size,
(DWORD)MFWaveFormatExConvertFlag_Normal (DWORD)MFWaveFormatExConvertFlag_Normal

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/Singleton.hpp> #include <kiwano/core/singleton.hpp>
#include <kiwano/base/Component.h> #include <kiwano/base/Component.h>
namespace kiwano namespace kiwano

View File

@ -27,7 +27,7 @@ namespace kiwano
{ {
KGE_DECLARE_SMART_PTR(ImGuiLayer); KGE_DECLARE_SMART_PTR(ImGuiLayer);
using ImGuiPipeline = Closure<void()>; using ImGuiPipeline = Function<void()>;
class ImGuiLayer class ImGuiLayer
: public Layer : public Layer

View File

@ -1,8 +1,8 @@
// Copyright (C) 2019 Nomango // Copyright (C) 2019 Nomango
#include <kiwano/common/helper.h> #include <kiwano/core/core.h>
#include <kiwano/common/Closure.hpp> #include <kiwano/core/Function.hpp>
#include <kiwano/common/IntrusivePtr.hpp> #include <kiwano/core/intrusive_ptr.hpp>
#include <kiwano/base/Window.h> #include <kiwano/base/Window.h>
#include <kiwano/base/Input.h> #include <kiwano/base/Input.h>
#include <kiwano/renderer/render.h> #include <kiwano/renderer/render.h>

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include <kiwano/base/Component.h> #include <kiwano/base/Component.h>
#include <kiwano/common/Singleton.hpp> #include <kiwano/core/singleton.hpp>
namespace kiwano namespace kiwano
{ {

View File

@ -35,7 +35,7 @@ struct VERTEX_CONSTANT_BUFFER
float mvp[4][4]; 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) // (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) void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
{ {

View File

@ -36,7 +36,7 @@ struct VERTEX_CONSTANT_BUFFER
float mvp[4][4]; 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) // (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) void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
{ {

View File

@ -105,7 +105,7 @@ namespace
} }
} }
bool Init(HttpClient* client, Array<kiwano::string> const& headers, kiwano::string const& url, kiwano::string* response_data, kiwano::string* response_header, char* error_buffer) bool Init(HttpClient* client, Vector<kiwano::string> const& headers, kiwano::string const& url, kiwano::string* response_data, kiwano::string* response_header, char* error_buffer)
{ {
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer)) if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
return false; return false;
@ -171,7 +171,7 @@ namespace
public: public:
static inline bool GetRequest( static inline bool GetRequest(
HttpClient* client, HttpClient* client,
Array<kiwano::string> const& headers, Vector<kiwano::string> const& headers,
kiwano::string const& url, kiwano::string const& url,
long* response_code, long* response_code,
kiwano::string* response_data, kiwano::string* response_data,
@ -186,7 +186,7 @@ namespace
static inline bool PostRequest( static inline bool PostRequest(
HttpClient* client, HttpClient* client,
Array<kiwano::string> const& headers, Vector<kiwano::string> const& headers,
kiwano::string const& url, kiwano::string const& url,
kiwano::string const& request_data, kiwano::string const& request_data,
long* response_code, long* response_code,
@ -204,7 +204,7 @@ namespace
static inline bool PutRequest( static inline bool PutRequest(
HttpClient* client, HttpClient* client,
Array<kiwano::string> const& headers, Vector<kiwano::string> const& headers,
kiwano::string const& url, kiwano::string const& url,
kiwano::string const& request_data, kiwano::string const& request_data,
long* response_code, long* response_code,
@ -222,7 +222,7 @@ namespace
static inline bool DeleteRequest( static inline bool DeleteRequest(
HttpClient* client, HttpClient* client,
Array<kiwano::string> const& headers, Vector<kiwano::string> const& headers,
kiwano::string const& url, kiwano::string const& url,
long* response_code, long* response_code,
kiwano::string* response_data, kiwano::string* response_data,
@ -256,7 +256,7 @@ namespace kiwano
{ {
::curl_global_init(CURL_GLOBAL_ALL); ::curl_global_init(CURL_GLOBAL_ALL);
std::thread thread(MakeClosure(this, &HttpClient::NetworkThread)); std::thread thread(bind_func(this, &HttpClient::NetworkThread));
thread.detach(); thread.detach();
} }
@ -299,7 +299,7 @@ namespace kiwano
response_queue_.push(response); response_queue_.push(response);
response_mutex_.unlock(); 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 url = convert_to_utf8(request->GetUrl());
kiwano::string data = convert_to_utf8(request->GetData()); kiwano::string data = convert_to_utf8(request->GetData());
Array<kiwano::string> headers; Vector<kiwano::string> headers;
headers.reserve(request->GetHeaders().size()); headers.reserve(request->GetHeaders().size());
for (const auto& pair : request->GetHeaders()) for (const auto& pair : request->GetHeaders())
{ {

View File

@ -19,8 +19,8 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/helper.h> #include <kiwano/core/core.h>
#include <kiwano/common/Singleton.hpp> #include <kiwano/core/singleton.hpp>
#include <kiwano/base/Component.h> #include <kiwano/base/Component.h>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>

View File

@ -19,15 +19,15 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/Closure.hpp> #include <kiwano/core/Function.hpp>
#include <kiwano/common/Json.hpp> #include <kiwano/core/basic_json.hpp>
#include <kiwano/base/Object.h> #include <kiwano/base/Object.h>
namespace kiwano namespace kiwano
{ {
namespace network namespace network
{ {
typedef Closure<void(HttpRequestPtr, HttpResponsePtr)> ResponseCallback; typedef Function<void(HttpRequestPtr, HttpResponsePtr)> ResponseCallback;
class KGE_API HttpRequest class KGE_API HttpRequest
: public Object : public Object

View File

@ -19,8 +19,8 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include <kiwano/common/Closure.hpp> #include <kiwano/core/Function.hpp>
#include <kiwano/common/Json.hpp> #include <kiwano/core/basic_json.hpp>
#include <kiwano/base/Object.h> #include <kiwano/base/Object.h>
namespace kiwano namespace kiwano

View File

@ -71,12 +71,12 @@ namespace kiwano
OnUpdate(dt); OnUpdate(dt);
} }
if (!children_.IsEmpty()) if (!children_.is_empty())
{ {
ActorPtr next; 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); child->Update(dt);
} }
} }
@ -89,7 +89,7 @@ namespace kiwano
UpdateTransform(); UpdateTransform();
if (children_.IsEmpty()) if (children_.is_empty())
{ {
PrepareRender(); PrepareRender();
OnRender(); OnRender();
@ -97,14 +97,14 @@ namespace kiwano
else else
{ {
// render children those are less than 0 in Z-Order // render children those are less than 0 in Z-Order
Actor* child = children_.First().Get(); Actor* child = children_.first_item().get();
while (child) while (child)
{ {
if (child->GetZOrder() >= 0) if (child->GetZOrder() >= 0)
break; break;
child->Render(); child->Render();
child = child->NextItem().Get(); child = child->next_item().get();
} }
PrepareRender(); PrepareRender();
@ -113,7 +113,7 @@ namespace kiwano
while (child) while (child)
{ {
child->Render(); child->Render();
child = child->NextItem().Get(); child = child->next_item().get();
} }
} }
} }
@ -130,7 +130,7 @@ namespace kiwano
renderer->DrawRectangle(bounds, Color(Color::Red, .8f), 4.f); 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(); child->RenderBorder();
} }
@ -142,9 +142,9 @@ namespace kiwano
return; return;
ActorPtr prev; 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); child->Dispatch(evt);
} }
@ -245,7 +245,7 @@ namespace kiwano
} }
// update children's transform // 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; child->dirty_transform_ = true;
} }
@ -260,7 +260,7 @@ namespace kiwano
displayed_opacity_ = opacity_; 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(); child->UpdateOpacity();
} }
@ -271,7 +271,7 @@ namespace kiwano
if (scene && stage_ != scene) if (scene && stage_ != 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; child->stage_ = scene;
} }
@ -284,28 +284,28 @@ namespace kiwano
{ {
ActorPtr me = this; 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_) if (sibling && sibling->GetZOrder() > z_order_)
{ {
sibling = sibling->PrevItem().Get(); sibling = sibling->prev_item().get();
while (sibling) while (sibling)
{ {
if (sibling->GetZOrder() <= z_order_) if (sibling->GetZOrder() <= z_order_)
break; break;
sibling = sibling->PrevItem().Get(); sibling = sibling->prev_item().get();
} }
} }
if (sibling) if (sibling)
{ {
parent_->children_.InsertAfter(me, sibling); parent_->children_.insert_after(me, sibling);
} }
else else
{ {
parent_->children_.PushFront(me); parent_->children_.push_front_item(me);
} }
} }
} }
@ -519,15 +519,15 @@ namespace kiwano
#ifdef KGE_DEBUG #ifdef KGE_DEBUG
if (child->parent_) 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_) for (Actor* parent = parent_; parent; parent = parent->parent_)
if (parent == child) 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 #endif // KGE_DEBUG
children_.PushBack(child); children_.push_back_item(child);
child->parent_ = this; child->parent_ = this;
child->SetStage(this->stage_); child->SetStage(this->stage_);
child->dirty_transform_ = true; child->dirty_transform_ = true;
@ -536,11 +536,11 @@ namespace kiwano
} }
} }
void Actor::AddChildren(Array<ActorPtr> const& children) void Actor::AddChildren(Vector<ActorPtr> const& children)
{ {
for (const auto& node : children) for (const auto& actor : children)
{ {
this->AddChild(node); this->AddChild(actor);
} }
} }
@ -554,12 +554,12 @@ namespace kiwano
return GetTransformMatrix().Transform(GetBounds()); return GetTransformMatrix().Transform(GetBounds());
} }
Array<ActorPtr> Actor::GetChildren(String const& name) const Vector<ActorPtr> Actor::GetChildren(String const& name) const
{ {
Array<ActorPtr> children; Vector<ActorPtr> children;
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<String>{}(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)) if (child->hash_name_ == hash_code && child->IsName(name))
{ {
@ -573,7 +573,7 @@ namespace kiwano
{ {
size_t hash_code = std::hash<String>{}(name); size_t hash_code = std::hash<String>{}(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)) if (child->hash_name_ == hash_code && child->IsName(name))
{ {
@ -598,27 +598,27 @@ namespace kiwano
void Actor::RemoveChild(ActorPtr child) void Actor::RemoveChild(ActorPtr child)
{ {
RemoveChild(child.Get()); RemoveChild(child.get());
} }
void Actor::RemoveChild(Actor * child) void Actor::RemoveChild(Actor * child)
{ {
KGE_ASSERT(child && "Actor::RemoveChild failed, NULL pointer exception"); KGE_ASSERT(child && "Actor::RemoveChild failed, NULL pointer exception");
if (children_.IsEmpty()) if (children_.is_empty())
return; return;
if (child) if (child)
{ {
child->parent_ = nullptr; child->parent_ = nullptr;
if (child->stage_) child->SetStage(nullptr); if (child->stage_) child->SetStage(nullptr);
children_.Remove(ActorPtr(child)); children_.remove_item(ActorPtr(child));
} }
} }
void Actor::RemoveChildren(String const& child_name) void Actor::RemoveChildren(String const& child_name)
{ {
if (children_.IsEmpty()) if (children_.is_empty())
{ {
return; return;
} }
@ -626,9 +626,9 @@ namespace kiwano
size_t hash_code = std::hash<String>{}(child_name); size_t hash_code = std::hash<String>{}(child_name);
Actor* next; 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)) if (child->hash_name_ == hash_code && child->IsName(child_name))
{ {
@ -639,7 +639,7 @@ namespace kiwano
void Actor::RemoveAllChildren() void Actor::RemoveAllChildren()
{ {
children_.Clear(); children_.clear_items();
} }
void Actor::SetResponsible(bool enable) void Actor::SetResponsible(bool enable)

View File

@ -35,14 +35,14 @@ namespace kiwano
, public TimerManager , public TimerManager
, public ActionManager , public ActionManager
, public EventDispatcher , public EventDispatcher
, public IntrusiveListItem<ActorPtr> , public intrusive_list_item<ActorPtr>
{ {
friend class Director; friend class Director;
friend class Transition; friend class Transition;
friend class IntrusiveList<ActorPtr>; friend class intrusive_list<ActorPtr>;
using Children = IntrusiveList<ActorPtr>; using Children = intrusive_list<ActorPtr>;
using UpdateCallback = Closure<void(Duration)>; using UpdateCallback = Function<void(Duration)>;
public: public:
Actor(); Actor();
@ -342,11 +342,11 @@ namespace kiwano
// 添加多个子角色 // 添加多个子角色
void AddChildren( void AddChildren(
Array<ActorPtr> const& children Vector<ActorPtr> const& children
); );
// 获取所有名称相同的子角色 // 获取所有名称相同的子角色
Array<ActorPtr> GetChildren( Vector<ActorPtr> GetChildren(
String const& name String const& name
) const; ) const;

View File

@ -51,7 +51,7 @@ namespace kiwano
ThrowIfFailed( ThrowIfFailed(
ITextRenderer::Create( ITextRenderer::Create(
&text_renderer_, &text_renderer_,
render_target_.Get() render_target_.get()
) )
); );
@ -169,9 +169,9 @@ namespace kiwano
render_target_->DrawLine( render_target_->DrawLine(
D2D1::Point2F(begin.x, begin.y), D2D1::Point2F(begin.x, begin.y),
D2D1::Point2F(end.x, end.y), D2D1::Point2F(end.x, end.y),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -187,9 +187,9 @@ namespace kiwano
radius, radius,
radius radius
), ),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -205,9 +205,9 @@ namespace kiwano
radius_x, radius_x,
radius_y radius_y
), ),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -221,9 +221,9 @@ namespace kiwano
rect.origin.x + rect.size.x, rect.origin.x + rect.size.x,
rect.origin.y + rect.size.y rect.origin.y + rect.size.y
), ),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -241,9 +241,9 @@ namespace kiwano
radius_x, radius_x,
radius_y radius_y
), ),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -253,7 +253,7 @@ namespace kiwano
if (image && image->GetBitmap()) if (image && image->GetBitmap())
{ {
render_target_->DrawBitmap( render_target_->DrawBitmap(
image->GetBitmap().Get(), image->GetBitmap().get(),
D2D1::RectF(0, 0, image->GetWidth(), image->GetHeight()), D2D1::RectF(0, 0, image->GetWidth(), image->GetHeight()),
opacity, opacity,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
@ -292,7 +292,7 @@ namespace kiwano
); );
ThrowIfFailed( ThrowIfFailed(
text_layout->Draw(nullptr, text_renderer_.Get(), point.x, point.y) text_layout->Draw(nullptr, text_renderer_.get(), point.x, point.y)
); );
} }
@ -307,7 +307,7 @@ namespace kiwano
radius, radius,
radius radius
), ),
fill_brush_.Get() fill_brush_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -323,7 +323,7 @@ namespace kiwano
radius_x, radius_x,
radius_y radius_y
), ),
fill_brush_.Get() fill_brush_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -337,7 +337,7 @@ namespace kiwano
rect.origin.x + rect.size.x, rect.origin.x + rect.size.x,
rect.origin.y + rect.size.y rect.origin.y + rect.size.y
), ),
fill_brush_.Get() fill_brush_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -355,7 +355,7 @@ namespace kiwano
radius_x, radius_x,
radius_y radius_y
), ),
fill_brush_.Get() fill_brush_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -393,7 +393,7 @@ namespace kiwano
current_sink_->AddLine(DX::ConvertToPoint2F(point)); current_sink_->AddLine(DX::ConvertToPoint2F(point));
} }
void Canvas::AddLines(Array<Point> const& points) void Canvas::AddLines(Vector<Point> const& points)
{ {
if (current_sink_ && !points.empty()) if (current_sink_ && !points.empty())
{ {
@ -437,10 +437,10 @@ namespace kiwano
void Canvas::StrokePath() void Canvas::StrokePath()
{ {
render_target_->DrawGeometry( render_target_->DrawGeometry(
current_geometry_.Get(), current_geometry_.get(),
stroke_brush_.Get(), stroke_brush_.get(),
stroke_width_, stroke_width_,
outline_join_style_.Get() outline_join_style_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }
@ -448,8 +448,8 @@ namespace kiwano
void Canvas::FillPath() void Canvas::FillPath()
{ {
render_target_->FillGeometry( render_target_->FillGeometry(
current_geometry_.Get(), current_geometry_.get(),
fill_brush_.Get() fill_brush_.get()
); );
cache_expired_ = true; cache_expired_ = true;
} }

View File

@ -140,7 +140,7 @@ namespace kiwano
// 添加多条线段 // 添加多条线段
void AddLines( void AddLines(
Array<Point> const& points Vector<Point> const& points
); );
// 添加一条三次方贝塞尔曲线 // 添加一条三次方贝塞尔曲线

View File

@ -31,7 +31,7 @@ namespace kiwano
DebugNode::DebugNode() DebugNode::DebugNode()
: background_color_(0.0f, 0.0f, 0.0f, 0.7f) : background_color_(0.0f, 0.0f, 0.0f, 0.7f)
{ {
SetName(L"kiwano-debug-node"); SetName(L"kiwano-debug-actor");
SetPosition(10, 10); SetPosition(10, 10);
SetResponsible(true); SetResponsible(true);
SetCascadeOpacityEnabled(true); SetCascadeOpacityEnabled(true);

View File

@ -38,6 +38,6 @@ namespace kiwano
protected: protected:
Color background_color_; Color background_color_;
TextPtr debug_text_; TextPtr debug_text_;
Array<Time> frame_time_; Vector<Time> frame_time_;
}; };
} }

View File

@ -28,7 +28,7 @@ namespace kiwano
{ {
} }
FrameSequence::FrameSequence(Array<FramePtr> const& frames) FrameSequence::FrameSequence(Vector<FramePtr> const& frames)
{ {
this->AddFrames(frames); this->AddFrames(frames);
} }
@ -47,7 +47,7 @@ namespace kiwano
} }
} }
void FrameSequence::AddFrames(Array<FramePtr> const& frames) void FrameSequence::AddFrames(Vector<FramePtr> const& frames)
{ {
if (frames_.empty()) if (frames_.empty())
frames_ = frames; frames_ = frames;
@ -65,7 +65,7 @@ namespace kiwano
return frames_[index]; return frames_[index];
} }
Array<FramePtr> const& FrameSequence::GetFrames() const Vector<FramePtr> const& FrameSequence::GetFrames() const
{ {
return frames_; return frames_;
} }

View File

@ -31,7 +31,7 @@ namespace kiwano
FrameSequence(); FrameSequence();
explicit FrameSequence( explicit FrameSequence(
Array<FramePtr> const& frames /* Ö¡ÐòÁÐ */ Vector<FramePtr> const& frames /* Ö¡ÐòÁÐ */
); );
virtual ~FrameSequence(); virtual ~FrameSequence();
@ -43,14 +43,14 @@ namespace kiwano
// 添加多个关键帧 // 添加多个关键帧
void AddFrames( void AddFrames(
Array<FramePtr> const& frames Vector<FramePtr> const& frames
); );
// 获取关键帧 // 获取关键帧
FramePtr GetFrame(size_t index) const; FramePtr GetFrame(size_t index) const;
// 获取关键帧 // 获取关键帧
Array<FramePtr> const& GetFrames() const; Vector<FramePtr> const& GetFrames() const;
// 获取帧动画的拷贝对象 // 获取帧动画的拷贝对象
FrameSequencePtr Clone() const; FrameSequencePtr Clone() const;
@ -59,6 +59,6 @@ namespace kiwano
FrameSequencePtr Reverse() const; FrameSequencePtr Reverse() const;
protected: protected:
Array<FramePtr> frames_; Vector<FramePtr> frames_;
}; };
} }

View File

@ -163,7 +163,7 @@ namespace kiwano
loop_count_++; loop_count_++;
} }
frame_rt_->DrawBitmap(image_->GetRawFrame().Get(), image_->GetFramePosition()); frame_rt_->DrawBitmap(image_->GetRawFrame().get(), image_->GetFramePosition());
hr = frame_rt_->EndDraw(); hr = frame_rt_->EndDraw();
} }

View File

@ -30,8 +30,8 @@ namespace kiwano
: public VisualActor : public VisualActor
{ {
public: public:
using LoopDoneCallback = Closure<void(int)>; using LoopDoneCallback = Function<void(int)>;
using DoneCallback = Closure<void()>; using DoneCallback = Function<void()>;
GifSprite(); GifSprite();

View File

@ -29,7 +29,7 @@ namespace kiwano
{ {
SetSize(Renderer::GetInstance()->GetOutputSize()); SetSize(Renderer::GetInstance()->GetOutputSize());
auto handler = MakeClosure(this, &Layer::HandleMessages); auto handler = bind_func(this, &Layer::HandleMessages);
AddListener(Event::MouseBtnDown, handler); AddListener(Event::MouseBtnDown, handler);
AddListener(Event::MouseBtnUp, handler); AddListener(Event::MouseBtnUp, handler);
@ -53,9 +53,9 @@ namespace kiwano
if (!swallow_) if (!swallow_)
{ {
ActorPtr prev; 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); child->Dispatch(evt);
} }
} }

View File

@ -428,7 +428,7 @@ namespace kiwano
current_sink_->AddLine(DX::ConvertToPoint2F(point)); current_sink_->AddLine(DX::ConvertToPoint2F(point));
} }
void PathNode::AddLines(Array<Point> const& points) void PathNode::AddLines(Vector<Point> const& points)
{ {
if (current_sink_ && !points.empty()) if (current_sink_ && !points.empty())
{ {

View File

@ -320,7 +320,7 @@ namespace kiwano
// 添加多条线段 // 添加多条线段
void AddLines( void AddLines(
Array<Point> const& points Vector<Point> const& points
); );
// 添加一条三次方贝塞尔曲线 // 添加一条三次方贝塞尔曲线

View File

@ -23,17 +23,17 @@
namespace kiwano namespace kiwano
{ {
using ActionCallback = Closure<void()>; using ActionCallback = Function<void()>;
class ActionManager; class ActionManager;
class KGE_API Action class KGE_API Action
: public Object : public Object
, protected IntrusiveListItem<ActionPtr> , protected intrusive_list_item<ActionPtr>
{ {
friend class ActionManager; friend class ActionManager;
friend class ActionGroup; friend class ActionGroup;
friend class IntrusiveList<ActionPtr>; friend class intrusive_list<ActionPtr>;
public: public:
enum class Status enum class Status

View File

@ -33,7 +33,7 @@ namespace kiwano
{ {
} }
ActionGroup::ActionGroup(Array<ActionPtr> const& actions, bool sequence) ActionGroup::ActionGroup(Vector<ActionPtr> const& actions, bool sequence)
: sequence_(sequence) : sequence_(sequence)
{ {
this->Add(actions); this->Add(actions);
@ -45,19 +45,19 @@ namespace kiwano
void ActionGroup::Init(ActorPtr target) void ActionGroup::Init(ActorPtr target)
{ {
if (actions_.IsEmpty()) if (actions_.is_empty())
{ {
Done(); Done();
return; return;
} }
current_ = actions_.First(); current_ = actions_.first_item();
current_->Restart(target); // init first action current_->Restart(target); // init first action
if (!sequence_) if (!sequence_)
{ {
// init all actions // init all actions
for (; current_; current_ = current_->NextItem()) for (; current_; current_ = current_->next_item())
{ {
current_->Restart(target); current_->Restart(target);
} }
@ -74,7 +74,7 @@ namespace kiwano
if (current_->IsDone()) if (current_->IsDone())
{ {
current_ = current_->NextItem(); current_ = current_->next_item();
if (current_) if (current_)
current_->Restart(target); // init next action current_->Restart(target); // init next action
@ -86,7 +86,7 @@ namespace kiwano
else else
{ {
bool done = true; bool done = true;
for (current_ = actions_.First(); current_; current_ = current_->NextItem()) for (current_ = actions_.first_item(); current_; current_ = current_->next_item())
{ {
if (!current_->IsDone()) if (!current_->IsDone())
{ {
@ -106,11 +106,11 @@ namespace kiwano
{ {
if (action) if (action)
{ {
actions_.PushBack(action); actions_.push_back_item(action);
} }
} }
void ActionGroup::Add(Array<ActionPtr> const& actions) void ActionGroup::Add(Vector<ActionPtr> const& actions)
{ {
for (const auto& action : actions) for (const auto& action : actions)
Add(action); Add(action);
@ -121,7 +121,7 @@ namespace kiwano
auto group = new (std::nothrow) ActionGroup(); auto group = new (std::nothrow) ActionGroup();
if (group) if (group)
{ {
for (auto action = actions_.First(); action; action = action->NextItem()) for (auto action = actions_.first_item(); action; action = action->next_item())
{ {
if (action) if (action)
{ {
@ -135,9 +135,9 @@ namespace kiwano
ActionPtr ActionGroup::Reverse() const ActionPtr ActionGroup::Reverse() const
{ {
auto group = new (std::nothrow) ActionGroup(); auto group = new (std::nothrow) ActionGroup();
if (group && !actions_.IsEmpty()) if (group && !actions_.is_empty())
{ {
for (auto action = actions_.Last(); action; action = action->PrevItem()) for (auto action = actions_.last_item(); action; action = action->prev_item())
{ {
group->Add(action->Reverse()); group->Add(action->Reverse());
} }

View File

@ -28,12 +28,12 @@ namespace kiwano
: public Action : public Action
{ {
public: public:
using ActionList = IntrusiveList<ActionPtr>; using ActionList = intrusive_list<ActionPtr>;
ActionGroup(); ActionGroup();
explicit ActionGroup( explicit ActionGroup(
Array<ActionPtr> const& actions, Vector<ActionPtr> const& actions,
bool sequence = true // 按顺序执行或同时执行 bool sequence = true // 按顺序执行或同时执行
); );
@ -46,7 +46,7 @@ namespace kiwano
// 添加多个动作 // 添加多个动作
void Add( void Add(
Array<ActionPtr> const& actions Vector<ActionPtr> const& actions
); );
// 获取所有动作 // 获取所有动作
@ -84,7 +84,7 @@ namespace kiwano
inline ActionSequence() : ActionGroup() {} inline ActionSequence() : ActionGroup() {}
KGE_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead") KGE_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead")
inline explicit ActionSequence(Array<ActionPtr> const& actions) : ActionGroup(actions, true) {} inline explicit ActionSequence(Vector<ActionPtr> const& actions) : ActionGroup(actions, true) {}
virtual ~ActionSequence() {} virtual ~ActionSequence() {}
}; };
@ -99,7 +99,7 @@ namespace kiwano
inline ActionSpawn() : ActionGroup() { sequence_ = false; } inline ActionSpawn() : ActionGroup() { sequence_ = false; }
KGE_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead") KGE_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead")
inline explicit ActionSpawn(Array<ActionPtr> const& actions) : ActionGroup(actions, false) {} inline explicit ActionSpawn(Vector<ActionPtr> const& actions) : ActionGroup(actions, false) {}
virtual ~ActionSpawn() {} virtual ~ActionSpawn() {}
}; };

View File

@ -184,7 +184,7 @@ namespace kiwano
} }
static inline TweenHelper static inline TweenHelper
Animation(FramesPtr frames) Animation(FrameSequencePtr frames)
{ {
return TweenHelper(new kiwano::Animation(0, frames)); return TweenHelper(new kiwano::Animation(0, frames));
} }
@ -202,13 +202,13 @@ namespace kiwano
} }
static inline ActionHelper static inline ActionHelper
Group(Array<ActionPtr> const& actions, bool sequence = true) Group(Vector<ActionPtr> const& actions, bool sequence = true)
{ {
return ActionHelper(new kiwano::ActionGroup(actions, sequence)); return ActionHelper(new kiwano::ActionGroup(actions, sequence));
} }
static inline ActionHelper static inline ActionHelper
Multiple(Array<ActionPtr> const& actions) Multiple(Vector<ActionPtr> const& actions)
{ {
return ActionHelper(new kiwano::ActionGroup(actions, false)); return ActionHelper(new kiwano::ActionGroup(actions, false));
} }
@ -233,14 +233,14 @@ namespace kiwano
KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead") KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead")
static inline ActionHelper static inline ActionHelper
Sequence(Array<ActionPtr> const& actions) Sequence(Vector<ActionPtr> const& actions)
{ {
return ActionHelper(new kiwano::ActionGroup(actions, true)); return ActionHelper(new kiwano::ActionGroup(actions, true));
} }
KGE_DEPRECATED("Tween::Spawn is deprecated, use Tween::Multiple instead") KGE_DEPRECATED("Tween::Spawn is deprecated, use Tween::Multiple instead")
static inline ActionHelper static inline ActionHelper
Spawn(Array<ActionPtr> const& actions) Spawn(Vector<ActionPtr> const& actions)
{ {
return ActionHelper(new kiwano::ActionGroup(actions, false)); return ActionHelper(new kiwano::ActionGroup(actions, false));
} }

View File

@ -26,19 +26,19 @@ namespace kiwano
{ {
void ActionManager::UpdateActions(ActorPtr target, Duration dt) void ActionManager::UpdateActions(ActorPtr target, Duration dt)
{ {
if (actions_.IsEmpty() || !target) if (actions_.is_empty() || !target)
return; return;
ActionPtr next; ActionPtr next;
for (auto action = actions_.First(); action; action = next) for (auto action = actions_.first_item(); action; action = next)
{ {
next = action->NextItem(); next = action->next_item();
if (action->IsRunning()) if (action->IsRunning())
action->UpdateStep(target, dt); action->UpdateStep(target, dt);
if (action->IsRemoveable()) if (action->IsRemoveable())
actions_.Remove(action); actions_.remove_item(action);
} }
} }
@ -48,17 +48,17 @@ namespace kiwano
if (action) if (action)
{ {
actions_.PushBack(action); actions_.push_back_item(action);
} }
return action; return action;
} }
ActionPtr ActionManager::GetAction(String const & name) ActionPtr ActionManager::GetAction(String const & name)
{ {
if (actions_.IsEmpty()) if (actions_.is_empty())
return nullptr; return nullptr;
for (auto action = actions_.First().Get(); action; action = action->NextItem().Get()) for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
if (action->IsName(name)) if (action->IsName(name))
return action; return action;
return nullptr; return nullptr;
@ -66,10 +66,10 @@ namespace kiwano
void ActionManager::ResumeAllActions() void ActionManager::ResumeAllActions()
{ {
if (actions_.IsEmpty()) if (actions_.is_empty())
return; return;
for (auto action = actions_.First().Get(); action; action = action->NextItem().Get()) for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{ {
action->Resume(); action->Resume();
} }
@ -77,10 +77,10 @@ namespace kiwano
void ActionManager::PauseAllActions() void ActionManager::PauseAllActions()
{ {
if (actions_.IsEmpty()) if (actions_.is_empty())
return; return;
for (auto action = actions_.First().Get(); action; action = action->NextItem().Get()) for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{ {
action->Pause(); action->Pause();
} }
@ -88,10 +88,10 @@ namespace kiwano
void ActionManager::StopAllActions() void ActionManager::StopAllActions()
{ {
if (actions_.IsEmpty()) if (actions_.is_empty())
return; return;
for (auto action = actions_.First().Get(); action; action = action->NextItem().Get()) for (auto action = actions_.first_item().get(); action; action = action->next_item().get())
{ {
action->Stop(); action->Stop();
} }

View File

@ -25,7 +25,7 @@ namespace kiwano
{ {
class KGE_API ActionManager class KGE_API ActionManager
{ {
using Actions = IntrusiveList<ActionPtr>; using Actions = intrusive_list<ActionPtr>;
public: public:
// 添加动作 // 添加动作

View File

@ -564,7 +564,7 @@ namespace kiwano
} }
} }
void ActionPath::AddLines(Array<Point> const& points) void ActionPath::AddLines(Vector<Point> const& points)
{ {
if (!path_beginning_) if (!path_beginning_)
{ {

View File

@ -26,7 +26,7 @@
namespace kiwano namespace kiwano
{ {
// 缓动函数 // 缓动函数
using EaseFunc = Closure<float(float)>; using EaseFunc = Function<float(float)>;
// 缓动函数枚举 // 缓动函数枚举
// See https://easings.net for more information // See https://easings.net for more information
@ -446,7 +446,7 @@ namespace kiwano
// 添加多条线段 // 添加多条线段
void AddLines( void AddLines(
Array<Point> const& points Vector<Point> const& points
); );
// 添加一条三次方贝塞尔曲线 // 添加一条三次方贝塞尔曲线
@ -502,7 +502,7 @@ namespace kiwano
: public ActionTween : public ActionTween
{ {
public: public:
using TweenFunc = Closure<void(ActorPtr, float)>; using TweenFunc = Function<void(ActorPtr, float)>;
ActionCustom( ActionCustom(
Duration duration, /* 持续时长 */ Duration duration, /* 持续时长 */

View File

@ -58,7 +58,7 @@ namespace kiwano
return; return;
} }
auto sprite_target = dynamic_cast<Sprite*>(target.Get()); auto sprite_target = dynamic_cast<Sprite*>(target.get());
if (sprite_target && frame_seq_) if (sprite_target && frame_seq_)
{ {
sprite_target->SetFrame(frame_seq_->GetFrames()[0]); sprite_target->SetFrame(frame_seq_->GetFrames()[0]);
@ -67,7 +67,7 @@ namespace kiwano
void Animation::UpdateTween(ActorPtr target, float percent) void Animation::UpdateTween(ActorPtr target, float percent)
{ {
auto sprite_target = dynamic_cast<Sprite*>(target.Get()); auto sprite_target = dynamic_cast<Sprite*>(target.get());
KGE_ASSERT(sprite_target && "Animation only supports Sprites"); KGE_ASSERT(sprite_target && "Animation only supports Sprites");

View File

@ -20,14 +20,11 @@
#pragma once #pragma once
#include "Color.h" #include "Color.h"
#include "../common/helper.h" #include "../core/core.h"
#include "../common/ComPtr.hpp"
#include "../common/Closure.hpp"
#include "../common/Singleton.hpp"
#include "../common/IntrusiveList.hpp"
#include "../base/time.h" #include "../base/time.h"
#include "../base/RefCounter.hpp" #include "../base/RefCounter.hpp"
#include "../base/SmartPtr.hpp" #include "../base/SmartPtr.hpp"
#include "../base/ComPtr.hpp"
#include "../base/Object.h" #include "../base/Object.h"
#include "../math/helper.h" #include "../math/helper.h"
#include "../base/types.h" #include "../base/types.h"

View File

@ -24,7 +24,7 @@
namespace kiwano namespace kiwano
{ {
AsyncTask::AsyncTask() AsyncTask::AsyncTask()
: thread_(MakeClosure(this, &AsyncTask::TaskThread)) : thread_(bind_func(this, &AsyncTask::TaskThread))
{ {
} }
@ -74,7 +74,7 @@ namespace kiwano
func_mutex_.unlock(); func_mutex_.unlock();
} }
Application::PreformInMainThread(MakeClosure(this, &AsyncTask::Complete)); Application::PreformInMainThread(bind_func(this, &AsyncTask::Complete));
} }
void AsyncTask::Complete() void AsyncTask::Complete()

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include "Object.h" #include "Object.h"
#include "../common/Closure.hpp"
#include <thread> #include <thread>
#include <mutex> #include <mutex>
@ -28,8 +27,8 @@ namespace kiwano
{ {
KGE_DECLARE_SMART_PTR(AsyncTask); KGE_DECLARE_SMART_PTR(AsyncTask);
typedef Closure<void()> AsyncTaskFunc; typedef Function<void()> AsyncTaskFunc;
typedef Closure<void()> AsyncTaskCallback; typedef Function<void()> AsyncTaskCallback;
class AsyncTask class AsyncTask
: public Object : public Object

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "IntrusivePtr.hpp" #include "../core/intrusive_ptr.hpp"
#include <Unknwnbase.h> #include <Unknwnbase.h>
#include <type_traits> #include <type_traits>
@ -42,6 +42,6 @@ namespace kiwano
template< template<
typename _Ty, typename _Ty,
typename = typename std::enable_if<std::is_base_of<IUnknown, _Ty>::value, int>::type> typename = typename std::enable_if<std::is_base_of<IUnknown, _Ty>::value, int>::type>
using ComPtr = IntrusivePtr<_Ty, ComPtrManager>; using ComPtr = intrusive_ptr<_Ty, ComPtrManager>;
} }

View File

@ -74,15 +74,23 @@ namespace kiwano
{ {
if (show) if (show)
{ {
if (!debug_node_) if (!debug_actor_)
debug_node_ = new DebugNode; debug_actor_ = new DebugNode;
} }
else else
{ {
debug_node_.Reset(); debug_actor_.reset();
} }
} }
void Director::ClearStages()
{
curr_scene_.reset();
next_scene_.reset();
debug_actor_.reset();
transition_.reset();
}
void Director::OnUpdate(Duration dt) void Director::OnUpdate(Duration dt)
{ {
if (transition_) if (transition_)
@ -112,8 +120,8 @@ namespace kiwano
if (next_scene_) if (next_scene_)
next_scene_->Update(dt); next_scene_->Update(dt);
if (debug_node_) if (debug_actor_)
debug_node_->Update(dt); debug_actor_->Update(dt);
} }
void Director::OnRender() void Director::OnRender()
@ -127,8 +135,8 @@ namespace kiwano
curr_scene_->Render(); curr_scene_->Render();
} }
if (debug_node_) if (debug_actor_)
debug_node_->Render(); debug_actor_->Render();
} }
void Director::AfterRender() void Director::AfterRender()
@ -142,8 +150,8 @@ namespace kiwano
void Director::HandleEvent(Event& evt) void Director::HandleEvent(Event& evt)
{ {
if (debug_node_) if (debug_actor_)
debug_node_->Dispatch(evt); debug_actor_->Dispatch(evt);
if (curr_scene_) if (curr_scene_)
curr_scene_->Dispatch(evt); curr_scene_->Dispatch(evt);

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/Singleton.hpp"
#include "../2d/include-forwards.h" #include "../2d/include-forwards.h"
#include "Component.h" #include "Component.h"
@ -54,6 +53,9 @@ namespace kiwano
// 显示调试信息 // 显示调试信息
void ShowDebugInfo(bool show = true); void ShowDebugInfo(bool show = true);
// 헌왕校憩
void ClearStages();
public: public:
void SetupComponent() override {} void SetupComponent() override {}
@ -76,7 +78,7 @@ namespace kiwano
bool render_border_enabled_; bool render_border_enabled_;
StagePtr curr_scene_; StagePtr curr_scene_;
StagePtr next_scene_; StagePtr next_scene_;
ActorPtr debug_node_; ActorPtr debug_actor_;
TransitionPtr transition_; TransitionPtr transition_;
}; };
} }

View File

@ -25,13 +25,13 @@ namespace kiwano
{ {
void EventDispatcher::Dispatch(Event& evt) void EventDispatcher::Dispatch(Event& evt)
{ {
if (listeners_.IsEmpty()) if (listeners_.is_empty())
return; return;
EventListenerPtr next; EventListenerPtr next;
for (auto listener = listeners_.First(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->NextItem(); next = listener->next_item();
if (listener->type_ == evt.type) if (listener->type_ == evt.type)
{ {
@ -46,7 +46,7 @@ namespace kiwano
if (listener) if (listener)
{ {
listeners_.PushBack(listener); listeners_.push_back_item(listener);
} }
return listener; return listener;
} }
@ -56,13 +56,13 @@ namespace kiwano
EventListenerPtr listener = new EventListener(type, callback, name); EventListenerPtr listener = new EventListener(type, callback, name);
if (listener) if (listener)
{ {
listeners_.PushBack(listener); listeners_.push_back_item(listener);
} }
} }
void EventDispatcher::StartListeners(String const & listener_name) void EventDispatcher::StartListeners(String const & listener_name)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
{ {
if (listener->IsName(listener_name)) if (listener->IsName(listener_name))
{ {
@ -73,7 +73,7 @@ namespace kiwano
void EventDispatcher::StopListeners(String const & listener_name) void EventDispatcher::StopListeners(String const & listener_name)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
{ {
if (listener->IsName(listener_name)) if (listener->IsName(listener_name))
{ {
@ -85,20 +85,20 @@ namespace kiwano
void EventDispatcher::RemoveListeners(String const & listener_name) void EventDispatcher::RemoveListeners(String const & listener_name)
{ {
EventListenerPtr next; EventListenerPtr next;
for (auto listener = listeners_.First(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->NextItem(); next = listener->next_item();
if (listener->IsName(listener_name)) if (listener->IsName(listener_name))
{ {
listeners_.Remove(listener); listeners_.remove_item(listener);
} }
} }
} }
void EventDispatcher::StartListeners(UINT type) void EventDispatcher::StartListeners(UINT type)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
{ {
if (listener->type_ == type) if (listener->type_ == type)
{ {
@ -109,7 +109,7 @@ namespace kiwano
void EventDispatcher::StopListeners(UINT type) void EventDispatcher::StopListeners(UINT type)
{ {
for (auto listener = listeners_.First(); listener; listener = listener->NextItem()) for (auto listener = listeners_.first_item(); listener; listener = listener->next_item())
{ {
if (listener->type_ == type) if (listener->type_ == type)
{ {
@ -121,13 +121,13 @@ namespace kiwano
void EventDispatcher::RemoveListeners(UINT type) void EventDispatcher::RemoveListeners(UINT type)
{ {
EventListenerPtr next; EventListenerPtr next;
for (auto listener = listeners_.First(); listener; listener = next) for (auto listener = listeners_.first_item(); listener; listener = next)
{ {
next = listener->NextItem(); next = listener->next_item();
if (listener->type_ == type) if (listener->type_ == type)
{ {
listeners_.Remove(listener); listeners_.remove_item(listener);
} }
} }
} }

View File

@ -25,7 +25,7 @@ namespace kiwano
{ {
class KGE_API EventDispatcher class KGE_API EventDispatcher
{ {
using Listeners = IntrusiveList<EventListenerPtr>; using Listeners = intrusive_list<EventListenerPtr>;
public: public:
// 添加监听器 // 添加监听器

View File

@ -19,17 +19,14 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../core/core.h"
#include "../base/SmartPtr.hpp" #include "../base/SmartPtr.hpp"
#include "../common/helper.h"
#include "../common/Closure.hpp"
#include "../common/IntrusiveList.hpp"
#include "Object.h" #include "Object.h"
#include "Event.hpp" #include "Event.hpp"
#include <functional>
namespace kiwano namespace kiwano
{ {
typedef Closure<void(Event const&)> EventCallback; typedef Function<void(Event const&)> EventCallback;
class EventDispatcher; class EventDispatcher;
@ -38,10 +35,10 @@ namespace kiwano
// 事件监听器 // 事件监听器
class KGE_API EventListener class KGE_API EventListener
: public Object : public Object
, protected IntrusiveListItem<EventListenerPtr> , protected intrusive_list_item<EventListenerPtr>
{ {
friend class EventDispatcher; friend class EventDispatcher;
friend class IntrusiveList<EventListenerPtr>; friend class intrusive_list<EventListenerPtr>;
public: public:
EventListener( EventListener(

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/Singleton.hpp" #include "../core/core.h"
#include "../math/helper.h" #include "../math/helper.h"
#include "keys.hpp" #include "keys.hpp"
#include "Component.h" #include "Component.h"

View File

@ -27,7 +27,7 @@ namespace kiwano
namespace namespace
{ {
bool tracing_leaks = false; bool tracing_leaks = false;
Array<Object*> tracing_objects; Vector<Object*> tracing_objects;
} }
unsigned int Object::last_object_id = 0; unsigned int Object::last_object_id = 0;
@ -120,7 +120,7 @@ namespace kiwano
KGE_LOG(L"------------------------- Total size: %d -------------------------", tracing_objects.size()); KGE_LOG(L"------------------------- Total size: %d -------------------------", tracing_objects.size());
} }
Array<Object*>& kiwano::Object::__GetTracingObjects() Vector<Object*>& kiwano::Object::__GetTracingObjects()
{ {
return tracing_objects; return tracing_objects;
} }

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h" #include "../core/core.h"
#include "RefCounter.hpp" #include "RefCounter.hpp"
#include "SmartPtr.hpp" #include "SmartPtr.hpp"
@ -60,7 +60,7 @@ namespace kiwano
static void DumpTracingObjects(); static void DumpTracingObjects();
public: public:
static Array<Object*>& __GetTracingObjects(); static Vector<Object*>& __GetTracingObjects();
static void __AddObjectToTracingList(Object*); static void __AddObjectToTracingList(Object*);

View File

@ -20,12 +20,12 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/Noncopyable.hpp" #include "../core/noncopyable.hpp"
namespace kiwano namespace kiwano
{ {
class KGE_API RefCounter class KGE_API RefCounter
: protected Noncopyable : protected noncopyable
{ {
public: public:
// 增加引用计数 // 增加引用计数

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h" #include "../core/core.h"
namespace kiwano namespace kiwano
{ {

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../base/RefCounter.hpp" #include "../base/RefCounter.hpp"
#include "../common/IntrusivePtr.hpp" #include "../core/intrusive_ptr.hpp"
namespace kiwano namespace kiwano
{ {
@ -38,7 +38,7 @@ namespace kiwano
}; };
template <typename _Ty> template <typename _Ty>
using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager>; using SmartPtr = intrusive_ptr<_Ty, DefaultIntrusivePtrManager>;
} }

View File

@ -19,9 +19,6 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../common/helper.h"
#include "../common/Closure.hpp"
#include "../common/IntrusiveList.hpp"
#include "Object.h" #include "Object.h"
#include "time.h" #include "time.h"
#include <functional> #include <functional>
@ -35,12 +32,12 @@ namespace kiwano
// 定时任务 // 定时任务
class KGE_API Timer class KGE_API Timer
: public Object : public Object
, protected IntrusiveListItem<TimerPtr> , protected intrusive_list_item<TimerPtr>
{ {
friend class TimerManager; friend class TimerManager;
friend class IntrusiveList<TimerPtr>; friend class intrusive_list<TimerPtr>;
using Callback = Closure<void()>; using Callback = Function<void()>;
public: public:
explicit Timer( explicit Timer(

View File

@ -25,19 +25,19 @@ namespace kiwano
{ {
void TimerManager::UpdateTimers(Duration dt) void TimerManager::UpdateTimers(Duration dt)
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
TimerPtr next; TimerPtr next;
for (auto timer = timers_.First(); timer; timer = next) for (auto timer = timers_.first_item(); timer; timer = next)
{ {
next = timer->NextItem(); next = timer->next_item();
bool remove_after_update = false; bool remove_after_update = false;
timer->Update(dt, remove_after_update); timer->Update(dt, remove_after_update);
if (remove_after_update) if (remove_after_update)
timers_.Remove(timer); timers_.remove_item(timer);
} }
} }
@ -48,16 +48,16 @@ namespace kiwano
if (timer) if (timer)
{ {
timer->Reset(); timer->Reset();
timers_.PushBack(timer); timers_.push_back_item(timer);
} }
} }
void TimerManager::StopTimers(String const& name) void TimerManager::StopTimers(String const& name)
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
for (auto timer = timers_.First().Get(); timer; timer = timer->NextItem().Get()) for (auto timer = timers_.first_item().get(); timer; timer = timer->next_item().get())
{ {
if (timer->IsName(name)) if (timer->IsName(name))
{ {
@ -68,10 +68,10 @@ namespace kiwano
void TimerManager::StartTimers(String const& name) void TimerManager::StartTimers(String const& name)
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
for (auto timer = timers_.First().Get(); timer; timer = timer->NextItem().Get()) for (auto timer = timers_.first_item().get(); timer; timer = timer->next_item().get())
{ {
if (timer->IsName(name)) if (timer->IsName(name))
{ {
@ -82,26 +82,26 @@ namespace kiwano
void TimerManager::RemoveTimers(String const& name) void TimerManager::RemoveTimers(String const& name)
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
TimerPtr next; TimerPtr next;
for (auto timer = timers_.First(); timer; timer = next) for (auto timer = timers_.first_item(); timer; timer = next)
{ {
next = timer->NextItem(); next = timer->next_item();
if (timer->IsName(name)) if (timer->IsName(name))
{ {
timers_.Remove(timer); timers_.remove_item(timer);
} }
} }
} }
void TimerManager::StopAllTimers() void TimerManager::StopAllTimers()
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
for (auto timer = timers_.First().Get(); timer; timer = timer->NextItem().Get()) for (auto timer = timers_.first_item().get(); timer; timer = timer->next_item().get())
{ {
timer->Stop(); timer->Stop();
} }
@ -109,10 +109,10 @@ namespace kiwano
void TimerManager::StartAllTimers() void TimerManager::StartAllTimers()
{ {
if (timers_.IsEmpty()) if (timers_.is_empty())
return; return;
for (auto timer = timers_.First().Get(); timer; timer = timer->NextItem().Get()) for (auto timer = timers_.first_item().get(); timer; timer = timer->next_item().get())
{ {
timer->Start(); timer->Start();
} }
@ -120,7 +120,7 @@ namespace kiwano
void TimerManager::RemoveAllTimers() void TimerManager::RemoveAllTimers()
{ {
timers_.Clear(); timers_.clear_items();
} }
const TimerManager::Timers & TimerManager::GetAllTimers() const const TimerManager::Timers & TimerManager::GetAllTimers() const

View File

@ -25,7 +25,7 @@ namespace kiwano
{ {
class KGE_API TimerManager class KGE_API TimerManager
{ {
using Timers = IntrusiveList<TimerPtr>; using Timers = intrusive_list<TimerPtr>;
public: public:
// Ìí¼ÓÈÎÎñ // Ìí¼ÓÈÎÎñ

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/Singleton.hpp" #include "../core/core.h"
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>

View File

@ -73,7 +73,7 @@ namespace kiwano
static LARGE_INTEGER freq = {}; static LARGE_INTEGER freq = {};
if (freq.QuadPart == 0LL) if (freq.QuadPart == 0LL)
{ {
// the function will always succceed on systems that run Windows XP or later // the Function will always succceed on systems that run Windows XP or later
QueryPerformanceFrequency(&freq); QueryPerformanceFrequency(&freq);
} }

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/String.hpp" #include "../core/core.h"
#include <ostream> #include <ostream>
#include <istream> #include <istream>

View File

@ -20,9 +20,8 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h" #include "../core/core.h"
#include "../math/helper.h" #include "../math/helper.h"
#include "../common/Singleton.hpp"
#include "types.h" #include "types.h"
namespace kiwano namespace kiwano

View File

@ -1,277 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <memory>
#include <type_traits>
#include <exception>
namespace kiwano
{
//
// ArrayManager<> with memory operations
//
template<typename _Ty, typename _Alloc, bool _IsClassType = std::is_class<_Ty>::value>
struct __ArrayManager;
//
// Array<>
// Lightweight std::vector<>-like class
//
template<
typename _Ty,
typename _Alloc = std::allocator<_Ty>,
typename _Manager = __ArrayManager<_Ty, _Alloc>>
class Array
{
public:
using value_type = _Ty;
using size_type = std::size_t;
using iterator = value_type * ;
using const_iterator = const value_type*;
using reference = value_type & ;
using const_reference = const value_type &;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using allocator_type = typename _Alloc;
using manager = typename _Manager;
using initializer_list = std::initializer_list<value_type>;
public:
inline Array() : size_(0), capacity_(0), data_(nullptr) { }
inline Array(size_type count) : Array() { reserve(count); }
inline Array(size_type count, const _Ty& val) : Array() { assign(count, val); }
inline Array(initializer_list list) : Array() { assign(list); }
inline Array(const Array& src) : Array() { assign(src); }
inline Array(Array&& src) noexcept : Array() { swap(src); }
inline ~Array() { destroy(); }
template <typename _Iter>
inline Array(_Iter first, _Iter last) : Array() { assign(first, last); }
inline Array& operator=(const Array& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); }
inline Array& operator=(Array&& src) noexcept { swap(src); return *this; }
inline Array& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); }
inline Array& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); }
inline Array& assign(const Array& src) { return operator=(src); }
inline Array& assign(initializer_list list) { return operator=(list); }
template <typename _Iter>
inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); }
inline void clear() { destroy(); size_ = capacity_ = 0; data_ = nullptr; }
inline void swap(Array& rhs) noexcept { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); }
inline void resize(size_type new_size) { resize(new_size, _Ty()); }
void resize(size_type new_size, const _Ty& v);
void reserve(size_type new_capacity);
inline void push_back(const _Ty& val) { resize(size_ + 1, val); }
inline void pop_back() { if (empty()) throw std::out_of_range("pop() called on empty vector"); resize(size_ - 1); }
inline void push_front(const _Ty& val) { if (size_ == 0) push_back(val); else insert(begin(), val); }
inline iterator erase(const_iterator where) { return erase(where, where + 1); }
iterator erase(const_iterator first, const_iterator last);
iterator insert(const_iterator where, const _Ty& v);
inline bool empty() const { return size_ == 0; }
inline size_type size() const { return size_; }
inline size_type size_in_bytes() const { return size_ * ((size_type)sizeof(_Ty)); }
inline size_type capacity() const { return capacity_; }
inline reference operator[](size_type off) { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
inline const_reference operator[](size_type off) const { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
inline bool contains(const _Ty& v) const { auto data = cbegin(); const auto data_end = cend(); while (data != data_end) if (*(data++) == v) return true; return false; }
inline size_type index_of(const_iterator it) const { check_offset(it - cbegin(), "invalid array position"); return it - data_; }
inline iterator begin() { return iterator(data_); }
inline const_iterator begin() const { return const_iterator(data_); }
inline const_iterator cbegin() const { return begin(); }
inline iterator end() { return iterator(data_ + size_); }
inline const_iterator end() const { return const_iterator(data_ + size_); }
inline const_iterator cend() const { return end(); }
inline reverse_iterator rbegin() { return reverse_iterator(end()); }
inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
inline const_reverse_iterator crbegin() const { return rbegin(); }
inline reverse_iterator rend() { return reverse_iterator(begin()); }
inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
inline const_reverse_iterator crend() const { return rend(); }
inline reference front() { if (empty()) throw std::out_of_range("front() called on empty array"); return data_[0]; }
inline const_reference front() const { if (empty()) throw std::out_of_range("front() called on empty array"); return data_[0]; }
inline reference back() { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; }
inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; }
private:
inline size_type grow_capacity(size_type sz) const { size_type new_capacity = capacity_ ? (capacity_ + capacity_ / 2) : 8; return new_capacity > sz ? new_capacity : sz; }
inline void check_offset(const size_type off) const { if (off < 0 || off >= size_) throw std::out_of_range("invalid vector position"); }
inline void destroy() { manager::destroy(data_, size_); manager::deallocate(data_, capacity_); }
protected:
size_type size_;
size_type capacity_;
_Ty* data_;
};
template<typename _Ty, typename _Alloc, typename _Manager>
void Array<_Ty, _Alloc, _Manager>::resize(size_type new_size, const _Ty& val)
{
if (new_size > size_)
{
if (new_size > capacity_)
{
reserve(grow_capacity(new_size));
}
manager::construct(begin() + size_, new_size - size_, val);
}
else
{
manager::destroy(begin() + new_size, size_ - new_size);
}
size_ = new_size;
}
template<typename _Ty, typename _Alloc, typename _Manager>
void Array<_Ty, _Alloc, _Manager>::reserve(size_type new_capacity)
{
if (new_capacity <= capacity_)
return;
auto new_data = manager::allocate(new_capacity);
if (data_)
{
manager::construct(new_data, size_/* only construct needed size */);
manager::copy_data(new_data, data_, size_);
/* destroy old memory, but not resize */
destroy();
}
data_ = new_data;
capacity_ = new_capacity;
}
template<typename _Ty, typename _Alloc, typename _Manager>
typename Array<_Ty, _Alloc, _Manager>::iterator
Array<_Ty, _Alloc, _Manager>::erase(const_iterator first, const_iterator last)
{
const auto off = first - begin();
const auto count = last - first;
if (count != 0)
{
check_offset(off);
manager::move_data(begin() + off, begin() + off + count, size_ - off - count);
resize(size_ - count); // do destruction
}
return begin() + off;
}
template<typename _Ty, typename _Alloc, typename _Manager>
typename Array<_Ty, _Alloc, _Manager>::iterator
Array<_Ty, _Alloc, _Manager>::insert(const_iterator where, const _Ty& v)
{
const auto off = where - begin();
const auto insert_at = begin() + off;
check_offset(off);
resize(size_ + 1);
manager::move_data(insert_at + 1, insert_at, size_ - off - 1);
data_[off] = v;
return begin() + off;
}
//
// ArrayManager for common type
//
template<typename _Ty, typename _Alloc>
struct __ArrayManager<_Ty, _Alloc, false>
{
using value_type = _Ty;
using size_type = size_t;
using allocator_type = typename _Alloc;
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (int)val, (size_t)count * sizeof(value_type)); }
static void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (size_t)count * sizeof(value_type)); }
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static void construct(value_type* ptr, size_type count) { }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) { --count; *(ptr + count) = val; } }
static void destroy(value_type* ptr, size_type count) { }
private:
static allocator_type& get_allocator()
{
static allocator_type allocator_;
return allocator_;
}
};
//
// ArrayManager for class
//
template<typename _Ty, typename _Alloc>
struct __ArrayManager<_Ty, _Alloc, true>
{
using value_type = _Ty;
using size_type = size_t;
using allocator_type = typename _Alloc;
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { while (count--) (*dest++) = val; }
static void move_data(value_type* dest, const value_type* src, size_type count)
{
if (src == dest) return;
if (dest > src && dest < src + count)
{
src = src + count - 1;
dest = dest + count - 1;
while (count--)
(*dest--) = (*src--);
}
else
{
while (count--)
(*dest++) = (*src++);
}
}
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static void construct(value_type* ptr, size_type count) { construct(ptr, count, value_type()); }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) get_allocator().construct(ptr + (--count), val); }
static void destroy(value_type* ptr, size_type count) { while (count) get_allocator().destroy(ptr + (--count)); }
private:
static allocator_type& get_allocator()
{
static allocator_type allocator_;
return allocator_;
}
};
}

View File

@ -1,255 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "../macros.h"
#include <functional>
// #define KGE_DEBUG_ENABLE_LIST_CHECK
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
# define KGE_DEBUG_CHECK_LIST(list_ptr) list_ptr->Check()
#else
# define KGE_DEBUG_CHECK_LIST __noop
#endif
namespace kiwano
{
template <typename T> class IntrusiveList;
template <typename T>
class IntrusiveListItem
{
T prev_;
T next_;
template <typename U>
friend class IntrusiveList;
public:
using ItemType = T;
IntrusiveListItem() : prev_(), next_() {}
T const& PrevItem() const { return prev_; }
T& PrevItem() { return prev_; }
T const& NextItem() const { return next_; }
T& NextItem() { return next_; }
};
template <typename T>
class IntrusiveList
{
T first_;
T last_;
public:
using ItemType = T;
IntrusiveList() : first_(), last_() {}
~IntrusiveList() { Clear(); }
T const& First() const { return first_; }
T& First() { return first_; }
T const& Last() const { return last_; }
T& Last() { return last_; }
bool IsEmpty() const { return !first_; }
void PushBack(T const& child)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
child->prev_ = last_;
child->next_ = nullptr;
if (first_)
{
last_->next_ = child;
}
else
{
first_ = child;
}
last_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void PushFront(T const& child)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
child->prev_ = nullptr;
child->next_ = first_;
if (first_)
{
first_->prev_ = child;
}
else
{
last_ = child;
}
first_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void InsertBefore(T const& child, T const& before)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
if (before->prev_)
before->prev_->next_ = child;
else
first_ = child;
child->prev_ = before->prev_;
child->next_ = before;
before->prev_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void InsertAfter(T const& child, T const& after)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
if (after->next_)
after->next_->prev_ = child;
else
last_ = child;
child->next_ = after->next_;
child->prev_ = after;
after->next_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void Remove(T const& child)
{
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
T tmp = first_;
while (tmp != child)
{
KGE_ASSERT((tmp != last_) && "The node to be removed is not in this list");
tmp = tmp->next_;
}
#endif
if (child->next_)
{
child->next_->prev_ = child->prev_;
}
else
{
last_ = child->prev_;
}
if (child->prev_)
{
child->prev_->next_ = child->next_;
}
else
{
first_ = child->next_;
}
child->prev_ = nullptr;
child->next_ = nullptr;
KGE_DEBUG_CHECK_LIST(this);
}
void Clear()
{
T p = first_;
while (p)
{
T tmp = p;
p = p->next_;
if (tmp)
{
tmp->next_ = nullptr;
tmp->prev_ = nullptr;
}
}
first_ = nullptr;
last_ = nullptr;
}
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
private:
void Check()
{
if (!first_)
return;
int pos = 0;
T p = first_;
T tmp = p;
do
{
tmp = p;
p = p->next_;
++pos;
if (p)
{
KGE_ASSERT(p->prev_ == tmp && "Check list failed");
}
else
{
KGE_ASSERT(tmp == last_ && "Check list failed");
}
} while (p);
}
#endif
};
}
#undef KGE_DEBUG_CHECK_LIST
#undef KGE_DEBUG_ENABLE_LIST_CHECK

View File

@ -1,212 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining lhs copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "../macros.h"
#include <utility>
#include <type_traits>
namespace kiwano
{
template <typename _Ty, typename _Manager>
class IntrusivePtr
{
_Ty* ptr_{ nullptr };
public:
using Type = _Ty;
IntrusivePtr() noexcept {}
IntrusivePtr(nullptr_t) noexcept {}
IntrusivePtr(Type* p) noexcept : ptr_(p)
{
typename _Manager::AddRef(ptr_);
}
IntrusivePtr(const Type* p) noexcept : ptr_(p)
{
typename _Manager::AddRef(ptr_);
}
IntrusivePtr(const IntrusivePtr& other) noexcept
: ptr_(other.ptr_)
{
typename _Manager::AddRef(ptr_);
}
template <typename _UTy>
IntrusivePtr(const IntrusivePtr<_UTy, _Manager>& other) noexcept
: ptr_(other.Get())
{
typename _Manager::AddRef(ptr_);
}
IntrusivePtr(IntrusivePtr&& other) noexcept
{
ptr_ = other.ptr_;
other.ptr_ = nullptr;
}
~IntrusivePtr() noexcept
{
typename _Manager::Release(ptr_);
}
inline Type* Get() const noexcept { return ptr_; }
inline void Reset() noexcept
{
IntrusivePtr{}.Swap(*this);
}
inline void Swap(IntrusivePtr& other) noexcept
{
std::swap(ptr_, other.ptr_);
}
inline Type* operator ->() const
{
KGE_ASSERT(ptr_ != nullptr && "Invalid pointer");
return ptr_;
}
inline Type& operator *() const
{
KGE_ASSERT(ptr_ != nullptr && "Invalid pointer");
return *ptr_;
}
inline Type** operator &()
{
KGE_ASSERT(ptr_ == nullptr && "Memory leak");
return &ptr_;
}
inline operator bool() const noexcept { return ptr_ != nullptr; }
inline bool operator !() const noexcept { return ptr_ == 0; }
inline IntrusivePtr& operator =(const IntrusivePtr& other) noexcept
{
if (other.ptr_ != ptr_)
IntrusivePtr(other).Swap(*this);
return *this;
}
inline IntrusivePtr& operator =(IntrusivePtr&& other) noexcept
{
typename _Manager::Release(ptr_);
ptr_ = other.ptr_;
other.ptr_ = nullptr;
return *this;
}
inline IntrusivePtr& operator =(Type* p) noexcept
{
if (p != ptr_)
IntrusivePtr(p).Swap(*this);
return *this;
}
inline IntrusivePtr& operator =(nullptr_t) noexcept
{
if (nullptr != ptr_)
IntrusivePtr{}.Swap(*this);
return *this;
}
};
template <class _Ty, class _UTy, class _Manager>
inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{
return lhs.Get() == rhs.Get();
}
template <class _Ty, class _UTy, class _Manager>
inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{
return lhs.Get() != rhs.Get();
}
template <class _Ty, class _UTy, class _Manager>
inline bool operator<(IntrusivePtr<_Ty, _Manager> const& lhs, IntrusivePtr<_UTy, _Manager> const& rhs) noexcept
{
return lhs.Get() < rhs.Get();
}
template <class _Ty, class _Manager>
inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept
{
return lhs.Get() == rhs;
}
template <class _Ty, class _Manager>
inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) noexcept
{
return lhs.Get() != rhs;
}
template <class _Ty, class _Manager>
inline bool operator==(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{
return lhs == rhs.Get();
}
template <class _Ty, class _Manager>
inline bool operator!=(_Ty* lhs, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{
return lhs != rhs.Get();
}
template <class _Ty, class _Manager>
inline bool operator==(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept
{
return !static_cast<bool>(lhs);
}
template <class _Ty, class _Manager>
inline bool operator!=(IntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) noexcept
{
return static_cast<bool>(lhs);
}
template <class _Ty, class _Manager>
inline bool operator==(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{
return !static_cast<bool>(rhs);
}
template <class _Ty, class _Manager>
inline bool operator!=(nullptr_t, IntrusivePtr<_Ty, _Manager> const& rhs) noexcept
{
return static_cast<bool>(rhs);
}
// template class cannot specialize std::swap,
// so implement a swap function in kiwano namespace
template <class _Ty, class _Manager>
inline void swap(IntrusivePtr<_Ty, _Manager>& lhs, IntrusivePtr<_Ty, _Manager>& rhs) noexcept
{
lhs.Swap(rhs);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,344 +0,0 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <stdexcept>
#include <type_traits>
namespace kiwano
{
//
// Closure is a light weight std::function<>-like class
//
namespace __closure_detail
{
//
// is_callable
//
namespace __callable_detail
{
template <typename _Ty, typename _Ret, typename... _Args>
struct helper
{
template <typename _Uty> static int test(...);
template <typename _Uty, _Ret(_Uty::*)(_Args...)> struct class_mem;
template <typename _Uty> static char test(class_mem<_Uty, &_Uty::operator()>*);
template <typename _Uty, _Ret(_Uty::*)(_Args...) const> struct class_const_mem;
template <typename _Uty> static char test(class_const_mem<_Uty, &_Uty::operator()>*);
template<
typename _Uty,
typename _Uret = typename std::decay<decltype(std::declval<_Uty>().operator()(std::declval<_Args>()...))>::type,
typename = typename std::enable_if<std::is_convertible<_Ret, _Uret>::value>::type>
static char test(int);
static constexpr bool value = sizeof(test<_Ty>(0)) == sizeof(char);
};
}
template<typename _Ty, typename _Ret, typename... _Args>
struct is_callable
: public std::bool_constant<__callable_detail::helper<_Ty, _Ret, _Args...>::value>
{
};
//
// Callable
//
template<typename _Ret, typename... _Args>
class Callable
{
public:
virtual ~Callable() {}
virtual void AddRef() = 0;
virtual void Release() = 0;
virtual _Ret Invoke(_Args... args) const = 0;
};
template<typename _Ret, typename... _Args>
class RefCountCallable
: public Callable<_Ret, _Args...>
{
public:
RefCountCallable() : ref_count_(0) {}
virtual void AddRef() override
{
++ref_count_;
}
virtual void Release() override
{
--ref_count_;
if (ref_count_ <= 0)
{
delete this;
}
}
private:
int ref_count_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class ProxyCallable
: public RefCountCallable<_Ret, _Args...>
{
public:
ProxyCallable(_Ty&& val)
: callee_(std::move(val))
{
}
virtual _Ret Invoke(_Args... args) const override
{
return callee_(std::forward<_Args&&>(args)...);
}
static inline Callable<_Ret, _Args...>* Make(_Ty&& val)
{
return new (std::nothrow) ProxyCallable<_Ty, _Ret, _Args...>(std::move(val));
}
private:
_Ty callee_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class ProxyMemCallable
: public RefCountCallable<_Ret, _Args...>
{
public:
typedef _Ret(_Ty::* _FuncType)(_Args...);
virtual _Ret Invoke(_Args... args) const override
{
return (static_cast<_Ty*>(ptr_)->*func_)(std::forward<_Args>(args)...);
}
static inline Callable<_Ret, _Args...>* Make(void* ptr, _FuncType func)
{
return new (std::nothrow) ProxyMemCallable<_Ty, _Ret, _Args...>(ptr, func);
}
protected:
ProxyMemCallable(void* ptr, _FuncType func)
: ptr_(ptr)
, func_(func)
{
}
protected:
void* ptr_;
_FuncType func_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class ProxyConstMemCallable
: public RefCountCallable<_Ret, _Args...>
{
public:
typedef _Ret(_Ty::* _FuncType)(_Args...) const;
virtual _Ret Invoke(_Args... args) const override
{
return (static_cast<_Ty*>(ptr_)->*func_)(std::forward<_Args>(args)...);
}
static inline Callable<_Ret, _Args...>* Make(void* ptr, _FuncType func)
{
return new (std::nothrow) ProxyConstMemCallable<_Ty, _Ret, _Args...>(ptr, func);
}
protected:
ProxyConstMemCallable(void* ptr, _FuncType func)
: ptr_(ptr)
, func_(func)
{
}
protected:
void* ptr_;
_FuncType func_;
};
}
//
// exceptions
//
class bad_function_call : public std::exception
{
public:
bad_function_call() {}
virtual const char* what() const override
{
return "bad function call";
}
};
//
// Closure details
//
template<typename _Ty>
class Closure;
template<typename _Ret, typename... _Args>
class Closure<_Ret(_Args...)>
{
public:
Closure()
: callable_(nullptr)
{
}
Closure(std::nullptr_t)
: callable_(nullptr)
{
}
Closure(const Closure& rhs)
: callable_(rhs.callable_)
{
if (callable_) callable_->AddRef();
}
Closure(Closure&& rhs) noexcept
: callable_(rhs.callable_)
{
rhs.callable_ = nullptr;
}
Closure(_Ret(*func)(_Args...))
{
callable_ = __closure_detail::ProxyCallable<_Ret(*)(_Args...), _Ret, _Args...>::Make(std::move(func));
if (callable_) callable_->AddRef();
}
template<
typename _Ty,
typename = typename std::enable_if<__closure_detail::is_callable<_Ty, _Ret, _Args...>::value, int>::type>
Closure(_Ty val)
{
callable_ = __closure_detail::ProxyCallable<_Ty, _Ret, _Args...>::Make(std::move(val));
if (callable_) callable_->AddRef();
}
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type>
Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
{
callable_ = __closure_detail::ProxyMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func);
if (callable_) callable_->AddRef();
}
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int>::type>
Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
{
callable_ = __closure_detail::ProxyConstMemCallable<_Ty, _Ret, _Args...>::Make(ptr, func);
if (callable_) callable_->AddRef();
}
~Closure()
{
tidy();
}
inline void swap(const Closure& rhs)
{
std::swap(callable_, rhs.callable_);
}
inline _Ret operator()(_Args... args) const
{
if (!callable_)
throw bad_function_call();
return callable_->Invoke(std::forward<_Args>(args)...);
}
inline operator bool() const
{
return !!callable_;
}
inline Closure& operator=(const Closure& rhs)
{
tidy();
callable_ = rhs.callable_;
if (callable_) callable_->AddRef();
return (*this);
}
inline Closure& operator=(Closure&& rhs)
{
tidy();
callable_ = rhs.callable_;
rhs.callable_ = nullptr;
return (*this);
}
private:
inline void tidy()
{
if (callable_)
{
callable_->Release();
callable_ = nullptr;
}
}
private:
__closure_detail::Callable<_Ret, _Args...>* callable_;
};
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type,
typename _Ret,
typename... _Args>
inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
{
return Closure<_Ret(_Args...)>(ptr, func);
}
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type,
typename _Ret,
typename... _Args>
inline Closure<_Ret(_Args...)> MakeClosure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
{
return Closure<_Ret(_Args...)>(ptr, func);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -19,8 +19,14 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "Array.hpp" #include "vector.hpp"
#include "String.hpp" #include "string.hpp"
#include "intrusive_list.hpp"
#include "intrusive_ptr.hpp"
#include "noncopyable.hpp"
#include "singleton.hpp"
#include "Function.hpp"
#include "basic_json.hpp"
#include <set> #include <set>
#include <map> #include <map>
#include <list> #include <list>
@ -30,26 +36,55 @@
namespace kiwano namespace kiwano
{ {
using String = kiwano::core::wstring;
using StringStream = std::wstringstream; using StringStream = std::wstringstream;
template<typename _Ty1, typename _Ty2> template <typename _Ty, typename... _Args>
using Pair = std::pair<_Ty1, _Ty2>; using Vector = kiwano::core::vector<_Ty, _Args...>;
template<typename _Ty, typename... _Args> template <typename _Ty, typename... _Args>
using List = std::list<_Ty, _Args...>; using List = std::list<_Ty, _Args...>;
template<typename _Ty, typename... _Args> template <typename _Ty, typename... _Args>
using Queue = std::queue<_Ty, _Args...>; using Queue = std::queue<_Ty, _Args...>;
template<typename _Ty, typename... _Args> template <typename _Ty, typename... _Args>
using Set = std::set<_Ty, _Args...>; using Set = std::set<_Ty, _Args...>;
template<typename _Ty, typename... _Args> template <typename _Ty1, typename _Ty2>
using Pair = std::pair<_Ty1, _Ty2>;
template <typename _Ty, typename... _Args>
using UnorderedSet = std::unordered_set<_Ty, _Args...>; using UnorderedSet = std::unordered_set<_Ty, _Args...>;
template<typename _Kty, typename _Ty, typename... _Args> template <typename _Kty, typename _Ty, typename... _Args>
using Map = std::map<_Kty, _Ty, _Args...>; using Map = std::map<_Kty, _Ty, _Args...>;
template<typename _Kty, typename _Ty, typename... _Args> template <typename _Kty, typename _Ty, typename... _Args>
using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>;
template <typename _FuncTy>
using Function = kiwano::core::function<_FuncTy>;
using Json = kiwano::core::basic_json<kiwano::Map, kiwano::Vector, kiwano::String,
std::int32_t, double, bool, std::allocator>;
}
namespace std
{
template<>
struct hash<::kiwano::Json>
{
::std::size_t operator()(const ::kiwano::Json& json) const
{
return hash<::kiwano::Json::string_type>{}(json.dump());
}
};
template<>
inline void swap<::kiwano::Json>(::kiwano::Json& lhs, ::kiwano::Json& rhs) noexcept
{
lhs.swap(rhs);
}
} }

View File

@ -0,0 +1,353 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <stdexcept>
#include <type_traits>
namespace kiwano
{
inline namespace core
{
//
// function is a light weight ::std::function<>-like class
//
namespace __function_detail
{
//
// is_callable
//
namespace __callable_detail
{
template <typename _Ty, typename _Ret, typename... _Args>
struct helper
{
template <typename _Uty> static int test(...);
template <typename _Uty, _Ret(_Uty::*)(_Args...)> struct class_mem;
template <typename _Uty> static char test(class_mem<_Uty, &_Uty::operator()>*);
template <typename _Uty, _Ret(_Uty::*)(_Args...) const> struct class_const_mem;
template <typename _Uty> static char test(class_const_mem<_Uty, &_Uty::operator()>*);
template<
typename _Uty,
typename _Uret = typename ::std::decay<decltype(::std::declval<_Uty>().operator()(::std::declval<_Args>()...))>::type,
typename = typename ::std::enable_if<::std::is_convertible<_Ret, _Uret>::value>::type>
static char test(int);
static constexpr bool value = sizeof(test<_Ty>(0)) == sizeof(char);
};
}
template<typename _Ty, typename _Ret, typename... _Args>
struct is_callable
: public ::std::bool_constant<__callable_detail::helper<_Ty, _Ret, _Args...>::value>
{
};
//
// callable
//
template<typename _Ret, typename... _Args>
class callable
{
public:
virtual ~callable() {}
virtual void AddRef() = 0;
virtual void Release() = 0;
virtual _Ret Invoke(_Args... args) const = 0;
};
template<typename _Ret, typename... _Args>
class ref_count_callable
: public callable<_Ret, _Args...>
{
public:
ref_count_callable() : ref_count_(0) {}
virtual void AddRef() override
{
++ref_count_;
}
virtual void Release() override
{
--ref_count_;
if (ref_count_ <= 0)
{
delete this;
}
}
private:
int ref_count_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class proxy_callable
: public ref_count_callable<_Ret, _Args...>
{
public:
proxy_callable(_Ty&& val)
: callee_(::std::move(val))
{
}
virtual _Ret Invoke(_Args... args) const override
{
return callee_(::std::forward<_Args&&>(args)...);
}
static inline callable<_Ret, _Args...>* Make(_Ty&& val)
{
return new (::std::nothrow) proxy_callable<_Ty, _Ret, _Args...>(::std::move(val));
}
private:
_Ty callee_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class proxy_mem_callable
: public ref_count_callable<_Ret, _Args...>
{
public:
typedef _Ret(_Ty::* _FuncType)(_Args...);
virtual _Ret Invoke(_Args... args) const override
{
return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...);
}
static inline callable<_Ret, _Args...>* Make(void* ptr, _FuncType func)
{
return new (::std::nothrow) proxy_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
}
protected:
proxy_mem_callable(void* ptr, _FuncType func)
: ptr_(ptr)
, func_(func)
{
}
protected:
void* ptr_;
_FuncType func_;
};
template<typename _Ty, typename _Ret, typename... _Args>
class proxy_const_mem_callable
: public ref_count_callable<_Ret, _Args...>
{
public:
typedef _Ret(_Ty::* _FuncType)(_Args...) const;
virtual _Ret Invoke(_Args... args) const override
{
return (static_cast<_Ty*>(ptr_)->*func_)(::std::forward<_Args>(args)...);
}
static inline callable<_Ret, _Args...>* Make(void* ptr, _FuncType func)
{
return new (::std::nothrow) proxy_const_mem_callable<_Ty, _Ret, _Args...>(ptr, func);
}
protected:
proxy_const_mem_callable(void* ptr, _FuncType func)
: ptr_(ptr)
, func_(func)
{
}
protected:
void* ptr_;
_FuncType func_;
};
}
//
// exceptions
//
class bad_function_call : public ::std::exception
{
public:
bad_function_call() {}
virtual const char* what() const override
{
return "bad function call";
}
};
//
// function details
//
template<typename _Ty>
class function;
template<typename _Ret, typename... _Args>
class function<_Ret(_Args...)>
{
public:
function()
: callable_(nullptr)
{
}
function(::std::nullptr_t)
: callable_(nullptr)
{
}
function(const function& rhs)
: callable_(rhs.callable_)
{
if (callable_) callable_->AddRef();
}
function(function&& rhs) noexcept
: callable_(rhs.callable_)
{
rhs.callable_ = nullptr;
}
function(_Ret(*func)(_Args...))
{
callable_ = __function_detail::proxy_callable<_Ret(*)(_Args...), _Ret, _Args...>::Make(::std::move(func));
if (callable_) callable_->AddRef();
}
template<
typename _Ty,
typename = typename ::std::enable_if<__function_detail::is_callable<_Ty, _Ret, _Args...>::value, int>::type>
function(_Ty val)
{
callable_ = __function_detail::proxy_callable<_Ty, _Ret, _Args...>::Make(::std::move(val));
if (callable_) callable_->AddRef();
}
template<typename _Ty,
typename _Uty,
typename = typename ::std::enable_if<::std::is_same<_Ty, _Uty>::value || ::std::is_base_of<_Ty, _Uty>::value, int>::type>
function(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
{
callable_ = __function_detail::proxy_mem_callable<_Ty, _Ret, _Args...>::Make(ptr, func);
if (callable_) callable_->AddRef();
}
template<typename _Ty,
typename _Uty,
typename = typename ::std::enable_if<::std::is_same<_Ty, _Uty>::value || ::std::is_base_of<_Ty, _Uty>::value, int>::type>
function(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
{
callable_ = __function_detail::proxy_const_mem_callable<_Ty, _Ret, _Args...>::Make(ptr, func);
if (callable_) callable_->AddRef();
}
~function()
{
tidy();
}
inline void swap(const function& rhs)
{
::std::swap(callable_, rhs.callable_);
}
inline _Ret operator()(_Args... args) const
{
if (!callable_)
throw bad_function_call();
return callable_->Invoke(::std::forward<_Args>(args)...);
}
inline operator bool() const
{
return !!callable_;
}
inline function& operator=(const function& rhs)
{
tidy();
callable_ = rhs.callable_;
if (callable_) callable_->AddRef();
return (*this);
}
inline function& operator=(function&& rhs)
{
tidy();
callable_ = rhs.callable_;
rhs.callable_ = nullptr;
return (*this);
}
private:
inline void tidy()
{
if (callable_)
{
callable_->Release();
callable_ = nullptr;
}
}
private:
__function_detail::callable<_Ret, _Args...>* callable_;
};
} // inline namespace core
} // namespace kiwano
namespace kiwano
{
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type,
typename _Ret,
typename... _Args>
inline function<_Ret(_Args...)> bind_func(_Uty* ptr, _Ret(_Ty::* func)(_Args...))
{
return function<_Ret(_Args...)>(ptr, func);
}
template<typename _Ty,
typename _Uty,
typename = typename std::enable_if<
std::is_same<_Ty, _Uty>::value || std::is_base_of<_Ty, _Uty>::value, int
>::type,
typename _Ret,
typename... _Args>
inline function<_Ret(_Args...)> bind_func(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const)
{
return function<_Ret(_Args...)>(ptr, func);
}
}

View File

@ -0,0 +1,261 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "../macros.h"
// #define KGE_DEBUG_ENABLE_LIST_CHECK
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
# define KGE_DEBUG_CHECK_LIST(list_ptr) list_ptr->check_list()
#else
# define KGE_DEBUG_CHECK_LIST __noop
#endif
namespace kiwano
{
inline namespace core
{
template <typename T> class intrusive_list;
template <typename T>
class intrusive_list_item
{
T prev_;
T next_;
template <typename U>
friend class intrusive_list;
public:
using ItemType = T;
intrusive_list_item() : prev_(), next_() {}
T const& prev_item() const { return prev_; }
T& prev_item() { return prev_; }
T const& next_item() const { return next_; }
T& next_item() { return next_; }
};
template <typename T>
class intrusive_list
{
T first_;
T last_;
public:
using ItemType = T;
intrusive_list() : first_(), last_() {}
~intrusive_list() { clear_items(); }
T const& first_item() const { return first_; }
T& first_item() { return first_; }
T const& last_item() const { return last_; }
T& last_item() { return last_; }
bool is_empty() const { return !first_; }
void push_back_item(T const& child)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
child->prev_ = last_;
child->next_ = nullptr;
if (first_)
{
last_->next_ = child;
}
else
{
first_ = child;
}
last_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void push_front_item(T const& child)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
child->prev_ = nullptr;
child->next_ = first_;
if (first_)
{
first_->prev_ = child;
}
else
{
last_ = child;
}
first_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void insert_before(T const& child, T const& before)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
if (before->prev_)
before->prev_->next_ = child;
else
first_ = child;
child->prev_ = before->prev_;
child->next_ = before;
before->prev_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void insert_after(T const& child, T const& after)
{
if (child->prev_)
child->prev_->next_ = child->next_;
if (child->next_)
child->next_->prev_ = child->prev_;
if (after->next_)
after->next_->prev_ = child;
else
last_ = child;
child->next_ = after->next_;
child->prev_ = after;
after->next_ = child;
KGE_DEBUG_CHECK_LIST(this);
}
void remove_item(T const& child)
{
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
T tmp = first_;
while (tmp != child)
{
KGE_ASSERT((tmp != last_) && "The actor to be removed is not in this list");
tmp = tmp->next_;
}
#endif
if (child->next_)
{
child->next_->prev_ = child->prev_;
}
else
{
last_ = child->prev_;
}
if (child->prev_)
{
child->prev_->next_ = child->next_;
}
else
{
first_ = child->next_;
}
child->prev_ = nullptr;
child->next_ = nullptr;
KGE_DEBUG_CHECK_LIST(this);
}
void clear_items()
{
T p = first_;
while (p)
{
T tmp = p;
p = p->next_;
if (tmp)
{
tmp->next_ = nullptr;
tmp->prev_ = nullptr;
}
}
first_ = nullptr;
last_ = nullptr;
}
#ifdef KGE_DEBUG_ENABLE_LIST_CHECK
private:
void check_list()
{
if (!first_)
return;
int pos = 0;
T p = first_;
T tmp = p;
do
{
tmp = p;
p = p->next_;
++pos;
if (p)
{
KGE_ASSERT(p->prev_ == tmp && "Check list failed");
}
else
{
KGE_ASSERT(tmp == last_ && "Check list failed");
}
} while (p);
}
#endif
};
} // inline namespace core
} // namespace kiwano
#undef KGE_DEBUG_CHECK_LIST
#undef KGE_DEBUG_ENABLE_LIST_CHECK

View File

@ -0,0 +1,222 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining lhs copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "../macros.h"
#include <utility>
#include <type_traits>
namespace kiwano
{
inline namespace core
{
template <typename _Ty, typename _ManagerTy>
class intrusive_ptr
{
public:
using value_type = _Ty;
using pointer_type = _Ty*;
using const_pointer_type = const _Ty*;
using manager_type = _ManagerTy;
intrusive_ptr() noexcept {}
intrusive_ptr(nullptr_t) noexcept {}
intrusive_ptr(pointer_type p) noexcept : ptr_(p)
{
typename manager_type::AddRef(ptr_);
}
intrusive_ptr(const_pointer_type p) noexcept : ptr_(p)
{
typename manager_type::AddRef(ptr_);
}
intrusive_ptr(const intrusive_ptr& other) noexcept
: ptr_(other.ptr_)
{
typename manager_type::AddRef(ptr_);
}
template <typename _UTy>
intrusive_ptr(const intrusive_ptr<_UTy, manager_type>& other) noexcept
: ptr_(other.get())
{
typename manager_type::AddRef(ptr_);
}
intrusive_ptr(intrusive_ptr&& other) noexcept
{
ptr_ = other.ptr_;
other.ptr_ = nullptr;
}
~intrusive_ptr() noexcept
{
typename manager_type::Release(ptr_);
}
inline pointer_type get() const noexcept { return ptr_; }
inline void reset() noexcept
{
intrusive_ptr{}.swap(*this);
}
inline void swap(intrusive_ptr& other) noexcept
{
std::swap(ptr_, other.ptr_);
}
inline pointer_type operator ->() const
{
KGE_ASSERT(ptr_ != nullptr && "Invalid pointer");
return ptr_;
}
inline value_type& operator *() const
{
KGE_ASSERT(ptr_ != nullptr && "Invalid pointer");
return *ptr_;
}
inline pointer_type* operator &()
{
KGE_ASSERT(ptr_ == nullptr && "Memory leak");
return &ptr_;
}
inline operator bool() const noexcept { return ptr_ != nullptr; }
inline bool operator !() const noexcept { return ptr_ == 0; }
inline intrusive_ptr& operator =(const intrusive_ptr& other) noexcept
{
if (other.ptr_ != ptr_)
intrusive_ptr(other).swap(*this);
return *this;
}
inline intrusive_ptr& operator =(intrusive_ptr&& other) noexcept
{
typename manager_type::Release(ptr_);
ptr_ = other.ptr_;
other.ptr_ = nullptr;
return *this;
}
inline intrusive_ptr& operator =(pointer_type p) noexcept
{
if (p != ptr_)
intrusive_ptr(p).swap(*this);
return *this;
}
inline intrusive_ptr& operator =(nullptr_t) noexcept
{
if (nullptr != ptr_)
intrusive_ptr{}.swap(*this);
return *this;
}
private:
pointer_type ptr_{ nullptr };
};
template <class _Ty, class _UTy, class manager_type>
inline bool operator==(intrusive_ptr<_Ty, manager_type> const& lhs, intrusive_ptr<_UTy, manager_type> const& rhs) noexcept
{
return lhs.get() == rhs.get();
}
template <class _Ty, class _UTy, class manager_type>
inline bool operator!=(intrusive_ptr<_Ty, manager_type> const& lhs, intrusive_ptr<_UTy, manager_type> const& rhs) noexcept
{
return lhs.get() != rhs.get();
}
template <class _Ty, class _UTy, class manager_type>
inline bool operator<(intrusive_ptr<_Ty, manager_type> const& lhs, intrusive_ptr<_UTy, manager_type> const& rhs) noexcept
{
return lhs.get() < rhs.get();
}
template <class _Ty, class manager_type>
inline bool operator==(intrusive_ptr<_Ty, manager_type> const& lhs, _Ty* rhs) noexcept
{
return lhs.get() == rhs;
}
template <class _Ty, class manager_type>
inline bool operator!=(intrusive_ptr<_Ty, manager_type> const& lhs, _Ty* rhs) noexcept
{
return lhs.get() != rhs;
}
template <class _Ty, class manager_type>
inline bool operator==(_Ty* lhs, intrusive_ptr<_Ty, manager_type> const& rhs) noexcept
{
return lhs == rhs.get();
}
template <class _Ty, class manager_type>
inline bool operator!=(_Ty* lhs, intrusive_ptr<_Ty, manager_type> const& rhs) noexcept
{
return lhs != rhs.get();
}
template <class _Ty, class manager_type>
inline bool operator==(intrusive_ptr<_Ty, manager_type> const& lhs, nullptr_t) noexcept
{
return !static_cast<bool>(lhs);
}
template <class _Ty, class manager_type>
inline bool operator!=(intrusive_ptr<_Ty, manager_type> const& lhs, nullptr_t) noexcept
{
return static_cast<bool>(lhs);
}
template <class _Ty, class manager_type>
inline bool operator==(nullptr_t, intrusive_ptr<_Ty, manager_type> const& rhs) noexcept
{
return !static_cast<bool>(rhs);
}
template <class _Ty, class manager_type>
inline bool operator!=(nullptr_t, intrusive_ptr<_Ty, manager_type> const& rhs) noexcept
{
return static_cast<bool>(rhs);
}
// template class cannot specialize std::swap,
// so implement a swap Function in kiwano namespace
template <class _Ty, class manager_type>
inline void swap(intrusive_ptr<_Ty, manager_type>& lhs, intrusive_ptr<_Ty, manager_type>& rhs) noexcept
{
lhs.swap(rhs);
}
} // inline namespace core
} // namespace kiwano

View File

@ -22,14 +22,19 @@
namespace kiwano namespace kiwano
{ {
class Noncopyable inline namespace core
{ {
protected:
Noncopyable() = default;
private: class noncopyable
Noncopyable(const Noncopyable&) = delete; {
protected:
noncopyable() = default;
Noncopyable& operator=(const Noncopyable&) = delete; private:
}; noncopyable(const noncopyable&) = delete;
}
noncopyable& operator=(const noncopyable&) = delete;
};
} // inline namespace core
} // namespace kiwano

View File

@ -33,48 +33,53 @@
namespace kiwano namespace kiwano
{ {
template <typename _Ty> inline namespace core
struct Singleton {
template <typename _Ty>
struct Singleton
{
public:
static inline _Ty* GetInstance()
{ {
public: if (!instance_)
static inline _Ty* GetInstance()
{ {
if (!instance_) std::call_once(once_, InitInstance);
{
std::call_once(once_, InitInstance);
}
return instance_.get();
} }
return instance_.get();
}
static inline void InitInstance() static inline void DestroyInstance()
{
instance_.reset();
}
protected:
Singleton() = default;
private:
Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete;
static inline void InitInstance()
{
if (!instance_)
{ {
if (!instance_) instance_.reset(new (std::nothrow) _Ty);
{
instance_.reset(new (std::nothrow) _Ty);
}
} }
}
static inline void DestroyInstance() private:
{ static std::once_flag once_;
instance_.reset(); static std::unique_ptr<_Ty> instance_;
} };
protected: template <typename _Ty>
Singleton() = default; std::once_flag Singleton<_Ty>::once_;
private: template <typename _Ty>
Singleton(const Singleton&) = delete; std::unique_ptr<_Ty> Singleton<_Ty>::instance_;
Singleton& operator=(const Singleton&) = delete; } // inline namespace core
} // namespace kiwano
private:
static std::once_flag once_;
static std::unique_ptr<_Ty> instance_;
};
template <typename _Ty>
std::once_flag Singleton<_Ty>::once_;
template <typename _Ty>
std::unique_ptr<_Ty> Singleton<_Ty>::instance_;
}

1741
src/kiwano/core/string.hpp Normal file

File diff suppressed because it is too large Load Diff

288
src/kiwano/core/vector.hpp Normal file
View File

@ -0,0 +1,288 @@
// Copyright (c) 2016-2018 Kiwano - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include <memory>
#include <type_traits>
#include <exception>
namespace kiwano
{
inline namespace core
{
//
// ArrayManager<> with memory operations
//
namespace __vector_details
{
template<typename _Ty, typename _Alloc, bool _IsClassType = std::is_class<_Ty>::value>
struct vector_memory_manager;
}
//
// vector<>
// Lightweight std::vector<>-like class
//
template<
typename _Ty,
typename _Alloc = std::allocator<_Ty>,
typename _Manager = __vector_details::vector_memory_manager<_Ty, _Alloc>>
class vector
{
public:
using value_type = _Ty;
using size_type = std::size_t;
using iterator = value_type * ;
using const_iterator = const value_type*;
using reference = value_type & ;
using const_reference = const value_type &;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using allocator_type = typename _Alloc;
using manager = typename _Manager;
using initializer_list = std::initializer_list<value_type>;
public:
inline vector() : size_(0), capacity_(0), data_(nullptr) { }
inline vector(size_type count) : vector() { reserve(count); }
inline vector(size_type count, const _Ty& val) : vector() { assign(count, val); }
inline vector(initializer_list list) : vector() { assign(list); }
inline vector(const vector& src) : vector() { assign(src); }
inline vector(vector&& src) noexcept : vector() { swap(src); }
inline ~vector() { destroy(); }
template <typename _Iter>
inline vector(_Iter first, _Iter last) : vector() { assign(first, last); }
inline vector& operator=(const vector& src) { if (&src != this) { resize(src.size_); manager::copy_data(begin(), src.cbegin(), size_); } return (*this); }
inline vector& operator=(vector&& src) noexcept { swap(src); return *this; }
inline vector& operator=(initializer_list list) { if (list.size()) { assign(list.begin(), list.end()); } else clear(); return (*this); }
inline vector& assign(size_type count, const _Ty& val) { if (count > 0) { resize(count); manager::copy_data(begin(), count, val); } else clear(); return (*this); }
inline vector& assign(const vector& src) { return operator=(src); }
inline vector& assign(initializer_list list) { return operator=(list); }
template <typename _Iter>
inline void assign(_Iter first, _Iter last) { auto diff = std::distance(first, last); resize((size_type)diff); auto data = begin(); while (first != last) (*data++) = (*first++); }
inline void clear() { destroy(); size_ = capacity_ = 0; data_ = nullptr; }
inline void swap(vector& rhs) noexcept { std::swap(size_, rhs.size_); std::swap(capacity_, rhs.capacity_); std::swap(data_, rhs.data_); }
inline void resize(size_type new_size) { resize(new_size, _Ty()); }
void resize(size_type new_size, const _Ty& v);
void reserve(size_type new_capacity);
inline void push_back(const _Ty& val) { resize(size_ + 1, val); }
inline void pop_back() { if (empty()) throw std::out_of_range("pop() called on empty vector"); resize(size_ - 1); }
inline void push_front(const _Ty& val) { if (size_ == 0) push_back(val); else insert(begin(), val); }
inline iterator erase(const_iterator where) { return erase(where, where + 1); }
iterator erase(const_iterator first, const_iterator last);
iterator insert(const_iterator where, const _Ty& v);
inline bool empty() const { return size_ == 0; }
inline size_type size() const { return size_; }
inline size_type size_in_bytes() const { return size_ * ((size_type)sizeof(_Ty)); }
inline size_type capacity() const { return capacity_; }
inline reference operator[](size_type off) { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
inline const_reference operator[](size_type off) const { if (off < 0 || off >= size_) throw std::out_of_range("vector subscript out of range"); return data_[off]; }
inline bool contains(const _Ty& v) const { auto data = cbegin(); const auto data_end = cend(); while (data != data_end) if (*(data++) == v) return true; return false; }
inline size_type index_of(const_iterator it) const { check_offset(it - cbegin(), "invalid array position"); return it - data_; }
inline iterator begin() { return iterator(data_); }
inline const_iterator begin() const { return const_iterator(data_); }
inline const_iterator cbegin() const { return begin(); }
inline iterator end() { return iterator(data_ + size_); }
inline const_iterator end() const { return const_iterator(data_ + size_); }
inline const_iterator cend() const { return end(); }
inline reverse_iterator rbegin() { return reverse_iterator(end()); }
inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
inline const_reverse_iterator crbegin() const { return rbegin(); }
inline reverse_iterator rend() { return reverse_iterator(begin()); }
inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
inline const_reverse_iterator crend() const { return rend(); }
inline reference front() { if (empty()) throw std::out_of_range("front() called on empty array"); return data_[0]; }
inline const_reference front() const { if (empty()) throw std::out_of_range("front() called on empty array"); return data_[0]; }
inline reference back() { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; }
inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; }
private:
inline size_type grow_capacity(size_type sz) const { size_type new_capacity = capacity_ ? (capacity_ + capacity_ / 2) : 8; return new_capacity > sz ? new_capacity : sz; }
inline void check_offset(const size_type off) const { if (off < 0 || off >= size_) throw std::out_of_range("invalid vector position"); }
inline void destroy() { manager::destroy(data_, size_); manager::deallocate(data_, capacity_); }
protected:
size_type size_;
size_type capacity_;
_Ty* data_;
};
template<typename _Ty, typename _Alloc, typename _Manager>
void vector<_Ty, _Alloc, _Manager>::resize(size_type new_size, const _Ty& val)
{
if (new_size > size_)
{
if (new_size > capacity_)
{
reserve(grow_capacity(new_size));
}
manager::construct(begin() + size_, new_size - size_, val);
}
else
{
manager::destroy(begin() + new_size, size_ - new_size);
}
size_ = new_size;
}
template<typename _Ty, typename _Alloc, typename _Manager>
void vector<_Ty, _Alloc, _Manager>::reserve(size_type new_capacity)
{
if (new_capacity <= capacity_)
return;
auto new_data = manager::allocate(new_capacity);
if (data_)
{
manager::construct(new_data, size_/* only construct needed size */);
manager::copy_data(new_data, data_, size_);
/* destroy old memory, but not resize */
destroy();
}
data_ = new_data;
capacity_ = new_capacity;
}
template<typename _Ty, typename _Alloc, typename _Manager>
typename vector<_Ty, _Alloc, _Manager>::iterator
vector<_Ty, _Alloc, _Manager>::erase(const_iterator first, const_iterator last)
{
const auto off = first - begin();
const auto count = last - first;
if (count != 0)
{
check_offset(off);
manager::move_data(begin() + off, begin() + off + count, size_ - off - count);
resize(size_ - count); // do destruction
}
return begin() + off;
}
template<typename _Ty, typename _Alloc, typename _Manager>
typename vector<_Ty, _Alloc, _Manager>::iterator
vector<_Ty, _Alloc, _Manager>::insert(const_iterator where, const _Ty& v)
{
const auto off = where - begin();
const auto insert_at = begin() + off;
check_offset(off);
resize(size_ + 1);
manager::move_data(insert_at + 1, insert_at, size_ - off - 1);
data_[off] = v;
return begin() + off;
}
namespace __vector_details
{
//
// ArrayManager for core type
//
template<typename _Ty, typename _Alloc>
struct vector_memory_manager<_Ty, _Alloc, false>
{
using value_type = _Ty;
using size_type = size_t;
using allocator_type = typename _Alloc;
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memcpy(dest, src, (size_t)count * sizeof(value_type)); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { ::memset(dest, (int)val, (size_t)count * sizeof(value_type)); }
static void move_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; ::memmove(dest, src, (size_t)count * sizeof(value_type)); }
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static void construct(value_type* ptr, size_type count) { }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) { --count; *(ptr + count) = val; } }
static void destroy(value_type* ptr, size_type count) { }
private:
static allocator_type& get_allocator()
{
static allocator_type allocator_;
return allocator_;
}
};
//
// ArrayManager for class
//
template<typename _Ty, typename _Alloc>
struct vector_memory_manager<_Ty, _Alloc, true>
{
using value_type = _Ty;
using size_type = size_t;
using allocator_type = typename _Alloc;
static void copy_data(value_type* dest, const value_type* src, size_type count) { if (src == dest) return; while (count--) (*dest++) = (*src++); }
static void copy_data(value_type* dest, size_type count, const value_type& val) { while (count--) (*dest++) = val; }
static void move_data(value_type* dest, const value_type* src, size_type count)
{
if (src == dest) return;
if (dest > src && dest < src + count)
{
src = src + count - 1;
dest = dest + count - 1;
while (count--)
(*dest--) = (*src--);
}
else
{
while (count--)
(*dest++) = (*src++);
}
}
static value_type* allocate(size_type count) { return get_allocator().allocate(count); }
static void deallocate(value_type*& ptr, size_type count) { if (ptr) { get_allocator().deallocate(ptr, count); ptr = nullptr; } }
static void construct(value_type* ptr, size_type count) { construct(ptr, count, value_type()); }
static void construct(value_type* ptr, size_type count, const value_type& val) { while (count) get_allocator().construct(ptr + (--count), val); }
static void destroy(value_type* ptr, size_type count) { while (count) get_allocator().destroy(ptr + (--count)); }
private:
static allocator_type& get_allocator()
{
static allocator_type allocator_;
return allocator_;
}
};
}
} // inline namespace core
} // namespace kiwano

View File

@ -29,19 +29,18 @@
// //
// common // core
// //
#include "common/Array.hpp" #include "core/vector.hpp"
#include "common/String.hpp" #include "core/string.hpp"
#include "common/helper.h" #include "core/core.h"
#include "common/Closure.hpp" #include "core/Function.hpp"
#include "common/IntrusiveList.hpp" #include "core/intrusive_list.hpp"
#include "common/IntrusivePtr.hpp" #include "core/intrusive_ptr.hpp"
#include "common/ComPtr.hpp" #include "core/noncopyable.hpp"
#include "common/Noncopyable.hpp" #include "core/singleton.hpp"
#include "common/Singleton.hpp" #include "core/basic_json.hpp"
#include "common/Json.hpp"
// //
@ -70,6 +69,9 @@
#include "base/Director.h" #include "base/Director.h"
#include "base/logs.h" #include "base/logs.h"
#include "base/SmartPtr.hpp"
#include "base/ComPtr.hpp"
#include "base/Object.h" #include "base/Object.h"
#include "base/Event.hpp" #include "base/Event.hpp"
#include "base/EventListener.h" #include "base/EventListener.h"

View File

@ -99,7 +99,7 @@ namespace kiwano
inline value_type GetBottom() const { return origin.y + size.y; } inline value_type GetBottom() const { return origin.y + size.y; }
inline bool IsEmpty() const { return origin.IsOrigin() && size.IsOrigin(); } inline bool is_empty() const { return origin.IsOrigin() && size.IsOrigin(); }
inline bool ContainsPoint(const Vec2T<value_type>& point) const inline bool ContainsPoint(const Vec2T<value_type>& point) const
{ {

View File

@ -36,7 +36,7 @@ namespace kiwano
{ {
namespace namespace
{ {
using FunctionToPerform = Closure<void()>; using FunctionToPerform = Function<void()>;
std::mutex perform_mutex_; std::mutex perform_mutex_;
Queue<FunctionToPerform> functions_to_perform_; Queue<FunctionToPerform> functions_to_perform_;
@ -123,7 +123,7 @@ namespace kiwano
{ {
HWND hwnd = Window::GetInstance()->GetHandle(); HWND hwnd = Window::GetInstance()->GetHandle();
if (!hwnd) if (!inited_)
throw std::exception("Calling Application::Run before Application::Init"); throw std::exception("Calling Application::Run before Application::Init");
if (hwnd) if (hwnd)
@ -147,6 +147,9 @@ namespace kiwano
void Application::Destroy() void Application::Destroy()
{ {
// Clear all stages
Director::GetInstance()->ClearStages();
if (inited_) if (inited_)
{ {
inited_ = false; inited_ = false;
@ -159,8 +162,8 @@ namespace kiwano
} }
// Destroy all instances // Destroy all instances
ResourceCache::DestroyInstance();
Director::DestroyInstance(); Director::DestroyInstance();
ResourceCache::DestroyInstance();
Input::DestroyInstance(); Input::DestroyInstance();
Renderer::DestroyInstance(); Renderer::DestroyInstance();
Window::DestroyInstance(); Window::DestroyInstance();
@ -284,10 +287,10 @@ namespace kiwano
} }
} }
void Application::PreformInMainThread(Closure<void()> function) void Application::PreformInMainThread(Function<void()> Function)
{ {
std::lock_guard<std::mutex> lock(perform_mutex_); std::lock_guard<std::mutex> lock(perform_mutex_);
functions_to_perform_.push(function); functions_to_perform_.push(Function);
} }
LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)

View File

@ -19,10 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../common/String.hpp" #include "../core/core.h"
#include "../common/Array.hpp"
#include "../common/Closure.hpp"
#include "../common/Noncopyable.hpp"
#include "../base/time.h" #include "../base/time.h"
#include "../base/Component.h" #include "../base/Component.h"
#include "../base/Event.hpp" #include "../base/Event.hpp"
@ -56,7 +53,7 @@ namespace kiwano
// 应用 // 应用
class KGE_API Application class KGE_API Application
: protected Noncopyable : protected noncopyable
{ {
public: public:
Application(); Application();
@ -107,7 +104,7 @@ namespace kiwano
// 在 Kiwano 主线程中执行函数 // 在 Kiwano 主线程中执行函数
// 当在其他线程调用 Kiwano 函数时使用 // 当在其他线程调用 Kiwano 函数时使用
static void PreformInMainThread( static void PreformInMainThread(
Closure<void()> function Function<void()> Function
); );
protected: protected:
@ -122,6 +119,6 @@ namespace kiwano
bool inited_; bool inited_;
float time_scale_; float time_scale_;
Array<Component*> components_; Vector<Component*> components_;
}; };
} }

View File

@ -176,17 +176,17 @@ namespace kiwano
{ {
ImageCache::GetInstance()->Clear(); ImageCache::GetInstance()->Clear();
factory_.Reset(); factory_.reset();
device_.Reset(); device_.reset();
device_context_.Reset(); device_context_.reset();
target_bitmap_.Reset(); target_bitmap_.reset();
imaging_factory_.Reset(); imaging_factory_.reset();
dwrite_factory_.Reset(); dwrite_factory_.reset();
d2d_miter_stroke_style_.Reset(); d2d_miter_stroke_style_.reset();
d2d_bevel_stroke_style_.Reset(); d2d_bevel_stroke_style_.reset();
d2d_round_stroke_style_.Reset(); d2d_round_stroke_style_.reset();
} }
HRESULT D2DDeviceResources::CreateDeviceIndependentResources() HRESULT D2DDeviceResources::CreateDeviceIndependentResources()
@ -315,7 +315,7 @@ namespace kiwano
{ {
target_bitmap_ = target; target_bitmap_ = target;
if (device_context_) if (device_context_)
device_context_->SetTarget(target_bitmap_.Get()); device_context_->SetTarget(target_bitmap_.get());
} }
HRESULT D2DDeviceResources::CreateBitmapFromFile(_Out_ ComPtr<ID2D1Bitmap> & bitmap, _In_ String const & file_path) HRESULT D2DDeviceResources::CreateBitmapFromFile(_Out_ ComPtr<ID2D1Bitmap> & bitmap, _In_ String const & file_path)
@ -357,7 +357,7 @@ namespace kiwano
{ {
// 图片格式转换成 32bppPBGRA // 图片格式转换成 32bppPBGRA
hr = converter->Initialize( hr = converter->Initialize(
source.Get(), source.get(),
GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, WICBitmapDitherTypeNone,
nullptr, nullptr,
@ -369,7 +369,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = device_context_->CreateBitmapFromWicBitmap( hr = device_context_->CreateBitmapFromWicBitmap(
converter.Get(), converter.get(),
nullptr, nullptr,
&bitmap_tmp &bitmap_tmp
); );
@ -414,7 +414,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = imaging_factory_->CreateDecoderFromStream( hr = imaging_factory_->CreateDecoderFromStream(
stream.Get(), stream.get(),
nullptr, nullptr,
WICDecodeMetadataCacheOnLoad, WICDecodeMetadataCacheOnLoad,
&decoder &decoder
@ -435,7 +435,7 @@ namespace kiwano
{ {
// 图片格式转换成 32bppPBGRA // 图片格式转换成 32bppPBGRA
hr = converter->Initialize( hr = converter->Initialize(
source.Get(), source.get(),
GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, WICBitmapDitherTypeNone,
nullptr, nullptr,
@ -447,7 +447,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = device_context_->CreateBitmapFromWicBitmap( hr = device_context_->CreateBitmapFromWicBitmap(
converter.Get(), converter.get(),
nullptr, nullptr,
&bitmap_tmp &bitmap_tmp
); );
@ -517,7 +517,7 @@ namespace kiwano
hr = dwrite_factory_->CreateTextLayout( hr = dwrite_factory_->CreateTextLayout(
text.c_str(), text.c_str(),
length, length,
text_format.Get(), text_format.get(),
text_style.wrap_width, text_style.wrap_width,
0, 0,
&text_layout_tmp &text_layout_tmp
@ -528,7 +528,7 @@ namespace kiwano
hr = dwrite_factory_->CreateTextLayout( hr = dwrite_factory_->CreateTextLayout(
text.c_str(), text.c_str(),
length, length,
text_format.Get(), text_format.get(),
0, 0,
0, 0,
&text_layout_tmp &text_layout_tmp
@ -546,7 +546,7 @@ namespace kiwano
hr = dwrite_factory_->CreateTextLayout( hr = dwrite_factory_->CreateTextLayout(
text.c_str(), text.c_str(),
length, length,
text_format.Get(), text_format.get(),
metrics.width, metrics.width,
0, 0,
&text_layout_tmp &text_layout_tmp
@ -586,9 +586,9 @@ namespace kiwano
{ {
switch (stroke) switch (stroke)
{ {
case StrokeStyle::Miter: return d2d_miter_stroke_style_.Get(); break; case StrokeStyle::Miter: return d2d_miter_stroke_style_.get(); break;
case StrokeStyle::Bevel: return d2d_bevel_stroke_style_.Get(); break; case StrokeStyle::Bevel: return d2d_bevel_stroke_style_.get(); break;
case StrokeStyle::Round: return d2d_round_stroke_style_.Get(); break; case StrokeStyle::Round: return d2d_round_stroke_style_.get(); break;
} }
return nullptr; return nullptr;
} }

View File

@ -72,12 +72,12 @@ namespace kiwano
virtual void DiscardResources() = 0; virtual void DiscardResources() = 0;
inline ID2D1Factory1* GetFactory() const { KGE_ASSERT(factory_); return factory_.Get(); } inline ID2D1Factory1* GetFactory() const { KGE_ASSERT(factory_); return factory_.get(); }
inline IWICImagingFactory* GetWICImagingFactory() const { KGE_ASSERT(imaging_factory_); return imaging_factory_.Get(); } inline IWICImagingFactory* GetWICImagingFactory() const { KGE_ASSERT(imaging_factory_); return imaging_factory_.get(); }
inline IDWriteFactory* GetDWriteFactory() const { KGE_ASSERT(dwrite_factory_); return dwrite_factory_.Get(); } inline IDWriteFactory* GetDWriteFactory() const { KGE_ASSERT(dwrite_factory_); return dwrite_factory_.get(); }
inline ID2D1Device* GetDevice() const { KGE_ASSERT(device_); return device_.Get(); } inline ID2D1Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); }
inline ID2D1DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.Get(); } inline ID2D1DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); }
inline ID2D1Bitmap1* GetTargetBitmap() const { KGE_ASSERT(target_bitmap_); return target_bitmap_.Get(); } inline ID2D1Bitmap1* GetTargetBitmap() const { KGE_ASSERT(target_bitmap_); return target_bitmap_.get(); }
protected: protected:
ComPtr<ID2D1Factory1> factory_; ComPtr<ID2D1Factory1> factory_;

View File

@ -188,20 +188,20 @@ namespace kiwano
{ {
KGE_ASSERT(device_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr); KGE_ASSERT(device_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr);
auto rt_view = rt_view_.Get(); auto rt_view = rt_view_.get();
device_->OMSetRenderTargets(1, &rt_view, ds_view_.Get()); device_->OMSetRenderTargets(1, &rt_view, ds_view_.get());
device_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color)); device_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color));
return S_OK; return S_OK;
} }
void D3D10DeviceResources::DiscardResources() void D3D10DeviceResources::DiscardResources()
{ {
d2d_res_.Reset(); d2d_res_.reset();
device_.Reset(); device_.reset();
rt_view_.Reset(); rt_view_.reset();
ds_view_.Reset(); ds_view_.reset();
dxgi_swap_chain_.Reset(); dxgi_swap_chain_.reset();
dxgi_factory_.Reset(); dxgi_factory_.reset();
hwnd_ = nullptr; hwnd_ = nullptr;
} }
@ -261,7 +261,7 @@ namespace kiwano
// Create the Direct2D device object and a corresponding context. // Create the Direct2D device object and a corresponding context.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = d2d_res_->GetFactory()->CreateDevice(dxgi_device.Get(), &d2d_device); hr = d2d_res_->GetFactory()->CreateDevice(dxgi_device.get(), &d2d_device);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -310,7 +310,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = dxgi_factory->CreateSwapChain( hr = dxgi_factory->CreateSwapChain(
device_.Get(), device_.get(),
&swap_chain_desc, &swap_chain_desc,
&dxgi_swap_chain_); &dxgi_swap_chain_);
} }
@ -367,7 +367,7 @@ namespace kiwano
renderDesc.Texture2D.MipSlice = 0; renderDesc.Texture2D.MipSlice = 0;
rt_view_ = nullptr; rt_view_ = nullptr;
hr = device_->CreateRenderTargetView(dxgi_back_buffer.Get(), &renderDesc, &rt_view_); hr = device_->CreateRenderTargetView(dxgi_back_buffer.get(), &renderDesc, &rt_view_);
} }
} }
@ -397,14 +397,14 @@ namespace kiwano
desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; desc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
desc.Texture2D.MipSlice = 0; desc.Texture2D.MipSlice = 0;
ds_view_.Reset(); ds_view_.reset();
hr = device_->CreateDepthStencilView(depth_stencil.Get(), &desc, &ds_view_); hr = device_->CreateDepthStencilView(depth_stencil.get(), &desc, &ds_view_);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
ID3D10RenderTargetView* main_view = rt_view_.Get(); ID3D10RenderTargetView* main_view = rt_view_.get();
device_->OMSetRenderTargets(1, &main_view, ds_view_.Get()); device_->OMSetRenderTargets(1, &main_view, ds_view_.get());
} }
} }
@ -433,7 +433,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface( hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface(
dxgi_back_buffer.Get(), dxgi_back_buffer.get(),
D2D1::BitmapProperties1( D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),

View File

@ -35,11 +35,11 @@ namespace kiwano
public: public:
static HRESULT Create(ID3D10DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd); static HRESULT Create(ID3D10DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd);
inline ID3D10Device* GetDevice() const { KGE_ASSERT(device_); return device_.Get(); } inline ID3D10Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); }
inline ID3D10RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.Get(); } inline ID3D10RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.get(); }
inline ID3D10DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.Get(); } inline ID3D10DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.get(); }
inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.Get(); } inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); }
inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.Get(); } inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); }
protected: protected:
ComPtr<ID3D10Device> device_; ComPtr<ID3D10Device> device_;

View File

@ -165,21 +165,21 @@ namespace kiwano
{ {
KGE_ASSERT(device_context_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr); KGE_ASSERT(device_context_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr);
auto rt_view = rt_view_.Get(); auto rt_view = rt_view_.get();
device_context_->OMSetRenderTargets(1, &rt_view, ds_view_.Get()); device_context_->OMSetRenderTargets(1, &rt_view, ds_view_.get());
device_context_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color)); device_context_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color));
return S_OK; return S_OK;
} }
void D3D11DeviceResources::DiscardResources() void D3D11DeviceResources::DiscardResources()
{ {
d2d_res_.Reset(); d2d_res_.reset();
device_.Reset(); device_.reset();
device_context_.Reset(); device_context_.reset();
rt_view_.Reset(); rt_view_.reset();
ds_view_.Reset(); ds_view_.reset();
dxgi_swap_chain_.Reset(); dxgi_swap_chain_.reset();
dxgi_factory_.Reset(); dxgi_factory_.reset();
hwnd_ = nullptr; hwnd_ = nullptr;
} }
@ -278,7 +278,7 @@ namespace kiwano
// Create the Direct2D device object and a corresponding context. // Create the Direct2D device object and a corresponding context.
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = d2d_res_->GetFactory()->CreateDevice(dxgi_device.Get(), &d2d_device); hr = d2d_res_->GetFactory()->CreateDevice(dxgi_device.get(), &d2d_device);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -346,7 +346,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = dxgi_factory->CreateSwapChain( hr = dxgi_factory->CreateSwapChain(
device_.Get(), device_.get(),
&swap_chain_desc, &swap_chain_desc,
&dxgi_swap_chain_); &dxgi_swap_chain_);
} }
@ -395,7 +395,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
rt_view_ = nullptr; rt_view_ = nullptr;
hr = device_->CreateRenderTargetView(dxgi_back_buffer.Get(), nullptr, &rt_view_); hr = device_->CreateRenderTargetView(dxgi_back_buffer.get(), nullptr, &rt_view_);
} }
} }
@ -418,14 +418,14 @@ namespace kiwano
{ {
CD3D11_DEPTH_STENCIL_VIEW_DESC desc(D3D11_DSV_DIMENSION_TEXTURE2D); CD3D11_DEPTH_STENCIL_VIEW_DESC desc(D3D11_DSV_DIMENSION_TEXTURE2D);
ds_view_.Reset(); ds_view_.reset();
hr = device_->CreateDepthStencilView(depth_stencil.Get(), &desc, &ds_view_); hr = device_->CreateDepthStencilView(depth_stencil.get(), &desc, &ds_view_);
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
ID3D11RenderTargetView* main_view = rt_view_.Get(); ID3D11RenderTargetView* main_view = rt_view_.get();
device_context_->OMSetRenderTargets(1, &main_view, ds_view_.Get()); device_context_->OMSetRenderTargets(1, &main_view, ds_view_.get());
} }
} }
@ -452,7 +452,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface( hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface(
dxgi_back_buffer.Get(), dxgi_back_buffer.get(),
D2D1::BitmapProperties1( D2D1::BitmapProperties1(
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW, D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED), D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),

View File

@ -35,12 +35,12 @@ namespace kiwano
public: public:
static HRESULT Create(ID3D11DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd); static HRESULT Create(ID3D11DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd);
inline ID3D11Device* GetDevice() const { KGE_ASSERT(device_); return device_.Get(); } inline ID3D11Device* GetDevice() const { KGE_ASSERT(device_); return device_.get(); }
inline ID3D11DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.Get(); } inline ID3D11DeviceContext* GetDeviceContext() const { KGE_ASSERT(device_context_); return device_context_.get(); }
inline ID3D11RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.Get(); } inline ID3D11RenderTargetView* GetRenderTargetView() const { KGE_ASSERT(rt_view_); return rt_view_.get(); }
inline ID3D11DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.Get(); } inline ID3D11DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.get(); }
inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.Get(); } inline IDXGIFactory* GetDXGIFactory() const { KGE_ASSERT(dxgi_factory_); return dxgi_factory_.get(); }
inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.Get(); } inline IDXGISwapChain* GetDXGISwapChain() const { KGE_ASSERT(dxgi_swap_chain_); return dxgi_swap_chain_.get(); }
protected: protected:
ComPtr<ID3D11Device> device_; ComPtr<ID3D11Device> device_;

View File

@ -48,8 +48,8 @@ namespace kiwano
frames_count_ = 0; frames_count_ = 0;
disposal_type_ = DisposalType::None; disposal_type_ = DisposalType::None;
saved_frame_.Reset(); saved_frame_.reset();
decoder_.Reset(); decoder_.reset();
auto factory = Renderer::GetInstance()->GetD2DDeviceResources()->GetWICImagingFactory(); auto factory = Renderer::GetInstance()->GetD2DDeviceResources()->GetWICImagingFactory();
@ -94,7 +94,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = factory->CreateDecoderFromStream( hr = factory->CreateDecoderFromStream(
stream.Get(), stream.get(),
nullptr, nullptr,
WICDecodeMetadataCacheOnLoad, WICDecodeMetadataCacheOnLoad,
&decoder_ &decoder_
@ -131,7 +131,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = converter->Initialize( hr = converter->Initialize(
wic_frame.Get(), wic_frame.get(),
GUID_WICPixelFormat32bppPBGRA, GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone, WICBitmapDitherTypeNone,
nullptr, nullptr,
@ -144,9 +144,9 @@ namespace kiwano
auto ctx = Renderer::GetInstance()->GetD2DDeviceResources()->GetDeviceContext(); auto ctx = Renderer::GetInstance()->GetD2DDeviceResources()->GetDeviceContext();
// Create a D2DBitmap from IWICBitmapSource // Create a D2DBitmap from IWICBitmapSource
raw_frame_.Reset(); raw_frame_.reset();
hr = ctx->CreateBitmapFromWicBitmap( hr = ctx->CreateBitmapFromWicBitmap(
converter.Get(), converter.get(),
nullptr, nullptr,
&raw_frame_); &raw_frame_);
} }
@ -294,7 +294,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// 获取背景色 // 获取背景色
if (FAILED(GetBackgroundColor(metadata_reader.Get()))) if (FAILED(GetBackgroundColor(metadata_reader.get())))
{ {
// 如果未能获得颜色,则默认为透明 // 如果未能获得颜色,则默认为透明
bg_color_ = D2D1::ColorF(0, 0.f); bg_color_ = D2D1::ColorF(0, 0.f);
@ -426,7 +426,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = saved_frame_->CopyFromBitmap(nullptr, frame_to_be_saved.Get(), nullptr); hr = saved_frame_->CopyFromBitmap(nullptr, frame_to_be_saved.get(), nullptr);
} }
return hr; return hr;
} }
@ -446,7 +446,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = frame_to_copy_to->CopyFromBitmap(nullptr, saved_frame_.Get(), nullptr); hr = frame_to_copy_to->CopyFromBitmap(nullptr, saved_frame_.get(), nullptr);
} }
return hr; return hr;
@ -510,7 +510,7 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = decoder_->CopyPalette(wic_palette.Get()); hr = decoder_->CopyPalette(wic_palette.get());
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))

View File

@ -57,6 +57,7 @@ namespace kiwano
{ {
ImagePtr ptr = new Image(bitmap); ImagePtr ptr = new Image(bitmap);
image_cache_.insert(std::make_pair(hash_code, ptr)); image_cache_.insert(std::make_pair(hash_code, ptr));
return ptr;
} }
else else
{ {

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../common/Singleton.hpp" #include "../core/singleton.hpp"
#include "render.h" #include "render.h"
namespace kiwano namespace kiwano

View File

@ -19,7 +19,7 @@
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #pragma once
#include "../common/ComPtr.hpp" #include "../base/ComPtr.hpp"
#include "../math/helper.h" #include "../math/helper.h"
#include "../2d/Color.h" #include "../2d/Color.h"
#include <d2d1.h> #include <d2d1.h>

View File

@ -62,13 +62,13 @@ namespace kiwano
#if defined(KGE_USE_DIRECTX10) #if defined(KGE_USE_DIRECTX10)
ID3D10DeviceResources::Create( ID3D10DeviceResources::Create(
&d3d_res_, &d3d_res_,
d2d_res_.Get(), d2d_res_.get(),
hwnd_ hwnd_
) )
#else #else
ID3D11DeviceResources::Create( ID3D11DeviceResources::Create(
&d3d_res_, &d3d_res_,
d2d_res_.Get(), d2d_res_.get(),
hwnd_ hwnd_
) )
#endif #endif
@ -93,10 +93,10 @@ namespace kiwano
{ {
KGE_LOG(L"Destroying device resources"); KGE_LOG(L"Destroying device resources");
drawing_state_block_.Reset(); drawing_state_block_.reset();
solid_color_brush_.Reset(); solid_color_brush_.reset();
d2d_res_.Reset(); d2d_res_.reset();
d3d_res_.Reset(); d3d_res_.reset();
} }
void Renderer::BeforeRender() void Renderer::BeforeRender()
@ -141,7 +141,7 @@ namespace kiwano
{ {
hr = ITextRenderer::Create( hr = ITextRenderer::Create(
&text_renderer_, &text_renderer_,
device_context_.Get() device_context_.get()
); );
} }
@ -175,7 +175,7 @@ namespace kiwano
status_.primitives = 0; status_.primitives = 0;
} }
device_context_->SaveDrawingState(drawing_state_block_.Get()); device_context_->SaveDrawingState(drawing_state_block_.get());
device_context_->BeginDraw(); device_context_->BeginDraw();
@ -191,7 +191,7 @@ namespace kiwano
HRESULT hr = device_context_->EndDraw(); HRESULT hr = device_context_->EndDraw();
device_context_->RestoreDrawingState(drawing_state_block_.Get()); device_context_->RestoreDrawingState(drawing_state_block_.get());
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -233,8 +233,8 @@ namespace kiwano
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color)); solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
device_context_->DrawGeometry( device_context_->DrawGeometry(
geometry.Get(), geometry.get(),
solid_color_brush_.Get(), solid_color_brush_.get(),
stroke_width, stroke_width,
d2d_res_->GetStrokeStyle(stroke) d2d_res_->GetStrokeStyle(stroke)
); );
@ -251,8 +251,8 @@ namespace kiwano
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color)); solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
device_context_->FillGeometry( device_context_->FillGeometry(
geometry.Get(), geometry.get(),
solid_color_brush_.Get() solid_color_brush_.get()
); );
return S_OK; return S_OK;
@ -267,7 +267,7 @@ namespace kiwano
device_context_->DrawRectangle( device_context_->DrawRectangle(
DX::ConvertToRectF(rect), DX::ConvertToRectF(rect),
solid_color_brush_.Get(), solid_color_brush_.get(),
stroke_width, stroke_width,
d2d_res_->GetStrokeStyle(stroke) d2d_res_->GetStrokeStyle(stroke)
); );
@ -285,7 +285,7 @@ namespace kiwano
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color)); solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
device_context_->FillRectangle( device_context_->FillRectangle(
DX::ConvertToRectF(rect), DX::ConvertToRectF(rect),
solid_color_brush_.Get() solid_color_brush_.get()
); );
return S_OK; return S_OK;
@ -300,7 +300,7 @@ namespace kiwano
return S_OK; return S_OK;
device_context_->DrawBitmap( device_context_->DrawBitmap(
bitmap.Get(), bitmap.get(),
DX::ConvertToRectF(dest_rect), DX::ConvertToRectF(dest_rect),
opacity_, opacity_,
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
@ -319,7 +319,7 @@ namespace kiwano
if (collecting_status_) if (collecting_status_)
++status_.primitives; ++status_.primitives;
return text_layout->Draw(nullptr, text_renderer_.Get(), 0, 0); return text_layout->Draw(nullptr, text_renderer_.get(), 0, 0);
} }
void Renderer::SetVSyncEnabled(bool enabled) void Renderer::SetVSyncEnabled(bool enabled)
@ -361,10 +361,10 @@ namespace kiwano
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
properties.opacity, properties.opacity,
solid_color_brush_.Get(), solid_color_brush_.get(),
D2D1_LAYER_OPTIONS_NONE D2D1_LAYER_OPTIONS_NONE
), ),
layer.Get() layer.get()
); );
return S_OK; return S_OK;
} }

View File

@ -174,13 +174,13 @@ namespace kiwano
inline Size const& GetOutputSize() const { return output_size_; } inline Size const& GetOutputSize() const { return output_size_; }
inline ID2DDeviceResources* GetD2DDeviceResources() const { KGE_ASSERT(d2d_res_); return d2d_res_.Get(); } inline ID2DDeviceResources* GetD2DDeviceResources() const { KGE_ASSERT(d2d_res_); return d2d_res_.get(); }
inline ID3DDeviceResources* GetD3DDeviceResources() const { KGE_ASSERT(d3d_res_); return d3d_res_.Get(); } inline ID3DDeviceResources* GetD3DDeviceResources() const { KGE_ASSERT(d3d_res_); return d3d_res_.get(); }
inline ITextRenderer* GetTextRenderer() const { KGE_ASSERT(text_renderer_); return text_renderer_.Get(); } inline ITextRenderer* GetTextRenderer() const { KGE_ASSERT(text_renderer_); return text_renderer_.get(); }
inline ID2D1SolidColorBrush* GetSolidColorBrush() const { KGE_ASSERT(solid_color_brush_); return solid_color_brush_.Get(); } inline ID2D1SolidColorBrush* GetSolidColorBrush() const { KGE_ASSERT(solid_color_brush_); return solid_color_brush_.get(); }
private: private:
Renderer(); Renderer();

View File

@ -110,8 +110,6 @@ static const int TIXML2_PATCH_VERSION = 1;
#define TINYXML2_STR(STR) (L##STR) #define TINYXML2_STR(STR) (L##STR)
#define TINYXML2_CHAR(CH) (L##CH) #define TINYXML2_CHAR(CH) (L##CH)
#include "../../common/String.hpp"
// A fixed element depth limit is problematic. There needs to be a // A fixed element depth limit is problematic. There needs to be a
// limit to avoid a stack overflow. However, that limit varies per // limit to avoid a stack overflow. However, that limit varies per
// system, and the capacity of the stack. On the other hand, it's a trivial // system, and the capacity of the stack. On the other hand, it's a trivial

View File

@ -32,10 +32,10 @@ namespace kiwano
{ {
SetResponsible(true); SetResponsible(true);
AddListener(Event::MouseHover, MakeClosure(this, &Button::UpdateStatus)); AddListener(Event::MouseHover, bind_func(this, &Button::UpdateStatus));
AddListener(Event::MouseOut, MakeClosure(this, &Button::UpdateStatus)); AddListener(Event::MouseOut, bind_func(this, &Button::UpdateStatus));
AddListener(Event::MouseBtnDown, MakeClosure(this, &Button::UpdateStatus)); AddListener(Event::MouseBtnDown, bind_func(this, &Button::UpdateStatus));
AddListener(Event::MouseBtnUp, MakeClosure(this, &Button::UpdateStatus)); AddListener(Event::MouseBtnUp, bind_func(this, &Button::UpdateStatus));
} }
Button::Button(const Callback& click) Button::Button(const Callback& click)

View File

@ -28,7 +28,7 @@ namespace kiwano
: public Sprite : public Sprite
{ {
public: public:
using Callback = Closure<void()>; using Callback = Function<void()>;
Button(); Button();

View File

@ -27,7 +27,7 @@ namespace kiwano
{ {
} }
Menu::Menu(Array<ButtonPtr> const& buttons) Menu::Menu(Vector<ButtonPtr> const& buttons)
: enabled_(true) : enabled_(true)
{ {
for (const auto& button : buttons) for (const auto& button : buttons)
@ -92,7 +92,7 @@ namespace kiwano
return false; return false;
} }
Array<ButtonPtr> const& Menu::GetAllButtons() const Vector<ButtonPtr> const& Menu::GetAllButtons() const
{ {
return buttons_; return buttons_;
} }

View File

@ -31,7 +31,7 @@ namespace kiwano
Menu(); Menu();
explicit Menu( explicit Menu(
Array<ButtonPtr> const& buttons /* 按钮数组 */ Vector<ButtonPtr> const& buttons /* 按钮数组 */
); );
// 获取菜单是否禁用 // 获取菜单是否禁用
@ -56,11 +56,11 @@ namespace kiwano
); );
// 获取所有按钮 // 获取所有按钮
Array<ButtonPtr> const& GetAllButtons() const; Vector<ButtonPtr> const& GetAllButtons() const;
private: private:
bool enabled_; bool enabled_;
Array<ButtonPtr> buttons_; Vector<ButtonPtr> buttons_;
}; };
} }

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h" #include "../core/core.h"
namespace kiwano namespace kiwano
{ {

View File

@ -20,7 +20,6 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h"
#include "../base/Resource.h" #include "../base/Resource.h"
namespace kiwano namespace kiwano

View File

@ -20,7 +20,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h" #include "../core/core.h"
namespace kiwano namespace kiwano
{ {

View File

@ -35,12 +35,12 @@ namespace kiwano
namespace namespace
{ {
Map<String, Closure<bool(ResourceCache*, Json const&)>> load_json_funcs = { Map<String, Function<bool(ResourceCache*, Json const&)>> load_json_funcs = {
{ L"latest", __resource_cache_01::LoadJsonData }, { L"latest", __resource_cache_01::LoadJsonData },
{ L"0.1", __resource_cache_01::LoadJsonData }, { L"0.1", __resource_cache_01::LoadJsonData },
}; };
Map<String, Closure<bool(ResourceCache*, tinyxml2::XMLElement*)>> load_xml_funcs = { Map<String, Function<bool(ResourceCache*, tinyxml2::XMLElement*)>> load_xml_funcs = {
{ L"latest", __resource_cache_01::LoadXmlData }, { L"latest", __resource_cache_01::LoadXmlData },
{ L"0.1", __resource_cache_01::LoadXmlData }, { L"0.1", __resource_cache_01::LoadXmlData },
}; };
@ -219,12 +219,12 @@ namespace kiwano
return false; return false;
} }
size_t ResourceCache::AddFrameSequence(String const& id, Array<Resource> const& images) size_t ResourceCache::AddFrameSequence(String const& id, Vector<Resource> const& images)
{ {
if (images.empty()) if (images.empty())
return 0; return 0;
Array<FramePtr> image_arr; Vector<FramePtr> image_arr;
image_arr.reserve(images.size()); image_arr.reserve(images.size());
for (const auto& image : images) for (const auto& image : images)
@ -247,7 +247,7 @@ namespace kiwano
return 0; return 0;
} }
size_t ResourceCache::AddFrameSequence(String const& id, Array<FramePtr> const& images) size_t ResourceCache::AddFrameSequence(String const& id, Vector<FramePtr> const& images)
{ {
if (images.empty()) if (images.empty())
return 0; return 0;
@ -270,7 +270,7 @@ namespace kiwano
float width = raw_width / cols; float width = raw_width / cols;
float height = raw_height / rows; float height = raw_height / rows;
Array<FramePtr> image_arr; Vector<FramePtr> image_arr;
image_arr.reserve(rows * cols); image_arr.reserve(rows * cols);
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
@ -290,13 +290,13 @@ namespace kiwano
return AddFrameSequence(id, frames); return AddFrameSequence(id, frames);
} }
size_t ResourceCache::AddFrameSequence(String const & id, Resource const & image, Array<Rect> const & crop_rects) size_t ResourceCache::AddFrameSequence(String const & id, Resource const & image, Vector<Rect> const & crop_rects)
{ {
FramePtr raw = new (std::nothrow) Frame; FramePtr raw = new (std::nothrow) Frame;
if (!raw || !raw->Load(image)) if (!raw || !raw->Load(image))
return 0; return 0;
Array<FramePtr> image_arr; Vector<FramePtr> image_arr;
image_arr.reserve(crop_rects.size()); image_arr.reserve(crop_rects.size());
for (const auto& rect : crop_rects) for (const auto& rect : crop_rects)
@ -370,7 +370,7 @@ namespace kiwano
}; };
bool LoadImagesFromData(ResourceCache* loader, GlobalData* gdata, const String* id, const String* type, bool LoadImagesFromData(ResourceCache* loader, GlobalData* gdata, const String* id, const String* type,
const String* file, const Array<const wchar_t*>* files, int rows, int cols) const String* file, const Vector<const wchar_t*>* files, int rows, int cols)
{ {
if (!gdata || !id) return false; if (!gdata || !id) return false;
@ -400,7 +400,7 @@ namespace kiwano
// Frames // Frames
if (files) if (files)
{ {
Array<FramePtr> frames; Vector<FramePtr> frames;
frames.reserve(files->size()); frames.reserve(files->size());
for (const auto& file : (*files)) for (const auto& file : (*files))
{ {
@ -438,7 +438,7 @@ namespace kiwano
if (image.count(L"files")) if (image.count(L"files"))
{ {
Array<const wchar_t*> files; Vector<const wchar_t*> files;
files.reserve(image[L"files"].size()); files.reserve(image[L"files"].size());
for (const auto& file : image[L"files"]) for (const auto& file : image[L"files"])
{ {
@ -480,7 +480,7 @@ namespace kiwano
if (file.empty() && !image->NoChildren()) if (file.empty() && !image->NoChildren())
{ {
Array<const wchar_t*> files_arr; Vector<const wchar_t*> files_arr;
for (auto file = image->FirstChildElement(); file; file = file->NextSiblingElement()) for (auto file = image->FirstChildElement(); file; file = file->NextSiblingElement())
{ {
if (auto path = file->Attribute(L"path")) if (auto path = file->Attribute(L"path"))

View File

@ -20,9 +20,6 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../common/helper.h"
#include "../common/Json.hpp"
#include "../common/Singleton.hpp"
#include "../base/Resource.h" #include "../base/Resource.h"
#include "../2d/include-forwards.h" #include "../2d/include-forwards.h"
#include "../renderer/GifImage.h" #include "../renderer/GifImage.h"
@ -62,10 +59,10 @@ namespace kiwano
bool AddGifImage(String const& id, GifImagePtr image); bool AddGifImage(String const& id, GifImagePtr image);
// 添加序列帧 // 添加序列帧
size_t AddFrameSequence(String const& id, Array<Resource> const& frames); size_t AddFrameSequence(String const& id, Vector<Resource> const& frames);
// 添加序列帧 // 添加序列帧
size_t AddFrameSequence(String const& id, Array<FramePtr> const& frames); size_t AddFrameSequence(String const& id, Vector<FramePtr> const& frames);
// 添加序列帧 // 添加序列帧
// 按行列数裁剪图片 // 按行列数裁剪图片
@ -73,7 +70,7 @@ namespace kiwano
// 添加序列帧 // 添加序列帧
// 按指定裁剪矩形裁剪图片 // 按指定裁剪矩形裁剪图片
size_t AddFrameSequence(String const& id, Resource const& frame, Array<Rect> const& crop_rects); size_t AddFrameSequence(String const& id, Resource const& frame, Vector<Rect> const& crop_rects);
// 添加序列帧 // 添加序列帧
size_t AddFrameSequence(String const& id, FrameSequencePtr frames); size_t AddFrameSequence(String const& id, FrameSequencePtr frames);
@ -102,7 +99,7 @@ namespace kiwano
auto iter = cache_.find(id); auto iter = cache_.find(id);
if (iter == cache_.end()) if (iter == cache_.end())
return nullptr; return nullptr;
return dynamic_cast<_Ty*>((*iter).second.Get()); return dynamic_cast<_Ty*>((*iter).second.get());
} }
protected: protected: