mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 02:59:37 +00:00 
			
		
		
		
	application config for window settings
This commit is contained in:
		@ -1,12 +1,15 @@
 | 
				
			|||||||
import Foundation
 | 
					import Foundation
 | 
				
			||||||
import SDL3
 | 
					import SDL3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Application {
 | 
					public class Application {
 | 
				
			||||||
 | 
					  private let cfg: ApplicationConfiguration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private var window: OpaquePointer? = nil
 | 
					  private var window: OpaquePointer? = nil
 | 
				
			||||||
  private var lastCounter: UInt64 = 0
 | 
					  private var lastCounter: UInt64 = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private static let windowWidth: Int32 = 1280
 | 
					  public init(configuration: ApplicationConfiguration) {
 | 
				
			||||||
  private static let windowHeight: Int32 = 720
 | 
					    self.cfg = configuration
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private func initialize() -> ApplicationExecutionState {
 | 
					  private func initialize() -> ApplicationExecutionState {
 | 
				
			||||||
    guard SDL_Init(SDL_INIT_VIDEO) >= 0 else {
 | 
					    guard SDL_Init(SDL_INIT_VIDEO) >= 0 else {
 | 
				
			||||||
@ -14,9 +17,11 @@ class Application {
 | 
				
			|||||||
      return .exitFailure
 | 
					      return .exitFailure
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    window = SDL_CreateWindow("Voxelotl",
 | 
					    var windowFlags = SDL_WindowFlags(SDL_WINDOW_HIGH_PIXEL_DENSITY)
 | 
				
			||||||
      Self.windowWidth, Self.windowHeight,
 | 
					    if (cfg.flags.contains(.resizable)) {
 | 
				
			||||||
      SDL_WindowFlags(SDL_WINDOW_RESIZABLE) | SDL_WindowFlags(SDL_WINDOW_HIGH_PIXEL_DENSITY))
 | 
					      windowFlags |= SDL_WindowFlags(SDL_WINDOW_RESIZABLE)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    window = SDL_CreateWindow(cfg.title, cfg.width, cfg.height, windowFlags)
 | 
				
			||||||
    guard window != nil else {
 | 
					    guard window != nil else {
 | 
				
			||||||
      print("SDL_CreateWindow() error: \(String(cString: SDL_GetError()))")
 | 
					      print("SDL_CreateWindow() error: \(String(cString: SDL_GetError()))")
 | 
				
			||||||
      return .exitFailure
 | 
					      return .exitFailure
 | 
				
			||||||
@ -81,6 +86,37 @@ class Application {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public struct ApplicationConfiguration {
 | 
				
			||||||
 | 
					  public struct Flags: OptionSet {
 | 
				
			||||||
 | 
					    public let rawValue: Int
 | 
				
			||||||
 | 
					    public init(rawValue: Int) {
 | 
				
			||||||
 | 
					      self.rawValue = rawValue
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static let resizable = Flags(rawValue: 1 << 0)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public enum VSyncMode {
 | 
				
			||||||
 | 
					    case off
 | 
				
			||||||
 | 
					    case on(interval: UInt)
 | 
				
			||||||
 | 
					    case adaptive
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let width: Int32
 | 
				
			||||||
 | 
					  let height: Int32
 | 
				
			||||||
 | 
					  let title: String
 | 
				
			||||||
 | 
					  let flags: Flags
 | 
				
			||||||
 | 
					  let vsyncMode: VSyncMode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public init(width: Int32, height: Int32, title: String, flags: Flags, vsyncMode: VSyncMode) {
 | 
				
			||||||
 | 
					    self.width = width
 | 
				
			||||||
 | 
					    self.height = height
 | 
				
			||||||
 | 
					    self.title = title
 | 
				
			||||||
 | 
					    self.flags = flags
 | 
				
			||||||
 | 
					    self.vsyncMode = vsyncMode
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fileprivate enum ApplicationExecutionState {
 | 
					fileprivate enum ApplicationExecutionState {
 | 
				
			||||||
  case exitFailure
 | 
					  case exitFailure
 | 
				
			||||||
  case exitSuccess
 | 
					  case exitSuccess
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,11 @@
 | 
				
			|||||||
import Darwin
 | 
					import Darwin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let app = Application()
 | 
					let app = Application(
 | 
				
			||||||
 | 
					  configuration: ApplicationConfiguration(
 | 
				
			||||||
 | 
					  width: 1280,
 | 
				
			||||||
 | 
					  height: 720,
 | 
				
			||||||
 | 
					  title: "Voxelotl Demo",
 | 
				
			||||||
 | 
					  flags: .resizable,
 | 
				
			||||||
 | 
					  vsyncMode: .on(interval: 1)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exit(app.run())
 | 
					exit(app.run())
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user