Skip to content

[WIP] Adopt Slab for SwiftBreak #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/SwiftBreak/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ guard let home = Context.environment["HOME"] else {
let swiftSettingsSimulator: [SwiftSetting] = [
.enableExperimentalFeature("Embedded"),
.enableExperimentalFeature("NoncopyableGenerics"),
.enableExperimentalFeature("ValueGenerics"),
.unsafeFlags([
"-Xfrontend", "-disable-objc-interop",
"-Xfrontend", "-disable-stack-protector",
Expand Down
14 changes: 7 additions & 7 deletions Examples/SwiftBreak/Sources/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Sprites: ~Copyable {
var ball: Sprite
var paddle: Sprite
var gameOver: Sprite
var bricks: FixedArray<Sprite>
var bricks: Slab<40, Sprite>
}

struct ActiveGame {
Expand Down Expand Up @@ -46,7 +46,7 @@ struct Game: ~Copyable {
ball: .ball(),
paddle: .paddle(),
gameOver: .gameOver(),
bricks: .init(count: 40, first: brick) { $0.copy() })
bricks: .init(first: brick) { $0.copy() })
Sprite.drawSprites()
self.state = .loading
}
Expand Down Expand Up @@ -125,13 +125,13 @@ extension Game {

let brickWidth = 40
let brickHeight = 24
sprites.bricks.enumerated { index, brick in
for index in sprites.bricks.indices {
let x = (index % 10)
let y = (index / 10)
brick.moveTo(
sprites.bricks[index].moveTo(
x: Float(x * brickWidth + brickWidth / 2),
y: Float(y * brickHeight + brickHeight / 2))
brick.addSprite()
sprites.bricks[index].addSprite()
}
activeGame.bricksRemaining = sprites.bricks.count

Expand All @@ -154,8 +154,8 @@ extension Game {
mutating func gameOver() {
self.sprites.ball.removeSprite()
self.sprites.paddle.removeSprite()
self.sprites.bricks.forEach { brick in
brick.removeSprite()
for i in self.sprites.bricks.indices {
self.sprites.bricks[i].removeSprite()
}
self.sprites.gameOver.moveTo(
x: Float(LCD_COLUMNS / 2),
Expand Down
1 change: 1 addition & 0 deletions Examples/swift.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ SWIFT_FLAGS := \
$(addprefix -Xcc , $(C_FLAGS)) \
-O \
-wmo -enable-experimental-feature Embedded \
-enable-experimental-feature ValueGenerics \
-Xfrontend -disable-stack-protector \
-Xfrontend -function-sections \
-swift-version 6 \
Expand Down