refactor core module
This commit is contained in:
parent
222b09f166
commit
ed034750fe
|
|
@ -9,8 +9,18 @@
|
|||
<ClInclude Include="..\src\kiwano\2d\action\Animation.h" />
|
||||
<ClInclude Include="..\src\kiwano\2d\Frame.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\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\config.h" />
|
||||
<ClInclude Include="..\src\kiwano\macros.h" />
|
||||
|
|
@ -45,16 +55,6 @@
|
|||
<ClInclude Include="..\src\kiwano\base\TimerManager.h" />
|
||||
<ClInclude Include="..\src\kiwano\base\time.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\ease.hpp" />
|
||||
<ClInclude Include="..\src\kiwano\math\helper.h" />
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@
|
|||
<Filter Include="ui">
|
||||
<UniqueIdentifier>{07b6d541-4a1b-472a-aae0-daf9d082fe84}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="common">
|
||||
<UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="platform">
|
||||
<UniqueIdentifier>{c2654ccc-59f6-4c17-bb6b-99b07fc78702}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
|
@ -37,6 +34,9 @@
|
|||
<Filter Include="2d\action">
|
||||
<UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="core">
|
||||
<UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\kiwano\ui\Button.h">
|
||||
|
|
@ -78,21 +78,6 @@
|
|||
<ClInclude Include="..\src\kiwano\2d\Transition.h">
|
||||
<Filter>2d</Filter>
|
||||
</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">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -213,21 +198,6 @@
|
|||
<ClInclude Include="..\src\kiwano\2d\GifSprite.h">
|
||||
<Filter>2d</Filter>
|
||||
</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">
|
||||
<Filter>third-party\tinyxml2</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -279,6 +249,36 @@
|
|||
<ClInclude Include="..\src\kiwano\2d\FrameSequence.h">
|
||||
<Filter>2d</Filter>
|
||||
</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>
|
||||
<ClCompile Include="..\src\kiwano\ui\Button.cpp">
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/IntrusivePtr.hpp>
|
||||
#include <kiwano/core/intrusive_ptr.hpp>
|
||||
#include <kiwano/base/Object.h>
|
||||
#include "Sound.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/IntrusivePtr.hpp>
|
||||
#include <kiwano/core/intrusive_ptr.hpp>
|
||||
#include <kiwano/base/Object.h>
|
||||
#include <kiwano/base/Resource.h>
|
||||
#include <xaudio2.h>
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@
|
|||
#endif
|
||||
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/common/ComPtr.hpp>
|
||||
#include <kiwano/common/String.hpp>
|
||||
#include <kiwano/core/string.hpp>
|
||||
#include <kiwano/base/ComPtr.hpp>
|
||||
#include <kiwano/base/Resource.h>
|
||||
#include <kiwano/base/logs.h>
|
||||
#include <kiwano/platform/modules.h>
|
||||
|
|
@ -69,7 +69,7 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = ReadSource(reader.Get(), wave_data, wave_data_size);
|
||||
hr = ReadSource(reader.get(), wave_data, wave_data_size);
|
||||
}
|
||||
|
||||
return hr;
|
||||
|
|
@ -100,13 +100,13 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.Get(), &byte_stream);
|
||||
hr = modules::MediaFoundation::Get().MFCreateMFByteStreamOnStream(stream.get(), &byte_stream);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = modules::MediaFoundation::Get().MFCreateSourceReaderFromByteStream(
|
||||
byte_stream.Get(),
|
||||
byte_stream.get(),
|
||||
nullptr,
|
||||
&reader
|
||||
);
|
||||
|
|
@ -114,7 +114,7 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = ReadSource(reader.Get(), wave_data, wave_data_size);
|
||||
hr = ReadSource(reader.get(), wave_data, wave_data_size);
|
||||
}
|
||||
|
||||
return hr;
|
||||
|
|
@ -146,7 +146,7 @@ namespace kiwano
|
|||
hr = reader->SetCurrentMediaType(
|
||||
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
|
||||
0,
|
||||
partial_type.Get()
|
||||
partial_type.get()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ namespace kiwano
|
|||
{
|
||||
UINT32 size = 0;
|
||||
hr = modules::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType(
|
||||
uncompressed_type.Get(),
|
||||
uncompressed_type.get(),
|
||||
&wave_format_,
|
||||
&size,
|
||||
(DWORD)MFWaveFormatExConvertFlag_Normal
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/Singleton.hpp>
|
||||
#include <kiwano/core/singleton.hpp>
|
||||
#include <kiwano/base/Component.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace kiwano
|
|||
{
|
||||
KGE_DECLARE_SMART_PTR(ImGuiLayer);
|
||||
|
||||
using ImGuiPipeline = Closure<void()>;
|
||||
using ImGuiPipeline = Function<void()>;
|
||||
|
||||
class ImGuiLayer
|
||||
: public Layer
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include <kiwano/common/helper.h>
|
||||
#include <kiwano/common/Closure.hpp>
|
||||
#include <kiwano/common/IntrusivePtr.hpp>
|
||||
#include <kiwano/core/core.h>
|
||||
#include <kiwano/core/Function.hpp>
|
||||
#include <kiwano/core/intrusive_ptr.hpp>
|
||||
#include <kiwano/base/Window.h>
|
||||
#include <kiwano/base/Input.h>
|
||||
#include <kiwano/renderer/render.h>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/base/Component.h>
|
||||
#include <kiwano/common/Singleton.hpp>
|
||||
#include <kiwano/core/singleton.hpp>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ struct VERTEX_CONSTANT_BUFFER
|
|||
float mvp[4][4];
|
||||
};
|
||||
|
||||
// Render function
|
||||
// Render Function
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ struct VERTEX_CONSTANT_BUFFER
|
|||
float mvp[4][4];
|
||||
};
|
||||
|
||||
// Render function
|
||||
// Render Function
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
return false;
|
||||
|
|
@ -171,7 +171,7 @@ namespace
|
|||
public:
|
||||
static inline bool GetRequest(
|
||||
HttpClient* client,
|
||||
Array<kiwano::string> const& headers,
|
||||
Vector<kiwano::string> const& headers,
|
||||
kiwano::string const& url,
|
||||
long* response_code,
|
||||
kiwano::string* response_data,
|
||||
|
|
@ -186,7 +186,7 @@ namespace
|
|||
|
||||
static inline bool PostRequest(
|
||||
HttpClient* client,
|
||||
Array<kiwano::string> const& headers,
|
||||
Vector<kiwano::string> const& headers,
|
||||
kiwano::string const& url,
|
||||
kiwano::string const& request_data,
|
||||
long* response_code,
|
||||
|
|
@ -204,7 +204,7 @@ namespace
|
|||
|
||||
static inline bool PutRequest(
|
||||
HttpClient* client,
|
||||
Array<kiwano::string> const& headers,
|
||||
Vector<kiwano::string> const& headers,
|
||||
kiwano::string const& url,
|
||||
kiwano::string const& request_data,
|
||||
long* response_code,
|
||||
|
|
@ -222,7 +222,7 @@ namespace
|
|||
|
||||
static inline bool DeleteRequest(
|
||||
HttpClient* client,
|
||||
Array<kiwano::string> const& headers,
|
||||
Vector<kiwano::string> const& headers,
|
||||
kiwano::string const& url,
|
||||
long* response_code,
|
||||
kiwano::string* response_data,
|
||||
|
|
@ -256,7 +256,7 @@ namespace kiwano
|
|||
{
|
||||
::curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
std::thread thread(MakeClosure(this, &HttpClient::NetworkThread));
|
||||
std::thread thread(bind_func(this, &HttpClient::NetworkThread));
|
||||
thread.detach();
|
||||
}
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ namespace kiwano
|
|||
response_queue_.push(response);
|
||||
response_mutex_.unlock();
|
||||
|
||||
Application::PreformInMainThread(MakeClosure(this, &HttpClient::DispatchResponseCallback));
|
||||
Application::PreformInMainThread(bind_func(this, &HttpClient::DispatchResponseCallback));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +314,7 @@ namespace kiwano
|
|||
kiwano::string url = convert_to_utf8(request->GetUrl());
|
||||
kiwano::string data = convert_to_utf8(request->GetData());
|
||||
|
||||
Array<kiwano::string> headers;
|
||||
Vector<kiwano::string> headers;
|
||||
headers.reserve(request->GetHeaders().size());
|
||||
for (const auto& pair : request->GetHeaders())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/helper.h>
|
||||
#include <kiwano/common/Singleton.hpp>
|
||||
#include <kiwano/core/core.h>
|
||||
#include <kiwano/core/singleton.hpp>
|
||||
#include <kiwano/base/Component.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
|
|
|||
|
|
@ -19,15 +19,15 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/Closure.hpp>
|
||||
#include <kiwano/common/Json.hpp>
|
||||
#include <kiwano/core/Function.hpp>
|
||||
#include <kiwano/core/basic_json.hpp>
|
||||
#include <kiwano/base/Object.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
namespace network
|
||||
{
|
||||
typedef Closure<void(HttpRequestPtr, HttpResponsePtr)> ResponseCallback;
|
||||
typedef Function<void(HttpRequestPtr, HttpResponsePtr)> ResponseCallback;
|
||||
|
||||
class KGE_API HttpRequest
|
||||
: public Object
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/common/Closure.hpp>
|
||||
#include <kiwano/common/Json.hpp>
|
||||
#include <kiwano/core/Function.hpp>
|
||||
#include <kiwano/core/basic_json.hpp>
|
||||
#include <kiwano/base/Object.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
|
|||
|
|
@ -71,12 +71,12 @@ namespace kiwano
|
|||
OnUpdate(dt);
|
||||
}
|
||||
|
||||
if (!children_.IsEmpty())
|
||||
if (!children_.is_empty())
|
||||
{
|
||||
ActorPtr next;
|
||||
for (auto child = children_.First(); child; child = next)
|
||||
for (auto child = children_.first_item(); child; child = next)
|
||||
{
|
||||
next = child->NextItem();
|
||||
next = child->next_item();
|
||||
child->Update(dt);
|
||||
}
|
||||
}
|
||||
|
|
@ -89,7 +89,7 @@ namespace kiwano
|
|||
|
||||
UpdateTransform();
|
||||
|
||||
if (children_.IsEmpty())
|
||||
if (children_.is_empty())
|
||||
{
|
||||
PrepareRender();
|
||||
OnRender();
|
||||
|
|
@ -97,14 +97,14 @@ namespace kiwano
|
|||
else
|
||||
{
|
||||
// render children those are less than 0 in Z-Order
|
||||
Actor* child = children_.First().Get();
|
||||
Actor* child = children_.first_item().get();
|
||||
while (child)
|
||||
{
|
||||
if (child->GetZOrder() >= 0)
|
||||
break;
|
||||
|
||||
child->Render();
|
||||
child = child->NextItem().Get();
|
||||
child = child->next_item().get();
|
||||
}
|
||||
|
||||
PrepareRender();
|
||||
|
|
@ -113,7 +113,7 @@ namespace kiwano
|
|||
while (child)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
for (auto child = children_.First(); child; child = child->NextItem())
|
||||
for (auto child = children_.first_item(); child; child = child->next_item())
|
||||
{
|
||||
child->RenderBorder();
|
||||
}
|
||||
|
|
@ -142,9 +142,9 @@ namespace kiwano
|
|||
return;
|
||||
|
||||
ActorPtr prev;
|
||||
for (auto child = children_.Last(); child; child = prev)
|
||||
for (auto child = children_.last_item(); child; child = prev)
|
||||
{
|
||||
prev = child->PrevItem();
|
||||
prev = child->prev_item();
|
||||
child->Dispatch(evt);
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ namespace kiwano
|
|||
}
|
||||
|
||||
// update children's transform
|
||||
for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get())
|
||||
for (Actor* child = children_.first_item().get(); child; child = child->next_item().get())
|
||||
child->dirty_transform_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ namespace kiwano
|
|||
displayed_opacity_ = opacity_;
|
||||
}
|
||||
|
||||
for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get())
|
||||
for (Actor* child = children_.first_item().get(); child; child = child->next_item().get())
|
||||
{
|
||||
child->UpdateOpacity();
|
||||
}
|
||||
|
|
@ -271,7 +271,7 @@ namespace kiwano
|
|||
if (scene && stage_ != scene)
|
||||
{
|
||||
stage_ = scene;
|
||||
for (Actor* child = children_.First().Get(); child; child = child->NextItem().Get())
|
||||
for (Actor* child = children_.first_item().get(); child; child = child->next_item().get())
|
||||
{
|
||||
child->stage_ = scene;
|
||||
}
|
||||
|
|
@ -284,28 +284,28 @@ namespace kiwano
|
|||
{
|
||||
ActorPtr me = this;
|
||||
|
||||
parent_->children_.Remove(me);
|
||||
parent_->children_.remove_item(me);
|
||||
|
||||
Actor* sibling = parent_->children_.Last().Get();
|
||||
Actor* sibling = parent_->children_.last_item().get();
|
||||
|
||||
if (sibling && sibling->GetZOrder() > z_order_)
|
||||
{
|
||||
sibling = sibling->PrevItem().Get();
|
||||
sibling = sibling->prev_item().get();
|
||||
while (sibling)
|
||||
{
|
||||
if (sibling->GetZOrder() <= z_order_)
|
||||
break;
|
||||
sibling = sibling->PrevItem().Get();
|
||||
sibling = sibling->prev_item().get();
|
||||
}
|
||||
}
|
||||
|
||||
if (sibling)
|
||||
{
|
||||
parent_->children_.InsertAfter(me, sibling);
|
||||
parent_->children_.insert_after(me, sibling);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent_->children_.PushFront(me);
|
||||
parent_->children_.push_front_item(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -519,15 +519,15 @@ namespace kiwano
|
|||
#ifdef KGE_DEBUG
|
||||
|
||||
if (child->parent_)
|
||||
KGE_ERROR_LOG(L"The node to be added already has a parent");
|
||||
KGE_ERROR_LOG(L"The actor to be added already has a parent");
|
||||
|
||||
for (Actor* parent = parent_; parent; parent = parent->parent_)
|
||||
if (parent == child)
|
||||
KGE_ERROR_LOG(L"A node cannot be its own parent");
|
||||
KGE_ERROR_LOG(L"A actor cannot be its own parent");
|
||||
|
||||
#endif // KGE_DEBUG
|
||||
|
||||
children_.PushBack(child);
|
||||
children_.push_back_item(child);
|
||||
child->parent_ = this;
|
||||
child->SetStage(this->stage_);
|
||||
child->dirty_transform_ = true;
|
||||
|
|
@ -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());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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))
|
||||
{
|
||||
|
|
@ -573,7 +573,7 @@ namespace kiwano
|
|||
{
|
||||
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))
|
||||
{
|
||||
|
|
@ -598,27 +598,27 @@ namespace kiwano
|
|||
|
||||
void Actor::RemoveChild(ActorPtr child)
|
||||
{
|
||||
RemoveChild(child.Get());
|
||||
RemoveChild(child.get());
|
||||
}
|
||||
|
||||
void Actor::RemoveChild(Actor * child)
|
||||
{
|
||||
KGE_ASSERT(child && "Actor::RemoveChild failed, NULL pointer exception");
|
||||
|
||||
if (children_.IsEmpty())
|
||||
if (children_.is_empty())
|
||||
return;
|
||||
|
||||
if (child)
|
||||
{
|
||||
child->parent_ = nullptr;
|
||||
if (child->stage_) child->SetStage(nullptr);
|
||||
children_.Remove(ActorPtr(child));
|
||||
children_.remove_item(ActorPtr(child));
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::RemoveChildren(String const& child_name)
|
||||
{
|
||||
if (children_.IsEmpty())
|
||||
if (children_.is_empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
@ -626,9 +626,9 @@ namespace kiwano
|
|||
size_t hash_code = std::hash<String>{}(child_name);
|
||||
|
||||
Actor* next;
|
||||
for (Actor* child = children_.First().Get(); child; child = next)
|
||||
for (Actor* child = children_.first_item().get(); child; child = next)
|
||||
{
|
||||
next = child->NextItem().Get();
|
||||
next = child->next_item().get();
|
||||
|
||||
if (child->hash_name_ == hash_code && child->IsName(child_name))
|
||||
{
|
||||
|
|
@ -639,7 +639,7 @@ namespace kiwano
|
|||
|
||||
void Actor::RemoveAllChildren()
|
||||
{
|
||||
children_.Clear();
|
||||
children_.clear_items();
|
||||
}
|
||||
|
||||
void Actor::SetResponsible(bool enable)
|
||||
|
|
|
|||
|
|
@ -35,14 +35,14 @@ namespace kiwano
|
|||
, public TimerManager
|
||||
, public ActionManager
|
||||
, public EventDispatcher
|
||||
, public IntrusiveListItem<ActorPtr>
|
||||
, public intrusive_list_item<ActorPtr>
|
||||
{
|
||||
friend class Director;
|
||||
friend class Transition;
|
||||
friend class IntrusiveList<ActorPtr>;
|
||||
friend class intrusive_list<ActorPtr>;
|
||||
|
||||
using Children = IntrusiveList<ActorPtr>;
|
||||
using UpdateCallback = Closure<void(Duration)>;
|
||||
using Children = intrusive_list<ActorPtr>;
|
||||
using UpdateCallback = Function<void(Duration)>;
|
||||
|
||||
public:
|
||||
Actor();
|
||||
|
|
@ -342,11 +342,11 @@ namespace kiwano
|
|||
|
||||
// 添加多个子角色
|
||||
void AddChildren(
|
||||
Array<ActorPtr> const& children
|
||||
Vector<ActorPtr> const& children
|
||||
);
|
||||
|
||||
// 获取所有名称相同的子角色
|
||||
Array<ActorPtr> GetChildren(
|
||||
Vector<ActorPtr> GetChildren(
|
||||
String const& name
|
||||
) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace kiwano
|
|||
ThrowIfFailed(
|
||||
ITextRenderer::Create(
|
||||
&text_renderer_,
|
||||
render_target_.Get()
|
||||
render_target_.get()
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -169,9 +169,9 @@ namespace kiwano
|
|||
render_target_->DrawLine(
|
||||
D2D1::Point2F(begin.x, begin.y),
|
||||
D2D1::Point2F(end.x, end.y),
|
||||
stroke_brush_.Get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -187,9 +187,9 @@ namespace kiwano
|
|||
radius,
|
||||
radius
|
||||
),
|
||||
stroke_brush_.Get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -205,9 +205,9 @@ namespace kiwano
|
|||
radius_x,
|
||||
radius_y
|
||||
),
|
||||
stroke_brush_.Get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -221,9 +221,9 @@ namespace kiwano
|
|||
rect.origin.x + rect.size.x,
|
||||
rect.origin.y + rect.size.y
|
||||
),
|
||||
stroke_brush_.Get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -241,9 +241,9 @@ namespace kiwano
|
|||
radius_x,
|
||||
radius_y
|
||||
),
|
||||
stroke_brush_.Get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -253,7 +253,7 @@ namespace kiwano
|
|||
if (image && image->GetBitmap())
|
||||
{
|
||||
render_target_->DrawBitmap(
|
||||
image->GetBitmap().Get(),
|
||||
image->GetBitmap().get(),
|
||||
D2D1::RectF(0, 0, image->GetWidth(), image->GetHeight()),
|
||||
opacity,
|
||||
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
||||
|
|
@ -292,7 +292,7 @@ namespace kiwano
|
|||
);
|
||||
|
||||
ThrowIfFailed(
|
||||
text_layout->Draw(nullptr, text_renderer_.Get(), point.x, point.y)
|
||||
text_layout->Draw(nullptr, text_renderer_.get(), point.x, point.y)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +307,7 @@ namespace kiwano
|
|||
radius,
|
||||
radius
|
||||
),
|
||||
fill_brush_.Get()
|
||||
fill_brush_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -323,7 +323,7 @@ namespace kiwano
|
|||
radius_x,
|
||||
radius_y
|
||||
),
|
||||
fill_brush_.Get()
|
||||
fill_brush_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ namespace kiwano
|
|||
rect.origin.x + rect.size.x,
|
||||
rect.origin.y + rect.size.y
|
||||
),
|
||||
fill_brush_.Get()
|
||||
fill_brush_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ namespace kiwano
|
|||
radius_x,
|
||||
radius_y
|
||||
),
|
||||
fill_brush_.Get()
|
||||
fill_brush_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -393,7 +393,7 @@ namespace kiwano
|
|||
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())
|
||||
{
|
||||
|
|
@ -437,10 +437,10 @@ namespace kiwano
|
|||
void Canvas::StrokePath()
|
||||
{
|
||||
render_target_->DrawGeometry(
|
||||
current_geometry_.Get(),
|
||||
stroke_brush_.Get(),
|
||||
current_geometry_.get(),
|
||||
stroke_brush_.get(),
|
||||
stroke_width_,
|
||||
outline_join_style_.Get()
|
||||
outline_join_style_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
@ -448,8 +448,8 @@ namespace kiwano
|
|||
void Canvas::FillPath()
|
||||
{
|
||||
render_target_->FillGeometry(
|
||||
current_geometry_.Get(),
|
||||
fill_brush_.Get()
|
||||
current_geometry_.get(),
|
||||
fill_brush_.get()
|
||||
);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ namespace kiwano
|
|||
|
||||
// 添加多条线段
|
||||
void AddLines(
|
||||
Array<Point> const& points
|
||||
Vector<Point> const& points
|
||||
);
|
||||
|
||||
// 添加一条三次方贝塞尔曲线
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
|||
DebugNode::DebugNode()
|
||||
: background_color_(0.0f, 0.0f, 0.0f, 0.7f)
|
||||
{
|
||||
SetName(L"kiwano-debug-node");
|
||||
SetName(L"kiwano-debug-actor");
|
||||
SetPosition(10, 10);
|
||||
SetResponsible(true);
|
||||
SetCascadeOpacityEnabled(true);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,6 @@ namespace kiwano
|
|||
protected:
|
||||
Color background_color_;
|
||||
TextPtr debug_text_;
|
||||
Array<Time> frame_time_;
|
||||
Vector<Time> frame_time_;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
FrameSequence::FrameSequence(Array<FramePtr> const& frames)
|
||||
FrameSequence::FrameSequence(Vector<FramePtr> const& 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())
|
||||
frames_ = frames;
|
||||
|
|
@ -65,7 +65,7 @@ namespace kiwano
|
|||
return frames_[index];
|
||||
}
|
||||
|
||||
Array<FramePtr> const& FrameSequence::GetFrames() const
|
||||
Vector<FramePtr> const& FrameSequence::GetFrames() const
|
||||
{
|
||||
return frames_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
|||
FrameSequence();
|
||||
|
||||
explicit FrameSequence(
|
||||
Array<FramePtr> const& frames /* Ö¡ÐòÁÐ */
|
||||
Vector<FramePtr> const& frames /* Ö¡ÐòÁÐ */
|
||||
);
|
||||
|
||||
virtual ~FrameSequence();
|
||||
|
|
@ -43,14 +43,14 @@ namespace kiwano
|
|||
|
||||
// 添加多个关键帧
|
||||
void AddFrames(
|
||||
Array<FramePtr> const& frames
|
||||
Vector<FramePtr> const& frames
|
||||
);
|
||||
|
||||
// 获取关键帧
|
||||
FramePtr GetFrame(size_t index) const;
|
||||
|
||||
// 获取关键帧
|
||||
Array<FramePtr> const& GetFrames() const;
|
||||
Vector<FramePtr> const& GetFrames() const;
|
||||
|
||||
// 获取帧动画的拷贝对象
|
||||
FrameSequencePtr Clone() const;
|
||||
|
|
@ -59,6 +59,6 @@ namespace kiwano
|
|||
FrameSequencePtr Reverse() const;
|
||||
|
||||
protected:
|
||||
Array<FramePtr> frames_;
|
||||
Vector<FramePtr> frames_;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ namespace kiwano
|
|||
loop_count_++;
|
||||
}
|
||||
|
||||
frame_rt_->DrawBitmap(image_->GetRawFrame().Get(), image_->GetFramePosition());
|
||||
frame_rt_->DrawBitmap(image_->GetRawFrame().get(), image_->GetFramePosition());
|
||||
hr = frame_rt_->EndDraw();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ namespace kiwano
|
|||
: public VisualActor
|
||||
{
|
||||
public:
|
||||
using LoopDoneCallback = Closure<void(int)>;
|
||||
using DoneCallback = Closure<void()>;
|
||||
using LoopDoneCallback = Function<void(int)>;
|
||||
using DoneCallback = Function<void()>;
|
||||
|
||||
GifSprite();
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace kiwano
|
|||
{
|
||||
SetSize(Renderer::GetInstance()->GetOutputSize());
|
||||
|
||||
auto handler = MakeClosure(this, &Layer::HandleMessages);
|
||||
auto handler = bind_func(this, &Layer::HandleMessages);
|
||||
|
||||
AddListener(Event::MouseBtnDown, handler);
|
||||
AddListener(Event::MouseBtnUp, handler);
|
||||
|
|
@ -53,9 +53,9 @@ namespace kiwano
|
|||
if (!swallow_)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ namespace kiwano
|
|||
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())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ namespace kiwano
|
|||
|
||||
// 添加多条线段
|
||||
void AddLines(
|
||||
Array<Point> const& points
|
||||
Vector<Point> const& points
|
||||
);
|
||||
|
||||
// 添加一条三次方贝塞尔曲线
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
using ActionCallback = Closure<void()>;
|
||||
using ActionCallback = Function<void()>;
|
||||
|
||||
class ActionManager;
|
||||
|
||||
class KGE_API Action
|
||||
: public Object
|
||||
, protected IntrusiveListItem<ActionPtr>
|
||||
, protected intrusive_list_item<ActionPtr>
|
||||
{
|
||||
friend class ActionManager;
|
||||
friend class ActionGroup;
|
||||
friend class IntrusiveList<ActionPtr>;
|
||||
friend class intrusive_list<ActionPtr>;
|
||||
|
||||
public:
|
||||
enum class Status
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
ActionGroup::ActionGroup(Array<ActionPtr> const& actions, bool sequence)
|
||||
ActionGroup::ActionGroup(Vector<ActionPtr> const& actions, bool sequence)
|
||||
: sequence_(sequence)
|
||||
{
|
||||
this->Add(actions);
|
||||
|
|
@ -45,19 +45,19 @@ namespace kiwano
|
|||
|
||||
void ActionGroup::Init(ActorPtr target)
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
if (actions_.is_empty())
|
||||
{
|
||||
Done();
|
||||
return;
|
||||
}
|
||||
|
||||
current_ = actions_.First();
|
||||
current_ = actions_.first_item();
|
||||
current_->Restart(target); // init first action
|
||||
|
||||
if (!sequence_)
|
||||
{
|
||||
// init all actions
|
||||
for (; current_; current_ = current_->NextItem())
|
||||
for (; current_; current_ = current_->next_item())
|
||||
{
|
||||
current_->Restart(target);
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ namespace kiwano
|
|||
|
||||
if (current_->IsDone())
|
||||
{
|
||||
current_ = current_->NextItem();
|
||||
current_ = current_->next_item();
|
||||
|
||||
if (current_)
|
||||
current_->Restart(target); // init next action
|
||||
|
|
@ -86,7 +86,7 @@ namespace kiwano
|
|||
else
|
||||
{
|
||||
bool done = true;
|
||||
for (current_ = actions_.First(); current_; current_ = current_->NextItem())
|
||||
for (current_ = actions_.first_item(); current_; current_ = current_->next_item())
|
||||
{
|
||||
if (!current_->IsDone())
|
||||
{
|
||||
|
|
@ -106,11 +106,11 @@ namespace kiwano
|
|||
{
|
||||
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)
|
||||
Add(action);
|
||||
|
|
@ -121,7 +121,7 @@ namespace kiwano
|
|||
auto group = new (std::nothrow) ActionGroup();
|
||||
if (group)
|
||||
{
|
||||
for (auto action = actions_.First(); action; action = action->NextItem())
|
||||
for (auto action = actions_.first_item(); action; action = action->next_item())
|
||||
{
|
||||
if (action)
|
||||
{
|
||||
|
|
@ -135,9 +135,9 @@ namespace kiwano
|
|||
ActionPtr ActionGroup::Reverse() const
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ namespace kiwano
|
|||
: public Action
|
||||
{
|
||||
public:
|
||||
using ActionList = IntrusiveList<ActionPtr>;
|
||||
using ActionList = intrusive_list<ActionPtr>;
|
||||
|
||||
ActionGroup();
|
||||
|
||||
explicit ActionGroup(
|
||||
Array<ActionPtr> const& actions,
|
||||
Vector<ActionPtr> const& actions,
|
||||
bool sequence = true // 按顺序执行或同时执行
|
||||
);
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ namespace kiwano
|
|||
|
||||
// 添加多个动作
|
||||
void Add(
|
||||
Array<ActionPtr> const& actions
|
||||
Vector<ActionPtr> const& actions
|
||||
);
|
||||
|
||||
// 获取所有动作
|
||||
|
|
@ -84,7 +84,7 @@ namespace kiwano
|
|||
inline ActionSequence() : ActionGroup() {}
|
||||
|
||||
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() {}
|
||||
};
|
||||
|
|
@ -99,7 +99,7 @@ namespace kiwano
|
|||
inline ActionSpawn() : ActionGroup() { sequence_ = false; }
|
||||
|
||||
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() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ namespace kiwano
|
|||
}
|
||||
|
||||
static inline TweenHelper
|
||||
Animation(FramesPtr frames)
|
||||
Animation(FrameSequencePtr frames)
|
||||
{
|
||||
return TweenHelper(new kiwano::Animation(0, frames));
|
||||
}
|
||||
|
|
@ -202,13 +202,13 @@ namespace kiwano
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
static inline ActionHelper
|
||||
Multiple(Array<ActionPtr> const& actions)
|
||||
Multiple(Vector<ActionPtr> const& actions)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, false));
|
||||
}
|
||||
|
|
@ -233,14 +233,14 @@ namespace kiwano
|
|||
|
||||
KGE_DEPRECATED("Tween::Sequence is deprecated, use Tween::Group instead")
|
||||
static inline ActionHelper
|
||||
Sequence(Array<ActionPtr> const& actions)
|
||||
Sequence(Vector<ActionPtr> const& actions)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, true));
|
||||
}
|
||||
|
||||
KGE_DEPRECATED("Tween::Spawn is deprecated, use Tween::Multiple instead")
|
||||
static inline ActionHelper
|
||||
Spawn(Array<ActionPtr> const& actions)
|
||||
Spawn(Vector<ActionPtr> const& actions)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, false));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,19 +26,19 @@ namespace kiwano
|
|||
{
|
||||
void ActionManager::UpdateActions(ActorPtr target, Duration dt)
|
||||
{
|
||||
if (actions_.IsEmpty() || !target)
|
||||
if (actions_.is_empty() || !target)
|
||||
return;
|
||||
|
||||
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())
|
||||
action->UpdateStep(target, dt);
|
||||
|
||||
if (action->IsRemoveable())
|
||||
actions_.Remove(action);
|
||||
actions_.remove_item(action);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,17 +48,17 @@ namespace kiwano
|
|||
|
||||
if (action)
|
||||
{
|
||||
actions_.PushBack(action);
|
||||
actions_.push_back_item(action);
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
ActionPtr ActionManager::GetAction(String const & name)
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
if (actions_.is_empty())
|
||||
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))
|
||||
return action;
|
||||
return nullptr;
|
||||
|
|
@ -66,10 +66,10 @@ namespace kiwano
|
|||
|
||||
void ActionManager::ResumeAllActions()
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
if (actions_.is_empty())
|
||||
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();
|
||||
}
|
||||
|
|
@ -77,10 +77,10 @@ namespace kiwano
|
|||
|
||||
void ActionManager::PauseAllActions()
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
if (actions_.is_empty())
|
||||
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();
|
||||
}
|
||||
|
|
@ -88,10 +88,10 @@ namespace kiwano
|
|||
|
||||
void ActionManager::StopAllActions()
|
||||
{
|
||||
if (actions_.IsEmpty())
|
||||
if (actions_.is_empty())
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace kiwano
|
|||
{
|
||||
class KGE_API ActionManager
|
||||
{
|
||||
using Actions = IntrusiveList<ActionPtr>;
|
||||
using Actions = intrusive_list<ActionPtr>;
|
||||
|
||||
public:
|
||||
// 添加动作
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
void ActionPath::AddLines(Array<Point> const& points)
|
||||
void ActionPath::AddLines(Vector<Point> const& points)
|
||||
{
|
||||
if (!path_beginning_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
namespace kiwano
|
||||
{
|
||||
// 缓动函数
|
||||
using EaseFunc = Closure<float(float)>;
|
||||
using EaseFunc = Function<float(float)>;
|
||||
|
||||
// 缓动函数枚举
|
||||
// See https://easings.net for more information
|
||||
|
|
@ -446,7 +446,7 @@ namespace kiwano
|
|||
|
||||
// 添加多条线段
|
||||
void AddLines(
|
||||
Array<Point> const& points
|
||||
Vector<Point> const& points
|
||||
);
|
||||
|
||||
// 添加一条三次方贝塞尔曲线
|
||||
|
|
@ -502,7 +502,7 @@ namespace kiwano
|
|||
: public ActionTween
|
||||
{
|
||||
public:
|
||||
using TweenFunc = Closure<void(ActorPtr, float)>;
|
||||
using TweenFunc = Function<void(ActorPtr, float)>;
|
||||
|
||||
ActionCustom(
|
||||
Duration duration, /* 持续时长 */
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace kiwano
|
|||
return;
|
||||
}
|
||||
|
||||
auto sprite_target = dynamic_cast<Sprite*>(target.Get());
|
||||
auto sprite_target = dynamic_cast<Sprite*>(target.get());
|
||||
if (sprite_target && frame_seq_)
|
||||
{
|
||||
sprite_target->SetFrame(frame_seq_->GetFrames()[0]);
|
||||
|
|
@ -67,7 +67,7 @@ namespace kiwano
|
|||
|
||||
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");
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,11 @@
|
|||
|
||||
#pragma once
|
||||
#include "Color.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../common/ComPtr.hpp"
|
||||
#include "../common/Closure.hpp"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../common/IntrusiveList.hpp"
|
||||
#include "../core/core.h"
|
||||
#include "../base/time.h"
|
||||
#include "../base/RefCounter.hpp"
|
||||
#include "../base/SmartPtr.hpp"
|
||||
#include "../base/ComPtr.hpp"
|
||||
#include "../base/Object.h"
|
||||
#include "../math/helper.h"
|
||||
#include "../base/types.h"
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
namespace kiwano
|
||||
{
|
||||
AsyncTask::AsyncTask()
|
||||
: thread_(MakeClosure(this, &AsyncTask::TaskThread))
|
||||
: thread_(bind_func(this, &AsyncTask::TaskThread))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ namespace kiwano
|
|||
func_mutex_.unlock();
|
||||
}
|
||||
|
||||
Application::PreformInMainThread(MakeClosure(this, &AsyncTask::Complete));
|
||||
Application::PreformInMainThread(bind_func(this, &AsyncTask::Complete));
|
||||
}
|
||||
|
||||
void AsyncTask::Complete()
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
#include "Object.h"
|
||||
#include "../common/Closure.hpp"
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
|
|
@ -28,8 +27,8 @@ namespace kiwano
|
|||
{
|
||||
KGE_DECLARE_SMART_PTR(AsyncTask);
|
||||
|
||||
typedef Closure<void()> AsyncTaskFunc;
|
||||
typedef Closure<void()> AsyncTaskCallback;
|
||||
typedef Function<void()> AsyncTaskFunc;
|
||||
typedef Function<void()> AsyncTaskCallback;
|
||||
|
||||
class AsyncTask
|
||||
: public Object
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "IntrusivePtr.hpp"
|
||||
#include "../core/intrusive_ptr.hpp"
|
||||
#include <Unknwnbase.h>
|
||||
#include <type_traits>
|
||||
|
||||
|
|
@ -42,6 +42,6 @@ namespace kiwano
|
|||
template<
|
||||
typename _Ty,
|
||||
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>;
|
||||
|
||||
}
|
||||
|
|
@ -74,15 +74,23 @@ namespace kiwano
|
|||
{
|
||||
if (show)
|
||||
{
|
||||
if (!debug_node_)
|
||||
debug_node_ = new DebugNode;
|
||||
if (!debug_actor_)
|
||||
debug_actor_ = new DebugNode;
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (transition_)
|
||||
|
|
@ -112,8 +120,8 @@ namespace kiwano
|
|||
if (next_scene_)
|
||||
next_scene_->Update(dt);
|
||||
|
||||
if (debug_node_)
|
||||
debug_node_->Update(dt);
|
||||
if (debug_actor_)
|
||||
debug_actor_->Update(dt);
|
||||
}
|
||||
|
||||
void Director::OnRender()
|
||||
|
|
@ -127,8 +135,8 @@ namespace kiwano
|
|||
curr_scene_->Render();
|
||||
}
|
||||
|
||||
if (debug_node_)
|
||||
debug_node_->Render();
|
||||
if (debug_actor_)
|
||||
debug_actor_->Render();
|
||||
}
|
||||
|
||||
void Director::AfterRender()
|
||||
|
|
@ -142,8 +150,8 @@ namespace kiwano
|
|||
|
||||
void Director::HandleEvent(Event& evt)
|
||||
{
|
||||
if (debug_node_)
|
||||
debug_node_->Dispatch(evt);
|
||||
if (debug_actor_)
|
||||
debug_actor_->Dispatch(evt);
|
||||
|
||||
if (curr_scene_)
|
||||
curr_scene_->Dispatch(evt);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../2d/include-forwards.h"
|
||||
#include "Component.h"
|
||||
|
||||
|
|
@ -54,6 +53,9 @@ namespace kiwano
|
|||
// 显示调试信息
|
||||
void ShowDebugInfo(bool show = true);
|
||||
|
||||
// 헌왕校憩
|
||||
void ClearStages();
|
||||
|
||||
public:
|
||||
void SetupComponent() override {}
|
||||
|
||||
|
|
@ -76,7 +78,7 @@ namespace kiwano
|
|||
bool render_border_enabled_;
|
||||
StagePtr curr_scene_;
|
||||
StagePtr next_scene_;
|
||||
ActorPtr debug_node_;
|
||||
ActorPtr debug_actor_;
|
||||
TransitionPtr transition_;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ namespace kiwano
|
|||
{
|
||||
void EventDispatcher::Dispatch(Event& evt)
|
||||
{
|
||||
if (listeners_.IsEmpty())
|
||||
if (listeners_.is_empty())
|
||||
return;
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ namespace kiwano
|
|||
|
||||
if (listener)
|
||||
{
|
||||
listeners_.PushBack(listener);
|
||||
listeners_.push_back_item(listener);
|
||||
}
|
||||
return listener;
|
||||
}
|
||||
|
|
@ -56,13 +56,13 @@ namespace kiwano
|
|||
EventListenerPtr listener = new EventListener(type, callback, name);
|
||||
if (listener)
|
||||
{
|
||||
listeners_.PushBack(listener);
|
||||
listeners_.push_back_item(listener);
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
{
|
||||
|
|
@ -73,7 +73,7 @@ namespace kiwano
|
|||
|
||||
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))
|
||||
{
|
||||
|
|
@ -85,20 +85,20 @@ namespace kiwano
|
|||
void EventDispatcher::RemoveListeners(String const & listener_name)
|
||||
{
|
||||
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))
|
||||
{
|
||||
listeners_.Remove(listener);
|
||||
listeners_.remove_item(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -109,7 +109,7 @@ namespace kiwano
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -121,13 +121,13 @@ namespace kiwano
|
|||
void EventDispatcher::RemoveListeners(UINT type)
|
||||
{
|
||||
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)
|
||||
{
|
||||
listeners_.Remove(listener);
|
||||
listeners_.remove_item(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace kiwano
|
|||
{
|
||||
class KGE_API EventDispatcher
|
||||
{
|
||||
using Listeners = IntrusiveList<EventListenerPtr>;
|
||||
using Listeners = intrusive_list<EventListenerPtr>;
|
||||
|
||||
public:
|
||||
// 添加监听器
|
||||
|
|
|
|||
|
|
@ -19,17 +19,14 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../core/core.h"
|
||||
#include "../base/SmartPtr.hpp"
|
||||
#include "../common/helper.h"
|
||||
#include "../common/Closure.hpp"
|
||||
#include "../common/IntrusiveList.hpp"
|
||||
#include "Object.h"
|
||||
#include "Event.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
typedef Closure<void(Event const&)> EventCallback;
|
||||
typedef Function<void(Event const&)> EventCallback;
|
||||
|
||||
class EventDispatcher;
|
||||
|
||||
|
|
@ -38,10 +35,10 @@ namespace kiwano
|
|||
// 事件监听器
|
||||
class KGE_API EventListener
|
||||
: public Object
|
||||
, protected IntrusiveListItem<EventListenerPtr>
|
||||
, protected intrusive_list_item<EventListenerPtr>
|
||||
{
|
||||
friend class EventDispatcher;
|
||||
friend class IntrusiveList<EventListenerPtr>;
|
||||
friend class intrusive_list<EventListenerPtr>;
|
||||
|
||||
public:
|
||||
EventListener(
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../core/core.h"
|
||||
#include "../math/helper.h"
|
||||
#include "keys.hpp"
|
||||
#include "Component.h"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace kiwano
|
|||
namespace
|
||||
{
|
||||
bool tracing_leaks = false;
|
||||
Array<Object*> tracing_objects;
|
||||
Vector<Object*> tracing_objects;
|
||||
}
|
||||
|
||||
unsigned int Object::last_object_id = 0;
|
||||
|
|
@ -120,7 +120,7 @@ namespace kiwano
|
|||
KGE_LOG(L"------------------------- Total size: %d -------------------------", tracing_objects.size());
|
||||
}
|
||||
|
||||
Array<Object*>& kiwano::Object::__GetTracingObjects()
|
||||
Vector<Object*>& kiwano::Object::__GetTracingObjects()
|
||||
{
|
||||
return tracing_objects;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../core/core.h"
|
||||
#include "RefCounter.hpp"
|
||||
#include "SmartPtr.hpp"
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ namespace kiwano
|
|||
static void DumpTracingObjects();
|
||||
|
||||
public:
|
||||
static Array<Object*>& __GetTracingObjects();
|
||||
static Vector<Object*>& __GetTracingObjects();
|
||||
|
||||
static void __AddObjectToTracingList(Object*);
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/Noncopyable.hpp"
|
||||
#include "../core/noncopyable.hpp"
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
class KGE_API RefCounter
|
||||
: protected Noncopyable
|
||||
: protected noncopyable
|
||||
{
|
||||
public:
|
||||
// 增加引用计数
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../core/core.h"
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../base/RefCounter.hpp"
|
||||
#include "../common/IntrusivePtr.hpp"
|
||||
#include "../core/intrusive_ptr.hpp"
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -38,7 +38,7 @@ namespace kiwano
|
|||
};
|
||||
|
||||
template <typename _Ty>
|
||||
using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager>;
|
||||
using SmartPtr = intrusive_ptr<_Ty, DefaultIntrusivePtrManager>;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../common/helper.h"
|
||||
#include "../common/Closure.hpp"
|
||||
#include "../common/IntrusiveList.hpp"
|
||||
#include "Object.h"
|
||||
#include "time.h"
|
||||
#include <functional>
|
||||
|
|
@ -35,12 +32,12 @@ namespace kiwano
|
|||
// 定时任务
|
||||
class KGE_API Timer
|
||||
: public Object
|
||||
, protected IntrusiveListItem<TimerPtr>
|
||||
, protected intrusive_list_item<TimerPtr>
|
||||
{
|
||||
friend class TimerManager;
|
||||
friend class IntrusiveList<TimerPtr>;
|
||||
friend class intrusive_list<TimerPtr>;
|
||||
|
||||
using Callback = Closure<void()>;
|
||||
using Callback = Function<void()>;
|
||||
|
||||
public:
|
||||
explicit Timer(
|
||||
|
|
|
|||
|
|
@ -25,19 +25,19 @@ namespace kiwano
|
|||
{
|
||||
void TimerManager::UpdateTimers(Duration dt)
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
return;
|
||||
|
||||
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;
|
||||
timer->Update(dt, remove_after_update);
|
||||
|
||||
if (remove_after_update)
|
||||
timers_.Remove(timer);
|
||||
timers_.remove_item(timer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,16 +48,16 @@ namespace kiwano
|
|||
if (timer)
|
||||
{
|
||||
timer->Reset();
|
||||
timers_.PushBack(timer);
|
||||
timers_.push_back_item(timer);
|
||||
}
|
||||
}
|
||||
|
||||
void TimerManager::StopTimers(String const& name)
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
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))
|
||||
{
|
||||
|
|
@ -68,10 +68,10 @@ namespace kiwano
|
|||
|
||||
void TimerManager::StartTimers(String const& name)
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
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))
|
||||
{
|
||||
|
|
@ -82,26 +82,26 @@ namespace kiwano
|
|||
|
||||
void TimerManager::RemoveTimers(String const& name)
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
return;
|
||||
|
||||
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))
|
||||
{
|
||||
timers_.Remove(timer);
|
||||
timers_.remove_item(timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimerManager::StopAllTimers()
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
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();
|
||||
}
|
||||
|
|
@ -109,10 +109,10 @@ namespace kiwano
|
|||
|
||||
void TimerManager::StartAllTimers()
|
||||
{
|
||||
if (timers_.IsEmpty())
|
||||
if (timers_.is_empty())
|
||||
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();
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ namespace kiwano
|
|||
|
||||
void TimerManager::RemoveAllTimers()
|
||||
{
|
||||
timers_.Clear();
|
||||
timers_.clear_items();
|
||||
}
|
||||
|
||||
const TimerManager::Timers & TimerManager::GetAllTimers() const
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace kiwano
|
|||
{
|
||||
class KGE_API TimerManager
|
||||
{
|
||||
using Timers = IntrusiveList<TimerPtr>;
|
||||
using Timers = intrusive_list<TimerPtr>;
|
||||
|
||||
public:
|
||||
// Ìí¼ÓÈÎÎñ
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../core/core.h"
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace kiwano
|
|||
static LARGE_INTEGER freq = {};
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/String.hpp"
|
||||
#include "../core/core.h"
|
||||
#include <ostream>
|
||||
#include <istream>
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,8 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../core/core.h"
|
||||
#include "../math/helper.h"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "types.h"
|
||||
|
||||
namespace kiwano
|
||||
|
|
|
|||
|
|
@ -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_;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
|
@ -19,8 +19,14 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "Array.hpp"
|
||||
#include "String.hpp"
|
||||
#include "vector.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 <map>
|
||||
#include <list>
|
||||
|
|
@ -30,10 +36,12 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
using String = kiwano::core::wstring;
|
||||
|
||||
using StringStream = std::wstringstream;
|
||||
|
||||
template<typename _Ty1, typename _Ty2>
|
||||
using Pair = std::pair<_Ty1, _Ty2>;
|
||||
template <typename _Ty, typename... _Args>
|
||||
using Vector = kiwano::core::vector<_Ty, _Args...>;
|
||||
|
||||
template <typename _Ty, typename... _Args>
|
||||
using List = std::list<_Ty, _Args...>;
|
||||
|
|
@ -44,6 +52,9 @@ namespace kiwano
|
|||
template <typename _Ty, typename... _Args>
|
||||
using Set = std::set<_Ty, _Args...>;
|
||||
|
||||
template <typename _Ty1, typename _Ty2>
|
||||
using Pair = std::pair<_Ty1, _Ty2>;
|
||||
|
||||
template <typename _Ty, typename... _Args>
|
||||
using UnorderedSet = std::unordered_set<_Ty, _Args...>;
|
||||
|
||||
|
|
@ -52,4 +63,28 @@ namespace kiwano
|
|||
|
||||
template <typename _Kty, typename _Ty, typename... _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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -22,14 +22,19 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
class Noncopyable
|
||||
inline namespace core
|
||||
{
|
||||
|
||||
class noncopyable
|
||||
{
|
||||
protected:
|
||||
Noncopyable() = default;
|
||||
noncopyable() = default;
|
||||
|
||||
private:
|
||||
Noncopyable(const Noncopyable&) = delete;
|
||||
noncopyable(const noncopyable&) = delete;
|
||||
|
||||
Noncopyable& operator=(const Noncopyable&) = delete;
|
||||
noncopyable& operator=(const noncopyable&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
} // inline namespace core
|
||||
} // namespace kiwano
|
||||
|
|
@ -33,6 +33,9 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
inline namespace core
|
||||
{
|
||||
|
||||
template <typename _Ty>
|
||||
struct Singleton
|
||||
{
|
||||
|
|
@ -46,14 +49,6 @@ namespace kiwano
|
|||
return instance_.get();
|
||||
}
|
||||
|
||||
static inline void InitInstance()
|
||||
{
|
||||
if (!instance_)
|
||||
{
|
||||
instance_.reset(new (std::nothrow) _Ty);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void DestroyInstance()
|
||||
{
|
||||
instance_.reset();
|
||||
|
|
@ -67,6 +62,14 @@ namespace kiwano
|
|||
|
||||
Singleton& operator=(const Singleton&) = delete;
|
||||
|
||||
static inline void InitInstance()
|
||||
{
|
||||
if (!instance_)
|
||||
{
|
||||
instance_.reset(new (std::nothrow) _Ty);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static std::once_flag once_;
|
||||
static std::unique_ptr<_Ty> instance_;
|
||||
|
|
@ -77,4 +80,6 @@ namespace kiwano
|
|||
|
||||
template <typename _Ty>
|
||||
std::unique_ptr<_Ty> Singleton<_Ty>::instance_;
|
||||
}
|
||||
|
||||
} // inline namespace core
|
||||
} // namespace kiwano
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -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
|
||||
|
|
@ -29,19 +29,18 @@
|
|||
|
||||
|
||||
//
|
||||
// common
|
||||
// core
|
||||
//
|
||||
|
||||
#include "common/Array.hpp"
|
||||
#include "common/String.hpp"
|
||||
#include "common/helper.h"
|
||||
#include "common/Closure.hpp"
|
||||
#include "common/IntrusiveList.hpp"
|
||||
#include "common/IntrusivePtr.hpp"
|
||||
#include "common/ComPtr.hpp"
|
||||
#include "common/Noncopyable.hpp"
|
||||
#include "common/Singleton.hpp"
|
||||
#include "common/Json.hpp"
|
||||
#include "core/vector.hpp"
|
||||
#include "core/string.hpp"
|
||||
#include "core/core.h"
|
||||
#include "core/Function.hpp"
|
||||
#include "core/intrusive_list.hpp"
|
||||
#include "core/intrusive_ptr.hpp"
|
||||
#include "core/noncopyable.hpp"
|
||||
#include "core/singleton.hpp"
|
||||
#include "core/basic_json.hpp"
|
||||
|
||||
|
||||
//
|
||||
|
|
@ -70,6 +69,9 @@
|
|||
#include "base/Director.h"
|
||||
#include "base/logs.h"
|
||||
|
||||
#include "base/SmartPtr.hpp"
|
||||
#include "base/ComPtr.hpp"
|
||||
|
||||
#include "base/Object.h"
|
||||
#include "base/Event.hpp"
|
||||
#include "base/EventListener.h"
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ namespace kiwano
|
|||
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace kiwano
|
|||
{
|
||||
namespace
|
||||
{
|
||||
using FunctionToPerform = Closure<void()>;
|
||||
using FunctionToPerform = Function<void()>;
|
||||
|
||||
std::mutex perform_mutex_;
|
||||
Queue<FunctionToPerform> functions_to_perform_;
|
||||
|
|
@ -123,7 +123,7 @@ namespace kiwano
|
|||
{
|
||||
HWND hwnd = Window::GetInstance()->GetHandle();
|
||||
|
||||
if (!hwnd)
|
||||
if (!inited_)
|
||||
throw std::exception("Calling Application::Run before Application::Init");
|
||||
|
||||
if (hwnd)
|
||||
|
|
@ -147,6 +147,9 @@ namespace kiwano
|
|||
|
||||
void Application::Destroy()
|
||||
{
|
||||
// Clear all stages
|
||||
Director::GetInstance()->ClearStages();
|
||||
|
||||
if (inited_)
|
||||
{
|
||||
inited_ = false;
|
||||
|
|
@ -159,8 +162,8 @@ namespace kiwano
|
|||
}
|
||||
|
||||
// Destroy all instances
|
||||
ResourceCache::DestroyInstance();
|
||||
Director::DestroyInstance();
|
||||
ResourceCache::DestroyInstance();
|
||||
Input::DestroyInstance();
|
||||
Renderer::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_);
|
||||
functions_to_perform_.push(function);
|
||||
functions_to_perform_.push(Function);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../common/String.hpp"
|
||||
#include "../common/Array.hpp"
|
||||
#include "../common/Closure.hpp"
|
||||
#include "../common/Noncopyable.hpp"
|
||||
#include "../core/core.h"
|
||||
#include "../base/time.h"
|
||||
#include "../base/Component.h"
|
||||
#include "../base/Event.hpp"
|
||||
|
|
@ -56,7 +53,7 @@ namespace kiwano
|
|||
|
||||
// 应用
|
||||
class KGE_API Application
|
||||
: protected Noncopyable
|
||||
: protected noncopyable
|
||||
{
|
||||
public:
|
||||
Application();
|
||||
|
|
@ -107,7 +104,7 @@ namespace kiwano
|
|||
// 在 Kiwano 主线程中执行函数
|
||||
// 当在其他线程调用 Kiwano 函数时使用
|
||||
static void PreformInMainThread(
|
||||
Closure<void()> function
|
||||
Function<void()> Function
|
||||
);
|
||||
|
||||
protected:
|
||||
|
|
@ -122,6 +119,6 @@ namespace kiwano
|
|||
bool inited_;
|
||||
float time_scale_;
|
||||
|
||||
Array<Component*> components_;
|
||||
Vector<Component*> components_;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,17 +176,17 @@ namespace kiwano
|
|||
{
|
||||
ImageCache::GetInstance()->Clear();
|
||||
|
||||
factory_.Reset();
|
||||
device_.Reset();
|
||||
device_context_.Reset();
|
||||
target_bitmap_.Reset();
|
||||
factory_.reset();
|
||||
device_.reset();
|
||||
device_context_.reset();
|
||||
target_bitmap_.reset();
|
||||
|
||||
imaging_factory_.Reset();
|
||||
dwrite_factory_.Reset();
|
||||
imaging_factory_.reset();
|
||||
dwrite_factory_.reset();
|
||||
|
||||
d2d_miter_stroke_style_.Reset();
|
||||
d2d_bevel_stroke_style_.Reset();
|
||||
d2d_round_stroke_style_.Reset();
|
||||
d2d_miter_stroke_style_.reset();
|
||||
d2d_bevel_stroke_style_.reset();
|
||||
d2d_round_stroke_style_.reset();
|
||||
}
|
||||
|
||||
HRESULT D2DDeviceResources::CreateDeviceIndependentResources()
|
||||
|
|
@ -315,7 +315,7 @@ namespace kiwano
|
|||
{
|
||||
target_bitmap_ = target;
|
||||
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)
|
||||
|
|
@ -357,7 +357,7 @@ namespace kiwano
|
|||
{
|
||||
// 图片格式转换成 32bppPBGRA
|
||||
hr = converter->Initialize(
|
||||
source.Get(),
|
||||
source.get(),
|
||||
GUID_WICPixelFormat32bppPBGRA,
|
||||
WICBitmapDitherTypeNone,
|
||||
nullptr,
|
||||
|
|
@ -369,7 +369,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = device_context_->CreateBitmapFromWicBitmap(
|
||||
converter.Get(),
|
||||
converter.get(),
|
||||
nullptr,
|
||||
&bitmap_tmp
|
||||
);
|
||||
|
|
@ -414,7 +414,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = imaging_factory_->CreateDecoderFromStream(
|
||||
stream.Get(),
|
||||
stream.get(),
|
||||
nullptr,
|
||||
WICDecodeMetadataCacheOnLoad,
|
||||
&decoder
|
||||
|
|
@ -435,7 +435,7 @@ namespace kiwano
|
|||
{
|
||||
// 图片格式转换成 32bppPBGRA
|
||||
hr = converter->Initialize(
|
||||
source.Get(),
|
||||
source.get(),
|
||||
GUID_WICPixelFormat32bppPBGRA,
|
||||
WICBitmapDitherTypeNone,
|
||||
nullptr,
|
||||
|
|
@ -447,7 +447,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = device_context_->CreateBitmapFromWicBitmap(
|
||||
converter.Get(),
|
||||
converter.get(),
|
||||
nullptr,
|
||||
&bitmap_tmp
|
||||
);
|
||||
|
|
@ -517,7 +517,7 @@ namespace kiwano
|
|||
hr = dwrite_factory_->CreateTextLayout(
|
||||
text.c_str(),
|
||||
length,
|
||||
text_format.Get(),
|
||||
text_format.get(),
|
||||
text_style.wrap_width,
|
||||
0,
|
||||
&text_layout_tmp
|
||||
|
|
@ -528,7 +528,7 @@ namespace kiwano
|
|||
hr = dwrite_factory_->CreateTextLayout(
|
||||
text.c_str(),
|
||||
length,
|
||||
text_format.Get(),
|
||||
text_format.get(),
|
||||
0,
|
||||
0,
|
||||
&text_layout_tmp
|
||||
|
|
@ -546,7 +546,7 @@ namespace kiwano
|
|||
hr = dwrite_factory_->CreateTextLayout(
|
||||
text.c_str(),
|
||||
length,
|
||||
text_format.Get(),
|
||||
text_format.get(),
|
||||
metrics.width,
|
||||
0,
|
||||
&text_layout_tmp
|
||||
|
|
@ -586,9 +586,9 @@ namespace kiwano
|
|||
{
|
||||
switch (stroke)
|
||||
{
|
||||
case StrokeStyle::Miter: return d2d_miter_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::Miter: return d2d_miter_stroke_style_.get(); break;
|
||||
case StrokeStyle::Bevel: return d2d_bevel_stroke_style_.get(); break;
|
||||
case StrokeStyle::Round: return d2d_round_stroke_style_.get(); break;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,12 +72,12 @@ namespace kiwano
|
|||
|
||||
virtual void DiscardResources() = 0;
|
||||
|
||||
inline ID2D1Factory1* GetFactory() const { KGE_ASSERT(factory_); return 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 ID2D1Device* GetDevice() const { KGE_ASSERT(device_); return device_.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 ID2D1Factory1* GetFactory() const { KGE_ASSERT(factory_); return 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 ID2D1Device* GetDevice() const { KGE_ASSERT(device_); return device_.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(); }
|
||||
|
||||
protected:
|
||||
ComPtr<ID2D1Factory1> factory_;
|
||||
|
|
|
|||
|
|
@ -188,20 +188,20 @@ namespace kiwano
|
|||
{
|
||||
KGE_ASSERT(device_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr);
|
||||
|
||||
auto rt_view = rt_view_.Get();
|
||||
device_->OMSetRenderTargets(1, &rt_view, ds_view_.Get());
|
||||
auto rt_view = rt_view_.get();
|
||||
device_->OMSetRenderTargets(1, &rt_view, ds_view_.get());
|
||||
device_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void D3D10DeviceResources::DiscardResources()
|
||||
{
|
||||
d2d_res_.Reset();
|
||||
device_.Reset();
|
||||
rt_view_.Reset();
|
||||
ds_view_.Reset();
|
||||
dxgi_swap_chain_.Reset();
|
||||
dxgi_factory_.Reset();
|
||||
d2d_res_.reset();
|
||||
device_.reset();
|
||||
rt_view_.reset();
|
||||
ds_view_.reset();
|
||||
dxgi_swap_chain_.reset();
|
||||
dxgi_factory_.reset();
|
||||
|
||||
hwnd_ = nullptr;
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ namespace kiwano
|
|||
// Create the Direct2D device object and a corresponding context.
|
||||
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))
|
||||
|
|
@ -310,7 +310,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = dxgi_factory->CreateSwapChain(
|
||||
device_.Get(),
|
||||
device_.get(),
|
||||
&swap_chain_desc,
|
||||
&dxgi_swap_chain_);
|
||||
}
|
||||
|
|
@ -367,7 +367,7 @@ namespace kiwano
|
|||
renderDesc.Texture2D.MipSlice = 0;
|
||||
|
||||
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.Texture2D.MipSlice = 0;
|
||||
|
||||
ds_view_.Reset();
|
||||
hr = device_->CreateDepthStencilView(depth_stencil.Get(), &desc, &ds_view_);
|
||||
ds_view_.reset();
|
||||
hr = device_->CreateDepthStencilView(depth_stencil.get(), &desc, &ds_view_);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ID3D10RenderTargetView* main_view = rt_view_.Get();
|
||||
device_->OMSetRenderTargets(1, &main_view, ds_view_.Get());
|
||||
ID3D10RenderTargetView* main_view = rt_view_.get();
|
||||
device_->OMSetRenderTargets(1, &main_view, ds_view_.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +433,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface(
|
||||
dxgi_back_buffer.Get(),
|
||||
dxgi_back_buffer.get(),
|
||||
D2D1::BitmapProperties1(
|
||||
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ namespace kiwano
|
|||
public:
|
||||
static HRESULT Create(ID3D10DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd);
|
||||
|
||||
inline ID3D10Device* GetDevice() const { KGE_ASSERT(device_); return device_.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 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 ID3D10Device* GetDevice() const { KGE_ASSERT(device_); return device_.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 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(); }
|
||||
|
||||
protected:
|
||||
ComPtr<ID3D10Device> device_;
|
||||
|
|
|
|||
|
|
@ -165,21 +165,21 @@ namespace kiwano
|
|||
{
|
||||
KGE_ASSERT(device_context_ != nullptr && rt_view_ != nullptr && ds_view_ != nullptr);
|
||||
|
||||
auto rt_view = rt_view_.Get();
|
||||
device_context_->OMSetRenderTargets(1, &rt_view, ds_view_.Get());
|
||||
auto rt_view = rt_view_.get();
|
||||
device_context_->OMSetRenderTargets(1, &rt_view, ds_view_.get());
|
||||
device_context_->ClearRenderTargetView(rt_view, reinterpret_cast<float*>(&clear_color));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void D3D11DeviceResources::DiscardResources()
|
||||
{
|
||||
d2d_res_.Reset();
|
||||
device_.Reset();
|
||||
device_context_.Reset();
|
||||
rt_view_.Reset();
|
||||
ds_view_.Reset();
|
||||
dxgi_swap_chain_.Reset();
|
||||
dxgi_factory_.Reset();
|
||||
d2d_res_.reset();
|
||||
device_.reset();
|
||||
device_context_.reset();
|
||||
rt_view_.reset();
|
||||
ds_view_.reset();
|
||||
dxgi_swap_chain_.reset();
|
||||
dxgi_factory_.reset();
|
||||
|
||||
hwnd_ = nullptr;
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ namespace kiwano
|
|||
// Create the Direct2D device object and a corresponding context.
|
||||
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))
|
||||
|
|
@ -346,7 +346,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = dxgi_factory->CreateSwapChain(
|
||||
device_.Get(),
|
||||
device_.get(),
|
||||
&swap_chain_desc,
|
||||
&dxgi_swap_chain_);
|
||||
}
|
||||
|
|
@ -395,7 +395,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
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);
|
||||
|
||||
ds_view_.Reset();
|
||||
hr = device_->CreateDepthStencilView(depth_stencil.Get(), &desc, &ds_view_);
|
||||
ds_view_.reset();
|
||||
hr = device_->CreateDepthStencilView(depth_stencil.get(), &desc, &ds_view_);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
ID3D11RenderTargetView* main_view = rt_view_.Get();
|
||||
device_context_->OMSetRenderTargets(1, &main_view, ds_view_.Get());
|
||||
ID3D11RenderTargetView* main_view = rt_view_.get();
|
||||
device_context_->OMSetRenderTargets(1, &main_view, ds_view_.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -452,7 +452,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = d2d_res_->GetDeviceContext()->CreateBitmapFromDxgiSurface(
|
||||
dxgi_back_buffer.Get(),
|
||||
dxgi_back_buffer.get(),
|
||||
D2D1::BitmapProperties1(
|
||||
D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED),
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ namespace kiwano
|
|||
public:
|
||||
static HRESULT Create(ID3D11DeviceResources** device_resources, ID2DDeviceResources* d2d_device_res, HWND hwnd);
|
||||
|
||||
inline ID3D11Device* GetDevice() const { KGE_ASSERT(device_); return device_.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 ID3D11DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.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 ID3D11Device* GetDevice() const { KGE_ASSERT(device_); return device_.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 ID3D11DepthStencilView* GetDepthStencilView() const { KGE_ASSERT(ds_view_); return ds_view_.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(); }
|
||||
|
||||
protected:
|
||||
ComPtr<ID3D11Device> device_;
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ namespace kiwano
|
|||
frames_count_ = 0;
|
||||
disposal_type_ = DisposalType::None;
|
||||
|
||||
saved_frame_.Reset();
|
||||
decoder_.Reset();
|
||||
saved_frame_.reset();
|
||||
decoder_.reset();
|
||||
|
||||
auto factory = Renderer::GetInstance()->GetD2DDeviceResources()->GetWICImagingFactory();
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = factory->CreateDecoderFromStream(
|
||||
stream.Get(),
|
||||
stream.get(),
|
||||
nullptr,
|
||||
WICDecodeMetadataCacheOnLoad,
|
||||
&decoder_
|
||||
|
|
@ -131,7 +131,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = converter->Initialize(
|
||||
wic_frame.Get(),
|
||||
wic_frame.get(),
|
||||
GUID_WICPixelFormat32bppPBGRA,
|
||||
WICBitmapDitherTypeNone,
|
||||
nullptr,
|
||||
|
|
@ -144,9 +144,9 @@ namespace kiwano
|
|||
auto ctx = Renderer::GetInstance()->GetD2DDeviceResources()->GetDeviceContext();
|
||||
|
||||
// Create a D2DBitmap from IWICBitmapSource
|
||||
raw_frame_.Reset();
|
||||
raw_frame_.reset();
|
||||
hr = ctx->CreateBitmapFromWicBitmap(
|
||||
converter.Get(),
|
||||
converter.get(),
|
||||
nullptr,
|
||||
&raw_frame_);
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ namespace kiwano
|
|||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// 获取背景色
|
||||
if (FAILED(GetBackgroundColor(metadata_reader.Get())))
|
||||
if (FAILED(GetBackgroundColor(metadata_reader.get())))
|
||||
{
|
||||
// 如果未能获得颜色,则默认为透明
|
||||
bg_color_ = D2D1::ColorF(0, 0.f);
|
||||
|
|
@ -426,7 +426,7 @@ namespace kiwano
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
@ -446,7 +446,7 @@ namespace kiwano
|
|||
|
||||
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;
|
||||
|
|
@ -510,7 +510,7 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = decoder_->CopyPalette(wic_palette.Get());
|
||||
hr = decoder_->CopyPalette(wic_palette.get());
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ namespace kiwano
|
|||
{
|
||||
ImagePtr ptr = new Image(bitmap);
|
||||
image_cache_.insert(std::make_pair(hash_code, ptr));
|
||||
return ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../core/singleton.hpp"
|
||||
#include "render.h"
|
||||
|
||||
namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include "../common/ComPtr.hpp"
|
||||
#include "../base/ComPtr.hpp"
|
||||
#include "../math/helper.h"
|
||||
#include "../2d/Color.h"
|
||||
#include <d2d1.h>
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ namespace kiwano
|
|||
#if defined(KGE_USE_DIRECTX10)
|
||||
ID3D10DeviceResources::Create(
|
||||
&d3d_res_,
|
||||
d2d_res_.Get(),
|
||||
d2d_res_.get(),
|
||||
hwnd_
|
||||
)
|
||||
#else
|
||||
ID3D11DeviceResources::Create(
|
||||
&d3d_res_,
|
||||
d2d_res_.Get(),
|
||||
d2d_res_.get(),
|
||||
hwnd_
|
||||
)
|
||||
#endif
|
||||
|
|
@ -93,10 +93,10 @@ namespace kiwano
|
|||
{
|
||||
KGE_LOG(L"Destroying device resources");
|
||||
|
||||
drawing_state_block_.Reset();
|
||||
solid_color_brush_.Reset();
|
||||
d2d_res_.Reset();
|
||||
d3d_res_.Reset();
|
||||
drawing_state_block_.reset();
|
||||
solid_color_brush_.reset();
|
||||
d2d_res_.reset();
|
||||
d3d_res_.reset();
|
||||
}
|
||||
|
||||
void Renderer::BeforeRender()
|
||||
|
|
@ -141,7 +141,7 @@ namespace kiwano
|
|||
{
|
||||
hr = ITextRenderer::Create(
|
||||
&text_renderer_,
|
||||
device_context_.Get()
|
||||
device_context_.get()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ namespace kiwano
|
|||
status_.primitives = 0;
|
||||
}
|
||||
|
||||
device_context_->SaveDrawingState(drawing_state_block_.Get());
|
||||
device_context_->SaveDrawingState(drawing_state_block_.get());
|
||||
|
||||
device_context_->BeginDraw();
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ namespace kiwano
|
|||
|
||||
HRESULT hr = device_context_->EndDraw();
|
||||
|
||||
device_context_->RestoreDrawingState(drawing_state_block_.Get());
|
||||
device_context_->RestoreDrawingState(drawing_state_block_.get());
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
|
@ -233,8 +233,8 @@ namespace kiwano
|
|||
solid_color_brush_->SetColor(DX::ConvertToColorF(stroke_color));
|
||||
|
||||
device_context_->DrawGeometry(
|
||||
geometry.Get(),
|
||||
solid_color_brush_.Get(),
|
||||
geometry.get(),
|
||||
solid_color_brush_.get(),
|
||||
stroke_width,
|
||||
d2d_res_->GetStrokeStyle(stroke)
|
||||
);
|
||||
|
|
@ -251,8 +251,8 @@ namespace kiwano
|
|||
|
||||
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
||||
device_context_->FillGeometry(
|
||||
geometry.Get(),
|
||||
solid_color_brush_.Get()
|
||||
geometry.get(),
|
||||
solid_color_brush_.get()
|
||||
);
|
||||
|
||||
return S_OK;
|
||||
|
|
@ -267,7 +267,7 @@ namespace kiwano
|
|||
|
||||
device_context_->DrawRectangle(
|
||||
DX::ConvertToRectF(rect),
|
||||
solid_color_brush_.Get(),
|
||||
solid_color_brush_.get(),
|
||||
stroke_width,
|
||||
d2d_res_->GetStrokeStyle(stroke)
|
||||
);
|
||||
|
|
@ -285,7 +285,7 @@ namespace kiwano
|
|||
solid_color_brush_->SetColor(DX::ConvertToColorF(fill_color));
|
||||
device_context_->FillRectangle(
|
||||
DX::ConvertToRectF(rect),
|
||||
solid_color_brush_.Get()
|
||||
solid_color_brush_.get()
|
||||
);
|
||||
|
||||
return S_OK;
|
||||
|
|
@ -300,7 +300,7 @@ namespace kiwano
|
|||
return S_OK;
|
||||
|
||||
device_context_->DrawBitmap(
|
||||
bitmap.Get(),
|
||||
bitmap.get(),
|
||||
DX::ConvertToRectF(dest_rect),
|
||||
opacity_,
|
||||
D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
|
||||
|
|
@ -319,7 +319,7 @@ namespace kiwano
|
|||
|
||||
if (collecting_status_)
|
||||
++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)
|
||||
|
|
@ -361,10 +361,10 @@ namespace kiwano
|
|||
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
|
||||
D2D1::Matrix3x2F::Identity(),
|
||||
properties.opacity,
|
||||
solid_color_brush_.Get(),
|
||||
solid_color_brush_.get(),
|
||||
D2D1_LAYER_OPTIONS_NONE
|
||||
),
|
||||
layer.Get()
|
||||
layer.get()
|
||||
);
|
||||
return S_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,13 +174,13 @@ namespace kiwano
|
|||
|
||||
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:
|
||||
Renderer();
|
||||
|
|
|
|||
|
|
@ -110,8 +110,6 @@ static const int TIXML2_PATCH_VERSION = 1;
|
|||
#define TINYXML2_STR(STR) (L##STR)
|
||||
#define TINYXML2_CHAR(CH) (L##CH)
|
||||
|
||||
#include "../../common/String.hpp"
|
||||
|
||||
// A fixed element depth limit is problematic. There needs to be a
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ namespace kiwano
|
|||
{
|
||||
SetResponsible(true);
|
||||
|
||||
AddListener(Event::MouseHover, MakeClosure(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseOut, MakeClosure(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseBtnDown, MakeClosure(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseBtnUp, MakeClosure(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseHover, bind_func(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseOut, bind_func(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseBtnDown, bind_func(this, &Button::UpdateStatus));
|
||||
AddListener(Event::MouseBtnUp, bind_func(this, &Button::UpdateStatus));
|
||||
}
|
||||
|
||||
Button::Button(const Callback& click)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace kiwano
|
|||
: public Sprite
|
||||
{
|
||||
public:
|
||||
using Callback = Closure<void()>;
|
||||
using Callback = Function<void()>;
|
||||
|
||||
Button();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Menu::Menu(Array<ButtonPtr> const& buttons)
|
||||
Menu::Menu(Vector<ButtonPtr> const& buttons)
|
||||
: enabled_(true)
|
||||
{
|
||||
for (const auto& button : buttons)
|
||||
|
|
@ -92,7 +92,7 @@ namespace kiwano
|
|||
return false;
|
||||
}
|
||||
|
||||
Array<ButtonPtr> const& Menu::GetAllButtons() const
|
||||
Vector<ButtonPtr> const& Menu::GetAllButtons() const
|
||||
{
|
||||
return buttons_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace kiwano
|
|||
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:
|
||||
bool enabled_;
|
||||
Array<ButtonPtr> buttons_;
|
||||
Vector<ButtonPtr> buttons_;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../core/core.h"
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../base/Resource.h"
|
||||
|
||||
namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../core/core.h"
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ namespace kiwano
|
|||
|
||||
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"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"0.1", __resource_cache_01::LoadXmlData },
|
||||
};
|
||||
|
|
@ -219,12 +219,12 @@ namespace kiwano
|
|||
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())
|
||||
return 0;
|
||||
|
||||
Array<FramePtr> image_arr;
|
||||
Vector<FramePtr> image_arr;
|
||||
image_arr.reserve(images.size());
|
||||
|
||||
for (const auto& image : images)
|
||||
|
|
@ -247,7 +247,7 @@ namespace kiwano
|
|||
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())
|
||||
return 0;
|
||||
|
|
@ -270,7 +270,7 @@ namespace kiwano
|
|||
float width = raw_width / cols;
|
||||
float height = raw_height / rows;
|
||||
|
||||
Array<FramePtr> image_arr;
|
||||
Vector<FramePtr> image_arr;
|
||||
image_arr.reserve(rows * cols);
|
||||
|
||||
for (int i = 0; i < rows; i++)
|
||||
|
|
@ -290,13 +290,13 @@ namespace kiwano
|
|||
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;
|
||||
if (!raw || !raw->Load(image))
|
||||
return 0;
|
||||
|
||||
Array<FramePtr> image_arr;
|
||||
Vector<FramePtr> image_arr;
|
||||
image_arr.reserve(crop_rects.size());
|
||||
|
||||
for (const auto& rect : crop_rects)
|
||||
|
|
@ -370,7 +370,7 @@ namespace kiwano
|
|||
};
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -400,7 +400,7 @@ namespace kiwano
|
|||
// Frames
|
||||
if (files)
|
||||
{
|
||||
Array<FramePtr> frames;
|
||||
Vector<FramePtr> frames;
|
||||
frames.reserve(files->size());
|
||||
for (const auto& file : (*files))
|
||||
{
|
||||
|
|
@ -438,7 +438,7 @@ namespace kiwano
|
|||
|
||||
if (image.count(L"files"))
|
||||
{
|
||||
Array<const wchar_t*> files;
|
||||
Vector<const wchar_t*> files;
|
||||
files.reserve(image[L"files"].size());
|
||||
for (const auto& file : image[L"files"])
|
||||
{
|
||||
|
|
@ -480,7 +480,7 @@ namespace kiwano
|
|||
|
||||
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())
|
||||
{
|
||||
if (auto path = file->Attribute(L"path"))
|
||||
|
|
|
|||
|
|
@ -20,9 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
#include "../macros.h"
|
||||
#include "../common/helper.h"
|
||||
#include "../common/Json.hpp"
|
||||
#include "../common/Singleton.hpp"
|
||||
#include "../base/Resource.h"
|
||||
#include "../2d/include-forwards.h"
|
||||
#include "../renderer/GifImage.h"
|
||||
|
|
@ -62,10 +59,10 @@ namespace kiwano
|
|||
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);
|
||||
|
|
@ -102,7 +99,7 @@ namespace kiwano
|
|||
auto iter = cache_.find(id);
|
||||
if (iter == cache_.end())
|
||||
return nullptr;
|
||||
return dynamic_cast<_Ty*>((*iter).second.Get());
|
||||
return dynamic_cast<_Ty*>((*iter).second.get());
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue