migrate to SDL3_image

This commit is contained in:
candy committed 2024-10-24 18:29:07 -04:00
1 parent e84c85fbac
commit 7665786c61
13 files changed
+45 -54

No files matched your search

+3 -14
View File
@@ -14,20 +14,9 @@ let package = Package(
dependencies: [
"SDL",
"CSDL3",
//"CSDL2_Image",
]),
.target(name: "SDL", dependencies: ["CSDL3"/*, "CSDL2_Image" */]),
.systemLibrary(name: "CSDL3", pkgConfig: "sdl3"//,
//providers: [
// .brew(["sdl2"]),
// .apt(["libsdl2-dev"])
//]
)
//.systemLibrary(name: "CSDL2_Image", pkgConfig: "SDL2_image",
// providers: [
// .brew(["sdl2_image"]),
// .apt(["libsdl2_image-dev"])
// ]
//)
.target(name: "SDL", dependencies: ["CSDL3", "CSDL3_Image"]),
.systemLibrary(name: "CSDL3", pkgConfig: "sdl3"),
.systemLibrary(name: "CSDL3_Image", pkgConfig: "sdl3-image")
]
)
-5
View File
@@ -1,5 +0,0 @@
module CSDL2_Image [system] {
header "shim.h"
link "SDL2"
export *
}
+1 -1
View File
@@ -1,4 +1,4 @@
module CSDL2 [system] {
module CSDL3 [system] {
header "shim.h"
link "SDL3"
export *
+5
View File
@@ -0,0 +1,5 @@
module CSDL3_Image [system] {
header "shim.h"
link "SDL3"
export *
}
@@ -1,5 +1,5 @@
#ifdef __APPLE__
#include "/opt/homebrew/include/SDL2/SDL_image.h"
#else
#include <SDL2/SDL_image.h>
#include <SDL3_image/SDL_image.h>
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
import SDL
import CSDL2
import CSDL3
let puzzle = [
[0,0,0,0,0,1,0,0,0,0],
+11 -8
View File
@@ -1,5 +1,5 @@
import CSDL2
//import CSDL2_Image
import CSDL3
import CSDL3_Image
public struct Engine {
@@ -9,10 +9,14 @@ public struct Engine {
///
/// - 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))
public static func start(subsystems: InitSubSystems = .video, imageFormats: InitImageFormats = .png) {
guard SDL_InitSubSystem(subsystems.rawValue) else {
fatalError("SDL failed to start: \(SDLError.current()?.errorMessage ?? "Failed to obtain error message!")")
}
//try! IMG_Init(Int32(IMG_INIT_PNG.rawValue)).sdlThrow(type: type(of: self))
guard IMG_Init(imageFormats.rawValue) == imageFormats.rawValue else {
fatalError("SDL_image failed to start: \(SDLError.current()?.errorMessage ?? "Failed to obtain error message!")")
}
}
public static func delay(_ ms: UInt32) {
@@ -23,7 +27,6 @@ public struct Engine {
SDL_Quit()
}
///
public struct InitSubSystems: OptionSet, Sendable {
public let rawValue: UInt32
@@ -42,9 +45,9 @@ public struct Engine {
}
public struct InitImageFormats: OptionSet, Sendable {
public let rawValue: Int32
public let rawValue: UInt32
public init(rawValue: Int32) {
public init(rawValue: UInt32) {
self.rawValue = rawValue
}
+1 -1
View File
@@ -1,4 +1,4 @@
import CSDL2
import CSDL3
public class EventHandler {
var handle: SDL_Event
+1 -1
View File
@@ -1,4 +1,4 @@
import CSDL2
import CSDL3
public class Renderer {
var handle: OpaquePointer
+3 -2
View File
@@ -1,4 +1,4 @@
import CSDL2
import CSDL3
public struct SDLError: Error {
@@ -64,6 +64,7 @@ internal extension SDLError {
SDL_ClearError()
let errorDescription = String(cString: cString)
print(errorDescription)
return SDLError(errorMessage: errorDescription, debugInformation: debugInformation)
}
@@ -92,7 +93,7 @@ internal extension Bool {
function: String = #function,
line: UInt = #line) throws(SDLError) {
guard self == false else {
guard self else {
let debugInformation = SDLError.DebugInformation(file: file, type: type, function: function, line: line)
guard let error = SDLError.current(debugInformation: debugInformation) else {
assertionFailure("No error for error code \(self)")
+11 -11
View File
@@ -1,14 +1,14 @@
//import CSDL2
//import CSDL2_Image
import CSDL3
import CSDL3_Image
//public class Surface {
// var handle: UnsafeMutablePointer<SDL_Surface>
public class Surface {
var handle: UnsafeMutablePointer<SDL_Surface>
// public init(from imagePath: String) throws {
// handle = try IMG_Load(imagePath).sdlThrow(type: type(of: self))
// }
public init(from imagePath: String) throws {
handle = try IMG_Load(imagePath).sdlThrow(type: type(of: self))
}
// deinit {
// SDL_FreeSurface(handle)
// }
//}
deinit {
SDL_DestroySurface(handle)
}
}
+6 -8
View File
@@ -1,6 +1,5 @@
import Foundation
import CSDL2
//import CSDL2_Image
import CSDL3
import CSDL3_Image
/// An efficent, driver-specific representation of pixel data.
@@ -64,8 +63,7 @@ public class Texture {
/// - renderer: The `Renderer` to attach the created `Texture` to.
/// - Throws: ``SDLError`` on failure.
public init(from imagePath: String, renderer: Renderer) throws(SDLError) {
fatalError("init(from imagePath:renderer:) TODO")
//handle = try IMG_LoadTexture(renderer.handle, imagePath).sdlThrow(type: type(of: self))
handle = try IMG_LoadTexture(renderer.handle, imagePath).sdlThrow(type: type(of: self))
}
/// Creates a ``Texture`` from an existing surface.
@@ -76,9 +74,9 @@ public class Texture {
/// - surface: The ``Surface`` structure containing pixel data used to fill the ``Texture``.
/// - renderer: The ``Renderer`` to attach the newly created ``Texture`` to.
/// - Throws: ``SDLError`` on failure.
//public init(from surface: Surface, renderer: Renderer) throws(SDLError) {
// handle = try SDL_CreateTextureFromSurface(renderer.handle, surface.handle).sdlThrow(type: type(of: self))
//}
public init(from surface: Surface, renderer: Renderer) throws(SDLError) {
handle = try SDL_CreateTextureFromSurface(renderer.handle, surface.handle).sdlThrow(type: type(of: self))
}
/// Calls SDL_DestroyTexture on the texture. Should be safe.
deinit {
+1 -1
View File
@@ -1,4 +1,4 @@
import CSDL2
import CSDL3
public class Window {
let handle: OpaquePointer