Files
CavesOfSwift/Sources/Test/CavesOfJolk.swift

68 lines
1.3 KiB
Swift
Raw Normal View History

2024-05-05 17:01:56 +10:00
import Foundation
import simd
import JolkEngine
@main struct Program
{
static func main()
{
Application(
application: CavesOfJolk(),
config: ApplicationConfiguration(
resizable: true,
vSync: .on,
windowWidth: 1280,
windowHeight: 720,
2024-05-09 20:52:01 +10:00
title: "Caves of Swift",
2024-05-05 17:01:56 +10:00
bundle: Bundle.module)
).run()
}
}
class CavesOfJolk: ApplicationImplementation
{
2024-05-09 20:52:01 +10:00
private lazy var scene = Scene1()
//private lazy var scene = CaveScene()
2024-05-05 17:01:56 +10:00
private var aspect: Float = 0
private var frameCount = 0
private var frameTimer: Float = 1
func create(render: inout Renderer)
{
2024-05-09 20:52:01 +10:00
scene.setup(render: &render)
2024-05-05 17:01:56 +10:00
}
func loadContent(content: inout ContentManager) throws
{
2024-05-09 20:52:01 +10:00
try scene.loadContent(content: &content)
2024-05-05 17:01:56 +10:00
}
func resize(width: Int, height: Int)
{
aspect = Float(width) / Float(height)
print(aspect)
}
func update(deltaTime: Float)
{
2024-05-09 20:52:01 +10:00
scene.update(deltaTime: deltaTime)
2024-05-05 17:01:56 +10:00
frameCount += 1
frameTimer -= deltaTime
if frameTimer <= 0
{
print("FPS: \(frameCount)")
frameCount = 0
frameTimer += 1.0
}
}
func draw(render: inout Renderer, deltaTime: Float)
{
2024-05-09 20:52:01 +10:00
if Input.instance.keyboard.keyPressed(.w, repeat: true) { render.wireframe = !render.wireframe }
2024-05-05 17:01:56 +10:00
2024-05-09 20:52:01 +10:00
scene.draw(render: &render, deltaTime: deltaTime, aspectRatio: aspect)
2024-05-05 17:01:56 +10:00
}
}