Skip to content

Commit ecad7f0

Browse files
authored
Mouse audit (#23)
1 parent 9519d51 commit ecad7f0

File tree

34 files changed

+1207
-409
lines changed

34 files changed

+1207
-409
lines changed

.github/workflows/Linux.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v3
19-
- name: Deps
19+
- name: Deps Update
20+
run: sudo apt-get update --fix-missing
21+
- name: Deps Install
2022
run: sudo apt-get install freeglut3-dev; sudo apt-get install libopenal-dev
2123

2224
- name: Swift Version

NOTICE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,23 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
553553
DAMAGES.
554554

555555
END OF TERMS AND CONDITIONS
556+
557+
558+
-- SDL_GameControllerDB --
559+
Copyright (C) 1997-2022 Sam Lantinga <[email protected]>
560+
561+
This software is provided 'as-is', without any express or implied
562+
warranty. In no event will the authors be held liable for any damages
563+
arising from the use of this software.
564+
565+
Permission is granted to anyone to use this software for any purpose,
566+
including commercial applications, and to alter it and redistribute it
567+
freely, subject to the following restrictions:
568+
569+
1. The origin of this software must not be misrepresented; you must not
570+
claim that you wrote the original software. If you use this software
571+
in a product, an acknowledgment in the product documentation would be
572+
appreciated but is not required.
573+
2. Altered source versions must be plainly marked as such, and must not be
574+
misrepresented as being the original software.
575+
3. This notice may not be removed or altered from any source distribution.

Package.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ let package = Package(
7272
}(),
7373
resources: [
7474
.copy("_Resources/GateEngine"),
75-
.copy("System/HID/GamePad/GamePadInterpreter/Interpreters/HID/Mapping/SDL2/SDL2 Game Controller DB.txt"),
7675
],
7776
cSettings: [
7877
.define("GL_SILENCE_DEPRECATION", .when(platforms: [.macOS, .iOS, .tvOS])),
@@ -97,11 +96,11 @@ let package = Package(
9796
.define("GATEENGINE_PLATFORM_DEFERS_LAUNCH", .when(platforms: [.wasi])),
9897
])
9998

100-
#if false // Options for development of GateEngine. These should be commented out for a tagged version releases.
99+
#if false // Options for development of GateEngine. These should be commented out for tagged version releases.
101100
#warning("GateEngine development options are enabled. These can cause strange build errors on some platforms.")
102101

103102
// Options for developemnt of WASI platform
104-
#if true
103+
#if false
105104
settings.append(contentsOf: [
106105
/// Allows HTML5 platform to be compiled from a compatible host, such as macOS. This allows the IDE to show compile errors without targeting WASI.
107106
.define("GATEENGINE_ENABLE_WASI_IDE_SUPPORT", .when(platforms: [.macOS, .linux], configuration: .debug)),
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2023 Dustin Collins (Strega's Gate)
3+
* All Rights Reserved.
4+
*
5+
* http://stregasgate.com
6+
*/
7+
#if canImport(WinSDK)
8+
import WinSDK
9+
10+
public extension Rect {
11+
func RECT() -> WinSDK.RECT {
12+
let left: Int32 = Int32(position.x)
13+
let top: Int32 = Int32(position.y)
14+
let right: Int32 = Int32(position.x + size.width)
15+
let bottom: Int32 = Int32(position.y + size.height)
16+
return WinSDK.RECT(left: left, top: top, right: right, bottom: bottom)
17+
}
18+
19+
init(_ RECT: WinSDK.RECT) {
20+
let position: Position2 = Position2(x: Float(RECT.left), y: Float(RECT.top))
21+
let size: Size2 = Size2(width: Float(RECT.width), height: Float(RECT.height))
22+
self.init(position: position, size: size)
23+
}
24+
}
25+
26+
27+
public extension WinSDK.RECT {
28+
@_transparent
29+
var x: Int32 {self.left}
30+
@_transparent
31+
var y: Int32 {self.top}
32+
@_transparent
33+
var width: Int32 {self.right - self.left}
34+
@_transparent
35+
var height: Int32 {self.bottom - self.top}
36+
}
37+
38+
#endif

Sources/GateEngine/Game.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import GameMath
1111
public final class Game {
1212
public let platform: CurrentPlatform = CurrentPlatform()
1313

14-
@MainActor public let delegate: GameDelegate
14+
public let delegate: GameDelegate
1515

1616
@MainActor public private(set) lazy var state: State = platform.loadState()
17+
18+
lazy private(set) var identifier: String = delegate.resolvedGameIdentifier()
1719

1820
nonisolated public let isHeadless: Bool
1921
@MainActor internal init(delegate: GameDelegate) {
@@ -45,6 +47,9 @@ public final class Game {
4547
}
4648
}
4749
#endif
50+
51+
self.primeDeltaTime()
52+
4853
#if !GATEENGINE_PLATFORM_DEFERS_LAUNCH
4954
self.addPlatformSystems()
5055
self.delegate.didFinishLaunching(game: self, options: [])
@@ -66,9 +71,18 @@ public final class Game {
6671
/// The current delta time as a Double
6772
@usableFromInline
6873
internal var highPrecisionDeltaTime: Double = 0
74+
private var previousTime: Double = 0
75+
76+
@inline(__always)
77+
func primeDeltaTime() {
78+
for _ in 0 ..< 2 {
79+
let now: Double = Game.shared.platform.systemTime()
80+
self.highPrecisionDeltaTime = now - self.previousTime
81+
self.previousTime = now
82+
}
83+
}
6984

7085
#if GATEENGINE_PLATFORM_EVENT_DRIVEN
71-
private var previousTime: Double = 0
7286
@MainActor internal func eventLoop(completion: @escaping ()->Void) {
7387
Task {@MainActor in
7488
let now: Double = Game.shared.platform.systemTime()
@@ -81,14 +95,13 @@ public final class Game {
8195
}
8296
}else{
8397
#if GATEENGINE_DEBUG_RENDERING
84-
Log.warn("Frame Dropped")
98+
Log.warn("Frame Dropped", "DeltaTime:", highPrecisionDeltaTime)
8599
#endif
86100
completion()
87101
}
88102
}
89103
}
90104
#else
91-
private var previousTime: Double = 0
92105
internal func gameLoop() {
93106
Task {@MainActor in
94107
let now: Double = Game.shared.platform.systemTime()
@@ -100,7 +113,7 @@ public final class Game {
100113
}
101114
}else{
102115
#if GATEENGINE_DEBUG_RENDERING
103-
Log.warn("Frame Dropped")
116+
Log.warn("Frame Dropped. DeltaTime:", Float(highPrecisionDeltaTime))
104117
#endif
105118
}
106119
self.gameLoop()

Sources/GateEngine/GameDelegate.swift

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public struct LaunchOptions: OptionSet {
1515
}
1616
}
1717

18-
@MainActor public protocol GameDelegate: AnyObject {
18+
public protocol GameDelegate: AnyObject {
1919
/// Called when the app finishes loading.
20-
func didFinishLaunching(game: Game, options: LaunchOptions)
20+
@MainActor func didFinishLaunching(game: Game, options: LaunchOptions)
2121

2222
/**
2323
Create a customized mainWindow
@@ -26,19 +26,19 @@ public struct LaunchOptions: OptionSet {
2626
- parameter game: The game to create the window from
2727
- parameter identifier: The identifier to give the window. You must use this identifier.
2828
*/
29-
func createMainWindow(game: Game, identifier: String) throws -> Window
29+
@MainActor func createMainWindow(game: Game, identifier: String) throws -> Window
3030

3131
/// The end user has tried to open a window using the platforms mechanisms
32-
func userRequestedWindow(game: Game) throws -> Window?
32+
@MainActor func userRequestedWindow(game: Game) throws -> Window?
3333

3434
/**
3535
A display has been attached.
3636
- returns: A new window instance to put on the screen. Passing an existing window is undefined behaviour.
3737
*/
38-
func screenBecomeAvailable(game: Game) throws -> Window?
38+
@MainActor func screenBecomeAvailable(game: Game) throws -> Window?
3939

4040
/// Might be called immediatley before the app closes.
41-
func willTerminate(game: Game)
41+
@MainActor func willTerminate(game: Game)
4242

4343
/**
4444
Start the game with no window and skip updating RenderingSystem(s).
@@ -51,7 +51,7 @@ public struct LaunchOptions: OptionSet {
5151
- returns: true if the game doesn't draw anything.
5252
- note: RenderingSystem(s) do not recive updates in headless mode.
5353
*/
54-
func isHeadless() -> Bool
54+
@MainActor func isHeadless() -> Bool
5555

5656
/**
5757
Add additional search paths for resources.
@@ -60,13 +60,21 @@ public struct LaunchOptions: OptionSet {
6060
Search paths for your Swift Packages are already located automatically and don't need to be added here.
6161
- returns: An array of URLs each pointing to a directory containing game resources.
6262
*/
63-
func resourceSearchPaths() -> [URL]
63+
nonisolated func resourceSearchPaths() -> [URL]
6464

65-
init()
65+
/**
66+
An ID for the current game. This identifier is used for storing user settings.
67+
68+
By providing a stable identifier, you're free to rename your executable without breaking user settings.
69+
By default the executablke name is used.
70+
*/
71+
nonisolated func gameIdentifier() -> StaticString?
72+
73+
@MainActor init()
6674
}
6775

6876
public extension GameDelegate {
69-
func createMainWindow(game: Game, identifier: String) throws -> Window {
77+
@MainActor func createMainWindow(game: Game, identifier: String) throws -> Window {
7078
return try game.windowManager.createWindow(identifier: identifier, style: .system, options: .defaultForMainWindow)
7179
}
7280
func userRequestedWindow(game: Game) throws -> Window? {return nil}
@@ -75,13 +83,21 @@ public extension GameDelegate {
7583
func willTerminate(game: Game) {}
7684
func isHeadless() -> Bool {return false}
7785
func resourceSearchPaths() -> [URL] {return []}
86+
87+
func gameIdentifier() -> StaticString? {return nil}
88+
89+
@_transparent
90+
internal func resolvedGameIdentifier() -> String {
91+
if let identifer: StaticString = self.gameIdentifier() {
92+
return identifer.description
93+
}
94+
return CommandLine.arguments[0]
95+
}
7896
}
7997

8098
public extension GameDelegate {
81-
static func main() {
99+
@MainActor static func main() {
82100
Game.shared = Game(delegate: Self())
83101
Game.shared.platform.main()
84102
}
85103
}
86-
87-

0 commit comments

Comments
 (0)