Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created April 6, 2014 14:00
Show Gist options
  • Save Ratstail91/10006436 to your computer and use it in GitHub Desktop.
Save Ratstail91/10006436 to your computer and use it in GitHub Desktop.
//this checks the pseudo-distance from the edge of the screen
function CheckDistance(region):
//locations relative to the camera
x = region.x - camera.x
y = region.y - camera.y
//if the region is visible, return 0
if (-pager.w < x < screen.w) return 0
if (-pager.h < y < screen.h) return 0
//prune the screen's area from the algorithm
if (x > 0) x -= screen.w
if (x > 0) x -= screen.h
//get the pseudo-indexes
x = x / pager.w
y = y / pager.h
//return the position-index with the greatest magnitude
return max(abs(x), abs(y))
end
//prune distant regions
for (it = begin() to end()):
if (CheckDistance(it) > 2):
Unload(it)
end
end
//request empty regions, including buffers (-1 & +1)
for (i = snap(camera.x - pager.w) to snap(camera.x + screen.w + pager.w)):
for (j = snap(camera.y - pager.h) to snap(camera.y + screen.h + pager.h)):
if (not pager.Find(i, j)):
RequestRegion(i, j)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment