-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Another piece of valueable scrap from BAR-quat: separate UpdateList c…
…lass - useful to keep track of what items got updated (#1932)
- Loading branch information
Showing
5 changed files
with
155 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include "UpdateList.h" | ||
#include "System/Misc/TracyDefs.h" | ||
|
||
#include <algorithm> | ||
|
||
CR_BIND(UpdateList, ) | ||
CR_REG_METADATA(UpdateList, ( | ||
CR_MEMBER(updateList), | ||
CR_MEMBER(changed) | ||
)) | ||
|
||
|
||
void UpdateList::SetNeedUpdateAll() | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
std::fill(updateList.begin(), updateList.end(), true); | ||
changed = true; | ||
} | ||
|
||
void UpdateList::ResetNeedUpdateAll() | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
std::fill(updateList.begin(), updateList.end(), false); | ||
changed = false; | ||
} | ||
|
||
void UpdateList::Trim(size_t newLessThanOrEqualSize) | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
assert(newLessThanOrEqualSize <= updateList.size()); | ||
updateList.resize(newLessThanOrEqualSize); | ||
// no need to modify the update status | ||
} | ||
|
||
void UpdateList::SetUpdate(size_t first, size_t count) | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
|
||
auto beg = updateList.begin() + first; | ||
auto end = beg + count; | ||
|
||
SetUpdate(UpdateList::IteratorPair(beg, end)); | ||
} | ||
|
||
void UpdateList::SetUpdate(const UpdateList::IteratorPair& it) | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
std::fill(it.first, it.second, true); | ||
changed = true; | ||
} | ||
|
||
void UpdateList::SetUpdate(size_t offset) | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
assert(offset < updateList.size()); | ||
updateList[offset] = true; | ||
changed = true; | ||
} | ||
|
||
void UpdateList::EmplaceBackUpdate() | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
updateList.emplace_back(true); | ||
changed = true; | ||
} | ||
|
||
void UpdateList::PopBack() | ||
{ | ||
updateList.pop_back(); | ||
changed = true; | ||
} | ||
|
||
void UpdateList::PopBack(size_t N) | ||
{ | ||
while (N-- >= 0) | ||
updateList.pop_back(); | ||
|
||
changed = true; | ||
} | ||
|
||
std::optional<UpdateList::ConstIteratorPair> UpdateList::GetNext(const std::optional<UpdateList::ConstIteratorPair>& prev) const | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
auto beg = prev.has_value() ? prev.value().second : updateList.begin(); | ||
beg = std::find(beg, updateList.end(), true); | ||
auto end = std::find(beg, updateList.end(), false); | ||
|
||
if (beg == end) | ||
return std::nullopt; | ||
|
||
return std::make_optional(std::make_pair(beg, end)); | ||
} | ||
|
||
std::pair<size_t, size_t> UpdateList::GetOffsetAndSize(const UpdateList::ConstIteratorPair& it) const | ||
{ | ||
RECOIL_DETAILED_TRACY_ZONE; | ||
return std::make_pair( | ||
std::distance(updateList.begin(), it.first ), | ||
std::distance(it.first , it.second) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <tuple> | ||
#include <optional> | ||
#include <vector> | ||
#include "System/creg/creg_cond.h" | ||
|
||
class UpdateList { | ||
CR_DECLARE_STRUCT(UpdateList) | ||
public: | ||
using ConstIteratorPair = std::pair<std::vector<bool>::const_iterator, std::vector<bool>::const_iterator>; | ||
using IteratorPair = std::pair<std::vector<bool>::iterator, std::vector<bool>::iterator>; | ||
public: | ||
UpdateList() | ||
: updateList() | ||
, changed(false) | ||
{} | ||
UpdateList(size_t initialSize) | ||
: updateList(initialSize) | ||
, changed(initialSize > 0) | ||
{} | ||
|
||
size_t Size() const { return updateList.size(); } | ||
size_t Capacity() const { return updateList.capacity(); } | ||
bool Empty() const { return updateList.empty(); } | ||
|
||
void Trim(size_t newLessThanOrEqualSize); | ||
void Resize(size_t newSize) { updateList.resize(newSize); SetNeedUpdateAll(); } | ||
void Reserve(size_t reservedSize) { updateList.reserve(reservedSize); } | ||
void Clear() { *this = std::move(UpdateList()); } | ||
|
||
void SetUpdate(size_t first, size_t count); | ||
void SetUpdate(const IteratorPair& it); | ||
void SetUpdate(size_t offset); | ||
|
||
void SetNeedUpdateAll(); | ||
void ResetNeedUpdateAll(); | ||
|
||
void EmplaceBackUpdate(); | ||
void PopBack(); | ||
void PopBack(size_t N); | ||
|
||
bool NeedUpdate() const { return changed; } | ||
|
||
std::optional<ConstIteratorPair> GetNext(const std::optional<ConstIteratorPair>& prev = std::nullopt) const; | ||
std::pair<size_t, size_t> GetOffsetAndSize(const ConstIteratorPair& it) const; | ||
private: | ||
std::vector<bool> updateList; | ||
bool changed; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters