Files
Picross/Sources/SDL/Engine.swift
T
2024-10-24 14:38:04 -04:00

59 lines
2.1 KiB
Swift

import CSDL2
import CSDL2_Image
public struct Engine {
/// Initalizes SDL. This must be called before any other SDL function, and can only be called once per program.
///
/// Errors encountered in this function are considered unrecoverable, and will crash the entire program.
///
/// - Parameters:
/// - subsystems: The SDL subsystem(s) to start. Default value only initalizes the video subsystem.
public static func start(subsystems: InitSubSystems = .video) {
try! SDL_InitSubSystem(subsystems.rawValue).sdlThrow(type: type(of: self))
try! IMG_Init(Int32(IMG_INIT_PNG.rawValue)).sdlThrow(type: type(of: self))
}
public static func delay(_ ms: UInt32) {
SDL_Delay(ms)
}
public static func quit() {
SDL_Quit()
}
///
public struct InitSubSystems: OptionSet, Sendable {
public let rawValue: UInt32
public init(rawValue: UInt32) {
self.rawValue = rawValue
}
public static let timer = InitSubSystems(rawValue: SDL_INIT_TIMER)
public static let audio = InitSubSystems(rawValue: SDL_INIT_AUDIO)
public static let video = InitSubSystems(rawValue: SDL_INIT_VIDEO)
public static let joystick = InitSubSystems(rawValue: SDL_INIT_JOYSTICK)
public static let haptic = InitSubSystems(rawValue: SDL_INIT_HAPTIC)
public static let gameController = InitSubSystems(rawValue: SDL_INIT_GAMECONTROLLER)
public static let events = InitSubSystems(rawValue: SDL_INIT_EVENTS)
}
public struct InitImageFormats: OptionSet, Sendable {
public let rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
public static let jpg = InitImageFormats(rawValue: 0x00000001)
public static let png = InitImageFormats(rawValue: 0x00000002)
public static let tif = InitImageFormats(rawValue: 0x00000004)
public static let webp = InitImageFormats(rawValue: 0x00000008)
public static let jxl = InitImageFormats(rawValue: 0x000000010)
public static let avif = InitImageFormats(rawValue: 0x00000020)
}
}