Skip to content

Commit 867de1f

Browse files
authored
Remove fmt package and protobuf (#21)
1 parent d0c19c1 commit 867de1f

28 files changed

Lines changed: 683 additions & 728 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ dist/
1212
*.exe
1313
*.wat
1414
*.wasm
15+
*.dcmp
1516
*.mi
1617
*.zip

.golangci.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2025 Kalle Fagerberg
2+
#
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
version: "2"
6+
7+
linters:
8+
default: standard
9+
enable:
10+
- depguard
11+
- gocritic
12+
13+
settings:
14+
depguard:
15+
rules:
16+
firefly:
17+
deny:
18+
- pkg: fmt
19+
desc: Formatting package is too big
20+
21+
gocritic:
22+
enable-all: true
23+
disabled-checks:
24+
- importShadow
25+
- singleCaseSwitch
26+
- commentedOutCode

.zed/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-FileCopyrightText: 2025 Kalle Fagerberg
2+
//
3+
// SPDX-License-Identifier: CC0-1.0
4+
5+
// Folder-specific settings
6+
//
7+
// For a full list of overridable settings, and general information on folder-specific settings,
8+
// see the documentation: https://zed.dev/docs/configuring-zed#settings-files
9+
{
10+
"file_types": {
11+
"C": ["*.dcmp"],
12+
},
13+
}

REUSE.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ version = 1
77
[[annotations]]
88
path = [
99
"**/*.go",
10-
"**/*.proto",
1110
"assets/*.png",
1211
"assets/*.pxo",
1312
]

go.mod

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ module github.com/applejag/epic-wizard-firefly-gladiators
33
go 1.25.5
44

55
require (
6-
github.com/aperturerobotics/protobuf-go-lite v0.11.0
76
github.com/applejag/firefly-go-math v0.2.0
87
github.com/firefly-zero/firefly-go v0.10.0
98
github.com/orsinium-labs/tinymath v1.1.0
109
)
11-
12-
require google.golang.org/protobuf v1.36.11 // indirect
13-
14-
tool (
15-
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite
16-
google.golang.org/protobuf/cmd/protoc-gen-go
17-
)

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
github.com/aperturerobotics/protobuf-go-lite v0.11.0 h1:IAaZISqrEpodqECYxk0yKWgROEbZtMhs7bErP+Zma9o=
2-
github.com/aperturerobotics/protobuf-go-lite v0.11.0/go.mod h1:c4kGy7Dkfz6B1m0t4QBIMQoNeQ7m+nYj3Qxxnlwhygo=
31
github.com/applejag/firefly-go-math v0.2.0 h1:IiDXTbHpLDU8LR8LP3RKGpyUA59mQp2HwAdkDyLLask=
42
github.com/applejag/firefly-go-math v0.2.0/go.mod h1:XbmMPAO9vDIYvwAJIPlY6HE0m1RZ3tXgn3GP9agFXos=
53
github.com/firefly-zero/firefly-go v0.10.0 h1:CFEVPrXdLCZYgMna2DMncZ+lR01xg3danlXtIw+dJkE=
64
github.com/firefly-zero/firefly-go v0.10.0/go.mod h1:+X/XGyPdES51OESkV8NSf1mszEBZionoROM7x2pBofw=
7-
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
8-
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
95
github.com/orsinium-labs/tinymath v1.1.0 h1:KomdsyLHB7vE3f1nRAJF2dyf1m/gnM2HxfTeV1vS5UA=
106
github.com/orsinium-labs/tinymath v1.1.0/go.mod h1:WPXX6ei3KSXG7JfA03a+ekCYaY9SWN4I+JRl2p6ck+A=
11-
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
12-
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=

mise.toml

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,87 @@
55
[tools]
66
uv = "latest"
77
"pipx:reuse" = "latest"
8-
protoc = "33.4"
9-
protoc-gen-go = "1.36.11"
108
"aqua:tinygo-org/tinygo" = "0.40.1"
119
"github:firefly-zero/firefly-cli"= { version = "0.15.8", rename_exe = "ff" }
1210
"github:firefly-zero/firefly-emulator" = "0.9.8"
13-
14-
[tasks."install:tools"]
15-
description = "Install protoc plugins"
16-
run = "go install tool"
17-
18-
[tasks."build:generate"]
19-
# using https://github.com/aperturerobotics/protobuf-go-lite
20-
description = "Generate protobuf files"
21-
run = """
22-
: "${GOBIN:="$(go env GOBIN)"}"
23-
: "${GOBIN:="$(go env GOPATH)/bin"}"
24-
protoc \
25-
--go-lite_out=proto --plugin protoc-gen-go-lite="${GOBIN}/protoc-gen-go-lite" \
26-
--go-lite_opt=features=size+marshal+unmarshal \
27-
proto/game/v1/gamestate.proto
28-
"""
29-
sources = ['proto/game/v1/*.proto']
30-
outputs = ['proto/game/v1/*.go']
31-
depends = ['install:tools']
11+
"github:wwwg/wasmdec" = "latest"
12+
golangci-lint = "2.8.0"
3213

3314
[tasks.build]
3415
description = "Build the game using firefly CLI"
3516
run = "ff build"
36-
depends = ['build:generate']
3717

38-
[tasks."build:print-allocs"]
18+
[tasks."debug:print-allocs"]
3919
description = "Build with tinygo and print allocations"
4020
run = """
41-
tinygo build -print-allocs "$(basename "$PWD")|firefly-go" -buildmode c-shared -target target.json -o /dev/null \
21+
tinygo build -print-allocs "$(basename "$PWD")|firefly-go|.*" -buildmode c-shared -target target.json -o /dev/null \
4222
2>&1 | sed "s|^$PWD/|./|; s|^$HOME/|~/|"
4323
"""
4424

25+
[tasks."debug:build:tinygo"]
26+
description = "Build with tinygo"
27+
run = """
28+
tinygo build -target target.json -buildmode c-shared -o dist/ewfg.wasm .
29+
"""
30+
sources = ['**/*.go', 'go.mod', 'go.sum', 'assets/**']
31+
outputs = ['dist/ewfg.wasm']
32+
33+
[tasks."debug:build:opt"]
34+
description = """
35+
Optimize the debug binary with wasm-opt
36+
37+
Basically the same command used by firefly-cli, but with extra `--debuginfo`.
38+
https://github.com/firefly-zero/firefly-cli/blob/6bfc4b02369577d5073145ea0c53a6168771907a/src/wasm.rs#L79-L99
39+
"""
40+
run = """
41+
wasm-opt \
42+
-Oz \
43+
--disable-exception-handling \
44+
--disable-gc \
45+
--disable-typed-function-references \
46+
--enable-bulk-memory \
47+
--enable-extended-const \
48+
--enable-memory64 \
49+
--enable-multivalue \
50+
--enable-mutable-globals \
51+
--enable-nontrapping-float-to-int \
52+
--enable-reference-types \
53+
--enable-relaxed-simd \
54+
--enable-sign-ext \
55+
--enable-simd \
56+
--enable-tail-call \
57+
-o dist/ewfg-opt.wasm \
58+
--debuginfo \
59+
dist/ewfg.wasm
60+
"""
61+
wait_for = ['debug:build:tinygo']
62+
sources = ['dist/ewfg.wasm']
63+
outputs = ['dist/ewfg-opt.wasm']
64+
65+
[tasks."debug:build"]
66+
description = "Build and optimize the game using wasm-opt (with debug symbols on)"
67+
depends = ['debug:build:tinygo', 'debug:build:opt']
68+
69+
[tasks."debug:wasm2wat"]
70+
description = "Build the game and output the WAT"
71+
run = """
72+
wasm2wat dist/ewfg.wasm --output=dist/ewfg.wat
73+
wasm2wat dist/ewfg-opt.wasm --output=dist/ewfg-opt.wat
74+
"""
75+
depends = ['debug:build']
76+
sources = ['dist/ewfg.wasm', 'dist/ewfg-opt.wasm']
77+
outputs = ['dist/ewfg.wat', 'dist/ewfg-opt.wat']
78+
79+
[tasks."debug:wasm-decompile"]
80+
description = "Build the game and decompile into the .dcmp pseudo-language"
81+
run = """
82+
wasm-decompile dist/ewfg.wasm --output=dist/ewfg.dcmp
83+
wasm-decompile dist/ewfg-opt.wasm --output=dist/ewfg-opt.dcmp
84+
"""
85+
depends = ['debug:build']
86+
sources = ['dist/ewfg.wasm', 'dist/ewfg-opt.wasm']
87+
outputs = ['dist/ewfg.dcmp', 'dist/ewfg-opt.dcmp']
88+
4589
[tasks.start]
4690
description = "Run the game using firefly emulator"
4791
run = "firefly-emulator --id applejag.ewfg"

pkg/game/scenemanager.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package game
22

33
import (
4-
"fmt"
5-
64
"github.com/applejag/epic-wizard-firefly-gladiators/assets"
75
"github.com/applejag/epic-wizard-firefly-gladiators/pkg/scenes"
86
"github.com/applejag/epic-wizard-firefly-gladiators/pkg/scenes/field"
@@ -31,19 +29,30 @@ type SceneManager struct {
3129

3230
// SwitchScene implements [scenes.SceneSwitcher].
3331
func (s *SceneManager) SwitchScene(scene scenes.Scene) {
32+
prev := s.currentScene
3433
s.nextScene = scene
3534
s.Transition.Play()
36-
firefly.LogDebug(fmt.Sprintf("switching scene from %q to %q", s.currentScene, scene))
3735
s.onSceneSwitch(scene)
36+
37+
var buf [22 + scenes.LongestSceneName + 6 + scenes.LongestSceneName + 1]byte
38+
written := util.ConcatInto(buf[:],
39+
"switching scene from '", prev.String(), "' to '", scene.String(), "'",
40+
)
41+
util.LogDebugBytes(buf[:written])
3842
}
3943

4044
func (s *SceneManager) SwitchSceneNoTransition(scene scenes.Scene) {
4145
prev := s.currentScene
4246
s.nextScene = scene
4347
s.currentScene = scene
4448
s.Transition.Stop()
45-
firefly.LogDebug(fmt.Sprintf("switching scene from %q to %q (without transition)", prev, scene))
4649
s.onSceneSwitch(scene)
50+
51+
var buf [22 + scenes.LongestSceneName + 6 + scenes.LongestSceneName + 22]byte
52+
written := util.ConcatInto(buf[:],
53+
"switching scene from '", prev.String(), "' to '", scene.String(), "' (without transition)",
54+
)
55+
util.LogDebugBytes(buf[:written])
4756
}
4857

4958
func (s *SceneManager) Boot() {

pkg/scenes/field/fireflymodal_stats.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ func (p *StatsPage) Render(innerScrollPoint firefly.Point, fireflyID int) {
8484

8585
text := p.cachedFireflyNameText
8686
if text == "" {
87+
var buf [util.LongestPossibleName]byte
8788
text = util.WordWrap(
88-
data.Name.String(),
89+
string(buf[:data.Name.WriteInto(buf[:])]),
8990
scrollInnerWidth,
9091
assets.FontEG_6x9.CharWidth(),
9192
)

pkg/scenes/field/scene.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ func (s *Scene) Render() {
104104

105105
if len(s.fireflies) > 0 {
106106
if idx := s.FindFireflyByID(s.focusedID); idx != -1 {
107-
s.renderFocused(s.fireflies[idx])
107+
s.renderFocused(&s.fireflies[idx])
108108
}
109109
}
110110

111111
s.shopButtonAnim.Draw(firefly.P(firefly.Width-46, firefly.Height-16))
112112
}
113113

114-
func (s *Scene) renderFocused(f Firefly) {
114+
func (s *Scene) renderFocused(f *Firefly) {
115115
pos := f.pos.Round().Point()
116116
s.highlight.Draw(pos.Sub(firefly.P(15, 15)))
117117

@@ -123,8 +123,9 @@ func (s *Scene) renderFocused(f Firefly) {
123123

124124
text := s.cachedFireflyNameText
125125
if text == "" {
126+
var buf [util.LongestPossibleName]byte
126127
text = util.WordWrap(
127-
data.Name.String(),
128+
string(buf[:data.Name.WriteInto(buf[:])]),
128129
firefly.Width-75,
129130
assets.FontEG_6x9.CharWidth(),
130131
)
@@ -157,8 +158,8 @@ func (s *Scene) OnSceneEnter() {
157158
})
158159
s.cachedFireflyNameText = ""
159160
s.fireflyIDs = make([]int, len(s.fireflies))
160-
for i, f := range s.fireflies {
161-
s.fireflyIDs[i] = f.id
161+
for i := range s.fireflies {
162+
s.fireflyIDs[i] = s.fireflies[i].id
162163
}
163164
slices.Sort(s.fireflyIDs)
164165
}

0 commit comments

Comments
 (0)