Merge remote-tracking branch 'refs/remotes/origin/master' into console-widget
This commit is contained in:
commit
f00359072f
2
Doxyfile
2
Doxyfile
|
|
@ -38,7 +38,7 @@ PROJECT_NAME = "Nazara Engine"
|
||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = 0.2
|
PROJECT_NUMBER = 0.3
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ namespace Ndk
|
||||||
{
|
{
|
||||||
inline BaseWidget::BaseWidget() :
|
inline BaseWidget::BaseWidget() :
|
||||||
m_canvasIndex(InvalidCanvasIndex),
|
m_canvasIndex(InvalidCanvasIndex),
|
||||||
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
|
||||||
m_canvas(nullptr),
|
m_canvas(nullptr),
|
||||||
|
m_backgroundColor(Nz::Color(230, 230, 230, 255)),
|
||||||
m_cursor(Nz::SystemCursor_Default),
|
m_cursor(Nz::SystemCursor_Default),
|
||||||
m_contentSize(50.f, 50.f),
|
m_contentSize(50.f, 50.f),
|
||||||
m_widgetParent(nullptr),
|
m_widgetParent(nullptr),
|
||||||
|
|
@ -33,6 +33,7 @@ namespace Ndk
|
||||||
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
inline void BaseWidget::AddChild(std::unique_ptr<BaseWidget>&& widget)
|
||||||
{
|
{
|
||||||
widget->Show(m_visible);
|
widget->Show(m_visible);
|
||||||
|
widget->SetParent(this);
|
||||||
m_children.emplace_back(std::move(widget));
|
m_children.emplace_back(std::move(widget));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ namespace Ndk
|
||||||
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
inline CameraComponent::CameraComponent(const CameraComponent& camera) :
|
||||||
Component(camera),
|
Component(camera),
|
||||||
AbstractViewer(camera),
|
AbstractViewer(camera),
|
||||||
|
HandledObject(camera),
|
||||||
m_visibilityHash(camera.m_visibilityHash),
|
m_visibilityHash(camera.m_visibilityHash),
|
||||||
m_projectionType(camera.m_projectionType),
|
m_projectionType(camera.m_projectionType),
|
||||||
m_targetRegion(camera.m_targetRegion),
|
m_targetRegion(camera.m_targetRegion),
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace Ndk
|
||||||
|
|
||||||
//virtual ButtonWidget* Clone() const = 0;
|
//virtual ButtonWidget* Clone() const = 0;
|
||||||
|
|
||||||
void ResizeToContent();
|
void ResizeToContent() override;
|
||||||
|
|
||||||
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
inline void UpdateText(const Nz::AbstractTextDrawer& drawer);
|
||||||
|
|
||||||
|
|
@ -40,7 +40,6 @@ namespace Ndk
|
||||||
void Layout() override;
|
void Layout() override;
|
||||||
|
|
||||||
void OnMouseEnter() override;
|
void OnMouseEnter() override;
|
||||||
void OnMouseMoved(int x, int y, int deltaX, int deltaY) override;
|
|
||||||
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
void OnMouseButtonRelease(int x, int y, Nz::Mouse::Button button) override;
|
||||||
void OnMouseExit() override;
|
void OnMouseExit() override;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,11 +158,16 @@ namespace Ndk
|
||||||
}
|
}
|
||||||
m_systemBits.Clear();
|
m_systemBits.Clear();
|
||||||
|
|
||||||
UnregisterAllHandles();
|
// We properly destroy each component
|
||||||
|
for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i))
|
||||||
|
m_components[i]->SetEntity(nullptr);
|
||||||
|
|
||||||
m_components.clear();
|
m_components.clear();
|
||||||
m_componentBits.Reset();
|
m_componentBits.Reset();
|
||||||
|
|
||||||
|
// And then free every handle
|
||||||
|
UnregisterAllHandles();
|
||||||
|
|
||||||
m_valid = false;
|
m_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,23 +85,23 @@ namespace Ndk
|
||||||
|
|
||||||
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
entity.BindMethod("AddComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
{
|
{
|
||||||
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
return binding->adder(instance, handle);
|
return bindingComponent->adder(instance, handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
entity.BindMethod("GetComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
{
|
{
|
||||||
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
return binding->getter(instance, handle->GetComponent(binding->index));
|
return bindingComponent->getter(instance, handle->GetComponent(bindingComponent->index));
|
||||||
});
|
});
|
||||||
|
|
||||||
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
entity.BindMethod("RemoveComponent", [this] (Nz::LuaInstance& instance, EntityHandle& handle, std::size_t /*argumentCount*/) -> int
|
||||||
{
|
{
|
||||||
LuaBinding::ComponentBinding* binding = m_binding.QueryComponentIndex(instance);
|
LuaBinding::ComponentBinding* bindingComponent = m_binding.QueryComponentIndex(instance);
|
||||||
|
|
||||||
handle->RemoveComponent(binding->index);
|
handle->RemoveComponent(bindingComponent->index);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,9 +61,6 @@ namespace Ndk
|
||||||
m_gradientSprite->SetColor(Nz::Color(128, 128, 128));
|
m_gradientSprite->SetColor(Nz::Color(128, 128, 128));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonWidget::OnMouseMoved(int x, int y, int deltaX, int deltaY)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void ButtonWidget::OnMouseExit()
|
void ButtonWidget::OnMouseExit()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,27 +43,27 @@ namespace Nz
|
||||||
bool Create(SoundStream* soundStream);
|
bool Create(SoundStream* soundStream);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void EnableLooping(bool loop);
|
void EnableLooping(bool loop) override;
|
||||||
|
|
||||||
UInt32 GetDuration() const;
|
UInt32 GetDuration() const override;
|
||||||
AudioFormat GetFormat() const;
|
AudioFormat GetFormat() const;
|
||||||
UInt32 GetPlayingOffset() const;
|
UInt32 GetPlayingOffset() const override;
|
||||||
UInt64 GetSampleCount() const;
|
UInt64 GetSampleCount() const;
|
||||||
UInt32 GetSampleRate() const;
|
UInt32 GetSampleRate() const;
|
||||||
SoundStatus GetStatus() const;
|
SoundStatus GetStatus() const override;
|
||||||
|
|
||||||
bool IsLooping() const;
|
bool IsLooping() const override;
|
||||||
|
|
||||||
bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
|
bool OpenFromFile(const String& filePath, const MusicParams& params = MusicParams());
|
||||||
bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
|
bool OpenFromMemory(const void* data, std::size_t size, const MusicParams& params = MusicParams());
|
||||||
bool OpenFromStream(Stream& stream, const MusicParams& params = MusicParams());
|
bool OpenFromStream(Stream& stream, const MusicParams& params = MusicParams());
|
||||||
|
|
||||||
void Pause();
|
void Pause() override;
|
||||||
void Play();
|
void Play() override;
|
||||||
|
|
||||||
void SetPlayingOffset(UInt32 offset);
|
void SetPlayingOffset(UInt32 offset);
|
||||||
|
|
||||||
void Stop();
|
void Stop() override;
|
||||||
|
|
||||||
Music& operator=(const Music&) = delete;
|
Music& operator=(const Music&) = delete;
|
||||||
Music& operator=(Music&&) = delete; ///TODO
|
Music& operator=(Music&&) = delete; ///TODO
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,14 @@ namespace Nz
|
||||||
Sound(Sound&&) = default;
|
Sound(Sound&&) = default;
|
||||||
~Sound();
|
~Sound();
|
||||||
|
|
||||||
void EnableLooping(bool loop);
|
void EnableLooping(bool loop) override;
|
||||||
|
|
||||||
const SoundBuffer* GetBuffer() const;
|
const SoundBuffer* GetBuffer() const;
|
||||||
UInt32 GetDuration() const;
|
UInt32 GetDuration() const override;
|
||||||
UInt32 GetPlayingOffset() const;
|
UInt32 GetPlayingOffset() const override;
|
||||||
SoundStatus GetStatus() const;
|
SoundStatus GetStatus() const override;
|
||||||
|
|
||||||
bool IsLooping() const;
|
bool IsLooping() const override;
|
||||||
bool IsPlayable() const;
|
bool IsPlayable() const;
|
||||||
bool IsPlaying() const;
|
bool IsPlaying() const;
|
||||||
|
|
||||||
|
|
@ -38,13 +38,13 @@ namespace Nz
|
||||||
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
|
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams());
|
||||||
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
|
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams());
|
||||||
|
|
||||||
void Pause();
|
void Pause() override;
|
||||||
void Play();
|
void Play() override;
|
||||||
|
|
||||||
void SetBuffer(const SoundBuffer* buffer);
|
void SetBuffer(const SoundBuffer* buffer);
|
||||||
void SetPlayingOffset(UInt32 offset);
|
void SetPlayingOffset(UInt32 offset);
|
||||||
|
|
||||||
void Stop();
|
void Stop() override;
|
||||||
|
|
||||||
Sound& operator=(const Sound&) = delete; ///TODO?
|
Sound& operator=(const Sound&) = delete; ///TODO?
|
||||||
Sound& operator=(Sound&&) = default;
|
Sound& operator=(Sound&&) = default;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
||||||
ByteStream(const void* ptr, Nz::UInt64 size);
|
ByteStream(const void* ptr, Nz::UInt64 size);
|
||||||
ByteStream(const ByteStream&) = delete;
|
ByteStream(const ByteStream&) = delete;
|
||||||
inline ByteStream(ByteStream&& stream);
|
inline ByteStream(ByteStream&& stream);
|
||||||
~ByteStream();
|
virtual ~ByteStream();
|
||||||
|
|
||||||
inline Endianness GetDataEndianness() const;
|
inline Endianness GetDataEndianness() const;
|
||||||
inline Nz::UInt64 GetSize() const;
|
inline Nz::UInt64 GetSize() const;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
using BitField = typename std::conditional<(EnumAsFlags<E>::max > 32), UInt64, UInt32>::type;
|
using BitField = typename std::conditional<(EnumAsFlags<E>::max > 32), UInt64, UInt32>::type;
|
||||||
|
|
||||||
constexpr Flags(BitField value);
|
constexpr Flags(BitField value = 0);
|
||||||
constexpr Flags(E enumVal);
|
constexpr Flags(E enumVal);
|
||||||
|
|
||||||
explicit constexpr operator bool() const;
|
explicit constexpr operator bool() const;
|
||||||
|
|
@ -54,13 +54,13 @@ namespace Nz
|
||||||
private:
|
private:
|
||||||
BitField m_value;
|
BitField m_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs);
|
|
||||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs);
|
|
||||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs);
|
|
||||||
template<typename E> constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs);
|
||||||
|
template<typename E> constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs);
|
||||||
|
|
||||||
#include <Nazara/Core/Flags.inl>
|
#include <Nazara/Core/Flags.inl>
|
||||||
|
|
||||||
#endif // NAZARA_FLAGS_HPP
|
#endif // NAZARA_FLAGS_HPP
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
return 1U << static_cast<BitField>(enumValue);
|
return 1U << static_cast<BitField>(enumValue);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Override binary NOT operator on enum to turns into a Flags object.
|
* \brief Override binary NOT operator on enum to turns into a Flags object.
|
||||||
|
|
@ -220,9 +220,9 @@ namespace Nz
|
||||||
* Returns a Flags object with all state enabled except for the enum one.
|
* Returns a Flags object with all state enabled except for the enum one.
|
||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator~(E lhs)
|
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator~(E lhs)
|
||||||
{
|
{
|
||||||
return ~Flags<E>(lhs);
|
return ~Nz::Flags<E>(lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -235,9 +235,9 @@ namespace Nz
|
||||||
* Returns a Flags object with combined states from the two enumeration values.
|
* Returns a Flags object with combined states from the two enumeration values.
|
||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator|(E lhs, E rhs)
|
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator|(E lhs, E rhs)
|
||||||
{
|
{
|
||||||
return Flags<E>(lhs) | rhs;
|
return Nz::Flags<E>(lhs) | rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -251,9 +251,9 @@ namespace Nz
|
||||||
* In this case, only one flag will be enabled if both enumeration values are the same.
|
* In this case, only one flag will be enabled if both enumeration values are the same.
|
||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator&(E lhs, E rhs)
|
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator&(E lhs, E rhs)
|
||||||
{
|
{
|
||||||
return Flags<E>(lhs) & rhs;
|
return Nz::Flags<E>(lhs) & rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -267,10 +267,9 @@ namespace Nz
|
||||||
* In this case, two flags will be enabled if both the enumeration values are different.
|
* In this case, two flags will be enabled if both the enumeration values are different.
|
||||||
*/
|
*/
|
||||||
template<typename E>
|
template<typename E>
|
||||||
constexpr std::enable_if_t<EnumAsFlags<E>::value, Flags<E>> operator^(E lhs, E rhs)
|
constexpr std::enable_if_t<Nz::EnumAsFlags<E>::value, Nz::Flags<E>> operator^(E lhs, E rhs)
|
||||||
{
|
{
|
||||||
return Flags<E>(lhs) ^ rhs;
|
return Nz::Flags<E>(lhs) ^ rhs;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Core/DebugOff.hpp>
|
#include <Nazara/Core/DebugOff.hpp>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
FunctorWithoutArgs(F func);
|
FunctorWithoutArgs(F func);
|
||||||
|
|
||||||
void Run();
|
void Run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
F m_func;
|
F m_func;
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
FunctorWithArgs(F func, Args&&... args);
|
FunctorWithArgs(F func, Args&&... args);
|
||||||
|
|
||||||
void Run();
|
void Run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
F m_func;
|
F m_func;
|
||||||
|
|
@ -48,7 +48,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
MemberWithoutArgs(void (C::*func)(), C* object);
|
MemberWithoutArgs(void (C::*func)(), C* object);
|
||||||
|
|
||||||
void Run();
|
void Run() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void (C::*m_func)();
|
void (C::*m_func)();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -38,6 +38,9 @@ namespace Nz
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
T* PlacementNew(T* ptr, Args&&... args);
|
T* PlacementNew(T* ptr, Args&&... args);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void PlacementDestroy(T* ptr);
|
||||||
|
|
||||||
class StackAllocation
|
class StackAllocation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -64,6 +64,17 @@ namespace Nz
|
||||||
return new (ptr) T(std::forward<Args>(args)...);
|
return new (ptr) T(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Calls the object destructor explicitly
|
||||||
|
*
|
||||||
|
* \param ptr Pointer to a previously constructed pointer on raw memory
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
void PlacementDestroy(T* ptr)
|
||||||
|
{
|
||||||
|
ptr->~T();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \ingroup core
|
* \ingroup core
|
||||||
* \class Nz::StackAllocation
|
* \class Nz::StackAllocation
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,14 @@ namespace Nz
|
||||||
~MemoryPool() = default;
|
~MemoryPool() = default;
|
||||||
|
|
||||||
void* Allocate(unsigned int size);
|
void* Allocate(unsigned int size);
|
||||||
|
|
||||||
template<typename T> void Delete(T* ptr);
|
template<typename T> void Delete(T* ptr);
|
||||||
|
|
||||||
void Free(void* ptr);
|
void Free(void* ptr);
|
||||||
|
|
||||||
unsigned int GetBlockSize() const;
|
inline unsigned int GetBlockSize() const;
|
||||||
unsigned int GetFreeBlocks() const;
|
inline unsigned int GetFreeBlocks() const;
|
||||||
unsigned int GetSize() const;
|
inline unsigned int GetSize() const;
|
||||||
|
|
||||||
template<typename T, typename... Args> T* New(Args&&... args);
|
template<typename T, typename... Args> T* New(Args&&... args);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// This file is part of the "Nazara Engine - Core module"
|
// This file is part of the "Nazara Engine - Core module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#include <Nazara/Core/MemoryPool.hpp>
|
||||||
#include <Nazara/Core/MemoryHelper.hpp>
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
@ -95,9 +96,8 @@ namespace Nz
|
||||||
*
|
*
|
||||||
* \remark If ptr is null, nothing is done
|
* \remark If ptr is null, nothing is done
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void MemoryPool::Delete(T* ptr)
|
void MemoryPool::Delete(T* ptr)
|
||||||
{
|
{
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ namespace Nz
|
||||||
template<typename T> bool operator<(const T& lhs, const ObjectHandle<T>& rhs);
|
template<typename T> bool operator<(const T& lhs, const ObjectHandle<T>& rhs);
|
||||||
template<typename T> bool operator<(const ObjectHandle<T>& lhs, const T& rhs);
|
template<typename T> bool operator<(const ObjectHandle<T>& lhs, const T& rhs);
|
||||||
|
|
||||||
template<typename T> bool operator<=(const ObjectHandle<T>, const ObjectHandle<T>& rhs);
|
template<typename T> bool operator<=(const ObjectHandle<T>&, const ObjectHandle<T>& rhs);
|
||||||
template<typename T> bool operator<=(const T& lhs, const ObjectHandle<T>& rhs);
|
template<typename T> bool operator<=(const T& lhs, const ObjectHandle<T>& rhs);
|
||||||
template<typename T> bool operator<=(const ObjectHandle<T>& lhs, const T& rhs);
|
template<typename T> bool operator<=(const ObjectHandle<T>& lhs, const T& rhs);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ namespace Nz
|
||||||
ColorBackground(const ColorBackground&) = default;
|
ColorBackground(const ColorBackground&) = default;
|
||||||
ColorBackground(ColorBackground&&) = delete;
|
ColorBackground(ColorBackground&&) = delete;
|
||||||
|
|
||||||
void Draw(const AbstractViewer* viewer) const;
|
void Draw(const AbstractViewer* viewer) const override;
|
||||||
|
|
||||||
BackgroundType GetBackgroundType() const;
|
BackgroundType GetBackgroundType() const override;
|
||||||
Color GetColor() const;
|
Color GetColor() const;
|
||||||
|
|
||||||
void SetColor(const Color& color);
|
void SetColor(const Color& color);
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ namespace Nz
|
||||||
float GetBrightThreshold() const;
|
float GetBrightThreshold() const;
|
||||||
Texture* GetTexture(unsigned int i) const;
|
Texture* GetTexture(unsigned int i) const;
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
bool Resize(const Vector2ui& dimensions);
|
bool Resize(const Vector2ui& dimensions) override;
|
||||||
|
|
||||||
void SetBlurPassCount(unsigned int passCount);
|
void SetBlurPassCount(unsigned int passCount);
|
||||||
void SetBrightLuminance(float luminance);
|
void SetBrightLuminance(float luminance);
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ namespace Nz
|
||||||
DeferredDOFPass();
|
DeferredDOFPass();
|
||||||
virtual ~DeferredDOFPass();
|
virtual ~DeferredDOFPass();
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
bool Resize(const Vector2ui& dimensions);
|
bool Resize(const Vector2ui& dimensions) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderTexture m_dofRTT;
|
RenderTexture m_dofRTT;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
||||||
DeferredFXAAPass();
|
DeferredFXAAPass();
|
||||||
virtual ~DeferredFXAAPass();
|
virtual ~DeferredFXAAPass();
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderStates m_states;
|
RenderStates m_states;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
||||||
DeferredFinalPass();
|
DeferredFinalPass();
|
||||||
virtual ~DeferredFinalPass();
|
virtual ~DeferredFinalPass();
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderStates m_states;
|
RenderStates m_states;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Nz
|
||||||
DeferredFogPass();
|
DeferredFogPass();
|
||||||
virtual ~DeferredFogPass();
|
virtual ~DeferredFogPass();
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderStates m_states;
|
RenderStates m_states;
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ namespace Nz
|
||||||
DeferredForwardPass();
|
DeferredForwardPass();
|
||||||
virtual ~DeferredForwardPass();
|
virtual ~DeferredForwardPass();
|
||||||
|
|
||||||
void Initialize(DeferredRenderTechnique* technique);
|
void Initialize(DeferredRenderTechnique* technique) override;
|
||||||
bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int workTexture, unsigned int sceneTexture) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const ForwardRenderTechnique* m_forwardTechnique;
|
const ForwardRenderTechnique* m_forwardTechnique;
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ namespace Nz
|
||||||
DeferredGeometryPass();
|
DeferredGeometryPass();
|
||||||
virtual ~DeferredGeometryPass();
|
virtual ~DeferredGeometryPass();
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
bool Resize(const Vector2ui& dimensions);
|
bool Resize(const Vector2ui& dimensions) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct ShaderUniforms;
|
struct ShaderUniforms;
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
||||||
|
|
||||||
bool IsLightMeshesDrawingEnabled() const;
|
bool IsLightMeshesDrawingEnabled() const;
|
||||||
|
|
||||||
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const;
|
bool Process(const SceneData& sceneData, unsigned int firstWorkTexture, unsigned int secondWorkTexture) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LightUniforms m_directionalLightUniforms;
|
LightUniforms m_directionalLightUniforms;
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ namespace Nz
|
||||||
public:
|
public:
|
||||||
TextureBackground(TextureRef texture = TextureRef());
|
TextureBackground(TextureRef texture = TextureRef());
|
||||||
|
|
||||||
void Draw(const AbstractViewer* viewer) const;
|
void Draw(const AbstractViewer* viewer) const override;
|
||||||
|
|
||||||
BackgroundType GetBackgroundType() const;
|
BackgroundType GetBackgroundType() const override;
|
||||||
inline const TextureRef& GetTexture() const;
|
inline const TextureRef& GetTexture() const;
|
||||||
|
|
||||||
inline void SetTexture(TextureRef texture);
|
inline void SetTexture(TextureRef texture);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#ifndef NAZARA_ENUMS_NETWORK_HPP
|
#ifndef NAZARA_ENUMS_NETWORK_HPP
|
||||||
#define NAZARA_ENUMS_NETWORK_HPP
|
#define NAZARA_ENUMS_NETWORK_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
enum NetCode : UInt16
|
enum NetCode : UInt16
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef NAZARA_NETBUFFER_HPP
|
||||||
|
#define NAZARA_NETBUFFER_HPP
|
||||||
|
|
||||||
|
#include <Nazara/Prerequesites.hpp>
|
||||||
|
|
||||||
|
namespace Nz
|
||||||
|
{
|
||||||
|
struct NetBuffer
|
||||||
|
{
|
||||||
|
void* data;
|
||||||
|
std::size_t dataLength;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // NAZARA_NETBUFFER_HPP
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include <Nazara/Core/Stream.hpp>
|
#include <Nazara/Core/Stream.hpp>
|
||||||
#include <Nazara/Network/AbstractSocket.hpp>
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -49,6 +50,7 @@ namespace Nz
|
||||||
bool ReceivePacket(NetPacket* packet);
|
bool ReceivePacket(NetPacket* packet);
|
||||||
|
|
||||||
bool Send(const void* buffer, std::size_t size, std::size_t* sent);
|
bool Send(const void* buffer, std::size_t size, std::size_t* sent);
|
||||||
|
bool SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent);
|
||||||
bool SendPacket(const NetPacket& packet);
|
bool SendPacket(const NetPacket& packet);
|
||||||
|
|
||||||
bool SetCursorPos(UInt64 offset) override;
|
bool SetCursorPos(UInt64 offset) override;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Network/AbstractSocket.hpp>
|
#include <Nazara/Network/AbstractSocket.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
|
@ -42,6 +43,7 @@ namespace Nz
|
||||||
bool ReceivePacket(NetPacket* packet, IpAddress* from);
|
bool ReceivePacket(NetPacket* packet, IpAddress* from);
|
||||||
|
|
||||||
bool Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent);
|
bool Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent);
|
||||||
|
bool SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent);
|
||||||
bool SendPacket(const IpAddress& to, const NetPacket& packet);
|
bool SendPacket(const IpAddress& to, const NetPacket& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MixerBase();
|
MixerBase();
|
||||||
~MixerBase() = default;
|
virtual ~MixerBase() = default;
|
||||||
|
|
||||||
virtual float Get(float x, float y, float scale) const = 0;
|
virtual float Get(float x, float y, float scale) const = 0;
|
||||||
virtual float Get(float x, float y, float z, float scale) const = 0;
|
virtual float Get(float x, float y, float z, float scale) const = 0;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NoiseBase(unsigned int seed = 0);
|
NoiseBase(unsigned int seed = 0);
|
||||||
~NoiseBase() = default;
|
virtual ~NoiseBase() = default;
|
||||||
|
|
||||||
virtual float Get(float x, float y, float scale) const = 0;
|
virtual float Get(float x, float y, float scale) const = 0;
|
||||||
virtual float Get(float x, float y, float z, float scale) const = 0;
|
virtual float Get(float x, float y, float z, float scale) const = 0;
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Nz
|
||||||
static std::array<Vector4f, 2 * 2 * 2 * 2 * 2> s_gradients4;
|
static std::array<Vector4f, 2 * 2 * 2 * 2 * 2> s_gradients4;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::default_random_engine m_randomEngine;
|
std::mt19937 m_randomEngine;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,22 @@ namespace Nz
|
||||||
friend RigidBody2D;
|
friend RigidBody2D;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Collider2D() = default;
|
inline Collider2D();
|
||||||
Collider2D(const Collider2D&) = delete;
|
Collider2D(const Collider2D&) = delete;
|
||||||
Collider2D(Collider2D&&) = delete;
|
Collider2D(Collider2D&&) = delete;
|
||||||
virtual ~Collider2D();
|
virtual ~Collider2D();
|
||||||
|
|
||||||
virtual float ComputeInertialMatrix(float mass) const = 0;
|
virtual float ComputeInertialMatrix(float mass) const = 0;
|
||||||
|
|
||||||
|
inline unsigned int GetCollisionId() const;
|
||||||
|
|
||||||
virtual ColliderType2D GetType() const = 0;
|
virtual ColliderType2D GetType() const = 0;
|
||||||
|
|
||||||
|
inline bool IsTrigger() const;
|
||||||
|
|
||||||
|
inline void SetCollisionId(unsigned long typeId);
|
||||||
|
inline void SetTrigger(bool trigger);
|
||||||
|
|
||||||
Collider2D& operator=(const Collider2D&) = delete;
|
Collider2D& operator=(const Collider2D&) = delete;
|
||||||
Collider2D& operator=(Collider2D&&) = delete;
|
Collider2D& operator=(Collider2D&&) = delete;
|
||||||
|
|
||||||
|
|
@ -53,6 +60,12 @@ namespace Nz
|
||||||
protected:
|
protected:
|
||||||
virtual std::vector<cpShape*> CreateShapes(RigidBody2D* body) const = 0;
|
virtual std::vector<cpShape*> CreateShapes(RigidBody2D* body) const = 0;
|
||||||
|
|
||||||
|
bool m_trigger;
|
||||||
|
unsigned int m_collisionId;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual std::vector<cpShape*> GenerateShapes(RigidBody2D* body) const;
|
||||||
|
|
||||||
static Collider2DLibrary::LibraryMap s_library;
|
static Collider2DLibrary::LibraryMap s_library;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,32 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline Collider2D::Collider2D() :
|
||||||
|
m_collisionId(0),
|
||||||
|
m_trigger(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline unsigned int Collider2D::GetCollisionId() const
|
||||||
|
{
|
||||||
|
return m_collisionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool Collider2D::IsTrigger() const
|
||||||
|
{
|
||||||
|
return m_trigger;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Collider2D::SetCollisionId(unsigned long typeId)
|
||||||
|
{
|
||||||
|
m_collisionId = typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Collider2D::SetTrigger(bool trigger)
|
||||||
|
{
|
||||||
|
m_trigger = trigger;
|
||||||
|
}
|
||||||
|
|
||||||
inline const Rectf& BoxCollider2D::GetRect() const
|
inline const Rectf& BoxCollider2D::GetRect() const
|
||||||
{
|
{
|
||||||
return m_rect;
|
return m_rect;
|
||||||
|
|
@ -82,3 +108,4 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Physics2D/DebugOff.hpp>
|
#include <Nazara/Physics2D/DebugOff.hpp>
|
||||||
|
#include "Collider2D.hpp"
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,26 @@
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Math/Vector2.hpp>
|
#include <Nazara/Math/Vector2.hpp>
|
||||||
#include <Nazara/Physics2D/Config.hpp>
|
#include <Nazara/Physics2D/Config.hpp>
|
||||||
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
struct cpCollisionHandler;
|
||||||
struct cpSpace;
|
struct cpSpace;
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
class RigidBody2D;
|
||||||
|
|
||||||
class NAZARA_PHYSICS2D_API PhysWorld2D
|
class NAZARA_PHYSICS2D_API PhysWorld2D
|
||||||
{
|
{
|
||||||
|
using ContactEndCallback = void(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||||
|
using ContactPreSolveCallback = bool(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||||
|
using ContactPostSolveCallback = void(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||||
|
using ContactStartCallback = bool(*)(PhysWorld2D& world, RigidBody2D& bodyA, RigidBody2D& bodyB, void* userdata);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct Callback;
|
||||||
|
|
||||||
PhysWorld2D();
|
PhysWorld2D();
|
||||||
PhysWorld2D(const PhysWorld2D&) = delete;
|
PhysWorld2D(const PhysWorld2D&) = delete;
|
||||||
PhysWorld2D(PhysWorld2D&&) = delete; ///TODO
|
PhysWorld2D(PhysWorld2D&&) = delete; ///TODO
|
||||||
|
|
@ -27,8 +39,10 @@ namespace Nz
|
||||||
cpSpace* GetHandle() const;
|
cpSpace* GetHandle() const;
|
||||||
float GetStepSize() const;
|
float GetStepSize() const;
|
||||||
|
|
||||||
|
void RegisterCallbacks(unsigned int collisionId, const Callback& callbacks);
|
||||||
|
void RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks);
|
||||||
|
|
||||||
void SetGravity(const Vector2f& gravity);
|
void SetGravity(const Vector2f& gravity);
|
||||||
void SetSolverModel(unsigned int model);
|
|
||||||
void SetStepSize(float stepSize);
|
void SetStepSize(float stepSize);
|
||||||
|
|
||||||
void Step(float timestep);
|
void Step(float timestep);
|
||||||
|
|
@ -36,7 +50,19 @@ namespace Nz
|
||||||
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
|
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
|
||||||
PhysWorld2D& operator=(PhysWorld2D&&) = delete; ///TODO
|
PhysWorld2D& operator=(PhysWorld2D&&) = delete; ///TODO
|
||||||
|
|
||||||
|
struct Callback
|
||||||
|
{
|
||||||
|
ContactEndCallback endCallback;
|
||||||
|
ContactPreSolveCallback preSolveCallback;
|
||||||
|
ContactPostSolveCallback postSolveCallback;
|
||||||
|
ContactStartCallback startCallback;
|
||||||
|
void* userdata;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks);
|
||||||
|
|
||||||
|
std::unordered_map<cpCollisionHandler*, std::unique_ptr<Callback>> m_callbacks;
|
||||||
cpSpace* m_handle;
|
cpSpace* m_handle;
|
||||||
float m_stepSize;
|
float m_stepSize;
|
||||||
float m_timestepAccumulator;
|
float m_timestepAccumulator;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <Nazara/Prerequesites.hpp>
|
#include <Nazara/Prerequesites.hpp>
|
||||||
#include <Nazara/Core/Enums.hpp>
|
#include <Nazara/Core/Enums.hpp>
|
||||||
|
#include <Nazara/Core/Signal.hpp>
|
||||||
#include <Nazara/Math/Matrix4.hpp>
|
#include <Nazara/Math/Matrix4.hpp>
|
||||||
#include <Nazara/Math/Quaternion.hpp>
|
#include <Nazara/Math/Quaternion.hpp>
|
||||||
#include <Nazara/Math/Rect.hpp>
|
#include <Nazara/Math/Rect.hpp>
|
||||||
|
|
@ -43,6 +44,7 @@ namespace Nz
|
||||||
float GetMass() const;
|
float GetMass() const;
|
||||||
Vector2f GetPosition() const;
|
Vector2f GetPosition() const;
|
||||||
float GetRotation() const;
|
float GetRotation() const;
|
||||||
|
void* GetUserdata() const;
|
||||||
Vector2f GetVelocity() const;
|
Vector2f GetVelocity() const;
|
||||||
|
|
||||||
bool IsMoveable() const;
|
bool IsMoveable() const;
|
||||||
|
|
@ -54,11 +56,15 @@ namespace Nz
|
||||||
void SetMassCenter(const Vector2f& center);
|
void SetMassCenter(const Vector2f& center);
|
||||||
void SetPosition(const Vector2f& position);
|
void SetPosition(const Vector2f& position);
|
||||||
void SetRotation(float rotation);
|
void SetRotation(float rotation);
|
||||||
|
void SetUserdata(void* ud);
|
||||||
void SetVelocity(const Vector2f& velocity);
|
void SetVelocity(const Vector2f& velocity);
|
||||||
|
|
||||||
RigidBody2D& operator=(const RigidBody2D& object);
|
RigidBody2D& operator=(const RigidBody2D& object);
|
||||||
RigidBody2D& operator=(RigidBody2D&& object);
|
RigidBody2D& operator=(RigidBody2D&& object);
|
||||||
|
|
||||||
|
NazaraSignal(OnRigidBody2DMove, RigidBody2D* /*oldPointer*/, RigidBody2D* /*newPointer*/);
|
||||||
|
NazaraSignal(OnRigidBody2DRelease, RigidBody2D* /*rigidBody*/);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Create(float mass = 1.f, float moment = 1.f);
|
void Create(float mass = 1.f, float moment = 1.f);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
@ -66,6 +72,7 @@ namespace Nz
|
||||||
std::vector<cpShape*> m_shapes;
|
std::vector<cpShape*> m_shapes;
|
||||||
Collider2DRef m_geom;
|
Collider2DRef m_geom;
|
||||||
cpBody* m_handle;
|
cpBody* m_handle;
|
||||||
|
void* m_userData;
|
||||||
PhysWorld2D* m_world;
|
PhysWorld2D* m_world;
|
||||||
float m_gravityFactor;
|
float m_gravityFactor;
|
||||||
float m_mass;
|
float m_mass;
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@
|
||||||
|
|
||||||
// Nazara version macro
|
// Nazara version macro
|
||||||
#define NAZARA_VERSION_MAJOR 0
|
#define NAZARA_VERSION_MAJOR 0
|
||||||
#define NAZARA_VERSION_MINOR 2
|
#define NAZARA_VERSION_MINOR 3
|
||||||
#define NAZARA_VERSION_PATCH 1
|
#define NAZARA_VERSION_PATCH 0
|
||||||
|
|
||||||
#include <Nazara/Core/Config.hpp>
|
#include <Nazara/Core/Config.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
||||||
UberShaderInstancePreprocessor(const Shader* shader);
|
UberShaderInstancePreprocessor(const Shader* shader);
|
||||||
virtual ~UberShaderInstancePreprocessor();
|
virtual ~UberShaderInstancePreprocessor();
|
||||||
|
|
||||||
bool Activate() const;
|
bool Activate() const override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ namespace Nz
|
||||||
UberShaderPreprocessor() = default;
|
UberShaderPreprocessor() = default;
|
||||||
~UberShaderPreprocessor();
|
~UberShaderPreprocessor();
|
||||||
|
|
||||||
UberShaderInstance* Get(const ParameterList& parameters) const;
|
UberShaderInstance* Get(const ParameterList& parameters) const override;
|
||||||
|
|
||||||
void SetShader(ShaderStageType stage, const String& source, const String& shaderFlags, const String& requiredFlags = String());
|
void SetShader(ShaderStageType stage, const String& source, const String& shaderFlags, const String& requiredFlags = String());
|
||||||
bool SetShaderFromFile(ShaderStageType stage, const String& filePath, const String& shaderFlags, const String& requiredFlags = String());
|
bool SetShaderFromFile(ShaderStageType stage, const String& filePath, const String& shaderFlags, const String& requiredFlags = String());
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
inline EventHandler::EventHandler(const EventHandler&)
|
inline EventHandler::EventHandler(const EventHandler& other) :
|
||||||
|
HandledObject(other)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,18 +78,18 @@ namespace Nz
|
||||||
bool FlipVertically();
|
bool FlipVertically();
|
||||||
|
|
||||||
const UInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0) const;
|
const UInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0) const;
|
||||||
unsigned int GetDepth(UInt8 level = 0) const;
|
unsigned int GetDepth(UInt8 level = 0) const override;
|
||||||
PixelFormatType GetFormat() const;
|
PixelFormatType GetFormat() const override;
|
||||||
unsigned int GetHeight(UInt8 level = 0) const;
|
unsigned int GetHeight(UInt8 level = 0) const override;
|
||||||
UInt8 GetLevelCount() const;
|
UInt8 GetLevelCount() const override;
|
||||||
UInt8 GetMaxLevel() const;
|
UInt8 GetMaxLevel() const override;
|
||||||
std::size_t GetMemoryUsage() const;
|
std::size_t GetMemoryUsage() const override;
|
||||||
std::size_t GetMemoryUsage(UInt8 level) const;
|
std::size_t GetMemoryUsage(UInt8 level) const override;
|
||||||
Color GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
|
Color GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
|
||||||
UInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0);
|
UInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, UInt8 level = 0);
|
||||||
Vector3ui GetSize(UInt8 level = 0) const;
|
Vector3ui GetSize(UInt8 level = 0) const override;
|
||||||
ImageType GetType() const;
|
ImageType GetType() const override;
|
||||||
unsigned int GetWidth(UInt8 level = 0) const;
|
unsigned int GetWidth(UInt8 level = 0) const override;
|
||||||
|
|
||||||
bool HasAlpha() const;
|
bool HasAlpha() const;
|
||||||
|
|
||||||
|
|
@ -126,9 +126,9 @@ namespace Nz
|
||||||
void SetLevelCount(UInt8 levelCount);
|
void SetLevelCount(UInt8 levelCount);
|
||||||
bool SetPixelColor(const Color& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
|
bool SetPixelColor(const Color& color, unsigned int x, unsigned int y = 0, unsigned int z = 0);
|
||||||
|
|
||||||
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
bool Update(const UInt8* pixels, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
bool Update(const UInt8* pixels, const Boxui& box, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0);
|
bool Update(const UInt8* pixels, const Rectui& rect, unsigned int z = 0, unsigned int srcWidth = 0, unsigned int srcHeight = 0, UInt8 level = 0) override;
|
||||||
|
|
||||||
Image& operator=(const Image& image);
|
Image& operator=(const Image& image);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Nz
|
||||||
void SetName(const String& name);
|
void SetName(const String& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InvalidateNode();
|
void InvalidateNode() override;
|
||||||
void UpdateSkinningMatrix() const;
|
void UpdateSkinningMatrix() const;
|
||||||
|
|
||||||
Matrix4f m_inverseBindMatrix;
|
Matrix4f m_inverseBindMatrix;
|
||||||
|
|
|
||||||
|
|
@ -29,13 +29,13 @@ namespace Nz
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
const Boxf& GetAABB() const override;
|
const Boxf& GetAABB() const override;
|
||||||
AnimationType GetAnimationType() const final;
|
AnimationType GetAnimationType() const final override;
|
||||||
const IndexBuffer* GetIndexBuffer() const override;
|
const IndexBuffer* GetIndexBuffer() const override;
|
||||||
VertexBuffer* GetVertexBuffer();
|
VertexBuffer* GetVertexBuffer();
|
||||||
const VertexBuffer* GetVertexBuffer() const;
|
const VertexBuffer* GetVertexBuffer() const;
|
||||||
unsigned int GetVertexCount() const override;
|
unsigned int GetVertexCount() const override;
|
||||||
|
|
||||||
bool IsAnimated() const final;
|
bool IsAnimated() const final override;
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
void SetAABB(const Boxf& aabb);
|
void SetAABB(const Boxf& aabb);
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,13 @@ namespace Nz
|
||||||
bool GenerateAABB();
|
bool GenerateAABB();
|
||||||
|
|
||||||
const Boxf& GetAABB() const override;
|
const Boxf& GetAABB() const override;
|
||||||
AnimationType GetAnimationType() const final;
|
AnimationType GetAnimationType() const final override;
|
||||||
const IndexBuffer* GetIndexBuffer() const override;
|
const IndexBuffer* GetIndexBuffer() const override;
|
||||||
VertexBuffer* GetVertexBuffer();
|
VertexBuffer* GetVertexBuffer();
|
||||||
const VertexBuffer* GetVertexBuffer() const;
|
const VertexBuffer* GetVertexBuffer() const;
|
||||||
unsigned int GetVertexCount() const override;
|
unsigned int GetVertexCount() const override;
|
||||||
|
|
||||||
bool IsAnimated() const final;
|
bool IsAnimated() const final override;
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
void SetAABB(const Boxf& aabb);
|
void SetAABB(const Boxf& aabb);
|
||||||
|
|
|
||||||
|
|
@ -141,12 +141,12 @@ bool Load(Mesh* mesh, Stream& stream, const MeshParams& parameters)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
|
||||||
{
|
{
|
||||||
aiMesh* mesh = scene->mMeshes[i];
|
aiMesh* currentMesh = scene->mMeshes[i];
|
||||||
if (mesh->HasBones()) // Inline functions can be safely called
|
if (currentMesh->HasBones()) // Inline functions can be safely called
|
||||||
{
|
{
|
||||||
animatedMesh = true;
|
animatedMesh = true;
|
||||||
for (unsigned int j = 0; j < mesh->mNumBones; ++j)
|
for (unsigned int j = 0; j < currentMesh->mNumBones; ++j)
|
||||||
joints.insert(mesh->mBones[j]->mName.C_Str());
|
joints.insert(currentMesh->mBones[j]->mName.C_Str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -312,9 +312,9 @@ namespace Nz
|
||||||
while (!remainingRects.empty())
|
while (!remainingRects.empty())
|
||||||
{
|
{
|
||||||
// Stores the penalty score of the best rectangle placement - bigger=worse, smaller=better.
|
// Stores the penalty score of the best rectangle placement - bigger=worse, smaller=better.
|
||||||
bool bestFlipped;
|
bool bestFlipped = false;
|
||||||
std::size_t bestFreeRect;
|
std::size_t bestFreeRect = m_freeRectangles.size();
|
||||||
std::size_t bestRect;
|
std::size_t bestRect = std::numeric_limits<int>::min();
|
||||||
int bestScore = std::numeric_limits<int>::max();
|
int bestScore = std::numeric_limits<int>::max();
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_freeRectangles.size(); ++i)
|
for (std::size_t i = 0; i < m_freeRectangles.size(); ++i)
|
||||||
|
|
|
||||||
|
|
@ -413,9 +413,9 @@ namespace Nz
|
||||||
while (ptr != &s_list)
|
while (ptr != &s_list)
|
||||||
{
|
{
|
||||||
if (ptr->file)
|
if (ptr->file)
|
||||||
std::fprintf(log, "-0x%p -> %zu bytes allocated at %s:%u\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size, ptr->file, ptr->line);
|
std::fprintf(log, "-0x%s -> %zu bytes allocated at %s:%u\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size, ptr->file, ptr->line);
|
||||||
else
|
else
|
||||||
std::fprintf(log, "-0x%p -> %zu bytes allocated at unknown position\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size);
|
std::fprintf(log, "-0x%s -> %zu bytes allocated at unknown position\n", reinterpret_cast<UInt8*>(ptr) + sizeof(Block), ptr->size);
|
||||||
|
|
||||||
void* pointer = ptr;
|
void* pointer = ptr;
|
||||||
ptr = ptr->next;
|
ptr = ptr->next;
|
||||||
|
|
|
||||||
|
|
@ -5102,10 +5102,14 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
String String::FormatVA(const char* format, va_list args)
|
String String::FormatVA(const char* format, va_list args)
|
||||||
{
|
{
|
||||||
|
// Copy va_list to use it twice
|
||||||
|
va_list args2;
|
||||||
|
va_copy(args2, args);
|
||||||
|
|
||||||
std::size_t length = std::vsnprintf(nullptr, 0, format, args);
|
std::size_t length = std::vsnprintf(nullptr, 0, format, args);
|
||||||
|
|
||||||
auto str = std::make_shared<SharedString>(length);
|
auto str = std::make_shared<SharedString>(length);
|
||||||
std::vsnprintf(str->string.get(), length + 1, format, args);
|
std::vsnprintf(str->string.get(), length + 1, format, args2);
|
||||||
|
|
||||||
return String(std::move(str));
|
return String(std::move(str));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
||||||
* \param sceneData Data of the scene
|
* \param sceneData Data of the scene
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void DepthRenderTechnique::Clear(const SceneData& sceneData) const
|
void DepthRenderTechnique::Clear(const SceneData& /*sceneData*/) const
|
||||||
{
|
{
|
||||||
Renderer::Enable(RendererParameter_DepthBuffer, true);
|
Renderer::Enable(RendererParameter_DepthBuffer, true);
|
||||||
Renderer::Enable(RendererParameter_DepthWrite, true);
|
Renderer::Enable(RendererParameter_DepthWrite, true);
|
||||||
|
|
|
||||||
|
|
@ -990,7 +990,6 @@ namespace Nz
|
||||||
if (uniforms.locations.shadowMapping != -1)
|
if (uniforms.locations.shadowMapping != -1)
|
||||||
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
||||||
|
|
||||||
unsigned int textureUnit = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_ShadowCube_1 + index));
|
|
||||||
if (light.shadowMap)
|
if (light.shadowMap)
|
||||||
{
|
{
|
||||||
unsigned int textureUnitCube = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_ShadowCube_1 + index));
|
unsigned int textureUnitCube = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_ShadowCube_1 + index));
|
||||||
|
|
@ -1014,7 +1013,6 @@ namespace Nz
|
||||||
if (uniforms.locations.shadowMapping != -1)
|
if (uniforms.locations.shadowMapping != -1)
|
||||||
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr);
|
||||||
|
|
||||||
unsigned int textureUnit = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_Shadow2D_1 + index));
|
|
||||||
if (light.shadowMap)
|
if (light.shadowMap)
|
||||||
{
|
{
|
||||||
unsigned int textureUnit2D = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_Shadow2D_1 + index));
|
unsigned int textureUnit2D = Material::GetTextureUnit(static_cast<TextureMap>(TextureMap_Shadow2D_1 + index));
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) :
|
ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) :
|
||||||
m_declaration(std::move(declaration)),
|
|
||||||
m_processing(false),
|
|
||||||
m_maxParticleCount(maxParticleCount),
|
m_maxParticleCount(maxParticleCount),
|
||||||
m_particleCount(0)
|
m_particleCount(0),
|
||||||
|
m_declaration(std::move(declaration)),
|
||||||
|
m_processing(false)
|
||||||
{
|
{
|
||||||
// In case of error, the constructor can only throw an exception
|
// In case of error, the constructor can only throw an exception
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||||
|
|
@ -60,14 +60,14 @@ namespace Nz
|
||||||
|
|
||||||
ParticleGroup::ParticleGroup(const ParticleGroup& system) :
|
ParticleGroup::ParticleGroup(const ParticleGroup& system) :
|
||||||
Renderable(system),
|
Renderable(system),
|
||||||
|
m_maxParticleCount(system.m_maxParticleCount),
|
||||||
|
m_particleCount(system.m_particleCount),
|
||||||
|
m_particleSize(system.m_particleSize),
|
||||||
m_controllers(system.m_controllers),
|
m_controllers(system.m_controllers),
|
||||||
m_generators(system.m_generators),
|
m_generators(system.m_generators),
|
||||||
m_declaration(system.m_declaration),
|
m_declaration(system.m_declaration),
|
||||||
m_renderer(system.m_renderer),
|
m_renderer(system.m_renderer),
|
||||||
m_processing(false),
|
m_processing(false)
|
||||||
m_maxParticleCount(system.m_maxParticleCount),
|
|
||||||
m_particleCount(system.m_particleCount),
|
|
||||||
m_particleSize(system.m_particleSize)
|
|
||||||
{
|
{
|
||||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,8 +117,7 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
std::size_t AbstractSocket::QueryReceiveBufferSize() const
|
std::size_t AbstractSocket::QueryReceiveBufferSize() const
|
||||||
{
|
{
|
||||||
if (m_handle == SocketImpl::InvalidHandle)
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||||
return 0;
|
|
||||||
|
|
||||||
return SocketImpl::QueryReceiveBufferSize(m_handle);
|
return SocketImpl::QueryReceiveBufferSize(m_handle);
|
||||||
}
|
}
|
||||||
|
|
@ -129,8 +128,7 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
std::size_t AbstractSocket::QuerySendBufferSize() const
|
std::size_t AbstractSocket::QuerySendBufferSize() const
|
||||||
{
|
{
|
||||||
if (m_handle == SocketImpl::InvalidHandle)
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||||
return 0;
|
|
||||||
|
|
||||||
return SocketImpl::QuerySendBufferSize(m_handle);
|
return SocketImpl::QuerySendBufferSize(m_handle);
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +140,8 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
void AbstractSocket::SetReceiveBufferSize(std::size_t size)
|
void AbstractSocket::SetReceiveBufferSize(std::size_t size)
|
||||||
{
|
{
|
||||||
if (m_handle != SocketImpl::InvalidHandle)
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||||
|
|
||||||
SocketImpl::SetReceiveBufferSize(m_handle, size);
|
SocketImpl::SetReceiveBufferSize(m_handle, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +152,8 @@ namespace Nz
|
||||||
*/
|
*/
|
||||||
void AbstractSocket::SetSendBufferSize(std::size_t size)
|
void AbstractSocket::SetSendBufferSize(std::size_t size)
|
||||||
{
|
{
|
||||||
if (m_handle != SocketImpl::InvalidHandle)
|
NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first");
|
||||||
|
|
||||||
SocketImpl::SetSendBufferSize(m_handle, size);
|
SocketImpl::SetSendBufferSize(m_handle, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@
|
||||||
#include <Nazara/Network/Posix/SocketImpl.hpp>
|
#include <Nazara/Network/Posix/SocketImpl.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Log.hpp>
|
#include <Nazara/Core/Log.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
|
#include <Nazara/Network/Posix/IpAddressImpl.hpp>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
@ -463,6 +465,9 @@ namespace Nz
|
||||||
if (byteRead == SOCKET_ERROR)
|
if (byteRead == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
int errorCode = GetLastErrorCode();
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
|
|
@ -512,6 +517,9 @@ namespace Nz
|
||||||
if (byteRead == SOCKET_ERROR)
|
if (byteRead == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
int errorCode = GetLastErrorCode();
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
|
|
@ -560,12 +568,26 @@ namespace Nz
|
||||||
|
|
||||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
return false; //< Error
|
return false; //< Error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
*sent = byteSent;
|
*sent = byteSent;
|
||||||
|
|
@ -576,6 +598,60 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error)
|
||||||
|
{
|
||||||
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||||
|
|
||||||
|
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec));
|
||||||
|
struct iovec* sysBuffers = static_cast<struct iovec*>(memory.GetPtr());
|
||||||
|
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||||
|
{
|
||||||
|
sysBuffers[i].iov_base = buffers[i].data;
|
||||||
|
sysBuffers[i].iov_len = buffers[i].dataLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct msghdr msgHdr;
|
||||||
|
std::memset(&msgHdr, 0, sizeof(msgHdr));
|
||||||
|
|
||||||
|
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||||
|
msgHdr.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||||
|
msgHdr.msg_name = nameBuffer.data();
|
||||||
|
msgHdr.msg_iov = sysBuffers;
|
||||||
|
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||||
|
|
||||||
|
int byteSent = sendmsg(handle, &msgHdr, MSG_NOSIGNAL);
|
||||||
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = static_cast<int>(byteSent);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = SocketError_NoError;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
@ -586,12 +662,26 @@ namespace Nz
|
||||||
|
|
||||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = GetLastErrorCode();
|
||||||
|
if (errorCode == EAGAIN)
|
||||||
|
errorCode = EWOULDBLOCK;
|
||||||
|
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case EWOULDBLOCK:
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
*error = TranslateErrnoToResolveError(GetLastErrorCode());
|
*error = TranslateErrnoToResolveError(errorCode);
|
||||||
|
|
||||||
return false; //< Error
|
return false; //< Error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
*sent = byteSent;
|
*sent = byteSent;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <Nazara/Network/SocketHandle.hpp>
|
#include <Nazara/Network/SocketHandle.hpp>
|
||||||
#include <Nazara/Network/Enums.hpp>
|
#include <Nazara/Network/Enums.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
|
||||||
#define NAZARA_NETWORK_POLL_SUPPORT 1
|
#define NAZARA_NETWORK_POLL_SUPPORT 1
|
||||||
|
|
||||||
|
|
@ -64,6 +65,7 @@ namespace Nz
|
||||||
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
||||||
|
|
||||||
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
||||||
|
static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error);
|
||||||
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
||||||
|
|
||||||
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||||
|
|
|
||||||
|
|
@ -353,6 +353,45 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sends multiple buffers at once
|
||||||
|
* \return true If data were sent
|
||||||
|
*
|
||||||
|
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
|
||||||
|
* \param size Number of NetBuffer to send
|
||||||
|
* \param sent Optional argument to get the number of bytes sent
|
||||||
|
*/
|
||||||
|
bool TcpClient::SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
|
||||||
|
{
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
|
||||||
|
|
||||||
|
int byteSent;
|
||||||
|
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, m_peerAddress, &byteSent, &m_lastError))
|
||||||
|
{
|
||||||
|
switch (m_lastError)
|
||||||
|
{
|
||||||
|
case SocketError_ConnectionClosed:
|
||||||
|
case SocketError_ConnectionRefused:
|
||||||
|
UpdateState(SocketState_NotConnected);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
UpdateState(SocketState_Connected);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sends the packet available
|
* \brief Sends the packet available
|
||||||
* \return true If packet sent
|
* \return true If packet sent
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,12 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
/*!
|
||||||
|
* \ingroup network
|
||||||
|
* \class Nz::UdpSocket
|
||||||
|
* \brief Network class that represents a UDP socket, allowing for sending/receiving datagrams.
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Binds a specific IpAddress
|
* \brief Binds a specific IpAddress
|
||||||
* \return State of the socket
|
* \return State of the socket
|
||||||
|
|
@ -93,7 +99,18 @@ namespace Nz
|
||||||
|
|
||||||
int read;
|
int read;
|
||||||
if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast<int>(size), from, &read, &m_lastError))
|
if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast<int>(size), from, &read, &m_lastError))
|
||||||
|
{
|
||||||
|
switch (m_lastError)
|
||||||
|
{
|
||||||
|
case SocketError_ConnectionClosed:
|
||||||
|
m_lastError = SocketError_NoError;
|
||||||
|
read = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (received)
|
if (received)
|
||||||
*received = read;
|
*received = read;
|
||||||
|
|
@ -179,6 +196,31 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Sends multiple buffers as one datagram
|
||||||
|
* \return true If data were sent
|
||||||
|
*
|
||||||
|
* \param to Destination IpAddress (must match socket protocol)
|
||||||
|
* \param buffers A pointer to an array of NetBuffer containing buffers and size data
|
||||||
|
* \param size Number of NetBuffer to send
|
||||||
|
* \param sent Optional argument to get the number of bytes sent
|
||||||
|
*/
|
||||||
|
bool UdpSocket::SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent)
|
||||||
|
{
|
||||||
|
NazaraAssert(to.IsValid(), "Invalid ip address");
|
||||||
|
NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffer");
|
||||||
|
|
||||||
|
int byteSent;
|
||||||
|
if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, to, &byteSent, &m_lastError))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = byteSent;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Sends the packet available
|
* \brief Sends the packet available
|
||||||
* \return true If packet sent
|
* \return true If packet sent
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <Nazara/Network/Win32/SocketImpl.hpp>
|
#include <Nazara/Network/Win32/SocketImpl.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Core/Log.hpp>
|
#include <Nazara/Core/Log.hpp>
|
||||||
|
#include <Nazara/Core/MemoryHelper.hpp>
|
||||||
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
|
#include <Nazara/Network/Win32/IpAddressImpl.hpp>
|
||||||
|
|
||||||
#if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5
|
#if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5
|
||||||
|
|
@ -592,12 +593,25 @@ namespace Nz
|
||||||
|
|
||||||
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
int byteSent = send(handle, reinterpret_cast<const char*>(buffer), length, 0);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = WSAGetLastError();
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
return false; //< Error
|
return false; //< Error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
*sent = byteSent;
|
*sent = byteSent;
|
||||||
|
|
@ -608,6 +622,53 @@ namespace Nz
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error)
|
||||||
|
{
|
||||||
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||||
|
|
||||||
|
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||||
|
int bufferLength = IpAddressImpl::ToSockAddr(to, nameBuffer.data());
|
||||||
|
|
||||||
|
StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(WSABUF));
|
||||||
|
WSABUF* winBuffers = static_cast<WSABUF*>(memory.GetPtr());
|
||||||
|
for (std::size_t i = 0; i < bufferCount; ++i)
|
||||||
|
{
|
||||||
|
winBuffers[i].buf = static_cast<CHAR*>(buffers[i].data);
|
||||||
|
winBuffers[i].len = static_cast<ULONG>(buffers[i].dataLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD byteSent;
|
||||||
|
if (WSASendTo(handle, winBuffers, static_cast<DWORD>(bufferCount), &byteSent, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength, nullptr, nullptr) == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = WSAGetLastError();
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
|
return false; //< Error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent)
|
||||||
|
*sent = static_cast<int>(byteSent);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
*error = SocketError_NoError;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error)
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
@ -618,12 +679,25 @@ namespace Nz
|
||||||
|
|
||||||
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
int byteSent = sendto(handle, reinterpret_cast<const char*>(buffer), length, 0, reinterpret_cast<const sockaddr*>(nameBuffer.data()), bufferLength);
|
||||||
if (byteSent == SOCKET_ERROR)
|
if (byteSent == SOCKET_ERROR)
|
||||||
|
{
|
||||||
|
int errorCode = WSAGetLastError();
|
||||||
|
switch (errorCode)
|
||||||
|
{
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
{
|
||||||
|
byteSent = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
*error = TranslateWSAErrorToSocketError(WSAGetLastError());
|
*error = TranslateWSAErrorToSocketError(errorCode);
|
||||||
|
|
||||||
return false; //< Error
|
return false; //< Error
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sent)
|
if (sent)
|
||||||
*sent = byteSent;
|
*sent = byteSent;
|
||||||
|
|
@ -719,7 +793,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
DWORD option = size;
|
DWORD option = static_cast<DWORD>(size);
|
||||||
if (setsockopt(handle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
if (setsockopt(handle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
|
|
@ -738,7 +812,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||||
|
|
||||||
DWORD option = size;
|
DWORD option = static_cast<DWORD>(size);
|
||||||
if (setsockopt(handle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
if (setsockopt(handle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&option), sizeof(option)) == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (error)
|
if (error)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright (C) 2017 Jérôme Leclercq
|
// Copyright (C) 2017 Jérôme Leclercq
|
||||||
// This file is part of the "Nazara Engine - Network module"
|
// This file is part of the "Nazara Engine - Network module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
|
|
@ -7,9 +7,10 @@
|
||||||
#ifndef NAZARA_SOCKETIMPL_HPP
|
#ifndef NAZARA_SOCKETIMPL_HPP
|
||||||
#define NAZARA_SOCKETIMPL_HPP
|
#define NAZARA_SOCKETIMPL_HPP
|
||||||
|
|
||||||
#include <Nazara/Network/SocketHandle.hpp>
|
|
||||||
#include <Nazara/Network/Enums.hpp>
|
#include <Nazara/Network/Enums.hpp>
|
||||||
#include <Nazara/Network/IpAddress.hpp>
|
#include <Nazara/Network/IpAddress.hpp>
|
||||||
|
#include <Nazara/Network/NetBuffer.hpp>
|
||||||
|
#include <Nazara/Network/SocketHandle.hpp>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
|
||||||
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6
|
#define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6
|
||||||
|
|
@ -65,6 +66,7 @@ namespace Nz
|
||||||
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error);
|
||||||
|
|
||||||
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error);
|
||||||
|
static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error);
|
||||||
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error);
|
||||||
|
|
||||||
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,18 @@ namespace Nz
|
||||||
{
|
{
|
||||||
Collider2D::~Collider2D() = default;
|
Collider2D::~Collider2D() = default;
|
||||||
|
|
||||||
|
std::vector<cpShape*> Collider2D::GenerateShapes(RigidBody2D* body) const
|
||||||
|
{
|
||||||
|
std::vector<cpShape*> shapes = CreateShapes(body);
|
||||||
|
for (cpShape* shape : shapes)
|
||||||
|
{
|
||||||
|
cpShapeSetCollisionType(shape, m_collisionId);
|
||||||
|
cpShapeSetSensor(shape, (m_trigger) ? cpTrue : cpFalse);
|
||||||
|
}
|
||||||
|
|
||||||
|
return shapes;
|
||||||
|
}
|
||||||
|
|
||||||
/******************************** BoxCollider2D *********************************/
|
/******************************** BoxCollider2D *********************************/
|
||||||
|
|
||||||
BoxCollider2D::BoxCollider2D(const Vector2f& size, float radius) :
|
BoxCollider2D::BoxCollider2D(const Vector2f& size, float radius) :
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,16 @@ namespace Nz
|
||||||
return m_stepSize;
|
return m_stepSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysWorld2D::RegisterCallbacks(unsigned int collisionId, const Callback& callbacks)
|
||||||
|
{
|
||||||
|
InitCallbacks(cpSpaceAddWildcardHandler(m_handle, collisionId), callbacks);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysWorld2D::RegisterCallbacks(unsigned int collisionIdA, unsigned int collisionIdB, const Callback& callbacks)
|
||||||
|
{
|
||||||
|
InitCallbacks(cpSpaceAddCollisionHandler(m_handle, collisionIdA, collisionIdB), callbacks);
|
||||||
|
}
|
||||||
|
|
||||||
void PhysWorld2D::SetGravity(const Vector2f& gravity)
|
void PhysWorld2D::SetGravity(const Vector2f& gravity)
|
||||||
{
|
{
|
||||||
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
|
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
|
||||||
|
|
@ -57,4 +67,99 @@ namespace Nz
|
||||||
m_timestepAccumulator -= m_stepSize;
|
m_timestepAccumulator -= m_stepSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysWorld2D::InitCallbacks(cpCollisionHandler* handler, const Callback& callbacks)
|
||||||
|
{
|
||||||
|
auto it = m_callbacks.emplace(handler, std::make_unique<Callback>(callbacks)).first;
|
||||||
|
|
||||||
|
handler->userData = it->second.get();
|
||||||
|
|
||||||
|
if (callbacks.startCallback)
|
||||||
|
{
|
||||||
|
handler->beginFunc = [](cpArbiter* arb, cpSpace* space, void *data) -> cpBool
|
||||||
|
{
|
||||||
|
cpBody* firstBody;
|
||||||
|
cpBody* secondBody;
|
||||||
|
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||||
|
|
||||||
|
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||||
|
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||||
|
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||||
|
|
||||||
|
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||||
|
if (customCallbacks->startCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||||
|
{
|
||||||
|
cpBool retA = cpArbiterCallWildcardBeginA(arb, space);
|
||||||
|
cpBool retB = cpArbiterCallWildcardBeginB(arb, space);
|
||||||
|
return retA && retB;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return cpFalse;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callbacks.endCallback)
|
||||||
|
{
|
||||||
|
handler->separateFunc = [](cpArbiter* arb, cpSpace* space, void *data)
|
||||||
|
{
|
||||||
|
cpBody* firstBody;
|
||||||
|
cpBody* secondBody;
|
||||||
|
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||||
|
|
||||||
|
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||||
|
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||||
|
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||||
|
|
||||||
|
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||||
|
customCallbacks->endCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||||
|
|
||||||
|
cpArbiterCallWildcardSeparateA(arb, space);
|
||||||
|
cpArbiterCallWildcardSeparateB(arb, space);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callbacks.preSolveCallback)
|
||||||
|
{
|
||||||
|
handler->preSolveFunc = [](cpArbiter* arb, cpSpace* space, void *data) -> cpBool
|
||||||
|
{
|
||||||
|
cpBody* firstBody;
|
||||||
|
cpBody* secondBody;
|
||||||
|
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||||
|
|
||||||
|
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||||
|
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||||
|
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||||
|
|
||||||
|
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||||
|
if (customCallbacks->preSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata))
|
||||||
|
{
|
||||||
|
cpBool retA = cpArbiterCallWildcardPreSolveA(arb, space);
|
||||||
|
cpBool retB = cpArbiterCallWildcardPreSolveB(arb, space);
|
||||||
|
return retA && retB;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return cpFalse;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (callbacks.postSolveCallback)
|
||||||
|
{
|
||||||
|
handler->postSolveFunc = [](cpArbiter* arb, cpSpace* space, void *data)
|
||||||
|
{
|
||||||
|
cpBody* firstBody;
|
||||||
|
cpBody* secondBody;
|
||||||
|
cpArbiterGetBodies(arb, &firstBody, &secondBody);
|
||||||
|
|
||||||
|
PhysWorld2D* world = static_cast<PhysWorld2D*>(cpSpaceGetUserData(space));
|
||||||
|
RigidBody2D* firstRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(firstBody));
|
||||||
|
RigidBody2D* secondRigidBody = static_cast<RigidBody2D*>(cpBodyGetUserData(secondBody));
|
||||||
|
|
||||||
|
const Callback* customCallbacks = static_cast<const Callback*>(data);
|
||||||
|
customCallbacks->postSolveCallback(*world, *firstRigidBody, *secondRigidBody, customCallbacks->userdata);
|
||||||
|
|
||||||
|
cpArbiterCallWildcardPostSolveA(arb, space);
|
||||||
|
cpArbiterCallWildcardPostSolveB(arb, space);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ namespace Nz
|
||||||
|
|
||||||
RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom) :
|
RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom) :
|
||||||
m_geom(),
|
m_geom(),
|
||||||
|
m_userData(nullptr),
|
||||||
m_world(world),
|
m_world(world),
|
||||||
m_gravityFactor(1.f),
|
m_gravityFactor(1.f),
|
||||||
m_mass(1.f)
|
m_mass(1.f)
|
||||||
|
|
@ -34,6 +35,7 @@ namespace Nz
|
||||||
|
|
||||||
RigidBody2D::RigidBody2D(const RigidBody2D& object) :
|
RigidBody2D::RigidBody2D(const RigidBody2D& object) :
|
||||||
m_geom(object.m_geom),
|
m_geom(object.m_geom),
|
||||||
|
m_userData(object.m_userData),
|
||||||
m_world(object.m_world),
|
m_world(object.m_world),
|
||||||
m_gravityFactor(object.m_gravityFactor),
|
m_gravityFactor(object.m_gravityFactor),
|
||||||
m_mass(0.f)
|
m_mass(0.f)
|
||||||
|
|
@ -48,18 +50,27 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
|
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
|
||||||
|
OnRigidBody2DMove(std::move(object.OnRigidBody2DMove)),
|
||||||
|
OnRigidBody2DRelease(std::move(object.OnRigidBody2DRelease)),
|
||||||
m_shapes(std::move(object.m_shapes)),
|
m_shapes(std::move(object.m_shapes)),
|
||||||
m_geom(std::move(object.m_geom)),
|
m_geom(std::move(object.m_geom)),
|
||||||
|
m_userData(object.m_userData),
|
||||||
m_handle(object.m_handle),
|
m_handle(object.m_handle),
|
||||||
m_world(object.m_world),
|
m_world(object.m_world),
|
||||||
m_gravityFactor(object.m_gravityFactor),
|
m_gravityFactor(object.m_gravityFactor),
|
||||||
m_mass(object.m_mass)
|
m_mass(object.m_mass)
|
||||||
{
|
{
|
||||||
|
cpBodySetUserData(m_handle, this);
|
||||||
|
|
||||||
object.m_handle = nullptr;
|
object.m_handle = nullptr;
|
||||||
|
|
||||||
|
OnRigidBody2DMove(&object, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
RigidBody2D::~RigidBody2D()
|
RigidBody2D::~RigidBody2D()
|
||||||
{
|
{
|
||||||
|
OnRigidBody2DRelease(this);
|
||||||
|
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,6 +155,11 @@ namespace Nz
|
||||||
return static_cast<float>(cpBodyGetAngle(m_handle));
|
return static_cast<float>(cpBodyGetAngle(m_handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* RigidBody2D::GetUserdata() const
|
||||||
|
{
|
||||||
|
return m_userData;
|
||||||
|
}
|
||||||
|
|
||||||
Vector2f RigidBody2D::GetVelocity() const
|
Vector2f RigidBody2D::GetVelocity() const
|
||||||
{
|
{
|
||||||
cpVect vel = cpBodyGetVelocity(m_handle);
|
cpVect vel = cpBodyGetVelocity(m_handle);
|
||||||
|
|
@ -190,7 +206,7 @@ namespace Nz
|
||||||
else
|
else
|
||||||
m_geom = NullCollider2D::New();
|
m_geom = NullCollider2D::New();
|
||||||
|
|
||||||
m_shapes = m_geom->CreateShapes(this);
|
m_shapes = m_geom->GenerateShapes(this);
|
||||||
|
|
||||||
cpSpace* space = m_world->GetHandle();
|
cpSpace* space = m_world->GetHandle();
|
||||||
for (cpShape* shape : m_shapes)
|
for (cpShape* shape : m_shapes)
|
||||||
|
|
@ -242,6 +258,11 @@ namespace Nz
|
||||||
cpBodySetAngle(m_handle, rotation);
|
cpBodySetAngle(m_handle, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RigidBody2D::SetUserdata(void* ud)
|
||||||
|
{
|
||||||
|
m_userData = ud;
|
||||||
|
}
|
||||||
|
|
||||||
void RigidBody2D::SetVelocity(const Vector2f& velocity)
|
void RigidBody2D::SetVelocity(const Vector2f& velocity)
|
||||||
{
|
{
|
||||||
cpBodySetVelocity(m_handle, cpv(velocity.x, velocity.y));
|
cpBodySetVelocity(m_handle, cpv(velocity.x, velocity.y));
|
||||||
|
|
@ -257,15 +278,23 @@ namespace Nz
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
|
OnRigidBody2DMove = std::move(object.OnRigidBody2DMove);
|
||||||
|
OnRigidBody2DRelease = std::move(object.OnRigidBody2DRelease);
|
||||||
|
|
||||||
m_handle = object.m_handle;
|
m_handle = object.m_handle;
|
||||||
m_geom = std::move(object.m_geom);
|
m_geom = std::move(object.m_geom);
|
||||||
m_gravityFactor = object.m_gravityFactor;
|
m_gravityFactor = object.m_gravityFactor;
|
||||||
m_mass = object.m_mass;
|
m_mass = object.m_mass;
|
||||||
m_shapes = std::move(object.m_shapes);
|
m_shapes = std::move(object.m_shapes);
|
||||||
|
m_userData = object.m_userData;
|
||||||
m_world = object.m_world;
|
m_world = object.m_world;
|
||||||
|
|
||||||
|
cpBodySetUserData(m_handle, this);
|
||||||
|
|
||||||
object.m_handle = nullptr;
|
object.m_handle = nullptr;
|
||||||
|
|
||||||
|
OnRigidBody2DMove(&object, this);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,28 +8,28 @@
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
// Major version of OpenGL, initialised by OpenGL::Initialize()
|
||||||
UInt8 ContextParameters::defaultMajorVersion;
|
UInt8 ContextParameters::defaultMajorVersion;
|
||||||
|
|
||||||
// Version majeure d'OpenGL, initialisé par OpenGL::Initialize()
|
// Minor version of OpenGL, initialised by OpenGL::Initialize()
|
||||||
UInt8 ContextParameters::defaultMinorVersion;
|
UInt8 ContextParameters::defaultMinorVersion;
|
||||||
|
|
||||||
// Contexte de partage par défaut, initialisé par OpenGL::Initialize()
|
// Context of default sharing, initialised by OpenGL::Initialize()
|
||||||
const Context* ContextParameters::defaultShareContext = nullptr;
|
const Context* ContextParameters::defaultShareContext = nullptr;
|
||||||
|
|
||||||
// Si possible, garder la compatibilité avec les fonctionnalités dépréciées
|
// If it's possible, keep the compatibility with deprecated functionalities
|
||||||
bool ContextParameters::defaultCompatibilityProfile = false;
|
bool ContextParameters::defaultCompatibilityProfile = false;
|
||||||
|
|
||||||
// Mode debug d'OpenGL par défaut
|
// Default debug mode of OpenGL
|
||||||
#if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG)
|
#if NAZARA_RENDERER_OPENGL_DEBUG || defined(NAZARA_DEBUG)
|
||||||
bool ContextParameters::defaultDebugMode = true;
|
bool ContextParameters::defaultDebugMode = true;
|
||||||
#else
|
#else
|
||||||
bool ContextParameters::defaultDebugMode = false;
|
bool ContextParameters::defaultDebugMode = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Active le double-buffering sur les contextes
|
// Enables double-buffering on contexts Active le double-buffering sur les contextes
|
||||||
bool ContextParameters::defaultDoubleBuffered = false;
|
bool ContextParameters::defaultDoubleBuffered = false;
|
||||||
|
|
||||||
// Active le partage des ressources entre contextes (Via le defaultShareContext)
|
// Enables ressource sharing on contexts (via defaultShareContext)
|
||||||
bool ContextParameters::defaultShared = true;
|
bool ContextParameters::defaultShared = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Nz
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int attachmentIndex[AttachmentPoint_Max+1] =
|
unsigned int s_attachmentIndex[AttachmentPoint_Max+1] =
|
||||||
{
|
{
|
||||||
3, // AttachmentPoint_Color
|
3, // AttachmentPoint_Color
|
||||||
0, // AttachmentPoint_Depth
|
0, // AttachmentPoint_Depth
|
||||||
|
|
@ -117,7 +117,7 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int depthStencilIndex = attachmentIndex[AttachmentPoint_DepthStencil];
|
unsigned int depthStencilIndex = s_attachmentIndex[AttachmentPoint_DepthStencil];
|
||||||
if (m_impl->attachments.size() > depthStencilIndex && m_impl->attachments[depthStencilIndex].isUsed)
|
if (m_impl->attachments.size() > depthStencilIndex && m_impl->attachments[depthStencilIndex].isUsed)
|
||||||
{
|
{
|
||||||
if (attachmentPoint == AttachmentPoint_Depth)
|
if (attachmentPoint == AttachmentPoint_Depth)
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Nz
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index;
|
||||||
if (attachIndex >= m_impl->attachments.size())
|
if (attachIndex >= m_impl->attachments.size())
|
||||||
m_impl->attachments.resize(attachIndex+1);
|
m_impl->attachments.resize(attachIndex+1);
|
||||||
|
|
||||||
|
|
@ -223,7 +223,7 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int depthStencilIndex = attachmentIndex[AttachmentPoint_DepthStencil];
|
unsigned int depthStencilIndex = s_attachmentIndex[AttachmentPoint_DepthStencil];
|
||||||
if (attachmentPoint == AttachmentPoint_Depth && m_impl->attachments.size() > depthStencilIndex &&
|
if (attachmentPoint == AttachmentPoint_Depth && m_impl->attachments.size() > depthStencilIndex &&
|
||||||
m_impl->attachments[depthStencilIndex].isUsed)
|
m_impl->attachments[depthStencilIndex].isUsed)
|
||||||
{
|
{
|
||||||
|
|
@ -288,7 +288,7 @@ namespace Nz
|
||||||
|
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index;
|
||||||
if (attachIndex >= m_impl->attachments.size())
|
if (attachIndex >= m_impl->attachments.size())
|
||||||
m_impl->attachments.resize(attachIndex+1);
|
m_impl->attachments.resize(attachIndex+1);
|
||||||
|
|
||||||
|
|
@ -394,7 +394,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
unsigned int attachIndex = attachmentIndex[attachmentPoint] + index;
|
unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index;
|
||||||
if (attachIndex >= m_impl->attachments.size())
|
if (attachIndex >= m_impl->attachments.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -575,7 +575,7 @@ namespace Nz
|
||||||
#if NAZARA_RENDERER_SAFE
|
#if NAZARA_RENDERER_SAFE
|
||||||
for (unsigned int i = 0; i < targetCount; ++i)
|
for (unsigned int i = 0; i < targetCount; ++i)
|
||||||
{
|
{
|
||||||
unsigned int index = attachmentIndex[AttachmentPoint_Color] + targets[i];
|
unsigned int index = s_attachmentIndex[AttachmentPoint_Color] + targets[i];
|
||||||
if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed)
|
if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed)
|
||||||
{
|
{
|
||||||
NazaraError("Target " + String::Number(targets[i]) + " not attached");
|
NazaraError("Target " + String::Number(targets[i]) + " not attached");
|
||||||
|
|
@ -598,7 +598,7 @@ namespace Nz
|
||||||
#if NAZARA_RENDERER_SAFE
|
#if NAZARA_RENDERER_SAFE
|
||||||
for (UInt8 target : targets)
|
for (UInt8 target : targets)
|
||||||
{
|
{
|
||||||
unsigned int index = attachmentIndex[AttachmentPoint_Color] + target;
|
unsigned int index = s_attachmentIndex[AttachmentPoint_Color] + target;
|
||||||
if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed)
|
if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed)
|
||||||
{
|
{
|
||||||
NazaraError("Target " + String::Number(target) + " not attached");
|
NazaraError("Target " + String::Number(target) + " not attached");
|
||||||
|
|
@ -752,7 +752,7 @@ namespace Nz
|
||||||
|
|
||||||
for (UInt8 index : m_impl->colorTargets)
|
for (UInt8 index : m_impl->colorTargets)
|
||||||
{
|
{
|
||||||
Attachment& attachment = m_impl->attachments[attachmentIndex[AttachmentPoint_Color] + index];
|
Attachment& attachment = m_impl->attachments[s_attachmentIndex[AttachmentPoint_Color] + index];
|
||||||
if (!attachment.isBuffer)
|
if (!attachment.isBuffer)
|
||||||
attachment.texture->InvalidateMipmaps();
|
attachment.texture->InvalidateMipmaps();
|
||||||
}
|
}
|
||||||
|
|
@ -833,7 +833,7 @@ namespace Nz
|
||||||
m_impl->colorTargets.clear();
|
m_impl->colorTargets.clear();
|
||||||
|
|
||||||
unsigned int colorIndex = 0;
|
unsigned int colorIndex = 0;
|
||||||
for (unsigned int index = attachmentIndex[AttachmentPoint_Color]; index < m_impl->attachments.size(); ++index)
|
for (unsigned int index = s_attachmentIndex[AttachmentPoint_Color]; index < m_impl->attachments.size(); ++index)
|
||||||
m_impl->colorTargets.push_back(colorIndex++);
|
m_impl->colorTargets.push_back(colorIndex++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ namespace Nz
|
||||||
|
|
||||||
if (s_useAnisotropicFilter)
|
if (s_useAnisotropicFilter)
|
||||||
{
|
{
|
||||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||||
{
|
{
|
||||||
if (((pair.first >> 5) & 0xFF) == 0)
|
if (((pair.first >> 5) & 0xFF) == 0)
|
||||||
glSamplerParameterf(pair.second, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<float>(anisotropyLevel));
|
glSamplerParameterf(pair.second, GL_TEXTURE_MAX_ANISOTROPY_EXT, static_cast<float>(anisotropyLevel));
|
||||||
|
|
@ -149,7 +149,7 @@ namespace Nz
|
||||||
|
|
||||||
s_defaultFilterMode = filterMode;
|
s_defaultFilterMode = filterMode;
|
||||||
|
|
||||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||||
{
|
{
|
||||||
if (((pair.first >> 1) & 0x3) == SamplerFilter_Default)
|
if (((pair.first >> 1) & 0x3) == SamplerFilter_Default)
|
||||||
{
|
{
|
||||||
|
|
@ -204,7 +204,7 @@ namespace Nz
|
||||||
s_defaultWrapMode = wrapMode;
|
s_defaultWrapMode = wrapMode;
|
||||||
|
|
||||||
GLenum wrapEnum = OpenGL::SamplerWrapMode[wrapMode];
|
GLenum wrapEnum = OpenGL::SamplerWrapMode[wrapMode];
|
||||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||||
{
|
{
|
||||||
if (((pair.first >> 3) & 0x3) == SamplerWrap_Default)
|
if (((pair.first >> 3) & 0x3) == SamplerWrap_Default)
|
||||||
{
|
{
|
||||||
|
|
@ -380,7 +380,7 @@ namespace Nz
|
||||||
if (!s_samplers.empty())
|
if (!s_samplers.empty())
|
||||||
{
|
{
|
||||||
Context::EnsureContext();
|
Context::EnsureContext();
|
||||||
for (const std::pair<UInt32, GLuint>& pair : s_samplers)
|
for (const std::pair<const UInt32, GLuint>& pair : s_samplers)
|
||||||
OpenGL::DeleteSampler(pair.second);
|
OpenGL::DeleteSampler(pair.second);
|
||||||
|
|
||||||
s_samplers.clear();
|
s_samplers.clear();
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ namespace Nz
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled);
|
ErrorFlags errFlags2(ErrorFlag_ThrowExceptionDisabled);
|
||||||
|
|
||||||
NazaraError("Shader code failed to compile (" + stage.GetLog() + ")\n" + code.ToString());
|
NazaraError("Shader code failed to compile (" + stage.GetLog() + ")\n" + code.ToString());
|
||||||
throw;
|
throw;
|
||||||
|
|
|
||||||
|
|
@ -835,7 +835,6 @@ namespace Nz
|
||||||
if (!PixelFormat::IsCompressed(m_sharedImage->format))
|
if (!PixelFormat::IsCompressed(m_sharedImage->format))
|
||||||
{
|
{
|
||||||
const PixelFormatInfo& info = PixelFormat::GetInfo(m_sharedImage->format);
|
const PixelFormatInfo& info = PixelFormat::GetInfo(m_sharedImage->format);
|
||||||
const UInt8* pixel = GetConstPixels();
|
|
||||||
|
|
||||||
Bitset<> workingBitset;
|
Bitset<> workingBitset;
|
||||||
std::size_t pixelCount = m_sharedImage->width * m_sharedImage->height * ((m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth);
|
std::size_t pixelCount = m_sharedImage->width * m_sharedImage->height * ((m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth);
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,10 @@ namespace Nz
|
||||||
IndexBuffer::IndexBuffer(const IndexBuffer& indexBuffer) :
|
IndexBuffer::IndexBuffer(const IndexBuffer& indexBuffer) :
|
||||||
RefCounted(),
|
RefCounted(),
|
||||||
m_buffer(indexBuffer.m_buffer),
|
m_buffer(indexBuffer.m_buffer),
|
||||||
m_largeIndices(indexBuffer.m_largeIndices),
|
|
||||||
m_endOffset(indexBuffer.m_endOffset),
|
m_endOffset(indexBuffer.m_endOffset),
|
||||||
m_indexCount(indexBuffer.m_indexCount),
|
m_indexCount(indexBuffer.m_indexCount),
|
||||||
m_startOffset(indexBuffer.m_startOffset)
|
m_startOffset(indexBuffer.m_startOffset),
|
||||||
|
m_largeIndices(indexBuffer.m_largeIndices)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -365,12 +365,14 @@ namespace Nz
|
||||||
{
|
{
|
||||||
case '\n':
|
case '\n':
|
||||||
{
|
{
|
||||||
|
// Extend the line bounding rect to the last glyph it contains, thus extending upon all glyphs of the line
|
||||||
if (!m_glyphs.empty())
|
if (!m_glyphs.empty())
|
||||||
{
|
{
|
||||||
Glyph& glyph = m_glyphs.back();
|
Glyph& lastGlyph = m_glyphs.back();
|
||||||
m_lines.back().bounds.ExtendTo(glyph.bounds);
|
m_lines.back().bounds.ExtendTo(lastGlyph.bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset cursor
|
||||||
advance = 0;
|
advance = 0;
|
||||||
m_drawPos.x = 0;
|
m_drawPos.x = 0;
|
||||||
m_drawPos.y += sizeInfo.lineHeight;
|
m_drawPos.y += sizeInfo.lineHeight;
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ namespace Nz
|
||||||
VertexBuffer::VertexBuffer(const VertexBuffer& vertexBuffer) :
|
VertexBuffer::VertexBuffer(const VertexBuffer& vertexBuffer) :
|
||||||
RefCounted(),
|
RefCounted(),
|
||||||
m_buffer(vertexBuffer.m_buffer),
|
m_buffer(vertexBuffer.m_buffer),
|
||||||
m_vertexDeclaration(vertexBuffer.m_vertexDeclaration),
|
|
||||||
m_endOffset(vertexBuffer.m_endOffset),
|
m_endOffset(vertexBuffer.m_endOffset),
|
||||||
m_startOffset(vertexBuffer.m_startOffset),
|
m_startOffset(vertexBuffer.m_startOffset),
|
||||||
m_vertexCount(vertexBuffer.m_vertexCount)
|
m_vertexCount(vertexBuffer.m_vertexCount),
|
||||||
|
m_vertexDeclaration(vertexBuffer.m_vertexDeclaration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,19 @@ namespace Nz
|
||||||
ScopedXCBConnection connection;
|
ScopedXCBConnection connection;
|
||||||
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
|
xcb_screen_t* screen = X11::XCBDefaultScreen(connection);
|
||||||
|
|
||||||
|
const char* cursorName = s_systemCursorIds[cursor];
|
||||||
|
if (cursorName)
|
||||||
|
{
|
||||||
if (xcb_cursor_context_new(connection, screen, &m_cursorContext) >= 0)
|
if (xcb_cursor_context_new(connection, screen, &m_cursorContext) >= 0)
|
||||||
m_cursor = xcb_cursor_load_cursor(m_cursorContext, s_systemCursorIds[cursor]);
|
m_cursor = xcb_cursor_load_cursor(m_cursorContext, cursorName);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NazaraError("Failed to create cursor context");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_cursor = s_hiddenCursor;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -231,6 +242,7 @@ namespace Nz
|
||||||
xcb_cursor_t CursorImpl::s_hiddenCursor = 0;
|
xcb_cursor_t CursorImpl::s_hiddenCursor = 0;
|
||||||
|
|
||||||
std::array<const char*, SystemCursor_Max + 1> CursorImpl::s_systemCursorIds =
|
std::array<const char*, SystemCursor_Max + 1> CursorImpl::s_systemCursorIds =
|
||||||
|
{
|
||||||
{
|
{
|
||||||
// http://gnome-look.org/content/preview.php?preview=1&id=128170&file1=128170-1.png&file2=&file3=&name=Dummy+X11+cursors&PHPSESSID=6
|
// http://gnome-look.org/content/preview.php?preview=1&id=128170&file1=128170-1.png&file2=&file3=&name=Dummy+X11+cursors&PHPSESSID=6
|
||||||
"crosshair", // SystemCursor_Crosshair
|
"crosshair", // SystemCursor_Crosshair
|
||||||
|
|
@ -251,6 +263,7 @@ namespace Nz
|
||||||
"left_side", // SystemCursor_ResizeW
|
"left_side", // SystemCursor_ResizeW
|
||||||
"xterm", // SystemCursor_Text
|
"xterm", // SystemCursor_Text
|
||||||
"watch" // SystemCursor_Wait
|
"watch" // SystemCursor_Wait
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete");
|
static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete");
|
||||||
|
|
|
||||||
|
|
@ -229,14 +229,14 @@ namespace Nz
|
||||||
return screen_nbr;
|
return screen_nbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr)
|
xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screenIndex)
|
||||||
{
|
{
|
||||||
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
|
NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server");
|
||||||
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
|
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection));
|
||||||
|
|
||||||
for (; iter.rem; --screen_nbr, xcb_screen_next (&iter))
|
for (; iter.rem; --screenIndex, xcb_screen_next (&iter))
|
||||||
{
|
{
|
||||||
if (screen_nbr == 0)
|
if (screenIndex == 0)
|
||||||
return iter.data;
|
return iter.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ namespace Nz
|
||||||
m_style(0),
|
m_style(0),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_smoothScrolling(false),
|
m_smoothScrolling(false),
|
||||||
m_scrolling(0),
|
|
||||||
m_mousePos(0, 0),
|
m_mousePos(0, 0),
|
||||||
m_keyRepeat(true)
|
m_keyRepeat(true)
|
||||||
{
|
{
|
||||||
|
|
@ -1134,7 +1133,6 @@ namespace Nz
|
||||||
|
|
||||||
// if (std::isprint(codePoint)) Is not working ? + handle combining ?
|
// if (std::isprint(codePoint)) Is not working ? + handle combining ?
|
||||||
{
|
{
|
||||||
WindowEvent event;
|
|
||||||
event.type = Nz::WindowEventType_TextEntered;
|
event.type = Nz::WindowEventType_TextEntered;
|
||||||
event.text.character = codePoint;
|
event.text.character = codePoint;
|
||||||
event.text.repeated = false;
|
event.text.repeated = false;
|
||||||
|
|
@ -1396,7 +1394,7 @@ namespace Nz
|
||||||
hints.functions |= MWM_FUNC_CLOSE;
|
hints.functions |= MWM_FUNC_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedXCB<xcb_generic_error_t> error(xcb_request_check(
|
ScopedXCB<xcb_generic_error_t> propertyError(xcb_request_check(
|
||||||
connection,
|
connection,
|
||||||
xcb_change_property_checked(
|
xcb_change_property_checked(
|
||||||
connection,
|
connection,
|
||||||
|
|
@ -1410,7 +1408,7 @@ namespace Nz
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
if (error)
|
if (propertyError)
|
||||||
NazaraError("xcb_change_property failed, could not set window hints");
|
NazaraError("xcb_change_property failed, could not set window hints");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,6 @@ namespace Nz
|
||||||
bool m_ownsWindow;
|
bool m_ownsWindow;
|
||||||
bool m_smoothScrolling;
|
bool m_smoothScrolling;
|
||||||
bool m_threadActive;
|
bool m_threadActive;
|
||||||
short m_scrolling;
|
|
||||||
Vector2i m_mousePos;
|
Vector2i m_mousePos;
|
||||||
bool m_keyRepeat;
|
bool m_keyRepeat;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,9 @@ void EventState::AddEvent(const Nz::WindowEvent& event)
|
||||||
m_events.push_back(Nz::String::Number(m_count) + " - " + ToString(event));
|
m_events.push_back(Nz::String::Number(m_count) + " - " + ToString(event));
|
||||||
|
|
||||||
Nz::String content;
|
Nz::String content;
|
||||||
for (auto&& event : m_events)
|
for (auto&& currentEvent : m_events)
|
||||||
{
|
{
|
||||||
content += event + "\n";
|
content += currentEvent + "\n";
|
||||||
}
|
}
|
||||||
content += "\nM for Menu";
|
content += "\nM for Menu";
|
||||||
m_text.SetContent(content, 36);
|
m_text.SetContent(content, 36);
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void KeyState::DrawMenu()
|
||||||
m_text.SetContent("Clic on a key, this text should change !\nN for alternating event\nM for Menu");
|
m_text.SetContent("Clic on a key, this text should change !\nN for alternating event\nM for Menu");
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyState::ManageInput(KeyStatus isKeyPressed, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm)
|
void KeyState::ManageInput(KeyStatus /*isKeyPressed*/, const Nz::WindowEvent::KeyEvent& key, Ndk::StateMachine& fsm)
|
||||||
{
|
{
|
||||||
if (key.code == Nz::Keyboard::Key::M && key.shift)
|
if (key.code == Nz::Keyboard::Key::M && key.shift)
|
||||||
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
|
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ void MouseClickState::DrawMenu()
|
||||||
m_text.SetContent("Click in the windows, this text should change !\nM for Menu");
|
m_text.SetContent("Click in the windows, this text should change !\nM for Menu");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& fsm)
|
void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& /*fsm*/)
|
||||||
{
|
{
|
||||||
Nz::String content;
|
Nz::String content;
|
||||||
if (mouseStatus == MouseStatus::Pressed)
|
if (mouseStatus == MouseStatus::Pressed)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ Text::Text(StateContext& stateContext) :
|
||||||
m_context(stateContext)
|
m_context(stateContext)
|
||||||
{
|
{
|
||||||
m_text = m_context.world.CreateEntity();
|
m_text = m_context.world.CreateEntity();
|
||||||
Ndk::NodeComponent& nodeComponent = m_text->AddComponent<Ndk::NodeComponent>();
|
m_text->AddComponent<Ndk::NodeComponent>();
|
||||||
Ndk::GraphicsComponent& graphicsComponent = m_text->AddComponent<Ndk::GraphicsComponent>();
|
Ndk::GraphicsComponent& graphicsComponent = m_text->AddComponent<Ndk::GraphicsComponent>();
|
||||||
|
|
||||||
m_textSprite = Nz::TextSprite::New();
|
m_textSprite = Nz::TextSprite::New();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ SCENARIO("EntityList", "[NDK][ENTITYLIST]")
|
||||||
THEN("These results are expected")
|
THEN("These results are expected")
|
||||||
{
|
{
|
||||||
REQUIRE(entityList.Has(entity->GetId()));
|
REQUIRE(entityList.Has(entity->GetId()));
|
||||||
const Ndk::EntityHandle& entity = world.CreateEntity();
|
const Ndk::EntityHandle& newEntity = world.CreateEntity();
|
||||||
REQUIRE(!entityList.Has(entity->GetId()));
|
REQUIRE(!entityList.Has(newEntity->GetId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue