diff --git a/.gitignore b/.gitignore index 5fe1f32e7..d671b209b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ build/**/*.slo build/**/*.lo build/**/*.o build/**/*.obj +build/**/*.obj.enc # Compiled Dynamic libraries build/**/*.so diff --git a/SDK/include/NDK/BaseSystem.inl b/SDK/include/NDK/BaseSystem.inl index 0c86ddfdd..0c2811ac0 100644 --- a/SDK/include/NDK/BaseSystem.inl +++ b/SDK/include/NDK/BaseSystem.inl @@ -60,14 +60,16 @@ namespace Ndk { if (m_updateRate > 0.f) { - m_updateCounter -= elapsedTime; - if (m_updateCounter >= 0.f) - return; + m_updateCounter += elapsedTime; - m_updateCounter += m_updateRate; + while (m_updateCounter >= m_updateRate) + { + OnUpdate(m_updateRate); + m_updateCounter -= m_updateRate; + } } - - OnUpdate(elapsedTime); + else + OnUpdate(elapsedTime); } template diff --git a/SDK/src/NDK/LuaBinding.hpp b/SDK/include/NDK/LuaBinding.hpp similarity index 89% rename from SDK/src/NDK/LuaBinding.hpp rename to SDK/include/NDK/LuaBinding.hpp index 93363f7fb..a0e3e7719 100644 --- a/SDK/src/NDK/LuaBinding.hpp +++ b/SDK/include/NDK/LuaBinding.hpp @@ -27,12 +27,14 @@ namespace Ndk { - class LuaBinding + class NDK_API LuaBinding { public: LuaBinding(); ~LuaBinding() = default; + template void BindComponent(const Nz::String& name); + void RegisterClasses(Nz::LuaInstance& instance); private: @@ -42,8 +44,6 @@ namespace Ndk void BindSDK(); void BindUtility(); - template void EnableComponentBinding(); - void RegisterCore(Nz::LuaInstance& instance); void RegisterMath(Nz::LuaInstance& instance); void RegisterNetwork(Nz::LuaInstance& instance); @@ -93,8 +93,9 @@ namespace Ndk struct ComponentBinding { AddComponentFunc adder; + ComponentIndex index; GetComponentFunc getter; - bool valid = false; + Nz::String name; }; std::vector m_componentBinding; @@ -115,6 +116,14 @@ namespace Ndk Nz::LuaClass graphicsComponent; #endif }; + + template + int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle); + + template + int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component); } +#include + #endif // NDK_LUABINDING_HPP diff --git a/SDK/include/NDK/LuaBinding.inl b/SDK/include/NDK/LuaBinding.inl new file mode 100644 index 000000000..5ca290398 --- /dev/null +++ b/SDK/include/NDK/LuaBinding.inl @@ -0,0 +1,45 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Development Kit" +// For conditions of distribution and use, see copyright notice in Prerequesites.hpp + +#include + +namespace Ndk +{ + template + void LuaBinding::BindComponent(const Nz::String& name) + { + NazaraAssert(!name.IsEmpty(), "Component name cannot be empty"); + + ComponentBinding binding; + binding.adder = &AddComponentOfType; + binding.getter = &PushComponentOfType; + binding.index = T::componentIndex; + binding.name = name; + + if (m_componentBinding.size() <= T::componentIndex) + m_componentBinding.resize(T::componentIndex + 1); + + m_componentBinding[T::componentIndex] = std::move(binding); + } + + template + int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle) + { + static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); + + T& component = handle->AddComponent(); + lua.Push(component.CreateHandle()); + return 1; + } + + template + int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component) + { + static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); + + T& rightComponent = static_cast(component); + lua.Push(rightComponent.CreateHandle()); + return 1; + } +} diff --git a/SDK/include/NDK/Systems/RenderSystem.hpp b/SDK/include/NDK/Systems/RenderSystem.hpp index ff077278d..4b65de11d 100644 --- a/SDK/include/NDK/Systems/RenderSystem.hpp +++ b/SDK/include/NDK/Systems/RenderSystem.hpp @@ -8,7 +8,7 @@ #define NDK_SYSTEMS_RENDERSYSTEM_HPP #include -#include +#include #include #include #include @@ -25,11 +25,15 @@ namespace Ndk inline RenderSystem(const RenderSystem& renderSystem); ~RenderSystem() = default; + template void ChangeRenderTechnique(); + inline void ChangeRenderTechnique(std::unique_ptr&& renderTechnique); + inline const Nz::BackgroundRef& GetDefaultBackground() const; inline const Nz::Matrix4f& GetCoordinateSystemMatrix() const; inline Nz::Vector3f GetGlobalForward() const; inline Nz::Vector3f GetGlobalRight() const; inline Nz::Vector3f GetGlobalUp() const; + inline Nz::AbstractRenderTechnique& GetRenderTechnique() const; inline void SetDefaultBackground(Nz::BackgroundRef background); inline void SetGlobalForward(const Nz::Vector3f& direction); @@ -45,11 +49,11 @@ namespace Ndk void OnEntityValidation(Entity* entity, bool justAdded) override; void OnUpdate(float elapsedTime) override; + std::unique_ptr m_renderTechnique; EntityList m_cameras; EntityList m_drawables; EntityList m_lights; Nz::BackgroundRef m_background; - Nz::ForwardRenderTechnique m_renderTechnique; Nz::Matrix4f m_coordinateSystemMatrix; bool m_coordinateSystemInvalidated; }; diff --git a/SDK/include/NDK/Systems/RenderSystem.inl b/SDK/include/NDK/Systems/RenderSystem.inl index d0cb0af47..b85ace59f 100644 --- a/SDK/include/NDK/Systems/RenderSystem.inl +++ b/SDK/include/NDK/Systems/RenderSystem.inl @@ -9,6 +9,17 @@ namespace Ndk { } + template + inline void RenderSystem::ChangeRenderTechnique() + { + ChangeRenderTechnique(std::make_unique()); + } + + inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr&& renderTechnique) + { + m_renderTechnique = std::move(renderTechnique); + } + inline const Nz::BackgroundRef& RenderSystem::GetDefaultBackground() const { return m_background; @@ -34,6 +45,11 @@ namespace Ndk return Nz::Vector3f(m_coordinateSystemMatrix.m12, m_coordinateSystemMatrix.m22, m_coordinateSystemMatrix.m32); } + inline Nz::AbstractRenderTechnique& RenderSystem::GetRenderTechnique() const + { + return *m_renderTechnique.get(); + } + inline void RenderSystem::SetDefaultBackground(Nz::BackgroundRef background) { m_background = std::move(background); diff --git a/SDK/src/NDK/LuaBinding_Audio.cpp b/SDK/src/NDK/LuaBinding_Audio.cpp index 542c6b716..7c204b833 100644 --- a/SDK/src/NDK/LuaBinding_Audio.cpp +++ b/SDK/src/NDK/LuaBinding_Audio.cpp @@ -18,28 +18,28 @@ namespace Ndk //musicClass.SetMethod("Create", &Nz::Music::Create); //musicClass.SetMethod("Destroy", &Nz::Music::Destroy); - musicClass.SetMethod("EnableLooping", &Nz::Music::EnableLooping); + musicClass.BindMethod("EnableLooping", &Nz::Music::EnableLooping); - musicClass.SetMethod("GetDuration", &Nz::Music::GetDuration); - musicClass.SetMethod("GetFormat", &Nz::Music::GetFormat); - musicClass.SetMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); - musicClass.SetMethod("GetSampleCount", &Nz::Music::GetSampleCount); - musicClass.SetMethod("GetSampleRate", &Nz::Music::GetSampleRate); - musicClass.SetMethod("GetStatus", &Nz::Music::GetStatus); + musicClass.BindMethod("GetDuration", &Nz::Music::GetDuration); + musicClass.BindMethod("GetFormat", &Nz::Music::GetFormat); + musicClass.BindMethod("GetPlayingOffset", &Nz::Music::GetPlayingOffset); + musicClass.BindMethod("GetSampleCount", &Nz::Music::GetSampleCount); + musicClass.BindMethod("GetSampleRate", &Nz::Music::GetSampleRate); + musicClass.BindMethod("GetStatus", &Nz::Music::GetStatus); - musicClass.SetMethod("IsLooping", &Nz::Music::IsLooping); + musicClass.BindMethod("IsLooping", &Nz::Music::IsLooping); - musicClass.SetMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); + musicClass.BindMethod("OpenFromFile", &Nz::Music::OpenFromFile, Nz::MusicParams()); - musicClass.SetMethod("Pause", &Nz::Music::Pause); - musicClass.SetMethod("Play", &Nz::Music::Play); + musicClass.BindMethod("Pause", &Nz::Music::Pause); + musicClass.BindMethod("Play", &Nz::Music::Play); - musicClass.SetMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); + musicClass.BindMethod("SetPlayingOffset", &Nz::Music::SetPlayingOffset); - musicClass.SetMethod("Stop", &Nz::Music::Stop); + musicClass.BindMethod("Stop", &Nz::Music::Stop); // Manual - musicClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int + musicClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Music& music) -> int { Nz::StringStream stream("Music("); stream << music.GetFilePath() << ')'; @@ -56,17 +56,17 @@ namespace Ndk return new Nz::Sound; }); - soundClass.SetMethod("GetBuffer", &Nz::Sound::GetBuffer); + soundClass.BindMethod("GetBuffer", &Nz::Sound::GetBuffer); - soundClass.SetMethod("IsPlayable", &Nz::Sound::IsPlayable); - soundClass.SetMethod("IsPlaying", &Nz::Sound::IsPlaying); + soundClass.BindMethod("IsPlayable", &Nz::Sound::IsPlayable); + soundClass.BindMethod("IsPlaying", &Nz::Sound::IsPlaying); - soundClass.SetMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); + soundClass.BindMethod("LoadFromFile", &Nz::Sound::LoadFromFile, Nz::SoundBufferParams()); - soundClass.SetMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); + soundClass.BindMethod("SetPlayingOffset", &Nz::Sound::SetPlayingOffset); // Manual - soundClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int + soundClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Sound& sound) -> int { Nz::StringStream stream("Sound("); if (const Nz::SoundBuffer* buffer = sound.GetBuffer()) @@ -84,21 +84,21 @@ namespace Ndk return new Nz::SoundBufferRef(new Nz::SoundBuffer); }); - soundBuffer.SetMethod("Destroy", &Nz::SoundBuffer::Destroy); + soundBuffer.BindMethod("Destroy", &Nz::SoundBuffer::Destroy); - soundBuffer.SetMethod("GetDuration", &Nz::SoundBuffer::GetDuration); - soundBuffer.SetMethod("GetFormat", &Nz::SoundBuffer::GetFormat); - soundBuffer.SetMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); - soundBuffer.SetMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); + soundBuffer.BindMethod("GetDuration", &Nz::SoundBuffer::GetDuration); + soundBuffer.BindMethod("GetFormat", &Nz::SoundBuffer::GetFormat); + soundBuffer.BindMethod("GetSampleCount", &Nz::SoundBuffer::GetSampleCount); + soundBuffer.BindMethod("GetSampleRate", &Nz::SoundBuffer::GetSampleRate); - soundBuffer.SetMethod("IsValid", &Nz::SoundBuffer::IsValid); + soundBuffer.BindMethod("IsValid", &Nz::SoundBuffer::IsValid); - soundBuffer.SetMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); + soundBuffer.BindMethod("LoadFromFile", &Nz::SoundBuffer::LoadFromFile, Nz::SoundBufferParams()); - soundBuffer.SetStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); + soundBuffer.BindStaticMethod("IsFormatSupported", &Nz::SoundBuffer::IsFormatSupported); // Manual - soundBuffer.SetMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + soundBuffer.BindMethod("Create", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int { int index = 1; Nz::AudioFormat format = lua.Check(&index); @@ -113,13 +113,13 @@ namespace Ndk return 1; }); - soundBuffer.SetMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int + soundBuffer.BindMethod("GetSamples", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& instance) -> int { lua.PushString(reinterpret_cast(instance->GetSamples()), instance->GetSampleCount() * sizeof(Nz::Int16)); return 1; }); - soundBuffer.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int + soundBuffer.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::SoundBufferRef& soundBuffer) -> int { Nz::StringStream stream("SoundBuffer("); if (soundBuffer->IsValid()) @@ -137,33 +137,33 @@ namespace Ndk }); /*********************************** Nz::SoundEmitter **********************************/ - soundEmitter.SetMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); - soundEmitter.SetMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); + soundEmitter.BindMethod("EnableLooping", &Nz::SoundEmitter::EnableLooping); + soundEmitter.BindMethod("EnableSpatialization", &Nz::SoundEmitter::EnableSpatialization); - soundEmitter.SetMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); - soundEmitter.SetMethod("GetDuration", &Nz::SoundEmitter::GetDuration); - soundEmitter.SetMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); - soundEmitter.SetMethod("GetPitch", &Nz::SoundEmitter::GetPitch); - soundEmitter.SetMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); - soundEmitter.SetMethod("GetPosition", &Nz::Sound::GetPosition); - soundEmitter.SetMethod("GetStatus", &Nz::SoundEmitter::GetStatus); - soundEmitter.SetMethod("GetVelocity", &Nz::Sound::GetVelocity); - soundEmitter.SetMethod("GetVolume", &Nz::SoundEmitter::GetVolume); + soundEmitter.BindMethod("GetAttenuation", &Nz::SoundEmitter::GetAttenuation); + soundEmitter.BindMethod("GetDuration", &Nz::SoundEmitter::GetDuration); + soundEmitter.BindMethod("GetMinDistance", &Nz::SoundEmitter::GetMinDistance); + soundEmitter.BindMethod("GetPitch", &Nz::SoundEmitter::GetPitch); + soundEmitter.BindMethod("GetPlayingOffset", &Nz::SoundEmitter::GetPlayingOffset); + soundEmitter.BindMethod("GetPosition", &Nz::Sound::GetPosition); + soundEmitter.BindMethod("GetStatus", &Nz::SoundEmitter::GetStatus); + soundEmitter.BindMethod("GetVelocity", &Nz::Sound::GetVelocity); + soundEmitter.BindMethod("GetVolume", &Nz::SoundEmitter::GetVolume); - soundEmitter.SetMethod("IsLooping", &Nz::SoundEmitter::IsLooping); - soundEmitter.SetMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); + soundEmitter.BindMethod("IsLooping", &Nz::SoundEmitter::IsLooping); + soundEmitter.BindMethod("IsSpatialized", &Nz::SoundEmitter::IsSpatialized); - soundEmitter.SetMethod("Pause", &Nz::SoundEmitter::Pause); - soundEmitter.SetMethod("Play", &Nz::SoundEmitter::Play); + soundEmitter.BindMethod("Pause", &Nz::SoundEmitter::Pause); + soundEmitter.BindMethod("Play", &Nz::SoundEmitter::Play); - soundEmitter.SetMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); - soundEmitter.SetMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); - soundEmitter.SetMethod("SetPitch", &Nz::SoundEmitter::SetPitch); - soundEmitter.SetMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); - soundEmitter.SetMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); - soundEmitter.SetMethod("SetVolume", &Nz::SoundEmitter::SetVolume); + soundEmitter.BindMethod("SetAttenuation", &Nz::SoundEmitter::SetAttenuation); + soundEmitter.BindMethod("SetMinDistance", &Nz::SoundEmitter::SetMinDistance); + soundEmitter.BindMethod("SetPitch", &Nz::SoundEmitter::SetPitch); + soundEmitter.BindMethod("SetPosition", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetPosition); + soundEmitter.BindMethod("SetVelocity", (void(Nz::SoundEmitter::*)(const Nz::Vector3f&)) &Nz::SoundEmitter::SetVelocity); + soundEmitter.BindMethod("SetVolume", &Nz::SoundEmitter::SetVolume); - soundEmitter.SetMethod("Stop", &Nz::SoundEmitter::Stop); + soundEmitter.BindMethod("Stop", &Nz::SoundEmitter::Stop); } void LuaBinding::RegisterAudio(Nz::LuaInstance& instance) diff --git a/SDK/src/NDK/LuaBinding_Core.cpp b/SDK/src/NDK/LuaBinding_Core.cpp index 8ed8682ce..a4676284e 100644 --- a/SDK/src/NDK/LuaBinding_Core.cpp +++ b/SDK/src/NDK/LuaBinding_Core.cpp @@ -14,16 +14,16 @@ namespace Ndk return new Nz::Clock(lua.Check(&argIndex, 0), lua.Check(&argIndex, false)); }); - clockClass.SetMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); - clockClass.SetMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); - clockClass.SetMethod("GetSeconds", &Nz::Clock::GetSeconds); - clockClass.SetMethod("IsPaused", &Nz::Clock::IsPaused); - clockClass.SetMethod("Pause", &Nz::Clock::Pause); - clockClass.SetMethod("Restart", &Nz::Clock::Restart); - clockClass.SetMethod("Unpause", &Nz::Clock::Unpause); + clockClass.BindMethod("GetMicroseconds", &Nz::Clock::GetMicroseconds); + clockClass.BindMethod("GetMilliseconds", &Nz::Clock::GetMilliseconds); + clockClass.BindMethod("GetSeconds", &Nz::Clock::GetSeconds); + clockClass.BindMethod("IsPaused", &Nz::Clock::IsPaused); + clockClass.BindMethod("Pause", &Nz::Clock::Pause); + clockClass.BindMethod("Restart", &Nz::Clock::Restart); + clockClass.BindMethod("Unpause", &Nz::Clock::Unpause); // Manual - clockClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { + clockClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Clock& clock) -> int { Nz::StringStream stream("Clock(Elapsed: "); stream << clock.GetSeconds(); stream << "s, Paused: "; @@ -52,29 +52,29 @@ namespace Ndk return nullptr; }); - directoryClass.SetMethod("Close", &Nz::Directory::Close); - directoryClass.SetMethod("Exists", &Nz::Directory::Exists); - directoryClass.SetMethod("GetPath", &Nz::Directory::GetPath); - directoryClass.SetMethod("GetPattern", &Nz::Directory::GetPattern); - directoryClass.SetMethod("GetResultName", &Nz::Directory::GetResultName); - directoryClass.SetMethod("GetResultPath", &Nz::Directory::GetResultPath); - directoryClass.SetMethod("GetResultSize", &Nz::Directory::GetResultSize); - directoryClass.SetMethod("IsOpen", &Nz::Directory::IsOpen); - directoryClass.SetMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); - directoryClass.SetMethod("NextResult", &Nz::Directory::NextResult, true); - directoryClass.SetMethod("Open", &Nz::Directory::Open); - directoryClass.SetMethod("SetPath", &Nz::Directory::SetPath); - directoryClass.SetMethod("SetPattern", &Nz::Directory::SetPattern); + directoryClass.BindMethod("Close", &Nz::Directory::Close); + directoryClass.BindMethod("Exists", &Nz::Directory::Exists); + directoryClass.BindMethod("GetPath", &Nz::Directory::GetPath); + directoryClass.BindMethod("GetPattern", &Nz::Directory::GetPattern); + directoryClass.BindMethod("GetResultName", &Nz::Directory::GetResultName); + directoryClass.BindMethod("GetResultPath", &Nz::Directory::GetResultPath); + directoryClass.BindMethod("GetResultSize", &Nz::Directory::GetResultSize); + directoryClass.BindMethod("IsOpen", &Nz::Directory::IsOpen); + directoryClass.BindMethod("IsResultDirectory", &Nz::Directory::IsResultDirectory); + directoryClass.BindMethod("NextResult", &Nz::Directory::NextResult, true); + directoryClass.BindMethod("Open", &Nz::Directory::Open); + directoryClass.BindMethod("SetPath", &Nz::Directory::SetPath); + directoryClass.BindMethod("SetPattern", &Nz::Directory::SetPattern); - directoryClass.SetStaticMethod("Copy", Nz::Directory::Copy); - directoryClass.SetStaticMethod("Create", Nz::Directory::Create); - directoryClass.SetStaticMethod("Exists", Nz::Directory::Exists); - directoryClass.SetStaticMethod("GetCurrent", Nz::Directory::GetCurrent); - directoryClass.SetStaticMethod("Remove", Nz::Directory::Remove); - directoryClass.SetStaticMethod("SetCurrent", Nz::Directory::SetCurrent); + directoryClass.BindStaticMethod("Copy", Nz::Directory::Copy); + directoryClass.BindStaticMethod("Create", Nz::Directory::Create); + directoryClass.BindStaticMethod("Exists", Nz::Directory::Exists); + directoryClass.BindStaticMethod("GetCurrent", Nz::Directory::GetCurrent); + directoryClass.BindStaticMethod("Remove", Nz::Directory::Remove); + directoryClass.BindStaticMethod("SetCurrent", Nz::Directory::SetCurrent); // Manual - directoryClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { + directoryClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::Directory& directory) -> int { Nz::StringStream stream("Directory("); stream << directory.GetPath(); stream << ')'; @@ -84,22 +84,22 @@ namespace Ndk }); /*********************************** Nz::Stream ***********************************/ - streamClass.SetMethod("EnableTextMode", &Nz::Stream::EnableTextMode); - streamClass.SetMethod("Flush", &Nz::Stream::Flush); - streamClass.SetMethod("GetCursorPos", &Nz::Stream::GetCursorPos); - streamClass.SetMethod("GetDirectory", &Nz::Stream::GetDirectory); - streamClass.SetMethod("GetPath", &Nz::Stream::GetPath); - streamClass.SetMethod("GetOpenMode", &Nz::Stream::GetOpenMode); - streamClass.SetMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); - streamClass.SetMethod("GetSize", &Nz::Stream::GetSize); - streamClass.SetMethod("ReadLine", &Nz::Stream::ReadLine, 0U); - streamClass.SetMethod("IsReadable", &Nz::Stream::IsReadable); - streamClass.SetMethod("IsSequential", &Nz::Stream::IsSequential); - streamClass.SetMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); - streamClass.SetMethod("IsWritable", &Nz::Stream::IsWritable); - streamClass.SetMethod("SetCursorPos", &Nz::Stream::SetCursorPos); + streamClass.BindMethod("EnableTextMode", &Nz::Stream::EnableTextMode); + streamClass.BindMethod("Flush", &Nz::Stream::Flush); + streamClass.BindMethod("GetCursorPos", &Nz::Stream::GetCursorPos); + streamClass.BindMethod("GetDirectory", &Nz::Stream::GetDirectory); + streamClass.BindMethod("GetPath", &Nz::Stream::GetPath); + streamClass.BindMethod("GetOpenMode", &Nz::Stream::GetOpenMode); + streamClass.BindMethod("GetStreamOptions", &Nz::Stream::GetStreamOptions); + streamClass.BindMethod("GetSize", &Nz::Stream::GetSize); + streamClass.BindMethod("ReadLine", &Nz::Stream::ReadLine, 0U); + streamClass.BindMethod("IsReadable", &Nz::Stream::IsReadable); + streamClass.BindMethod("IsSequential", &Nz::Stream::IsSequential); + streamClass.BindMethod("IsTextModeEnabled", &Nz::Stream::IsTextModeEnabled); + streamClass.BindMethod("IsWritable", &Nz::Stream::IsWritable); + streamClass.BindMethod("SetCursorPos", &Nz::Stream::SetCursorPos); - streamClass.SetMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { + streamClass.BindMethod("Read", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { int argIndex = 1; std::size_t length = lua.Check(&argIndex); @@ -111,7 +111,7 @@ namespace Ndk return 1; }); - streamClass.SetMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { + streamClass.BindMethod("Write", [] (Nz::LuaInstance& lua, Nz::Stream& stream) -> int { int argIndex = 1; std::size_t bufferSize = 0; @@ -147,37 +147,37 @@ namespace Ndk return nullptr; }); - fileClass.SetMethod("Close", &Nz::File::Close); - fileClass.SetMethod("Copy", &Nz::File::Copy); - fileClass.SetMethod("Delete", &Nz::File::Delete); - fileClass.SetMethod("EndOfFile", &Nz::File::EndOfFile); - fileClass.SetMethod("Exists", &Nz::File::Exists); - fileClass.SetMethod("GetCreationTime", &Nz::File::GetCreationTime); - fileClass.SetMethod("GetFileName", &Nz::File::GetFileName); - fileClass.SetMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); - fileClass.SetMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.SetMethod("IsOpen", &Nz::File::IsOpen); - fileClass.SetMethod("Rename", &Nz::File::GetLastWriteTime); - fileClass.SetMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.SetMethod("SetFile", &Nz::File::GetLastWriteTime); + fileClass.BindMethod("Close", &Nz::File::Close); + fileClass.BindMethod("Copy", &Nz::File::Copy); + fileClass.BindMethod("Delete", &Nz::File::Delete); + fileClass.BindMethod("EndOfFile", &Nz::File::EndOfFile); + fileClass.BindMethod("Exists", &Nz::File::Exists); + fileClass.BindMethod("GetCreationTime", &Nz::File::GetCreationTime); + fileClass.BindMethod("GetFileName", &Nz::File::GetFileName); + fileClass.BindMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); + fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + fileClass.BindMethod("IsOpen", &Nz::File::IsOpen); + fileClass.BindMethod("Rename", &Nz::File::GetLastWriteTime); + fileClass.BindMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); + fileClass.BindMethod("SetFile", &Nz::File::GetLastWriteTime); - fileClass.SetStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); - fileClass.SetStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); - fileClass.SetStaticMethod("Copy", &Nz::File::Copy); - fileClass.SetStaticMethod("Delete", &Nz::File::Delete); - fileClass.SetStaticMethod("Exists", &Nz::File::Exists); + fileClass.BindStaticMethod("AbsolutePath", &Nz::File::AbsolutePath); + fileClass.BindStaticMethod("ComputeHash", (Nz::ByteArray (*)(Nz::HashType, const Nz::String&)) &Nz::File::ComputeHash); + fileClass.BindStaticMethod("Copy", &Nz::File::Copy); + fileClass.BindStaticMethod("Delete", &Nz::File::Delete); + fileClass.BindStaticMethod("Exists", &Nz::File::Exists); //fileClass.SetStaticMethod("GetCreationTime", &Nz::File::GetCreationTime); - fileClass.SetStaticMethod("GetDirectory", &Nz::File::GetDirectory); + fileClass.BindStaticMethod("GetDirectory", &Nz::File::GetDirectory); //fileClass.SetStaticMethod("GetLastAccessTime", &Nz::File::GetLastAccessTime); //fileClass.SetStaticMethod("GetLastWriteTime", &Nz::File::GetLastWriteTime); - fileClass.SetStaticMethod("GetSize", &Nz::File::GetSize); - fileClass.SetStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); - fileClass.SetStaticMethod("NormalizePath", &Nz::File::NormalizePath); - fileClass.SetStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); - fileClass.SetStaticMethod("Rename", &Nz::File::Rename); + fileClass.BindStaticMethod("GetSize", &Nz::File::GetSize); + fileClass.BindStaticMethod("IsAbsolute", &Nz::File::IsAbsolute); + fileClass.BindStaticMethod("NormalizePath", &Nz::File::NormalizePath); + fileClass.BindStaticMethod("NormalizeSeparators", &Nz::File::NormalizeSeparators); + fileClass.BindStaticMethod("Rename", &Nz::File::Rename); // Manual - fileClass.SetMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + fileClass.BindMethod("Open", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 2U); @@ -196,7 +196,7 @@ namespace Ndk return 0; }); - fileClass.SetMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int + fileClass.BindMethod("SetCursorPos", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 2U); @@ -214,7 +214,7 @@ namespace Ndk return 0; }); - fileClass.SetMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { + fileClass.BindMethod("__tostring", [] (Nz::LuaInstance& lua, Nz::File& file) -> int { Nz::StringStream stream("File("); if (file.IsOpen()) stream << "Path: " << file.GetPath(); diff --git a/SDK/src/NDK/LuaBinding_Graphics.cpp b/SDK/src/NDK/LuaBinding_Graphics.cpp index e3bbaec66..3d7597dd5 100644 --- a/SDK/src/NDK/LuaBinding_Graphics.cpp +++ b/SDK/src/NDK/LuaBinding_Graphics.cpp @@ -22,21 +22,21 @@ namespace Ndk }); //modelClass.SetMethod("GetMaterial", &Nz::Model::GetMaterial); - modelClass.SetMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); + modelClass.BindMethod("GetMaterialCount", &Nz::Model::GetMaterialCount); //modelClass.SetMethod("GetMesh", &Nz::Model::GetMesh); - modelClass.SetMethod("GetSkin", &Nz::Model::GetSkin); - modelClass.SetMethod("GetSkinCount", &Nz::Model::GetSkinCount); + modelClass.BindMethod("GetSkin", &Nz::Model::GetSkin); + modelClass.BindMethod("GetSkinCount", &Nz::Model::GetSkinCount); - modelClass.SetMethod("IsAnimated", &Nz::Model::IsAnimated); - modelClass.SetMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); + modelClass.BindMethod("IsAnimated", &Nz::Model::IsAnimated); + modelClass.BindMethod("LoadFromFile", &Nz::Model::LoadFromFile, Nz::ModelParameters()); - modelClass.SetMethod("Reset", &Nz::Model::Reset); + modelClass.BindMethod("Reset", &Nz::Model::Reset); //modelClass.SetMethod("SetMaterial", &Nz::Model::SetMaterial); //modelClass.SetMethod("SetMesh", &Nz::Model::SetMesh); //modelClass.SetMethod("SetSequence", &Nz::Model::SetSequence); - modelClass.SetMethod("SetSkin", &Nz::Model::SetSkin); - modelClass.SetMethod("SetSkinCount", &Nz::Model::SetSkinCount); + modelClass.BindMethod("SetSkin", &Nz::Model::SetSkin); + modelClass.BindMethod("SetSkinCount", &Nz::Model::SetSkinCount); } void LuaBinding::RegisterGraphics(Nz::LuaInstance& instance) diff --git a/SDK/src/NDK/LuaBinding_Math.cpp b/SDK/src/NDK/LuaBinding_Math.cpp index 5d7bc5a6b..808c93f86 100644 --- a/SDK/src/NDK/LuaBinding_Math.cpp +++ b/SDK/src/NDK/LuaBinding_Math.cpp @@ -28,7 +28,7 @@ namespace Ndk return nullptr; }); - eulerAnglesClass.SetMethod("__tostring", &Nz::EulerAnglesd::ToString); + eulerAnglesClass.BindMethod("__tostring", &Nz::EulerAnglesd::ToString); eulerAnglesClass.SetGetter([] (Nz::LuaInstance& lua, Nz::EulerAnglesd& instance) { @@ -173,7 +173,7 @@ namespace Ndk return nullptr; }); - quaternionClass.SetMethod("__tostring", &Nz::Quaterniond::ToString); + quaternionClass.BindMethod("__tostring", &Nz::Quaterniond::ToString); quaternionClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Quaterniond& instance) { @@ -262,7 +262,7 @@ namespace Ndk return nullptr; }); - vector2dClass.SetMethod("__tostring", &Nz::Vector2d::ToString); + vector2dClass.BindMethod("__tostring", &Nz::Vector2d::ToString); vector2dClass.SetGetter([](Nz::LuaInstance& lua, Nz::Vector2d& instance) { @@ -381,7 +381,7 @@ namespace Ndk return nullptr; }); - vector3dClass.SetMethod("__tostring", &Nz::Vector3d::ToString); + vector3dClass.BindMethod("__tostring", &Nz::Vector3d::ToString); vector3dClass.SetGetter([] (Nz::LuaInstance& lua, Nz::Vector3d& instance) { diff --git a/SDK/src/NDK/LuaBinding_Network.cpp b/SDK/src/NDK/LuaBinding_Network.cpp index 14f0b12ca..4b8334017 100644 --- a/SDK/src/NDK/LuaBinding_Network.cpp +++ b/SDK/src/NDK/LuaBinding_Network.cpp @@ -8,13 +8,13 @@ namespace Ndk void LuaBinding::BindNetwork() { /*********************************** Nz::AbstractSocket **********************************/ - abstractSocketClass.SetMethod("Close", &Nz::AbstractSocket::Close); - abstractSocketClass.SetMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); - abstractSocketClass.SetMethod("GetLastError", &Nz::AbstractSocket::GetLastError); - abstractSocketClass.SetMethod("GetState", &Nz::AbstractSocket::GetState); - abstractSocketClass.SetMethod("GetType", &Nz::AbstractSocket::GetType); - abstractSocketClass.SetMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); - abstractSocketClass.SetMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); + abstractSocketClass.BindMethod("Close", &Nz::AbstractSocket::Close); + abstractSocketClass.BindMethod("EnableBlocking", &Nz::AbstractSocket::EnableBlocking); + abstractSocketClass.BindMethod("GetLastError", &Nz::AbstractSocket::GetLastError); + abstractSocketClass.BindMethod("GetState", &Nz::AbstractSocket::GetState); + abstractSocketClass.BindMethod("GetType", &Nz::AbstractSocket::GetType); + abstractSocketClass.BindMethod("IsBlockingEnabled", &Nz::AbstractSocket::IsBlockingEnabled); + abstractSocketClass.BindMethod("QueryAvailableBytes", &Nz::AbstractSocket::QueryAvailableBytes); /*********************************** Nz::IpAddress **********************************/ ipAddressClass.SetConstructor([] (Nz::LuaInstance& lua) -> Nz::IpAddress* @@ -43,14 +43,14 @@ namespace Ndk return nullptr; }); - ipAddressClass.SetMethod("GetPort", &Nz::IpAddress::GetPort); - ipAddressClass.SetMethod("GetProtocol", &Nz::IpAddress::GetProtocol); - ipAddressClass.SetMethod("IsLoopback", &Nz::IpAddress::IsLoopback); - ipAddressClass.SetMethod("IsValid", &Nz::IpAddress::IsValid); - ipAddressClass.SetMethod("ToUInt32", &Nz::IpAddress::ToUInt32); - ipAddressClass.SetMethod("__tostring", &Nz::IpAddress::ToString); + ipAddressClass.BindMethod("GetPort", &Nz::IpAddress::GetPort); + ipAddressClass.BindMethod("GetProtocol", &Nz::IpAddress::GetProtocol); + ipAddressClass.BindMethod("IsLoopback", &Nz::IpAddress::IsLoopback); + ipAddressClass.BindMethod("IsValid", &Nz::IpAddress::IsValid); + ipAddressClass.BindMethod("ToUInt32", &Nz::IpAddress::ToUInt32); + ipAddressClass.BindMethod("__tostring", &Nz::IpAddress::ToString); - ipAddressClass.SetStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int + ipAddressClass.BindStaticMethod("ResolveAddress", [] (Nz::LuaInstance& instance) -> int { Nz::String service; Nz::ResolveError error = Nz::ResolveError_Unknown; @@ -72,7 +72,7 @@ namespace Ndk } }); - ipAddressClass.SetStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int + ipAddressClass.BindStaticMethod("ResolveHostname", [] (Nz::LuaInstance& instance) -> int { Nz::ResolveError error = Nz::ResolveError_Unknown; diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 3d5088a7e..7f020934d 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -7,41 +7,6 @@ namespace Ndk { - namespace - { - int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&) - { - lua.PushNil(); - return 1; - } - - template - int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle) - { - static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); - - T& component = handle->AddComponent(); - lua.Push(component.CreateHandle()); - return 1; - } - - int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&) - { - lua.PushNil(); - return 1; - } - - template - int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component) - { - static_assert(std::is_base_of::value, "ComponentType must inherit BaseComponent"); - - T& rightComponent = static_cast(component); - lua.Push(rightComponent.CreateHandle()); - return 1; - } - } - void LuaBinding::BindSDK() { /*********************************** Ndk::Application **********************************/ @@ -49,14 +14,14 @@ namespace Ndk #ifndef NDK_SERVER //application.SetMethod("AddWindow", &Application::AddWindow); #endif - application.SetMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int + application.BindMethod("AddWorld", [] (Nz::LuaInstance& instance, Application* application) -> int { instance.Push(application->AddWorld().CreateHandle()); return 1; }); - application.SetMethod("GetUpdateTime", &Application::GetUpdateTime); - application.SetMethod("Quit", &Application::Quit); + application.BindMethod("GetUpdateTime", &Application::GetUpdateTime); + application.BindMethod("Quit", &Application::Quit); /*********************************** Ndk::Console **********************************/ #ifndef NDK_SERVER @@ -65,40 +30,40 @@ namespace Ndk return handle->GetObject(); }); - consoleClass.SetMethod("AddLine", &Console::AddLine, Nz::Color::White); - consoleClass.SetMethod("Clear", &Console::Clear); - consoleClass.SetMethod("GetCharacterSize", &Console::GetCharacterSize); - consoleClass.SetMethod("GetHistory", &Console::GetHistory); - consoleClass.SetMethod("GetHistoryBackground", &Console::GetHistoryBackground); - consoleClass.SetMethod("GetInput", &Console::GetInput); - consoleClass.SetMethod("GetInputBackground", &Console::GetInputBackground); - consoleClass.SetMethod("GetSize", &Console::GetSize); + consoleClass.BindMethod("AddLine", &Console::AddLine, Nz::Color::White); + consoleClass.BindMethod("Clear", &Console::Clear); + consoleClass.BindMethod("GetCharacterSize", &Console::GetCharacterSize); + consoleClass.BindMethod("GetHistory", &Console::GetHistory); + consoleClass.BindMethod("GetHistoryBackground", &Console::GetHistoryBackground); + consoleClass.BindMethod("GetInput", &Console::GetInput); + consoleClass.BindMethod("GetInputBackground", &Console::GetInputBackground); + consoleClass.BindMethod("GetSize", &Console::GetSize); //consoleClass.SetMethod("GetTextFont", &Console::GetTextFont); - consoleClass.SetMethod("IsVisible", &Console::IsVisible); + consoleClass.BindMethod("IsVisible", &Console::IsVisible); - consoleClass.SetMethod("SendCharacter", &Console::SendCharacter); + consoleClass.BindMethod("SendCharacter", &Console::SendCharacter); //consoleClass.SetMethod("SendEvent", &Console::SendEvent); - consoleClass.SetMethod("SetCharacterSize", &Console::SetCharacterSize); - consoleClass.SetMethod("SetSize", &Console::SetSize); + consoleClass.BindMethod("SetCharacterSize", &Console::SetCharacterSize); + consoleClass.BindMethod("SetSize", &Console::SetSize); //consoleClass.SetMethod("SetTextFont", &Console::SetTextFont); - consoleClass.SetMethod("Show", &Console::Show, true); + consoleClass.BindMethod("Show", &Console::Show, true); #endif /*********************************** Ndk::Entity **********************************/ - entityClass.SetMethod("Enable", &Entity::Enable); - entityClass.SetMethod("GetId", &Entity::GetId); - entityClass.SetMethod("GetWorld", &Entity::GetWorld); - entityClass.SetMethod("Kill", &Entity::Kill); - entityClass.SetMethod("IsEnabled", &Entity::IsEnabled); - entityClass.SetMethod("IsValid", &Entity::IsValid); - entityClass.SetMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent); - entityClass.SetMethod("RemoveAllComponents", &Entity::RemoveAllComponents); - entityClass.SetMethod("__tostring", &EntityHandle::ToString); + entityClass.BindMethod("Enable", &Entity::Enable); + entityClass.BindMethod("GetId", &Entity::GetId); + entityClass.BindMethod("GetWorld", &Entity::GetWorld); + entityClass.BindMethod("Kill", &Entity::Kill); + entityClass.BindMethod("IsEnabled", &Entity::IsEnabled); + entityClass.BindMethod("IsValid", &Entity::IsValid); + entityClass.BindMethod("RemoveComponent", (void(Entity::*)(ComponentIndex)) &Entity::RemoveComponent); + entityClass.BindMethod("RemoveAllComponents", &Entity::RemoveAllComponents); + entityClass.BindMethod("__tostring", &EntityHandle::ToString); - entityClass.SetMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int + entityClass.BindMethod("AddComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int { int index = 1; ComponentIndex componentIndex = lua.Check(&index); @@ -110,7 +75,7 @@ namespace Ndk } ComponentBinding& binding = m_componentBinding[componentIndex]; - if (!binding.valid) + if (binding.name.IsEmpty()) { lua.Error("This component is not available to the LuaAPI"); return 0; @@ -119,7 +84,7 @@ namespace Ndk return binding.adder(lua, handle); }); - entityClass.SetMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int + entityClass.BindMethod("GetComponent", [this] (Nz::LuaInstance& lua, EntityHandle& handle) -> int { int index = 1; ComponentIndex componentIndex = lua.Check(&index); @@ -137,7 +102,7 @@ namespace Ndk } ComponentBinding& binding = m_componentBinding[componentIndex]; - if (!binding.valid) + if (binding.name.IsEmpty()) { lua.Error("This component is not available to the LuaAPI"); return 0; @@ -183,41 +148,28 @@ namespace Ndk }); /*********************************** Ndk::World **********************************/ - worldClass.SetMethod("CreateEntity", &World::CreateEntity); - worldClass.SetMethod("CreateEntities", &World::CreateEntities); - worldClass.SetMethod("Clear", &World::Clear); + worldClass.BindMethod("CreateEntity", &World::CreateEntity); + worldClass.BindMethod("CreateEntities", &World::CreateEntities); + worldClass.BindMethod("Clear", &World::Clear); #ifndef NDK_SERVER /*********************************** Ndk::GraphicsComponent **********************************/ - graphicsComponent.SetMethod("Attach", &GraphicsComponent::Attach, 0); + graphicsComponent.BindMethod("Attach", &GraphicsComponent::Attach, 0); #endif // Components functions - m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1); + m_componentBinding.resize(BaseComponent::GetMaxComponentIndex()); - EnableComponentBinding(); - EnableComponentBinding(); + BindComponent("Node"); + BindComponent("Velocity"); #ifndef NDK_SERVER - EnableComponentBinding(); + BindComponent("Graphics"); #endif } - template - void LuaBinding::EnableComponentBinding() - { - ComponentBinding binding; - binding.adder = &AddComponentOfType; - binding.getter = &PushComponentOfType; - binding.valid = true; - - NazaraAssert(T::componentIndex < m_componentBinding.size(), "Component index is over component binding size"); - - m_componentBinding[T::componentIndex] = std::move(binding); - } - void LuaBinding::RegisterSDK(Nz::LuaInstance& instance) { // Classes @@ -235,18 +187,16 @@ namespace Ndk // Enums // ComponentType (fake enumeration to expose component indexes) - instance.PushTable(); + instance.PushTable(0, m_componentBinding.size()); { - #ifndef NDK_SERVER - instance.PushInteger(GraphicsComponent::componentIndex); - instance.SetField("Graphics"); - #endif + for (const ComponentBinding& entry : m_componentBinding) + { + if (entry.name.IsEmpty()) + continue; - instance.PushInteger(NodeComponent::componentIndex); - instance.SetField("Node"); - - instance.PushInteger(VelocityComponent::componentIndex); - instance.SetField("Velocity"); + instance.PushInteger(entry.index); + instance.SetField(entry.name); + } } instance.SetGlobal("ComponentType"); } diff --git a/SDK/src/NDK/LuaBinding_Utility.cpp b/SDK/src/NDK/LuaBinding_Utility.cpp index 65447a0b3..86f4a6f9a 100644 --- a/SDK/src/NDK/LuaBinding_Utility.cpp +++ b/SDK/src/NDK/LuaBinding_Utility.cpp @@ -9,19 +9,19 @@ namespace Ndk void LuaBinding::BindUtility() { /*********************************** Nz::AbstractImage **********************************/ - abstractImage.SetMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel); - abstractImage.SetMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast(0)); - abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat); - abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast(0)); - abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount); - abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel); - abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast(0)); - abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType); - abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast(0)); - abstractImage.SetMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); - abstractImage.SetMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); + abstractImage.BindMethod("GetBytesPerPixel", &Nz::AbstractImage::GetBytesPerPixel); + abstractImage.BindMethod("GetDepth", &Nz::AbstractImage::GetDepth, static_cast(0)); + abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat); + abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast(0)); + abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount); + abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel); + abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast(0)); + abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType); + abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast(0)); + abstractImage.BindMethod("IsCompressed", &Nz::AbstractImage::IsCompressed); + abstractImage.BindMethod("IsCubemap", &Nz::AbstractImage::IsCubemap); - abstractImage.SetMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + abstractImage.BindMethod("GetMemoryUsage", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 1U); switch (argCount) @@ -42,7 +42,7 @@ namespace Ndk return 0; }); - abstractImage.SetMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int + abstractImage.BindMethod("Update", [] (Nz::LuaInstance& lua, Nz::AbstractImage* abstractImage) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 6U); int argIndex = 1; @@ -89,52 +89,52 @@ namespace Ndk }); /*********************************** Nz::Node **********************************/ - nodeClass.SetMethod("GetBackward", &Nz::Node::GetBackward); + nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward); //nodeClass.SetMethod("GetChilds", &Nz::Node::GetChilds); - nodeClass.SetMethod("GetDown", &Nz::Node::GetDown); - nodeClass.SetMethod("GetForward", &Nz::Node::GetForward); - nodeClass.SetMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); - nodeClass.SetMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); - nodeClass.SetMethod("GetInheritScale", &Nz::Node::GetInheritScale); - nodeClass.SetMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); + nodeClass.BindMethod("GetDown", &Nz::Node::GetDown); + nodeClass.BindMethod("GetForward", &Nz::Node::GetForward); + nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); + nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); + nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); + nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); //nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); - nodeClass.SetMethod("GetInitialScale", &Nz::Node::GetInitialScale); - nodeClass.SetMethod("GetLeft", &Nz::Node::GetLeft); - nodeClass.SetMethod("GetNodeType", &Nz::Node::GetNodeType); + nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); + nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft); + nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType); //nodeClass.SetMethod("GetParent", &Nz::Node::GetParent); - nodeClass.SetMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); - nodeClass.SetMethod("GetRight", &Nz::Node::GetRight); + nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); + nodeClass.BindMethod("GetRight", &Nz::Node::GetRight); //nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); - nodeClass.SetMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); + nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); //nodeClass.SetMethod("GetTransformMatrix", &Nz::Node::GetTransformMatrix); - nodeClass.SetMethod("GetUp", &Nz::Node::GetUp); + nodeClass.BindMethod("GetUp", &Nz::Node::GetUp); - nodeClass.SetMethod("HasChilds", &Nz::Node::HasChilds); + nodeClass.BindMethod("HasChilds", &Nz::Node::HasChilds); - nodeClass.SetMethod("GetBackward", &Nz::Node::GetBackward); - nodeClass.SetMethod("GetDown", &Nz::Node::GetDown); - nodeClass.SetMethod("GetForward", &Nz::Node::GetForward); - nodeClass.SetMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); - nodeClass.SetMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); - nodeClass.SetMethod("GetInheritScale", &Nz::Node::GetInheritScale); - nodeClass.SetMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); - nodeClass.SetMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); - nodeClass.SetMethod("GetInitialScale", &Nz::Node::GetInitialScale); - nodeClass.SetMethod("GetLeft", &Nz::Node::GetLeft); - nodeClass.SetMethod("GetNodeType", &Nz::Node::GetNodeType); - nodeClass.SetMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); - nodeClass.SetMethod("GetRight", &Nz::Node::GetRight); - nodeClass.SetMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); - nodeClass.SetMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); - nodeClass.SetMethod("GetUp", &Nz::Node::GetUp); + nodeClass.BindMethod("GetBackward", &Nz::Node::GetBackward); + nodeClass.BindMethod("GetDown", &Nz::Node::GetDown); + nodeClass.BindMethod("GetForward", &Nz::Node::GetForward); + nodeClass.BindMethod("GetInheritPosition", &Nz::Node::GetInheritPosition); + nodeClass.BindMethod("GetInheritRotation", &Nz::Node::GetInheritRotation); + nodeClass.BindMethod("GetInheritScale", &Nz::Node::GetInheritScale); + nodeClass.BindMethod("GetInitialPosition", &Nz::Node::GetInitialPosition); + nodeClass.BindMethod("GetInitialRotation", &Nz::Node::GetInitialRotation); + nodeClass.BindMethod("GetInitialScale", &Nz::Node::GetInitialScale); + nodeClass.BindMethod("GetLeft", &Nz::Node::GetLeft); + nodeClass.BindMethod("GetNodeType", &Nz::Node::GetNodeType); + nodeClass.BindMethod("GetPosition", &Nz::Node::GetPosition, Nz::CoordSys_Global); + nodeClass.BindMethod("GetRight", &Nz::Node::GetRight); + nodeClass.BindMethod("GetRotation", &Nz::Node::GetRotation, Nz::CoordSys_Global); + nodeClass.BindMethod("GetScale", &Nz::Node::GetScale, Nz::CoordSys_Global); + nodeClass.BindMethod("GetUp", &Nz::Node::GetUp); - nodeClass.SetMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition); - nodeClass.SetMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation); + nodeClass.BindMethod("SetInitialPosition", (void(Nz::Node::*)(const Nz::Vector3f&)) &Nz::Node::SetInitialPosition); + nodeClass.BindMethod("SetInitialRotation", (void(Nz::Node::*)(const Nz::Quaternionf&)) &Nz::Node::SetInitialRotation); - nodeClass.SetMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); - nodeClass.SetMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); + nodeClass.BindMethod("SetPosition", (void(Nz::Node::*)(const Nz::Vector3f&, Nz::CoordSys)) &Nz::Node::SetPosition, Nz::CoordSys_Local); + nodeClass.BindMethod("SetRotation", (void(Nz::Node::*)(const Nz::Quaternionf&, Nz::CoordSys)) &Nz::Node::SetRotation, Nz::CoordSys_Local); - nodeClass.SetMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + nodeClass.BindMethod("Move", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { int argIndex = 1; @@ -145,7 +145,7 @@ namespace Ndk return 0; }); - nodeClass.SetMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + nodeClass.BindMethod("Rotate", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { int argIndex = 1; @@ -156,7 +156,7 @@ namespace Ndk return 0; }); - nodeClass.SetMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + nodeClass.BindMethod("Scale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); @@ -182,7 +182,7 @@ namespace Ndk return 0; }); - nodeClass.SetMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + nodeClass.BindMethod("SetScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); @@ -219,7 +219,7 @@ namespace Ndk return 0; }); - nodeClass.SetMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int + nodeClass.BindMethod("SetInitialScale", [] (Nz::LuaInstance& lua, Nz::Node& node) -> int { unsigned int argCount = std::min(lua.GetStackTop(), 4U); diff --git a/SDK/src/NDK/Systems/RenderSystem.cpp b/SDK/src/NDK/Systems/RenderSystem.cpp index a87fdaf08..3237bbe52 100644 --- a/SDK/src/NDK/Systems/RenderSystem.cpp +++ b/SDK/src/NDK/Systems/RenderSystem.cpp @@ -15,6 +15,7 @@ namespace Ndk m_coordinateSystemMatrix(Nz::Matrix4f::Identity()), m_coordinateSystemInvalidated(true) { + ChangeRenderTechnique(); SetDefaultBackground(Nz::ColorBackground::New()); SetUpdateRate(0.f); } @@ -73,7 +74,7 @@ namespace Ndk CameraComponent& camComponent = camera->GetComponent(); camComponent.ApplyView(); - Nz::AbstractRenderQueue* renderQueue = m_renderTechnique.GetRenderQueue(); + Nz::AbstractRenderQueue* renderQueue = m_renderTechnique->GetRenderQueue(); renderQueue->Clear(); //TODO: Culling @@ -99,8 +100,8 @@ namespace Ndk sceneData.background = m_background; sceneData.viewer = &camComponent; - m_renderTechnique.Clear(sceneData); - m_renderTechnique.Draw(sceneData); + m_renderTechnique->Clear(sceneData); + m_renderTechnique->Draw(sceneData); } } diff --git a/include/Nazara/Core/Endianness.inl b/include/Nazara/Core/Endianness.inl index 400224920..2949e3f19 100644 --- a/include/Nazara/Core/Endianness.inl +++ b/include/Nazara/Core/Endianness.inl @@ -34,7 +34,7 @@ namespace Nz inline void SwapBytes(void* buffer, unsigned int size) { - UInt8* bytes = reinterpret_cast(buffer); + UInt8* bytes = static_cast(buffer); unsigned int i = 0; unsigned int j = size - 1; diff --git a/include/Nazara/Core/Error.hpp b/include/Nazara/Core/Error.hpp index b71bc8cf3..fbc4de38b 100644 --- a/include/Nazara/Core/Error.hpp +++ b/include/Nazara/Core/Error.hpp @@ -8,20 +8,19 @@ #define NAZARA_ERROR_HPP #include -#include #include -#include +#include #include #if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG) - #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) + #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION) #else #define NazaraAssert(a, err) for (;;) break #endif -#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) -#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) -#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) +#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION) +#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION) +#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION) namespace Nz { diff --git a/include/Nazara/Core/LockGuard.hpp b/include/Nazara/Core/LockGuard.hpp index 2dac4b578..d9ef5aa85 100644 --- a/include/Nazara/Core/LockGuard.hpp +++ b/include/Nazara/Core/LockGuard.hpp @@ -13,15 +13,22 @@ namespace Nz { class Mutex; - class NAZARA_CORE_API LockGuard + class LockGuard { public: - LockGuard(Mutex& mutex); - ~LockGuard(); + inline LockGuard(Mutex& mutex, bool lock = true); + inline ~LockGuard(); + + inline void Lock(); + inline bool TryLock(); + inline void Unlock(); private: Mutex& m_mutex; + bool m_locked; }; } +#include + #endif // NAZARA_LOCKGUARD_HPP diff --git a/include/Nazara/Core/LockGuard.inl b/include/Nazara/Core/LockGuard.inl new file mode 100644 index 000000000..73beab112 --- /dev/null +++ b/include/Nazara/Core/LockGuard.inl @@ -0,0 +1,83 @@ +// Copyright (C) 2015 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include + +namespace Nz +{ + /*! + * \ingroup core + * \class Nz::LockGuard + * \brief Core class that represents a mutex wrapper that provides a convenient RAII-style mechanism + */ + + /*! + * \brief Constructs a LockGuard object with a mutex + * + * \param mutex Mutex to lock + * \param lock Should the mutex be locked by the constructor + */ + inline LockGuard::LockGuard(Mutex& mutex, bool lock) : + m_mutex(mutex), + m_locked(false) + { + if (lock) + { + m_mutex.Lock(); + m_locked = true; + } + } + + /*! + * \brief Destructs a LockGuard object and unlocks the mutex if it was previously locked + */ + inline LockGuard::~LockGuard() + { + if (m_locked) + m_mutex.Unlock(); + } + + /*! + * \brief Locks the underlying mutex + * + * \see Mutex::Lock + */ + inline void LockGuard::Lock() + { + NazaraAssert(!m_locked, "Mutex is already locked"); + + m_mutex.Lock(); + } + + /*! + * \brief Tries to lock the underlying mutex + * + * \see Mutex::TryLock + * + * \return true if the lock was acquired successfully + */ + inline bool LockGuard::TryLock() + { + NazaraAssert(!m_locked, "Mutex is already locked"); + + return m_mutex.TryLock(); + } + + /*! + * \brief Unlocks the underlying mutex + * + * \see Mutex::Unlock + */ + inline void LockGuard::Unlock() + { + NazaraAssert(m_locked, "Mutex is not locked"); + + m_mutex.Unlock(); + } +} + +#include diff --git a/include/Nazara/Core/SparsePtr.inl b/include/Nazara/Core/SparsePtr.inl index 166efe751..0da69b0ad 100644 --- a/include/Nazara/Core/SparsePtr.inl +++ b/include/Nazara/Core/SparsePtr.inl @@ -161,7 +161,7 @@ namespace Nz template void SparsePtr::SetPtr(VoidPtr ptr) { - m_ptr = reinterpret_cast(ptr); + m_ptr = static_cast(ptr); } /*! diff --git a/include/Nazara/Lua/LuaClass.hpp b/include/Nazara/Lua/LuaClass.hpp index eb4cb51e3..8f9990bef 100644 --- a/include/Nazara/Lua/LuaClass.hpp +++ b/include/Nazara/Lua/LuaClass.hpp @@ -36,6 +36,15 @@ namespace Nz LuaClass(const String& name); + void BindMethod(const String& name, ClassFunc method); + template std::enable_if_t::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); + template std::enable_if_t::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); + template std::enable_if_t::type>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); + template std::enable_if_t::type>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); + + void BindStaticMethod(const String& name, StaticFunc func); + template void BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs); + template void Inherit(LuaClass

& parent); template void Inherit(LuaClass

& parent, ConvertToParent

convertFunc); @@ -46,15 +55,8 @@ namespace Nz void SetConstructor(ConstructorFunc constructor); void SetFinalizer(FinalizerFunc finalizer); void SetGetter(ClassIndexFunc getter); - void SetMethod(const String& name, ClassFunc method); - template std::enable_if_t::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); - template std::enable_if_t::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); - template std::enable_if_t::type>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs); - template std::enable_if_t::type>::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs); void SetSetter(ClassIndexFunc setter); void SetStaticGetter(StaticIndexFunc getter); - void SetStaticMethod(const String& name, StaticFunc func); - template void SetStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs); void SetStaticSetter(StaticIndexFunc getter); private: diff --git a/include/Nazara/Lua/LuaClass.inl b/include/Nazara/Lua/LuaClass.inl index ffcc4b0d8..913382f99 100644 --- a/include/Nazara/Lua/LuaClass.inl +++ b/include/Nazara/Lua/LuaClass.inl @@ -213,18 +213,18 @@ namespace Nz } template - void LuaClass::SetMethod(const String& name, ClassFunc method) + void LuaClass::BindMethod(const String& name, ClassFunc method) { m_methods[name] = method; } template template - std::enable_if_t::value> LuaClass::SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) + std::enable_if_t::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - SetMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int { handler.ProcessArgs(lua); @@ -234,11 +234,11 @@ namespace Nz template template - std::enable_if_t::value> LuaClass::SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) + std::enable_if_t::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - SetMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int { handler.ProcessArgs(lua); @@ -248,11 +248,11 @@ namespace Nz template template - std::enable_if_t::type>::value> LuaClass::SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) + std::enable_if_t::type>::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs) { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - SetMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int { handler.ProcessArgs(lua); @@ -262,11 +262,11 @@ namespace Nz template template - std::enable_if_t::type>::value> LuaClass::SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) + std::enable_if_t::type>::value> LuaClass::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs) { typename LuaImplMethodProxy::template Impl handler(std::forward(defArgs)...); - SetMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int + BindMethod(name, [func, handler] (LuaInstance& lua, T& object) -> int { handler.ProcessArgs(lua); @@ -287,18 +287,18 @@ namespace Nz } template - void LuaClass::SetStaticMethod(const String& name, StaticFunc method) + void LuaClass::BindStaticMethod(const String& name, StaticFunc method) { m_staticMethods[name] = method; } template template - void LuaClass::SetStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs) + void LuaClass::BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs) { typename LuaImplFunctionProxy::template Impl handler(std::forward(defArgs)...); - SetStaticMethod(name, [func, handler] (LuaInstance& lua) -> int + BindStaticMethod(name, [func, handler] (LuaInstance& lua) -> int { handler.ProcessArgs(lua); diff --git a/include/Nazara/Network/RUdpConnection.hpp b/include/Nazara/Network/RUdpConnection.hpp index 2896ec6ce..6166d787a 100644 --- a/include/Nazara/Network/RUdpConnection.hpp +++ b/include/Nazara/Network/RUdpConnection.hpp @@ -46,8 +46,8 @@ namespace Nz inline UInt16 GetBoundPort() const; inline SocketError GetLastError() const; - inline bool Listen(NetProtocol protocol, UInt16 port = 64266, unsigned int queueSize = 10); - bool Listen(const IpAddress& address, unsigned int queueSize = 10); + inline bool Listen(NetProtocol protocol, UInt16 port = 64266); + bool Listen(const IpAddress& address); bool PollMessage(RUdpMessage* message); @@ -56,6 +56,8 @@ namespace Nz inline void SetProtocolId(UInt32 protocolId); inline void SetTimeBeforeAck(UInt32 ms); + inline void SimulateNetwork(double packetLoss); + void Update(); RUdpConnection& operator=(const RUdpConnection&) = delete; @@ -137,9 +139,10 @@ namespace Nz UInt64 stateData1; }; - std::unordered_map m_peerByIP; + std::bernoulli_distribution m_packetLossProbability; std::queue m_receivedMessages; std::size_t m_peerIterator; + std::unordered_map m_peerByIP; std::vector m_peers; Bitset m_activeClients; Clock m_clock; @@ -151,6 +154,7 @@ namespace Nz UInt32 m_timeBeforePing; UInt32 m_timeBeforeTimeOut; UInt64 m_currentTime; + bool m_isSimulationEnabled; bool m_shouldAcceptConnections; static std::mt19937_64 s_randomGenerator; diff --git a/include/Nazara/Network/RUdpConnection.inl b/include/Nazara/Network/RUdpConnection.inl index cfb598bb9..b2372285d 100644 --- a/include/Nazara/Network/RUdpConnection.inl +++ b/include/Nazara/Network/RUdpConnection.inl @@ -33,7 +33,7 @@ namespace Nz return m_lastError; } - inline bool RUdpConnection::Listen(NetProtocol protocol, UInt16 port, unsigned int queueSize) + inline bool RUdpConnection::Listen(NetProtocol protocol, UInt16 port) { NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); @@ -56,7 +56,7 @@ namespace Nz } any.SetPort(port); - return Listen(any, queueSize); + return Listen(any); } inline void RUdpConnection::SetProtocolId(UInt32 protocolId) @@ -121,6 +121,19 @@ namespace Nz NazaraError("PacketReliability not handled (0x" + String::Number(reliability, 16) + ')'); return false; } + + inline void RUdpConnection::SimulateNetwork(double packetLoss) + { + NazaraAssert(packetLoss >= 0.0 && packetLoss <= 1.0, "Packet loss must be in range [0..1]"); + + if (packetLoss > 0.0) + { + m_isSimulationEnabled = true; + m_packetLossProbability = std::bernoulli_distribution(packetLoss); + } + else + m_isSimulationEnabled = false; + } } #include diff --git a/src/Nazara/Audio/Music.cpp b/src/Nazara/Audio/Music.cpp index be13419dc..aba84b5ff 100644 --- a/src/Nazara/Audio/Music.cpp +++ b/src/Nazara/Audio/Music.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,9 @@ namespace Nz ALenum audioFormat; std::unique_ptr stream; std::vector chunkSamples; + Mutex bufferLock; Thread thread; + UInt64 processedSamples; bool loop = false; bool streaming = false; unsigned int sampleRate; @@ -36,15 +39,9 @@ namespace Nz bool Music::Create(SoundStream* soundStream) { - Destroy(); + NazaraAssert(soundStream, "Invalid stream"); - #if NAZARA_AUDIO_SAFE - if (!soundStream) - { - NazaraError("Sound stream must be valid"); - return false; - } - #endif + Destroy(); AudioFormat format = soundStream->GetFormat(); @@ -54,6 +51,8 @@ namespace Nz m_impl->chunkSamples.resize(format * m_impl->sampleRate); // Une seconde de samples m_impl->stream.reset(soundStream); + SetPlayingOffset(0); + return true; } @@ -116,9 +115,14 @@ namespace Nz return 0; } #endif + + // Prevent music thread from enqueing new buffers while we're getting the count + Nz::LockGuard lock(m_impl->bufferLock); - ///TODO - return 0; + ALint samples = 0; + alGetSourcei(m_source, AL_SAMPLE_OFFSET, &samples); + + return (1000ULL * (samples + (m_impl->processedSamples / m_impl->stream->GetFormat()))) / m_impl->sampleRate; } UInt32 Music::GetSampleCount() const @@ -144,7 +148,7 @@ namespace Nz } #endif - return m_impl->stream->GetSampleRate(); + return m_impl->sampleRate; } SoundStatus Music::GetStatus() const @@ -209,22 +213,29 @@ namespace Nz } #endif - // Nous sommes déjà en train de jouer + // Maybe we are already playing if (m_impl->streaming) { - // Peut-être sommes-nous en pause - if (GetStatus() != SoundStatus_Playing) - alSourcePlay(m_source); + switch (GetStatus()) + { + case SoundStatus_Playing: + SetPlayingOffset(0); + break; - return; + case SoundStatus_Paused: + alSourcePlay(m_source); + break; + + default: + break; // We shouldn't be stopped + } + } + else + { + // Starting streaming's thread + m_impl->streaming = true; + m_impl->thread = Thread(&Music::MusicThread, this); } - - // Lancement du thread de streaming - m_impl->stream->Seek(0); - m_impl->streaming = true; - m_impl->thread = Thread(&Music::MusicThread, this); - - return; } void Music::SetPlayingOffset(UInt32 offset) @@ -237,7 +248,16 @@ namespace Nz } #endif - ///TODO + bool isPlaying = m_impl->streaming; + + if (isPlaying) + Stop(); + + m_impl->stream->Seek(offset); + m_impl->processedSamples = UInt64(offset) * m_impl->sampleRate * m_impl->stream->GetFormat() / 1000ULL; + + if (isPlaying) + Play(); } void Music::Stop() @@ -312,18 +332,29 @@ namespace Nz break; } + Nz::LockGuard lock(m_impl->bufferLock); + // On traite les buffers lus ALint processedCount = 0; alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &processedCount); - - ALuint buffer; while (processedCount--) { + ALuint buffer; alSourceUnqueueBuffers(m_source, 1, &buffer); + + ALint bits, size; + alGetBufferi(buffer, AL_BITS, &bits); + alGetBufferi(buffer, AL_SIZE, &size); + + if (bits != 0) + m_impl->processedSamples += (8 * size) / bits; + if (FillAndQueueBuffer(buffer)) break; } + lock.Unlock(); + // On retourne dormir un peu Thread::Sleep(50); } diff --git a/src/Nazara/Audio/Sound.cpp b/src/Nazara/Audio/Sound.cpp index 31ef3af27..7198a01d6 100644 --- a/src/Nazara/Audio/Sound.cpp +++ b/src/Nazara/Audio/Sound.cpp @@ -42,23 +42,17 @@ namespace Nz UInt32 Sound::GetDuration() const { - #if NAZARA_AUDIO_SAFE - if (!m_buffer) - { - NazaraError("Invalid sound buffer"); - return 0; - } - #endif + NazaraAssert(m_buffer, "Invalid sound buffer"); return m_buffer->GetDuration(); } UInt32 Sound::GetPlayingOffset() const { - ALfloat seconds = -1.f; - alGetSourcef(m_source, AL_SEC_OFFSET, &seconds); + ALint samples = 0; + alGetSourcei(m_source, AL_SAMPLE_OFFSET, &samples); - return static_cast(seconds*1000); + return static_cast(1000ULL * samples / m_buffer->GetSampleRate()); } SoundStatus Sound::GetStatus() const @@ -166,7 +160,7 @@ namespace Nz void Sound::SetPlayingOffset(UInt32 offset) { - alSourcef(m_source, AL_SEC_OFFSET, offset/1000.f); + alSourcei(m_source, AL_SAMPLE_OFFSET, static_cast(offset/1000.f * m_buffer->GetSampleRate())); } void Sound::Stop() diff --git a/src/Nazara/Audio/SoundBuffer.cpp b/src/Nazara/Audio/SoundBuffer.cpp index 10edc74f8..c01878383 100644 --- a/src/Nazara/Audio/SoundBuffer.cpp +++ b/src/Nazara/Audio/SoundBuffer.cpp @@ -105,7 +105,7 @@ namespace Nz m_impl = new SoundBufferImpl; m_impl->buffer = buffer; - m_impl->duration = (1000*sampleCount / (format * sampleRate)); + m_impl->duration = static_cast((1000ULL*sampleCount / (format * sampleRate))); m_impl->format = format; m_impl->sampleCount = sampleCount; m_impl->sampleRate = sampleRate; diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index ae6f0cc09..8de5e5747 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -165,6 +166,8 @@ namespace Nz void Error::Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function) { + file = Nz::Directory::GetCurrentFileRelativeToEngine(file); + if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) Log::WriteError(type, error, line, file, function); diff --git a/src/Nazara/Core/LockGuard.cpp b/src/Nazara/Core/LockGuard.cpp deleted file mode 100644 index e714f05f7..000000000 --- a/src/Nazara/Core/LockGuard.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2015 Jérôme Leclercq -// This file is part of the "Nazara Engine - Core module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup core - * \class Nz::LockGuard - * \brief Core class that represents a mutex wrapper that provides a convenient RAII-style mechanism - */ - - /*! - * \brief Constructs a LockGuard object with a mutex - * - * \param mutex Mutex to lock - */ - - LockGuard::LockGuard(Mutex& mutex) : - m_mutex(mutex) - { - m_mutex.Lock(); - } - - /*! - * \brief Destructs a LockGuard object and unlocks the mutex - */ - - LockGuard::~LockGuard() - { - m_mutex.Unlock(); - } -} diff --git a/src/Nazara/Core/MemoryManager.cpp b/src/Nazara/Core/MemoryManager.cpp index 5ee1755d7..3a4883bec 100644 --- a/src/Nazara/Core/MemoryManager.cpp +++ b/src/Nazara/Core/MemoryManager.cpp @@ -110,7 +110,7 @@ namespace Nz pthread_mutex_lock(&s_mutex); #endif - Block* ptr = reinterpret_cast(std::malloc(size+sizeof(Block))); + Block* ptr = static_cast(std::malloc(size+sizeof(Block))); if (!ptr) { char timeStr[23]; @@ -209,7 +209,7 @@ namespace Nz if (!pointer) return; - Block* ptr = reinterpret_cast(reinterpret_cast(pointer) - sizeof(Block)); + Block* ptr = reinterpret_cast(static_cast(pointer) - sizeof(Block)); if (ptr->magic != s_allocatedId) { char timeStr[23]; diff --git a/src/Nazara/Core/MemoryView.cpp b/src/Nazara/Core/MemoryView.cpp index 02c8b26c2..e501a031f 100644 --- a/src/Nazara/Core/MemoryView.cpp +++ b/src/Nazara/Core/MemoryView.cpp @@ -26,7 +26,7 @@ namespace Nz MemoryView::MemoryView(void* ptr, UInt64 size) : Stream(StreamOption_None, OpenMode_ReadWrite), - m_ptr(reinterpret_cast(ptr)), + m_ptr(static_cast(ptr)), m_pos(0), m_size(size) { @@ -43,7 +43,7 @@ namespace Nz MemoryView::MemoryView(const void* ptr, UInt64 size) : Stream(StreamOption_None, OpenMode_ReadOnly), - m_ptr(reinterpret_cast(const_cast(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only + m_ptr(static_cast(const_cast(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only m_pos(0), m_size(size) { diff --git a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp index c93859d68..5b5d7153d 100644 --- a/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp +++ b/src/Nazara/Core/Win32/TaskSchedulerImpl.cpp @@ -195,7 +195,7 @@ namespace Nz unsigned int __stdcall TaskSchedulerImpl::WorkerProc(void* userdata) { - unsigned int workerID = *reinterpret_cast(userdata); + unsigned int workerID = *static_cast(userdata); SetEvent(s_doneEvents[workerID]); Worker& worker = s_workers[workerID]; diff --git a/src/Nazara/Graphics/DeferredRenderTechnique.cpp b/src/Nazara/Graphics/DeferredRenderTechnique.cpp index a6956cdf8..88335d92b 100644 --- a/src/Nazara/Graphics/DeferredRenderTechnique.cpp +++ b/src/Nazara/Graphics/DeferredRenderTechnique.cpp @@ -120,7 +120,7 @@ namespace Nz for (unsigned int i = 0; i < 3; ++i) m_GBuffer[i] = Texture::New(); - + try { ErrorFlags errFlags(ErrorFlag_ThrowException); diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp index b2a63611d..21423fdc8 100644 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ b/src/Nazara/Graphics/ForwardRenderTechnique.cpp @@ -275,7 +275,7 @@ namespace Nz { // On ouvre le buffer en écriture BufferMapper vertexMapper(m_spriteBuffer, BufferAccess_DiscardAndWrite); - VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast(vertexMapper.GetPointer()); + VertexStruct_XYZ_Color_UV* vertices = static_cast(vertexMapper.GetPointer()); unsigned int spriteCount = 0; unsigned int maxSpriteCount = std::min(s_maxQuads, m_spriteBuffer.GetVertexCount()/4); @@ -414,7 +414,7 @@ namespace Nz billboardCount -= renderedBillboardCount; BufferMapper vertexMapper(m_billboardPointBuffer, BufferAccess_DiscardAndWrite, 0, renderedBillboardCount*4); - BillboardPoint* vertices = reinterpret_cast(vertexMapper.GetPointer()); + BillboardPoint* vertices = static_cast(vertexMapper.GetPointer()); for (unsigned int i = 0; i < renderedBillboardCount; ++i) { diff --git a/src/Nazara/Lua/LuaInstance.cpp b/src/Nazara/Lua/LuaInstance.cpp index c6b6a45e5..8e437d759 100644 --- a/src/Nazara/Lua/LuaInstance.cpp +++ b/src/Nazara/Lua/LuaInstance.cpp @@ -633,7 +633,7 @@ namespace Nz void LuaInstance::PushFunction(LuaFunction func) const { - LuaFunction* luaFunc = reinterpret_cast(lua_newuserdata(m_state, sizeof(LuaFunction))); + LuaFunction* luaFunc = static_cast(lua_newuserdata(m_state, sizeof(LuaFunction))); PlacementNew(luaFunc, std::move(func)); lua_pushcclosure(m_state, ProxyFunc, 1); diff --git a/src/Nazara/Network/RUdpConnection.cpp b/src/Nazara/Network/RUdpConnection.cpp index f8b57cf00..451d08f1e 100644 --- a/src/Nazara/Network/RUdpConnection.cpp +++ b/src/Nazara/Network/RUdpConnection.cpp @@ -18,6 +18,7 @@ namespace Nz m_timeBeforePing(500'000), //< 0.5s m_timeBeforeTimeOut(10'000'000), //< 10s m_currentTime(0), + m_isSimulationEnabled(false), m_shouldAcceptConnections(true) { } @@ -34,7 +35,7 @@ namespace Nz NetPacket connectionRequestPacket(NetCode_RequestConnection); connectionRequestPacket << client.stateData1; - EnqueuePacket(client, PacketPriority_Immediate, PacketReliability_Unreliable, connectionRequestPacket); + EnqueuePacket(client, PacketPriority_Immediate, PacketReliability_Reliable, connectionRequestPacket); return true; } @@ -63,7 +64,7 @@ namespace Nz return Connect(hostnameAddress); } - bool RUdpConnection::Listen(const IpAddress& address, unsigned int queueSize) + bool RUdpConnection::Listen(const IpAddress& address) { if (!InitSocket(address.GetProtocol())) return false; @@ -110,7 +111,7 @@ namespace Nz { PeerData& peer = m_peers[m_peerIterator]; - UInt32 timeSinceLastPacket = m_currentTime - peer.lastPacketTime; + UInt32 timeSinceLastPacket = static_cast(m_currentTime - peer.lastPacketTime); if (timeSinceLastPacket > m_timeBeforeTimeOut) { DisconnectPeer(peer.index); @@ -349,6 +350,12 @@ namespace Nz if (peer.receivedQueue.find(sequenceId) != peer.receivedQueue.end()) return; //< Ignore + if (m_isSimulationEnabled && m_packetLossProbability(s_randomGenerator)) + { + NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + String::Number(sequenceId) + " from " + peerIp.ToString() + " for simulation purpose"); + return; + } + ///< Receiving a packet from an acknowledged client means the connection works in both ways if (peer.state == PeerState_Aknowledged && packet.GetNetCode() != NetCode_RequestConnection) { diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index 5b31b6bd5..a134cf870 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -221,7 +221,7 @@ namespace Nz { int sendSize = static_cast(std::min(size - totalByteSent, std::numeric_limits::max())); //< Handle very large send int sentSize; - if (!SocketImpl::Send(m_handle, reinterpret_cast(buffer) + totalByteSent, sendSize, &sentSize, &m_lastError)) + if (!SocketImpl::Send(m_handle, static_cast(buffer) + totalByteSent, sendSize, &sentSize, &m_lastError)) { switch (m_lastError) { diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 1c5ee7ad0..35d4b2371 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -405,7 +405,7 @@ namespace Nz NazaraAssert(handle != InvalidHandle, "Invalid handle"); NazaraAssert(buffer && length > 0, "Invalid buffer"); - int byteRead = recv(handle, reinterpret_cast(buffer), length, 0); + int byteRead = recv(handle, static_cast(buffer), length, 0); if (byteRead == SOCKET_ERROR) { int errorCode = WSAGetLastError(); diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index 03b8b63a8..5623e6e8d 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -67,7 +67,7 @@ namespace Nz } BufferMapper mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24); - VertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); + VertexStruct_XYZ* vertex = static_cast(mapper.GetPointer()); Vector3f max, min; max = box.GetMaximum(); @@ -158,7 +158,7 @@ namespace Nz } BufferMapper mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24); - VertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); + VertexStruct_XYZ* vertex = static_cast(mapper.GetPointer()); vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftBottom)); vertex++; @@ -240,7 +240,7 @@ namespace Nz } BufferMapper mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24); - VertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); + VertexStruct_XYZ* vertex = static_cast(mapper.GetPointer()); vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftBottom)); vertex++; @@ -329,7 +329,7 @@ namespace Nz } BufferMapper mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, jointCount*2); - VertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); + VertexStruct_XYZ* vertex = static_cast(mapper.GetPointer()); unsigned int vertexCount = 0; for (unsigned int i = 0; i < jointCount; ++i) @@ -407,8 +407,8 @@ namespace Nz BufferMapper inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly); BufferMapper outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount); - MeshVertex* inputVertex = reinterpret_cast(inputMapper.GetPointer()); - VertexStruct_XYZ* outputVertex = reinterpret_cast(outputMapper.GetPointer()); + MeshVertex* inputVertex = static_cast(inputMapper.GetPointer()); + VertexStruct_XYZ* outputVertex = static_cast(outputMapper.GetPointer()); for (unsigned int i = 0; i < normalCount; ++i) { @@ -449,7 +449,7 @@ namespace Nz transformMatrix.SetTranslation(origin); BufferMapper mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 16); - VertexStruct_XYZ* vertex = reinterpret_cast(mapper.GetPointer()); + VertexStruct_XYZ* vertex = static_cast(mapper.GetPointer()); // On calcule le reste des points Vector3f base(Vector3f::Forward()*length); @@ -575,8 +575,8 @@ namespace Nz BufferMapper inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly); BufferMapper outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount); - MeshVertex* inputVertex = reinterpret_cast(inputMapper.GetPointer()); - VertexStruct_XYZ* outputVertex = reinterpret_cast(outputMapper.GetPointer()); + MeshVertex* inputVertex = static_cast(inputMapper.GetPointer()); + VertexStruct_XYZ* outputVertex = static_cast(outputMapper.GetPointer()); for (unsigned int i = 0; i < normalCount; ++i) { @@ -622,8 +622,8 @@ namespace Nz BufferMapper inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly); BufferMapper outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount); - MeshVertex* inputVertex = reinterpret_cast(inputMapper.GetPointer()); - VertexStruct_XYZ* outputVertex = reinterpret_cast(outputMapper.GetPointer()); + MeshVertex* inputVertex = static_cast(inputMapper.GetPointer()); + VertexStruct_XYZ* outputVertex = static_cast(outputMapper.GetPointer()); for (unsigned int i = 0; i < tangentCount; ++i) { diff --git a/src/Nazara/Renderer/GpuQuery.cpp b/src/Nazara/Renderer/GpuQuery.cpp index 6c3d404ce..4e7ff228f 100644 --- a/src/Nazara/Renderer/GpuQuery.cpp +++ b/src/Nazara/Renderer/GpuQuery.cpp @@ -19,7 +19,7 @@ namespace Nz Context::EnsureContext(); m_id = 0; - glGenQueries(1, reinterpret_cast(&m_id)); + glGenQueries(1, static_cast(&m_id)); #ifdef NAZARA_DEBUG if (!m_id) diff --git a/src/Nazara/Utility/Formats/MD2Loader.cpp b/src/Nazara/Utility/Formats/MD2Loader.cpp index 856a73823..184adfe17 100644 --- a/src/Nazara/Utility/Formats/MD2Loader.cpp +++ b/src/Nazara/Utility/Formats/MD2Loader.cpp @@ -115,7 +115,7 @@ namespace Nz stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle)); BufferMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite); - UInt16* index = reinterpret_cast(indexMapper.GetPointer()); + UInt16* index = static_cast(indexMapper.GetPointer()); for (unsigned int i = 0; i < header.num_tris; ++i) { @@ -190,7 +190,7 @@ namespace Nz translate *= s; BufferMapper vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite); - MeshVertex* vertex = reinterpret_cast(vertexMapper.GetPointer()); + MeshVertex* vertex = static_cast(vertexMapper.GetPointer()); /// Chargement des coordonnées de texture const unsigned int indexFix[3] = {0, 2, 1}; // Pour respécifier les indices dans le bon ordre diff --git a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp index 4c4b61bae..629452161 100644 --- a/src/Nazara/Utility/Formats/MD5MeshLoader.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshLoader.cpp @@ -249,7 +249,7 @@ namespace Nz VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage); BufferMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly); - MeshVertex* vertex = reinterpret_cast(vertexMapper.GetPointer()); + MeshVertex* vertex = static_cast(vertexMapper.GetPointer()); for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices) { // Skinning MD5 (Formule d'Id Tech) diff --git a/src/Nazara/Utility/IndexMapper.cpp b/src/Nazara/Utility/IndexMapper.cpp index e95f9b3cd..adf80a764 100644 --- a/src/Nazara/Utility/IndexMapper.cpp +++ b/src/Nazara/Utility/IndexMapper.cpp @@ -14,25 +14,25 @@ namespace Nz { UInt32 Getter16(const void* buffer, unsigned int i) { - const UInt16* ptr = reinterpret_cast(buffer); + const UInt16* ptr = static_cast(buffer); return ptr[i]; } UInt32 Getter32(const void* buffer, unsigned int i) { - const UInt32* ptr = reinterpret_cast(buffer); + const UInt32* ptr = static_cast(buffer); return ptr[i]; } void Setter16(void* buffer, unsigned int i, UInt32 value) { - UInt16* ptr = reinterpret_cast(buffer); + UInt16* ptr = static_cast(buffer); ptr[i] = static_cast(value); } void Setter32(void* buffer, unsigned int i, UInt32 value) { - UInt32* ptr = reinterpret_cast(buffer); + UInt32* ptr = static_cast(buffer); ptr[i] = value; } diff --git a/src/Nazara/Utility/Win32/InputImpl.cpp b/src/Nazara/Utility/Win32/InputImpl.cpp index 443e38855..ba604deb8 100644 --- a/src/Nazara/Utility/Win32/InputImpl.cpp +++ b/src/Nazara/Utility/Win32/InputImpl.cpp @@ -213,7 +213,7 @@ namespace Nz Vector2i EventImpl::GetMousePosition(const Window& relativeTo) { - HWND handle = reinterpret_cast(relativeTo.GetHandle()); + HWND handle = static_cast(relativeTo.GetHandle()); if (handle) { POINT pos; @@ -283,7 +283,7 @@ namespace Nz void EventImpl::SetMousePosition(int x, int y, const Window& relativeTo) { - HWND handle = reinterpret_cast(relativeTo.GetHandle()); + HWND handle = static_cast(relativeTo.GetHandle()); if (handle) { POINT pos = {x, y}; diff --git a/src/Nazara/Utility/Win32/WindowImpl.cpp b/src/Nazara/Utility/Win32/WindowImpl.cpp index e910e8acc..2bf9c9d02 100644 --- a/src/Nazara/Utility/Win32/WindowImpl.cpp +++ b/src/Nazara/Utility/Win32/WindowImpl.cpp @@ -193,7 +193,7 @@ namespace Nz bool WindowImpl::Create(WindowHandle handle) { - m_handle = reinterpret_cast(handle); + m_handle = static_cast(handle); if (!m_handle || !IsWindow(m_handle)) { @@ -342,7 +342,7 @@ namespace Nz #endif if (cursor != WindowCursor_None) - m_cursor = reinterpret_cast(LoadImage(nullptr, windowsCursors[cursor], IMAGE_CURSOR, 0, 0, LR_SHARED)); + m_cursor = static_cast(LoadImage(nullptr, windowsCursors[cursor], IMAGE_CURSOR, 0, 0, LR_SHARED)); else m_cursor = nullptr; @@ -1125,7 +1125,7 @@ namespace Nz WindowImpl* me; if (message == WM_CREATE) { - me = reinterpret_cast(reinterpret_cast(lParam)->lpCreateParams); + me = static_cast(reinterpret_cast(lParam)->lpCreateParams); SetWindowLongPtr(window, GWL_USERDATA, reinterpret_cast(me)); } else diff --git a/tests/Engine/Core/Serialization.cpp b/tests/Engine/Core/Serialization.cpp index 299b9cc8f..a4d8ff75e 100644 --- a/tests/Engine/Core/Serialization.cpp +++ b/tests/Engine/Core/Serialization.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include