Merge branch 'master' into vulkan

Former-commit-id: 783e31e1f02fea8f9cd5080dc5295eead00ba1ce [formerly 7bf4eb3cc900923a8b3483b45e73333954a9c143] [formerly bd47f3386b2ccaa49ab5a45d874ebcdd653df81f [formerly 60494c4bdb49e4c3cfbdd97f048ee9e5b7b3a81d]]
Former-commit-id: eea148c75240307741b212eff37937ae325d323d [formerly df04c665b6bddd805665558928d8b16938c719fc]
Former-commit-id: f69cd1b0f1762bb2c4a289e553207adbd622ac5a
This commit is contained in:
Lynix
2016-09-15 00:45:22 +02:00
149 changed files with 4906 additions and 1104 deletions

View File

@@ -97,7 +97,7 @@ namespace Nz
return m_format;
}
UInt32 GetSampleCount() const override
UInt64 GetSampleCount() const override
{
return m_sampleCount;
}
@@ -131,7 +131,7 @@ namespace Nz
bool Open(Stream& stream, bool forceMono)
{
SF_INFO infos;
infos.format = 0; // Format inconnu
infos.format = 0; // Unknown format
m_handle = sf_open_virtual(&callbacks, SFM_READ, &infos, &stream);
if (!m_handle)
@@ -154,7 +154,7 @@ namespace Nz
return false;
}
m_sampleCount = static_cast<UInt32>(infos.channels*infos.frames);
m_sampleCount = infos.channels*infos.frames;
m_sampleRate = infos.samplerate;
// Durée de la musique (s) = samples / channels*rate
@@ -180,7 +180,7 @@ namespace Nz
return true;
}
unsigned int Read(void* buffer, unsigned int sampleCount) override
UInt64 Read(void* buffer, UInt64 sampleCount) override
{
// Si la musique a été demandée en mono, nous devons la convertir à la volée lors de la lecture
if (m_mixToMono)
@@ -190,13 +190,13 @@ namespace Nz
sf_count_t readSampleCount = sf_read_short(m_handle, m_mixBuffer.data(), m_format * sampleCount);
MixToMono(m_mixBuffer.data(), static_cast<Int16*>(buffer), m_format, sampleCount);
return static_cast<unsigned int>(readSampleCount / m_format);
return readSampleCount / m_format;
}
else
return static_cast<unsigned int>(sf_read_short(m_handle, static_cast<Int16*>(buffer), sampleCount));
return sf_read_short(m_handle, static_cast<Int16*>(buffer), sampleCount);
}
void Seek(UInt32 offset) override
void Seek(UInt64 offset) override
{
sf_seek(m_handle, offset*m_sampleRate / 1000, SEEK_SET);
}
@@ -208,8 +208,8 @@ namespace Nz
SNDFILE* m_handle;
bool m_mixToMono;
UInt32 m_duration;
unsigned int m_sampleCount;
unsigned int m_sampleRate;
UInt32 m_sampleRate;
UInt64 m_sampleCount;
};
bool IsSupported(const String& extension)

View File

@@ -166,17 +166,10 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
*/
UInt32 Music::GetPlayingOffset() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Music not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Music not created");
// Prevent music thread from enqueing new buffers while we're getting the count
Nz::LockGuard lock(m_impl->bufferLock);
@@ -192,16 +185,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
*/
UInt32 Music::GetSampleCount() const
UInt64 Music::GetSampleCount() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Music not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Music not created");
return m_impl->stream->GetSampleCount();
}
@@ -212,16 +198,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
*/
UInt32 Music::GetSampleRate() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Music not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Music not created");
return m_impl->sampleRate;
}
@@ -233,16 +212,9 @@ namespace Nz
* \remark If the music is not playing, Stopped is returned
* \remark Produces a NazaraError if there is no music with NAZARA_AUDIO_SAFE defined
*/
SoundStatus Music::GetStatus() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Music not created");
return SoundStatus_Stopped;
}
#endif
NazaraAssert(m_impl, "Music not created");
SoundStatus status = GetInternalStatus();
@@ -425,8 +397,8 @@ namespace Nz
bool Music::FillAndQueueBuffer(unsigned int buffer)
{
unsigned int sampleCount = m_impl->chunkSamples.size();
unsigned int sampleRead = 0;
std::size_t sampleCount = m_impl->chunkSamples.size();
std::size_t sampleRead = 0;
// Fill the buffer by reading from the stream
for (;;)
@@ -446,7 +418,7 @@ namespace Nz
// Update the buffer (send it to OpenAL) and queue it if we got any data
if (sampleRead > 0)
{
alBufferData(buffer, m_impl->audioFormat, &m_impl->chunkSamples[0], sampleRead*sizeof(Int16), m_impl->sampleRate);
alBufferData(buffer, m_impl->audioFormat, &m_impl->chunkSamples[0], static_cast<ALsizei>(sampleRead*sizeof(Int16)), static_cast<ALsizei>(m_impl->sampleRate));
alSourceQueueBuffers(m_source, 1, &buffer);
}

View File

@@ -27,7 +27,6 @@ namespace Nz
*
* \param soundBuffer Buffer to read sound from
*/
Sound::Sound(const SoundBuffer* soundBuffer)
{
SetBuffer(soundBuffer);
@@ -38,7 +37,6 @@ namespace Nz
*
* \param sound Sound to copy
*/
Sound::Sound(const Sound& sound) :
SoundEmitter(sound)
{
@@ -50,7 +48,6 @@ namespace Nz
*
* \see Stop
*/
Sound::~Sound()
{
Stop();
@@ -61,7 +58,6 @@ namespace Nz
*
* \param loop Should sound loop
*/
void Sound::EnableLooping(bool loop)
{
alSourcei(m_source, AL_LOOPING, loop);
@@ -71,7 +67,6 @@ namespace Nz
* \brief Gets the internal buffer
* \return Internal buffer
*/
const SoundBuffer* Sound::GetBuffer() const
{
return m_buffer;
@@ -83,7 +78,6 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no buffer
*/
UInt32 Sound::GetDuration() const
{
NazaraAssert(m_buffer, "Invalid sound buffer");
@@ -95,7 +89,6 @@ namespace Nz
* \brief Gets the current offset in the sound
* \return Offset in milliseconds (works with entire seconds)
*/
UInt32 Sound::GetPlayingOffset() const
{
ALint samples = 0;
@@ -108,7 +101,6 @@ namespace Nz
* \brief Gets the status of the music
* \return Enumeration of type SoundStatus (Playing, Stopped, ...)
*/
SoundStatus Sound::GetStatus() const
{
return GetInternalStatus();
@@ -118,7 +110,6 @@ namespace Nz
* \brief Checks whether the sound is looping
* \return true if it is the case
*/
bool Sound::IsLooping() const
{
ALint loop;
@@ -141,7 +132,6 @@ namespace Nz
* \brief Checks whether the sound is playing
* \return true if it is the case
*/
bool Sound::IsPlaying() const
{
return GetStatus() == SoundStatus_Playing;
@@ -156,7 +146,6 @@ namespace Nz
*
* \remark Produces a NazaraError if loading failed
*/
bool Sound::LoadFromFile(const String& filePath, const SoundBufferParams& params)
{
SoundBufferRef buffer = SoundBuffer::New();
@@ -180,7 +169,6 @@ namespace Nz
*
* \remark Produces a NazaraError if loading failed
*/
bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
{
SoundBufferRef buffer = SoundBuffer::New();
@@ -203,7 +191,6 @@ namespace Nz
*
* \remark Produces a NazaraError if loading failed
*/
bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params)
{
SoundBufferRef buffer = SoundBuffer::New();
@@ -220,7 +207,6 @@ namespace Nz
/*!
* \brief Pauses the sound
*/
void Sound::Pause()
{
alSourcePause(m_source);
@@ -231,16 +217,9 @@ namespace Nz
*
* \remark Produces a NazaraError if the sound is not playable with NAZARA_AUDIO_SAFE defined
*/
void Sound::Play()
{
#if NAZARA_AUDIO_SAFE
if (!IsPlayable())
{
NazaraError("Invalid sound buffer");
return;
}
#endif
NazaraAssert(IsPlayable(), "Music is not playable");
alSourcePlay(m_source);
}
@@ -252,16 +231,9 @@ namespace Nz
*
* \remark Produces a NazaraError if buffer is invalid with NAZARA_AUDIO_SAFE defined
*/
void Sound::SetBuffer(const SoundBuffer* buffer)
{
#if NAZARA_AUDIO_SAFE
if (buffer && !buffer->IsValid())
{
NazaraError("Invalid sound buffer");
return;
}
#endif
NazaraAssert(!buffer || buffer->IsValid(), "Invalid sound buffer");
if (m_buffer == buffer)
return;
@@ -281,7 +253,6 @@ namespace Nz
*
* \param offset Offset in the sound in milliseconds
*/
void Sound::SetPlayingOffset(UInt32 offset)
{
alSourcei(m_source, AL_SAMPLE_OFFSET, static_cast<ALint>(offset/1000.f * m_buffer->GetSampleRate()));
@@ -290,7 +261,6 @@ namespace Nz
/*!
* \brief Stops the sound
*/
void Sound::Stop()
{
alSourceStop(m_source);

View File

@@ -6,6 +6,7 @@
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Audio/Config.hpp>
#include <Nazara/Audio/OpenAL.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <cstring>
#include <memory>
@@ -40,7 +41,7 @@ namespace Nz
AudioFormat format;
UInt32 duration;
std::unique_ptr<Int16[]> samples;
UInt32 sampleCount;
UInt64 sampleCount;
UInt32 sampleRate;
};
@@ -57,8 +58,7 @@ namespace Nz
*
* \see Create
*/
SoundBuffer::SoundBuffer(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples)
SoundBuffer::SoundBuffer(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples)
{
Create(format, sampleCount, sampleRate, samples);
@@ -76,7 +76,6 @@ namespace Nz
*
* \see Destroy
*/
SoundBuffer::~SoundBuffer()
{
OnSoundBufferRelease(this);
@@ -96,8 +95,7 @@ namespace Nz
* \remark Produces a NazaraError if creation went wrong with NAZARA_AUDIO_SAFE defined,
* this could happen if parameters are invalid or creation of OpenAL buffers failed
*/
bool SoundBuffer::Create(AudioFormat format, unsigned int sampleCount, unsigned int sampleRate, const Int16* samples)
bool SoundBuffer::Create(AudioFormat format, UInt64 sampleCount, UInt32 sampleRate, const Int16* samples)
{
Destroy();
@@ -132,19 +130,18 @@ namespace Nz
ALuint buffer;
alGenBuffers(1, &buffer);
if (alGetError() != AL_NO_ERROR)
{
NazaraError("Failed to create OpenAL buffer");
return false;
}
alBufferData(buffer, OpenAL::AudioFormat[format], samples, sampleCount*sizeof(Int16), sampleRate);
CallOnExit clearBufferOnExit([buffer] () { alDeleteBuffers(1, &buffer); });
alBufferData(buffer, OpenAL::AudioFormat[format], samples, static_cast<ALsizei>(sampleCount*sizeof(Int16)), static_cast<ALsizei>(sampleRate));
if (alGetError() != AL_NO_ERROR)
{
alDeleteBuffers(1, &buffer);
NazaraError("Failed to set OpenAL buffer");
return false;
}
@@ -158,6 +155,8 @@ namespace Nz
m_impl->samples.reset(new Int16[sampleCount]);
std::memcpy(&m_impl->samples[0], samples, sampleCount*sizeof(Int16));
clearBufferOnExit.Reset();
return true;
}
@@ -182,16 +181,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
UInt32 SoundBuffer::GetDuration() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Sound buffer not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Sound buffer not created");
return m_impl->duration;
}
@@ -205,13 +197,7 @@ namespace Nz
AudioFormat SoundBuffer::GetFormat() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Sound buffer not created");
return AudioFormat_Unknown;
}
#endif
NazaraAssert(m_impl, "Sound buffer not created");
return m_impl->format;
}
@@ -222,16 +208,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
const Int16* SoundBuffer::GetSamples() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Sound buffer not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "Sound buffer not created");
return m_impl->samples.get();
}
@@ -242,16 +221,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
unsigned int SoundBuffer::GetSampleCount() const
UInt64 SoundBuffer::GetSampleCount() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Sound buffer not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Sound buffer not created");
return m_impl->sampleCount;
}
@@ -262,16 +234,9 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
unsigned int SoundBuffer::GetSampleRate() const
UInt32 SoundBuffer::GetSampleRate() const
{
#if NAZARA_AUDIO_SAFE
if (!m_impl)
{
NazaraError("Sound buffer not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Sound buffer not created");
return m_impl->sampleRate;
}
@@ -293,7 +258,6 @@ namespace Nz
* \param filePath Path to the file
* \param params Parameters for the sound buffer
*/
bool SoundBuffer::LoadFromFile(const String& filePath, const SoundBufferParams& params)
{
return SoundBufferLoader::LoadFromFile(this, filePath, params);
@@ -307,7 +271,6 @@ namespace Nz
* \param size Size of the memory
* \param params Parameters for the sound buffer
*/
bool SoundBuffer::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params)
{
return SoundBufferLoader::LoadFromMemory(this, data, size, params);
@@ -320,7 +283,6 @@ namespace Nz
* \param stream Stream to the sound buffer
* \param params Parameters for the sound buffer
*/
bool SoundBuffer::LoadFromStream(Stream& stream, const SoundBufferParams& params)
{
return SoundBufferLoader::LoadFromStream(this, stream, params);
@@ -332,7 +294,6 @@ namespace Nz
*
* \param format Format to check
*/
bool SoundBuffer::IsFormatSupported(AudioFormat format)
{
return Audio::IsFormatSupported(format);
@@ -344,7 +305,6 @@ namespace Nz
*
* \remark Produces a NazaraError if there is no sound buffer with NAZARA_AUDIO_SAFE defined
*/
unsigned int SoundBuffer::GetOpenALBuffer() const
{
#ifdef NAZARA_DEBUG
@@ -364,7 +324,6 @@ namespace Nz
*
* \remark Produces a NazaraError if sub-initialization failed
*/
bool SoundBuffer::Initialize()
{
if (!SoundBufferLibrary::Initialize())
@@ -385,7 +344,6 @@ namespace Nz
/*!
* \brief Uninitializes the libraries and managers
*/
void SoundBuffer::Uninitialize()
{
SoundBufferManager::Uninitialize();

View File

@@ -76,25 +76,25 @@ namespace Nz
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
int supported;
asm volatile (" pushfl\n"
" pop %%eax\n"
" mov %%eax, %%ecx\n"
" xor $0x200000, %%eax\n"
" push %%eax\n"
" popfl\n"
" pushfl\n"
" pop %%eax\n"
" xor %%ecx, %%eax\n"
" mov %%eax, %0\n"
" push %%ecx\n"
" popfl"
: "=m" (supported) // output
: // input
: "eax", "ecx", "memory"); // clobbered register
" pop %%eax\n"
" mov %%eax, %%ecx\n"
" xor $0x200000, %%eax\n"
" push %%eax\n"
" popfl\n"
" pushfl\n"
" pop %%eax\n"
" xor %%ecx, %%eax\n"
" mov %%eax, %0\n"
" push %%ecx\n"
" popfl"
: "=m" (supported) // output
: // input
: "eax", "ecx", "memory"); // clobbered register
return supported != 0;
#else
return false;
#endif
#endif
}
}
}

View File

@@ -30,7 +30,7 @@ namespace Nz
if (!m_material)
return;
Nz::Vector3f position = instanceData.transformMatrix->GetTranslation();
Nz::Vector3f position = instanceData.transformMatrix.GetTranslation();
renderQueue->AddBillboards(instanceData.renderOrder, m_material, 1, &position, &m_size, &m_sinCos, &m_color);
}

View File

@@ -187,18 +187,11 @@ namespace Nz
drawFunc(meshData.primitiveMode, 0, indexCount);
}
}
instances.clear();
}
}
}
// And we set it back data to zero
matEntry.enabled = false;
}
}
pipelineEntry.maxInstanceCount = 0;
}
}
}

View File

@@ -273,11 +273,43 @@ namespace Nz
layers.clear();
else
{
for (auto it = layers.begin(); it != layers.end(); ++it)
for (auto it = layers.begin(); it != layers.end();)
{
Layer& layer = it->second;
if (layer.clearCount++ >= 100)
it = layers.erase(it);
else
{
for (auto& pipelinePair : layer.opaqueModels)
{
const MaterialPipeline* pipeline = pipelinePair.first;
auto& pipelineEntry = pipelinePair.second;
if (pipelineEntry.maxInstanceCount > 0)
{
for (auto& materialPair : pipelineEntry.materialMap)
{
auto& matEntry = materialPair.second;
if (matEntry.enabled)
{
MeshInstanceContainer& meshInstances = matEntry.meshMap;
for (auto& meshIt : meshInstances)
{
auto& meshEntry = meshIt.second;
meshEntry.instances.clear();
}
matEntry.enabled = false;
}
}
pipelineEntry.maxInstanceCount = 0;
}
}
++it;
}
}
}

View File

@@ -527,6 +527,62 @@ namespace Nz
layers.erase(it++);
else
{
for (auto& pipelinePair : layer.basicSprites)
{
auto& pipelineEntry = pipelinePair.second;
if (pipelineEntry.enabled)
{
for (auto& materialPair : pipelineEntry.materialMap)
{
auto& matEntry = materialPair.second;
if (matEntry.enabled)
{
auto& overlayMap = matEntry.overlayMap;
for (auto& overlayIt : overlayMap)
{
const Texture* overlay = overlayIt.first;
auto& spriteChainVector = overlayIt.second.spriteChains;
spriteChainVector.clear();
}
matEntry.enabled = false;
}
}
pipelineEntry.enabled = false;
}
}
for (auto& pipelinePair : layer.opaqueModels)
{
auto& pipelineEntry = pipelinePair.second;
if (pipelineEntry.maxInstanceCount > 0)
{
for (auto& materialPair : pipelineEntry.materialMap)
{
const Material* material = materialPair.first;
auto& matEntry = materialPair.second;
if (matEntry.enabled)
{
MeshInstanceContainer& meshInstances = matEntry.meshMap;
for (auto& meshIt : meshInstances)
{
auto& meshEntry = meshIt.second;
meshEntry.instances.clear();
}
matEntry.enabled = false;
}
}
pipelineEntry.maxInstanceCount = 0;
}
}
layer.otherDrawables.clear();
layer.transparentModels.clear();
layer.transparentModelData.clear();

View File

@@ -386,17 +386,12 @@ namespace Nz
vertexMapper.Unmap();
Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, spriteCount * 6);
} while (spriteChain < spriteChainCount);
spriteChainVector.clear();
}
while (spriteChain < spriteChainCount);
}
}
// We set it back to zero
matEntry.enabled = false;
}
}
pipelineEntry.enabled = false;
}
}
}
@@ -781,12 +776,8 @@ namespace Nz
instances.clear();
}
}
matEntry.enabled = false;
}
}
pipelineEntry.maxInstanceCount = 0;
}
}
}

View File

@@ -80,7 +80,7 @@ namespace Nz
NazaraAssert(instanceData, "Invalid instance data");
NazaraUnused(instanceData);
instanceData->volume.Update(*instanceData->transformMatrix);
instanceData->volume.Update(instanceData->transformMatrix);
}
/*!

View File

@@ -82,7 +82,7 @@ namespace Nz
meshData.primitiveMode = mesh->GetPrimitiveMode();
meshData.vertexBuffer = mesh->GetVertexBuffer();
renderQueue->AddMesh(instanceData.renderOrder, material, meshData, mesh->GetAABB(), *instanceData.transformMatrix);
renderQueue->AddMesh(instanceData.renderOrder, material, meshData, mesh->GetAABB(), instanceData.transformMatrix);
}
}

View File

@@ -69,7 +69,7 @@ namespace Nz
meshData.primitiveMode = mesh->GetPrimitiveMode();
meshData.vertexBuffer = SkinningManager::GetBuffer(mesh, &m_skeleton);
renderQueue->AddMesh(instanceData.renderOrder, material, meshData, m_skeleton.GetAABB(), *instanceData.transformMatrix);
renderQueue->AddMesh(instanceData.renderOrder, material, meshData, m_skeleton.GetAABB(), instanceData.transformMatrix);
}
}

View File

@@ -39,7 +39,9 @@ namespace Nz
void Sprite::MakeBoundingVolume() const
{
m_boundingVolume.Set(Vector3f(0.f), m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down());
Vector3f origin(m_origin.x, -m_origin.y, m_origin.z);
m_boundingVolume.Set(-origin, m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down() - origin);
}
/*!
@@ -47,7 +49,6 @@ namespace Nz
*
* \param instanceData Data of the instance
*/
void Sprite::UpdateData(InstanceData* instanceData) const
{
instanceData->data.resize(4 * sizeof(VertexStruct_XYZ_Color_UV));
@@ -57,25 +58,27 @@ namespace Nz
SparsePtr<Vector3f> posPtr(&vertices[0].position, sizeof(VertexStruct_XYZ_Color_UV));
SparsePtr<Vector2f> texCoordPtr(&vertices[0].uv, sizeof(VertexStruct_XYZ_Color_UV));
*colorPtr++ = m_color;
*posPtr++ = instanceData->transformMatrix->Transform(Vector3f(0.f));
Vector3f origin(m_origin.x, -m_origin.y, m_origin.z);
*colorPtr++ = m_color * m_cornerColor[RectCorner_LeftTop];
*posPtr++ = instanceData->transformMatrix.Transform(Vector3f(-origin));
*texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftTop);
*colorPtr++ = m_color;
*posPtr++ = instanceData->transformMatrix->Transform(m_size.x*Vector3f::Right());
*colorPtr++ = m_color * m_cornerColor[RectCorner_RightTop];
*posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() - origin);
*texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightTop);
*colorPtr++ = m_color;
*posPtr++ = instanceData->transformMatrix->Transform(m_size.y*Vector3f::Down());
*colorPtr++ = m_color * m_cornerColor[RectCorner_LeftBottom];
*posPtr++ = instanceData->transformMatrix.Transform(m_size.y*Vector3f::Down() - origin);
*texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftBottom);
*colorPtr++ = m_color;
*posPtr++ = instanceData->transformMatrix->Transform(m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down());
*colorPtr++ = m_color * m_cornerColor[RectCorner_RightBottom];
*posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down() - origin);
*texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightBottom);
}
/*!
* \brief Initializes the sprite librairies
* \brief Initializes the sprite library
* \return true If successful
*
* \remark Produces a NazaraError if the sprite library failed to be initialized
@@ -93,7 +96,7 @@ namespace Nz
}
/*!
* \brief Uninitializes the sprite librairies
* \brief Uninitializes the sprite library
*/
void Sprite::Uninitialize()

View File

@@ -310,7 +310,7 @@ namespace Nz
Vector3f localPos = localVertex->position.x*Vector3f::Right() + localVertex->position.y*Vector3f::Down();
localPos *= m_scale;
*pos++ = instanceData->transformMatrix->Transform(localPos);
*pos++ = instanceData->transformMatrix.Transform(localPos);
*color++ = m_color * localVertex->color;
*uv++ = localVertex->uv;

View File

@@ -71,25 +71,32 @@ namespace Nz
Vector3f tileLeftCorner(x * m_tileSize.x, y * -m_tileSize.y, 0.f);
*colorPtr++ = tile.color;
*posPtr++ = instanceData->transformMatrix->Transform(tileLeftCorner);
*posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner);
*texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_LeftTop);
*colorPtr++ = tile.color;
*posPtr++ = instanceData->transformMatrix->Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right());
*posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right());
*texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_RightTop);
*colorPtr++ = tile.color;
*posPtr++ = instanceData->transformMatrix->Transform(tileLeftCorner + m_tileSize.y * Vector3f::Down());
*posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.y * Vector3f::Down());
*texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_LeftBottom);
*colorPtr++ = tile.color;
*posPtr++ = instanceData->transformMatrix->Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right() + m_tileSize.y * Vector3f::Down());
*posPtr++ = instanceData->transformMatrix.Transform(tileLeftCorner + m_tileSize.x * Vector3f::Right() + m_tileSize.y * Vector3f::Down());
*texCoordPtr++ = tile.textureCoords.GetCorner(RectCorner_RightBottom);
}
spriteCount += layer.tiles.size();
}
}
/*!
* \brief Initializes the tilemap library
* \return true If successful
*
* \remark Produces a NazaraError if the tilemap library failed to be initialized
*/
bool TileMap::Initialize()
{
if (!TileMapLibrary::Initialize())
@@ -101,6 +108,10 @@ namespace Nz
return true;
}
/*!
* \brief Uninitializes the tilemap library
*/
void TileMap::Uninitialize()
{
TileMapLibrary::Uninitialize();

View File

@@ -145,7 +145,8 @@ namespace Nz
LuaInstance::~LuaInstance()
{
lua_close(m_state);
if (m_state)
lua_close(m_state);
}
void LuaInstance::ArgCheck(bool condition, unsigned int argNum, const char* error)
@@ -463,26 +464,6 @@ namespace Nz
return FromLuaType(lua_getglobal(m_state, name.GetConstBuffer()));
}
lua_State* LuaInstance::GetInternalState() const
{
return m_state;
}
String LuaInstance::GetLastError() const
{
return m_lastError;
}
UInt32 LuaInstance::GetMemoryLimit() const
{
return m_memoryLimit;
}
UInt32 LuaInstance::GetMemoryUsage() const
{
return m_memoryUsage;
}
LuaType LuaInstance::GetMetatable(const char* tname) const
{
return FromLuaType(luaL_getmetatable(m_state, tname));
@@ -500,7 +481,7 @@ namespace Nz
unsigned int LuaInstance::GetStackTop() const
{
return lua_gettop(m_state);
return static_cast<int>(lua_gettop(m_state));
}
LuaType LuaInstance::GetTable(int index) const
@@ -508,11 +489,6 @@ namespace Nz
return FromLuaType(lua_gettable(m_state, index));
}
UInt32 LuaInstance::GetTimeLimit() const
{
return m_timeLimit;
}
LuaType LuaInstance::GetType(int index) const
{
return FromLuaType(lua_type(m_state, index));
@@ -689,9 +665,10 @@ namespace Nz
lua_pushlstring(m_state, str.GetConstBuffer(), str.GetSize());
}
void LuaInstance::PushTable(unsigned int sequenceElementCount, unsigned int arrayElementCount) const
void LuaInstance::PushTable(std::size_t sequenceElementCount, std::size_t arrayElementCount) const
{
lua_createtable(m_state, sequenceElementCount, arrayElementCount);
constexpr std::size_t maxInt = std::numeric_limits<int>::max();
lua_createtable(m_state, static_cast<int>(std::min(sequenceElementCount, maxInt)), static_cast<int>(std::min(arrayElementCount, maxInt)));
}
void* LuaInstance::PushUserdata(std::size_t size) const

View File

@@ -93,7 +93,7 @@ namespace Nz
}
/*!
* \brief Uninitializes the Core module
* \brief Uninitializes the Network module
*
* \remark Produces a NazaraNotice
*/

View File

@@ -56,7 +56,7 @@ namespace Nz
std::array<char, NI_MAXHOST> hostnameBuffer;
std::array<char, NI_MAXSERV> serviceBuffer;
int result = getnameinfo(socketAddress, socketLen, hostnameBuffer.data(), static_cast<std::size_t>(hostnameBuffer.size()), serviceBuffer.data(), static_cast<std::size_t>(serviceBuffer.size()), flags);
int result = getnameinfo(socketAddress, socketLen, hostnameBuffer.data(), static_cast<DWORD>(hostnameBuffer.size()), serviceBuffer.data(), static_cast<DWORD>(serviceBuffer.size()), flags);
if (result == 0)
{
if (hostname)

View File

@@ -8,8 +8,9 @@
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
#include <Winsock2.h>
#ifdef NAZARA_COMPILER_MINGW
// MinGW is lacking Mstcpip.h and that's too bad
// Some compilers (olders versions of MinGW) are lacking Mstcpip.h which defines the following struct/#define
// Define them ourself for now
struct tcp_keepalive
{
u_long onoff;
@@ -18,9 +19,6 @@ struct tcp_keepalive
};
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
#else
#include <Mstcpip.h>
#endif // NAZARA_COMPILER_MINGW
#include <Nazara/Network/Debug.hpp>

View File

@@ -125,16 +125,7 @@ namespace Nz
PhysGeomRef PhysGeom::Build(const PrimitiveList& list)
{
unsigned int primitiveCount = list.GetSize();
#if NAZARA_PHYSICS_SAFE
if (primitiveCount == 0)
{
NazaraError("PrimitiveList must have at least one primitive");
return nullptr;
}
#endif
std::size_t primitiveCount = list.GetSize();
if (primitiveCount > 1)
{
std::vector<PhysGeom*> geoms(primitiveCount);
@@ -144,8 +135,10 @@ namespace Nz
return CompoundGeom::New(&geoms[0], primitiveCount);
}
else
else if (primitiveCount > 0)
return CreateGeomFromPrimitive(list.GetPrimitive(0));
else
return NullGeom::New();
}
bool PhysGeom::Initialize()
@@ -246,10 +239,10 @@ namespace Nz
/******************************* CompoundGeom ********************************/
CompoundGeom::CompoundGeom(PhysGeom** geoms, unsigned int geomCount)
CompoundGeom::CompoundGeom(PhysGeom** geoms, std::size_t geomCount)
{
m_geoms.reserve(geomCount);
for (unsigned int i = 0; i < geomCount; ++i)
for (std::size_t i = 0; i < geomCount; ++i)
m_geoms.emplace_back(geoms[i]);
}
@@ -349,7 +342,7 @@ namespace Nz
NewtonCollision* ConvexHullGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateConvexHull(world->GetHandle(), m_vertices.size(), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
return NewtonCreateConvexHull(world->GetHandle(), static_cast<int>(m_vertices.size()), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
}
/******************************* CylinderGeom ********************************/

View File

@@ -14,13 +14,13 @@ namespace Nz
{
struct AnimationImpl
{
std::unordered_map<String, unsigned int> sequenceMap;
std::unordered_map<String, UInt32> sequenceMap;
std::vector<Sequence> sequences;
std::vector<SequenceJoint> sequenceJoints; // Uniquement pour les animations squelettiques
AnimationType type;
bool loopPointInterpolation = false;
unsigned int frameCount;
unsigned int jointCount; // Uniquement pour les animations squelettiques
UInt32 frameCount;
UInt32 jointCount; // Uniquement pour les animations squelettiques
};
bool AnimationParams::IsValid() const
@@ -43,40 +43,18 @@ namespace Nz
bool Animation::AddSequence(const Sequence& sequence)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
if (sequence.frameCount == 0)
{
NazaraError("Sequence frame count must be over zero");
return false;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(sequence.frameCount > 0, "Sequence frame count must be over zero");
if (m_impl->type == AnimationType_Skeletal)
{
unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1;
UInt32 endFrame = sequence.firstFrame + sequence.frameCount - 1;
if (endFrame >= m_impl->frameCount)
{
m_impl->frameCount = endFrame+1;
m_impl->sequenceJoints.resize(m_impl->frameCount*m_impl->jointCount);
}
}
#if NAZARA_UTILITY_SAFE
else
{
unsigned int endFrame = sequence.firstFrame + sequence.frameCount - 1;
if (endFrame >= m_impl->frameCount)
{
NazaraError("Sequence end frame is over animation end frame");
return false;
}
}
#endif
if (!sequence.name.IsEmpty())
{
@@ -84,12 +62,12 @@ namespace Nz
auto it = m_impl->sequenceMap.find(sequence.name);
if (it != m_impl->sequenceMap.end())
{
NazaraError("Sequence name \"" + sequence.name + "\" is already used");
NazaraError("Sequence name \"" + sequence.name + "\" is already in use");
return false;
}
#endif
m_impl->sequenceMap[sequence.name] = m_impl->sequences.size();
m_impl->sequenceMap[sequence.name] = static_cast<UInt32>(m_impl->sequences.size());
}
m_impl->sequences.push_back(sequence);
@@ -97,55 +75,16 @@ namespace Nz
return true;
}
void Animation::AnimateSkeleton(Skeleton* targetSkeleton, unsigned int frameA, unsigned int frameB, float interpolation) const
void Animation::AnimateSkeleton(Skeleton* targetSkeleton, UInt32 frameA, UInt32 frameB, float interpolation) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
NazaraAssert(targetSkeleton && targetSkeleton->IsValid(), "Invalid skeleton");
NazaraAssert(targetSkeleton->GetJointCount() == m_impl->jointCount, "Skeleton joint does not match animation joint count");
NazaraAssert(frameA < m_impl->frameCount, "FrameA is out of range");
NazaraAssert(frameB < m_impl->frameCount, "FrameB is out of range");
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return;
}
if (!targetSkeleton || !targetSkeleton->IsValid())
{
NazaraError("Target skeleton is invalid");
return;
}
if (targetSkeleton->GetJointCount() != m_impl->jointCount)
{
NazaraError("Target skeleton joint count must match animation joint count");
return;
}
if (frameA >= m_impl->frameCount)
{
NazaraError("Frame A is out of range (" + String::Number(frameA) + " >= " + String::Number(m_impl->frameCount) + ')');
return;
}
if (frameB >= m_impl->frameCount)
{
NazaraError("Frame B is out of range (" + String::Number(frameB) + " >= " + String::Number(m_impl->frameCount) + ')');
return;
}
#endif
#ifdef NAZARA_DEBUG
if (interpolation < 0.f || interpolation > 1.f)
{
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
return;
}
#endif
for (unsigned int i = 0; i < m_impl->jointCount; ++i)
for (UInt32 i = 0; i < m_impl->jointCount; ++i)
{
Joint* joint = targetSkeleton->GetJoint(i);
@@ -158,17 +97,12 @@ namespace Nz
}
}
bool Animation::CreateSkeletal(unsigned int frameCount, unsigned int jointCount)
bool Animation::CreateSkeletal(UInt32 frameCount, UInt32 jointCount)
{
Destroy();
NazaraAssert(frameCount > 0, "Frame count must be over zero");
NazaraAssert(jointCount > 0, "Frame count must be over zero");
#if NAZARA_UTILITY_SAFE
if (frameCount == 0)
{
NazaraError("Frame count must be over zero");
return false;
}
#endif
Destroy();
m_impl = new AnimationImpl;
m_impl->frameCount = frameCount;
@@ -192,255 +126,130 @@ namespace Nz
void Animation::EnableLoopPointInterpolation(bool loopPointInterpolation)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
#endif
NazaraAssert(m_impl, "Animation not created");
m_impl->loopPointInterpolation = loopPointInterpolation;
}
unsigned int Animation::GetFrameCount() const
UInt32 Animation::GetFrameCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->frameCount;
}
unsigned int Animation::GetJointCount() const
UInt32 Animation::GetJointCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return 0;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->jointCount;
}
Sequence* Animation::GetSequence(const String& sequenceName)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
#endif
return &m_impl->sequences[it->second];
}
Sequence* Animation::GetSequence(unsigned int index)
Sequence* Animation::GetSequence(UInt32 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 (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
return &m_impl->sequences[index];
}
const Sequence* Animation::GetSequence(const String& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return nullptr;
}
#endif
return &m_impl->sequences[it->second];
}
const Sequence* Animation::GetSequence(unsigned int index) const
const Sequence* Animation::GetSequence(UInt32 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 (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')');
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
return &m_impl->sequences[index];
}
unsigned int Animation::GetSequenceCount() const
UInt32 Animation::GetSequenceCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return 0;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->sequences.size();
return static_cast<UInt32>(m_impl->sequences.size());
}
int Animation::GetSequenceIndex(const String& sequenceName) const
UInt32 Animation::GetSequenceIndex(const String& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return -1;
}
#endif
NazaraAssert(m_impl, "Animation not created");
auto it = m_impl->sequenceMap.find(sequenceName);
#if NAZARA_UTILITY_SAFE
if (it == m_impl->sequenceMap.end())
{
NazaraError("Sequence not found");
return -1;
return 0xFFFFFFFF;
}
#endif
return it->second;
}
SequenceJoint* Animation::GetSequenceJoints(unsigned int frameIndex)
SequenceJoint* Animation::GetSequenceJoints(UInt32 frameIndex)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
}
const SequenceJoint* Animation::GetSequenceJoints(unsigned int frameIndex) const
const SequenceJoint* Animation::GetSequenceJoints(UInt32 frameIndex) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return nullptr;
}
if (m_impl->type != AnimationType_Skeletal)
{
NazaraError("Animation is not skeletal");
return nullptr;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(m_impl->type == AnimationType_Skeletal, "Animation is not skeletal");
return &m_impl->sequenceJoints[frameIndex*m_impl->jointCount];
}
AnimationType Animation::GetType() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return AnimationType_Static; // Ce qui est une valeur invalide pour Animation
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->type;
}
bool Animation::HasSequence(const String& sequenceName) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->sequenceMap.find(sequenceName) != m_impl->sequenceMap.end();
}
bool Animation::HasSequence(unsigned int index) const
bool Animation::HasSequence(UInt32 index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return index >= m_impl->sequences.size();
}
bool Animation::IsLoopPointInterpolationEnabled() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return false;
}
#endif
NazaraAssert(m_impl, "Animation not created");
return m_impl->loopPointInterpolation;
}
@@ -467,12 +276,7 @@ namespace Nz
void Animation::RemoveSequence(const String& identifier)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
{
NazaraError("Animation not created");
return;
}
NazaraAssert(m_impl, "Animation not created");
auto it = m_impl->sequenceMap.find(identifier);
if (it == m_impl->sequenceMap.end())
@@ -481,32 +285,16 @@ namespace Nz
return;
}
int index = it->second;
#else
int index = m_impl->sequenceMap[identifier];
#endif
auto sequenceIt = m_impl->sequences.begin();
std::advance(sequenceIt, it->second);
auto it2 = m_impl->sequences.begin();
std::advance(it2, index);
m_impl->sequences.erase(it2);
m_impl->sequences.erase(sequenceIt);
}
void Animation::RemoveSequence(unsigned int index)
void Animation::RemoveSequence(UInt32 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 (" + String::Number(index) + " >= " + String::Number(m_impl->sequences.size()) + ')');
return;
}
#endif
NazaraAssert(m_impl, "Animation not created");
NazaraAssert(index < m_impl->sequences.size(), "Sequence index out of range");
auto it = m_impl->sequences.begin();
std::advance(it, index);

View File

@@ -37,10 +37,10 @@ namespace Nz
}
const MD5AnimParser::Frame* frames = parser.GetFrames();
std::size_t frameCount = parser.GetFrameCount();
std::size_t frameRate = parser.GetFrameRate();
UInt32 frameCount = parser.GetFrameCount();
UInt32 frameRate = parser.GetFrameRate();
const MD5AnimParser::Joint* joints = parser.GetJoints();
std::size_t jointCount = parser.GetJointCount();
UInt32 jointCount = parser.GetJointCount();
// À ce stade, nous sommes censés avoir assez d'informations pour créer l'animation
animation->CreateSkeletal(frameCount, jointCount);
@@ -57,12 +57,12 @@ namespace Nz
// Pour que le squelette soit correctement aligné, il faut appliquer un quaternion "de correction" aux joints à la base du squelette
Quaternionf rotationQuat = Quaternionf::RotationBetween(Vector3f::UnitX(), Vector3f::Forward()) *
Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
Quaternionf::RotationBetween(Vector3f::UnitZ(), Vector3f::Up());
for (std::size_t i = 0; i < jointCount; ++i)
for (UInt32 i = 0; i < jointCount; ++i)
{
int parent = joints[i].parent;
for (std::size_t j = 0; j < frameCount; ++j)
for (UInt32 j = 0; j < frameCount; ++j)
{
SequenceJoint& sequenceJoint = sequenceJoints[j*jointCount + i];

View File

@@ -48,9 +48,9 @@ namespace Nz
return Ternary_False;
}
std::size_t MD5AnimParser::GetAnimatedComponentCount() const
UInt32 MD5AnimParser::GetAnimatedComponentCount() const
{
return m_animatedComponents.size();
return static_cast<UInt32>(m_animatedComponents.size());
}
const MD5AnimParser::Frame* MD5AnimParser::GetFrames() const
@@ -58,12 +58,12 @@ namespace Nz
return m_frames.data();
}
std::size_t MD5AnimParser::GetFrameCount() const
UInt32 MD5AnimParser::GetFrameCount() const
{
return m_frames.size();
return static_cast<UInt32>(m_frames.size());
}
std::size_t MD5AnimParser::GetFrameRate() const
UInt32 MD5AnimParser::GetFrameRate() const
{
return m_frameRate;
}
@@ -73,9 +73,9 @@ namespace Nz
return m_joints.data();
}
std::size_t MD5AnimParser::GetJointCount() const
UInt32 MD5AnimParser::GetJointCount() const
{
return m_joints.size();
return static_cast<UInt32>(m_joints.size());
}
bool MD5AnimParser::Parse()
@@ -209,14 +209,14 @@ namespace Nz
}
}
unsigned int frameCount = m_frames.size();
std::size_t frameCount = m_frames.size();
if (frameCount == 0)
{
NazaraError("Frame count is invalid or missing");
return false;
}
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
NazaraError("Joint count is invalid or missing");
@@ -273,21 +273,21 @@ namespace Nz
bool MD5AnimParser::ParseBaseframe()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
// Space is important for the buffer of \n
if (std::sscanf(&m_currentLine[0], " ( %f %f %f ) ( %f %f %f )", &m_joints[i].bindPos.x, &m_joints[i].bindPos.y, &m_joints[i].bindPos.z,
&m_joints[i].bindOrient.x, &m_joints[i].bindOrient.y, &m_joints[i].bindOrient.z) != 6)
&m_joints[i].bindOrient.x, &m_joints[i].bindOrient.y, &m_joints[i].bindOrient.z) != 6)
{
UnrecognizedLine(true);
return false;
@@ -312,14 +312,14 @@ namespace Nz
bool MD5AnimParser::ParseBounds()
{
unsigned int frameCount = m_frames.size();
std::size_t frameCount = m_frames.size();
if (frameCount == 0)
{
Error("Frame count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < frameCount; ++i)
for (std::size_t i = 0; i < frameCount; ++i)
{
if (!Advance())
return false;
@@ -353,14 +353,14 @@ namespace Nz
bool MD5AnimParser::ParseFrame()
{
unsigned int animatedComponentsCount = m_animatedComponents.size();
std::size_t animatedComponentsCount = m_animatedComponents.size();
if (animatedComponentsCount == 0)
{
Error("Animated components count is missing or invalid");
return false;
}
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
@@ -369,14 +369,14 @@ namespace Nz
String line;
unsigned int count = 0;
std::size_t count = 0;
do
{
if (!Advance())
return false;
unsigned int index = 0;
unsigned int size = m_currentLine.GetSize();
std::size_t index = 0;
std::size_t size = m_currentLine.GetSize();
do
{
float f;
@@ -399,11 +399,11 @@ namespace Nz
m_frames[m_frameIndex].joints.resize(jointCount);
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
Quaternionf jointOrient = m_joints[i].bindOrient;
Vector3f jointPos = m_joints[i].bindPos;
unsigned int j = 0;
UInt32 j = 0;
if (m_joints[i].flags & 1) // Px
jointPos.x = m_animatedComponents[m_joints[i].index + j++];
@@ -447,19 +447,19 @@ namespace Nz
bool MD5AnimParser::ParseHierarchy()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
unsigned int pos = m_currentLine.Find(' ');
std::size_t pos = m_currentLine.Find(' ');
if (pos == String::npos)
{
UnrecognizedLine(true);
@@ -482,10 +482,10 @@ namespace Nz
m_joints[i].name = name;
m_joints[i].name.Trim('"');
int parent = m_joints[i].parent;
Int32 parent = m_joints[i].parent;
if (parent >= 0)
{
if (static_cast<unsigned int>(parent) >= jointCount)
if (static_cast<UInt32>(parent) >= jointCount)
{
Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')');
return false;

View File

@@ -53,15 +53,15 @@ namespace Nz
const MD5MeshParser::Joint* joints = parser.GetJoints();
const MD5MeshParser::Mesh* meshes = parser.GetMeshes();
std::size_t jointCount = parser.GetJointCount();
std::size_t meshCount = parser.GetMeshCount();
UInt32 jointCount = parser.GetJointCount();
UInt32 meshCount = parser.GetMeshCount();
if (parameters.animated)
{
mesh->CreateSkeletal(jointCount);
Skeleton* skeleton = mesh->GetSkeleton();
for (std::size_t i = 0; i < jointCount; ++i)
for (UInt32 i = 0; i < jointCount; ++i)
{
Joint* joint = skeleton->GetJoint(i);
@@ -82,7 +82,7 @@ namespace Nz
}
mesh->SetMaterialCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
@@ -100,7 +100,7 @@ namespace Nz
// Le format définit un set de triangles nous permettant de retrouver facilement les indices
// Cependant les sommets des triangles ne sont pas spécifiés dans le même ordre que ceux du moteur
// (On parle ici de winding)
unsigned int index = 0;
UInt32 index = 0;
for (const MD5MeshParser::Triangle& triangle : md5Mesh.triangles)
{
// On les respécifie dans le bon ordre (inversion du winding)
@@ -227,7 +227,7 @@ namespace Nz
}
mesh->SetMaterialCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const MD5MeshParser::Mesh& md5Mesh = meshes[i];
std::size_t indexCount = md5Mesh.triangles.size()*3;

View File

@@ -58,9 +58,9 @@ namespace Nz
return m_joints.data();
}
std::size_t MD5MeshParser::GetJointCount() const
UInt32 MD5MeshParser::GetJointCount() const
{
return m_joints.size();
return static_cast<UInt32>(m_joints.size());
}
const MD5MeshParser::Mesh* MD5MeshParser::GetMeshes() const
@@ -68,9 +68,9 @@ namespace Nz
return m_meshes.data();
}
std::size_t MD5MeshParser::GetMeshCount() const
UInt32 MD5MeshParser::GetMeshCount() const
{
return m_meshes.size();
return static_cast<UInt32>(m_meshes.size());
}
bool MD5MeshParser::Parse()
@@ -211,19 +211,19 @@ namespace Nz
bool MD5MeshParser::ParseJoints()
{
unsigned int jointCount = m_joints.size();
std::size_t jointCount = m_joints.size();
if (jointCount == 0)
{
Error("Joint count is invalid or missing");
return false;
}
for (unsigned int i = 0; i < jointCount; ++i)
for (std::size_t i = 0; i < jointCount; ++i)
{
if (!Advance())
return false;
unsigned int pos = m_currentLine.Find(' ');
std::size_t pos = m_currentLine.Find(' ');
if (pos == String::npos)
{
UnrecognizedLine(true);
@@ -248,10 +248,10 @@ namespace Nz
m_joints[i].name = name;
m_joints[i].name.Trim('"');
int parent = m_joints[i].parent;
Int32 parent = m_joints[i].parent;
if (parent >= 0)
{
if (static_cast<unsigned int>(parent) >= jointCount)
if (static_cast<std::size_t>(parent) >= jointCount)
{
Error("Joint's parent is out of bounds (" + String::Number(parent) + " >= " + String::Number(jointCount) + ')');
return false;

View File

@@ -160,7 +160,7 @@ namespace Nz
}
else if (keyword == "map_ka")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -172,7 +172,7 @@ namespace Nz
}
else if (keyword == "map_kd")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -184,7 +184,7 @@ namespace Nz
}
else if (keyword == "map_ks")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -196,7 +196,7 @@ namespace Nz
}
else if (keyword == "map_bump" || keyword == "bump")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -208,7 +208,7 @@ namespace Nz
}
else if (keyword == "map_d")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -220,7 +220,7 @@ namespace Nz
}
else if (keyword == "map_decal" || keyword == "decal")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -232,7 +232,7 @@ namespace Nz
}
else if (keyword == "map_disp" || keyword == "disp")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);
@@ -244,7 +244,7 @@ namespace Nz
}
else if (keyword == "map_refl" || keyword == "refl")
{
unsigned int mapPos = m_currentLine.GetWordPosition(1);
std::size_t mapPos = m_currentLine.GetWordPosition(1);
if (mapPos != String::npos)
{
String map = m_currentLine.SubString(mapPos);

View File

@@ -40,7 +40,7 @@ namespace Nz
return Ternary_Unknown;
}
bool ParseMTL(Mesh* mesh, const String& filePath, const String* materials, const OBJParser::Mesh* meshes, unsigned int meshCount)
bool ParseMTL(Mesh* mesh, const String& filePath, const String* materials, const OBJParser::Mesh* meshes, UInt32 meshCount)
{
File file(filePath);
if (!file.Open(OpenMode_ReadOnly | OpenMode_Text))
@@ -58,7 +58,7 @@ namespace Nz
std::unordered_map<String, ParameterList> materialCache;
String baseDir = file.GetDirectory();
for (unsigned int i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const String& matName = materials[meshes[i].material];
const MTLParser::Material* mtlMat = materialParser.GetMaterial(matName);
@@ -154,21 +154,21 @@ namespace Nz
const Vector3f* texCoords = parser.GetTexCoords();
const OBJParser::Mesh* meshes = parser.GetMeshes();
unsigned int meshCount = parser.GetMeshCount();
UInt32 meshCount = parser.GetMeshCount();
NazaraAssert(materials != nullptr && positions != nullptr && normals != nullptr &&
texCoords != nullptr && meshes != nullptr && meshCount > 0,
"Invalid OBJParser output");
// Un conteneur temporaire pour contenir les indices de face avant triangulation
std::vector<unsigned int> faceIndices(3); // Comme il y aura au moins trois sommets
for (unsigned int i = 0; i < meshCount; ++i)
std::vector<UInt32> faceIndices(3); // Comme il y aura au moins trois sommets
for (UInt32 i = 0; i < meshCount; ++i)
{
unsigned int faceCount = meshes[i].faces.size();
std::size_t faceCount = meshes[i].faces.size();
if (faceCount == 0)
continue;
std::vector<unsigned int> indices;
std::vector<UInt32> indices;
indices.reserve(faceCount*3); // Pire cas si les faces sont des triangles
// Afin d'utiliser OBJParser::FaceVertex comme clé dans un unordered_map,
@@ -205,10 +205,10 @@ namespace Nz
unsigned int vertexCount = 0;
for (unsigned int j = 0; j < faceCount; ++j)
{
unsigned int faceVertexCount = meshes[i].faces[j].vertexCount;
UInt32 faceVertexCount = meshes[i].faces[j].vertexCount;
faceIndices.resize(faceVertexCount);
for (unsigned int k = 0; k < faceVertexCount; ++k)
for (UInt32 k = 0; k < faceVertexCount; ++k)
{
const OBJParser::FaceVertex& vertex = meshes[i].vertices[meshes[i].faces[j].firstVertex + k];
@@ -220,7 +220,7 @@ namespace Nz
}
// Triangulation
for (unsigned int k = 1; k < faceVertexCount-1; ++k)
for (UInt32 k = 1; k < faceVertexCount-1; ++k)
{
indices.push_back(faceIndices[0]);
indices.push_back(faceIndices[k]);
@@ -234,7 +234,7 @@ namespace Nz
// Remplissage des indices
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
for (unsigned int j = 0; j < indices.size(); ++j)
for (std::size_t j = 0; j < indices.size(); ++j)
indexMapper.Set(j, indices[j]);
indexMapper.Unmap(); // Pour laisser les autres tâches affecter l'index buffer

View File

@@ -13,7 +13,7 @@
namespace Nz
{
bool OBJParser::Parse(Nz::Stream& stream, std::size_t reservedVertexCount)
bool OBJParser::Parse(Nz::Stream& stream, UInt32 reservedVertexCount)
{
m_currentStream = &stream;
@@ -50,8 +50,8 @@ namespace Nz
using MatPair = std::pair<Mesh, unsigned int>;
std::unordered_map<String, std::unordered_map<String, MatPair>> meshesByName;
std::size_t faceReserve = 0;
std::size_t vertexReserve = 0;
UInt32 faceReserve = 0;
UInt32 vertexReserve = 0;
unsigned int matCount = 0;
auto GetMaterial = [&] (const String& meshName, const String& matName) -> Mesh*
{
@@ -79,16 +79,16 @@ namespace Nz
{
case '#': //< Comment
// Some softwares write comments to gives the number of vertex/faces an importer can expect
std::size_t data;
if (std::sscanf(m_currentLine.GetConstBuffer(), "# position count: %zu", &data) == 1)
unsigned int data;
if (std::sscanf(m_currentLine.GetConstBuffer(), "# position count: %u", &data) == 1)
m_positions.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# normal count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# normal count: %u", &data) == 1)
m_normals.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# texcoords count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# texcoords count: %u", &data) == 1)
m_texCoords.reserve(data);
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# face count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# face count: %u", &data) == 1)
faceReserve = data;
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# vertex count: %zu", &data) == 1)
else if (std::sscanf(m_currentLine.GetConstBuffer(), "# vertex count: %u", &data) == 1)
vertexReserve = data;
break;
@@ -118,8 +118,8 @@ namespace Nz
currentMesh = GetMaterial(meshName, matName);
Face face;
face.firstVertex = currentMesh->vertices.size();
face.vertexCount = vertexCount;
face.firstVertex = static_cast<UInt32>(currentMesh->vertices.size());
face.vertexCount = static_cast<UInt32>(vertexCount);
currentMesh->vertices.resize(face.firstVertex + vertexCount, FaceVertex{0, 0, 0});
@@ -203,9 +203,9 @@ namespace Nz
break;
}
currentMesh->vertices[face.firstVertex + i].normal = static_cast<std::size_t>(n);
currentMesh->vertices[face.firstVertex + i].position = static_cast<std::size_t>(p);
currentMesh->vertices[face.firstVertex + i].texCoord = static_cast<std::size_t>(t);
currentMesh->vertices[face.firstVertex + i].normal = static_cast<UInt32>(n);
currentMesh->vertices[face.firstVertex + i].position = static_cast<UInt32>(p);
currentMesh->vertices[face.firstVertex + i].texCoord = static_cast<UInt32>(t);
pos += offset;
}

View File

@@ -35,12 +35,12 @@ namespace Nz
{
}
std::size_t GetCount() const
UInt32 GetCount() const
{
return m_count;
}
std::size_t Insert(const T& data)
UInt32 Insert(const T& data)
{
auto it = m_cache.find(data);
if (it == m_cache.end())
@@ -54,8 +54,8 @@ namespace Nz
}
private:
std::size_t m_count;
std::map<T, std::size_t> m_cache;
UInt32 m_count;
std::map<T, UInt32> m_cache;
T* m_buffer;
};
@@ -78,7 +78,7 @@ namespace Nz
return false;
}
std::size_t worstCacheVertexCount = mesh.GetVertexCount();
UInt32 worstCacheVertexCount = mesh.GetVertexCount();
OBJParser objFormat;
objFormat.SetNormalCount(worstCacheVertexCount);
objFormat.SetPositionCount(worstCacheVertexCount);
@@ -101,9 +101,9 @@ namespace Nz
MTLParser mtlFormat;
std::unordered_set<String> registredMaterials;
std::size_t matCount = mesh.GetMaterialCount();
UInt32 matCount = mesh.GetMaterialCount();
String* materialNames = objFormat.SetMaterialCount(matCount);
for (std::size_t i = 0; i < matCount; ++i)
for (UInt32 i = 0; i < matCount; ++i)
{
const ParameterList& matData = mesh.GetMaterialData(i);
@@ -152,13 +152,13 @@ namespace Nz
}
// Meshes
std::size_t meshCount = mesh.GetSubMeshCount();
UInt32 meshCount = mesh.GetSubMeshCount();
OBJParser::Mesh* meshes = objFormat.SetMeshCount(meshCount);
for (std::size_t i = 0; i < meshCount; ++i)
for (UInt32 i = 0; i < meshCount; ++i)
{
const StaticMesh* staticMesh = static_cast<const StaticMesh*>(mesh.GetSubMesh(i));
std::size_t triangleCount = staticMesh->GetTriangleCount();
UInt32 triangleCount = staticMesh->GetTriangleCount();
meshes[i].faces.resize(triangleCount);
meshes[i].material = staticMesh->GetMaterialIndex();
@@ -172,7 +172,7 @@ namespace Nz
SparsePtr<Vector3f> positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position);
SparsePtr<Vector2f> texCoordsPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord);
std::size_t faceIndex = 0;
UInt32 faceIndex = 0;
TriangleIterator triangle(staticMesh);
do
{
@@ -180,11 +180,11 @@ namespace Nz
face.firstVertex = faceIndex * 3;
face.vertexCount = 3;
for (std::size_t j = 0; j < 3; ++j)
for (unsigned int j = 0; j < 3; ++j)
{
OBJParser::FaceVertex& vertexIndices = meshes[i].vertices[face.firstVertex + j];
std::size_t index = triangle[j];
UInt32 index = triangle[j];
vertexIndices.normal = normalCache.Insert(normalPtr[index]);
vertexIndices.position = positionCache.Insert(positionPtr[index]);
vertexIndices.texCoord = texCoordsCache.Insert(texCoordsPtr[index]);

View File

@@ -55,7 +55,7 @@ namespace Nz
materialData.resize(1); // Un matériau par défaut
}
std::unordered_map<String, unsigned int> subMeshMap;
std::unordered_map<String, UInt32> subMeshMap;
std::vector<ParameterList> materialData;
std::vector<SubMeshRef> subMeshes;
AnimationType animationType;
@@ -63,7 +63,7 @@ namespace Nz
Skeleton skeleton; // Uniquement pour les meshs squelettiques
String animationPath;
bool aabbUpdated = false;
unsigned int jointCount; // Uniquement pour les meshs squelettiques
UInt32 jointCount; // Uniquement pour les meshs squelettiques
};
Mesh::~Mesh()
@@ -92,7 +92,7 @@ namespace Nz
NazaraAssert(subMesh, "Invalid submesh");
NazaraAssert(subMesh->GetAnimationType() == m_impl->animationType, "Submesh animation type doesn't match mesh animation type");
int index = m_impl->subMeshes.size();
UInt32 index = m_impl->subMeshes.size();
m_impl->subMeshes.push_back(subMesh);
m_impl->subMeshMap[identifier] = index;
@@ -276,11 +276,11 @@ namespace Nz
void Mesh::BuildSubMeshes(const PrimitiveList& list, const MeshParams& params)
{
for (unsigned int i = 0; i < list.GetSize(); ++i)
for (UInt32 i = 0; i < list.GetSize(); ++i)
BuildSubMesh(list.GetPrimitive(i), params);
}
bool Mesh::CreateSkeletal(unsigned int jointCount)
bool Mesh::CreateSkeletal(UInt32 jointCount)
{
Destroy();
@@ -349,11 +349,11 @@ namespace Nz
if (!m_impl->aabbUpdated)
{
unsigned int subMeshCount = m_impl->subMeshes.size();
UInt32 subMeshCount = m_impl->subMeshes.size();
if (subMeshCount > 0)
{
m_impl->aabb.Set(m_impl->subMeshes[0]->GetAABB());
for (unsigned int i = 1; i < subMeshCount; ++i)
for (UInt32 i = 1; i < subMeshCount; ++i)
m_impl->aabb.ExtendTo(m_impl->subMeshes[i]->GetAABB());
}
else
@@ -379,7 +379,7 @@ namespace Nz
return m_impl->animationType;
}
unsigned int Mesh::GetJointCount() const
UInt32 Mesh::GetJointCount() const
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(m_impl->animationType == AnimationType_Skeletal, "Mesh is not skeletal");
@@ -387,7 +387,7 @@ namespace Nz
return m_impl->jointCount;
}
ParameterList& Mesh::GetMaterialData(unsigned int index)
ParameterList& Mesh::GetMaterialData(UInt32 index)
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->materialData.size(), "Material index out of range");
@@ -395,7 +395,7 @@ namespace Nz
return m_impl->materialData[index];
}
const ParameterList& Mesh::GetMaterialData(unsigned int index) const
const ParameterList& Mesh::GetMaterialData(UInt32 index) const
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->materialData.size(), "Material index out of range");
@@ -403,7 +403,7 @@ namespace Nz
return m_impl->materialData[index];
}
unsigned int Mesh::GetMaterialCount() const
UInt32 Mesh::GetMaterialCount() const
{
NazaraAssert(m_impl, "Mesh should be created first");
@@ -436,7 +436,7 @@ namespace Nz
return m_impl->subMeshes[it->second];
}
SubMesh* Mesh::GetSubMesh(unsigned int index)
SubMesh* Mesh::GetSubMesh(UInt32 index)
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@@ -454,7 +454,7 @@ namespace Nz
return m_impl->subMeshes[it->second];
}
const SubMesh* Mesh::GetSubMesh(unsigned int index) const
const SubMesh* Mesh::GetSubMesh(UInt32 index) const
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@@ -462,14 +462,14 @@ namespace Nz
return m_impl->subMeshes[index];
}
unsigned int Mesh::GetSubMeshCount() const
UInt32 Mesh::GetSubMeshCount() const
{
NazaraAssert(m_impl, "Mesh should be created first");
return m_impl->subMeshes.size();
}
int Mesh::GetSubMeshIndex(const String& identifier) const
UInt32 Mesh::GetSubMeshIndex(const String& identifier) const
{
NazaraAssert(m_impl, "Mesh should be created first");
@@ -479,22 +479,22 @@ namespace Nz
return it->second;
}
unsigned int Mesh::GetTriangleCount() const
UInt32 Mesh::GetTriangleCount() const
{
NazaraAssert(m_impl, "Mesh should be created first");
unsigned int triangleCount = 0;
UInt32 triangleCount = 0;
for (SubMesh* subMesh : m_impl->subMeshes)
triangleCount += subMesh->GetTriangleCount();
return triangleCount;
}
unsigned int Mesh::GetVertexCount() const
UInt32 Mesh::GetVertexCount() const
{
NazaraAssert(m_impl, "Mesh should be created first");
unsigned int vertexCount = 0;
UInt32 vertexCount = 0;
for (SubMesh* subMesh : m_impl->subMeshes)
vertexCount += subMesh->GetVertexCount();
@@ -515,7 +515,7 @@ namespace Nz
return m_impl->subMeshMap.find(identifier) != m_impl->subMeshMap.end();
}
bool Mesh::HasSubMesh(unsigned int index) const
bool Mesh::HasSubMesh(UInt32 index) const
{
NazaraAssert(m_impl, "Mesh should be created first");
@@ -564,8 +564,8 @@ namespace Nz
BufferMapper<VertexBuffer> mapper(staticMesh->GetVertexBuffer(), BufferAccess_ReadWrite);
MeshVertex* vertices = static_cast<MeshVertex*>(mapper.GetPointer());
unsigned int vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i)
UInt32 vertexCount = staticMesh->GetVertexCount();
for (UInt32 i = 0; i < vertexCount; ++i)
{
vertices->position -= center;
vertices++;
@@ -583,7 +583,7 @@ namespace Nz
void Mesh::RemoveSubMesh(const String& identifier)
{
unsigned int index = GetSubMeshIndex(identifier);
UInt32 index = GetSubMeshIndex(identifier);
// On déplace l'itérateur du début d'une distance de x
auto it2 = m_impl->subMeshes.begin();
@@ -593,7 +593,7 @@ namespace Nz
InvalidateAABB();
}
void Mesh::RemoveSubMesh(unsigned int index)
void Mesh::RemoveSubMesh(UInt32 index)
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(index < m_impl->subMeshes.size(), "Submesh index out of range");
@@ -623,7 +623,7 @@ namespace Nz
m_impl->animationPath = animationPath;
}
void Mesh::SetMaterialData(unsigned int matIndex, ParameterList data)
void Mesh::SetMaterialData(UInt32 matIndex, ParameterList data)
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(matIndex < m_impl->materialData.size(), "Material index out of range");
@@ -631,7 +631,7 @@ namespace Nz
m_impl->materialData[matIndex] = std::move(data);
}
void Mesh::SetMaterialCount(unsigned int matCount)
void Mesh::SetMaterialCount(UInt32 matCount)
{
NazaraAssert(m_impl, "Mesh should be created first");
NazaraAssert(matCount > 0, "A mesh should have at least a material");
@@ -641,7 +641,7 @@ namespace Nz
#ifdef NAZARA_DEBUG
for (SubMesh* subMesh : m_impl->subMeshes)
{
unsigned int matIndex = subMesh->GetMaterialIndex();
UInt32 matIndex = subMesh->GetMaterialIndex();
if (matIndex >= matCount)
{
subMesh->SetMaterialIndex(0); // To prevent a crash
@@ -665,8 +665,8 @@ namespace Nz
Boxf aabb(vertices->position.x, vertices->position.y, vertices->position.z, 0.f, 0.f, 0.f);
unsigned int vertexCount = staticMesh->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i)
UInt32 vertexCount = staticMesh->GetVertexCount();
for (UInt32 i = 0; i < vertexCount; ++i)
{
vertices->position = matrix.Transform(vertices->position);
aabb.ExtendTo(vertices->position);

View File

@@ -10,7 +10,7 @@ namespace Nz
{
struct SkeletonImpl
{
std::unordered_map<String, unsigned int> jointMap;
std::unordered_map<String, UInt32> jointMap;
std::vector<Joint> joints;
Boxf aabb;
bool aabbUpdated = false;
@@ -31,7 +31,7 @@ namespace Nz
Destroy();
}
bool Skeleton::Create(unsigned int jointCount)
bool Skeleton::Create(UInt32 jointCount)
{
#if NAZARA_UTILITY_SAFE
if (jointCount == 0)
@@ -72,12 +72,12 @@ namespace Nz
if (!m_impl->aabbUpdated)
{
unsigned int jointCount = m_impl->joints.size();
UInt32 jointCount = m_impl->joints.size();
if (jointCount > 0)
{
Vector3f pos = m_impl->joints[0].GetPosition();
m_impl->aabb.Set(pos.x, pos.y, pos.z, 0.f, 0.f, 0.f);
for (unsigned int i = 1; i < jointCount; ++i)
for (UInt32 i = 1; i < jointCount; ++i)
m_impl->aabb.ExtendTo(m_impl->joints[i].GetPosition());
}
else
@@ -117,7 +117,7 @@ namespace Nz
return &m_impl->joints[it->second];
}
Joint* Skeleton::GetJoint(unsigned int index)
Joint* Skeleton::GetJoint(UInt32 index)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
@@ -164,7 +164,7 @@ namespace Nz
return &m_impl->joints[it->second];
}
const Joint* Skeleton::GetJoint(unsigned int index) const
const Joint* Skeleton::GetJoint(UInt32 index) const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
@@ -209,7 +209,7 @@ namespace Nz
return &m_impl->joints[0];
}
unsigned int Skeleton::GetJointCount() const
UInt32 Skeleton::GetJointCount() const
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
@@ -278,13 +278,13 @@ namespace Nz
Joint* jointsA = &skeletonA.m_impl->joints[0];
Joint* jointsB = &skeletonB.m_impl->joints[0];
for (unsigned int i = 0; i < m_impl->joints.size(); ++i)
for (std::size_t i = 0; i < m_impl->joints.size(); ++i)
m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys_Local);
InvalidateJoints();
}
void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, unsigned int* indices, unsigned int indiceCount)
void Skeleton::Interpolate(const Skeleton& skeletonA, const Skeleton& skeletonB, float interpolation, UInt32* indices, UInt32 indiceCount)
{
#if NAZARA_UTILITY_SAFE
if (!m_impl)
@@ -314,9 +314,9 @@ namespace Nz
const Joint* jointsA = &skeletonA.m_impl->joints[0];
const Joint* jointsB = &skeletonB.m_impl->joints[0];
for (unsigned int i = 0; i < indiceCount; ++i)
for (UInt32 i = 0; i < indiceCount; ++i)
{
unsigned int index = indices[i];
UInt32 index = indices[i];
#if NAZARA_UTILITY_SAFE
if (index >= m_impl->joints.size())
@@ -351,16 +351,16 @@ namespace Nz
m_impl->jointMapUpdated = skeleton.m_impl->jointMapUpdated;
m_impl->joints = skeleton.m_impl->joints;
// Code crade mais son optimisation demanderait de stocker jointCount*sizeof(unsigned int) en plus
// Code crade mais son optimisation demanderait de stocker jointCount*sizeof(UInt32) en plus
// Ce qui, pour juste une copie qui ne se fera que rarement, ne vaut pas le coup
// L'éternel trade-off mémoire/calculs ..
unsigned int jointCount = skeleton.m_impl->joints.size();
for (unsigned int i = 0; i < jointCount; ++i)
std::size_t jointCount = skeleton.m_impl->joints.size();
for (std::size_t i = 0; i < jointCount; ++i)
{
const Node* parent = skeleton.m_impl->joints[i].GetParent();
if (parent)
{
for (unsigned int j = 0; j < i; ++j) // Le parent se trouve forcément avant nous
for (std::size_t j = 0; j < i; ++j) // Le parent se trouve forcément avant nous
{
if (parent == &skeleton.m_impl->joints[j]) // A-t-on trouvé le parent ?
{
@@ -406,7 +406,7 @@ namespace Nz
#endif
m_impl->jointMap.clear();
for (unsigned int i = 0; i < m_impl->joints.size(); ++i)
for (std::size_t i = 0; i < m_impl->joints.size(); ++i)
{
String name = m_impl->joints[i].GetName();
if (!name.IsEmpty())

View File

@@ -196,7 +196,7 @@ namespace Nz
return 0;
}
unsigned int SubMesh::GetMaterialIndex() const
UInt32 SubMesh::GetMaterialIndex() const
{
return m_matIndex;
}
@@ -206,7 +206,7 @@ namespace Nz
m_primitiveMode = mode;
}
void SubMesh::SetMaterialIndex(unsigned int matIndex)
void SubMesh::SetMaterialIndex(UInt32 matIndex)
{
m_matIndex = matIndex;
}

View File

@@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/LockGuard.hpp>
@@ -60,25 +61,22 @@ namespace Nz
else if (style & WindowStyle_Closable || style & WindowStyle_Resizable)
style |= WindowStyle_Titlebar;
m_impl = new WindowImpl(this);
if (!m_impl->Create(mode, title, style))
std::unique_ptr<WindowImpl> impl = std::make_unique<WindowImpl>(this);
if (!impl->Create(mode, title, style))
{
NazaraError("Failed to create window implementation");
delete m_impl;
m_impl = nullptr;
return false;
}
m_impl = impl.release();
CallOnExit destroyOnFailure([this] () { Destroy(); });
m_closed = false;
m_ownsWindow = true;
if (!OnWindowCreated())
{
NazaraError("Failed to initialize window extension");
delete m_impl;
m_impl = nullptr;
return false;
}
@@ -93,6 +91,10 @@ namespace Nz
if (opened)
m_impl->SetPosition(position.x, position.y);
OnWindowResized();
destroyOnFailure.Reset();
return true;
}
@@ -325,6 +327,15 @@ namespace Nz
return false;
}
void Window::ProcessEvents(bool block)
{
NazaraAssert(m_impl, "Window not created");
#if !NAZARA_UTILITY_THREADED_WINDOW
m_impl->ProcessEvents(block);
#endif
}
void Window::SetCursor(WindowCursor cursor)
{
#if NAZARA_UTILITY_SAFE