2024-08-13 08:38:21 +10:00
|
|
|
public protocol GameDelegate {
|
2024-08-25 14:49:07 +10:00
|
|
|
func create(_ renderer: Renderer)
|
2024-08-13 08:38:21 +10:00
|
|
|
func fixedUpdate(_ time: GameTime)
|
|
|
|
func update(_ time: GameTime)
|
|
|
|
func draw(_ renderer: Renderer, _ time: GameTime)
|
|
|
|
func resize(_ size: Size<Int>)
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension GameDelegate {
|
|
|
|
func fixedUpdate(_ time: GameTime) {}
|
|
|
|
func update(_ time: GameTime) {}
|
|
|
|
func resize(_ size: Size<Int>) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
public struct GameTime {
|
|
|
|
let total: Duration
|
|
|
|
let delta: Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Duration {
|
|
|
|
var asFloat: Double {
|
|
|
|
Double(components.seconds) + Double(components.attoseconds) * 1e-18
|
|
|
|
}
|
|
|
|
}
|
2024-09-13 18:59:14 +10:00
|
|
|
|
|
|
|
extension Float {
|
|
|
|
public init(_ value: Duration) {
|
|
|
|
self = Float(value.asFloat)
|
|
|
|
}
|
|
|
|
}
|