Update Singleton
This commit is contained in:
parent
d938922605
commit
9329b6f888
|
|
@ -63,7 +63,7 @@ Sound::~Sound()
|
||||||
|
|
||||||
bool Sound::Load(String const& file_path)
|
bool Sound::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_WARN(L"Media file '%s' not found", file_path.c_str());
|
KGE_WARN(L"Media file '%s' not found", file_path.c_str());
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -74,7 +74,7 @@ bool Sound::Load(String const& file_path)
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
HRESULT hr = transcoder_.LoadMediaFile(full_path);
|
HRESULT hr = transcoder_.LoadMediaFile(full_path);
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
|
|
@ -83,7 +83,7 @@ bool Sound::Load(String const& file_path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -107,7 +107,7 @@ bool Sound::Load(Resource const& res)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!AudioEngine::Instance().CreateSound(*this, transcoder_.GetBuffer()))
|
if (!AudioEngine::GetInstance().CreateSound(*this, transcoder_.GetBuffer()))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ void ImGuiModule::SetupComponent()
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
// Setup Platform/Renderer bindings
|
// Setup Platform/Renderer bindings
|
||||||
target_window_ = Renderer::Instance().GetTargetWindow();
|
target_window_ = Renderer::GetInstance().GetTargetWindow();
|
||||||
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||||
io.BackendFlags |=
|
io.BackendFlags |=
|
||||||
|
|
@ -58,7 +58,7 @@ void ImGuiModule::SetupComponent()
|
||||||
io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y;
|
io.KeyMap[ImGuiKey_Y] = (int)KeyCode::Y;
|
||||||
io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z;
|
io.KeyMap[ImGuiKey_Z] = (int)KeyCode::Z;
|
||||||
|
|
||||||
ImGui_Impl_Init(Renderer::Instance());
|
ImGui_Impl_Init(Renderer::GetInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiModule::DestroyComponent()
|
void ImGuiModule::DestroyComponent()
|
||||||
|
|
@ -75,10 +75,10 @@ void ImGuiModule::OnUpdate(Duration dt)
|
||||||
io.DeltaTime = dt.Seconds();
|
io.DeltaTime = dt.Seconds();
|
||||||
|
|
||||||
// Read keyboard modifiers inputs
|
// Read keyboard modifiers inputs
|
||||||
io.KeyCtrl = Input::Instance().IsDown(KeyCode::Ctrl);
|
io.KeyCtrl = Input::GetInstance().IsDown(KeyCode::Ctrl);
|
||||||
io.KeyShift = Input::Instance().IsDown(KeyCode::Shift);
|
io.KeyShift = Input::GetInstance().IsDown(KeyCode::Shift);
|
||||||
io.KeyAlt = Input::Instance().IsDown(KeyCode::Alt);
|
io.KeyAlt = Input::GetInstance().IsDown(KeyCode::Alt);
|
||||||
io.KeySuper = Input::Instance().IsDown(KeyCode::Super);
|
io.KeySuper = Input::GetInstance().IsDown(KeyCode::Super);
|
||||||
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below.
|
// io.KeysDown[], io.MousePos, io.MouseDown[], io.MouseWheel: filled by the HandleEvent function below.
|
||||||
|
|
||||||
// Update OS mouse position
|
// Update OS mouse position
|
||||||
|
|
@ -96,7 +96,7 @@ void ImGuiModule::BeforeRender()
|
||||||
KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!");
|
KGE_ASSERT(io.Fonts->IsBuilt() && "Font atlas not built!");
|
||||||
|
|
||||||
// Setup display size (every frame to accommodate for window resizing)
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
Size display_size = Renderer::Instance().GetOutputSize();
|
Size display_size = Renderer::GetInstance().GetOutputSize();
|
||||||
io.DisplaySize = ImVec2(display_size.x, display_size.y);
|
io.DisplaySize = ImVec2(display_size.x, display_size.y);
|
||||||
|
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
@ -181,7 +181,7 @@ void ImGuiModule::UpdateMousePos()
|
||||||
::SetCursorPos(pos.x, pos.y);
|
::SetCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point pos = Input::Instance().GetMousePos();
|
Point pos = Input::GetInstance().GetMousePos();
|
||||||
io.MousePos = ImVec2(pos.x, pos.y);
|
io.MousePos = ImVec2(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,7 +219,7 @@ void ImGuiModule::UpdateMouseCursor()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Instance().SetCursor(cursor);
|
Window::GetInstance().SetCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace imgui
|
} // namespace imgui
|
||||||
|
|
|
||||||
|
|
@ -78,14 +78,14 @@ void Button::SetStatus(Status status)
|
||||||
|
|
||||||
if (status == Status::Normal)
|
if (status == Status::Normal)
|
||||||
{
|
{
|
||||||
Window::Instance().SetCursor(CursorType::Arrow);
|
Window::GetInstance().SetCursor(CursorType::Arrow);
|
||||||
|
|
||||||
if (mouse_out_callback_)
|
if (mouse_out_callback_)
|
||||||
mouse_out_callback_(this);
|
mouse_out_callback_(this);
|
||||||
}
|
}
|
||||||
else if (status == Status::Hover)
|
else if (status == Status::Hover)
|
||||||
{
|
{
|
||||||
Window::Instance().SetCursor(CursorType::Hand);
|
Window::GetInstance().SetCursor(CursorType::Hand);
|
||||||
|
|
||||||
if (old_status == Status::Pressed)
|
if (old_status == Status::Pressed)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ void DebugActor::OnUpdate(Duration dt)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto& status = Renderer::Instance().GetContext().GetStatus();
|
const auto& status = Renderer::GetInstance().GetContext().GetStatus();
|
||||||
|
|
||||||
ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl;
|
ss << "Render: " << status.duration.Milliseconds() << "ms" << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ Frame::Frame() {}
|
||||||
|
|
||||||
bool Frame::Load(String const& file_path)
|
bool Frame::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(file_path);
|
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(file_path);
|
||||||
if (texture->IsValid())
|
if (texture->IsValid())
|
||||||
{
|
{
|
||||||
SetTexture(texture);
|
SetTexture(texture);
|
||||||
|
|
@ -71,7 +71,7 @@ bool Frame::Load(String const& file_path)
|
||||||
|
|
||||||
bool Frame::Load(Resource const& res)
|
bool Frame::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
TexturePtr texture = TextureCache::Instance().AddOrGetTexture(res);
|
TexturePtr texture = TextureCache::GetInstance().AddOrGetTexture(res);
|
||||||
if (texture->IsValid())
|
if (texture->IsValid())
|
||||||
{
|
{
|
||||||
SetTexture(texture);
|
SetTexture(texture);
|
||||||
|
|
|
||||||
|
|
@ -67,13 +67,13 @@ GifSprite::GifSprite()
|
||||||
|
|
||||||
bool GifSprite::Load(String const& file_path)
|
bool GifSprite::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(file_path);
|
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(file_path);
|
||||||
return Load(image);
|
return Load(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GifSprite::Load(Resource const& res)
|
bool GifSprite::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
GifImagePtr image = TextureCache::Instance().AddOrGetGifImage(res);
|
GifImagePtr image = TextureCache::GetInstance().AddOrGetGifImage(res);
|
||||||
return Load(image);
|
return Load(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ Stage::Stage()
|
||||||
SetStage(this);
|
SetStage(this);
|
||||||
|
|
||||||
SetAnchor(Vec2{ 0, 0 });
|
SetAnchor(Vec2{ 0, 0 });
|
||||||
SetSize(Renderer::Instance().GetOutputSize());
|
SetSize(Renderer::GetInstance().GetOutputSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
Stage::~Stage() {}
|
Stage::~Stage() {}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ void Transition::Init(StagePtr prev, StagePtr next)
|
||||||
|
|
||||||
out_stage_ = prev;
|
out_stage_ = prev;
|
||||||
in_stage_ = next;
|
in_stage_ = next;
|
||||||
window_size_ = Renderer::Instance().GetOutputSize();
|
window_size_ = Renderer::GetInstance().GetOutputSize();
|
||||||
|
|
||||||
if (in_stage_)
|
if (in_stage_)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,26 +27,26 @@
|
||||||
#ifndef KGE_SYS_LOG
|
#ifndef KGE_SYS_LOG
|
||||||
#ifdef KGE_DEBUG
|
#ifdef KGE_DEBUG
|
||||||
#define KGE_SYS_LOG(FORMAT, ...) \
|
#define KGE_SYS_LOG(FORMAT, ...) \
|
||||||
::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__)
|
::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::System, FORMAT, __VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define KGE_SYS_LOG __noop
|
#define KGE_SYS_LOG __noop
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_WARN
|
#ifndef KGE_WARN
|
||||||
#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__)
|
#define KGE_WARN(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Warning, FORMAT, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_ERROR
|
#ifndef KGE_ERROR
|
||||||
#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__)
|
#define KGE_ERROR(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Error, FORMAT, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_LOG
|
#ifndef KGE_LOG
|
||||||
#define KGE_LOG(...) ::kiwano::Logger::Instance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__)
|
#define KGE_LOG(...) ::kiwano::Logger::GetInstance().Println(::kiwano::Logger::Level::Info, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef KGE_LOGF
|
#ifndef KGE_LOGF
|
||||||
#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::Instance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__)
|
#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::GetInstance().Printf(::kiwano::Logger::Level::Info, FORMAT, __VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ private:
|
||||||
{
|
{
|
||||||
ObjectCreator()
|
ObjectCreator()
|
||||||
{
|
{
|
||||||
(void)Singleton<_Ty>::Instance();
|
(void)Singleton<_Ty>::GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Dummy() const {}
|
inline void Dummy() const {}
|
||||||
|
|
@ -46,7 +46,7 @@ private:
|
||||||
public:
|
public:
|
||||||
using object_type = _Ty;
|
using object_type = _Ty;
|
||||||
|
|
||||||
static inline object_type& Instance()
|
static inline object_type& GetInstance()
|
||||||
{
|
{
|
||||||
static object_type instance;
|
static object_type instance;
|
||||||
creator_.Dummy();
|
creator_.Dummy();
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ Queue<FunctionToPerform> functions_to_perform_;
|
||||||
Application::Application()
|
Application::Application()
|
||||||
: time_scale_(1.f)
|
: time_scale_(1.f)
|
||||||
{
|
{
|
||||||
Use(&Renderer::Instance());
|
Use(&Renderer::GetInstance());
|
||||||
Use(&Input::Instance());
|
Use(&Input::GetInstance());
|
||||||
Use(&Director::Instance());
|
Use(&Director::GetInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
|
|
@ -61,8 +61,8 @@ void Application::Run(bool debug)
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
Director::Instance().ShowDebugInfo(true);
|
Director::GetInstance().ShowDebugInfo(true);
|
||||||
Renderer::Instance().GetContext().SetCollectingStatus(true);
|
Renderer::GetInstance().GetContext().SetCollectingStatus(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything is ready
|
// Everything is ready
|
||||||
|
|
@ -70,7 +70,7 @@ void Application::Run(bool debug)
|
||||||
|
|
||||||
last_update_time_ = Time::Now();
|
last_update_time_ = Time::Now();
|
||||||
|
|
||||||
Window& window = Window::Instance();
|
Window& window = Window::GetInstance();
|
||||||
while (!window.ShouldClose())
|
while (!window.ShouldClose())
|
||||||
{
|
{
|
||||||
while (EventPtr evt = window.PollEvent())
|
while (EventPtr evt = window.PollEvent())
|
||||||
|
|
@ -85,15 +85,15 @@ void Application::Run(bool debug)
|
||||||
|
|
||||||
void Application::Quit()
|
void Application::Quit()
|
||||||
{
|
{
|
||||||
Window::Instance().Destroy();
|
Window::GetInstance().Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Destroy()
|
void Application::Destroy()
|
||||||
{
|
{
|
||||||
// Clear all resources
|
// Clear all resources
|
||||||
Director::Instance().ClearStages();
|
Director::GetInstance().ClearStages();
|
||||||
ResourceCache::Instance().Clear();
|
ResourceCache::GetInstance().Clear();
|
||||||
TextureCache::Instance().Clear();
|
TextureCache::GetInstance().Clear();
|
||||||
|
|
||||||
for (auto iter = comps_.rbegin(); iter != comps_.rend(); ++iter)
|
for (auto iter = comps_.rbegin(); iter != comps_.rend(); ++iter)
|
||||||
{
|
{
|
||||||
|
|
@ -185,7 +185,7 @@ void Application::Update()
|
||||||
|
|
||||||
void Application::Render()
|
void Application::Render()
|
||||||
{
|
{
|
||||||
Renderer& renderer = Renderer::Instance();
|
Renderer& renderer = Renderer::GetInstance();
|
||||||
renderer.Clear();
|
renderer.Clear();
|
||||||
|
|
||||||
// Before render
|
// Before render
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ public:
|
||||||
* \~chinese
|
* \~chinese
|
||||||
* @brief 获取窗口实例
|
* @brief 获取窗口实例
|
||||||
*/
|
*/
|
||||||
static Window& Instance();
|
static Window& GetInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \~chinese
|
* \~chinese
|
||||||
|
|
|
||||||
|
|
@ -684,7 +684,7 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd, UINT32 msg, WPARAM wparam, LPARA
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
Window& Window::Instance()
|
Window& Window::GetInstance()
|
||||||
{
|
{
|
||||||
static win32::WindowImpl instance;
|
static win32::WindowImpl instance;
|
||||||
return instance;
|
return instance;
|
||||||
|
|
|
||||||
|
|
@ -112,17 +112,17 @@ void Brush::SetOpacity(float opacity)
|
||||||
|
|
||||||
void Brush::SetColor(Color const& color)
|
void Brush::SetColor(Color const& color)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateBrush(*this, color);
|
Renderer::GetInstance().CreateBrush(*this, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Brush::SetStyle(LinearGradientStyle const& style)
|
void Brush::SetStyle(LinearGradientStyle const& style)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateBrush(*this, style);
|
Renderer::GetInstance().CreateBrush(*this, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Brush::SetStyle(RadialGradientStyle const& style)
|
void Brush::SetStyle(RadialGradientStyle const& style)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateBrush(*this, style);
|
Renderer::GetInstance().CreateBrush(*this, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ bool Font::Load(String const& file)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateFontCollection(*this, file);
|
Renderer::GetInstance().CreateFontCollection(*this, file);
|
||||||
}
|
}
|
||||||
catch (std::runtime_error&)
|
catch (std::runtime_error&)
|
||||||
{
|
{
|
||||||
|
|
@ -65,7 +65,7 @@ bool Font::Load(Resource const& resource)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateFontCollection(*this, resource);
|
Renderer::GetInstance().CreateFontCollection(*this, resource);
|
||||||
}
|
}
|
||||||
catch (std::runtime_error&)
|
catch (std::runtime_error&)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ GifImage::GifImage()
|
||||||
|
|
||||||
bool GifImage::Load(String const& file_path)
|
bool GifImage::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateGifImage(*this, file_path);
|
Renderer::GetInstance().CreateGifImage(*this, file_path);
|
||||||
|
|
||||||
if (IsValid())
|
if (IsValid())
|
||||||
{
|
{
|
||||||
|
|
@ -70,7 +70,7 @@ bool GifImage::Load(String const& file_path)
|
||||||
|
|
||||||
bool GifImage::Load(Resource const& res)
|
bool GifImage::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateGifImage(*this, res);
|
Renderer::GetInstance().CreateGifImage(*this, res);
|
||||||
|
|
||||||
if (IsValid())
|
if (IsValid())
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +90,7 @@ bool GifImage::IsValid() const
|
||||||
GifImage::Frame GifImage::GetFrame(uint32_t index)
|
GifImage::Frame GifImage::GetFrame(uint32_t index)
|
||||||
{
|
{
|
||||||
Frame frame;
|
Frame frame;
|
||||||
Renderer::Instance().CreateGifImageFrame(frame, *this, index);
|
Renderer::GetInstance().CreateGifImageFrame(frame, *this, index);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ void Renderer::SetupComponent()
|
||||||
|
|
||||||
win32::ThrowIfFailed(::CoInitialize(nullptr));
|
win32::ThrowIfFailed(::CoInitialize(nullptr));
|
||||||
|
|
||||||
target_window_ = Window::Instance().GetHandle();
|
target_window_ = Window::GetInstance().GetHandle();
|
||||||
output_size_ = Window::Instance().GetSize();
|
output_size_ = Window::GetInstance().GetSize();
|
||||||
|
|
||||||
d2d_res_ = nullptr;
|
d2d_res_ = nullptr;
|
||||||
d3d_res_ = nullptr;
|
d3d_res_ = nullptr;
|
||||||
|
|
@ -197,7 +197,7 @@ void Renderer::CreateTexture(Texture& texture, String const& file_path)
|
||||||
hr = E_UNEXPECTED;
|
hr = E_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_WARN(L"Texture file '%s' not found!", file_path.c_str());
|
KGE_WARN(L"Texture file '%s' not found!", file_path.c_str());
|
||||||
hr = E_FAIL;
|
hr = E_FAIL;
|
||||||
|
|
@ -205,7 +205,7 @@ void Renderer::CreateTexture(Texture& texture, String const& file_path)
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
ComPtr<IWICBitmapDecoder> decoder;
|
ComPtr<IWICBitmapDecoder> decoder;
|
||||||
hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path);
|
hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path);
|
||||||
|
|
@ -295,7 +295,7 @@ void Renderer::CreateGifImage(GifImage& gif, String const& file_path)
|
||||||
hr = E_UNEXPECTED;
|
hr = E_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_WARN(L"Gif texture file '%s' not found!", file_path.c_str());
|
KGE_WARN(L"Gif texture file '%s' not found!", file_path.c_str());
|
||||||
hr = E_FAIL;
|
hr = E_FAIL;
|
||||||
|
|
@ -303,7 +303,7 @@ void Renderer::CreateGifImage(GifImage& gif, String const& file_path)
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
ComPtr<IWICBitmapDecoder> decoder;
|
ComPtr<IWICBitmapDecoder> decoder;
|
||||||
hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path);
|
hr = d2d_res_->CreateBitmapDecoderFromFile(decoder, full_path);
|
||||||
|
|
@ -514,7 +514,7 @@ void Renderer::CreateFontCollection(Font& font, String const& file_path)
|
||||||
|
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_WARN(L"Font file '%s' not found!", file_path.c_str());
|
KGE_WARN(L"Font file '%s' not found!", file_path.c_str());
|
||||||
hr = E_FAIL;
|
hr = E_FAIL;
|
||||||
|
|
@ -525,7 +525,7 @@ void Renderer::CreateFontCollection(Font& font, String const& file_path)
|
||||||
{
|
{
|
||||||
LPVOID key = nullptr;
|
LPVOID key = nullptr;
|
||||||
uint32_t key_size = 0;
|
uint32_t key_size = 0;
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
hr = font_collection_loader_->AddFilePaths({ full_path }, &key, &key_size);
|
hr = font_collection_loader_->AddFilePaths({ full_path }, &key, &key_size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,35 +108,35 @@ bool Shape::ContainsPoint(Point const& point, const Matrix3x2* transform) const
|
||||||
ShapePtr Shape::CreateLine(Point const& begin, Point const& end)
|
ShapePtr Shape::CreateLine(Point const& begin, Point const& end)
|
||||||
{
|
{
|
||||||
ShapePtr output = new Shape;
|
ShapePtr output = new Shape;
|
||||||
Renderer::Instance().CreateLineShape(*output, begin, end);
|
Renderer::GetInstance().CreateLineShape(*output, begin, end);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapePtr Shape::CreateRect(Rect const& rect)
|
ShapePtr Shape::CreateRect(Rect const& rect)
|
||||||
{
|
{
|
||||||
ShapePtr output = new Shape;
|
ShapePtr output = new Shape;
|
||||||
Renderer::Instance().CreateRectShape(*output, rect);
|
Renderer::GetInstance().CreateRectShape(*output, rect);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapePtr Shape::CreateRoundedRect(Rect const& rect, Vec2 const& radius)
|
ShapePtr Shape::CreateRoundedRect(Rect const& rect, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
ShapePtr output = new Shape;
|
ShapePtr output = new Shape;
|
||||||
Renderer::Instance().CreateRoundedRectShape(*output, rect, radius);
|
Renderer::GetInstance().CreateRoundedRectShape(*output, rect, radius);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapePtr Shape::CreateCircle(Point const& center, float radius)
|
ShapePtr Shape::CreateCircle(Point const& center, float radius)
|
||||||
{
|
{
|
||||||
ShapePtr output = new Shape;
|
ShapePtr output = new Shape;
|
||||||
Renderer::Instance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
|
Renderer::GetInstance().CreateEllipseShape(*output, center, Vec2{ radius, radius });
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShapePtr Shape::CreateEllipse(Point const& center, Vec2 const& radius)
|
ShapePtr Shape::CreateEllipse(Point const& center, Vec2 const& radius)
|
||||||
{
|
{
|
||||||
ShapePtr output = new Shape;
|
ShapePtr output = new Shape;
|
||||||
Renderer::Instance().CreateEllipseShape(*output, center, radius);
|
Renderer::GetInstance().CreateEllipseShape(*output, center, radius);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ void ShapeSink::Open()
|
||||||
if (!IsOpened())
|
if (!IsOpened())
|
||||||
{
|
{
|
||||||
path_geo_.reset();
|
path_geo_.reset();
|
||||||
Renderer::Instance().CreateShapeSink(*this);
|
Renderer::GetInstance().CreateShapeSink(*this);
|
||||||
|
|
||||||
win32::ThrowIfFailed(path_geo_->Open(&sink_));
|
win32::ThrowIfFailed(path_geo_->Open(&sink_));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ StrokeStylePtr StrokeStyle::Create(CapStyle cap, LineJoinStyle line_join, const
|
||||||
StrokeStylePtr ptr = new (std::nothrow) StrokeStyle;
|
StrokeStylePtr ptr = new (std::nothrow) StrokeStyle;
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateStrokeStyle(*ptr, cap, line_join, dash_array, dash_size, dash_offset);
|
Renderer::GetInstance().CreateStrokeStyle(*ptr, cap, line_join, dash_array, dash_size, dash_offset);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ void TextLayout::Update()
|
||||||
|
|
||||||
if (!text_format_ || (dirty_flag_ & DirtyFlag::DirtyFormat))
|
if (!text_format_ || (dirty_flag_ & DirtyFlag::DirtyFormat))
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTextFormat(*this);
|
Renderer::GetInstance().CreateTextFormat(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dirty_flag_ & DirtyFlag::DirtyLayout)
|
if (dirty_flag_ & DirtyFlag::DirtyLayout)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTextLayout(*this);
|
Renderer::GetInstance().CreateTextLayout(*this);
|
||||||
|
|
||||||
if (text_layout_)
|
if (text_layout_)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,13 +57,13 @@ Texture::~Texture() {}
|
||||||
|
|
||||||
bool Texture::Load(String const& file_path)
|
bool Texture::Load(String const& file_path)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTexture(*this, file_path);
|
Renderer::GetInstance().CreateTexture(*this, file_path);
|
||||||
return IsValid();
|
return IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Texture::Load(Resource const& res)
|
bool Texture::Load(Resource const& res)
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTexture(*this, res);
|
Renderer::GetInstance().CreateTexture(*this, res);
|
||||||
return IsValid();
|
return IsValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ TextureRenderContextPtr TextureRenderContext::Create()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTextureRenderContext(*ptr);
|
Renderer::GetInstance().CreateTextureRenderContext(*ptr);
|
||||||
}
|
}
|
||||||
catch (std::exception)
|
catch (std::exception)
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +49,7 @@ TextureRenderContextPtr TextureRenderContext::Create(Size const& desired_size)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Renderer::Instance().CreateTextureRenderContext(*ptr, &desired_size);
|
Renderer::GetInstance().CreateTextureRenderContext(*ptr, &desired_size);
|
||||||
}
|
}
|
||||||
catch (std::exception)
|
catch (std::exception)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ ResourceCache::~ResourceCache()
|
||||||
|
|
||||||
bool ResourceCache::LoadFromJsonFile(String const& file_path)
|
bool ResourceCache::LoadFromJsonFile(String const& file_path)
|
||||||
{
|
{
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"ResourceCache::LoadFromJsonFile failed: File not found.");
|
KGE_ERROR(L"ResourceCache::LoadFromJsonFile failed: File not found.");
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -65,7 +65,7 @@ bool ResourceCache::LoadFromJsonFile(String const& file_path)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
ifs.open(full_path.c_str());
|
ifs.open(full_path.c_str());
|
||||||
ifs >> json_data;
|
ifs >> json_data;
|
||||||
ifs.close();
|
ifs.close();
|
||||||
|
|
@ -116,13 +116,13 @@ bool ResourceCache::LoadFromJson(Json const& json_data)
|
||||||
|
|
||||||
bool ResourceCache::LoadFromXmlFile(String const& file_path)
|
bool ResourceCache::LoadFromXmlFile(String const& file_path)
|
||||||
{
|
{
|
||||||
if (!FileSystem::Instance().IsFileExists(file_path))
|
if (!FileSystem::GetInstance().IsFileExists(file_path))
|
||||||
{
|
{
|
||||||
KGE_ERROR(L"ResourceCache::LoadFromXmlFile failed: File not found.");
|
KGE_ERROR(L"ResourceCache::LoadFromXmlFile failed: File not found.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String full_path = FileSystem::Instance().GetFullPathForFile(file_path);
|
String full_path = FileSystem::GetInstance().GetFullPathForFile(file_path);
|
||||||
|
|
||||||
pugi::xml_document doc;
|
pugi::xml_document doc;
|
||||||
pugi::xml_parse_result result = doc.load_file(full_path.c_str(), pugi::parse_default, pugi::encoding_auto);
|
pugi::xml_parse_result result = doc.load_file(full_path.c_str(), pugi::parse_default, pugi::encoding_auto);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue