Added a static New method to RefCounted-derived classes

Former-commit-id: efd9e68e050fb6cc7e0df7a7c222ca759c502dc5
This commit is contained in:
Lynix
2015-01-25 23:41:09 +01:00
parent 5f5be93992
commit 0db92e671d
59 changed files with 532 additions and 354 deletions

View File

@@ -61,6 +61,7 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
bool LoadFromStream(NzInputStream& stream, const NzSoundBufferParams& params = NzSoundBufferParams());
static bool IsFormatSupported(nzAudioFormat format);
template<typename... Args> static NzSoundBufferRef New(Args&&... args);
private:
unsigned int GetOpenALBuffer() const;
@@ -70,4 +71,6 @@ class NAZARA_API NzSoundBuffer : public NzRefCounted, public NzResource, NzNonCo
static NzSoundBufferLoader::LoaderList s_loaders;
};
#include <Nazara/Audio/SoundBuffer.inl>
#endif // NAZARA_SOUNDBUFFER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Audio module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Audio/Debug.hpp>
template<typename... Args>
NzSoundBufferRef NzSoundBuffer::New(Args&&... args)
{
std::unique_ptr<NzSoundBuffer> object(new NzSoundBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Audio/DebugOff.hpp>

View File

@@ -23,6 +23,7 @@ class NzObjectRef
NzObjectRef(NzObjectRef&& ref) noexcept;
~NzObjectRef();
T* Get() const;
bool IsValid() const;
T* Release();
bool Reset(T* object = nullptr);

View File

@@ -41,6 +41,12 @@ NzObjectRef<T>::~NzObjectRef()
m_object->RemoveReference();
}
template<typename T>
T* NzObjectRef<T>::Get() const
{
return m_object;
}
template<typename T>
bool NzObjectRef<T>::IsValid() const
{

View File

@@ -134,6 +134,7 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
NzMaterial& operator=(const NzMaterial& material);
static NzMaterial* GetDefault();
template<typename... Args> static NzMaterialRef New(Args&&... args);
private:
struct ShaderInstance
@@ -172,8 +173,10 @@ class NAZARA_API NzMaterial : public NzRefCounted, public NzResource
float m_alphaThreshold;
float m_shininess;
static NzMaterial* s_defaultMaterial;
static NzMaterialRef s_defaultMaterial;
static NzMaterialLoader::LoaderList s_loaders;
};
#include <Nazara/Graphics/Material.inl>
#endif // NAZARA_MATERIAL_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 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 <memory>
#include <Nazara/Graphics/Debug.hpp>
template<typename... Args>
NzMaterialRef NzMaterial::New(Args&&... args)
{
std::unique_ptr<NzMaterial> object(new NzMaterial(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -40,6 +40,7 @@ class NAZARA_API NzRenderBuffer : public NzRefCounted, NzNonCopyable
bool IsValid() const;
static bool IsSupported();
template<typename... Args> static NzRenderBufferRef New(Args&&... args);
private:
nzPixelFormat m_pixelFormat;
@@ -48,4 +49,6 @@ class NAZARA_API NzRenderBuffer : public NzRefCounted, NzNonCopyable
unsigned int m_width;
};
#include <Nazara/Renderer/RenderBuffer.inl>
#endif // NAZARA_RENDERBUFFER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzRenderBufferRef NzRenderBuffer::New(Args&&... args)
{
std::unique_ptr<NzRenderBuffer> object(new NzRenderBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -97,6 +97,7 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
unsigned int GetOpenGLID() const;
static bool IsStageSupported(nzShaderStage stage);
template<typename... Args> static NzShaderRef New(Args&&... args);
private:
bool PostLinkage();
@@ -107,4 +108,6 @@ class NAZARA_API NzShader : public NzRefCounted, NzNonCopyable
unsigned int m_program;
};
#include <Nazara/Renderer/Shader.inl>
#endif // NAZARA_SHADER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzShaderRef NzShader::New(Args&&... args)
{
std::unique_ptr<NzShader> object(new NzShader(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -101,6 +101,7 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
static bool IsFormatSupported(nzPixelFormat format);
static bool IsMipmappingSupported();
static bool IsTypeSupported(nzImageType type);
template<typename... Args> static NzTextureRef New(Args&&... args);
private:
bool CreateTexture(bool proxy);
@@ -108,4 +109,6 @@ class NAZARA_API NzTexture : public NzAbstractImage, public NzRefCounted, public
NzTextureImpl* m_impl = nullptr;
};
#include <Nazara/Renderer/Texture.inl>
#endif // NAZARA_TEXTURE_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzTextureRef NzTexture::New(Args&&... args)
{
std::unique_ptr<NzTexture> object(new NzTexture(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -9,12 +9,21 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Core/ObjectListenerWrapper.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderStage.hpp>
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
#include <unordered_map>
class NzUberShaderPreprocessor;
using NzUberShaderPreprocessorConstListener = NzObjectListenerWrapper<const NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorConstRef = NzObjectRef<const NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorListener = NzObjectListenerWrapper<NzUberShaderPreprocessor>;
using NzUberShaderPreprocessorRef = NzObjectRef<NzUberShaderPreprocessor>;
class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
{
public:
@@ -27,6 +36,7 @@ class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
bool SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& shaderFlags, const NzString& requiredFlags = NzString());
static bool IsSupported();
template<typename... Args> static NzUberShaderPreprocessorRef New(Args&&... args);
private:
struct Shader
@@ -43,4 +53,6 @@ class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
Shader m_shaders[nzShaderStage_Max+1];
};
#include <Nazara/Renderer/UberShaderPreprocessor.inl>
#endif // NAZARA_UBERSHADERPREPROCESSOR_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Renderer/Debug.hpp>
template<typename... Args>
NzUberShaderPreprocessorRef NzUberShaderPreprocessor::New(Args&&... args)
{
std::unique_ptr<NzUberShaderPreprocessor> object(new NzUberShaderPreprocessor(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Renderer/DebugOff.hpp>

View File

@@ -80,10 +80,14 @@ class NAZARA_API NzAnimation : public NzRefCounted, public NzResource
void RemoveSequence(const NzString& sequenceName);
void RemoveSequence(unsigned int index);
template<typename... Args> static NzAnimationRef New(Args&&... args);
private:
NzAnimationImpl* m_impl = nullptr;
static NzAnimationLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Animation.inl>
#endif // NAZARA_ANIMATION_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzAnimationRef NzAnimation::New(Args&&... args)
{
std::unique_ptr<NzAnimation> object(new NzAnimation(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -58,6 +58,7 @@ class NAZARA_API NzBuffer : public NzRefCounted, NzNonCopyable
void Unmap() const;
static bool IsStorageSupported(nzUInt32 storage);
template<typename... Args> static NzBufferRef New(Args&&... args);
static void SetBufferFactory(nzUInt32 storage, BufferFactory func);
private:
@@ -73,4 +74,6 @@ class NAZARA_API NzBuffer : public NzRefCounted, NzNonCopyable
static BufferFactory s_bufferFactories[nzDataStorage_Max+1];
};
#include <Nazara/Utility/Buffer.inl>
#endif // NAZARA_BUFFER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzBufferRef NzBuffer::New(Args&&... args)
{
std::unique_ptr<NzBuffer> object(new NzBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -85,6 +85,8 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzAbstractAtla
static bool Initialize();
template<typename... Args> static NzFontRef New(Args&&... args);
static void SetDefaultAtlas(const std::shared_ptr<NzAbstractAtlas>& atlas);
static void SetDefaultGlyphBorder(unsigned int borderSize);
static void SetDefaultMinimumStepSize(unsigned int minimumStepSize);
@@ -138,10 +140,12 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzAbstractAtla
unsigned int m_minimumStepSize;
static std::shared_ptr<NzAbstractAtlas> s_defaultAtlas;
static NzFont* s_defaultFont;
static NzFontRef s_defaultFont;
static NzFontLoader::LoaderList s_loaders;
static unsigned int s_defaultGlyphBorder;
static unsigned int s_defaultMinimumStepSize;
};
#include <Nazara/Utility/Font.inl>
#endif // NAZARA_FONT_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzFontRef NzFont::New(Args&&... args)
{
std::unique_ptr<NzFont> object(new NzFont(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -112,6 +112,7 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
static void Copy(nzUInt8* destination, const nzUInt8* source, nzUInt8 bpp, unsigned int width, unsigned int height, unsigned int depth = 1, unsigned int dstWidth = 0, unsigned int dstHeight = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0);
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);
static nzUInt8 GetMaxLevel(nzImageType type, unsigned int width, unsigned int height, unsigned int depth = 1);
template<typename... Args> static NzImageRef New(Args&&... args);
struct SharedImage
{
@@ -149,4 +150,6 @@ class NAZARA_API NzImage : public NzAbstractImage, public NzRefCounted, public N
static NzImageLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Image.inl>
#endif // NAZARA_IMAGE_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzImageRef NzImage::New(Args&&... args)
{
std::unique_ptr<NzImage> object(new NzImage(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -64,6 +64,8 @@ class NAZARA_API NzIndexBuffer : public NzRefCounted
NzIndexBuffer& operator=(const NzIndexBuffer& indexBuffer);
template<typename... Args> static NzIndexBufferRef New(Args&&... args);
private:
NzBufferRef m_buffer;
bool m_largeIndices;
@@ -72,4 +74,6 @@ class NAZARA_API NzIndexBuffer : public NzRefCounted
unsigned int m_startOffset;
};
#include <Nazara/Utility/IndexBuffer.inl>
#endif // NAZARA_INDEXBUFFER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzIndexBufferRef NzIndexBuffer::New(Args&&... args)
{
std::unique_ptr<NzIndexBuffer> object(new NzIndexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -123,10 +123,14 @@ class NAZARA_API NzMesh : public NzRefCounted, public NzResource
void Transform(const NzMatrix4f& matrix);
template<typename... Args> static NzMeshRef New(Args&&... args);
private:
NzMeshImpl* m_impl = nullptr;
static NzMeshLoader::LoaderList s_loaders;
};
#include <Nazara/Utility/Mesh.inl>
#endif // NAZARA_MESH_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzMeshRef NzMesh::New(Args&&... args)
{
std::unique_ptr<NzMesh> object(new NzMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -41,10 +41,14 @@ class NAZARA_API NzSkeletalMesh final : public NzSubMesh
void SetAABB(const NzBoxf& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
template<typename... Args> static NzSkeletalMeshRef New(Args&&... args);
private:
NzBoxf m_aabb;
NzIndexBufferConstRef m_indexBuffer = nullptr;
NzVertexBufferRef m_vertexBuffer = nullptr;
};
#include <Nazara/Utility/SkeletalMesh.inl>
#endif // NAZARA_SKELETALMESH_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzSkeletalMeshRef NzSkeletalMesh::New(Args&&... args)
{
std::unique_ptr<NzSkeletalMesh> object(new NzSkeletalMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -53,6 +53,8 @@ class NAZARA_API NzSkeleton : public NzRefCounted
NzSkeleton& operator=(const NzSkeleton& skeleton);
template<typename... Args> static NzSkeletonRef New(Args&&... args);
private:
void InvalidateJoints();
void InvalidateJointMap();
@@ -61,4 +63,6 @@ class NAZARA_API NzSkeleton : public NzRefCounted
NzSkeletonImpl* m_impl = nullptr;
};
#include <Nazara/Utility/Skeleton.inl>
#endif // NAZARA_SKELETON_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzSkeletonRef NzSkeleton::New(Args&&... args)
{
std::unique_ptr<NzSkeleton> object(new NzSkeleton(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -45,10 +45,14 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
void SetAABB(const NzBoxf& aabb);
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
template<typename... Args> static NzStaticMeshRef New(Args&&... args);
private:
NzBoxf m_aabb;
NzIndexBufferConstRef m_indexBuffer = nullptr;
NzVertexBufferRef m_vertexBuffer = nullptr;
};
#include <Nazara/Utility/StaticMesh.inl>
#endif // NAZARA_STATICMESH_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzStaticMeshRef NzStaticMesh::New(Args&&... args)
{
std::unique_ptr<NzStaticMesh> object(new NzStaticMesh(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -62,6 +62,8 @@ class NAZARA_API NzVertexBuffer : public NzRefCounted
NzVertexBuffer& operator=(const NzVertexBuffer& vertexBuffer);
template<typename... Args> static NzVertexBufferRef New(Args&&... args);
private:
NzBufferRef m_buffer;
NzVertexDeclarationConstRef m_vertexDeclaration;
@@ -70,4 +72,6 @@ class NAZARA_API NzVertexBuffer : public NzRefCounted
unsigned int m_vertexCount;
};
#include <Nazara/Utility/VertexBuffer.inl>
#endif // NAZARA_VERTEXBUFFER_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzVertexBufferRef NzVertexBuffer::New(Args&&... args)
{
std::unique_ptr<NzVertexBuffer> object(new NzVertexBuffer(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -41,6 +41,7 @@ class NAZARA_API NzVertexDeclaration : public NzRefCounted
static NzVertexDeclaration* Get(nzVertexLayout layout);
static bool IsTypeSupported(nzComponentType type);
template<typename... Args> static NzVertexDeclarationRef New(Args&&... args);
private:
static bool Initialize();
@@ -67,4 +68,6 @@ class NAZARA_API NzVertexDeclaration : public NzRefCounted
static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1];
};
#include <Nazara/Utility/VertexDeclaration.hpp>
#endif // NAZARA_VERTEXDECLARATION_HPP

View File

@@ -0,0 +1,17 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Utility/Debug.hpp>
template<typename... Args>
NzVertexDeclarationRef NzVertexDeclaration::New(Args&&... args)
{
std::unique_ptr<NzVertexDeclaration> object(new NzVertexDeclaration(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -2,8 +2,8 @@
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Debug.hpp>
template <typename T>
NzSparsePtr<T> NzVertexMapper::GetComponentPtr(nzVertexComponent component)