Former-commit-id: d9f7e15f4da9496cd44987901c1889cde45a4c18
This commit is contained in:
Lynix 2016-04-18 12:14:56 +02:00
commit 1a9ef6a42a
45 changed files with 597 additions and 462 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ build/**/*.slo
build/**/*.lo
build/**/*.o
build/**/*.obj
build/**/*.obj.enc
# Compiled Dynamic libraries
build/**/*.so

View File

@ -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<typename ComponentType>

View File

@ -27,12 +27,14 @@
namespace Ndk
{
class LuaBinding
class NDK_API LuaBinding
{
public:
LuaBinding();
~LuaBinding() = default;
template<typename T> void BindComponent(const Nz::String& name);
void RegisterClasses(Nz::LuaInstance& instance);
private:
@ -42,8 +44,6 @@ namespace Ndk
void BindSDK();
void BindUtility();
template<typename T> 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<ComponentBinding> m_componentBinding;
@ -115,6 +116,14 @@ namespace Ndk
Nz::LuaClass<GraphicsComponentHandle> graphicsComponent;
#endif
};
template<typename T>
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle);
template<typename T>
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component);
}
#include <NDK/LuaBinding.inl>
#endif // NDK_LUABINDING_HPP

View File

@ -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 <NDK/LuaBinding.hpp>
namespace Ndk
{
template<typename T>
void LuaBinding::BindComponent(const Nz::String& name)
{
NazaraAssert(!name.IsEmpty(), "Component name cannot be empty");
ComponentBinding binding;
binding.adder = &AddComponentOfType<T>;
binding.getter = &PushComponentOfType<T>;
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<typename T>
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
T& component = handle->AddComponent<T>();
lua.Push(component.CreateHandle());
return 1;
}
template<typename T>
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
T& rightComponent = static_cast<T&>(component);
lua.Push(rightComponent.CreateHandle());
return 1;
}
}

View File

@ -8,7 +8,7 @@
#define NDK_SYSTEMS_RENDERSYSTEM_HPP
#include <Nazara/Graphics/AbstractBackground.hpp>
#include <Nazara/Graphics/ForwardRenderTechnique.hpp>
#include <Nazara/Graphics/DeferredRenderTechnique.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <unordered_map>
@ -25,11 +25,15 @@ namespace Ndk
inline RenderSystem(const RenderSystem& renderSystem);
~RenderSystem() = default;
template<typename T> void ChangeRenderTechnique();
inline void ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& 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<Nz::AbstractRenderTechnique> 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;
};

View File

@ -9,6 +9,17 @@ namespace Ndk
{
}
template<typename T>
inline void RenderSystem::ChangeRenderTechnique()
{
ChangeRenderTechnique(std::make_unique<T>());
}
inline void RenderSystem::ChangeRenderTechnique(std::unique_ptr<Nz::AbstractRenderTechnique>&& 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);

View File

@ -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<Nz::AudioFormat>(&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<const char*>(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)

View File

@ -14,16 +14,16 @@ namespace Ndk
return new Nz::Clock(lua.Check<Nz::Int64>(&argIndex, 0), lua.Check<bool>(&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<std::size_t>(&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();

View File

@ -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)

View File

@ -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)
{

View File

@ -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;

View File

@ -7,41 +7,6 @@
namespace Ndk
{
namespace
{
int AddNilComponent(Nz::LuaInstance& lua, EntityHandle&)
{
lua.PushNil();
return 1;
}
template<typename T>
int AddComponentOfType(Nz::LuaInstance& lua, EntityHandle& handle)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
T& component = handle->AddComponent<T>();
lua.Push(component.CreateHandle());
return 1;
}
int PushNilComponent(Nz::LuaInstance& lua, BaseComponent&)
{
lua.PushNil();
return 1;
}
template<typename T>
int PushComponentOfType(Nz::LuaInstance& lua, BaseComponent& component)
{
static_assert(std::is_base_of<BaseComponent, T>::value, "ComponentType must inherit BaseComponent");
T& rightComponent = static_cast<T&>(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<ComponentIndex>(&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<ComponentIndex>(&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<NodeComponent>();
EnableComponentBinding<VelocityComponent>();
BindComponent<NodeComponent>("Node");
BindComponent<VelocityComponent>("Velocity");
#ifndef NDK_SERVER
EnableComponentBinding<GraphicsComponent>();
BindComponent<GraphicsComponent>("Graphics");
#endif
}
template<typename T>
void LuaBinding::EnableComponentBinding()
{
ComponentBinding binding;
binding.adder = &AddComponentOfType<T>;
binding.getter = &PushComponentOfType<T>;
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");
}

View File

@ -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<Nz::UInt8>(0));
abstractImage.SetMethod("GetFormat", &Nz::AbstractImage::GetFormat);
abstractImage.SetMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
abstractImage.SetMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
abstractImage.SetMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
abstractImage.SetMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
abstractImage.SetMethod("GetType", &Nz::AbstractImage::GetType);
abstractImage.SetMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(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<Nz::UInt8>(0));
abstractImage.BindMethod("GetFormat", &Nz::AbstractImage::GetFormat);
abstractImage.BindMethod("GetHeight", &Nz::AbstractImage::GetHeight, static_cast<Nz::UInt8>(0));
abstractImage.BindMethod("GetLevelCount", &Nz::AbstractImage::GetLevelCount);
abstractImage.BindMethod("GetMaxLevel", &Nz::AbstractImage::GetMaxLevel);
abstractImage.BindMethod("GetSize", &Nz::AbstractImage::GetSize, static_cast<Nz::UInt8>(0));
abstractImage.BindMethod("GetType", &Nz::AbstractImage::GetType);
abstractImage.BindMethod("GetWidth", &Nz::AbstractImage::GetWidth, static_cast<Nz::UInt8>(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);

View File

@ -15,6 +15,7 @@ namespace Ndk
m_coordinateSystemMatrix(Nz::Matrix4f::Identity()),
m_coordinateSystemInvalidated(true)
{
ChangeRenderTechnique<Nz::ForwardRenderTechnique>();
SetDefaultBackground(Nz::ColorBackground::New());
SetUpdateRate(0.f);
}
@ -73,7 +74,7 @@ namespace Ndk
CameraComponent& camComponent = camera->GetComponent<CameraComponent>();
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);
}
}

View File

@ -34,7 +34,7 @@ namespace Nz
inline void SwapBytes(void* buffer, unsigned int size)
{
UInt8* bytes = reinterpret_cast<UInt8*>(buffer);
UInt8* bytes = static_cast<UInt8*>(buffer);
unsigned int i = 0;
unsigned int j = size - 1;

View File

@ -8,20 +8,19 @@
#define NAZARA_ERROR_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/String.hpp>
#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
{

View File

@ -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 <Nazara/Core/LockGuard.inl>
#endif // NAZARA_LOCKGUARD_HPP

View File

@ -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 <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Debug.hpp>
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 <Nazara/Core/DebugOff.hpp>

View File

@ -161,7 +161,7 @@ namespace Nz
template<typename T>
void SparsePtr<T>::SetPtr(VoidPtr ptr)
{
m_ptr = reinterpret_cast<BytePtr>(ptr);
m_ptr = static_cast<BytePtr>(ptr);
}
/*!

View File

@ -36,6 +36,15 @@ namespace Nz
LuaClass(const String& name);
void BindMethod(const String& name, ClassFunc method);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
void BindStaticMethod(const String& name, StaticFunc func);
template<typename R, typename... Args, typename... DefArgs> void BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs);
template<class P> void Inherit(LuaClass<P>& parent);
template<class P> void Inherit(LuaClass<P>& parent, ConvertToParent<P> 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<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, T>::value> SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs);
template<typename R, typename P, typename... Args, typename... DefArgs> std::enable_if_t<std::is_base_of<P, typename PointedType<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<typename R, typename... Args, typename... DefArgs> void SetStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs);
void SetStaticSetter(StaticIndexFunc getter);
private:

View File

@ -213,18 +213,18 @@ namespace Nz
}
template<class T>
void LuaClass<T>::SetMethod(const String& name, ClassFunc method)
void LuaClass<T>::BindMethod(const String& name, ClassFunc method)
{
m_methods[name] = method;
}
template<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(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<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
std::enable_if_t<std::is_base_of<P, T>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(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<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(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<class T>
template<typename R, typename P, typename... Args, typename... DefArgs>
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::SetMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
std::enable_if_t<std::is_base_of<P, typename PointedType<T>::type>::value> LuaClass<T>::BindMethod(const String& name, R(P::*func)(Args...) const, DefArgs&&... defArgs)
{
typename LuaImplMethodProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(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<class T>
void LuaClass<T>::SetStaticMethod(const String& name, StaticFunc method)
void LuaClass<T>::BindStaticMethod(const String& name, StaticFunc method)
{
m_staticMethods[name] = method;
}
template<class T>
template<typename R, typename... Args, typename... DefArgs>
void LuaClass<T>::SetStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs)
void LuaClass<T>::BindStaticMethod(const String& name, R(*func)(Args...), DefArgs&&... defArgs)
{
typename LuaImplFunctionProxy<Args...>::template Impl<DefArgs...> handler(std::forward<DefArgs>(defArgs)...);
SetStaticMethod(name, [func, handler] (LuaInstance& lua) -> int
BindStaticMethod(name, [func, handler] (LuaInstance& lua) -> int
{
handler.ProcessArgs(lua);

View File

@ -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<IpAddress, std::size_t> m_peerByIP;
std::bernoulli_distribution m_packetLossProbability;
std::queue<RUdpMessage> m_receivedMessages;
std::size_t m_peerIterator;
std::unordered_map<IpAddress, std::size_t> m_peerByIP;
std::vector<PeerData> m_peers;
Bitset<UInt64> 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;

View File

@ -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 <Nazara/Network/DebugOff.hpp>

View File

@ -6,6 +6,7 @@
#include <Nazara/Audio/Audio.hpp>
#include <Nazara/Audio/OpenAL.hpp>
#include <Nazara/Audio/SoundStream.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Thread.hpp>
#include <memory>
#include <vector>
@ -23,7 +24,9 @@ namespace Nz
ALenum audioFormat;
std::unique_ptr<SoundStream> stream;
std::vector<Int16> 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);
}

View File

@ -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<UInt32>(seconds*1000);
return static_cast<UInt32>(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<ALint>(offset/1000.f * m_buffer->GetSampleRate()));
}
void Sound::Stop()

View File

@ -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<UInt32>((1000ULL*sampleCount / (format * sampleRate)));
m_impl->format = format;
m_impl->sampleCount = sampleCount;
m_impl->sampleRate = sampleRate;

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/Log.hpp>
#include <cstdlib>
#include <stdexcept>
@ -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);

View File

@ -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 <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/Debug.hpp>
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();
}
}

View File

@ -110,7 +110,7 @@ namespace Nz
pthread_mutex_lock(&s_mutex);
#endif
Block* ptr = reinterpret_cast<Block*>(std::malloc(size+sizeof(Block)));
Block* ptr = static_cast<Block*>(std::malloc(size+sizeof(Block)));
if (!ptr)
{
char timeStr[23];
@ -209,7 +209,7 @@ namespace Nz
if (!pointer)
return;
Block* ptr = reinterpret_cast<Block*>(reinterpret_cast<UInt8*>(pointer) - sizeof(Block));
Block* ptr = reinterpret_cast<Block*>(static_cast<UInt8*>(pointer) - sizeof(Block));
if (ptr->magic != s_allocatedId)
{
char timeStr[23];

View File

@ -26,7 +26,7 @@ namespace Nz
MemoryView::MemoryView(void* ptr, UInt64 size) :
Stream(StreamOption_None, OpenMode_ReadWrite),
m_ptr(reinterpret_cast<UInt8*>(ptr)),
m_ptr(static_cast<UInt8*>(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<UInt8*>(const_cast<void*>(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only
m_ptr(static_cast<UInt8*>(const_cast<void*>(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only
m_pos(0),
m_size(size)
{

View File

@ -195,7 +195,7 @@ namespace Nz
unsigned int __stdcall TaskSchedulerImpl::WorkerProc(void* userdata)
{
unsigned int workerID = *reinterpret_cast<unsigned int*>(userdata);
unsigned int workerID = *static_cast<unsigned int*>(userdata);
SetEvent(s_doneEvents[workerID]);
Worker& worker = s_workers[workerID];

View File

@ -120,7 +120,7 @@ namespace Nz
for (unsigned int i = 0; i < 3; ++i)
m_GBuffer[i] = Texture::New();
try
{
ErrorFlags errFlags(ErrorFlag_ThrowException);

View File

@ -275,7 +275,7 @@ namespace Nz
{
// On ouvre le buffer en écriture
BufferMapper<VertexBuffer> vertexMapper(m_spriteBuffer, BufferAccess_DiscardAndWrite);
VertexStruct_XYZ_Color_UV* vertices = reinterpret_cast<VertexStruct_XYZ_Color_UV*>(vertexMapper.GetPointer());
VertexStruct_XYZ_Color_UV* vertices = static_cast<VertexStruct_XYZ_Color_UV*>(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<VertexBuffer> vertexMapper(m_billboardPointBuffer, BufferAccess_DiscardAndWrite, 0, renderedBillboardCount*4);
BillboardPoint* vertices = reinterpret_cast<BillboardPoint*>(vertexMapper.GetPointer());
BillboardPoint* vertices = static_cast<BillboardPoint*>(vertexMapper.GetPointer());
for (unsigned int i = 0; i < renderedBillboardCount; ++i)
{

View File

@ -633,7 +633,7 @@ namespace Nz
void LuaInstance::PushFunction(LuaFunction func) const
{
LuaFunction* luaFunc = reinterpret_cast<LuaFunction*>(lua_newuserdata(m_state, sizeof(LuaFunction)));
LuaFunction* luaFunc = static_cast<LuaFunction*>(lua_newuserdata(m_state, sizeof(LuaFunction)));
PlacementNew<LuaFunction>(luaFunc, std::move(func));
lua_pushcclosure(m_state, ProxyFunc, 1);

View File

@ -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<UInt32>(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)
{

View File

@ -221,7 +221,7 @@ namespace Nz
{
int sendSize = static_cast<int>(std::min<std::size_t>(size - totalByteSent, std::numeric_limits<int>::max())); //< Handle very large send
int sentSize;
if (!SocketImpl::Send(m_handle, reinterpret_cast<const UInt8*>(buffer) + totalByteSent, sendSize, &sentSize, &m_lastError))
if (!SocketImpl::Send(m_handle, static_cast<const UInt8*>(buffer) + totalByteSent, sendSize, &sentSize, &m_lastError))
{
switch (m_lastError)
{

View File

@ -405,7 +405,7 @@ namespace Nz
NazaraAssert(handle != InvalidHandle, "Invalid handle");
NazaraAssert(buffer && length > 0, "Invalid buffer");
int byteRead = recv(handle, reinterpret_cast<char*>(buffer), length, 0);
int byteRead = recv(handle, static_cast<char*>(buffer), length, 0);
if (byteRead == SOCKET_ERROR)
{
int errorCode = WSAGetLastError();

View File

@ -67,7 +67,7 @@ namespace Nz
}
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
VertexStruct_XYZ* vertex = reinterpret_cast<VertexStruct_XYZ*>(mapper.GetPointer());
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
Vector3f max, min;
max = box.GetMaximum();
@ -158,7 +158,7 @@ namespace Nz
}
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
VertexStruct_XYZ* vertex = reinterpret_cast<VertexStruct_XYZ*>(mapper.GetPointer());
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
vertex->position.Set(frustum.GetCorner(BoxCorner_NearLeftBottom));
vertex++;
@ -240,7 +240,7 @@ namespace Nz
}
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 24);
VertexStruct_XYZ* vertex = reinterpret_cast<VertexStruct_XYZ*>(mapper.GetPointer());
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
vertex->position.Set(orientedBox.GetCorner(BoxCorner_NearLeftBottom));
vertex++;
@ -329,7 +329,7 @@ namespace Nz
}
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, jointCount*2);
VertexStruct_XYZ* vertex = reinterpret_cast<VertexStruct_XYZ*>(mapper.GetPointer());
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
unsigned int vertexCount = 0;
for (unsigned int i = 0; i < jointCount; ++i)
@ -407,8 +407,8 @@ namespace Nz
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
MeshVertex* inputVertex = reinterpret_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = reinterpret_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
for (unsigned int i = 0; i < normalCount; ++i)
{
@ -449,7 +449,7 @@ namespace Nz
transformMatrix.SetTranslation(origin);
BufferMapper<VertexBuffer> mapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, 16);
VertexStruct_XYZ* vertex = reinterpret_cast<VertexStruct_XYZ*>(mapper.GetPointer());
VertexStruct_XYZ* vertex = static_cast<VertexStruct_XYZ*>(mapper.GetPointer());
// On calcule le reste des points
Vector3f base(Vector3f::Forward()*length);
@ -575,8 +575,8 @@ namespace Nz
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
MeshVertex* inputVertex = reinterpret_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = reinterpret_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
for (unsigned int i = 0; i < normalCount; ++i)
{
@ -622,8 +622,8 @@ namespace Nz
BufferMapper<VertexBuffer> inputMapper(subMesh->GetVertexBuffer(), BufferAccess_ReadOnly);
BufferMapper<VertexBuffer> outputMapper(s_vertexBuffer, BufferAccess_DiscardAndWrite, 0, vertexCount);
MeshVertex* inputVertex = reinterpret_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = reinterpret_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
MeshVertex* inputVertex = static_cast<MeshVertex*>(inputMapper.GetPointer());
VertexStruct_XYZ* outputVertex = static_cast<VertexStruct_XYZ*>(outputMapper.GetPointer());
for (unsigned int i = 0; i < tangentCount; ++i)
{

View File

@ -19,7 +19,7 @@ namespace Nz
Context::EnsureContext();
m_id = 0;
glGenQueries(1, reinterpret_cast<GLuint*>(&m_id));
glGenQueries(1, static_cast<GLuint*>(&m_id));
#ifdef NAZARA_DEBUG
if (!m_id)

View File

@ -115,7 +115,7 @@ namespace Nz
stream.Read(&triangles[0], header.num_tris*sizeof(MD2_Triangle));
BufferMapper<IndexBuffer> indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
UInt16* index = reinterpret_cast<UInt16*>(indexMapper.GetPointer());
UInt16* index = static_cast<UInt16*>(indexMapper.GetPointer());
for (unsigned int i = 0; i < header.num_tris; ++i)
{
@ -190,7 +190,7 @@ namespace Nz
translate *= s;
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_DiscardAndWrite);
MeshVertex* vertex = reinterpret_cast<MeshVertex*>(vertexMapper.GetPointer());
MeshVertex* vertex = static_cast<MeshVertex*>(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

View File

@ -249,7 +249,7 @@ namespace Nz
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage);
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
MeshVertex* vertex = reinterpret_cast<MeshVertex*>(vertexMapper.GetPointer());
MeshVertex* vertex = static_cast<MeshVertex*>(vertexMapper.GetPointer());
for (const MD5MeshParser::Vertex& md5Vertex : md5Mesh.vertices)
{
// Skinning MD5 (Formule d'Id Tech)

View File

@ -14,25 +14,25 @@ namespace Nz
{
UInt32 Getter16(const void* buffer, unsigned int i)
{
const UInt16* ptr = reinterpret_cast<const UInt16*>(buffer);
const UInt16* ptr = static_cast<const UInt16*>(buffer);
return ptr[i];
}
UInt32 Getter32(const void* buffer, unsigned int i)
{
const UInt32* ptr = reinterpret_cast<const UInt32*>(buffer);
const UInt32* ptr = static_cast<const UInt32*>(buffer);
return ptr[i];
}
void Setter16(void* buffer, unsigned int i, UInt32 value)
{
UInt16* ptr = reinterpret_cast<UInt16*>(buffer);
UInt16* ptr = static_cast<UInt16*>(buffer);
ptr[i] = static_cast<UInt16>(value);
}
void Setter32(void* buffer, unsigned int i, UInt32 value)
{
UInt32* ptr = reinterpret_cast<UInt32*>(buffer);
UInt32* ptr = static_cast<UInt32*>(buffer);
ptr[i] = value;
}

View File

@ -213,7 +213,7 @@ namespace Nz
Vector2i EventImpl::GetMousePosition(const Window& relativeTo)
{
HWND handle = reinterpret_cast<HWND>(relativeTo.GetHandle());
HWND handle = static_cast<HWND>(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<HWND>(relativeTo.GetHandle());
HWND handle = static_cast<HWND>(relativeTo.GetHandle());
if (handle)
{
POINT pos = {x, y};

View File

@ -193,7 +193,7 @@ namespace Nz
bool WindowImpl::Create(WindowHandle handle)
{
m_handle = reinterpret_cast<HWND>(handle);
m_handle = static_cast<HWND>(handle);
if (!m_handle || !IsWindow(m_handle))
{
@ -342,7 +342,7 @@ namespace Nz
#endif
if (cursor != WindowCursor_None)
m_cursor = reinterpret_cast<HCURSOR>(LoadImage(nullptr, windowsCursors[cursor], IMAGE_CURSOR, 0, 0, LR_SHARED));
m_cursor = static_cast<HCURSOR>(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<WindowImpl*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
me = static_cast<WindowImpl*>(reinterpret_cast<CREATESTRUCT*>(lParam)->lpCreateParams);
SetWindowLongPtr(window, GWL_USERDATA, reinterpret_cast<LONG_PTR>(me));
}
else

View File

@ -5,6 +5,7 @@
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Ray.hpp>
#include <array>
#include <Catch/catch.hpp>