This commit is contained in:
Mikulas Florek 2016-07-25 01:02:36 +02:00
parent 97f708b6e7
commit 944e5ca229
37 changed files with 105 additions and 136 deletions

View file

@ -19,7 +19,7 @@ static const ResourceType ANIMATION_TYPE("animation");
Resource* AnimationManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Animation)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Animation)(path, *this, m_allocator);
}
@ -29,7 +29,7 @@ void AnimationManager::destroyResource(Resource& resource)
}
Animation::Animation(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
Animation::Animation(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_bone_count(-1)
, m_rotations(nullptr)
@ -136,7 +136,7 @@ bool Animation::load(FS::IFile& file)
IAllocator& Animation::getAllocator()
{
return static_cast<AnimationManager*>(m_resource_manager.get(ANIMATION_TYPE))->getAllocator();
return static_cast<AnimationManager&>(m_resource_manager).getAllocator();
}

View file

@ -21,7 +21,7 @@ struct Vec3;
class AnimationManager : public ResourceManagerBase
{
public:
explicit AnimationManager(IAllocator& allocator)
explicit AnimationManager(IAllocator& allocator)
: ResourceManagerBase(allocator)
, m_allocator(allocator)
{}
@ -51,7 +51,7 @@ class Animation : public Resource
};
public:
Animation(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Animation(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~Animation();
void getPose(float time, Pose& pose, Model& model) const;

View file

@ -124,9 +124,7 @@ struct AnimationSceneImpl : public AnimationScene
{
if (!animation) return;
auto& rm = animation->getResourceManager();
auto* animation_manager = rm.get(ANIMATION_TYPE);
animation_manager->unload(*animation);
animation->getResourceManager().unload(*animation);
}

View file

@ -93,7 +93,7 @@ struct AudioSceneImpl : public AudioScene
{
for (auto* clip : m_clips)
{
clip->clip->getResourceManager().get(CLIP_RESOURCE_TYPE)->unload(*clip->clip);
clip->clip->getResourceManager().unload(*clip->clip);
LUMIX_DELETE(m_allocator, clip);
}
m_clips.clear();
@ -474,7 +474,7 @@ struct AudioSceneImpl : public AudioScene
auto* clip = info->clip;
if (clip)
{
clip->getResourceManager().get(CLIP_RESOURCE_TYPE)->unload(*clip);
clip->getResourceManager().unload(*clip);
}
LUMIX_DELETE(m_allocator, info);
m_clips.eraseItem(info);
@ -504,7 +504,7 @@ struct AudioSceneImpl : public AudioScene
auto* clip = m_clips[clip_id]->clip;
if (clip)
{
clip->getResourceManager().get(CLIP_RESOURCE_TYPE)->unload(*clip);
clip->getResourceManager().unload(*clip);
}
auto* new_res = m_system.getClipManager().load(path);
m_clips[clip_id]->clip = static_cast<Clip*>(new_res);

View file

@ -35,7 +35,7 @@ bool Clip::load(FS::IFile& file)
Resource* ClipManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Clip)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Clip)(path, *this, m_allocator);
}

View file

@ -13,7 +13,7 @@ namespace Lumix
class Clip : public Resource
{
public:
Clip(const Path& path, ResourceManager& manager, IAllocator& allocator)
Clip(const Path& path, ResourceManagerBase& manager, IAllocator& allocator)
: Resource(path, manager, allocator)
, m_data(allocator)
{

View file

@ -137,9 +137,7 @@ void AssetBrowser::unloadResource()
{
plugin->onResourceUnloaded(m_selected_resource);
}
m_selected_resource->getResourceManager()
.get(getResourceType(m_selected_resource->getPath().c_str()))
->unload(*m_selected_resource);
m_selected_resource->getResourceManager().unload(*m_selected_resource);
m_selected_resource = nullptr;
}

View file

@ -12,7 +12,7 @@ namespace Lumix
struct PrefabResource : public Resource
{
PrefabResource(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
PrefabResource(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, blob(allocator)
{
@ -46,7 +46,7 @@ public:
protected:
Resource* createResource(const Path& path) override
{
return LUMIX_NEW(m_allocator, PrefabResource)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, PrefabResource)(path, *this, m_allocator);
}

View file

@ -4,7 +4,10 @@
#include "engine/log.h"
#include "engine/lumix.h"
#include "engine/path.h"
#include "engine/resource.h"
#include "engine/resource_manager.h"
#include "engine/resource_manager_base.h"
namespace Lumix
{
@ -17,7 +20,7 @@ ResourceType::ResourceType(const char* type_name)
}
Resource::Resource(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
Resource::Resource(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: m_ref_count()
, m_empty_dep_count(1)
, m_failed_dep_count(0)
@ -126,7 +129,7 @@ void Resource::doLoad()
if (m_is_waiting_for_load) return;
m_is_waiting_for_load = true;
FS::FileSystem& fs = m_resource_manager.getFileSystem();
FS::FileSystem& fs = m_resource_manager.getOwner().getFileSystem();
FS::ReadCallback cb;
cb.bind<Resource, &Resource::fileLoaded>(this);
fs.openAsync(fs.getDefaultDevice(), m_path, FS::Mode::OPEN_AND_READ, cb);

View file

@ -49,7 +49,7 @@ public:
ObserverCallback& getObserverCb() { return m_cb; }
size_t size() const { return m_size; }
const Path& getPath() const { return m_path; }
ResourceManager& getResourceManager() { return m_resource_manager; }
ResourceManagerBase& getResourceManager() { return m_resource_manager; }
template <typename C, void (C::*Function)(State, State)> void onLoaded(C* instance)
{
@ -61,7 +61,7 @@ public:
}
protected:
Resource(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Resource(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
virtual ~Resource();
virtual void onBeforeReady() {}
@ -78,7 +78,7 @@ protected:
State m_desired_state;
uint16 m_empty_dep_count;
size_t m_size;
ResourceManager& m_resource_manager;
ResourceManagerBase& m_resource_manager;
protected:
void checkState();

View file

@ -49,12 +49,12 @@ public:
ResourceManagerBase(IAllocator& allocator);
virtual ~ResourceManagerBase();
ResourceManager& getOwner() const { return *m_owner; }
protected:
virtual Resource* createResource(const Path& path) = 0;
virtual void destroyResource(Resource& resource) = 0;
ResourceManager& getOwner() const { return *m_owner; }
private:
IAllocator& m_allocator;
uint32 m_size;

View file

@ -45,6 +45,12 @@ Universe::Universe(IAllocator& allocator)
}
IScene* Universe::getScene(ComponentType type) const
{
return m_component_type_scene_map[type.index];
}
IScene* Universe::getScene(uint32 hash) const
{
for (auto* scene : m_scenes)
@ -406,12 +412,6 @@ void Universe::registerComponentTypeScene(ComponentType type, IScene* scene)
}
IScene* Universe::getScene(ComponentType type) const
{
return m_component_type_scene_map[type.index];
}
ComponentUID Universe::getFirstComponent(Entity entity) const
{
uint64 mask = m_components[m_entity_map[entity.index]];

View file

@ -45,7 +45,6 @@ public:
ComponentUID getComponent(Entity entity, ComponentType type) const;
ComponentUID getFirstComponent(Entity entity) const;
ComponentUID getNextComponent(const ComponentUID& cmp) const;
IScene* getScene(ComponentType type) const;
void registerComponentTypeScene(ComponentType type, IScene* scene);
int getEntityCount() const { return m_transformations.size(); }
@ -83,6 +82,7 @@ public:
void serialize(OutputBlob& serializer);
void deserialize(InputBlob& serializer);
IScene* getScene(ComponentType type) const;
IScene* getScene(uint32 hash) const;
Array<IScene*>& getScenes();
void addScene(IScene* scene);

View file

@ -80,15 +80,8 @@ struct GUIRenderer : public TBRendererBatcher
~GUIRenderer()
{
auto* material_manager = m_material->getResourceManager().get(ResourceType("material"));
material_manager->unload(*m_material);
if (m_pipeline)
{
m_pipeline->destroyUniform(m_texture_uniform);
auto* material_manager = m_material->getResourceManager().get(ResourceType("material"));
material_manager->unload(*m_material);
}
if (m_material) m_material->getResourceManager().unload(*m_material);
if (m_pipeline) m_pipeline->destroyUniform(m_texture_uniform);
}

View file

@ -9,9 +9,7 @@ namespace Lumix
{
LuaScript::LuaScript(const Path& path,
ResourceManager& resource_manager,
IAllocator& allocator)
LuaScript::LuaScript(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_source_code(allocator)
{
@ -80,7 +78,7 @@ LuaScriptManager::~LuaScriptManager()
Resource* LuaScriptManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, LuaScript)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, LuaScript)(path, *this, m_allocator);
}

View file

@ -14,9 +14,7 @@ namespace Lumix
class LuaScript : public Resource
{
public:
LuaScript(const Path& path,
ResourceManager& resource_manager,
IAllocator& allocator);
LuaScript(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
virtual ~LuaScript();
void unload() override;

View file

@ -784,7 +784,7 @@ namespace Lumix
void unloadScript(LuaScript* script)
{
if (!script) return;
script->getResourceManager().get(LUA_SCRIPT_RESOURCE_TYPE)->unload(*script);
script->getResourceManager().unload(*script);
}

View file

@ -86,7 +86,7 @@ struct InputStream : public physx::PxInputStream
Resource* PhysicsGeometryManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, PhysicsGeometry)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, PhysicsGeometry)(path, *this, m_allocator);
}
@ -96,7 +96,7 @@ void PhysicsGeometryManager::destroyResource(Resource& resource)
}
PhysicsGeometry::PhysicsGeometry(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
PhysicsGeometry::PhysicsGeometry(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_geometry(nullptr)
{
@ -124,8 +124,7 @@ bool PhysicsGeometry::load(FS::IFile& file)
return false;
}
auto* phy_manager = m_resource_manager.get(PHYSICS_TYPE);
PhysicsSystem& system = static_cast<PhysicsGeometryManager*>(phy_manager)->getSystem();
PhysicsSystem& system = static_cast<PhysicsGeometryManager&>(m_resource_manager).getSystem();
int32 num_verts;
Array<Vec3> verts(getAllocator());
@ -190,7 +189,7 @@ bool PhysicsGeometry::load(FS::IFile& file)
IAllocator& PhysicsGeometry::getAllocator()
{
return static_cast<PhysicsGeometryManager*>(m_resource_manager.get(PHYSICS_TYPE))->getAllocator();
return static_cast<PhysicsGeometryManager&>(m_resource_manager).getAllocator();
}

View file

@ -60,7 +60,7 @@ class PhysicsGeometry : public Resource
};
public:
PhysicsGeometry(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
PhysicsGeometry(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~PhysicsGeometry();
physx::PxGeometry* getGeometry() { return m_geometry; }

View file

@ -3541,7 +3541,7 @@ void PhysicsSceneImpl::RigidActor::setResource(PhysicsGeometry* _resource)
if (resource)
{
resource->getObserverCb().unbind<RigidActor, &RigidActor::onStateChanged>(this);
resource->getResourceManager().get(PHYSICS_TYPE)->unload(*resource);
resource->getResourceManager().unload(*resource);
}
resource = _resource;
if (resource)
@ -3566,11 +3566,8 @@ Heightfield::~Heightfield()
if(m_actor) m_actor->release();
if (m_heightmap)
{
m_heightmap->getResourceManager()
.get(TEXTURE_TYPE)
->unload(*m_heightmap);
m_heightmap->getObserverCb().unbind<Heightfield, &Heightfield::heightmapLoaded>(
this);
m_heightmap->getResourceManager().unload(*m_heightmap);
m_heightmap->getObserverCb().unbind<Heightfield, &Heightfield::heightmapLoaded>(this);
}
}

View file

@ -1040,7 +1040,7 @@ struct SceneViewPlugin : public StudioApp::IPlugin
auto iter = m_textures.find(handle);
if (iter == m_textures.end()) return;
auto* texture = iter.value();
texture->getResourceManager().get(TEXTURE_TYPE)->unload(*texture);
texture->getResourceManager().unload(*texture);
m_textures.erase(iter);
}
@ -1102,7 +1102,7 @@ struct SceneViewPlugin : public StudioApp::IPlugin
void unloadModel(ModelHandle handle) override
{
auto* model = m_models[handle];
model->getResourceManager().get(MODEL_TYPE)->unload(*model);
model->getResourceManager().unload(*model);
m_models.erase(handle);
}
@ -1368,7 +1368,7 @@ struct GameViewPlugin : public StudioApp::IPlugin
m_material = static_cast<Material*>(resource);
Texture* texture = LUMIX_NEW(editor.getAllocator(), Texture)(
Path("font"), m_engine->getResourceManager(), editor.getAllocator());
Path("font"), *m_engine->getResourceManager().get(TEXTURE_TYPE), editor.getAllocator());
texture->create(width, height, pixels);
m_material->setTexture(0, texture);
@ -1404,7 +1404,7 @@ struct GameViewPlugin : public StudioApp::IPlugin
texture->destroy();
LUMIX_DELETE(m_app.getWorldEditor()->getAllocator(), texture);
m_material->getResourceManager().get(MATERIAL_TYPE)->unload(*m_material);
m_material->getResourceManager().unload(*m_material);
}

View file

@ -32,6 +32,7 @@
static const Lumix::ComponentType RENDERABLE_TYPE = Lumix::PropertyRegister::getComponentType("renderable");
static const Lumix::ComponentType TERRAIN_TYPE = Lumix::PropertyRegister::getComponentType("terrain");
static const Lumix::ResourceType MATERIAL_TYPE("material");
static const Lumix::ResourceType TEXTURE_TYPE("texture");
static const char* HEIGHTMAP_UNIFORM = "u_texHeightmap";
static const char* SPLATMAP_UNIFORM = "u_texSplatmap";
static const char* COLORMAP_UNIFORM = "u_texColormap";
@ -1287,7 +1288,7 @@ void TerrainEditor::onGUI()
LUMIX_DELETE(m_world_editor.getAllocator(), m_brush_texture);
}
m_brush_texture = LUMIX_NEW(m_world_editor.getAllocator(), Lumix::Texture)(
Lumix::Path("brush_texture"), rm, m_world_editor.getAllocator());
Lumix::Path("brush_texture"), *rm.get(TEXTURE_TYPE), m_world_editor.getAllocator());
m_brush_texture->create(image_width, image_height, data);
stbi_image_free(data);

View file

@ -35,7 +35,7 @@ static struct CustomFlags
static uint8 DEFAULT_COMMAND_BUFFER = 0;
Material::Material(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
Material::Material(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_shader(nullptr)
, m_uniforms(allocator)
@ -136,7 +136,7 @@ void Material::unload(void)
m_uniforms.clear();
setShader(nullptr);
ResourceManagerBase* texture_manager = m_resource_manager.get(TEXTURE_TYPE);
ResourceManagerBase* texture_manager = m_resource_manager.getOwner().get(TEXTURE_TYPE);
for (int i = 0; i < m_texture_count; i++)
{
if (m_textures[i])
@ -155,8 +155,7 @@ bool Material::save(JsonSerializer& serializer)
if(!isReady()) return false;
if(!m_shader) return false;
auto* manager = getResourceManager().get(MATERIAL_TYPE);
auto& renderer = static_cast<MaterialManager*>(manager)->getRenderer();
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
serializer.beginObject();
serializer.serialize("shader", m_shader ? m_shader->getPath() : Path(""));
@ -293,8 +292,7 @@ void Material::deserializeCustomFlags(JsonSerializer& serializer)
void Material::deserializeDefines(JsonSerializer& serializer)
{
auto* manager = getResourceManager().get(MATERIAL_TYPE);
auto& renderer = static_cast<MaterialManager*>(manager)->getRenderer();
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
serializer.deserializeArrayBegin();
m_define_mask = 0;
while (!serializer.isArrayEnd())
@ -382,8 +380,7 @@ void Material::setTexturePath(int i, const Path& path)
}
else
{
Texture* texture =
static_cast<Texture*>(m_resource_manager.get(TEXTURE_TYPE)->load(path));
Texture* texture = static_cast<Texture*>(m_resource_manager.getOwner().get(TEXTURE_TYPE)->load(path));
setTexture(i, texture);
}
}
@ -401,7 +398,7 @@ void Material::setTexture(int i, Texture* texture)
{
if (texture) texture->atlas_size = old_texture->atlas_size;
removeDependency(*old_texture);
m_resource_manager.get(TEXTURE_TYPE)->unload(*old_texture);
m_resource_manager.getOwner().get(TEXTURE_TYPE)->unload(*old_texture);
}
if (isReady() && m_shader)
{
@ -426,7 +423,7 @@ void Material::setTexture(int i, Texture* texture)
void Material::setShader(const Path& path)
{
Shader* shader = static_cast<Shader*>(m_resource_manager.get(SHADER_TYPE)->load(path));
Shader* shader = static_cast<Shader*>(m_resource_manager.getOwner().get(SHADER_TYPE)->load(path));
setShader(shader);
}
@ -466,8 +463,7 @@ void Material::createCommandBuffer()
}
Vec4 color_shininess(m_color, m_shininess);
auto* material_manager = getResourceManager().get(MATERIAL_TYPE);
auto& renderer = static_cast<MaterialManager*>(material_manager)->getRenderer();
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
auto& uniform = renderer.getMaterialColorShininessUniform();
generator.setUniform(uniform, color_shininess);
generator.end();
@ -535,15 +531,14 @@ void Material::onBeforeReady()
void Material::setShader(Shader* shader)
{
auto* manager = getResourceManager().get(MATERIAL_TYPE);
auto* mat_manager = static_cast<MaterialManager*>(manager);
auto& mat_manager = static_cast<MaterialManager&>(m_resource_manager);
if (m_shader && m_shader != mat_manager->getRenderer().getDefaultShader())
if (m_shader && m_shader != mat_manager.getRenderer().getDefaultShader())
{
Shader* shader = m_shader;
m_shader = nullptr;
removeDependency(*shader);
m_resource_manager.get(SHADER_TYPE)->unload(*shader);
m_resource_manager.getOwner().get(SHADER_TYPE)->unload(*shader);
}
m_shader = shader;
if (m_shader)
@ -553,7 +548,7 @@ void Material::setShader(Shader* shader)
}
else
{
m_shader = mat_manager->getRenderer().getDefaultShader();
m_shader = mat_manager.getRenderer().getDefaultShader();
m_shader_instance = m_shader->m_instances.empty() ? nullptr : m_shader->m_instances[0];
}
}
@ -610,7 +605,7 @@ bool Material::deserializeTexture(JsonSerializer& serializer, const char* materi
{
copyString(texture_path, path);
}
auto* mng = m_resource_manager.get(TEXTURE_TYPE);
auto* mng = m_resource_manager.getOwner().get(TEXTURE_TYPE);
m_textures[m_texture_count] = static_cast<Texture*>(mng->load(Path(texture_path)));
addDependency(*m_textures[m_texture_count]);
}
@ -745,8 +740,7 @@ bool Material::load(FS::IFile& file)
{
PROFILE_FUNCTION();
auto* manager = getResourceManager().get(MATERIAL_TYPE);
auto& renderer = static_cast<MaterialManager*>(manager)->getRenderer();
auto& renderer = static_cast<MaterialManager&>(m_resource_manager).getRenderer();
m_render_states = BGFX_STATE_CULL_CW;
setAlphaRef(DEFAULT_ALPHA_REF_VALUE);
@ -834,7 +828,7 @@ bool Material::load(FS::IFile& file)
{
Path path;
serializer.deserialize(path, Path(""));
auto* manager = m_resource_manager.get(SHADER_TYPE);
auto* manager = m_resource_manager.getOwner().get(SHADER_TYPE);
setShader(static_cast<Shader*>(manager->load(Path(path))));
}
else

View file

@ -45,7 +45,7 @@ public:
};
public:
Material(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Material(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~Material();
float getShininess() const { return m_shininess; }

View file

@ -8,7 +8,7 @@ namespace Lumix
{
Resource* MaterialManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Material)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Material)(path, *this, m_allocator);
}
void MaterialManager::destroyResource(Resource& resource)

View file

@ -53,7 +53,7 @@ void Mesh::set(int attribute_array_offset, int attribute_array_size, int indices
}
Model::Model(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
Model::Model(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_bounding_radius()
, m_allocator(allocator)
@ -500,7 +500,7 @@ bool Model::parseMeshes(FS::IFile& file, FileVersion version)
catString(material_path, material_name);
catString(material_path, ".mat");
auto* material_manager = m_resource_manager.get(MATERIAL_TYPE);
auto* material_manager = m_resource_manager.getOwner().get(MATERIAL_TYPE);
Material* material = static_cast<Material*>(material_manager->load(Path(material_path)));
int32 attribute_array_offset = 0;
@ -643,7 +643,7 @@ void Model::registerLuaAPI(lua_State* L)
void Model::unload(void)
{
auto* material_manager = m_resource_manager.get(MATERIAL_TYPE);
auto* material_manager = m_resource_manager.getOwner().get(MATERIAL_TYPE);
for (int i = 0; i < m_meshes.size(); ++i)
{
removeDependency(*m_meshes[i].material);

View file

@ -126,7 +126,7 @@ public:
};
public:
Model(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Model(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~Model();
void create(const bgfx::VertexDecl& def,

View file

@ -8,7 +8,7 @@ namespace Lumix
{
Resource* ModelManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Model)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Model)(path, *this, m_allocator);
}
void ModelManager::destroyResource(Resource& resource)

View file

@ -639,8 +639,7 @@ void ParticleEmitter::setMaterial(Material* material)
{
if (m_material)
{
auto* manager = m_material->getResourceManager().get(MATERIAL_TYPE);
manager->unload(*m_material);
m_material->getResourceManager().unload(*m_material);
}
m_material = material;
}

View file

@ -155,14 +155,12 @@ private:
, m_ref_count(0)
, m_model(model)
{
m_model->getObserverCb().bind<ModelLoadedCallback, &ModelLoadedCallback::callback>(
this);
m_model->getObserverCb().bind<ModelLoadedCallback, &ModelLoadedCallback::callback>(this);
}
~ModelLoadedCallback()
{
m_model->getObserverCb().unbind<ModelLoadedCallback, &ModelLoadedCallback::callback>(
this);
m_model->getObserverCb().unbind<ModelLoadedCallback, &ModelLoadedCallback::callback>(this);
}
void callback(Resource::State old_state, Resource::State new_state)
@ -230,9 +228,8 @@ public:
{
if (i.entity != INVALID_ENTITY && i.model)
{
auto& manager = i.model->getResourceManager();
freeCustomMeshes(i, material_manager);
manager.get(MODEL_TYPE)->unload(*i.model);
i.model->getResourceManager().unload(*i.model);
LUMIX_DELETE(m_allocator, i.pose);
}
}
@ -241,7 +238,7 @@ public:
for (auto& probe : m_environment_probes)
{
if (probe.texture) probe.texture->getResourceManager().get(TEXTURE_TYPE)->unload(*probe.texture);
if (probe.texture) probe.texture->getResourceManager().unload(*probe.texture);
}
m_environment_probes.clear();
}
@ -1113,7 +1110,7 @@ public:
{
Entity entity = {component.index};
auto& probe = m_environment_probes[entity];
if (probe.texture) probe.texture->getResourceManager().get(TEXTURE_TYPE)->unload(*probe.texture);
if (probe.texture) probe.texture->getResourceManager().unload(*probe.texture);
m_environment_probes.erase(entity);
m_universe.destroyComponent(entity, ENVIRONMENT_PROBE_TYPE, this, component);
}
@ -3689,7 +3686,7 @@ public:
ASSERT(r.model);
auto& rm = r.model->getResourceManager();
auto* material_manager = static_cast<MaterialManager*>(rm.get(MATERIAL_TYPE));
auto* material_manager = static_cast<MaterialManager*>(rm.getOwner().get(MATERIAL_TYPE));
auto* new_meshes = (Mesh*)m_allocator.allocate(count * sizeof(Mesh));
if (r.meshes)
@ -3736,7 +3733,7 @@ public:
if (r.meshes && r.mesh_count > index && path == r.meshes[index].material->getPath()) return;
auto& rm = r.model->getResourceManager();
auto* material_manager = static_cast<MaterialManager*>(rm.get(MATERIAL_TYPE));
auto* material_manager = static_cast<MaterialManager*>(rm.getOwner().get(MATERIAL_TYPE));
int new_count = Math::maximum(int8(index + 1), r.mesh_count);
allocateCustomMeshes(r, new_count);
@ -3765,13 +3762,13 @@ public:
bool no_change = model == old_model && old_model;
if (no_change)
{
old_model->getResourceManager().get(MODEL_TYPE)->unload(*old_model);
old_model->getResourceManager().unload(*old_model);
return;
}
if (old_model)
{
auto& rm = old_model->getResourceManager();
auto* material_manager = static_cast<MaterialManager*>(rm.get(MATERIAL_TYPE));
auto* material_manager = static_cast<MaterialManager*>(rm.getOwner().get(MATERIAL_TYPE));
freeCustomMeshes(renderable, material_manager);
int callback_idx = getModelLoadedCallback(old_model);
ModelLoadedCallback* callback = m_model_loaded_callbacks[callback_idx];
@ -3786,7 +3783,7 @@ public:
{
m_culling_system->removeStatic(component);
}
old_model->getResourceManager().get(MODEL_TYPE)->unload(*old_model);
old_model->getResourceManager().unload(*old_model);
}
renderable.model = model;
renderable.meshes = nullptr;

View file

@ -21,7 +21,7 @@ static const ResourceType SHADER_TYPE("shader");
static const ResourceType SHADER_BINARY_TYPE("shader_binary");
Shader::Shader(const Path& path, ResourceManager& resource_manager, IAllocator& allocator)
Shader::Shader(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_allocator(allocator)
, m_instances(m_allocator)
@ -69,8 +69,7 @@ ShaderCombinations::ShaderCombinations()
Renderer& Shader::getRenderer()
{
auto* manager = m_resource_manager.get(SHADER_TYPE);
return static_cast<ShaderManager*>(manager)->getRenderer();
return static_cast<ShaderManager&>(m_resource_manager).getRenderer();
}
@ -101,7 +100,7 @@ bool Shader::generateInstances()
uint32 count = 1 << m_combintions.define_count;
auto* binary_manager = m_resource_manager.get(SHADER_BINARY_TYPE);
auto* binary_manager = m_resource_manager.getOwner().get(SHADER_BINARY_TYPE);
char basename[MAX_PATH_LENGTH];
PathUtils::getBasename(basename, sizeof(basename), getPath().c_str());
@ -486,8 +485,7 @@ ShaderInstance::~ShaderInstance()
if (!binary) continue;
shader.removeDependency(*binary);
auto* manager = binary->getResourceManager().get(SHADER_BINARY_TYPE);
manager->unload(*binary);
binary->getResourceManager().unload(*binary);
}
}
@ -514,9 +512,7 @@ bool Shader::getShaderCombinations(Renderer& renderer,
}
ShaderBinary::ShaderBinary(const Path& path,
ResourceManager& resource_manager,
IAllocator& allocator)
ShaderBinary::ShaderBinary(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator)
: Resource(path, resource_manager, allocator)
, m_handle(BGFX_INVALID_HANDLE)
{

View file

@ -64,7 +64,7 @@ struct LUMIX_RENDERER_API ShaderCombinations
class LUMIX_RENDERER_API ShaderBinary : public Resource
{
public:
ShaderBinary(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
ShaderBinary(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
bgfx::ShaderHandle getHandle() { return m_handle; }
private:
@ -122,7 +122,7 @@ public:
static const int MAX_TEXTURE_SLOT_COUNT = 16;
public:
Shader(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Shader(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~Shader();
bool hasDefine(uint8 define_idx) const;

View file

@ -26,7 +26,7 @@ ShaderManager::~ShaderManager()
Resource* ShaderManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Shader)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Shader)(path, *this, m_allocator);
}
@ -67,7 +67,7 @@ ShaderBinaryManager::~ShaderBinaryManager()
Resource* ShaderBinaryManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, ShaderBinary)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, ShaderBinary)(path, *this, m_allocator);
}

View file

@ -202,7 +202,7 @@ Terrain::GrassType::~GrassType()
{
if (m_grass_model)
{
m_grass_model->getResourceManager().get(MODEL_TYPE)->unload(*m_grass_model);
m_grass_model->getResourceManager().unload(*m_grass_model);
m_grass_model->getObserverCb().unbind<GrassType, &GrassType::grassLoaded>(this);
}
}
@ -356,7 +356,7 @@ void Terrain::setGrassTypePath(int index, const Path& path)
GrassType& type = *m_grass_types[index];
if (type.m_grass_model)
{
type.m_grass_model->getResourceManager().get(MODEL_TYPE)->unload(*type.m_grass_model);
type.m_grass_model->getResourceManager().unload(*type.m_grass_model);
type.m_grass_model->getObserverCb().unbind<GrassType, &GrassType::grassLoaded>(&type);
type.m_grass_model = nullptr;
}
@ -588,7 +588,7 @@ void Terrain::setMaterial(Material* material)
{
if (m_material)
{
m_material->getResourceManager().get(MATERIAL_TYPE)->unload(*m_material);
m_material->getResourceManager().unload(*m_material);
m_material->getObserverCb().unbind<Terrain, &Terrain::onMaterialLoaded>(this);
}
m_material = material;
@ -602,7 +602,7 @@ void Terrain::setMaterial(Material* material)
}
else if(material)
{
material->getResourceManager().get(MATERIAL_TYPE)->unload(*material);
material->getResourceManager().unload(*material);
}
}

View file

@ -36,9 +36,7 @@ struct TGAHeader
#pragma pack()
Texture::Texture(const Path& path,
ResourceManager& resource_manager,
IAllocator& _allocator)
Texture::Texture(const Path& path, ResourceManagerBase& resource_manager, IAllocator& _allocator)
: Resource(path, resource_manager, _allocator)
, data_reference(0)
, allocator(_allocator)
@ -65,7 +63,7 @@ void Texture::setFlag(uint32 flag, bool value)
new_flags |= value ? flag : 0;
bgfx_flags = new_flags;
getResourceManager().get(TEXTURE_TYPE)->reload(*this);
m_resource_manager.reload(*this);
}
@ -267,7 +265,7 @@ static void saveTGA(Texture& texture)
return;
}
FS::FileSystem& fs = texture.getResourceManager().getFileSystem();
FS::FileSystem& fs = texture.getResourceManager().getOwner().getFileSystem();
FS::IFile* file = fs.open(fs.getDefaultDevice(), texture.getPath(), FS::Mode::CREATE_AND_WRITE);
saveTGA(texture.allocator,
@ -289,7 +287,7 @@ void Texture::save()
PathUtils::getExtension(ext, 5, getPath().c_str());
if (equalStrings(ext, "raw") && bytes_per_pixel == 2)
{
FS::FileSystem& fs = m_resource_manager.getFileSystem();
FS::FileSystem& fs = m_resource_manager.getOwner().getFileSystem();
FS::IFile* file = fs.open(fs.getDefaultDevice(), getPath(), FS::Mode::CREATE_AND_WRITE);
file->write(&data[0], data.size() * sizeof(data[0]));
@ -399,12 +397,12 @@ static bool loadTGA(Texture& texture, FS::IFile& file)
texture.width = header.width;
texture.height = header.height;
texture.is_cubemap = false;
TextureManager* manager = static_cast<TextureManager*>(texture.getResourceManager().get(TEXTURE_TYPE));
TextureManager& manager = static_cast<TextureManager&>(texture.getResourceManager());
if (texture.data_reference)
{
texture.data.resize(image_size);
}
uint8* image_dest = texture.data_reference ? &texture.data[0] : (uint8*)manager->getBuffer(image_size);
uint8* image_dest = texture.data_reference ? &texture.data[0] : (uint8*)manager.getBuffer(image_size);
// Targa is BGR, swap to RGB, add alpha and flip Y axis
for (long y = 0; y < header.height; y++)
@ -452,7 +450,7 @@ void Texture::addDataReference()
++data_reference;
if (data_reference == 1 && isReady())
{
m_resource_manager.get(TEXTURE_TYPE)->reload(*this);
m_resource_manager.reload(*this);
}
}

View file

@ -16,7 +16,7 @@ namespace FS
class LUMIX_RENDERER_API Texture : public Resource
{
public:
Texture(const Path& path, ResourceManager& resource_manager, IAllocator& allocator);
Texture(const Path& path, ResourceManagerBase& resource_manager, IAllocator& allocator);
~Texture();
bool create(int w, int h, void* data);

View file

@ -23,7 +23,7 @@ namespace Lumix
Resource* TextureManager::createResource(const Path& path)
{
return LUMIX_NEW(m_allocator, Texture)(path, getOwner(), m_allocator);
return LUMIX_NEW(m_allocator, Texture)(path, *this, m_allocator);
}
void TextureManager::destroyResource(Resource& resource)