Refactor the way resources are loaded (#191)
* WIP * WIP * Font works * WIP: Only Music remains * Looks like it's working * Fix oopsie * Core/ObjectRef: Add cast functions * Update ChangeLog.md * Audio/SoundStream: Make sound stream thread-safe
This commit is contained in:
@@ -137,10 +137,6 @@ namespace Nz
|
||||
inline bool IsShadowCastingEnabled() const;
|
||||
inline bool IsShadowReceiveEnabled() const;
|
||||
|
||||
inline bool LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
|
||||
inline bool LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
inline bool LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
void Reset();
|
||||
|
||||
void SaveToParameters(ParameterList* matData);
|
||||
@@ -180,6 +176,11 @@ namespace Nz
|
||||
|
||||
inline static MaterialRef GetDefault();
|
||||
inline static int GetTextureUnit(TextureMap textureMap);
|
||||
|
||||
static inline MaterialRef LoadFromFile(const String& filePath, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params = MaterialParams());
|
||||
static inline MaterialRef LoadFromStream(Stream& stream, const MaterialParams& params = MaterialParams());
|
||||
|
||||
template<typename... Args> static MaterialRef New(Args&&... args);
|
||||
|
||||
// Signals:
|
||||
|
||||
@@ -895,43 +895,6 @@ namespace Nz
|
||||
return m_pipelineInfo.shadowReceive;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from file
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param filePath Path to the file
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromFile(const String& filePath, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromFile(this, filePath, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from memory
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param data Raw memory
|
||||
* \param size Size of the memory
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromMemory(this, data, size, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from stream
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param stream Stream to the material
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline bool Material::LoadFromStream(Stream& stream, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromStream(this, stream, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the alpha map by name
|
||||
* \return true If successful
|
||||
@@ -1466,6 +1429,43 @@ namespace Nz
|
||||
return s_textureUnits[textureMap];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from file
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param filePath Path to the file
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromFile(const String& filePath, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromFile(filePath, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from memory
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param data Raw memory
|
||||
* \param size Size of the memory
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromMemory(const void* data, std::size_t size, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromMemory(data, size, params);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Loads the material from stream
|
||||
* \return true if loading is successful
|
||||
*
|
||||
* \param stream Stream to the material
|
||||
* \param params Parameters for the material
|
||||
*/
|
||||
inline MaterialRef Material::LoadFromStream(Stream& stream, const MaterialParams& params)
|
||||
{
|
||||
return MaterialLoader::LoadFromStream(stream, params);
|
||||
}
|
||||
|
||||
inline void Material::InvalidatePipeline()
|
||||
{
|
||||
m_pipelineUpdated = false;
|
||||
|
||||
@@ -65,10 +65,6 @@ namespace Nz
|
||||
|
||||
virtual bool IsAnimated() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
bool LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
using InstancedRenderable::SetMaterial;
|
||||
bool SetMaterial(const String& subMeshName, MaterialRef material);
|
||||
bool SetMaterial(std::size_t skinIndex, const String& subMeshName, MaterialRef material);
|
||||
@@ -78,6 +74,10 @@ namespace Nz
|
||||
Model& operator=(const Model& node) = default;
|
||||
Model& operator=(Model&& node) = delete;
|
||||
|
||||
static ModelRef LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
|
||||
static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
|
||||
|
||||
template<typename... Args> static ModelRef New(Args&&... args);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -59,7 +59,6 @@ namespace Nz
|
||||
*
|
||||
* \param args Arguments for the model
|
||||
*/
|
||||
|
||||
template<typename... Args>
|
||||
ModelRef Model::New(Args&&... args)
|
||||
{
|
||||
|
||||
@@ -26,12 +26,10 @@ namespace Nz
|
||||
|
||||
class SkeletalModel;
|
||||
|
||||
using SkeletalModelLoader = ResourceLoader<SkeletalModel, SkeletalModelParameters>;
|
||||
using SkeletalModelRef = ObjectRef<SkeletalModel>;
|
||||
|
||||
class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable
|
||||
{
|
||||
friend SkeletalModelLoader;
|
||||
|
||||
public:
|
||||
SkeletalModel();
|
||||
SkeletalModel(const SkeletalModel& model) = default;
|
||||
@@ -55,10 +53,6 @@ namespace Nz
|
||||
bool IsAnimated() const override;
|
||||
bool IsAnimationEnabled() const;
|
||||
|
||||
bool LoadFromFile(const String& filePath, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromMemory(const void* data, std::size_t size, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
bool LoadFromStream(Stream& stream, const SkeletalModelParameters& params = SkeletalModelParameters());
|
||||
|
||||
bool SetAnimation(Animation* animation);
|
||||
void SetMesh(Mesh* mesh) override;
|
||||
bool SetSequence(const String& sequenceName);
|
||||
@@ -67,6 +61,8 @@ namespace Nz
|
||||
SkeletalModel& operator=(const SkeletalModel& node) = default;
|
||||
SkeletalModel& operator=(SkeletalModel&& node) = default;
|
||||
|
||||
template<typename... Args> static SkeletalModelRef New(Args&&... args);
|
||||
|
||||
private:
|
||||
void MakeBoundingVolume() const override;
|
||||
/*void Register() override;
|
||||
@@ -80,9 +76,9 @@ namespace Nz
|
||||
float m_interpolation;
|
||||
unsigned int m_currentFrame;
|
||||
unsigned int m_nextFrame;
|
||||
|
||||
static SkeletalModelLoader::LoaderList s_loaders;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.inl>
|
||||
|
||||
#endif // NAZARA_SKELETALMODEL_HPP
|
||||
|
||||
27
include/Nazara/Graphics/SkeletalModel.inl
Normal file
27
include/Nazara/Graphics/SkeletalModel.inl
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2017 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Graphics module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Graphics/SkeletalModel.hpp>
|
||||
#include <memory>
|
||||
#include <Nazara/Graphics/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
* \brief Creates a new SkeletalModel from the arguments
|
||||
* \return A reference to the newly created SkeletalModel
|
||||
*
|
||||
* \param args Arguments for the skeletal model
|
||||
*/
|
||||
template<typename... Args>
|
||||
SkeletalModelRef SkeletalModel::New(Args&&... args)
|
||||
{
|
||||
std::unique_ptr<SkeletalModel> object(new SkeletalModel(std::forward<Args>(args)...));
|
||||
object->SetPersistent(false);
|
||||
|
||||
return object.release();
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
Reference in New Issue
Block a user