From dee8feb00333f3510dd6900656d56d4a619dba96 Mon Sep 17 00:00:00 2001 From: ManDude <7569514+ManDude@users.noreply.github.com> Date: Mon, 15 Aug 2022 23:46:29 +0100 Subject: [PATCH] fix a game bug and add a new compiler feature (#1758) * dont crash on inline static value array * [goalc] add support for non-static inline arrays of values * add a kernel group to jak1 * move and cleanup pc debug code * random cleanup in `hud-classes` * pc port fix for gondola spools * format * address feedback (wow it was actually just changing 1 line all along...) * minor decomp cleanup * ref test --- decompiler/config/all-types.gc | 2 +- goal_src/goal-lib.gc | 5 ++ goal_src/jak1/engine/gfx/hw/display-h.gc | 9 +++ goal_src/jak1/engine/target/target-death.gc | 25 ++------ goal_src/jak1/engine/ui/hud-classes.gc | 41 +++---------- goal_src/jak1/examples/display-all-colors.gc | 61 ------------------- goal_src/jak1/game.gp | 8 +++ goal_src/jak1/levels/village3/village3-obs.gc | 10 ++- goal_src/jak1/pc/util/display-font-color.gc | 52 ++++++++++++++++ .../{pc_debug => pc/util}/font-encode-test.gc | 39 +++++------- .../{pc_debug => pc/util}/pc-pad-utils.gc | 14 ++--- goalc/compiler/compilation/Static.cpp | 8 ++- goalc/compiler/compilation/Type.cpp | 11 ++-- .../jak1/engine/target/target-death_REF.gc | 26 ++------ 14 files changed, 134 insertions(+), 177 deletions(-) delete mode 100644 goal_src/jak1/examples/display-all-colors.gc create mode 100644 goal_src/jak1/pc/util/display-font-color.gc rename goal_src/jak1/{pc_debug => pc/util}/font-encode-test.gc (66%) rename goal_src/jak1/{pc_debug => pc/util}/pc-pad-utils.gc (95%) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index ec87b74519..d4ff86ae98 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -21051,7 +21051,7 @@ (define-extern death-movie-remap (function int int int)) (define-extern pov-camera-init-by-other (function vector skeleton-group string pov-camera-flag process-drawable pair none :behavior pov-camera)) ;; TODO - not confirmed -- sunken-elevator (define-extern target-hit-effect (function attack-info none :behavior target)) -(define-extern target-hit-setup-anim (function attack-info object :behavior target)) +(define-extern target-hit-setup-anim (function attack-info none :behavior target)) (define-extern target-hit-move (function attack-info symbol (function none :behavior target) float none :behavior target)) (define-extern target-hit-orient (function attack-info vector symbol :behavior target)) (define-extern target-hit-push (function vector matrix float float attack-info object :behavior target)) diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index 226c131d1f..b5e08c8602 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -878,6 +878,11 @@ `(make-group "iso") ) +(defmacro mkr () + "Make kernel" + `(make-group "kernel") + ) + (defmacro mng () "Make engine" `(make-group "engine") diff --git a/goal_src/jak1/engine/gfx/hw/display-h.gc b/goal_src/jak1/engine/gfx/hw/display-h.gc index deaff89224..680d02d2ba 100644 --- a/goal_src/jak1/engine/gfx/hw/display-h.gc +++ b/goal_src/jak1/engine/gfx/hw/display-h.gc @@ -246,3 +246,12 @@ (defmacro real-current-time () `(-> *display* real-frame-counter) ) + + +;; debug stuff really +(defmacro get-screen-x (frac) + `(the int (* ,frac 512))) + +(defmacro get-screen-y (frac) + `(the int (* ,frac 224))) + diff --git a/goal_src/jak1/engine/target/target-death.gc b/goal_src/jak1/engine/target/target-death.gc index 1327aee2fe..3df6095d27 100644 --- a/goal_src/jak1/engine/target/target-death.gc +++ b/goal_src/jak1/engine/target/target-death.gc @@ -714,25 +714,13 @@ (('back) (when (not (ja-group? eichar-hit-from-back-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-1 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-1 (the-as art-joint-anim eichar-hit-from-back-ja) num-func-identity) - (let ((f0-0 0.0)) - (set! (-> gp-1 frame-num) f0-0) - f0-0 - ) - ) + (ja :group! eichar-hit-from-back-ja :num! min) ) ) (('up 'up-forward) (when (not (ja-group? eichar-hit-up-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-2 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-2 (the-as art-joint-anim eichar-hit-up-ja) num-func-identity) - (let ((f0-1 0.0)) - (set! (-> gp-2 frame-num) f0-1) - f0-1 - ) - ) + (ja :group! eichar-hit-up-ja :num! min) ) ) (('air 'jump) @@ -752,16 +740,11 @@ (else (when (not (ja-group? eichar-hit-from-front-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-5 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-5 (the-as art-joint-anim eichar-hit-from-front-ja) num-func-identity) - (let ((f0-10 0.0)) - (set! (-> gp-5 frame-num) f0-10) - f0-10 - ) - ) + (ja :group! eichar-hit-from-front-ja :num! min) ) ) ) + (none) ) (defbehavior target-hit-move target ((arg0 attack-info) (arg1 symbol) (arg2 (function none :behavior target)) (arg3 float)) diff --git a/goal_src/jak1/engine/ui/hud-classes.gc b/goal_src/jak1/engine/ui/hud-classes.gc index a56ce2661e..3aa4a02483 100644 --- a/goal_src/jak1/engine/ui/hud-classes.gc +++ b/goal_src/jak1/engine/ui/hud-classes.gc @@ -742,38 +742,17 @@ (let ((t9-0 (method-of-type hud draw-hud))) (t9-0 obj) ) - (let* ((s5-0 (-> *display* frames (-> *display* on-screen) frame global-buf)) - (gp-0 (-> s5-0 base)) - ) - (let ((s4-0 draw-string-xy)) - (format (clear *temp-string*) "~D" (-> obj value)) - (s4-0 - *temp-string* - s5-0 - (+ (-> obj text-x) (* (-> obj x-sgn) (-> obj offset))) - (/ (* (+ (-> obj text-y) (* (-> obj y-sgn) (-> obj offset)) (-> obj y-offset)) - (the int (-> *video-parms* relative-y-scale)) + (with-dma-buffer-add-bucket ((buf (-> (current-frame) global-buf)) + (bucket-id debug)) + (draw-string-xy (string-format "~D" (-> obj value)) buf + (+ (-> obj text-x) (* (-> obj x-sgn) (-> obj offset))) + (/ (* (+ (-> obj text-y) (* (-> obj y-sgn) (-> obj offset)) (-> obj y-offset)) + (the int (-> *video-parms* relative-y-scale)) + ) + 2 ) - 2 - ) - (font-color dark-yellow) - (font-flags shadow kerning large) - ) - ) - (let ((a3-7 (-> s5-0 base))) - (let ((v1-8 (the-as dma-packet (-> s5-0 base)))) - (set! (-> v1-8 dma) (new 'static 'dma-tag :id (dma-tag-id next))) - (set! (-> v1-8 vif0) (new 'static 'vif-tag)) - (set! (-> v1-8 vif1) (new 'static 'vif-tag)) - (set! (-> s5-0 base) (&+ (the-as pointer v1-8) 16)) - ) - (dma-bucket-insert-tag - (-> *display* frames (-> *display* on-screen) frame bucket-group) - (bucket-id debug) - gp-0 - (the-as (pointer dma-tag) a3-7) - ) - ) + (font-color dark-yellow) + (font-flags shadow kerning large)) ) 0 (none) diff --git a/goal_src/jak1/examples/display-all-colors.gc b/goal_src/jak1/examples/display-all-colors.gc deleted file mode 100644 index 3a068c8a43..0000000000 --- a/goal_src/jak1/examples/display-all-colors.gc +++ /dev/null @@ -1,61 +0,0 @@ -;;-*-Lisp-*- -(in-package goal) - -;; This script creates a simple process that draws text demonstrating -;; all of GOAL's color constants to the on-screen debug output. - -;; Create somewhere for the handle to the process to live. See https://open-goal.github.io/docs/reference/process_and_state -;; as well as kernel/gstate.gc -(define *color-display-handle* (new 'static 'handle)) -(set! *color-display-handle* (the handle #f)) - - -(defun-debug start-display-text-colors () - "Spawn an onscreen string displaying all possible colors" - (if (not (handle->process *color-display-handle*)) - (let ((disp-proc - (process-spawn-function process :name 'display-proc - (lambda :behavior process () - (stack-size-set! (-> self main-thread) 256) - (loop - ;; These constants live in engine/gfx/font-h.gc - (format *stdcon* "~0k~%~% -~0L 0 default ~1L 1 white -~2L 2 gray ~3L 3 orange-red -~4L 4 bright-orange-red ~5L 5 bright-orange-red -~6L 6 bright-green ~7L 7 dark-blue -~8L 8 light-blue ~9L 9 dark-pink -~10L10 lighter-blue ~11L11 dark-light-blue -~12L12 dim-white ~13L13 dim-gray -~14L14 orange-red-2 ~15L15 yellow-green -~16L16 dark-green ~17L17 another-gray -~18L18 dark-dark-green ~19L19 flat-dark-purple -~20L20 flat-yellow ~21L21 blue-white -~22L22 pad-back ~23L23 pad-shine -~24L24 pad-square ~25L25 pad-circle -~26L26 pad-triangle ~27L27 pad-x -~28L28 lighter-lighter-blue ~29L29 yellow-orange -~30L30 yellow-green-2 ~31L31 another-light-blue -~32L32 light-yellow ~33L33 red-orange -~34L34 another-orange-red~0L~% - alternate names - ~3L3 red ~4L4 red2 ~5L5 yellow ~6L6 green ~7L7 blue - ~10L10 cyan ~33L33 red-reverse ~34L34 red-obverse~0L" - ) - (suspend) - ) - ) - ) - )) - (set! *color-display-handle* (ppointer->handle disp-proc)) - ) - ;; else - (format #t "Colors are already being displayed") - ) - ) - - -(defun-debug stop-display-text-colors () - "Kill the example text color display" - (kill-by-name 'display-proc *active-pool*) - ) diff --git a/goal_src/jak1/game.gp b/goal_src/jak1/game.gp index 914b6d6c15..c32ebe3297 100644 --- a/goal_src/jak1/game.gp +++ b/goal_src/jak1/game.gp @@ -400,6 +400,14 @@ +;;;;;;;;;;;;;;;;;;;;; +;; kernel Group +;;;;;;;;;;;;;;;;;;;;; +;; the kernel group is a group of files required to boot the game kernel + +(group "kernel" "$OUT/iso/KERNEL.CGO") + + ;;;;;;;;;;;;;;;;;;;;; ;; engine Group ;;;;;;;;;;;;;;;;;;;;; diff --git a/goal_src/jak1/levels/village3/village3-obs.gc b/goal_src/jak1/levels/village3/village3-obs.gc index ead7017be3..7ca81bd297 100644 --- a/goal_src/jak1/levels/village3/village3-obs.gc +++ b/goal_src/jak1/levels/village3/village3-obs.gc @@ -152,7 +152,15 @@ (not (movie?)) (not (level-hint-displayed?)) (>= (- (-> *display* base-frame-counter) (-> self state-time)) (seconds 3)) - (file-status *art-control* (-> self anim name) 0) + ;; pc port note : fix gondola spool not loading because it's "too far away" (technically) + (#if (not PC_PORT) + (file-status *art-control* (-> self anim name) 0) + (begin + (spool-push *art-control* (-> self anim name) 0 self (vector-vector-distance + (vector<-cspace! (new 'stack-no-clear 'vector) (-> self node-list data 3)) + (target-pos 0))) + (file-status *art-control* (-> self anim name) 0)) + ) ) ) (let ((s3-0 (get-reminder (get-task-control (game-task village3-button)) 2)) diff --git a/goal_src/jak1/pc/util/display-font-color.gc b/goal_src/jak1/pc/util/display-font-color.gc new file mode 100644 index 0000000000..e2eecfe9ab --- /dev/null +++ b/goal_src/jak1/pc/util/display-font-color.gc @@ -0,0 +1,52 @@ +;;-*-Lisp-*- +(in-package goal) + +;; This script creates a simple process that draws text demonstrating +;; all of GOAL's color constants to the on-screen debug output. + +;; Create somewhere for the handle to the process to live. See https://open-goal.github.io/docs/reference/process_and_state +;; as well as kernel/gstate.gc +(define *color-displays* (new 'global 'inline-array 'handle 1)) + +(defmacro get-color-display-handle () + `(-> *color-displays* 0)) + +(set! (get-color-display-handle) INVALID_HANDLE) + +;; font-color is from font-h.gc +(defun font-color->string ((val font-color)) + "return the name of the font-color" + (enum->string font-color val) + ) + +(defun draw-all-font-colors () + "draws all font color names onscreen" + (with-dma-buffer-add-bucket ((buf (-> (current-frame) debug-buf)) + (bucket-id debug-no-zbuf)) + (dotimes (i 48) + (draw-string-xy (string-format "~2D ~S" i (font-color->string (the font-color i))) buf + (+ 4 (* (get-screen-x 0.5) (mod i 2))) (+ 8 (* 8 (/ i 2))) (the font-color i) (font-flags shadow))) + ) + ) + +(defun start-display-text-colors () + "Spawn an onscreen string displaying all possible colors" + (if (handle->process (get-color-display-handle)) + (format #t "Colors are already being displayed") + ;; else + (set! (get-color-display-handle) + (ppointer->handle (process-spawn-function process :name 'display-proc + (lambda :behavior process () + (loop + (draw-all-font-colors) + (suspend)) + ) + ))) + ) + ) + + +(defun-debug stop-display-text-colors () + "Kill the example text color display" + (kill-by-name 'display-proc *active-pool*) + ) diff --git a/goal_src/jak1/pc_debug/font-encode-test.gc b/goal_src/jak1/pc/util/font-encode-test.gc similarity index 66% rename from goal_src/jak1/pc_debug/font-encode-test.gc rename to goal_src/jak1/pc/util/font-encode-test.gc index 05809eef87..4b1d5ef91a 100644 --- a/goal_src/jak1/pc_debug/font-encode-test.gc +++ b/goal_src/jak1/pc/util/font-encode-test.gc @@ -8,11 +8,9 @@ ;; To run this: #| -(make-group "iso") ;; build the game -(lt) ;; connect to the runtime -(lg) ;; have the runtime load the game engine -(test-play) ;; start the game loop -(ml "goal_src/pc_debug/font-encode-test.gc") ;; build and load this file. +(mi) ;; build the game +(lt) ;; connect to the runtime +(ml "goal_src/jak1/pc/util/font-encode-test.gc") ;; build and load this file. |# @@ -30,8 +28,8 @@ ;;;; functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define *font-string* (new 'global 'string 64 (the-as string #f))) -(define *font-string-ex* "") +(define *font-string* (new 'global 'string 64 (the string #f))) +(define *font-string-ex* (the string #f)) (define *font-string-val* #x96) (defun-debug font-encode-test-start () @@ -40,9 +38,6 @@ (unless (process-by-name 'font-encode *active-pool*) (process-spawn-function process :name 'font-encode (lambda :behavior process () - - (stack-size-set! (-> self main-thread) 768) - (let ((fnt (new 'stack 'font-context *font-default-matrix* FONT_ENCODE_TEXT_LEFT FONT_ENCODE_TEXT_Y 0.0 (font-color orange-red) (font-flags shadow kerning large middle))) ) @@ -54,27 +49,20 @@ (suspend) (if (or (cpad-pressed? 0 left) (cpad-hold? 0 l1)) - (-! *font-string-val* 1) - ) + (-! *font-string-val* 1)) (if (or (cpad-pressed? 0 right) (cpad-hold? 0 r1)) - (+! *font-string-val* 1) - ) - (if (< *font-string-val* 1) - (set! *font-string-val* 1) - ) - (if (> *font-string-val* #x1ff) - (set! *font-string-val* #x1ff) - ) + (+! *font-string-val* 1)) + (minmax! *font-string-val* 1 #x1ff) (clear *font-string*) (cond ((>= *font-string-val* #x100) (set! (-> *font-string* data 0) (/ *font-string-val* 256)) - (set! (-> *font-string* data 1) (mod *font-string-val* 256)) + (set! (-> *font-string* data 1) (logand *font-string-val* #xff)) (set! (-> *font-string* data 2) 0) ) (else - (set! (-> *font-string* data 0) (mod *font-string-val* 256)) + (set! (-> *font-string* data 0) (logand *font-string-val* #xff)) (set! (-> *font-string* data 1) 0) ) ) @@ -82,11 +70,12 @@ (set-origin! fnt FONT_ENCODE_TEXT_LEFT FONT_ENCODE_TEXT_Y) (set-flags! fnt (font-flags shadow kerning large middle)) (print-game-text *font-string* fnt #f 128 24) - (set-origin! fnt FONT_ENCODE_TEXT_LEFT (+ FONT_ENCODE_TEXT_Y 32)) - (print-game-text *font-string-ex* fnt #f 128 24) + (when *font-string-ex* + (set-origin! fnt FONT_ENCODE_TEXT_LEFT (+ FONT_ENCODE_TEXT_Y 32)) + (print-game-text *font-string-ex* fnt #f 128 24)) (set-origin! fnt FONT_ENCODE_TEXT_LEFT (- FONT_ENCODE_TEXT_Y 16)) (set-flags! fnt (font-flags shadow kerning middle)) - (print-game-text (string-format "#x~X" *font-string-val*) fnt #f 128 12) + (print-game-text (string-format "#x~x" *font-string-val*) fnt #f 128 12) ) ) diff --git a/goal_src/jak1/pc_debug/pc-pad-utils.gc b/goal_src/jak1/pc/util/pc-pad-utils.gc similarity index 95% rename from goal_src/jak1/pc_debug/pc-pad-utils.gc rename to goal_src/jak1/pc/util/pc-pad-utils.gc index fd00295898..a240aedaf6 100644 --- a/goal_src/jak1/pc_debug/pc-pad-utils.gc +++ b/goal_src/jak1/pc/util/pc-pad-utils.gc @@ -10,11 +10,9 @@ ;; To run this: #| -(make-group "iso") ;; build the game -(lt) ;; connect to the runtime -(lg) ;; have the runtime load the game engine -(test-play) ;; start the game loop -(ml "goal_src/pc_debug/pc-pad-utils.gc") ;; build and load this file. +(mi) ;; build the game +(lt) ;; connect to the runtime +(ml "goal_src/jak1/pc/util/pc-pad-utils.gc") ;; build and load this file. |# @@ -30,12 +28,12 @@ ) (define *pc-pad-proc-list* (new 'static 'pc-pad-proc-list)) -(set! (-> *pc-pad-proc-list* show) (the handle #f)) -(set! (-> *pc-pad-proc-list* input) (the handle #f)) +(set! (-> *pc-pad-proc-list* show) INVALID_HANDLE) +(set! (-> *pc-pad-proc-list* input) INVALID_HANDLE) ;; a pc pad process (deftype pc-pad-proc (process) - ((state-time int64) + ((state-time time-frame) (input-index uint64) (pad-idx int64) ) diff --git a/goalc/compiler/compilation/Static.cpp b/goalc/compiler/compilation/Static.cpp index a172284acc..8c1a40149e 100644 --- a/goalc/compiler/compilation/Static.cpp +++ b/goalc/compiler/compilation/Static.cpp @@ -1052,7 +1052,7 @@ StaticResult Compiler::fill_static_inline_array(const goos::Object& form, // get all arguments now auto args = get_list_as_vector(rest); if (args.size() < 4) { - throw_compiler_error(form, "new static boxed array must have type and min-size arguments"); + throw_compiler_error(form, "new static inline array must have type and min-size arguments"); } auto content_type = parse_typespec(args.at(2), env); s64 min_size = get_constant_integer_or_error(args.at(3), env); @@ -1060,8 +1060,10 @@ StaticResult Compiler::fill_static_inline_array(const goos::Object& form, auto inline_array_type = m_ts.make_inline_array_typespec(content_type); auto deref_info = m_ts.get_deref_info(inline_array_type); - ASSERT(deref_info.can_deref); - ASSERT(!deref_info.mem_deref); + if (!deref_info.can_deref || deref_info.mem_deref) { + throw_compiler_error(form, "new static inline array of type {} is currently not supported", + content_type.print()); + } auto obj = std::make_unique(seg); obj->set_offset(is_basic(content_type) ? 4 : 0); obj->data.resize(length * deref_info.stride); diff --git a/goalc/compiler/compilation/Type.cpp b/goalc/compiler/compilation/Type.cpp index 30b438a043..bbc3144bf3 100644 --- a/goalc/compiler/compilation/Type.cpp +++ b/goalc/compiler/compilation/Type.cpp @@ -982,8 +982,9 @@ Val* Compiler::compile_heap_new(const goos::Object& form, throw_compiler_error(form, "new array form got more arguments than expected"); } - auto ts = is_inline ? m_ts.make_inline_array_typespec(elt_type) - : m_ts.make_pointer_typespec(elt_type); + auto ts = is_inline && m_ts.lookup_type(elt_type)->is_reference() + ? m_ts.make_inline_array_typespec(elt_type) + : m_ts.make_pointer_typespec(elt_type); auto info = m_ts.get_deref_info(ts); if (!info.can_deref) { throw_compiler_error(form, "Cannot make an {} of {}\n", main_type.print(), ts.print()); @@ -1003,9 +1004,9 @@ Val* Compiler::compile_heap_new(const goos::Object& form, args.push_back(array_size); } - auto array = compile_real_function_call(form, malloc_func, args, env); - array->set_type(ts); - return array; + auto new_array = compile_real_function_call(form, malloc_func, args, env); + new_array->set_type(ts); + return new_array; } else { bool got_content_type = false; // for boxed array std::string content_type; // for boxed array. diff --git a/test/decompiler/reference/jak1/engine/target/target-death_REF.gc b/test/decompiler/reference/jak1/engine/target/target-death_REF.gc index baa50b097b..9eba9cd403 100644 --- a/test/decompiler/reference/jak1/engine/target/target-death_REF.gc +++ b/test/decompiler/reference/jak1/engine/target/target-death_REF.gc @@ -713,30 +713,19 @@ ) ;; definition for function target-hit-setup-anim +;; INFO: Return type mismatch object vs none. (defbehavior target-hit-setup-anim target ((arg0 attack-info)) (case (-> arg0 angle) (('back) (when (not (ja-group? eichar-hit-from-back-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-1 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-1 (the-as art-joint-anim eichar-hit-from-back-ja) num-func-identity) - (let ((f0-0 0.0)) - (set! (-> gp-1 frame-num) f0-0) - f0-0 - ) - ) + (ja :group! eichar-hit-from-back-ja :num! min) ) ) (('up 'up-forward) (when (not (ja-group? eichar-hit-up-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-2 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-2 (the-as art-joint-anim eichar-hit-up-ja) num-func-identity) - (let ((f0-1 0.0)) - (set! (-> gp-2 frame-num) f0-1) - f0-1 - ) - ) + (ja :group! eichar-hit-up-ja :num! min) ) ) (('air 'jump) @@ -756,16 +745,11 @@ (else (when (not (ja-group? eichar-hit-from-front-ja)) (ja-channel-push! 1 (seconds 0.075)) - (let ((gp-5 (-> self skel root-channel 0))) - (joint-control-channel-group-eval! gp-5 (the-as art-joint-anim eichar-hit-from-front-ja) num-func-identity) - (let ((f0-10 0.0)) - (set! (-> gp-5 frame-num) f0-10) - f0-10 - ) - ) + (ja :group! eichar-hit-from-front-ja :num! min) ) ) ) + (none) ) ;; definition for function target-hit-move