Browse Source

Some light clean-up

master
Macoy Madson 3 years ago
parent
commit
01bce56e41
  1. 18
      src/Main.cake
  2. 16
      src/PuzzleIO.cake

18
src/Main.cake

@ -273,7 +273,8 @@
;; - x wall (fixed obstacle)
;; - A primary piece (red car)
;; - B - Z all other pieces
;; I used lowercase ~o~ instead of periods ~.~ for the empty cells in the database so that the entire board description can be selected with a double-click.
;; I used lowercase ~o~ instead of periods ~.~ for the empty cells in the database so that the
;; entire board description can be selected with a double-click.
;; Example format:
;; 60 IBBxooIooLDDJAALooJoKEEMFFKooMGGHHHM 2332
(defun-local game-board-load (board-string (* (const char)) &return bool)
@ -521,7 +522,7 @@
(SDL_WriteLE32 save-file g-progression-file-version)
(SDL_WriteLE32 save-file g-num-puzzles-won)
(SDL_RWclose save-file))
(printf "warning: failed to save progression file\n")))
(SDL_Log "warning: failed to save progression file\n")))
(defun-local read-progression-data ()
(var save-file (* SDL_RWops) (SDL_RWFromFile g-save-file-name "r"))
@ -529,12 +530,12 @@
(scope
(var version int (SDL_ReadLE32 save-file))
(unless (= version g-progression-file-version)
(printf "warning: failed to load progression file (version mismatch). Progress will be lost\n")
(SDL_Log "warning: failed to load progression file (version mismatch). Progress will be lost\n")
(SDL_RWclose save-file)
(return))
(set g-num-puzzles-won (SDL_ReadLE32 save-file))
(SDL_RWclose save-file))
(printf "warning: failed to load progression file\n")))
(SDL_Log "warning: failed to load progression file\n")))
;;
;; UI (immediate-mode)
;;
@ -1032,12 +1033,15 @@ Rush Hour database from Michael Fogleman.\n\n")
(set exit-reason "Render error"))
(scope ;; UI
(when (do-button (addr in-state) (array 10.f 10.f) (array 166.f 166.f) renderer theme-button-texture)
(when (do-button (addr in-state) (array 10.f 10.f) (array 166.f 166.f)
renderer theme-button-texture)
(set is-day-mode (not is-day-mode)))
(when (do-button (addr in-state) (array 190.f 1900.f) (array 166.f 166.f) renderer undo-button-texture)
(when (do-button (addr in-state) (array 190.f 1900.f) (array 166.f 166.f)
renderer undo-button-texture)
(unless selected-piece ;; Don't allow undo while also moving another piece
(undo-action)))
(when (do-button (addr in-state) (array 724.f 1900.f) (array 166.f 166.f) renderer next-button-texture)
(when (do-button (addr in-state) (array 724.f 1900.f) (array 166.f 166.f)
renderer next-button-texture)
(game-board-load-next-puzzle)))
;; (when (not is-day-mode) ;; Draw grid

16
src/PuzzleIO.cake

@ -79,18 +79,18 @@
(defun-local write-puzzles-binary (filename (* (const char)) &return bool)
(unless g-num-puzzles
(printf "No puzzles to write\n")
(SDL_Log "No puzzles to write\n")
(return false))
(var puzzles-file (* SDL_RWops) (SDL_RWFromFile filename "w"))
(unless puzzles-file
(printf "Failed to open puzzles output file\n")
(SDL_Log "Failed to open puzzles output file\n")
(return false))
(SDL_WriteLE32 puzzles-file g-puzzle-binary-version)
(SDL_WriteLE32 puzzles-file g-num-puzzles)
(unless (SDL_RWwrite puzzles-file g-puzzle-list (sizeof (type puzzle-data)) g-num-puzzles)
(printf "Failed to write puzzles\n")
(SDL_Log "Failed to write puzzles\n")
(return false))
(SDL_RWclose puzzles-file)
@ -102,28 +102,28 @@
(set g-puzzle-list null))
(var puzzles-file (* SDL_RWops) (SDL_RWFromFile filename "r"))
(unless puzzles-file
(printf "Failed to open puzzles output file\n")
(SDL_Log "Failed to open puzzles output file\n")
(return false))
(var version Uint32 (SDL_ReadLE32 puzzles-file))
(unless (= g-puzzle-binary-version version)
(printf "Version mismatch: expected %d, got %d\n" g-puzzle-binary-version version)
(SDL_Log "Version mismatch: expected %d, got %d\n" g-puzzle-binary-version version)
(return false))
(set g-num-puzzles (SDL_ReadLE32 puzzles-file))
(unless g-num-puzzles
(printf "No puzzles to read\n")
(SDL_Log "No puzzles to read\n")
(return false))
(set g-puzzle-list (type-cast (calloc g-num-puzzles (sizeof (type puzzle-data))) (* puzzle-data)))
(unless (SDL_RWread puzzles-file g-puzzle-list (sizeof (type puzzle-data)) g-num-puzzles)
(printf "Failed to read puzzles\n")
(SDL_Log "Failed to read puzzles\n")
(return false))
;; Not even sure if this will work, but I don't care too much about this
(var test-num-moves int (field (at 0 g-puzzle-list) num-moves))
(when (or (< test-num-moves 0) (> test-num-moves 60))
(printf "Possible endianness mismatch. Puzzles will need to be loaded with converted endianness\n")
(SDL_Log "Possible endianness mismatch. Puzzles will need to be loaded with converted endianness\n")
(return false))
(SDL_RWclose puzzles-file)

Loading…
Cancel
Save