Up to date with Playdate SDK version 2.6
Odin-lang API bindings for the Playdate SDK, used to develop games for the Playdate handheld game system.
- Custom allocator for Playdate memory allocations (
new()
,make()
, etc should work as expected) - Custom logger for Playdate logging system (
core:log
procedures should work as expected)
- Download the Playdate SDK for your development platform.
- Make sure you have the
PLAYDATE_SDK_PATH
environment variable set to the directory you installed it to.
WIP - Expected to change
@(export)
eventHandler :: proc "c" (pd_api: ^playdate.Api, event: playdate.System_Event, arg: u32) -> i32 {}
import "base:runtime"
import "playdate"
import "core:log"
global_ctx : runtime.Context
// Call on eventHandler .Init
my_init :: proc "contextless" (pd: ^playdate.Api) {
global_ctx = playdate.playdate_context_create(pd)
}
// Call on eventHandler .Terminate
my_terminate :: proc "contextless" () {
playdate.playdate_context_destroy(&global_ctx)
}
update :: proc "c" (user_data: rawptr) -> playdate.Update_Result {
context = global_ctx
my_slice := make([]string, 99) // allocates using pd.system.realloc
delete(my_slice)
log.info("Hellope") // logs to Playdate console
return .Update_Display
}
From here, follow the official Playdate C guide for Game Initialization.
WIP - Expected to change
- Copy the build scripts from
playdate/_scripts
to the root directory of your project. - Add the directories
out_sim
andout_device
to your .gitignore file.
- Create an intermediate directory that the shared library will be compiled into, and an output directory, e.g. "./intermediate/" and "./out/"
- Compile your Odin project into your intermediate directory as a shared library with no default allocators
odin build . -out=intermediate/pdex.dll -build-mode:shared -default-to-nil-allocator
- Compile the intermediate directory using the Playdate Compiler, into your output directory
$PLAYDATE_SDK_PATH/bin/pdc intermediate/ out/Game_Name.pdx
- Run the simulator with your game
$PLAYDATE_SDK_PATH/bin/PlaydateSimulator out/Game_Name.pdx
Note: if you don't need a temporary allocator or you need as much memory as possible, the following Odin build flags are available:
-define:NO_PLAYDATE_TEMP_ALLOCATOR
to not create a temporary allocator withplaydate_context_create
(you can provide your own later)-define:DEFAULT_TEMP_ALLOCATOR_BACKING_SIZE=<n_bytes>
to resize the default temporary allocator arena (default: 4MB, with provided build script: 1MB)
Please feel free to contribute! Here is the current implementation status of each API feature:
- ➕ Implemented
- ➖ Partially implemented (see Notes)
- ❌ Not implemented
Package | C bindings | Tests | Notes |
---|---|---|---|
display |
➕ | ❌ | |
file |
➕ | ❌ | |
graphics |
➕ | ❌ | |
json |
➕ | ❌ | |
lua |
➕ | ❌ | |
scoreboards |
➕ | ❌ | Only approved games can use Scoreboards API |
sound |
➕ | ❌ | |
sprite |
➕ | ❌ | |
system |
➕ | ❌ |