Skip to content

Commit a0b200b

Browse files
committed
Tidy up
1 parent 519b117 commit a0b200b

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

pathfinder/core/d3d9/data/alpha_tile_id.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace Pathfinder {
1111

12-
const size_t ALPHA_TILE_LEVEL_COUNT = 2;
13-
const size_t ALPHA_TILES_PER_LEVEL = 1 << (32 - ALPHA_TILE_LEVEL_COUNT + 1);
12+
constexpr size_t ALPHA_TILE_LEVEL_COUNT = 2;
13+
constexpr size_t ALPHA_TILES_PER_LEVEL = 1 << (32 - ALPHA_TILE_LEVEL_COUNT + 1);
1414

1515
struct AlphaTileId {
1616
/// A valid value means a solid tile. Default is invalid.

pathfinder/core/d3d9/scene_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class SceneBuilderD3D9 : public SceneBuilder {
4747
std::vector<Fill> pending_fills;
4848

4949
// Tiles to draw.
50-
std::vector<DrawTileBatchD3D9> tile_batches{};
50+
std::vector<DrawTileBatchD3D9> tile_batches;
5151

5252
// Metadata texture data.
5353
std::vector<TextureMetadataEntry> metadata;

pathfinder/core/d3d9/tiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Pathfinder {
99

1010
/// This might be the most important class for building on D3D9 level.
1111
/// One tiler for one outline.
12-
struct Tiler {
12+
class Tiler {
1313
public:
1414
Tiler(SceneBuilderD3D9& _scene_builder,
1515
uint32_t path_id,

pathfinder/core/data/dense_tile_map.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,31 @@ struct DenseTileMap {
5959
}
6060

6161
/// A quick way to build z buffer.
62-
static inline DenseTileMap z_builder(const RectI &_rect) {
62+
static DenseTileMap z_builder(const RectI &_rect) {
6363
return {std::vector<T>(_rect.width() * _rect.height(), 0), _rect};
6464
}
6565

66-
inline T *get(const Vec2I &coords) {
66+
T *get(const Vec2I &coords) {
6767
auto index = coords_to_index(coords);
6868

6969
// We have to make sure the index we get is valid.
7070
if (index) {
7171
return &data[*index];
72-
} else {
73-
return nullptr;
7472
}
73+
return nullptr;
7574
}
7675

7776
/// A safe call to find index by coordinates.
78-
inline std::shared_ptr<size_t> coords_to_index(const Vec2I &coords) {
77+
std::shared_ptr<size_t> coords_to_index(const Vec2I &coords) {
7978
if (rect.contains_point(coords)) {
8079
return std::make_shared<size_t>(coords_to_index_unchecked(coords));
81-
} else {
82-
return nullptr;
8380
}
81+
return nullptr;
8482
}
8583

8684
/// An unsafe call to index by coordinates.
8785
/// The tile map's top and bottom bounds are not considered.
88-
inline int coords_to_index_unchecked(const Vec2I &coords) {
86+
int coords_to_index_unchecked(const Vec2I &coords) const {
8987
return (coords.y - rect.min_y()) * rect.size().x + coords.x - rect.min_x();
9088
}
9189
};

pathfinder/core/paint/texture_allocator.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Pathfinder {
66

77
// Invariant: `requested_size` must be a power of two.
88
RectI TreeNode::allocate(Vec2I this_origin, uint32_t this_size, uint32_t requested_size) {
9-
if (type == TreeNode::Type::FullLeaf) {
9+
if (type == Type::FullLeaf) {
1010
// No room here.
1111
return RectI();
1212
}
@@ -16,15 +16,15 @@ RectI TreeNode::allocate(Vec2I this_origin, uint32_t this_size, uint32_t request
1616
}
1717

1818
// Allocate here or split, as necessary.
19-
if (type == TreeNode::Type::EmptyLeaf) {
19+
if (type == Type::EmptyLeaf) {
2020
// Do we have a perfect fit?
2121
if (this_size == requested_size) {
22-
type = TreeNode::Type::FullLeaf;
22+
type = Type::FullLeaf;
2323
return RectI(this_origin, Vec2I(this_size, this_size));
2424
}
2525

2626
// Split.
27-
type = TreeNode::Type::Parent;
27+
type = Type::Parent;
2828

2929
for (int i = 0; i < 4; i++) {
3030
kids[i] = std::make_shared<TreeNode>();
@@ -33,7 +33,7 @@ RectI TreeNode::allocate(Vec2I this_origin, uint32_t this_size, uint32_t request
3333

3434
// Recurse into children.
3535
switch (type) {
36-
case TreeNode::Type::Parent: {
36+
case Type::Parent: {
3737
uint32_t kid_size = this_size / 2;
3838

3939
auto origin = kids[0]->allocate(this_origin, kid_size, requested_size);
@@ -69,7 +69,7 @@ RectI TreeNode::allocate(Vec2I this_origin, uint32_t this_size, uint32_t request
6969
void TreeNode::free(Vec2I this_origin, uint32_t this_size, Vec2I requested_origin, uint32_t requested_size) {
7070
if (this_size <= requested_size) {
7171
if (this_size == requested_size && this_origin == requested_origin) {
72-
type = TreeNode::Type::EmptyLeaf;
72+
type = Type::EmptyLeaf;
7373

7474
for (int i = 0; i < 4; i++) {
7575
kids[i] = nullptr;
@@ -101,7 +101,7 @@ void TreeNode::free(Vec2I this_origin, uint32_t this_size, Vec2I requested_origi
101101
}
102102
}
103103

104-
if (type == TreeNode::Type::Parent) {
104+
if (type == Type::Parent) {
105105
kids[child_index]->free(child_origin, child_size, requested_origin, requested_size);
106106
merge_if_necessary();
107107
} else {
@@ -111,22 +111,22 @@ void TreeNode::free(Vec2I this_origin, uint32_t this_size, Vec2I requested_origi
111111
}
112112

113113
void TreeNode::merge_if_necessary() {
114-
if (type == TreeNode::Type::Parent) {
114+
if (type == Type::Parent) {
115115
// Check if all kids are empty leaves.
116116
bool res = true;
117117
for (auto &k : kids) {
118118
if (k == nullptr) {
119119
throw std::runtime_error("Parent tree node should not have null kids!");
120120
}
121121

122-
if (k->type != TreeNode::Type::EmptyLeaf) {
122+
if (k->type != Type::EmptyLeaf) {
123123
res = false;
124124
break;
125125
}
126126
}
127127

128128
if (res) {
129-
type = TreeNode::Type::EmptyLeaf;
129+
type = Type::EmptyLeaf;
130130

131131
for (int i = 0; i < 4; i++) {
132132
kids[i] = nullptr;
@@ -279,12 +279,12 @@ Vec2I TextureAllocator::page_size(uint32_t page_id) {
279279

280280
if (page_allocator.type == TexturePageAllocator::Type::Atlas) {
281281
return Vec2I(page_allocator.allocator.size);
282-
} else {
283-
return Vec2I(page_allocator.image_size);
284282
}
285-
} else {
286-
throw std::runtime_error("No such texture page!");
283+
284+
return Vec2I(page_allocator.image_size);
287285
}
286+
287+
throw std::runtime_error("No such texture page!");
288288
}
289289

290290
Vec2F TextureAllocator::page_scale(uint32_t page_id) {
@@ -294,9 +294,9 @@ Vec2F TextureAllocator::page_scale(uint32_t page_id) {
294294
bool TextureAllocator::page_is_new(uint32_t page_id) {
295295
if (pages[page_id]) {
296296
return pages[page_id]->is_new;
297-
} else {
298-
throw std::runtime_error("No such texture page!");
299297
}
298+
299+
throw std::runtime_error("No such texture page!");
300300
}
301301

302302
void TextureAllocator::mark_all_pages_as_allocated() {
@@ -312,6 +312,7 @@ TexturePageIter TextureAllocator::page_ids() {
312312
while (first_index < pages.size() && pages[first_index] == nullptr) {
313313
first_index += 1;
314314
}
315+
315316
return TexturePageIter{this, first_index};
316317
}
317318

@@ -328,6 +329,7 @@ std::shared_ptr<uint32_t> TexturePageIter::next() {
328329
break;
329330
}
330331
}
332+
331333
return next_id;
332334
}
333335

pathfinder/core/paint/texture_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Pathfinder {
1313

14-
const uint32_t ATLAS_TEXTURE_LENGTH = 1024;
14+
constexpr uint32_t ATLAS_TEXTURE_LENGTH = 1024;
1515

1616
struct TreeNode {
1717
enum class Type {

0 commit comments

Comments
 (0)