Skip to content

Commit

Permalink
Mouse audit (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
STREGA authored Jun 20, 2023
1 parent 9519d51 commit ecad7f0
Show file tree
Hide file tree
Showing 34 changed files with 1,207 additions and 409 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Deps
- name: Deps Update
run: sudo apt-get update --fix-missing
- name: Deps Install
run: sudo apt-get install freeglut3-dev; sudo apt-get install libopenal-dev

- name: Swift Version
Expand Down
20 changes: 20 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,23 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

END OF TERMS AND CONDITIONS


-- SDL_GameControllerDB --
Copyright (C) 1997-2022 Sam Lantinga <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
5 changes: 2 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ let package = Package(
}(),
resources: [
.copy("_Resources/GateEngine"),
.copy("System/HID/GamePad/GamePadInterpreter/Interpreters/HID/Mapping/SDL2/SDL2 Game Controller DB.txt"),
],
cSettings: [
.define("GL_SILENCE_DEPRECATION", .when(platforms: [.macOS, .iOS, .tvOS])),
Expand All @@ -97,11 +96,11 @@ let package = Package(
.define("GATEENGINE_PLATFORM_DEFERS_LAUNCH", .when(platforms: [.wasi])),
])

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

// Options for developemnt of WASI platform
#if true
#if false
settings.append(contentsOf: [
/// Allows HTML5 platform to be compiled from a compatible host, such as macOS. This allows the IDE to show compile errors without targeting WASI.
.define("GATEENGINE_ENABLE_WASI_IDE_SUPPORT", .when(platforms: [.macOS, .linux], configuration: .debug)),
Expand Down
38 changes: 38 additions & 0 deletions Sources/GameMath/PlatformSpecific/Win32.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright © 2023 Dustin Collins (Strega's Gate)
* All Rights Reserved.
*
* http://stregasgate.com
*/
#if canImport(WinSDK)
import WinSDK

public extension Rect {
func RECT() -> WinSDK.RECT {
let left: Int32 = Int32(position.x)
let top: Int32 = Int32(position.y)
let right: Int32 = Int32(position.x + size.width)
let bottom: Int32 = Int32(position.y + size.height)
return WinSDK.RECT(left: left, top: top, right: right, bottom: bottom)
}

init(_ RECT: WinSDK.RECT) {
let position: Position2 = Position2(x: Float(RECT.left), y: Float(RECT.top))
let size: Size2 = Size2(width: Float(RECT.width), height: Float(RECT.height))
self.init(position: position, size: size)
}
}


public extension WinSDK.RECT {
@_transparent
var x: Int32 {self.left}
@_transparent
var y: Int32 {self.top}
@_transparent
var width: Int32 {self.right - self.left}
@_transparent
var height: Int32 {self.bottom - self.top}
}

#endif
23 changes: 18 additions & 5 deletions Sources/GateEngine/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import GameMath
public final class Game {
public let platform: CurrentPlatform = CurrentPlatform()

@MainActor public let delegate: GameDelegate
public let delegate: GameDelegate

@MainActor public private(set) lazy var state: State = platform.loadState()

lazy private(set) var identifier: String = delegate.resolvedGameIdentifier()

nonisolated public let isHeadless: Bool
@MainActor internal init(delegate: GameDelegate) {
Expand Down Expand Up @@ -45,6 +47,9 @@ public final class Game {
}
}
#endif

self.primeDeltaTime()

#if !GATEENGINE_PLATFORM_DEFERS_LAUNCH
self.addPlatformSystems()
self.delegate.didFinishLaunching(game: self, options: [])
Expand All @@ -66,9 +71,18 @@ public final class Game {
/// The current delta time as a Double
@usableFromInline
internal var highPrecisionDeltaTime: Double = 0
private var previousTime: Double = 0

@inline(__always)
func primeDeltaTime() {
for _ in 0 ..< 2 {
let now: Double = Game.shared.platform.systemTime()
self.highPrecisionDeltaTime = now - self.previousTime
self.previousTime = now
}
}

#if GATEENGINE_PLATFORM_EVENT_DRIVEN
private var previousTime: Double = 0
@MainActor internal func eventLoop(completion: @escaping ()->Void) {
Task {@MainActor in
let now: Double = Game.shared.platform.systemTime()
Expand All @@ -81,14 +95,13 @@ public final class Game {
}
}else{
#if GATEENGINE_DEBUG_RENDERING
Log.warn("Frame Dropped")
Log.warn("Frame Dropped", "DeltaTime:", highPrecisionDeltaTime)
#endif
completion()
}
}
}
#else
private var previousTime: Double = 0
internal func gameLoop() {
Task {@MainActor in
let now: Double = Game.shared.platform.systemTime()
Expand All @@ -100,7 +113,7 @@ public final class Game {
}
}else{
#if GATEENGINE_DEBUG_RENDERING
Log.warn("Frame Dropped")
Log.warn("Frame Dropped. DeltaTime:", Float(highPrecisionDeltaTime))
#endif
}
self.gameLoop()
Expand Down
42 changes: 29 additions & 13 deletions Sources/GateEngine/GameDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public struct LaunchOptions: OptionSet {
}
}

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

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

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

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

/// Might be called immediatley before the app closes.
func willTerminate(game: Game)
@MainActor func willTerminate(game: Game)

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

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

init()
/**
An ID for the current game. This identifier is used for storing user settings.

By providing a stable identifier, you're free to rename your executable without breaking user settings.
By default the executablke name is used.
*/
nonisolated func gameIdentifier() -> StaticString?

@MainActor init()
}

public extension GameDelegate {
func createMainWindow(game: Game, identifier: String) throws -> Window {
@MainActor func createMainWindow(game: Game, identifier: String) throws -> Window {
return try game.windowManager.createWindow(identifier: identifier, style: .system, options: .defaultForMainWindow)
}
func userRequestedWindow(game: Game) throws -> Window? {return nil}
Expand All @@ -75,13 +83,21 @@ public extension GameDelegate {
func willTerminate(game: Game) {}
func isHeadless() -> Bool {return false}
func resourceSearchPaths() -> [URL] {return []}

func gameIdentifier() -> StaticString? {return nil}

@_transparent
internal func resolvedGameIdentifier() -> String {
if let identifer: StaticString = self.gameIdentifier() {
return identifer.description
}
return CommandLine.arguments[0]
}
}

public extension GameDelegate {
static func main() {
@MainActor static func main() {
Game.shared = Game(delegate: Self())
Game.shared.platform.main()
}
}


Loading

0 comments on commit ecad7f0

Please sign in to comment.