Playdate - a cool gaming console with limited memory and CPU power

Related tags

Games swift-pd
Overview

Swift for Playdate

Playdate is a cool gaming console with limited memory and CPU power. Swift is a cool language which can be compiled to run efficiently on a wide range of devices. This is a proof of concept of what it could be like to write Playdate apps using Swift, but there are currenly many limitations.

Most importantly, you can only run apps on the Playdate Simulator, on an Apple Silicon Mac.

This repo implements the "Hello World" app from the SDK's C_API examples.

Requirements

  • On a Mac with Apple Silicon (i.e. M1)
  • Install the Playdate SDK (version 1.9.2 works)
  • Install swiftc, probably as part of Xcode (I used 13.1)

Build

Navigate to the directory containing one of the examples (or your own app) and run the build script:

$ cd Examples/SpriteGame
$ ../../build.sh

This script runs swift build to compile your app (along with the API wrappers, writing a .dylib and a bunch of other junk under .build/

Then it runs pdc to assemble any images, fonts, etc. from the directory Sources/Resources, into (for example) SpriteGame.pdx (which is actually a directory.)

Finally, it copies the app executable into the pdx and you should be ready to go.

Run

$ open SpriteGame.pdx

Or just double-click the .pdx icon.

If you want to see your Swift print() output (or anything else written to stdout), then run the simulator like this:

$ ~/"Developer/PlaydateSDK/bin/Playdate Simulator.app/Contents/MacOS/Playdate Simulator" HelloWorld.pdx

Or just use System.logToConsole() to send messages to the console window in the UI. Note: to format messages, use Swift's string interpolation, not Lua's, for example System.logToConsole("This is cool: \(awesomeness > 0.80)").

Starting an app from scratch

You just need a directory with these files:

./
  Package.swift
  Sources/
    MyApp/
      TheApp.swift
    Resources/
      pdxinfo

Take a look at Examples/HelloWorld/ for the bare minumum you need to get going.

Update the various target names and the relative path to the swift-pd package in your Package.swift. Then run build.sh from your directory.

Caveats

Your app built this way will not run on the Playdate hardware, only in the simulator. It would probably be possible to get something like this to work for building games to run on the device, but it looks like it will take a lot more effort and knowledge.

If anything goes wrong, the simulator might refuse to load the app, or give a confusing error, or just crash.

There are probably lots of Swift language/library features that won't work at all. And lots that will work in the Simulator but don't really make sense for the device.

Only a portion the the Playdate API is currently wrapped in nice Swift syntax, including basic input and drawing, and sprites. Additional APIs are often easy to add, but it can be tedious. With the current structure, you can't talk directly to the raw C APIs from your app, but you have the library source, so feel free to add what you need and submit a PR if you're feeling like sharing.

This might actually work on an Intel Mac, or on Linux or Windows, with some changes. If you try it and get somewhere, submit a PR.

I haven't tried to get Xcode to build the app. Imagine connecting the debugger to your Swift app running in the simulator. And keep imagining it, because it's definitely not happening at the moment.

Credit

@ericlewis worked out some details to get this off the ground. See this devforum thread for the full story.

This is only possible due to the amazing work of the Playdate and Swift teams. I don't know how either of them would feel about this being a real thing, but it's thanks to them that even an ugly hack like this can be done.

You might also like...
🦁 🃏 📱 An animal matching puzzle card game– built with turn-based game engine boardgame.io and React-Native + React-Native-Web
🦁 🃏 📱 An animal matching puzzle card game– built with turn-based game engine boardgame.io and React-Native + React-Native-Web

Matchimals.fun an animal matching puzzle card game 🦁 🃏 🍎 Download for iOS from the App Store 🤖 Download for Android from the Google Play Store 🖥

A Modern MUD Client for iPhone and iPad.
A Modern MUD Client for iPhone and iPad.

MUDRammer — A Modern MUD Client invoke incantation of build status divination You move a hand through a series of quick gestures, your digits twin

3D Shoot'em Up written with OpenGL ES 1.1/2.0 running on iOS, Android, Windows and MacOS X.
3D Shoot'em Up written with OpenGL ES 1.1/2.0 running on iOS, Android, Windows and MacOS X.

SHMUP This is the source code of "SHMUP" a 3D Shoot 'em up that I wrote in 2009. It is very inspired of Treasure Ikaruga, the engine runs on iOS, Andr

Spare Parts is a 2D physics game that lets you build silly contraptions and machines.

Spare Parts Spare Parts is a 2D physics game that lets you build silly contraptions and machines. The goal for this project is: 100% of the code is op

Switshot is a game media manager helps you transfer your game media from Nintendo Switch to your phone, and manage your media just few taps.
Switshot is a game media manager helps you transfer your game media from Nintendo Switch to your phone, and manage your media just few taps.

Switshot is a game media manager helps you transfer your game media from Nintendo Switch to your phone, and manage your media just few taps.

Mobile IOS Game App Developed by Haemi Lee, Dominika Popov, and Dylan Walsh

VroombaWars Mobile IOS Game App Developed by Haemi Lee, Dominika Popov, and Dylan Walsh Why clean your room in real life when you can have a virtual v

The ultimate spinning wheel view that supports dynamic content and rich customization.
The ultimate spinning wheel view that supports dynamic content and rich customization.

The ultimate spinning wheel control that supports dynamic content and rich customization. Main Features 🏵 Dynamic content, supports texts, images, an

PokaPlayer's native client for iOS and macOS
PokaPlayer's native client for iOS and macOS

PokaNative PokaPlayer's native client for iOS and macOS Installation Get the ipa file from Releases. Use some software like AltStore to install the ip

The Classic game TicTacToe made using SwiftUI and MVVM architecture

The Classic game TicTacToe made using SwiftUI and MVVM architecture

Comments
  • SpriteGame example leaks memory; crashes after a few minutes

    SpriteGame example leaks memory; crashes after a few minutes

    Looking at "Mallog Log", memory is continuously consumed, with many objects of a handful of sizes (7160, 5196, 1198, 1171, 1024, 976 bytes).

    It doesn't seem to matter too much what user behavior is going on.

    The crash is when the game tries to load the font and catches an error (i.e. null result):

    SpriteGame/SpriteGame.swift:52: Fatal error: no font
    Trace/BPT trap: 5
    

    Presumably related to the way bitmaps that get associated with sprites are being retained, and therefore presumably would be fixed by just pre-loading those images as the original does.

    Ideally, fix it without pre-loading, to show that refcounting can be made to work.

    opened by mossprescott 1
  • Fix leaks

    Fix leaks

    Turns out you do need to free Font instances, and you can do that with realloc(font, 0). That was worth 5KB on every frame.

    There was a bug in SpriteGame where it would try load explosion/0, which doesn't exist. That would lead to a null pointer being freed, but only later on, since I had disabled garbage collection for bitmaps used with sprites, thinking the issue was more subtle.

    In addition to fixing that, now throwing a RuntimeError immediately if any bitmap or font load produces null.

    With those two fixes, SpriteGame now runs for a long time in 100 KB.

    opened by mossprescott 0
  • Add support for building separate apps; SpriteGame example

    Add support for building separate apps; SpriteGame example

    Switched to SPM for builds, with a legitimate swift-pd/Playdate package you can include as a dependency in a separate package.

    Still using a dumb bash script for builds, but at least I can now include more than a single trivial example.

    Ported the example C game "SpriteGame", along with the Bitmap, Sprite, and input APIs it required. That was fairly involved and turned up a lot of fun issues with refcounting, capturing closures vs C function pointers, and so on. Anyway a lot of stuff is there now so the next app should port more easily.

    opened by mossprescott 0
Owner
Moss Prescott
Moss Prescott
🖐 Memory game with hand gesture recognition that will keep your brain in a good shape!

Hands I have always been interested in how I can improve my memory in addition to reading books, and once I came across an interesting technique relat

Tamerlan Satualdypov 35 Dec 19, 2022
Simple memory game written in Swift 4 using VIPER Architecture.

Viper Memory Game Simple memory game written in Swift 4.2 using VIPER Architecture. The Memory Game is a deck of cards where the user needs to find ma

Mati 23 Jun 6, 2022
The one and only open source 4X MMO mid-core strategy game for iOS. Similar to Game of War and Mobile Strike

4X MMO Strategy Game for iOS I have spent 4 years of my life and a significant amount of money into completing this game and I hope you enjoy it. For

shankqr 69 Nov 16, 2022
iPhone and iPod Touch version of Skeleton Key: is an addictive and unique puzzle game in which you shift keys around the board unlocking treasure chests. Made with cocos2d-iphone.

Skeleton Key (iOS) Skeleton Key is an addictive and unique puzzle game in which you shift keys around the board unlocking treasure chests. It's availa

null 117 Jun 6, 2022
Recreating the Poketch from Pokemon Diamond and Pearl on the Apple Watch with SwiftUI and WatchOS 8

Apple Watch Poketch What is it? It's an Apple Watch remake of the "Poketch" from Pokemon Diamond and Pearl made with SwiftUI! Check out the YouTube vi

Idrees Hassan 297 Dec 31, 2022
XCode and Swift game based on the generation of random cards and some functions related to the comparison of the results.

war-card-game-V1 XCode and Swift game based on the generation of random cards and some functions related to the comparison of the results. Once a card

Eduard 1 Dec 10, 2021
Gamer-s-Collection - An app for searching and saving favorite games using rawg.io api and Core Data

Gamer-s-Collection - An app for searching and saving favorite games using rawg.io api and Core Data

Rıdvan İmren 1 Aug 19, 2022
Glide is a SpriteKit and GameplayKit based engine for building 2d games easily

Glide is a SpriteKit and GameplayKit based engine for building 2d games easily, with a focus on side scrollers. Glide is developed with Swift and works on iOS, macOS and tvOS.

null 433 Jan 6, 2023
A game engine built with SDL and Swift.

Lark A game engine made with Swift and SDL. This is a pre-alpha work-in-progress. Don't try to use this unless you really know what you're doing. I ba

June Bash 41 Mar 11, 2022
Solitaire mahjong game with several themes and layouts. For android/iphone/ubuntu/firefoxos

green-mahjong Green Mahjong is a HTML5 based GPLv3 solitaire mahjong game. It features three nice themes, six different layouts and works accross all

Daniel Beck 82 Dec 25, 2022