IsChunkCellWithinViewport extraChunkRadius parameter for supporting overdraw.
This commit is contained in:
@@ -45,7 +45,10 @@ namespace CaveGame::Client
|
||||
JGL::RenderTarget* canvas_render_target;
|
||||
|
||||
|
||||
bool IsChunkCellWithinViewport(const Vector2& coords) const;
|
||||
/// Determines whether a given chunk coordinate lies within the viewable space, with an optional 'oversize' parameter.
|
||||
/// @param extraChunkRadius Specifies how many extra chunks can be considered within the viewport when they are in fact, just outside of the viewport.
|
||||
/// @note This is used to overdraw
|
||||
bool IsChunkCellWithinViewport(const Vector2& coords, int extraChunkRadius = 0) const;
|
||||
|
||||
void RenderChunk(const Vector2& coords);
|
||||
|
||||
|
@@ -204,10 +204,11 @@ namespace CaveGame::Client {
|
||||
return cached_chunk_sprites.size();
|
||||
}
|
||||
|
||||
bool LocalWorld::IsChunkCellWithinViewport(const Vector2 &coords) const {
|
||||
bool LocalWorld::IsChunkCellWithinViewport(const Vector2 &coords, int extraChunkRadius) const {
|
||||
int extraChunkComputedPixelsRequired = extraChunkRadius*Core::Chunk::ChunkSize;
|
||||
AABB2D chunk_bounding_box = AABB2D(coords*Core::Chunk::ChunkSize, coords*Core::Chunk::ChunkSize+Vector2(Core::Chunk::ChunkSize));
|
||||
return Core::Solver::AABB2Dvs(
|
||||
camera.ScaledViewport(), chunk_bounding_box);
|
||||
camera.ScaledViewportOversized(extraChunkComputedPixelsRequired), chunk_bounding_box);
|
||||
}
|
||||
|
||||
RNG rng;
|
||||
@@ -284,7 +285,7 @@ namespace CaveGame::Client {
|
||||
for (auto it = loaded_chunks.begin(); it != loaded_chunks.end();)
|
||||
{
|
||||
const auto coords = it->first;
|
||||
if (!IsChunkCellWithinViewport(coords)) {
|
||||
if (!IsChunkCellWithinViewport(coords, 2)) {
|
||||
// TODO: Move off main thread.
|
||||
SaveChunkToFile(coords, it->second);
|
||||
|
||||
@@ -304,8 +305,8 @@ namespace CaveGame::Client {
|
||||
// TODO If you want to load chunks the player cannot see, Update the "LookForChunksNeedUnloading" function to use the same bounds.
|
||||
// The chunks just outside the visible area would be written to the disk and reloaded every time the loop went around - Redacted.
|
||||
|
||||
Vector2 viewport_topleft = camera.ScaledViewport().minPoint;
|
||||
Vector2 viewport_bottomright = camera.ScaledViewport().maxPoint;
|
||||
Vector2 viewport_topleft = camera.ScaledViewportOversized(2*Core::Chunk::ChunkSize).minPoint;
|
||||
Vector2 viewport_bottomright = camera.ScaledViewportOversized(2*Core::Chunk::ChunkSize).maxPoint;
|
||||
|
||||
int lower_bound_h = Math::Floor(viewport_topleft.x / Core::Chunk::ChunkSize)/*-2*/;
|
||||
int upper_bound_h = Math::Floor(viewport_bottomright.x / Core::Chunk::ChunkSize)/*+2*/;
|
||||
|
Reference in New Issue
Block a user