diff --git a/Building.md b/Building.md index 60512f0..442897c 100644 --- a/Building.md +++ b/Building.md @@ -15,6 +15,7 @@ - [Build on macOS from scratch](#build-on-macos-from-scratch) - [WebAssembly](#webassembly) - [Build Tags](#build-tags) + - [doodad](#doodad) - [dpp](#dpp) # Dockerfile @@ -373,6 +374,13 @@ Some tips to get a WASM build to work: Go build tags used by this game: +## doodad + +This tag is used when building the `doodad` command-line tool. + +It ensures that the embedded bindata assets (built-in doodads, etc.) do not +need to be bundled into the doodad binary, but only the main game binary. + ## dpp The dpp tag stands for Doodle++ and is used for official commercial builds of diff --git a/Makefile b/Makefile index 0efce21..8fb40ca 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ setup: clean .PHONY: build build: go build $(LDFLAGS) $(BUILD_TAGS) -o bin/sketchymaze cmd/doodle/main.go - go build $(LDFLAGS) $(BUILD_TAGS) -o bin/doodad cmd/doodad/main.go + go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go # `make buildall` to run all build steps including doodads. .PHONY: buildall @@ -34,7 +34,7 @@ buildall: doodads build build-free: gofmt -w . go build $(LDFLAGS) -o bin/sketchymaze cmd/doodle/main.go - go build $(LDFLAGS) -o bin/doodad cmd/doodad/main.go + go build $(LDFLAGS) -tags=doodad -o bin/doodad cmd/doodad/main.go # `make bindata` generates the embedded binary assets package. .PHONY: bindata @@ -75,7 +75,7 @@ mingw: go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS) $(BUILD_TAGS) -o bin/doodad.exe cmd/doodad/main.go + go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go # `make mingw32` to cross-compile a Windows binary with mingw (32-bit). .PHONY: mingw32 @@ -85,7 +85,7 @@ mingw32: go build $(LDFLAGS_W) $(BUILD_TAGS) -o bin/sketchymaze.exe cmd/doodle/main.go env CGO_ENABLED="1" CC="/usr/bin/i686-w64-mingw32-gcc" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS) $(BUILD_TAGS) -o bin/doodad.exe cmd/doodad/main.go + go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go # `make mingw-free` for Windows binary in free mode. .PHONY: mingw-free @@ -95,7 +95,7 @@ mingw-free: go build $(LDFLAGS_W) -o bin/sketchymaze.exe cmd/doodle/main.go env CGO_ENABLED="1" CC="/usr/bin/x86_64-w64-mingw32-gcc" \ GOOS="windows" CGO_LDFLAGS="-lmingw32 -lSDL2" CGO_CFLAGS="-D_REENTRANT" \ - go build $(LDFLAGS) -o bin/doodad.exe cmd/doodad/main.go + go build $(LDFLAGS) -tags=doodad -o bin/doodad.exe cmd/doodad/main.go # `make release` runs the release.sh script, must be run # after `make dist` diff --git a/assets/assets_embed.go b/assets/assets_embed.go index ac18c67..2a73cda 100644 --- a/assets/assets_embed.go +++ b/assets/assets_embed.go @@ -1,3 +1,6 @@ +//go:build !doodad +// +build !doodad + // Package assets gets us off go-bindata by using Go 1.16 embed support. // // For Go 1.16 embed, this source file had to live inside the assets/ folder diff --git a/assets/assets_omitted.go b/assets/assets_omitted.go new file mode 100644 index 0000000..7f94524 --- /dev/null +++ b/assets/assets_omitted.go @@ -0,0 +1,32 @@ +//go:build doodad +// +build doodad + +// Dummy version of assets_embed.go that doesn't embed any files. +// For the `doodad` tool. + +package assets + +import ( + "embed" + "errors" +) + +var Embedded embed.FS + +var errNotEmbedded = errors.New("assets not embedded") + +// AssetDir returns the list of embedded files at the directory name. +func AssetDir(name string) ([]string, error) { + return nil, errNotEmbedded +} + +// Asset returns the byte data of an embedded asset. +func Asset(name string) ([]byte, error) { + return nil, errNotEmbedded +} + +// AssetNames dumps the names of all embedded assets, +// with their legacy "assets/" prefix from go-bindata. +func AssetNames() []string { + return nil +} diff --git a/cmd/doodad/commands/resave.go b/cmd/doodad/commands/resave.go index 495b162..e317c2b 100644 --- a/cmd/doodad/commands/resave.go +++ b/cmd/doodad/commands/resave.go @@ -101,6 +101,12 @@ func resaveDoodad(c *cli.Context, filename string) error { filename = output } + if err := dd.Vacuum(); err != nil { + log.Error("Vacuum error: %s", err) + } else { + log.Info("Run vacuum on doodad file.") + } + log.Info("Saving back to disk") if err := dd.WriteJSON(filename); err != nil { return fmt.Errorf("couldn't write %s: %s", filename, err) diff --git a/pkg/branding/branding.go b/pkg/branding/branding.go index 1c2a332..cad8053 100644 --- a/pkg/branding/branding.go +++ b/pkg/branding/branding.go @@ -9,7 +9,7 @@ import ( const ( AppName = "Sketchy Maze" Summary = "A drawing-based maze game" - Version = "0.14.0" + Version = "0.14.1" Website = "https://www.sketchymaze.com" Copyright = "2023 Noah Petherbridge" Byline = "a game by Noah Petherbridge." diff --git a/pkg/doodads/fmt_maintenance.go b/pkg/doodads/fmt_maintenance.go new file mode 100644 index 0000000..9b3099b --- /dev/null +++ b/pkg/doodads/fmt_maintenance.go @@ -0,0 +1,14 @@ +package doodads + +// Vacuum runs any maintenance or migration tasks for the level at time of save. +// +// It will prune broken links between actors, or migrate internal data structures +// to optimize storage on disk of its binary data. +func (m *Doodad) Vacuum() error { + // Let the Chunker optimize accessor types. + for _, layer := range m.Layers { + layer.Chunker.OptimizeChunkerAccessors() + } + + return nil +} diff --git a/pkg/doodads/fmt_readwrite.go b/pkg/doodads/fmt_readwrite.go index a50ae80..3d8e0bb 100644 --- a/pkg/doodads/fmt_readwrite.go +++ b/pkg/doodads/fmt_readwrite.go @@ -164,6 +164,11 @@ func (d *Doodad) WriteFile(filename string) error { d.Version = 1 d.GameVersion = branding.Version + // Maintenance functions, clean up cruft before save. + if err := d.Vacuum(); err != nil { + log.Error("Vacuum level %s: %s", filename, err) + } + bin, err := d.ToJSON() if err != nil { return err diff --git a/pkg/level/chunker_migrate.go b/pkg/level/chunker_migrate.go index 5b70fe2..60fce35 100644 --- a/pkg/level/chunker_migrate.go +++ b/pkg/level/chunker_migrate.go @@ -36,8 +36,11 @@ func (c *Chunker) OptimizeChunkerAccessors() { ma, _ := chunk.Accessor.(*MapAccessor) rle := NewRLEAccessor(chunk).FromMapAccessor(ma) + // Lock the chunker for updating. + c.chunkMu.Lock() c.Chunks[point].Type = RLEType c.Chunks[point].Accessor = rle + c.chunkMu.Unlock() } } }