This commit is contained in:
Mikulas Florek 2019-06-26 18:52:52 +02:00
parent 84061a540a
commit c3f2aa170e
20 changed files with 26 additions and 194 deletions

View file

@ -151,26 +151,6 @@ Path::Path(const Path& rhs)
}
Path::Path(const char* s1, const char* s2)
{
StaticString<MAX_PATH_LENGTH> tmp(s1, s2);
char out[MAX_PATH_LENGTH];
PathUtils::normalize(tmp, out, lengthOf(out));
u32 hash = crc32(out);
m_data = g_path_manager->getPath(hash, out);
}
Path::Path(const char* s1, const char* s2, const char* s3)
{
StaticString<MAX_PATH_LENGTH> tmp(s1, s2, s3);
char out[MAX_PATH_LENGTH];
PathUtils::normalize(tmp, out, lengthOf(out));
u32 hash = crc32(out);
m_data = g_path_manager->getPath(hash, out);
}
Path::Path(const char* path)
{
char tmp[MAX_PATH_LENGTH];

View file

@ -25,8 +25,6 @@ class LUMIX_ENGINE_API Path
public:
Path();
Path(const Path& rhs);
Path(const char* s1, const char* s2);
Path(const char* s1, const char* s2, const char* s3);
explicit Path(u32 hash);
explicit Path(const char* path);
~Path();

View file

@ -2,9 +2,7 @@
#include "engine/string.h"
namespace Lumix
{
namespace PathUtils
namespace Lumix::PathUtils
{
void normalize(const char* path, char* out, u32 max_size)
@ -81,20 +79,6 @@ void getBasename(char* basename, int max_length, const char* src)
}
}
void getFilename(char* filename, int max_length, const char* src)
{
for (int i = stringLength(src) - 1; i >= 0; --i)
{
if (src[i] == '\\' || src[i] == '/')
{
++i;
copyString(filename, max_length, src + i);
return;
}
}
copyString(filename, max_length, src);
}
void getExtension(char* extension, int max_length, const char* src)
{
@ -147,9 +131,4 @@ bool hasExtension(const char* filename, const char* ext)
}
bool isAbsolute(const char* path)
{
return path[0] != '\0' && path[1] == ':';
}
}
}
} // namespace Lumix::PathUtils

View file

@ -11,11 +11,9 @@ namespace PathUtils
LUMIX_ENGINE_API void normalize(const char* path, char* out, u32 max_size);
LUMIX_ENGINE_API void getDir(char* dir, int max_length, const char* src);
LUMIX_ENGINE_API void getBasename(char* basename, int max_length, const char* src);
LUMIX_ENGINE_API void getFilename(char* filename, int max_length, const char* src);
LUMIX_ENGINE_API void getExtension(char* extension, int max_length, const char* src);
LUMIX_ENGINE_API bool hasExtension(const char* filename, const char* ext);
LUMIX_ENGINE_API bool replaceExtension(char* path, const char* ext);
LUMIX_ENGINE_API bool isAbsolute(const char* path);
struct LUMIX_ENGINE_API FileInfo

View file

@ -284,12 +284,6 @@ static char makeLowercase(char c)
}
char makeUppercase(char c)
{
return c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c;
}
int compareMemory(const void* lhs, const void* rhs, size_t size)
{
return memcmp(lhs, rhs, size);
@ -413,29 +407,6 @@ bool makeLowercase(char* destination, int length, const char* source)
}
bool makeUppercase(char* destination, int length, const char* source)
{
if (!source)
{
return false;
}
while (*source && length)
{
*destination = makeUppercase(*source);
--length;
++destination;
++source;
}
if (length > 0)
{
*destination = 0;
return true;
}
return false;
}
const char* findSubstring(const char* haystack, const char* needle)
{
return strstr(haystack, needle);
@ -1016,16 +987,6 @@ bool toCString(double value, char* output, int length, int after_point)
}
char* trimmed(char* str)
{
while (*str && (*str == '\t' || *str == ' '))
{
++str;
}
return str;
}
bool startsWith(const char* str, const char* prefix)
{
const char* lhs = str;

View file

@ -36,9 +36,6 @@ LUMIX_ENGINE_API bool copyNString(char* destination,
LUMIX_ENGINE_API bool catString(char* destination, int length, const char* source);
LUMIX_ENGINE_API bool catNString(char* destination, int length, const char* source, int source_len);
LUMIX_ENGINE_API bool makeLowercase(char* destination, int length, const char* source);
LUMIX_ENGINE_API char makeUppercase(char c);
LUMIX_ENGINE_API bool makeUppercase(char* destination, int length, const char* source);
LUMIX_ENGINE_API char* trimmed(char* str);
LUMIX_ENGINE_API bool startsWith(const char* str, const char* prefix);
LUMIX_ENGINE_API int stringLength(const char* str);
LUMIX_ENGINE_API bool equalStrings(const char* lhs, const char* rhs);

View file

@ -12,7 +12,7 @@
#include "engine/universe/universe.h"
#include "gui_scene.h"
#include "gui_system.h"
#include "renderer/font_manager.h"
#include "renderer/font.h"
#include "renderer/pipeline.h"
#include "renderer/texture.h"
#include "sprite.h"

View file

@ -13,7 +13,7 @@
#include "engine/universe/universe.h"
#include "gui/gui_scene.h"
#include "gui/sprite.h"
#include "renderer/font_manager.h"
#include "renderer/font.h"
#include "renderer/material.h"
#include "renderer/pipeline.h"
#include "renderer/renderer.h"

View file

@ -29,7 +29,7 @@
#include "game_view.h"
#include "renderer/culling_system.h"
#include "renderer/ffr/ffr.h"
#include "renderer/font_manager.h"
#include "renderer/font.h"
#include "renderer/material.h"
#include "renderer/model.h"
#include "renderer/particle_system.h"
@ -2055,7 +2055,7 @@ struct RenderInterfaceImpl final : public RenderInterface
Texture* old_texture = material->getTexture(0);
PluginManager& plugin_manager = engine.getPluginManager();
Texture* texture = LUMIX_NEW(engine.getAllocator(), Texture)(
Path("font"), m_renderer, *engine.getResourceManager().get(Texture::TYPE), engine.getAllocator());
Path("font"), *engine.getResourceManager().get(Texture::TYPE), m_renderer, engine.getAllocator());
texture->create(width, height, pixels, width * height * 4);
material->setTexture(0, texture);
@ -2099,7 +2099,7 @@ struct RenderInterfaceImpl final : public RenderInterface
auto& rm = engine.getResourceManager();
auto& allocator = m_editor.getAllocator();
Texture* texture = LUMIX_NEW(allocator, Texture)(Path(name), m_renderer, *rm.get(Texture::TYPE), allocator);
Texture* texture = LUMIX_NEW(allocator, Texture)(Path(name), *rm.get(Texture::TYPE), m_renderer, allocator);
texture->create(w, h, pixels, w * h * 4);
m_textures.insert(&texture->handle, texture);
return (ImTextureID)(uintptr_t)texture->handle.value;

View file

@ -1314,7 +1314,7 @@ void TerrainEditor::onGUI()
IPlugin* plugin = m_world_editor.getEngine().getPluginManager().getPlugin("renderer");
Renderer& renderer = *static_cast<Renderer*>(plugin);
m_brush_texture = LUMIX_NEW(m_world_editor.getAllocator(), Texture)(
Path("brush_texture"), renderer, *rm.get(Texture::TYPE), m_world_editor.getAllocator());
Path("brush_texture"), *rm.get(Texture::TYPE), renderer, m_world_editor.getAllocator());
m_brush_texture->create(image_width, image_height, data, image_width * image_height * 4);
stbi_image_free(data);

View file

@ -1,7 +1,6 @@
#include "engine/stream.h"
#include "font_manager.h"
#include "font.h"
#include "renderer/texture.h"
#include "renderer/texture_manager.h"
#include "renderer/renderer.h"
@ -96,7 +95,7 @@ void FontManager::updateFontTexture()
else
{
auto& texture_manager = m_renderer.getTextureManager();
m_atlas_texture = LUMIX_NEW(m_allocator, Texture)(Path("draw2d_atlas"), m_renderer, texture_manager, m_allocator);
m_atlas_texture = LUMIX_NEW(m_allocator, Texture)(Path("draw2d_atlas"), texture_manager, m_renderer, m_allocator);
}
m_atlas_texture->create(w, h, pixels, w * h * 4);

View file

@ -17,7 +17,7 @@
#include "engine/resource_manager.h"
#include "engine/universe/universe.h"
#include "culling_system.h"
#include "font_manager.h"
#include "font.h"
#include "material.h"
#include "model.h"
#include "particle_system.h"
@ -235,7 +235,6 @@ struct PipelineImpl final : Pipeline
m_draw2d_shader = rm.load<Shader>(Path("pipelines/draw2d.shd"));
m_debug_shape_shader = rm.load<Shader>(Path("pipelines/debug_shape.shd"));
m_text_mesh_shader = rm.load<Shader>(Path("pipelines/text_mesh.shd"));
TextureManager& texture_manager = renderer.getTextureManager();
m_default_cubemap = rm.load<Texture>(Path("textures/common/default_probe.dds"));
FontAtlas& font_atlas = m_renderer.getFontManager().getFontAtlas();

View file

@ -20,7 +20,7 @@
#include "engine/universe/universe.h"
#include "lua_script/lua_script_system.h"
#include "renderer/culling_system.h"
#include "renderer/font_manager.h"
#include "renderer/font.h"
#include "renderer/material.h"
#include "renderer/model.h"
#include "renderer/particle_system.h"
@ -1684,10 +1684,7 @@ public:
if (m_culling_system->isAdded(entity)) {
if (m_universe.hasComponent(entity, MODEL_INSTANCE_TYPE)) {
ModelInstance& r = m_model_instances[entity.index];
const float radius = m_universe.getScale(entity) * r.model->getBoundingRadius();
const DVec3 position = m_universe.getPosition(entity);
m_culling_system->setRadius(entity, radius);
m_culling_system->setPosition(entity, position);
}
else if (m_universe.hasComponent(entity, DECAL_TYPE)) {

View file

@ -17,7 +17,7 @@
#include "engine/string.h"
#include "engine/universe/component.h"
#include "engine/universe/universe.h"
#include "renderer/font_manager.h"
#include "renderer/font.h"
#include "renderer/material.h"
#include "renderer/model.h"
#include "renderer/pipeline.h"
@ -26,7 +26,7 @@
#include "renderer/shader.h"
#include "renderer/terrain.h"
#include "renderer/texture.h"
#include "renderer/texture_manager.h"
#include <Windows.h>
#undef near
@ -845,7 +845,7 @@ struct RendererImpl final : public Renderer
}
TextureManager& getTextureManager() override { return m_texture_manager; }
ResourceManager& getTextureManager() override { return m_texture_manager; }
FontManager& getFontManager() override { return *m_font_manager; }
void createScenes(Universe& ctx) override
@ -956,13 +956,13 @@ struct RendererImpl final : public Renderer
IAllocator& m_allocator;
Array<ShaderDefine> m_shader_defines;
Array<StaticString<32>> m_layers;
TextureManager m_texture_manager;
FontManager* m_font_manager;
RenderResourceManager<Material> m_material_manager;
RenderResourceManager<Model> m_model_manager;
RenderResourceManager<ParticleEmitterResource> m_particle_emitter_manager;
RenderResourceManager<PipelineResource> m_pipeline_manager;
RenderResourceManager<Shader> m_shader_manager;
RenderResourceManager<Texture> m_texture_manager;
bool m_vsync;
JobSystem::SignalHandle m_last_exec_job = JobSystem::INVALID_HANDLE;
JobSystem::SignalHandle m_prev_frame_job = JobSystem::INVALID_HANDLE;

View file

@ -58,7 +58,7 @@ class LUMIX_RENDERER_API Renderer : public IPlugin
virtual const char* getShaderDefine(int define_idx) const = 0;
virtual int getShaderDefinesCount() const = 0;
virtual FontManager& getFontManager() = 0;
virtual TextureManager& getTextureManager() = 0;
virtual ResourceManager& getTextureManager() = 0;
virtual IAllocator& getAllocator() = 0;
virtual MemRef allocate(uint size) = 0;

View file

@ -8,7 +8,6 @@
#include "engine/stream.h"
#include "renderer/renderer.h"
#include "renderer/texture.h"
#include "renderer/texture_manager.h"
namespace Lumix
@ -18,7 +17,7 @@ namespace Lumix
const ResourceType Texture::TYPE("texture");
Texture::Texture(const Path& path, Renderer& renderer, ResourceManager& resource_manager, IAllocator& _allocator)
Texture::Texture(const Path& path, ResourceManager& resource_manager, Renderer& renderer, IAllocator& _allocator)
: Resource(path, resource_manager, _allocator)
, data_reference(0)
, allocator(_allocator)
@ -482,12 +481,12 @@ bool Texture::loadTGA(IInputStream& file)
height = header.height;
int pixel_count = width * height;
is_cubemap = false;
TextureManager& manager = static_cast<TextureManager&>(getResourceManager());
if (data_reference)
{
data.resize(image_size);
}
u8* image_dest = data_reference ? &data[0] : (u8*)manager.getBuffer(image_size);
if (data_reference) data.resize(image_size);
Renderer::MemRef mem;
if (!data_reference) mem = renderer.allocate(image_size);
u8* image_dest = data_reference ? &data[0] : (u8*)mem.data;
bool is_rle = header.dataType == 10;
if (is_rle)
@ -574,7 +573,7 @@ bool Texture::loadTGA(IInputStream& file)
bytes_per_pixel = 4;
mips = 1;
Renderer::MemRef mem = renderer.copy(image_dest, image_size);
if (data_reference) mem = renderer.copy(image_dest, image_size);
handle = renderer.createTexture(header.width, header.height, 1, ffr::TextureFormat::RGBA8, getFFRFlags(), mem, getPath().c_str());
depth = 1;
layers = 1;

View file

@ -39,7 +39,7 @@ public:
};
public:
Texture(const Path& path, Renderer& renderer, ResourceManager& resource_manager, IAllocator& allocator);
Texture(const Path& path, ResourceManager& resource_manager, Renderer& renderer, IAllocator& allocator);
~Texture();
ResourceType getType() const override { return TYPE; }

View file

@ -1,50 +0,0 @@
#include "engine/lumix.h"
#include "renderer/texture_manager.h"
#include "engine/resource.h"
#include "renderer/texture.h"
namespace Lumix
{
TextureManager::TextureManager(Renderer& renderer, IAllocator& allocator)
: ResourceManager(allocator)
, m_allocator(allocator)
, m_renderer(renderer)
{
m_buffer = nullptr;
m_buffer_size = -1;
}
TextureManager::~TextureManager()
{
m_allocator.deallocate(m_buffer);
}
Resource* TextureManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Texture)(path, m_renderer, *this, m_allocator);
}
void TextureManager::destroyResource(Resource& resource)
{
LUMIX_DELETE(m_allocator, static_cast<Texture*>(&resource));
}
u8* TextureManager::getBuffer(i32 size)
{
if (m_buffer_size < size)
{
m_allocator.deallocate(m_buffer);
m_buffer = nullptr;
m_buffer_size = -1;
}
if (m_buffer == nullptr)
{
m_buffer = (u8*)m_allocator.allocate(sizeof(u8) * size);
m_buffer_size = size;
}
return m_buffer;
}
}

View file

@ -1,25 +0,0 @@
#pragma once
#include "engine/resource_manager.h"
namespace Lumix
{
class LUMIX_RENDERER_API TextureManager final : public ResourceManager
{
public:
explicit TextureManager(class Renderer& renderer, IAllocator& allocator);
~TextureManager();
u8* getBuffer(i32 size);
protected:
Resource* createResource(const Path& path) override;
void destroyResource(Resource& resource) override;
private:
IAllocator& m_allocator;
Renderer& m_renderer;
u8* m_buffer;
i32 m_buffer_size;
};
}