summaryrefslogtreecommitdiffhomepage
path: root/src/world.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-09 11:45:34 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-09 11:45:34 +0100
commitff3a18b1a251a5e85057e52303efa0cdd79e8a66 (patch)
tree44c2f3a6f69bc922d71063debd14ba669c74ca0d /src/world.cpp
parentb4770eb85369e91cbf800e8192dac0d8c0c627cf (diff)
add floor mesh to struct chunk
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/world.cpp b/src/world.cpp
index 454f8e68..49a2fdf9 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -16,18 +16,11 @@ fm_noinline
chunk& world::operator[](chunk_coords coord) noexcept
{
maybe_collect();
-
- if (auto& [c, coord2] = _last_chunk; c && coord == coord2)
- {
- return *c;
- }
-
- auto [it, inserted] = _chunks.try_emplace(coord);
- auto& ret = it->second;
- auto& [_c, _coord] = _last_chunk;
- _c = &ret;
- _coord = coord;
- return ret;
+ auto& [c, coord2] = _last_chunk;
+ if (coord != coord2)
+ c = &_chunks.try_emplace(coord).first->second;
+ coord2 = coord;
+ return *c;
}
auto world::operator[](global_coords pt) noexcept -> pair
@@ -46,13 +39,14 @@ void world::clear()
_last_collection = 0;
_chunks.clear();
_chunks.rehash(initial_capacity);
- auto& [c, _] = _last_chunk;
+ auto& [c, pos] = _last_chunk;
c = nullptr;
+ pos = chunk_tuple::invalid_coords;
}
void world::maybe_collect()
{
- if (_last_collection + collect_every > _chunks.size())
+ if (_chunks.size() > _last_collection + collect_every)
collect();
}
@@ -68,8 +62,9 @@ void world::collect(bool force)
}
_last_collection = _chunks.size();
- auto& [c, _] = _last_chunk;
+ auto& [c, pos] = _last_chunk;
c = nullptr;
+ pos = chunk_tuple::invalid_coords;
}
} // namespace floormat