Added RenderTextures (And many others things)

-Added Forward, left and up vector (Vector3)
-Added Matrix4::ConcatenateAffine shortcut
-Added Quaternion::GetInverse() and Quaternion::Inverse()
-Added Resource listeners
-Added Depth and stencil pixel formats
-All enums now have an ending "max" entry
-Animation/Mesh::Add[Sequence/Skin/SubMesh] now returns a boolean
-Contexts are now resources
-Enhanced AnimatedMesh demo
-Fixed MD2 facing
-Fixed Vector3::CrossProduct
-Made Resource thread-safe
-Made OpenGL translation table global
-Many bugfixes
-MLT will now write malloc failure to the log
-Most of the strcpy were replaced with faster memcpy
-Occlusion queries availability is now always tested
-OpenGL-related includes now requires NAZARA_RENDERER_OPENGL to be
defined to have any effect
-Pixel formats now have a type
-Renamed RenderTarget::IsValid to IsRenderable
-Renamed Quaternion::GetNormalized() to GetNormal()
-Renamed Texture::Bind() to Prepare()
-Renamed VectorX::Make[Ceil|Floor] to Maximize/Minimize
-Removed MATH_MATRIX_COLUMN_MAJOR option (all matrices are column-major)
-Removed RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION option (Render
windows are active upon their creation)


Former-commit-id: 0d1da1e32c156a958221edf04a5315c75b354450
This commit is contained in:
Jérôme Leclercq
2012-09-20 22:07:30 +02:00
parent a6ed70123b
commit cd5a1b7a5e
65 changed files with 24385 additions and 22703 deletions

View File

@@ -1,317 +1,342 @@
// Copyright (C) 2012 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 <Nazara/Utility/Animation.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Utility/Config.hpp>
#include <map>
#include <vector>
#include <Nazara/Utility/Debug.hpp>
struct NzAnimationImpl
{
std::map<NzString, unsigned int> sequenceMap;
std::vector<NzSequence> sequences;
nzAnimationType type;
unsigned int frameCount;
};
bool NzAnimationParams::IsValid() const
{
if (startFrame > endFrame)
{
NazaraError("Start frame must be lower than end frame");
return false;
}
return true;
}
NzAnimation::~NzAnimation()
{
Destroy();
}
unsigned int NzAnimation::AddSequence(const NzSequence& sequence)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
#endif
unsigned int index = m_impl->sequences.size();
if (!sequence.name.IsEmpty())
{
#if NAZARA_UTILITY_SAFE
auto it = m_impl->sequenceMap.find(sequence.name);
if (it != m_impl->sequenceMap.end())
{
NazaraError("Sequence name \"" + sequence.name + "\" is already used");
return 0;
}
#endif
m_impl->sequenceMap[sequence.name] = index;
}
m_impl->sequences.push_back(sequence);
return index;
}
bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount)
{
Destroy();
#if NAZARA_UTILITY_SAFE
if (type == nzAnimationType_Static)
{
NazaraError("Invalid type");
return false;
}
if (frameCount == 0)
{
NazaraError("Frame count must be over zero");
return false;
}
#endif
m_impl = new NzAnimationImpl;
m_impl->frameCount = frameCount;
m_impl->type = type;
return true;
}
void NzAnimation::Destroy()
{
if (m_impl)
{
delete m_impl;
m_impl = nullptr;
}
}
unsigned int NzAnimation::GetFrameCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->frameCount;
}
NzSequence* NzAnimation::GetSequence(const NzString& sequenceName)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
auto it = m_impl->sequenceMap.find(sequenceName);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
return &m_impl->sequences[it->second];
#else
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
#endif
}
NzSequence* NzAnimation::GetSequence(unsigned int index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
return &m_impl->sequences[index];
}
const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
auto it = m_impl->sequenceMap.find(sequenceName);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
return &m_impl->sequences[it->second];
#else
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
#endif
}
const NzSequence* NzAnimation::GetSequence(unsigned int index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
return &m_impl->sequences[index];
}
unsigned int NzAnimation::GetSequenceCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
#endif
return m_impl->sequences.size();
}
nzAnimationType NzAnimation::GetType() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation
}
#endif
return m_impl->type;
}
bool NzAnimation::HasSequence(const NzString& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end();
}
bool NzAnimation::HasSequence(unsigned int index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return index >= m_impl->sequences.size();
}
bool NzAnimation::IsValid() const
{
return m_impl != nullptr;
}
bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromFile(this, filePath, params);
}
bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromMemory(this, data, size, params);
}
bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromStream(this, stream, params);
}
void NzAnimation::RemoveSequence(const NzString& identifier)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
auto it = m_impl->sequenceMap.find(identifier);
if (it == m_impl->sequenceMap.end())
{
NazaraError("SubMesh not found");
return;
}
unsigned int index = it->second;
#else
unsigned int index = m_impl->sequenceMap[identifier];
#endif
auto it2 = m_impl->sequences.begin();
std::advance(it2, index);
m_impl->sequences.erase(it2);
}
void NzAnimation::RemoveSequence(unsigned int index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return;
}
#endif
auto it = m_impl->sequences.begin();
std::advance(it, index);
m_impl->sequences.erase(it);
}
NzAnimationLoader::LoaderList NzAnimation::s_loaders;
// Copyright (C) 2012 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 <Nazara/Utility/Animation.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Utility/Config.hpp>
#include <map>
#include <vector>
#include <Nazara/Utility/Debug.hpp>
struct NzAnimationImpl
{
std::map<NzString, unsigned int> sequenceMap;
std::vector<NzSequence> sequences;
nzAnimationType type;
unsigned int frameCount;
};
bool NzAnimationParams::IsValid() const
{
if (startFrame > endFrame)
{
NazaraError("Start frame must be lower than end frame");
return false;
}
return true;
}
NzAnimation::~NzAnimation()
{
Destroy();
}
bool NzAnimation::AddSequence(const NzSequence& sequence)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
unsigned int index = m_impl->sequences.size();
if (!sequence.name.IsEmpty())
{
#if NAZARA_UTILITY_SAFE
auto it = m_impl->sequenceMap.find(sequence.name);
if (it != m_impl->sequenceMap.end())
{
NazaraError("Sequence name \"" + sequence.name + "\" is already used");
return false;
}
#endif
m_impl->sequenceMap[sequence.name] = index;
}
m_impl->sequences.push_back(sequence);
return true;
}
bool NzAnimation::Create(nzAnimationType type, unsigned int frameCount)
{
Destroy();
#if NAZARA_UTILITY_SAFE
if (type == nzAnimationType_Static)
{
NazaraError("Invalid type");
return false;
}
if (frameCount == 0)
{
NazaraError("Frame count must be over zero");
return false;
}
#endif
m_impl = new NzAnimationImpl;
m_impl->frameCount = frameCount;
m_impl->type = type;
NotifyCreated();
return true;
}
void NzAnimation::Destroy()
{
if (m_impl)
{
NotifyDestroy();
delete m_impl;
m_impl = nullptr;
}
}
unsigned int NzAnimation::GetFrameCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->frameCount;
}
NzSequence* NzAnimation::GetSequence(const NzString& sequenceName)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
auto it = m_impl->sequenceMap.find(sequenceName);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
return &m_impl->sequences[it->second];
#else
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
#endif
}
NzSequence* NzAnimation::GetSequence(unsigned int index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
return &m_impl->sequences[index];
}
const NzSequence* NzAnimation::GetSequence(const NzString& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
auto it = m_impl->sequenceMap.find(sequenceName);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
return &m_impl->sequences[it->second];
#else
return &m_impl->sequences[m_impl->sequenceMap[sequenceName]];
#endif
}
const NzSequence* NzAnimation::GetSequence(unsigned int index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
return &m_impl->sequences[index];
}
unsigned int NzAnimation::GetSequenceCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
#endif
return m_impl->sequences.size();
}
int NzAnimation::GetSequenceIndex(const NzString& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return -1;
}
auto it = m_impl->sequenceMap.find(sequenceName);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return -1;
}
return it->second;
#else
return m_impl->sequenceMap[sequenceName];
#endif
}
nzAnimationType NzAnimation::GetType() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nzAnimationType_Static; // Ce qui est une valeur invalide pour NzAnimation
}
#endif
return m_impl->type;
}
bool NzAnimation::HasSequence(const NzString& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end();
}
bool NzAnimation::HasSequence(unsigned int index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
return index >= m_impl->sequences.size();
}
bool NzAnimation::IsValid() const
{
return m_impl != nullptr;
}
bool NzAnimation::LoadFromFile(const NzString& filePath, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromFile(this, filePath, params);
}
bool NzAnimation::LoadFromMemory(const void* data, std::size_t size, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromMemory(this, data, size, params);
}
bool NzAnimation::LoadFromStream(NzInputStream& stream, const NzAnimationParams& params)
{
return NzAnimationLoader::LoadFromStream(this, stream, params);
}
void NzAnimation::RemoveSequence(const NzString& identifier)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
auto it = m_impl->sequenceMap.find(identifier);
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return;
}
int index = it->second;
#else
int index = m_impl->sequenceMap[identifier];
#endif
auto it2 = m_impl->sequences.begin();
std::advance(it2, index);
m_impl->sequences.erase(it2);
}
void NzAnimation::RemoveSequence(unsigned int index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
if (index >= m_impl->sequences.size())
{
NazaraError("Sequence index out of range (" + NzString::Number(index) + " >= " + NzString::Number(m_impl->sequences.size()) + ')');
return;
}
#endif
auto it = m_impl->sequences.begin();
std::advance(it, index);
m_impl->sequences.erase(it);
}
NzAnimationLoader::LoaderList NzAnimation::s_loaders;