From 656290d089c74994e6b47e088b9f5957dd6f3797 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 19 May 2015 14:31:04 +0200 Subject: [PATCH 1/2] Core/Bitset: Add comparison operators Former-commit-id: 7ca04f36fa001f322182c5e9457127f05432d373 --- build/scripts/features/core.lua | 4 +-- include/Nazara/Core/Bitset.hpp | 12 +++++++++ include/Nazara/Core/Bitset.inl | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/build/scripts/features/core.lua b/build/scripts/features/core.lua index 120917eab..9ce9919ff 100644 --- a/build/scripts/features/core.lua +++ b/build/scripts/features/core.lua @@ -42,8 +42,8 @@ return { { Title = "Stockage et gestion de champs de bits dynamiques (Bitset)", Description = "Classe permettant le stockage et la manipulation optimisée d'un nombre élevé et dynamique de bits (=booléens, opérations de comptage, recherche de bits activés, opérations entre champs de bits, etc.)", - Note = "Il manque des opérateurs de comparaison et une spécialisation de la fonction de hachage", - Progress = 90 + Note = "Il manque une spécialisation de la fonction de hachage", + Progress = 95 } } }, diff --git a/include/Nazara/Core/Bitset.hpp b/include/Nazara/Core/Bitset.hpp index bc1df0e27..389455ba0 100644 --- a/include/Nazara/Core/Bitset.hpp +++ b/include/Nazara/Core/Bitset.hpp @@ -110,6 +110,18 @@ bool operator==(const NzBitset& lhs, const NzBitset bool operator!=(const NzBitset& lhs, const NzBitset& rhs); +template +bool operator<(const NzBitset& lhs, const NzBitset& rhs); + +template +bool operator<=(const NzBitset& lhs, const NzBitset& rhs); + +template +bool operator>(const NzBitset& lhs, const NzBitset& rhs); + +template +bool operator>=(const NzBitset& lhs, const NzBitset& rhs); + template NzBitset operator&(const NzBitset& lhs, const NzBitset& rhs); diff --git a/include/Nazara/Core/Bitset.inl b/include/Nazara/Core/Bitset.inl index a02c16550..c0d365eea 100644 --- a/include/Nazara/Core/Bitset.inl +++ b/include/Nazara/Core/Bitset.inl @@ -555,6 +555,51 @@ bool operator!=(const NzBitset& lhs, const NzBitset +bool operator<(const NzBitset& lhs, const NzBitset& rhs) +{ + const NzBitset& greater = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? lhs : rhs; + const NzBitset& lesser = (lhs.GetBlockCount() > rhs.GetBlockCount()) ? rhs : lhs; + + unsigned int maxBlockCount = greater.GetBlockCount(); + unsigned int minBlockCount = lesser.GetBlockCount(); + + // If the greatest bitset has a single bit active in a block outside the lesser bitset range, then it is greater + for (unsigned int i = maxBlockCount; i > minBlockCount; ++i) + { + if (greater.GetBlock(i)) + return lhs.GetBlockCount() < rhs.GetBlockCount(); + } + + // Compare the common blocks + for (unsigned int i = 0; i < minBlockCount; ++i) + { + unsigned int index = (minBlockCount - i - 1); // Compare from the most significant block to the less significant block + if (lhs.GetBlock(index) < rhs.GetBlock(index)) + return true; + } + + return false; // They are equal +} + +template +bool operator<=(const NzBitset& lhs, const NzBitset& rhs) +{ + return lhs < rhs || lhs == rhs; +} + +template +bool operator>(const NzBitset& lhs, const NzBitset& rhs) +{ + return rhs < lhs; +} + +template +bool operator>=(const NzBitset& lhs, const NzBitset& rhs) +{ + return rhs <= lhs; +} + template NzBitset operator&(const NzBitset& lhs, const NzBitset& rhs) { From d369f6d583abf0c7941abb6c05a5ad52c6803669 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 22 May 2015 17:59:20 +0200 Subject: [PATCH 2/2] Ndk/RenderSystem: Add Entity Removed event Former-commit-id: 88b08f81e38f7dc4166f19b431288a212ccd8e75 --- SDK/include/NDK/Systems/RenderSystem.hpp | 1 + SDK/src/NDK/Systems/RenderSystem.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/SDK/include/NDK/Systems/RenderSystem.hpp b/SDK/include/NDK/Systems/RenderSystem.hpp index a35dc53ba..5cd046f55 100644 --- a/SDK/include/NDK/Systems/RenderSystem.hpp +++ b/SDK/include/NDK/Systems/RenderSystem.hpp @@ -27,6 +27,7 @@ namespace Ndk static SystemIndex systemIndex; private: + void OnEntityRemoved(Entity* entity) override; void OnEntityValidation(Entity* entity, bool justAdded) override; EntityList m_cameras; diff --git a/SDK/src/NDK/Systems/RenderSystem.cpp b/SDK/src/NDK/Systems/RenderSystem.cpp index 4c4f3a629..e114499e7 100644 --- a/SDK/src/NDK/Systems/RenderSystem.cpp +++ b/SDK/src/NDK/Systems/RenderSystem.cpp @@ -16,6 +16,12 @@ namespace Ndk { } + void RenderSystem::OnEntityRemoved(Entity* entity) + { + m_cameras.Remove(entity); + m_drawables.Remove(entity); + } + void RenderSystem::OnEntityValidation(Entity* entity, bool justAdded) { if (entity->HasComponent())