]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/threedee/TerrainCache.java
5f5733f72be4a0fa1eb2c954375d3900fb2d54ec
[GpsPrune.git] / src / tim / prune / threedee / TerrainCache.java
1 package tim.prune.threedee;
2
3 import tim.prune.DataStatus;
4 import tim.prune.data.Track;
5
6 /**
7  * This abstract class acts as a singleton to store a single
8  * terrain model (as a Track) for a given data status and terrain definition.
9  * When the data or the definition changes, this track becomes invalid.
10  */
11 public abstract class TerrainCache
12 {
13         /** The data status at the time this terrain was generated */
14         private static DataStatus _dataStatus = null;
15         /** The definition (grid size) for this terrain */
16         private static TerrainDefinition _terrainDef = null;
17         /** The generated grid of points with altitudes */
18         private static Track _terrainTrack = null;
19
20
21         /**
22          * Get the stored terrain track if it's still valid
23          * @param inCurrStatus current data status
24          * @param inTerrainDef currently selected terrain definition
25          * @return stored terrain track if it's valid, null otherwise
26          */
27         public static Track getTerrainTrack(DataStatus inCurrStatus, TerrainDefinition inTerrainDef)
28         {
29                 if (_dataStatus == null || _terrainDef == null || _terrainTrack == null)
30                 {
31                         return null; // nothing stored
32                 }
33                 if (inCurrStatus == null || inTerrainDef == null || !inTerrainDef.getUseTerrain())
34                 {
35                         return null; // nonsense requested
36                 }
37                 if (inCurrStatus.hasDataChanged(_dataStatus) || !inTerrainDef.equals(_terrainDef))
38                 {
39                         return null; // stored track is out of date
40                 }
41                 // we have a match
42                 return _terrainTrack;
43         }
44
45         /**
46          * Now that a terrain track has been generated, store it for possible reuse
47          * @param inTrack terrain track to store
48          * @param inCurrStatus current data status
49          * @param inTerrainDef terrain definition
50          */
51         public static void storeTerrainTrack(Track inTrack, DataStatus inCurrStatus, TerrainDefinition inTerrainDef)
52         {
53                 _terrainTrack = inTrack;
54                 _dataStatus = inCurrStatus;
55                 _terrainDef = inTerrainDef;
56         }
57 }