From 614c1556effbaebe4e4ab1325033d54b974e26aa Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 7 Sep 2016 13:04:58 +0200 Subject: [PATCH 1/8] Graphics/Sprite: Allows to set sprite corner color Former-commit-id: 66ca16acbb25da23a8a85b77d1bd4c4ca412e82f [formerly d4f67e512d1e7edd31c049045cc9069a8926d794] [formerly 7b9ca802280f114492d4e1aaa068c241802f3c25 [formerly 068f737047936c99b79057674bd453a54fe44960]] Former-commit-id: e92d6bb1bd4668a2f94f0311f887f38c00544277 [formerly da0e5d605a0b9197a767e48d8a5dbd94dd83872b] Former-commit-id: a4ce87c4974513dbe3890ac3f316ed14b74919eb --- include/Nazara/Graphics/Sprite.hpp | 3 ++ include/Nazara/Graphics/Sprite.inl | 59 +++++++++++++++++++++++++++--- src/Nazara/Graphics/Sprite.cpp | 9 ++--- 3 files changed, 60 insertions(+), 11 deletions(-) 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..bc27bf67c 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(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(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); } From 4c68121a8b80d82e4a6cd12a104578bb83c763b6 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 9 Sep 2016 23:17:36 +0200 Subject: [PATCH 2/8] Sdk/Entity: Fix component cleaning on destruction Former-commit-id: b074d35399413268e81643e49d75a669277e0668 [formerly da1d3881dcdcdf935530351875acb02069e10abb] [formerly 72680c76ca01af0b2b86012654f44cbc9fd62932 [formerly 0c56ea07f4641c92d983bb635b01ae25349024ed]] Former-commit-id: 08ce8b3cd0e089fabc182b20ad9e6a779adebde3 [formerly 59f13e00812fe2ae6000673f494e6dc2f8d29d06] Former-commit-id: 56471a336c769d464f54473e3f154da39b1d18df --- SDK/src/NDK/Entity.cpp | 3 +++ 1 file changed, 3 insertions(+) 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; } From 4565cd6089d89bea98afe86d9ae30ae9ee8e57f7 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 12 Sep 2016 14:29:12 +0200 Subject: [PATCH 3/8] Test AppVeyor Former-commit-id: 44e37f739c27026173c1928e65aa6228fbb1f784 [formerly 5629c7c880d437e2dbed1efc6c36d5bfee27c053] [formerly 577e36b635666e883ff56ce74260f3f93e330c4c [formerly df96d563b970bf18240f200b1408ca372aa60ecc]] Former-commit-id: 38787f2bfb98aea4199c56474e9e0621e30d3782 [formerly 2238b00a69dac9327c6d16cc5e1aacc4bb17e1d4] Former-commit-id: 53ee458a235a8089ac92d162ed89ab24bce76dba --- appveyor.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..756c1e14b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,23 @@ +shallow_clone: true + +os: + - Visual Studio 2015 + +environment: + matrix: + - TOOLSET: vs2010 + - TOOLSET: vs2013 + - TOOLSET: vs2015 + +install: + - cd build && "./premake5.exe" %TOOLSET% && cd .. + +configuration: + - Debug + - Release + +build: + project: NazaraEngine/build/$(TOOLSET)/NazaraEngine.sln + +after_test: + - NazaraEngine\tests\Tests.exe From 64f8f63a9e958b99ce588ce32d64825a5936a506 Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 12 Sep 2016 14:30:45 +0200 Subject: [PATCH 4/8] Try to fix build Former-commit-id: 18e448bb4fca705b15850ed3159dfe33ccbb7c5a [formerly a916f662377a1a5eb40ab9f8cd3dbb957c5e5cae] [formerly 5add32ceef4978ce39d3f73e8668af0886ee08fb [formerly b7d0e9b3773e7a50e46159f2918cad43d9902445]] Former-commit-id: c297e8dfb352ce5babe432c36b7f0bbe56a919b1 [formerly 4814adb5fa186d5f8e90c81384230b1413f99c4e] Former-commit-id: 14e280fdce38240c854cb507ebd8d9850d484a8f --- appveyor.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 756c1e14b..498270c14 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,8 +5,6 @@ os: environment: matrix: - - TOOLSET: vs2010 - - TOOLSET: vs2013 - TOOLSET: vs2015 install: @@ -17,7 +15,4 @@ configuration: - Release build: - project: NazaraEngine/build/$(TOOLSET)/NazaraEngine.sln - -after_test: - - NazaraEngine\tests\Tests.exe + project: build/$(TOOLSET)/NazaraEngine.sln \ No newline at end of file From 5c681d11ce9b175ee97fc07991ce076c1975c8cc Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 12 Sep 2016 14:35:58 +0200 Subject: [PATCH 5/8] Damnit Former-commit-id: aad22f6569e9d096a8af02034f7dd2ecc3bbe4eb [formerly a9fa210a8442a12064c5e768b3e03beb8ab1c10b] [formerly ca732eb0b0b42f7fce822e8ab0aae44e22c1e651 [formerly 11a53e81205d74e5b9cbb9fdbe9c242c5c7736c1]] Former-commit-id: 291082c51c9d9dc4b361c9ed5196b13c8edfc061 [formerly 8620c5eaff7c69742c98c94f52a028c721240a1e] Former-commit-id: 3f488710c3ab59acd5381dc7877f3ae968847703 --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 498270c14..a705a4c8c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,5 @@ +version: '{branch}-rev{build}' +configuration: DebugDynamic, ReleaseDynamic shallow_clone: true os: From b64e65bbb3608f0bed92448bfda28915697a3dac Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 12 Sep 2016 14:36:34 +0200 Subject: [PATCH 6/8] I'm a moron Former-commit-id: bba4e4d5d99fa7d4f8542ddf4f371578a6fbfde6 [formerly 38666d69d3f61b68f53452f9e08afd5d4545e247] [formerly 5d5ca1fbc58f8f55e49df32e840347807b307df1 [formerly 1268ae19bb805894bc4ea98bca9f3aaee23a884f]] Former-commit-id: db42585f88b7aac2d9d946aa19168a051180875f [formerly 437851904db490748a7b7b946e4823177e782a6a] Former-commit-id: ec09684d4e6f2d0ce7664f73f1c552e5dbde9278 --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a705a4c8c..39ff8f7a8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ version: '{branch}-rev{build}' -configuration: DebugDynamic, ReleaseDynamic + shallow_clone: true os: @@ -13,8 +13,8 @@ install: - cd build && "./premake5.exe" %TOOLSET% && cd .. configuration: - - Debug - - Release + - DebugDynamic + - ReleaseDynamic build: project: build/$(TOOLSET)/NazaraEngine.sln \ No newline at end of file From c6767a0fbd49a078241c9fc985da286b4613f7db Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 13 Sep 2016 19:51:46 +0200 Subject: [PATCH 7/8] Graphics/Sprite: Fix warning in Sprite.inl Former-commit-id: a3410af1934a462a4fe197700379ed64bbd6c76b [formerly 318faba08dbf1a4216a1fa5626be22c3b4973e92] [formerly 3f938befd96d748b6261b20301b8cb4afde287a5 [formerly 2dcf1a7bd016c4c81d9ecf08056ea202ac0c47ef]] Former-commit-id: 742fa64e7f5954bca97ac7dd7ae11697fe47eea9 [formerly bd0de568838add11360d8dbd27af5c7ae0ddb1bb] Former-commit-id: 35ca6c90855d4b3956e0cea3f7c265a286b121b5 --- include/Nazara/Graphics/Sprite.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Graphics/Sprite.inl b/include/Nazara/Graphics/Sprite.inl index bc27bf67c..35885a94a 100644 --- a/include/Nazara/Graphics/Sprite.inl +++ b/include/Nazara/Graphics/Sprite.inl @@ -89,7 +89,7 @@ namespace Nz */ inline const Color& Sprite::GetCornerColor(RectCorner corner) const { - NazaraAssert(corner < m_cornerColor.size(), "Invalid corner"); + NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); return m_cornerColor[corner]; } @@ -164,7 +164,7 @@ namespace Nz */ inline void Sprite::SetCornerColor(RectCorner corner, const Color& color) { - NazaraAssert(corner < m_cornerColor.size(), "Invalid corner"); + NazaraAssert(static_cast(corner) < m_cornerColor.size(), "Invalid corner"); m_cornerColor[corner] = color; From da03c9fc3b55652c681cbd5e3bf536dc1e070909 Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 15 Sep 2016 00:46:59 +0200 Subject: [PATCH 8/8] Core/MemoryHelper: Add portable stack allocation Former-commit-id: f1c38cd50d028ab9c3b7868178d457a3bde30158 [formerly 09f688b51171507d684db1a6e865f65202295ca3] [formerly da2fe586a5e71591f7869a24b0178d3b3554de67 [formerly 99d022f578a47294795819cddc85c1c41a08a943]] Former-commit-id: d92a834a6538f1a8d74bbaebb898d9abf48135ca [formerly 6db2b81497d7252583dda33c4a1bf03a77c8ba43] Former-commit-id: fa05a671eed209de23671b8d396217f0851011d1 --- include/Nazara/Core/MemoryHelper.hpp | 35 +++++++++++++++++++++ include/Nazara/Core/MemoryHelper.inl | 46 ++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) 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