diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index 815d0dc1b..a49a8f6aa 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -158,6 +158,9 @@ namespace Ndk UnregisterAllHandles(); + m_components.clear(); + m_componentBits.Reset(); + m_valid = false; } diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..39ff8f7a8 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +version: '{branch}-rev{build}' + +shallow_clone: true + +os: + - Visual Studio 2015 + +environment: + matrix: + - TOOLSET: vs2015 + +install: + - cd build && "./premake5.exe" %TOOLSET% && cd .. + +configuration: + - DebugDynamic + - ReleaseDynamic + +build: + project: build/$(TOOLSET)/NazaraEngine.sln \ No newline at end of file diff --git a/include/Nazara/Core/MemoryHelper.hpp b/include/Nazara/Core/MemoryHelper.hpp index e2f295622..ff81ea083 100644 --- a/include/Nazara/Core/MemoryHelper.hpp +++ b/include/Nazara/Core/MemoryHelper.hpp @@ -7,6 +7,27 @@ #ifndef NAZARA_MEMORYHELPER_HPP #define NAZARA_MEMORYHELPER_HPP +#if defined(NAZARA_COMPILER_MSVC) + +#include + +#define NAZARA_ALLOCA(size) _alloca(size) +#define NAZARA_ALLOCA_SUPPORT + +#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL) +#include + +#define NAZARA_ALLOCA(size) alloca(size) +#define NAZARA_ALLOCA_SUPPORT + +#endif + +#ifdef NAZARA_ALLOCA_SUPPORT + #define NazaraStackAllocation(size) Nz::StackAllocation(NAZARA_ALLOCA(size)) +#else + #define NazaraStackAllocation(size) Nz::StackAllocation(Nz::OperatorNew(size)) +#endif + #include namespace Nz @@ -16,6 +37,20 @@ namespace Nz template T* PlacementNew(T* ptr, Args&&... args); + + class StackAllocation + { + public: + explicit StackAllocation(void* stackMemory); + ~StackAllocation(); + + void* GetPtr(); + + operator void*(); + + private: + void* m_ptr; + }; } #include diff --git a/include/Nazara/Core/MemoryHelper.inl b/include/Nazara/Core/MemoryHelper.inl index 23a745a44..d3fe43155 100644 --- a/include/Nazara/Core/MemoryHelper.inl +++ b/include/Nazara/Core/MemoryHelper.inl @@ -9,6 +9,7 @@ #define NAZARA_DEBUG_NEWREDEFINITION_DISABLE_REDEFINITION #endif +#include #include #include #include @@ -62,6 +63,51 @@ namespace Nz { return new (ptr) T(std::forward(args)...); } + + /*! + * \ingroup core + * \class Nz::StackAllocation + * \brief Core class that represents a stack allocation + */ + + + /*! + * \brief Constructs a StackAllocation object with a pointer to a memory allocated with NAZARA_ALLOCA or OperatorNew is alloca is not supported + * + * \param ptr Pointer to raw memory + */ + inline StackAllocation::StackAllocation(void* stackMemory) : + m_ptr(stackMemory) + { + } + + /*! + * \brief Destructs the object and release memory if necessary + */ + inline StackAllocation::~StackAllocation() + { + #ifndef NAZARA_ALLOCA_SUPPORT + OperatorDelete(m_ptr); + #endif + } + + /*! + * \brief Access the internal pointer + * \return internal memory pointer + */ + inline void* StackAllocation::GetPtr() + { + return m_ptr; + } + + /*! + * \brief Access the internal pointer + * \return internal memory pointer + */ + inline StackAllocation::operator void*() + { + return m_ptr; + } } #include diff --git a/include/Nazara/Graphics/Sprite.hpp b/include/Nazara/Graphics/Sprite.hpp index 3aa261d89..13bcc289b 100644 --- a/include/Nazara/Graphics/Sprite.hpp +++ b/include/Nazara/Graphics/Sprite.hpp @@ -37,12 +37,14 @@ namespace Nz void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override; inline const Color& GetColor() const; + inline const Color& GetCornerColor(RectCorner corner) const; inline const MaterialRef& GetMaterial() const; inline const Vector3f& GetOrigin() const; inline const Vector2f& GetSize() const; inline const Rectf& GetTextureCoords() const; inline void SetColor(const Color& color); + inline void SetCornerColor(RectCorner corner, const Color& color); inline void SetDefaultMaterial(); inline void SetMaterial(MaterialRef material, bool resizeSprite = true); inline void SetOrigin(const Vector3f& origin); @@ -65,6 +67,7 @@ namespace Nz static bool Initialize(); static void Uninitialize(); + std::array m_cornerColor; Color m_color; MaterialRef m_material; Rectf m_textureCoords; diff --git a/include/Nazara/Graphics/Sprite.inl b/include/Nazara/Graphics/Sprite.inl index 410b42478..35885a94a 100644 --- a/include/Nazara/Graphics/Sprite.inl +++ b/include/Nazara/Graphics/Sprite.inl @@ -18,6 +18,9 @@ namespace Nz m_size(64.f, 64.f), m_origin(Nz::Vector3f::Zero()) { + for (Color& color : m_cornerColor) + color = Color::White; + SetDefaultMaterial(); } @@ -62,14 +65,35 @@ namespace Nz /*! * \brief Gets the color of the sprite + * + * This is the global color of the sprite, independent from corner colors + * * \return Current color + * + * \see GetCornerColor + * \see SetColor */ - inline const Color& Sprite::GetColor() const { return m_color; } + /*! + * \brief Gets the color setup on a corner of the sprite + * + * \return Current color + * + * \param corner Corner of the sprite to query + * + * \see SetCornerColor + */ + inline const Color& Sprite::GetCornerColor(RectCorner corner) const + { + NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); + + return m_cornerColor[corner]; + } + /*! * \brief Gets the material of the sprite * \return Current material @@ -86,7 +110,7 @@ namespace Nz * * \see SetOrigin */ - inline const Vector3f & Sprite::GetOrigin() const + inline const Vector3f& Sprite::GetOrigin() const { return m_origin; } @@ -105,18 +129,21 @@ namespace Nz * \brief Gets the texture coordinates of the sprite * \return Current texture coordinates */ - inline const Rectf& Sprite::GetTextureCoords() const { return m_textureCoords; } /*! - * \brief Sets the color of the billboard + * \brief Sets the global color of the sprite * - * \param color Color for the billboard + * This is independent from the corner color of the sprite + * + * \param color Color for the sprite + * + * \see GetColor + * \see SetCornerColor */ - inline void Sprite::SetColor(const Color& color) { m_color = color; @@ -124,6 +151,26 @@ namespace Nz InvalidateVertices(); } + /*! + * \brief Sets a color for a corner of the sprite + * + * This is independent from the sprite global color, which gets multiplied by the corner color when rendering the sprite. + * + * \param corner Corner of the sprite to set + * \param color Color for the sprite + * + * \see GetCornerColor + * \see SetColor + */ + inline void Sprite::SetCornerColor(RectCorner corner, const Color& color) + { + NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); + + m_cornerColor[corner] = color; + + InvalidateVertices(); + } + /*! * \brief Sets the default material of the sprite (just default material) */ diff --git a/src/Nazara/Graphics/Sprite.cpp b/src/Nazara/Graphics/Sprite.cpp index 8b950bf2a..1b14ab6de 100644 --- a/src/Nazara/Graphics/Sprite.cpp +++ b/src/Nazara/Graphics/Sprite.cpp @@ -49,7 +49,6 @@ namespace Nz * * \param instanceData Data of the instance */ - void Sprite::UpdateData(InstanceData* instanceData) const { instanceData->data.resize(4 * sizeof(VertexStruct_XYZ_Color_UV)); @@ -61,19 +60,19 @@ namespace Nz Vector3f origin(m_origin.x, -m_origin.y, m_origin.z); - *colorPtr++ = m_color; + *colorPtr++ = m_color * m_cornerColor[RectCorner_LeftTop]; *posPtr++ = instanceData->transformMatrix.Transform(Vector3f(-origin)); *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftTop); - *colorPtr++ = m_color; + *colorPtr++ = m_color * m_cornerColor[RectCorner_RightTop]; *posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() - origin); *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightTop); - *colorPtr++ = m_color; + *colorPtr++ = m_color * m_cornerColor[RectCorner_LeftBottom]; *posPtr++ = instanceData->transformMatrix.Transform(m_size.y*Vector3f::Down() - origin); *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_LeftBottom); - *colorPtr++ = m_color; + *colorPtr++ = m_color * m_cornerColor[RectCorner_RightBottom]; *posPtr++ = instanceData->transformMatrix.Transform(m_size.x*Vector3f::Right() + m_size.y*Vector3f::Down() - origin); *texCoordPtr++ = m_textureCoords.GetCorner(RectCorner_RightBottom); }