diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-31 14:23:45 +0000 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-31 14:23:45 +0000 |
| commit | 29e52544d389f88a4af836ae1d82b838ed7a10c7 (patch) | |
| tree | 4c80995e8ed0f5b2bdcc55404d18ee03ed474fd1 /src/main/kotlin/main.kt | |
| parent | 3c3322ef1a7aca3517ff94f723004fb809dec6cd (diff) | |
| download | kotlin-raycaster-29e52544d389f88a4af836ae1d82b838ed7a10c7.tar.xz kotlin-raycaster-29e52544d389f88a4af836ae1d82b838ed7a10c7.zip | |
Fix texture loading. Add log overlay
Diffstat (limited to 'src/main/kotlin/main.kt')
| -rw-r--r-- | src/main/kotlin/main.kt | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index aa69ad2..c29374d 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -1,43 +1,44 @@ -fun main() { - val raycastOptions = RaycastOptions(fixFisheye = false, stepPrecision = 32) - val renderer = Renderer(viewportWidth = 320, viewportHeight = 240, outputScale = 3) - val textureManager = TextureManager() - val camera = Camera( - fov = 90, - xPos = 1.2, - yPos = 2.5, - rotation = 60.0 - ) - val map = Map() - val minimap = Minimap(map) - - val context = RaycastContext(raycastOptions, renderer, textureManager, camera, map, minimap) - - val raycaster = Raycaster() - - CameraController(camera, moveSpeed = 1.0, rotateSpeed = 15) { - paint(raycaster, context) - } +import kotlinx.browser.window - val ui = Ui(context) { +fun main() { + window.onload = { + val raycastOptions = RaycastOptions(fixFisheye = false, stepPrecision = 32) + val renderer = Renderer(viewportWidth = 320, viewportHeight = 240, outputScale = 3) + val textureManager = TextureManager() + val camera = Camera( + fov = 90, + xPos = 1.2, + yPos = 2.5, + rotation = 60.0 + ) + val map = Map() + val minimap = Minimap(map) + + val context = RaycastContext(raycastOptions, renderer, textureManager, camera, map, minimap) + + val raycaster = Raycaster() + + CameraController(camera, moveSpeed = 1.0, rotateSpeed = 15) { + paint(raycaster, context) + } + + val ui = Ui(context) { + paint(raycaster, context) + } + + textureManager.loadTextures(ui.getSelectedTextureSet()) + + // Do an initial paint and wait for input paint(raycaster, context) + ui.removeLoadingIndicator() } - - textureManager.loadTextures(ui.getSelectedTextureSet()) - - // Do an initial paint and wait for input - paint(raycaster, context) - ui.removeLoadingIndicator() } -fun paint(raycaster: Raycaster, raycastContext: RaycastContext) { +private fun paint(raycaster: Raycaster, raycastContext: RaycastContext) { with(raycastContext) { renderer.clear() raycaster.raycast(this) minimap.update(camera) + Logger.logPosition(camera) } } - -fun toRadians(degrees: Double): Double { - return degrees * kotlin.math.PI / 180 -} |