Package com.rvandoosselaer.blocks
Class Pager<T>
java.lang.Object
com.rvandoosselaer.blocks.Pager<T>
- Direct Known Subclasses:
ChunkPager,PhysicsChunkPager
An abstract implementation of a 3D pager. Based on the given center location (
#setLocation(Vector3f) the pages
around this center page in the grid are calculated. Each call to update() will:
- detach one page that is outside the grid, if available
- attach one new page that is inside the grid, if available
- update a page inside the grid, if one is available.
Implementing classes need to implement the methods to create, attach and detach pages.
The boundaries of the grid can be set by setting #setGridLowerBounds(Vec3i) and #setGridUpperBounds(Vec3i).-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.simsilica.mathd.Vec3iprotected final @NonNull ChunkManagerprotected com.simsilica.mathd.Vec3iprotected com.simsilica.mathd.Vec3iprotected com.simsilica.mathd.Vec3iprotected com.jme3.math.Vector3fprotected List<PagerListener<T>>protected final Queue<com.simsilica.mathd.Vec3i>protected final Queue<com.simsilica.mathd.Vec3i>protected final Set<com.simsilica.mathd.Vec3i>protected final Queue<com.simsilica.mathd.Vec3i> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(@NonNull PagerListener<T> listener) protected abstract voidattachPage(T page) Attach the page.voidcleanup()protected abstract TcreatePage(Chunk chunk) Creates and returns the page based on the passed chunk.protected abstract voiddetachPage(T page) Detach the page.protected Set<com.simsilica.mathd.Vec3i>getPages()Calculates and returns the pages (chunks) in the grid, based on the gridSize and centerPageLocation in the grid.voidvoidremoveListener(@NonNull PagerListener<T> listener) voidupdate()protected voidUpdates the queues of the Pager.
-
Field Details
-
chunkManager
-
attachedPages
-
pagesToAttach
-
pagesToDetach
-
updatedPages
-
requestedPages
-
gridSize
protected com.simsilica.mathd.Vec3i gridSize -
centerPage
protected com.simsilica.mathd.Vec3i centerPage -
location
protected com.jme3.math.Vector3f location -
gridLowerBounds
protected com.simsilica.mathd.Vec3i gridLowerBounds -
gridUpperBounds
protected com.simsilica.mathd.Vec3i gridUpperBounds -
pagerListeners
-
-
Constructor Details
-
Pager
public Pager()
-
-
Method Details
-
initialize
public void initialize() -
update
public void update() -
cleanup
public void cleanup() -
addListener
-
removeListener
-
getPages
Calculates and returns the pages (chunks) in the grid, based on the gridSize and centerPageLocation in the grid.- Returns:
- the set of pages in the grid
-
updateQueues
protected void updateQueues()Updates the queues of the Pager. This should be called when the gridSize or centerPageLocation has changed. -
createPage
Creates and returns the page based on the passed chunk.- Parameters:
chunk-- Returns:
- page of the chunk or null
-
detachPage
Detach the page.- Parameters:
page- to detach
-
attachPage
Attach the page.- Parameters:
page- to attach
-