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.Vec3i
protected final @NonNull ChunkManager
protected com.simsilica.mathd.Vec3i
protected com.simsilica.mathd.Vec3i
protected com.simsilica.mathd.Vec3i
protected com.jme3.math.Vector3f
protected 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 TypeMethodDescriptionvoid
addListener
(@NonNull PagerListener<T> listener) protected abstract void
attachPage
(T page) Attach the page.void
cleanup()
protected abstract T
createPage
(Chunk chunk) Creates and returns the page based on the passed chunk.protected abstract void
detachPage
(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.void
void
removeListener
(@NonNull PagerListener<T> listener) void
update()
protected void
Updates 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
-