Package com.rvandoosselaer.blocks
Class Pager<T>
- java.lang.Object
-
- com.rvandoosselaer.blocks.Pager<T>
-
- Direct Known Subclasses:
ChunkPager
,PhysicsChunkPager
public abstract class Pager<T> extends java.lang.Object
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 toupdate()
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
Fields Modifier and Type Field Description protected java.util.Map<com.simsilica.mathd.Vec3i,T>
attachedPages
protected com.simsilica.mathd.Vec3i
centerPage
protected @NonNull ChunkManager
chunkManager
protected com.simsilica.mathd.Vec3i
gridLowerBounds
protected com.simsilica.mathd.Vec3i
gridSize
protected com.simsilica.mathd.Vec3i
gridUpperBounds
protected com.jme3.math.Vector3f
location
protected java.util.List<PagerListener<T>>
pagerListeners
protected java.util.Queue<com.simsilica.mathd.Vec3i>
pagesToAttach
protected java.util.Queue<com.simsilica.mathd.Vec3i>
pagesToDetach
protected java.util.Set<com.simsilica.mathd.Vec3i>
requestedPages
protected java.util.Queue<com.simsilica.mathd.Vec3i>
updatedPages
-
Constructor Summary
Constructors Constructor Description Pager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
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 java.util.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
initialize()
void
removeListener(@NonNull PagerListener<T> listener)
void
update()
protected void
updateQueues()
Updates the queues of the Pager.
-
-
-
Field Detail
-
chunkManager
@NonNull protected final @NonNull ChunkManager chunkManager
-
attachedPages
protected final java.util.Map<com.simsilica.mathd.Vec3i,T> attachedPages
-
pagesToAttach
protected final java.util.Queue<com.simsilica.mathd.Vec3i> pagesToAttach
-
pagesToDetach
protected final java.util.Queue<com.simsilica.mathd.Vec3i> pagesToDetach
-
updatedPages
protected final java.util.Queue<com.simsilica.mathd.Vec3i> updatedPages
-
requestedPages
protected final java.util.Set<com.simsilica.mathd.Vec3i> 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
protected java.util.List<PagerListener<T>> pagerListeners
-
-
Method Detail
-
initialize
public void initialize()
-
update
public void update()
-
cleanup
public void cleanup()
-
addListener
public void addListener(@NonNull @NonNull PagerListener<T> listener)
-
removeListener
public void removeListener(@NonNull @NonNull PagerListener<T> listener)
-
getPages
protected java.util.Set<com.simsilica.mathd.Vec3i> 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
protected abstract T createPage(Chunk chunk)
Creates and returns the page based on the passed chunk.- Parameters:
chunk
-- Returns:
- page of the chunk or null
-
detachPage
protected abstract void detachPage(T page)
Detach the page.- Parameters:
page
- to detach
-
attachPage
protected abstract void attachPage(T page)
Attach the page.- Parameters:
page
- to attach
-
-