Skip to content

Commit 675cffd

Browse files
committed
Actually checkout UpdateList.cpp/UpdateList.h
1 parent 9a166ac commit 675cffd

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

rts/Rendering/Common/UpdateList.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "UpdateList.h"
2+
#include "System/Misc/TracyDefs.h"
3+
4+
#include <algorithm>
5+
6+
CR_BIND(UpdateList, )
7+
CR_REG_METADATA(UpdateList, (
8+
CR_MEMBER(updateList),
9+
CR_MEMBER(changed)
10+
))
11+
12+
13+
void UpdateList::SetNeedUpdateAll()
14+
{
15+
RECOIL_DETAILED_TRACY_ZONE;
16+
std::fill(updateList.begin(), updateList.end(), true);
17+
changed = true;
18+
}
19+
20+
void UpdateList::ResetNeedUpdateAll()
21+
{
22+
RECOIL_DETAILED_TRACY_ZONE;
23+
std::fill(updateList.begin(), updateList.end(), false);
24+
changed = false;
25+
}
26+
27+
void UpdateList::SetUpdate(const UpdateList::IteratorPair& it)
28+
{
29+
RECOIL_DETAILED_TRACY_ZONE;
30+
std::fill(it.first, it.second, true);
31+
changed = true;
32+
}
33+
34+
void UpdateList::SetUpdate(size_t offset)
35+
{
36+
RECOIL_DETAILED_TRACY_ZONE;
37+
assert(offset < updateList.size());
38+
updateList[offset] = true;
39+
changed = true;
40+
}
41+
42+
void UpdateList::EmplaceBackUpdate()
43+
{
44+
RECOIL_DETAILED_TRACY_ZONE;
45+
updateList.emplace_back(true);
46+
changed = true;
47+
}
48+
49+
void UpdateList::PopBack()
50+
{
51+
updateList.pop_back();
52+
changed = true;
53+
}
54+
55+
void UpdateList::PopBack(size_t N)
56+
{
57+
while (N-- >= 0)
58+
updateList.pop_back();
59+
60+
changed = true;
61+
}
62+
63+
std::optional<UpdateList::IteratorPair> UpdateList::GetNext(const std::optional<UpdateList::IteratorPair>& prev)
64+
{
65+
RECOIL_DETAILED_TRACY_ZONE;
66+
auto beg = prev.has_value() ? prev.value().second : updateList.begin();
67+
beg = std::find(beg, updateList.end(), true);
68+
auto end = std::find(beg, updateList.end(), false);
69+
70+
if (beg == end)
71+
return std::nullopt;
72+
73+
return std::make_optional(std::make_pair(beg, end));
74+
}
75+
76+
std::pair<size_t, size_t> UpdateList::GetOffsetAndSize(const UpdateList::IteratorPair& it)
77+
{
78+
RECOIL_DETAILED_TRACY_ZONE;
79+
return std::make_pair(
80+
std::distance(updateList.begin(), it.first ),
81+
std::distance(it.first , it.second)
82+
);
83+
}

rts/Rendering/Common/UpdateList.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include <tuple>
4+
#include <optional>
5+
#include <vector>
6+
#include "System/creg/creg.h"
7+
8+
class UpdateList {
9+
CR_DECLARE_STRUCT(UpdateList)
10+
public:
11+
using IteratorPair = std::pair<std::vector<bool>::iterator, std::vector<bool>::iterator>;
12+
public:
13+
UpdateList()
14+
: updateList()
15+
, changed(true)
16+
{}
17+
18+
size_t Size() const { return updateList.size(); }
19+
size_t Capacity() const { return updateList.capacity(); }
20+
21+
void Resize(size_t newSize) { updateList.resize(newSize); SetNeedUpdateAll(); }
22+
void Reserve(size_t reservedSize) { updateList.reserve(reservedSize); }
23+
24+
void SetUpdate(const IteratorPair& it);
25+
void SetUpdate(size_t offset);
26+
27+
void SetNeedUpdateAll();
28+
void ResetNeedUpdateAll();
29+
30+
void EmplaceBackUpdate();
31+
void PopBack();
32+
void PopBack(size_t N);
33+
34+
bool NeedUpdate() const { return changed; }
35+
36+
std::optional<IteratorPair> GetNext(const std::optional<IteratorPair>& prev = std::nullopt);
37+
std::pair<size_t, size_t> GetOffsetAndSize(const IteratorPair& it);
38+
private:
39+
std::vector<bool> updateList;
40+
bool changed;
41+
};

0 commit comments

Comments
 (0)