Browse Source

Reformatted, update GameLib for Statement

This makes things like the preprocessor if statement much easier to
implement
master
Macoy Madson 3 years ago
parent
commit
469b0a8822
  1. 2
      Dependencies/gamelib
  2. 62
      src/Main.cake

2
Dependencies/gamelib

@ -1 +1 @@
Subproject commit 149130eadc08a8af30afe7e523c8151ede4be10c
Subproject commit 5afe9653bc26b881accde7f42fbfb8a841861983

62
src/Main.cake

@ -295,9 +295,9 @@
;; Loaded by PuzzleIO.cake
(defstruct puzzle-data
num-moves char
num-states int
board ([] 36 char))
num-moves char
num-states int
board ([] 36 char))
(var-global g-puzzle-list (* puzzle-data) null)
(var-global g-num-puzzles int 0)
@ -469,7 +469,7 @@
(var action-buffer-read-head (* move-action) (- g-action-buffer-write-head 1))
(when (< action-buffer-read-head g-action-buffer)
(set action-buffer-read-head (+ g-action-buffer
(- (array-size g-action-buffer) 1))))
(- (array-size g-action-buffer) 1))))
;; Nothing to do, the undo buffer is empty
(var piece (* board-piece) (path action-buffer-read-head > piece))
@ -857,7 +857,8 @@
(SDL_Delay todo-arbitrary-delay-ms))
(return exit-reason))
(comptime-cond ('Kitty-Main
(comptime-cond
('Kitty-Main
(defun main (num-args int args ([] (* char)) &return int)
(SDL_Log "Kitty Gridlock\n\n
Created by Macoy Madson <macoy@macoy.me>.\n
@ -1216,7 +1217,7 @@ Rush Hour database from Michael Fogleman.\n\n")
(draw-formatted-string (array 190.f 15.f) "%d" g-num-puzzles-won)
(when g-show-fps ;; Frame rate
(draw-formatted-string (array 700.f 2100.f) "%d" (type-cast (/ 1.f delta-time) int)))
(draw-formatted-string (array 700.f 2100.f) "%d" (type-cast (/ 1.f delta-time) int)))
(when (is-in-win-state)
(unless g-has-won-puzzle
@ -1299,7 +1300,7 @@ Rush Hour database from Michael Fogleman.\n\n")
(array Expression null 1)
(array Keyword " " -1)
(array Expression null 2)
(array Keyword "\n" -1)))
(array KeywordNoSpace "\n" -1)))
(return (c-statement-out define-statement)))
(defgenerator undefine-constant (define-name symbol)
@ -1307,7 +1308,7 @@ Rush Hour database from Michael Fogleman.\n\n")
(array
(array Keyword "#undef" -1)
(array Expression null 1)
(array Keyword "\n" -1)))
(array KeywordNoSpace "\n" -1)))
(return (c-statement-out define-statement)))
;; Necessary to create e.g. in C PREFIX "_my_thing"
@ -1328,30 +1329,18 @@ Rush Hour database from Michael Fogleman.\n\n")
(defgenerator if-c-preprocessor-defined (preprocessor-symbol symbol
true-block (index any) false-block (index any))
;; I had to use addStringOutput because CStatementOutput doesn't yet have a operation for
;; statements, i.e., arguments which should be evaluated in Body scope
(addStringOutput (field output source) "#ifdef" StringOutMod_SpaceAfter
(addr (at startTokenIndex tokens)))
(addStringOutput (field output source) (path preprocessor-symbol > contents)
StringOutMod_NewlineAfter
(addr (at startTokenIndex tokens)))
(var true-context EvaluatorContext context)
(set (field true-context scope) EvaluatorScope_Body)
(unless (= 0 (EvaluateGenerate_Recursive environment true-context tokens true-block output))
(return false))
(addStringOutput (field output source) "#else" StringOutMod_NewlineAfter
(addr (at startTokenIndex tokens)))
(var false-context EvaluatorContext context)
(set (field false-context scope) EvaluatorScope_Body)
(unless (= 0 (EvaluateGenerate_Recursive environment false-context tokens false-block output))
(return false))
(addStringOutput (field output source) "#endif" StringOutMod_NewlineAfter
(addr (at startTokenIndex tokens)))
(return true))
(var statement (const ([] CStatementOperation))
(array
(array Keyword "#ifdef" -1)
(array Expression null 1)
(array KeywordNoSpace "\n" -1)
(array Statement null 2)
(array KeywordNoSpace "#else" -1)
(array KeywordNoSpace "\n" -1)
(array Statement null 3)
(array KeywordNoSpace "#endif" -1)
(array KeywordNoSpace "\n" -1)))
(return (c-statement-out statement)))
(defmacro c-statement-out (statement-operation symbol)
(tokenize-push
@ -1492,11 +1481,12 @@ This tool requires rsync to be installed.\n")
(module-use-sdl-build-options)
(comptime-cond ('Kitty-Main
;; Note that this executable still pulls .so files from Dependencies
(set-cakelisp-option executable-output "../../kitty-gridlock")))
(comptime-cond
('Kitty-Main
;; Note that this executable still pulls .so files from Dependencies
(set-cakelisp-option executable-output "../../kitty-gridlock")))
; This ensures we still find SDL even after we've relocated the executable
;; This ensures we still find SDL even after we've relocated the executable
(add-library-runtime-search-directory "Dependencies/gamelib/Dependencies/SDL/buildSDLBuild/lib")
;; Use build label to make it easier to find in cakelisp_cache

Loading…
Cancel
Save