Package gaiasky.data
Class StreamingOctreeLoader
- java.lang.Object
-
- gaiasky.data.StreamingOctreeLoader
-
- All Implemented Interfaces:
ISceneGraphLoader,IObserver
- Direct Known Subclasses:
OctreeGroupLoader
public abstract class StreamingOctreeLoader extends java.lang.Object implements IObserver, ISceneGraphLoader
Contains the infrastructure common to all multifile octree loaders which streams data on-demand from disk and unloads unused data.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classStreamingOctreeLoader.DaemonLoaderThe daemon loader thread.
-
Field Summary
Fields Modifier and Type Field Description protected StreamingOctreeLoader.DaemonLoaderdaemonDaemon thread that gets the data loading requests and serves themprotected java.lang.Stringdescriptionprotected intidxLoadedIdsstatic StreamingOctreeLoaderinstanceprotected longlastQueueClearMsLast time of a queue clear event went throughprotected static intLOAD_QUEUE_MAX_SIZEDefault load queue size in octantsprotected long[]loadedIdsLoaded octant ids, for loggingprotected intloadedObjectsprotected booleanloadingPausedWhether loading is paused or notprotected static intMAX_LOAD_CHUNKMaximum number of pages to send to load every batchprotected intmaxLoadedIdsprotected longmaxLoadedStarsMax number of stars loaded at onceprotected java.lang.Stringmetadataprotected static longMIN_QUEUE_CLEAR_MSMinimum time to pass to be able to clear the queue againprotected java.lang.Stringnameprotected intnLoadedStarsCurrent number of stars that are loadedprotected java.lang.Stringparticlesprotected static intPRELOAD_DEPTHData will be pre-loaded at startup down to this octree depth.protected java.util.Queue<OctreeNode>toLoadQueueThe octant loading queueprotected java.util.Queue<OctreeNode>toUnloadQueueThis queue is sorted ascending by access date, so that we know which element to release if needed (oldest)
-
Constructor Summary
Constructors Constructor Description StreamingOctreeLoader()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidabortCurrentLoading()Tells the daemon to immediately stop the loading of octants and wait for new dataprotected voidaddLoadedInfo(long id, int nobjects)voidaddToQueue(OctreeNode octant)static voidclearQueue()Clears the current load queuevoidemptyLoadQueue()Removes all octants from the current load queue.protected voidflushLoadedIds()voidflushLoadQueue()Tells the loader to start loading the octants in the queue.static intgetLoadQueueSize()static intgetNLoadedStars()voidinitialize(java.lang.String[] files)voidinitialize(uk.ac.starlink.util.DataSource ds)com.badlogic.gdx.utils.Array<? extends SceneGraphNode>loadData()voidloadLod(java.lang.Integer lod, AbstractOctreeWrapper octreeWrapper)Loads all the levels of detail until the given one.abstract booleanloadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper, boolean fullinit)Loads the data of the given octantvoidloadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper, java.lang.Integer level)Loads the data of the given octant and its children down to the given levelintloadOctants(com.badlogic.gdx.utils.Array<OctreeNode> octants, AbstractOctreeWrapper octreeWrapper, java.util.concurrent.atomic.AtomicBoolean abort)Loads the objects of the given octantsprotected abstract AbstractOctreeWrapperloadOctreeData()Loads the nodes and the octreevoidnotify(Events event, java.lang.Object... data)static voidqueue(OctreeNode octant)Adds the octant to the load queuevoidsetDescription(java.lang.String description)voidsetName(java.lang.String name)static voidtouch(OctreeNode octant)Moves the octant to the end of the unload queuevoidtouchOctant(OctreeNode octant)Puts it at the end of the toUnloadQueuevoidunloadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper)Unloads the given octant
-
-
-
Field Detail
-
PRELOAD_DEPTH
protected static final int PRELOAD_DEPTH
Data will be pre-loaded at startup down to this octree depth.- See Also:
- Constant Field Values
-
LOAD_QUEUE_MAX_SIZE
protected static final int LOAD_QUEUE_MAX_SIZE
Default load queue size in octants- See Also:
- Constant Field Values
-
MIN_QUEUE_CLEAR_MS
protected static final long MIN_QUEUE_CLEAR_MS
Minimum time to pass to be able to clear the queue again- See Also:
- Constant Field Values
-
MAX_LOAD_CHUNK
protected static final int MAX_LOAD_CHUNK
Maximum number of pages to send to load every batch- See Also:
- Constant Field Values
-
instance
public static StreamingOctreeLoader instance
-
nLoadedStars
protected int nLoadedStars
Current number of stars that are loaded
-
maxLoadedStars
protected final long maxLoadedStars
Max number of stars loaded at once
-
toLoadQueue
protected java.util.Queue<OctreeNode> toLoadQueue
The octant loading queue
-
loadingPaused
protected boolean loadingPaused
Whether loading is paused or not
-
lastQueueClearMs
protected long lastQueueClearMs
Last time of a queue clear event went through
-
name
protected java.lang.String name
-
description
protected java.lang.String description
-
toUnloadQueue
protected java.util.Queue<OctreeNode> toUnloadQueue
This queue is sorted ascending by access date, so that we know which element to release if needed (oldest)
-
loadedIds
protected long[] loadedIds
Loaded octant ids, for logging
-
loadedObjects
protected int loadedObjects
-
maxLoadedIds
protected int maxLoadedIds
-
idxLoadedIds
protected int idxLoadedIds
-
metadata
protected java.lang.String metadata
-
particles
protected java.lang.String particles
-
daemon
protected StreamingOctreeLoader.DaemonLoader daemon
Daemon thread that gets the data loading requests and serves them
-
-
Method Detail
-
initialize
public void initialize(uk.ac.starlink.util.DataSource ds)
- Specified by:
initializein interfaceISceneGraphLoader
-
initialize
public void initialize(java.lang.String[] files) throws java.lang.RuntimeException- Specified by:
initializein interfaceISceneGraphLoader- Throws:
java.lang.RuntimeException
-
loadData
public com.badlogic.gdx.utils.Array<? extends SceneGraphNode> loadData()
- Specified by:
loadDatain interfaceISceneGraphLoader
-
addLoadedInfo
protected void addLoadedInfo(long id, int nobjects)
-
flushLoadedIds
protected void flushLoadedIds()
-
loadOctreeData
protected abstract AbstractOctreeWrapper loadOctreeData()
Loads the nodes and the octree- Returns:
-
queue
public static void queue(OctreeNode octant)
Adds the octant to the load queue- Parameters:
octant-
-
clearQueue
public static void clearQueue()
Clears the current load queue
-
getLoadQueueSize
public static int getLoadQueueSize()
-
getNLoadedStars
public static int getNLoadedStars()
-
touch
public static void touch(OctreeNode octant)
Moves the octant to the end of the unload queue- Parameters:
octant-
-
emptyLoadQueue
public void emptyLoadQueue()
Removes all octants from the current load queue. This happens when the camera viewport changes radically (velocity is high, direction changes a lot, etc.) so that the old octants are dropped and newly observed octants are loaded right away
-
addToQueue
public void addToQueue(OctreeNode octant)
-
touchOctant
public void touchOctant(OctreeNode octant)
Puts it at the end of the toUnloadQueue
-
flushLoadQueue
public void flushLoadQueue()
Tells the loader to start loading the octants in the queue.
-
abortCurrentLoading
public void abortCurrentLoading()
Tells the daemon to immediately stop the loading of octants and wait for new data
-
loadLod
public void loadLod(java.lang.Integer lod, AbstractOctreeWrapper octreeWrapper) throws java.io.IOExceptionLoads all the levels of detail until the given one.- Parameters:
lod- The level of detail to load.octreeWrapper- The octree wrapper.- Throws:
java.io.IOException
-
loadOctant
public void loadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper, java.lang.Integer level) throws java.io.IOException
Loads the data of the given octant and its children down to the given level- Parameters:
octant- The octant to load.octreeWrapper- The octree wrapper.level- The depth to load- Throws:
java.io.IOException
-
loadOctants
public int loadOctants(com.badlogic.gdx.utils.Array<OctreeNode> octants, AbstractOctreeWrapper octreeWrapper, java.util.concurrent.atomic.AtomicBoolean abort) throws java.io.IOException
Loads the objects of the given octants- Parameters:
octants- The list holding the octants to load.octreeWrapper- The octree wrapper.abort- State variable that will be set to true if an abort is called.- Returns:
- The actual number of loaded octants
- Throws:
java.io.IOException
-
unloadOctant
public void unloadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper)
Unloads the given octant- Parameters:
octant-octreeWrapper-
-
loadOctant
public abstract boolean loadOctant(OctreeNode octant, AbstractOctreeWrapper octreeWrapper, boolean fullinit) throws java.io.IOException
Loads the data of the given octant- Parameters:
octant- The octant to load.octreeWrapper- The octree wrapper.fullinit- Whether to fully initialise the objects (on-demand load) or not (startup)- Returns:
- True if the octant was loaded, false otherwise
- Throws:
java.io.IOException
-
notify
public void notify(Events event, java.lang.Object... data)
-
setName
public void setName(java.lang.String name)
- Specified by:
setNamein interfaceISceneGraphLoader
-
setDescription
public void setDescription(java.lang.String description)
- Specified by:
setDescriptionin interfaceISceneGraphLoader
-
-