-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial code and documentation for building generation
- Loading branch information
1 parent
5a9d025
commit e9e5b7e
Showing
7 changed files
with
150 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 25 additions & 17 deletions
42
core/src/main/kotlin/com/decosegfault/atlas/map/BuildingGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
package com.decosegfault.atlas.map | ||
|
||
import com.badlogic.gdx.graphics.g3d.ModelCache | ||
import com.badlogic.gdx.math.Vector3 | ||
import com.google.common.util.concurrent.ThreadFactoryBuilder | ||
import org.tinylog.kotlin.Logger | ||
import java.sql.Connection | ||
import java.sql.DriverManager | ||
import java.util.Properties | ||
import java.util.concurrent.LinkedBlockingQueue | ||
import java.util.concurrent.ThreadPoolExecutor | ||
import java.util.concurrent.TimeUnit | ||
|
||
/** | ||
* Class that handles the asynchronous generation and texturing of building meshes | ||
* Class that handles the asynchronous generation of building models from OpenStreetMap PostGIS data. | ||
* For more info see docs/atlas_buildings_design.md. | ||
* | ||
* @author Matt Young | ||
*/ | ||
object BuildingGenerator { | ||
/** Limit thread pool size to 2x the number of processors to prevent memory issues */ | ||
private val threadPoolSize = Runtime.getRuntime().availableProcessors() / 2 | ||
|
||
/** Queue used to manage tasks the executor should run when it's full (overflow) */ | ||
private val executorQueue = LinkedBlockingQueue<Runnable>() | ||
|
||
/** | ||
* Executor used for generating buildings. | ||
* This is the exact same as `Executors.newFixedThreadPool`, but we control the queue. | ||
*/ | ||
private val executor = ThreadPoolExecutor( | ||
threadPoolSize, threadPoolSize, | ||
0L, TimeUnit.MILLISECONDS, | ||
executorQueue, | ||
ThreadFactoryBuilder().setNameFormat("BuildingGen-%d").build() | ||
) | ||
private lateinit var conn: Connection | ||
|
||
/** Connects to the PostGIS database */ | ||
fun connect() { | ||
Logger.info("Connecting to PostGIS database") | ||
val props = Properties() | ||
props["user"] = "renderer" | ||
props["password"] = "renderer" | ||
|
||
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/gis", props) | ||
Logger.info("Connected to PostGIS successfully! ${conn.metaData.databaseProductName} ${conn.metaData.databaseProductVersion}") | ||
} | ||
|
||
/** | ||
* Generates a building chunk. Buildings are packaged together into a ModelCache. | ||
*/ | ||
fun generateBuildingChunk(chunk: Vector3): ModelCache { | ||
val cache = ModelCache() | ||
cache.begin() | ||
cache.end() | ||
return cache | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
core/src/main/kotlin/com/decosegfault/atlas/map/BuildingManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.decosegfault.atlas.map | ||
|
||
import com.badlogic.gdx.graphics.Camera | ||
import com.badlogic.gdx.graphics.g3d.ModelCache | ||
import com.decosegfault.atlas.render.GraphicsPreset | ||
|
||
/** | ||
* This class manages fetching and rendering buildings. Basically the building equivalent of | ||
* AtlasTileManager. For more info see docs/atlas_buildings_design.md | ||
* | ||
* @author Matt Young | ||
*/ | ||
class BuildingManager { | ||
fun getBuildingChunksCulled(cam: Camera, graphics: GraphicsPreset): List<ModelCache> { | ||
return listOf() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/kotlin/com/decosegfault/atlas/map/GCBuildingCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.decosegfault.atlas.map | ||
|
||
import com.badlogic.gdx.graphics.g3d.ModelCache | ||
import com.badlogic.gdx.math.Vector3 | ||
import com.decosegfault.atlas.util.AbstractGarbageCollectedCache | ||
|
||
/** **Soft** limit of buildings */ | ||
private const val MAX_BUILDINGS_RAM = 2048.0 | ||
|
||
/** If the cache is this% full, start trying to evict items */ | ||
private const val START_GC_THRESHOLD = 0.90 | ||
|
||
/** If the cache is below this% full, stop evicting */ | ||
private const val END_GC_THRESHOLD = 0.50 | ||
|
||
/** | ||
* Implementation of [AbstractGarbageCollectedCache] used to store buildings | ||
* | ||
* @author Matt Young | ||
*/ | ||
object GCBuildingCache : AbstractGarbageCollectedCache<Vector3, ModelCache>( | ||
"GCBuildingCache", | ||
MAX_BUILDINGS_RAM, | ||
START_GC_THRESHOLD, | ||
END_GC_THRESHOLD, | ||
Runtime.getRuntime().availableProcessors() | ||
) { | ||
override fun newItem(key: Vector3): ModelCache { | ||
return BuildingGenerator.generateBuildingChunk(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters