mirror of https://github.com/auygun/kaliber.git
Cleanup & refactor
This commit is contained in:
parent
67632ff144
commit
22d80d6152
|
@ -5,11 +5,6 @@
|
||||||
#include "engine/animatable.h"
|
#include "engine/animatable.h"
|
||||||
#include "engine/animator.h"
|
#include "engine/animator.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace eng {
|
namespace eng {
|
||||||
class Shader;
|
class Shader;
|
||||||
} // namespace eng
|
} // namespace eng
|
||||||
|
|
|
@ -276,14 +276,8 @@ void Engine::SetImageSource(const std::string& asset_name,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& t = textures_[asset_name] = {CreateRenderResource<Texture>(),
|
textures_[asset_name] = {std::make_unique<Texture>(renderer_.get()),
|
||||||
create_image, persistent, 0};
|
create_image, persistent, 0};
|
||||||
|
|
||||||
if (persistent) {
|
|
||||||
auto image = create_image();
|
|
||||||
if (image)
|
|
||||||
t.texture->Update(std::move(image));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::RefreshImage(const std::string& asset_name) {
|
void Engine::RefreshImage(const std::string& asset_name) {
|
||||||
|
@ -297,8 +291,6 @@ void Engine::RefreshImage(const std::string& asset_name) {
|
||||||
auto image = it->second.create_image();
|
auto image = it->second.create_image();
|
||||||
if (image)
|
if (image)
|
||||||
it->second.texture->Update(std::move(image));
|
it->second.texture->Update(std::move(image));
|
||||||
else
|
|
||||||
it->second.texture->Destroy();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,8 +302,11 @@ Texture* Engine::AcquireTexture(const std::string& asset_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
it->second.use_count++;
|
it->second.use_count++;
|
||||||
if (!it->second.texture->IsValid())
|
if (!it->second.texture->IsValid()) {
|
||||||
RefreshImage(it->first);
|
auto image = it->second.create_image();
|
||||||
|
if (image)
|
||||||
|
it->second.texture->Update(std::move(image));
|
||||||
|
}
|
||||||
return it->second.texture.get();
|
return it->second.texture.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +330,8 @@ void Engine::LoadCustomShader(const std::string& asset_name,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& s = shaders_[asset_name] = {CreateRenderResource<Shader>(), file_name};
|
auto& s = shaders_[asset_name] = {std::make_unique<Shader>(renderer_.get()),
|
||||||
|
file_name};
|
||||||
|
|
||||||
auto source = std::make_unique<ShaderSource>();
|
auto source = std::make_unique<ShaderSource>();
|
||||||
if (!source->Load(file_name))
|
if (!source->Load(file_name))
|
||||||
|
@ -623,7 +619,11 @@ void Engine::ContextLost() {
|
||||||
|
|
||||||
for (auto& t : textures_) {
|
for (auto& t : textures_) {
|
||||||
t.second.texture->SetRenderer(renderer_.get());
|
t.second.texture->SetRenderer(renderer_.get());
|
||||||
RefreshImage(t.first);
|
if (t.second.persistent || t.second.use_count > 0) {
|
||||||
|
auto image = t.second.create_image();
|
||||||
|
if (image)
|
||||||
|
t.second.texture->Update(std::move(image));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& s : shaders_) {
|
for (auto& s : shaders_) {
|
||||||
|
|
|
@ -61,11 +61,6 @@ class Engine : public PlatformObserver {
|
||||||
// Convert position form pixels to viewport coordinates.
|
// Convert position form pixels to viewport coordinates.
|
||||||
base::Vector2f ToPosition(const base::Vector2f& vec);
|
base::Vector2f ToPosition(const base::Vector2f& vec);
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
std::unique_ptr<T> CreateRenderResource() {
|
|
||||||
return std::unique_ptr<T>(static_cast<T*>(new T(renderer_.get())));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetImageSource(const std::string& asset_name,
|
void SetImageSource(const std::string& asset_name,
|
||||||
const std::string& file_name,
|
const std::string& file_name,
|
||||||
bool persistent = false);
|
bool persistent = false);
|
||||||
|
|
|
@ -32,7 +32,6 @@ void ImageQuad::Create(const std::string& asset_name,
|
||||||
asset_name_ = asset_name;
|
asset_name_ = asset_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: typo
|
|
||||||
void ImageQuad::Destroy() {
|
void ImageQuad::Destroy() {
|
||||||
if (texture_) {
|
if (texture_) {
|
||||||
Engine::Get().ReleaseTexture(asset_name_);
|
Engine::Get().ReleaseTexture(asset_name_);
|
||||||
|
|
Loading…
Reference in New Issue