Demo refinements
This commit is contained in:
parent
7c7b38253b
commit
e643c7761a
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
import Darwin.Mach.mach_time
|
||||
|
||||
struct Timer {
|
||||
public struct Timer {
|
||||
private let numerator: UInt64
|
||||
private let denominator: UInt64
|
||||
private var startTime: UInt64 = 0
|
||||
private var stopTime: UInt64 = 0
|
||||
|
||||
init() {
|
||||
public init() {
|
||||
var timeBaseInfo = mach_timebase_info.init(numer: 0, denom: 0 )
|
||||
let success: kern_return_t = mach_timebase_info(&timeBaseInfo)
|
||||
assert(KERN_SUCCESS == success)
|
||||
|
|
@ -21,30 +21,30 @@ struct Timer {
|
|||
denominator = UInt64(timeBaseInfo.denom)
|
||||
}
|
||||
|
||||
mutating func start() {
|
||||
public mutating func start() {
|
||||
startTime = mach_absolute_time()
|
||||
}
|
||||
mutating func stop() {
|
||||
public mutating func stop() {
|
||||
stopTime = mach_absolute_time()
|
||||
}
|
||||
mutating func reset() {
|
||||
public mutating func reset() {
|
||||
startTime = 0
|
||||
stopTime = 0
|
||||
}
|
||||
|
||||
var nanoSeconds: UInt64 {
|
||||
public var nanoSeconds: UInt64 {
|
||||
return ((stopTime - startTime) * numerator) / denominator
|
||||
}
|
||||
|
||||
var microSeconds: Double {
|
||||
public var microSeconds: Double {
|
||||
return Double(nanoSeconds) / 1.0e3
|
||||
}
|
||||
|
||||
var milliSeconds: Double {
|
||||
public var milliSeconds: Double {
|
||||
return Double(nanoSeconds) / 1.0e6
|
||||
}
|
||||
|
||||
var seconds: Double {
|
||||
public var seconds: Double {
|
||||
return Double(nanoSeconds) / 1.0e9
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import CSDL2
|
||||
import FirebladeECS
|
||||
|
||||
var tSetup = Timer()
|
||||
tSetup.start()
|
||||
if SDL_Init(SDL_INIT_VIDEO) != 0 {
|
||||
fatalError("could not init video")
|
||||
}
|
||||
|
|
@ -130,10 +131,31 @@ let positionResetSystem = PositionResetSystem()
|
|||
let renderSystem = RenderSystem(hWin: hWin)
|
||||
let colorSystem = ColorSystem()
|
||||
|
||||
createScene()
|
||||
func printHelp() {
|
||||
let help: String = """
|
||||
================ FIREBLADE ECS DEMO ===============
|
||||
press:
|
||||
ESC quit
|
||||
c change all colors (random)
|
||||
r reset all positions (to center)
|
||||
s stop movement
|
||||
+ increase movement speed
|
||||
- reduce movement speed
|
||||
space reset to default movement speed
|
||||
"""
|
||||
print(help)
|
||||
}
|
||||
|
||||
createScene()
|
||||
tSetup.stop()
|
||||
print("[SETUP]: took \(tSetup.milliSeconds)ms")
|
||||
var tRun = Timer()
|
||||
printHelp()
|
||||
|
||||
tRun.start()
|
||||
var event: SDL_Event = SDL_Event()
|
||||
var quit: Bool = false
|
||||
print("================ RUNNING ================")
|
||||
while quit == false {
|
||||
while SDL_PollEvent(&event) == 1 {
|
||||
switch SDL_EventType(rawValue: event.type) {
|
||||
|
|
@ -172,3 +194,5 @@ while quit == false {
|
|||
|
||||
SDL_DestroyWindow(hWin)
|
||||
SDL_Quit()
|
||||
tRun.stop()
|
||||
print("[RUN]: took \(tRun.seconds)s")
|
||||
|
|
|
|||
Loading…
Reference in New Issue