Core/Bitset:

This commit is contained in:
Lynix 2018-03-06 20:25:29 +01:00
parent 464419db73
commit 3036c32d9d
5 changed files with 19 additions and 16 deletions

View File

@ -71,6 +71,7 @@ Nazara Engine:
- PhysWorld3D class is now movable - PhysWorld3D class is now movable
- ⚠️ Removed array/pointer constructor from Vector classes - ⚠️ Removed array/pointer constructor from Vector classes
- Fixed Platform module not being classified as client-only - Fixed Platform module not being classified as client-only
- ⚠️ Renamed Bitset::Read to Bitset::Write
Nazara Development Kit: Nazara Development Kit:
- Added ImageWidget (#139) - Added ImageWidget (#139)

View File

@ -51,9 +51,6 @@ namespace Nz
std::size_t GetCapacity() const; std::size_t GetCapacity() const;
std::size_t GetSize() const; std::size_t GetSize() const;
PointerSequence Read(const void* ptr, std::size_t bitCount);
PointerSequence Read(const PointerSequence& sequence, std::size_t bitCount);
void PerformsAND(const Bitset& a, const Bitset& b); void PerformsAND(const Bitset& a, const Bitset& b);
void PerformsNOT(const Bitset& a); void PerformsNOT(const Bitset& a);
void PerformsOR(const Bitset& a, const Bitset& b); void PerformsOR(const Bitset& a, const Bitset& b);
@ -90,6 +87,9 @@ namespace Nz
void UnboundedSet(std::size_t bit, bool val = true); void UnboundedSet(std::size_t bit, bool val = true);
bool UnboundedTest(std::size_t bit) const; bool UnboundedTest(std::size_t bit) const;
PointerSequence Write(const void* ptr, std::size_t bitCount);
PointerSequence Write(const PointerSequence& sequence, std::size_t bitCount);
Bit operator[](std::size_t index); Bit operator[](std::size_t index);
bool operator[](std::size_t index) const; bool operator[](std::size_t index) const;

View File

@ -328,9 +328,9 @@ namespace Nz
} }
/*! /*!
* \brief Read a byte sequence into a bitset * \brief Writes a byte sequence into a bitset
* *
* This function extends the bitset with bits read from a byte sequence * This function extends the bitset with bits read from a byte sequence.
* *
* \param ptr A pointer to the start of the byte sequence * \param ptr A pointer to the start of the byte sequence
* \param bitCount Number of bits to read from the byte sequence * \param bitCount Number of bits to read from the byte sequence
@ -341,17 +341,18 @@ namespace Nz
* *
* \see AppendBits * \see AppendBits
* \see Read * \see Read
* \see Write
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Read(const void* ptr, std::size_t bitCount) typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Write(const void* ptr, std::size_t bitCount)
{ {
return Read(PointerSequence(ptr, 0U), bitCount); return Write(PointerSequence(ptr, 0U), bitCount);
} }
/*! /*!
* \brief Read a byte sequence into a bitset * \brief Writes a byte sequence into a bitset
* *
* This function extends the bitset with bits read from a pointer sequence (made of a pointer and a bit index) * This function extends the bitset with bits read from a pointer sequence (made of a pointer and a bit index).
* *
* \param sequence A pointer sequence to the start of the byte sequence * \param sequence A pointer sequence to the start of the byte sequence
* \param bitCount Number of bits to read from the byte sequence * \param bitCount Number of bits to read from the byte sequence
@ -362,9 +363,10 @@ namespace Nz
* *
* \see AppendBits * \see AppendBits
* \see Read * \see Read
* \see Write
*/ */
template<typename Block, class Allocator> template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Read(const PointerSequence& sequence, std::size_t bitCount) typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Write(const PointerSequence& sequence, std::size_t bitCount)
{ {
NazaraAssert(sequence.first, "Invalid pointer sequence"); NazaraAssert(sequence.first, "Invalid pointer sequence");
NazaraAssert(sequence.second < 8, "Invalid next bit index (must be < 8)"); NazaraAssert(sequence.second < 8, "Invalid next bit index (must be < 8)");
@ -1161,9 +1163,9 @@ namespace Nz
Bitset bitset; Bitset bitset;
if (sequence) if (sequence)
*sequence = bitset.Read(ptr, bitCount); *sequence = bitset.Write(ptr, bitCount);
else else
bitset.Read(ptr, bitCount); bitset.Write(ptr, bitCount);
return bitset; return bitset;
} }

View File

@ -839,7 +839,7 @@ namespace Nz
if (pixelCount == 0) if (pixelCount == 0)
return false; return false;
auto seq = workingBitset.Read(GetConstPixels(), info.bitsPerPixel); auto seq = workingBitset.Write(GetConstPixels(), info.bitsPerPixel);
do do
{ {
workingBitset &= info.alphaMask; workingBitset &= info.alphaMask;
@ -847,7 +847,7 @@ namespace Nz
return true; return true;
workingBitset.Clear(); workingBitset.Clear();
workingBitset.Read(seq, info.bitsPerPixel); workingBitset.Write(seq, info.bitsPerPixel);
} }
while (--pixelCount > 0); while (--pixelCount > 0);

View File

@ -322,9 +322,9 @@ void CheckRead(const char* title)
{ {
Nz::Bitset<Block> bitset; Nz::Bitset<Block> bitset;
auto seq = bitset.Read(data.data(), pair.second); auto seq = bitset.Write(data.data(), pair.second);
for (std::size_t i = pair.second; i < bitCount; i += pair.second) for (std::size_t i = pair.second; i < bitCount; i += pair.second)
seq = bitset.Read(seq, pair.second); seq = bitset.Write(seq, pair.second);
REQUIRE(bitset.GetSize() == bitCount); REQUIRE(bitset.GetSize() == bitCount);