Adjusted the naming of the library in the Package file.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
# Getting Started
|
||||
|
||||
Bootstrap the bindings from your game's entry point and drive a frame loop.
|
||||
|
||||
## Overview
|
||||
|
||||
A Playdate game has a single C entry point, `eventHandler`, which the
|
||||
firmware calls with a `PlaydateAPI*` and an event code. Export it with
|
||||
`@_cdecl`, call ``Playdate/initialize(with:)`` on the first event, and
|
||||
install an update callback:
|
||||
|
||||
```swift
|
||||
import CPlaydate
|
||||
import PlaydateKit
|
||||
|
||||
@_cdecl("eventHandler")
|
||||
func eventHandler(
|
||||
pointer: UnsafeMutableRawPointer,
|
||||
event: PDSystemEvent,
|
||||
argument: UInt32
|
||||
) -> Int32 {
|
||||
if case .initialize = SystemEvent(event: event, argument: argument) {
|
||||
Playdate.initialize(with: pointer) // must happen before anything else
|
||||
Game.shared.start()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
final class Game {
|
||||
nonisolated(unsafe) static let shared = Game()
|
||||
|
||||
func start() {
|
||||
Display.setRefreshRate(50)
|
||||
|
||||
System.setUpdateCallback {
|
||||
self.update()
|
||||
return true // true = redraw the display this frame
|
||||
}
|
||||
}
|
||||
|
||||
func update() {
|
||||
let (_, pushed, _) = System.buttonState
|
||||
if pushed.contains(.a) {
|
||||
System.log("A pressed")
|
||||
}
|
||||
|
||||
Graphics.clear(color: .white)
|
||||
Graphics.drawText("Hello, Playdate", x: 8, y: 8)
|
||||
System.drawFPS()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Conventions to know
|
||||
|
||||
- **Initialization.** Calling any wrapper before
|
||||
``Playdate/initialize(with:)`` is a programmer error and will crash.
|
||||
- **Errors.** Fallible operations use typed throws — ``PlaydateError``
|
||||
generally, ``Network/NetError`` for network I/O.
|
||||
- **Ownership.** A wrapper that creates a C object frees it on `deinit`;
|
||||
keep the wrapper referenced for as long as you use it. Wrappers vending
|
||||
OS-owned objects don't free them — keep the owner alive instead, as
|
||||
documented on each API.
|
||||
- **Threading.** The Playdate runtime is single-threaded; don't call the
|
||||
API from other threads.
|
||||
@@ -0,0 +1,61 @@
|
||||
# ``PlaydateKit``
|
||||
|
||||
Swift bindings to the Playdate C API.
|
||||
|
||||
## Overview
|
||||
|
||||
The Playdate C API is delivered as a `PlaydateAPI*` struct of function
|
||||
pointers that the firmware hands to your game at launch. This module wraps
|
||||
that surface in idiomatic Swift: top-level namespaces per subsystem, wrapper
|
||||
types with ownership semantics, closures instead of function-pointer/userdata
|
||||
pairs, `OptionSet`s and `enum`s instead of raw constants, and typed `throws`
|
||||
for fallible calls.
|
||||
|
||||
Call ``Playdate/initialize(with:)`` from your game's `eventHandler` before
|
||||
using anything else — see <doc:GettingStarted>.
|
||||
|
||||
The bindings are written within the Embedded Swift subset, so the same code
|
||||
compiles for the Playdate Simulator and for the device
|
||||
(`armv7em-none-none-eabi`).
|
||||
|
||||
## Topics
|
||||
|
||||
### Essentials
|
||||
|
||||
- <doc:GettingStarted>
|
||||
- ``Playdate``
|
||||
- ``SystemEvent``
|
||||
- ``PlaydateError``
|
||||
|
||||
### System and display
|
||||
|
||||
- ``System``
|
||||
- ``Display``
|
||||
|
||||
### Drawing
|
||||
|
||||
- ``Graphics``
|
||||
- ``Rect``
|
||||
|
||||
### Sprites
|
||||
|
||||
- ``Sprite``
|
||||
|
||||
### Audio
|
||||
|
||||
- ``Sound``
|
||||
|
||||
### Storage
|
||||
|
||||
- ``File``
|
||||
- ``JSON``
|
||||
|
||||
### Connectivity
|
||||
|
||||
- ``Network``
|
||||
- ``Scoreboards``
|
||||
- ``AccessReply``
|
||||
|
||||
### Lua interop
|
||||
|
||||
- ``Lua``
|
||||
Reference in New Issue
Block a user