@@ -6,7 +6,7 @@ namespace Pathfinder {
66
77// Invariant: `requested_size` must be a power of two.
88RectI 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
6969void 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
113113void 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
290290Vec2F TextureAllocator::page_scale (uint32_t page_id) {
@@ -294,9 +294,9 @@ Vec2F TextureAllocator::page_scale(uint32_t page_id) {
294294bool 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
302302void 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
0 commit comments