jak3: fix hud sprite crash + add entity debugger (#3516)

This commit is contained in:
ManDude 2024-05-13 04:09:25 +01:00 committed by GitHub
parent d1ece445d4
commit ebbbedabc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 584 additions and 166 deletions

View File

@ -36,6 +36,9 @@
#define ASSERT_NOT_REACHED_MSG(STR) \
(void)((private_assert_failed("not reached", __FILE__, __LINE__, __PRETTY_FUNCTION__, STR), 0))
#define ASSERT_EQ_IMM(EXPR, EXPECTED) \
ASSERT_MSG((EXPR) == (EXPECTED), fmt::format("result was {}, expected {}", (EXPR), (EXPECTED)))
#else
#define ASSERT(EX) ((void)0)

View File

@ -28512,8 +28512,6 @@
(name symbol :offset-assert 8) ;; guessed by decompiler
(process process-drawable :offset-assert 12) ;; guessed by decompiler
(curve curve :inline :offset-assert 16)
(num-cverts int32 :offset 20)
(cverts uint32 :offset 16)
)
:method-count-assert 32
:size-assert #x24

View File

@ -728,11 +728,9 @@
["lcit", 0, 0],
["pow", 0, 0],
["wasintro", 0, 0],
["wasintro-vis", 0, 0],
["lfacctyb", 0, 0],
["intpfall", 0, 0],
["lfaccity", 0, 0],
["lfacctyb-vis", 0, 0],
["ltowcity", 0, 0],
["powergd", 0, 0],
["lcitysml", 0, 0]

View File

@ -183,11 +183,11 @@
"DGO/RAILF.DGO",
"DGO/RAILX.DGO",
// // precursor
// "DGO/PRECA.DGO",
// "DGO/PRECB.DGO",
// "DGO/PRECC.DGO",
"DGO/PRECA.DGO",
"DGO/PRECB.DGO",
"DGO/PRECC.DGO",
// "DGO/PRECD.DGO",
// title/intro
// // title/intro
"DGO/WIN.DGO", // wasintro
"DGO/TITLE.DGO",
"DGO/INTTITLE.DGO",
@ -195,15 +195,15 @@
"DGO/IPF.DGO", // intro-palace-fall
"DGO/INTROCST.DGO",
// // outro
// "DGO/OUTCAST3.DGO",
// "DGO/OUTROCST.DGO",
"DGO/OUTCAST3.DGO",
"DGO/OUTROCST.DGO",
// // museum
// "DGO/MUSEUM.DGO",
// "DGO/MUSEUM2.DGO",
// "DGO/MUSEUM3.DGO",
// "DGO/MUSEUM3B.DGO",
// "DGO/MUSEUM4.DGO",
// "DGO/MUSEUM4B.DGO",
"DGO/MUSEUM.DGO",
"DGO/MUSEUM2.DGO",
"DGO/MUSEUM3.DGO",
"DGO/MUSEUM3B.DGO",
"DGO/MUSEUM4.DGO",
"DGO/MUSEUM4B.DGO",
// test
"DGO/HALFPIPE.DGO",
// borrow

View File

@ -28,25 +28,9 @@ namespace decompiler {
std::optional<ObjectFileRecord> get_bsp_file(const std::vector<ObjectFileRecord>& records,
const std::string& dgo_name) {
std::optional<ObjectFileRecord> result;
bool found = false;
for (auto& file : records) {
if (file.name.length() > 4 && file.name.substr(file.name.length() - 4) == "-vis") {
ASSERT(!found);
found = true;
result = file;
}
}
if (!result) {
if (str_util::ends_with(dgo_name, ".DGO") || str_util::ends_with(dgo_name, ".CGO")) {
auto expected_name = dgo_name.substr(0, dgo_name.length() - 4);
for (auto& c : expected_name) {
c = tolower(c);
}
if (!records.empty() && expected_name == records.back().name) {
return records.back();
}
}
if (str_util::ends_with(dgo_name, ".DGO")) {
// only DGOs are valid levels, and the last file is the bsp file
result = records.at(records.size() - 1);
}
return result;
}

View File

@ -378,6 +378,9 @@ void Sprite3::render_2d_group1(DmaFollower& dma,
case GameVersion::Jak2:
ASSERT(run.vifcode1().immediate == SpriteProgMem::Sprites2dHud_Jak2);
break;
case GameVersion::Jak3:
ASSERT_EQ_IMM(run.vifcode1().immediate, (int)SpriteProgMem::Sprites2dHud_Jak3);
break;
default:
ASSERT_NOT_REACHED();
}

View File

@ -205,6 +205,7 @@ enum SpriteProgMem {
Sprites2dGrp0 = 3, // world space 2d sprites
Sprites2dHud_Jak1 = 109, // hud sprites
Sprites2dHud_Jak2 = 115,
Sprites2dHud_Jak3 = 143,
Sprites3d = 211 // 3d sprites
};
@ -241,4 +242,4 @@ struct SpriteGlowConsts {
math::Vector4f clamp_min;
math::Vector4f clamp_max;
};
static_assert(sizeof(SpriteGlowConsts) == 0x180);
static_assert(sizeof(SpriteGlowConsts) == 0x180);

View File

@ -69,6 +69,7 @@ int start_overlord(int, const char* const*) {
param.initPriority = 0x73;
param.stackSize = 0x1000;
param.option = 0;
strcpy(param.name, "Loader"); // added
SndPlayThread = thread_player;
auto thread_loader = CreateThread(&param);
if (thread_loader <= 0) {

View File

@ -844,35 +844,6 @@
(when *debug-segment*
(deftype entity-debug-inspect (basic)
(
(scroll-y int16)
(scroll-y-max int16)
(entity entity)
(show-actor-info symbol)
(show-long-info symbol)
)
(:methods
(new (symbol type) _type_)
(set-entity! (_type_ entity) entity)
(update-pad (_type_ int) none)
)
)
(defmethod new entity-debug-inspect ((allocation symbol) (type-to-make type))
"make a new entity-debug-inspect object"
(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> obj scroll-y) 0)
(set! (-> obj scroll-y-max) 0)
(set! (-> obj entity) (the entity #f))
(set! (-> obj show-actor-info) #f)
(set! (-> obj show-long-info) #f)
obj
)
)
(defmethod update-pad entity-debug-inspect ((obj entity-debug-inspect) (pad-idx int))
"respond to pad inputs"
@ -893,9 +864,6 @@
(none))
(define *entity-debug-inspect* (new 'debug 'entity-debug-inspect))
) ;; when debug_segment

View File

@ -566,3 +566,44 @@
(defun-extern real-movie? symbol)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; entity debugging
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(when *debug-segment*
(deftype entity-debug-inspect (basic)
(
(scroll-y int16)
(scroll-y-max int16)
(entity entity)
(show-actor-info symbol)
(show-long-info symbol)
)
(:methods
(new (symbol type) _type_)
(set-entity! (_type_ entity) entity)
(update-pad (_type_ int) none)
)
)
(defmethod new entity-debug-inspect ((allocation symbol) (type-to-make type))
"make a new entity-debug-inspect object"
(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> obj scroll-y) 0)
(set! (-> obj scroll-y-max) 0)
(set! (-> obj entity) (the entity #f))
(set! (-> obj show-actor-info) #f)
(set! (-> obj show-long-info) #f)
obj
)
)
(define *entity-debug-inspect* (new 'debug 'entity-debug-inspect))
) ;; when debug_segment

View File

@ -471,4 +471,5 @@
"ragdoll-test.o"
"debris.o"
"shield-sphere.o"
"entity-debug.o" ;; added
))

View File

@ -3879,10 +3879,8 @@
)
)
(set! (-> this is-spooling?) (nonzero? (res-lump-value arg0 'spooling-val uint128 :time -1000000000.0)))
;; og:preserve-this some entities store their path data in the path1 lump
(let ((bad-entity? (symbol-member? (string->symbol (-> this name)) '(sound-on-path-119))))
(set! (-> this path) (new 'process 'path-control this (#if PC_PORT (if bad-entity? 'path1 'path) 'path) 0.0 arg0 #f))
)
;; og:preserve-this
(set! (-> this path) (new 'process 'path-control this (#if PC_PORT (if (string= (-> this name) "sound-on-path-119") 'path1 'path) 'path) 0.0 arg0 #f))
(logior! (-> this path flags) (path-control-flag display draw-line draw-point draw-text))
(logclear! (-> this mask) (process-mask actor-pause))
;; og:preserve-this

View File

@ -1921,6 +1921,64 @@
(update-eyes)
)
(when *debug-segment*
;; do all debug drawing.
(#when PC_PORT
(when (and (or (= *master-mode* 'game) (= *master-mode* 'pause)))
(when (-> *entity-debug-inspect* entity)
(define-extern entity-inspect-draw (function entity-debug-inspect object))
(entity-inspect-draw *entity-debug-inspect*)
)
;; go through active levels
(dotimes (lev-i (-> *level* length))
(let ((lev (-> *level* level lev-i)))
(when (= (-> lev status) 'active)
(let ((region-trees (-> lev bsp region-trees)))
(when (nonzero? region-trees)
(let* ((s3-5 (-> region-trees length))
(tree-i 0)
(region-tree (-> region-trees tree-i))
)
(while (< tree-i s3-5)
(let ((tree-name (-> region-tree name)))
(let* ((s0-4 (-> region-tree data2 (+ (-> region-tree length) -1) length))
(i 0)
(region (-> (the-as drawable-inline-array-region-prim (-> region-tree data2 (+ (-> region-tree length) -1))) data i))
)
(while (< i s0-4)
(let ((draw? #f))
(when (and *display-region-inside* (!= tree-name 'water) (point-in-region-debug! (-> region region) (target-pos 0)))
(true! draw?)
(format *stdcon* "~1kinside region-~D [~A] (l: ~A)~%" (-> region region id) tree-name (-> lev name)))
(when (and *region-debug-inspect* (or (= *region-debug-inspect* region) (and *merge-region-prims* (= (-> region region id) (-> *region-debug-inspect* region id)))))
(when (= *region-debug-inspect* region)
(format *stdcon* "~1kinspecting region-~D [~A] (l: ~A)~%" (-> *region-debug-inspect* region id) tree-name (-> lev name))
(format *stdcon* " on-enter: ~A~%" (-> *region-debug-inspect* region on-enter))
(format *stdcon* " on-inside: ~A~%" (-> *region-debug-inspect* region on-inside))
(format *stdcon* " on-exit: ~A~%" (-> *region-debug-inspect* region on-exit))
)
(true! draw?)
)
(when draw?
(set! *debug-region-color-alt* (= tree-name 'camera))
(debug-draw-region region 0)))
(set! i (+ i 1))
(set! region (-> (the-as drawable-inline-array-region-prim (-> region-tree data2 (+ (-> region-tree length) -1))) data i))
)
)
)
(+! tree-i 1)
(set! region-tree (-> region-trees tree-i))
)
)
)
)
)
)
)
)
(if *debug-track-skill*
(debug-track-skill))
)
(with-profiler 'debug *profile-debug-color*
(debug-draw-buffers)
)

View File

@ -23,12 +23,10 @@ Although it contains a `curve`, the knot part is not populated, so it's just tre
a bunch of line segments from the control points.
The child class curve-control does fill out the knot data and is a proper b-spline.
These path-controls are typically allocated on a process heap."
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
(num-cverts int32 :overlay-at (-> curve num-cverts))
(cverts uint32 :overlay-at (-> curve cverts))
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
)
(:methods
(new (symbol type process symbol float entity symbol) _type_)

View File

@ -1894,9 +1894,9 @@
)
;;(.lui fg-work 28672)
(set! fg-work (scratchpad-object foreground-work))
;; (with-pc
;; (when (-> *pc-settings* force-envmap?)
;; (set! dist-in 0.0)))
(with-pc
(when (-> *pc-settings* force-envmap?)
(set! dist-in 0.0)))
(let* ((bone-calc (the-as bone-calculation (-> dma-buf base)))
(matrix-mem (the-as object (&+ (the-as pointer bone-calc) 64)))
)

View File

@ -268,10 +268,10 @@
(cgo-file "railf.gd" common-dep)
(cgo-file "railx.gd" common-dep)
; ;; precursor
; (cgo-file "preca.gd" common-dep)
; (cgo-file "precb.gd" common-dep)
; (cgo-file "precc.gd" common-dep)
; (cgo-file "precd.gd" common-dep)
(cgo-file "preca.gd" common-dep)
(cgo-file "precb.gd" common-dep)
(cgo-file "precc.gd" common-dep)
;; (cgo-file "precd.gd" common-dep)
; ;; title/intro
(cgo-file "win.gd" common-dep) ;; wasintro
(cgo-file "title.gd" common-dep)
@ -280,15 +280,15 @@
(cgo-file "ipf.gd" common-dep) ;; intro-palace-fall
(cgo-file "introcst.gd" common-dep)
; ;; outro
; (cgo-file "outcast3.gd" common-dep)
; (cgo-file "outrocst.gd" common-dep)
(cgo-file "outcast3.gd" common-dep)
(cgo-file "outrocst.gd" common-dep)
; ;; museum
; (cgo-file "museum.gd" common-dep)
; (cgo-file "museum2.gd" common-dep)
; (cgo-file "museum3.gd" common-dep)
; (cgo-file "museum3b.gd" common-dep)
; (cgo-file "museum4.gd" common-dep)
; (cgo-file "museum4b.gd" common-dep)
(cgo-file "museum.gd" common-dep)
(cgo-file "museum2.gd" common-dep)
(cgo-file "museum3.gd" common-dep)
(cgo-file "museum3b.gd" common-dep)
(cgo-file "museum4.gd" common-dep)
(cgo-file "museum4b.gd" common-dep)
;; test
(cgo-file "halfpipe.gd" common-dep)
; ;; borrow

View File

@ -879,17 +879,6 @@
(flag "On" #t dm-subtitle-setting)
(flag "Auto" auto dm-subtitle-setting)
)
(menu "Text language"
;; TODO macro
(flag "english" (the binteger (pc-language english)) dm-text-language)
(flag "french" (the binteger (pc-language french)) dm-text-language)
(flag "german" (the binteger (pc-language german)) dm-text-language)
(flag "spanish" (the binteger (pc-language spanish)) dm-text-language)
(flag "italian" (the binteger (pc-language italian)) dm-text-language)
(flag "japanese" (the binteger (pc-language japanese)) dm-text-language)
(flag "korean" (the binteger (pc-language korean)) dm-text-language)
(flag "uk-english" (the binteger (pc-language uk-english)) dm-text-language)
)
(flag "Discord RPC" #t ,(dm-lambda-boolean-flag (-> *pc-settings* discord-rpc?)))
(flag "Speedrunner Mode" #t ,(dm-lambda-boolean-flag (-> *pc-settings* speedrunner-mode?)))
;; (flag "Speedrunner Mode" #t ,(dm-lambda-boolean-flag (-> *pc-settings* speedrunner-mode?)))

View File

@ -0,0 +1,338 @@
;;-*-Lisp-*-
(in-package goal)
#|
Entity debugging utilities.
|#
(declare-file (debug))
(define *debug-temp-string* (new 'debug 'string 4096 (the string #f)))
(defmethod set-entity! entity-debug-inspect ((obj entity-debug-inspect) (e entity))
"set the entity to inspect"
(set! (-> obj entity) e)
(set! (-> obj scroll-y) 0)
e
)
(defun entity-inspect-draw ((inspect-info entity-debug-inspect))
"draw text about an entity on screen"
(let ((LINE_HEIGHT (the int (ceil (* (get-debug-font-scale-factor) 15)))))
(update-pad inspect-info 0)
(let* ((e (-> inspect-info entity)) (name (res-lump-struct e 'name string)))
(debug-actor (the string (and (type-type? (-> e type) entity-actor) (-> inspect-info show-actor-info) name)))
(set! *display-race-marks* (race-marks-controls all-off))
(case (-> e type)
((entity-race-mesh)
(set! *display-race-marks* (race-marks-controls all-paths-on))
;(debug-draw-edges (-> (the entity-race-mesh e) race-mesh))
)
((entity-nav-mesh)
(debug-draw (the entity-nav-mesh e)))
(else
;; draw trans
(add-debug-x #t (bucket-id debug-no-zbuf1) (-> e trans) (static-rgba 255 255 0 128))
(add-debug-text-3d #t (bucket-id debug-no-zbuf1) name (-> e trans) (font-color red) (new 'static 'vector2h :y 8))
)
)
;; start writing text
(let* ((begin-y (- (* 2 LINE_HEIGHT) (* (-> inspect-info scroll-y) LINE_HEIGHT))) (cur-y begin-y) (y-adv LINE_HEIGHT))
(with-dma-buffer-add-bucket ((debug-buf (-> (current-frame) debug-buf))
(bucket-id debug-no-zbuf1))
;; basic info, actor id, etc
(draw-string-xy
(string-format "~3L~A~0L ~A~%tags: ~D size: ~D aid: #x~x level: ~S~%R1/L1 to scroll UP toggle display-long-info~%--------------------" (-> e type) name (length e) (asize-of e) (-> e aid) (aif (-> e extra) (-> it level name)))
debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y (* LINE_HEIGHT 4))
(cond
((type-type? (-> e type) entity-actor)
(let ((actor (the entity-actor e)))
;; print info for entity-actors
(draw-string-xy
(string-format "etype: ~A~%vis: ~D task: ~S" (-> actor etype) (-> actor vis-id) (game-task->string (-> actor task)))
debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y (* LINE_HEIGHT 2))
(when (and (nonzero? (-> actor extra)) (-> actor extra))
(draw-string-xy (string-format "perm: #x~X task: ~S" (-> actor extra perm user-uint64) (game-task->string (-> actor extra perm task)))
debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y (* LINE_HEIGHT 1))
(when (nonzero? (-> actor extra perm status))
(format (clear *debug-temp-string*) "(~S)" (begin (bit-enum->string entity-perm-status (-> actor extra perm status) (clear *temp-string*)) *temp-string*))
(draw-string-xy (string-format "perm-status: ~S" *debug-temp-string*)
debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y (* LINE_HEIGHT 1))
)
)
(when (nonzero? (-> actor kill-mask))
(format (clear *debug-temp-string*) "(~S)" (begin (bit-enum->string task-mask (-> actor kill-mask) (clear *temp-string*)) *temp-string*))
(draw-string-xy (string-format "kill-mask: ~S" *debug-temp-string*)
debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y (* LINE_HEIGHT 1))
)
)
)
)
;; draw each tag in entity
(dotimes (i (length e))
(let ((data (get-tag-index-data e i)))
;; tag info
(format (clear *debug-temp-string*) "~3L~2D)~0L ~20L~A~0L: " i (-> e tag i name) (-> e tag i elt-type))
;; tag data - special cases first
(cond
;; some water-height info
;; ((and (= (-> e tag i name) 'water-height) (= (-> e tag i elt-count) 4) (= (-> e tag i elt-type) float))
;; (+! y-adv (* LINE_HEIGHT 1))
;; (format *debug-temp-string* "~mm ~mm ~mm~%(~S)"
;; (-> (the (pointer float) data) 0)
;; (-> (the (pointer float) data) 1)
;; (-> (the (pointer float) data) 2)
;; (begin (bit-enum->string water-flags (the int (-> (the (pointer float) data) 3)) (clear *temp-string*)) *temp-string*)
;; )
;; )
;; some water-height info but with 5 elts
;; ((and (= (-> e tag i name) 'water-height) (= (-> e tag i elt-count) 4) (= (-> e tag i elt-type) float))
;; (+! y-adv (* LINE_HEIGHT 3))
;; (format *debug-temp-string* "~mm ~mm ~mm~%(~S)~%~mm"
;; (-> (the (pointer float) data) 0)
;; (-> (the (pointer float) data) 1)
;; (-> (the (pointer float) data) 2)
;; (begin (bit-enum->string water-flags (the int (-> (the (pointer float) data) 3)) (clear *temp-string*)) *temp-string*)
;; (-> (the (pointer float) data) 4)
;; )
;; )
;; text id (can be hint ambient)
;; ((and (= (-> e tag i name) 'text-id) (= (-> e tag i elt-count) 1) (= (-> e tag i elt-type) int32))
;; (format *debug-temp-string* "(text-id ~S)" (text-id->string (-> (the (pointer text-id) data) 0)))
;; )
;; eco-info, like in vents, crates, or collectables in general
((and (= (-> e tag i name) 'eco-info) (= (-> e tag i elt-count) 2) (= (-> e tag i elt-type) int32))
(format *debug-temp-string* "~S " (pickup-type->string (the-as pickup-type (-> (the (pointer int32) data) 0))))
(if (= (pickup-type fuel-cell) (-> (the (pointer int32) data) 0))
(format *debug-temp-string* "~S" (game-task->string (the-as game-task (-> (the (pointer int32) data) 1))))
(format *debug-temp-string* "~D" (-> (the (pointer int32) data) 1))
)
(if (= (pickup-type buzzer) (-> (the (pointer int32) data) 0))
(format *debug-temp-string* "~S" (game-task->string (the-as game-task (logand #xffff (-> (the (pointer int32) data) 1)))))
)
)
;; fact options, usually enemies or crates
;; ((and (= (-> e tag i name) 'options) (= (-> e tag i elt-count) 1) (= (-> e tag i elt-type) uint32))
;; (format *debug-temp-string* " (fact-options ")
;; (bit-enum->string fact-options (-> (the (pointer uint32) data) 0) *debug-temp-string*)
;; (format *debug-temp-string* ")")
;; )
;; these can be displayed visually with other tools.
((and (= (-> e tag i name) 'visvol) (= (-> e tag i elt-count) 2) (= (-> e tag i elt-type) vector) (not (-> inspect-info show-long-info)))
(format *debug-temp-string* "display actor-vis!")
)
((and (= (-> e tag i name) 'path) (= (-> e tag i elt-type) vector) (not (-> inspect-info show-long-info)))
(format *debug-temp-string* "display path marks!")
)
((and (= (-> e tag i name) 'vol) (= (-> e tag i elt-type) vector) (not (-> inspect-info show-long-info)))
(format *debug-temp-string* "display vol marks!")
)
((and (= (-> e tag i name) 'art-name) (= (-> e tag i elt-count) 1) (type-type? (-> e type) entity-actor) (type-type? (-> (the-as entity-actor e) etype) part-spawner))
(let* ((as-launch-group-ptr (-> (the (pointer (pointer sparticle-launch-group)) data)))
(as-string (the string as-launch-group-ptr)))
(cond
((part-group-pointer? as-launch-group-ptr)
(format *debug-temp-string* "(group) ~A" (-> as-launch-group-ptr 0 name))
)
((= (-> as-string type) string)
(format *debug-temp-string* "(string) ~A" as-string)
)
(else
(format *debug-temp-string* "<unknown art-name res-tag #x~x>" as-launch-group-ptr)
)
)
)
)
(else
;; more generic tag info
(dotimes (ii (-> e tag i elt-count))
(case (-> e tag i elt-type)
((string symbol type)
(format *debug-temp-string* "~A" (-> (the (pointer basic) data) ii)))
((float)
(case (-> e tag i name)
;; meters are better here
(('spring-height 'vis-dist 'height-info 'distance 'cam-notice-dist 'cam-vert 'cam-horz 'idle-distance
'nearest-y-threshold 'center-point 'center-radius 'notice-dist 'trigger-height 'notice-top
'elevator-move-rate 'elevator-y-threshold 'elevator-xz-threshold 'height)
(format *debug-temp-string* "~mm" (-> (the (pointer float) data) ii))
)
;; degrees are better for these
(('rotoffset 'fov 'rotmin 'rotmax 'tiltmin 'tiltmax 'rotspeed 'spinup-angle)
(format *debug-temp-string* "~rdeg" (-> (the (pointer float) data) ii))
)
(else
(format *debug-temp-string* "~f" (-> (the (pointer float) data) ii))
)
)
)
((int8)
(case (-> e tag i name)
(('task-actor)
(format *debug-temp-string* "~S" (game-task-actor->string (the-as game-task-actor (-> (the (pointer uint8) data) ii))))
)
(else
(format *debug-temp-string* "~D" (-> (the (pointer int8) data) ii))
)
)
)
((int16) (format *debug-temp-string* "~D" (-> (the (pointer int16) data) ii)))
((int32)
(case (-> e tag i name)
(('final-pickup 'pickup-type)
(format *debug-temp-string* "~S" (pickup-type->string (the-as pickup-type (-> (the (pointer int32) data) ii))))
)
(('alt-task)
(format *debug-temp-string* "~S" (game-task->string (the-as game-task (-> (the (pointer int32) data) ii))))
)
(else
(format *debug-temp-string* "~D" (-> (the (pointer int32) data) ii))
)
)
)
((uint8)
(case (-> e tag i name)
;; not sure
(('shadow-mask)
(format *debug-temp-string* "#b~b" (-> (the (pointer uint8) data) ii))
)
(('light-index)
(format *debug-temp-string* "~D" (-> (the (pointer uint8) data) ii))
)
(('task)
(format *debug-temp-string* "~S" (game-task->string (the-as game-task (-> (the (pointer uint8) data) ii))))
)
(('task-actor)
(format *debug-temp-string* "~S" (game-task-actor->string (the-as game-task-actor (-> (the (pointer uint8) data) ii))))
)
(else
(format *debug-temp-string* "#x~x" (-> (the (pointer uint8) data) ii))
)
)
)
((uint16) (format *debug-temp-string* "#x~x" (-> (the (pointer uint16) data) ii)))
((uint32)
(case (-> e tag i name)
;; actually actor-id
(('open-actor 'trigger-actor 'path-actor 'state-actor 'alt-actor 'next-actor 'prev-actor
'spawner-blocker-actor 'spawner-trigger-actor 'kill-actor 'fade-actor 'water-actor 'target-actor 'formation-actor)
(format *debug-temp-string* "~%#x~x (~S)" (-> (the (pointer uint32) data) ii)
(res-lump-struct (entity-by-aid (-> (the (pointer uint32) data) ii)) 'name string))
(+! y-adv LINE_HEIGHT)
)
(('nav-mesh-actor)
(format *debug-temp-string* "~%#x~x (~S)" (-> (the (pointer uint32) data) ii)
(res-lump-struct (entity-nav-mesh-by-aid (-> (the (pointer actor-id) data) ii)) 'name string))
(+! y-adv LINE_HEIGHT)
)
(('enemy-options)
(format *debug-temp-string* "~%(~S)" (begin (bit-enum->string enemy-option (-> (the (pointer uint32) data) ii) (clear *temp-string*)) *temp-string*))
(+! y-adv LINE_HEIGHT)
)
(('kill-mask)
(format *debug-temp-string* "~%(~S)" (begin (bit-enum->string task-mask (-> (the (pointer uint32) data) ii) (clear *temp-string*)) *temp-string*))
(+! y-adv LINE_HEIGHT)
)
(('elevator-flags)
(format *debug-temp-string* "~%(~S)" (begin (bit-enum->string elevator-flags (-> (the (pointer uint32) data) ii) (clear *temp-string*)) *temp-string*))
(+! y-adv LINE_HEIGHT)
)
(else
(format *debug-temp-string* "#x~x" (-> (the (pointer uint32) data) ii))
)
)
)
((uint128)
(case (-> e tag i name)
(('task)
(format *debug-temp-string* "~S" (game-task->string (the-as game-task (-> (the (pointer uint128) data) ii))))
)
(('task-actor)
(format *debug-temp-string* "~S" (game-task-actor->string (the-as game-task-actor (-> (the (pointer uint128) data) ii))))
)
)
)
((vector)
(case (-> e tag i name)
;; guess
(('movie-pos)
(format *debug-temp-string* "~%(~mm ~mm ~mm ~rdeg)"
(-> (the (inline-array vector) data) ii x)
(-> (the (inline-array vector) data) ii y)
(-> (the (inline-array vector) data) ii z)
(-> (the (inline-array vector) data) ii w)
)
)
;; not super useful
(('nav-mesh-sphere 'intro)
(format *debug-temp-string* "~%(~mm ~mm ~mm ~mm)"
(-> (the (inline-array vector) data) ii x)
(-> (the (inline-array vector) data) ii y)
(-> (the (inline-array vector) data) ii z)
(-> (the (inline-array vector) data) ii w)
)
)
(else
(format *debug-temp-string* "~%(~f ~f ~f ~f)"
(-> (the (inline-array vector) data) ii x)
(-> (the (inline-array vector) data) ii y)
(-> (the (inline-array vector) data) ii z)
(-> (the (inline-array vector) data) ii w)
)
)
)
(+! y-adv LINE_HEIGHT))
((pair)
(format *debug-temp-string* "~%~A" (-> (the (pointer pair) data) 0))
(+! y-adv LINE_HEIGHT)
)
((actor-group)
(let* ((group (-> (the (pointer actor-group) data) ii))
(len (-> group length)))
(format *debug-temp-string* "~%--- GROUP ~D: ---" ii len)
(dotimes (iii len)
(format *debug-temp-string* "~% #x~x (~S)" (-> group data iii id) (res-lump-struct (entity-by-aid (-> group data iii id)) 'name string))
(+! y-adv LINE_HEIGHT))
)
(+! y-adv LINE_HEIGHT)
)
;; no clue! please report this.
(else
(format *debug-temp-string* "<unknown res-tag type ~A>" (-> e tag i elt-type))
(set! ii (the int (-> e tag i elt-count)))
)
)
(format *debug-temp-string* " ")
)
)
)
;; draw a string for each tag instead of all at once. allows using smaller strings.
(draw-string-xy *debug-temp-string* debug-buf 352 cur-y (font-color default) (font-flags shadow kerning middle))
(+! cur-y y-adv)
(set! y-adv LINE_HEIGHT)
))
;; set max scroll based on how large the whole text was, ignore first 20 lines.
(set! (-> inspect-info scroll-y-max) (max 0 (+ (the int (/ (the float -20) (get-debug-font-scale-factor))) (/ (- cur-y begin-y) LINE_HEIGHT))))
)
))))

View File

@ -10,7 +10,7 @@
;; updated macro for jak 3, draw-sprite2d-xy also has z now
(defmacro draw-memory-bar-generic (buf &key remain &key total &key name &key idx &key color)
"draw a memory usage bar"
"draw a memory usage bar"
`(let* (
(total (the float ,total))
(remain (the float ,remain))
@ -29,47 +29,88 @@
)
)
(defmacro draw-memory-bar-level-masks (buf levels bit-amount &key name &key idx &key colors)
"draw a memory usage bar from level memory masks"
`(let* (
(bar-width (the int (/ (the float MEM_BAR_WIDTH) (-> *pc-settings* aspect-ratio-scale))))
(bar-x (- MEM_BAR_RIGHT bar-width MEM_BAR_HORZ_PAD)) ;; x coord for left side of the bar list
(bit-w (/ (the float bar-width) ,bit-amount))
(used-y (+ MEM_BAR_Y (* ,idx MEM_BAR_HEIGHT)))
(used-x 0)
(used-bits 0)
(bit-found? #f)
)
(dotimes (b ,bit-amount)
(set! used-x (+ bar-x (the int (* bit-w b))))
(set! bit-found? #f)
(dotimes (i (-> ,levels length))
(cond
((or (-> ,levels level i borrow-from-level) (= (-> ,levels level i status) 'inactive))
)
((logtest? (ash 1 b) (-> ,levels level i memory-mask))
(draw-sprite2d-xy ,buf used-x used-y (- (+ bar-x (the int (* bit-w (1+ b)))) used-x) MEM_BAR_HEIGHT (-> ,colors i) #x3fffff)
(set! i (-> ,levels length))
(set! bit-found? #t)
(1+! used-bits))
)
)
(unless bit-found?
(draw-sprite2d-xy ,buf used-x used-y (- (+ bar-x (the int (* bit-w (1+ b)))) used-x) MEM_BAR_HEIGHT MEM_BAR_BG_COL #x3fffff))
)
(draw-string-xy ,name ,buf (- bar-x MEM_BAR_HORZ_PAD) used-y (font-color red) (font-flags shadow kerning right))
(draw-string-xy (string-format "~D/~D" used-bits ,bit-amount) ,buf (+ bar-x bar-width MEM_BAR_HORZ_PAD) used-y (font-color red) (font-flags shadow kerning middle-vert))
)
)
(defmethod print-debug-misc pc-settings-jak3 ((obj pc-settings-jak3))
"prints various miscellaneous debug text to the game console, according to what's enabled in this object."
"prints various miscellaneous debug text to the game console, according to what's enabled in this object."
#f
)
#f
)
(defconstant MEM_BAR_HEIGHT (the int (* 14.0 (get-debug-font-scale-factor)))) ;; total height of the bar
(defconstant MEM_BAR_BOTTOM 416) ;; x coord for the bottom side of the bar list
(defconstant MEM_BAR_NUM (+ LEVEL_MAX 5)) ;; amount of memory usage bars (override later if wanted)
(defconstant MEM_BAR_NUM (+ LEVEL_MAX 6)) ;; amount of memory usage bars (override later if wanted)
(defmethod draw-memory pc-settings-jak3 ((obj pc-settings-jak3) (buf dma-buffer))
"draw the memory heap status in the bottom right corner"
"draw the memory heap status in the bottom right corner"
(when *display-heap-status*
(let ((idx 0)
(level-heap-colors (new 'static 'array rgba 3 (static-rgba 32 255 255 64)
(static-rgba 255 32 255 64)
(static-rgba 255 255 32 64)
)))
(draw-memory-bar-kheap buf global :idx idx :color (static-rgba 32 32 255 64))
(draw-memory-bar-kheap buf debug :idx (1+! idx) :color (static-rgba 255 32 32 64))
(dotimes (i LEVEL_MAX)
(draw-memory-bar-kheap buf (-> *level* level i heap)
:name (aif (-> *level* level i borrow-from-level)
(string-format "(~A)l~D<-l~D" (-> *level* level i name) i (-> it index))
(string-format "(~A)l~D" (-> *level* level i name) i))
:idx (1+! idx) :color (-> level-heap-colors (mod i 3)))
)
(draw-memory-bar-dead-pool-heap buf *nk-dead-pool* :name "actor" :idx (1+! idx) :color (static-rgba 32 255 32 64))
(draw-memory-bar-generic buf
:remain (* 16 (dma-buffer-free (-> *display* frames (-> *display* on-screen) global-buf)))
:total (length (-> *display* frames (-> *display* on-screen) global-buf))
:name "dma-global" :idx (1+! idx) :color (static-rgba 32 32 255 64))
(draw-memory-bar-generic buf
:remain (* 16 (dma-buffer-free (-> *display* frames (-> *display* on-screen) debug-buf)))
:total (length (-> *display* frames (-> *display* on-screen) debug-buf))
:name "dma-debug" :idx (1+! idx) :color (static-rgba 255 32 32 64))
)
#t)
)
(when *display-heap-status*
(let ((idx 0)
(level-heap-colors (new 'static 'array rgba 10 (static-rgba #x20 #xff #xff #x40)
(static-rgba #xff #x20 #xff #x40)
(static-rgba #xff #xff #x20 #x40)
(static-rgba #xff #x20 #x20 #x40)
(static-rgba #x20 #xff #x20 #x40)
(static-rgba #x20 #x20 #xff #x40)
(static-rgba #xff #xff #xff #x40)
(static-rgba #x80 #x20 #x80 #x40)
(static-rgba #xff #x80 #x20 #x40)
(static-rgba #x20 #x80 #x20 #x40)
)))
(draw-memory-bar-kheap buf global :idx idx :color (static-rgba 32 32 255 64))
(draw-memory-bar-kheap buf debug :idx (1+! idx) :color (static-rgba 255 32 32 64))
(dotimes (i (-> *level* length))
(draw-memory-bar-kheap buf (-> *level* level i heap)
:name (aif (-> *level* level i borrow-from-level)
(string-format "(~A)l~D<-l~D" (-> *level* level i name) i (-> it index))
(string-format "(~A)l~D" (-> *level* level i name) i))
:idx (1+! idx) :color (-> level-heap-colors (mod i 10)))
)
(draw-memory-bar-level-masks buf *level* 18 :name "level" :idx (1+! idx) :colors level-heap-colors)
(draw-memory-bar-dead-pool-heap buf *nk-dead-pool* :name "actor" :idx (1+! idx) :color (static-rgba 32 255 32 64))
(draw-memory-bar-generic buf
:remain (* 16 (dma-buffer-free (-> *display* frames (-> *display* on-screen) global-buf)))
:total (length (-> *display* frames (-> *display* on-screen) global-buf))
:name "dma-global" :idx (1+! idx) :color (static-rgba 32 32 255 64))
(draw-memory-bar-generic buf
:remain (* 16 (dma-buffer-free (-> *display* frames (-> *display* on-screen) debug-buf)))
:total (length (-> *display* frames (-> *display* on-screen) debug-buf))
:name "dma-debug" :idx (1+! idx) :color (static-rgba 255 32 32 64))
)
#t)
)
(define *region-debug-inspect* (the drawable-region-prim #f))
@ -84,27 +125,27 @@
(define *debug-track-skill* #f)
(defun debug-track-skill ()
"draws a line and prints the distance to every skill in every active level"
(let ((start-pos (target-pos 0)))
(dotimes (i (-> *level* length))
(let ((lev (-> *level* level i)))
(when (= (-> lev status) 'active)
;; actor entities
(let ((actors (-> lev bsp actors)))
(when (nonzero? actors)
(dotimes (ii (-> actors length))
(let ((e (-> actors data ii actor)))
(when (and (= (-> e etype symbol) 'skill) (or (not (-> e extra)) (zero? (-> e extra)) (not (logtest? (-> e extra perm status) (entity-perm-status dead)))))
(add-debug-line #t (bucket-id debug-no-zbuf1) start-pos (-> e trans) (new 'static 'rgba :r #xff :a #x80) #f (the-as rgba -1))
(format *stdcon* "~S at ~m ~m ~m (~m away)~%" (res-lump-struct e 'name string) (-> e trans x) (-> e trans y) (-> e trans z) (vector-vector-distance start-pos (-> e trans)))
)
)
)
)
)
)
)
)
)
#f)
"draws a line and prints the distance to every skill in every active level"
(let ((start-pos (target-pos 0)))
(dotimes (i (-> *level* length))
(let ((lev (-> *level* level i)))
(when (= (-> lev status) 'active)
;; actor entities
(let ((actors (-> lev bsp actors)))
(when (nonzero? actors)
(dotimes (ii (-> actors length))
(let ((e (-> actors data ii actor)))
(when (and (= (-> e etype symbol) 'skill) (or (not (-> e extra)) (zero? (-> e extra)) (not (logtest? (-> e extra perm status) (entity-perm-status dead)))))
(add-debug-line #t (bucket-id debug-no-zbuf1) start-pos (-> e trans) (new 'static 'rgba :r #xff :a #x80) #f (the-as rgba -1))
(format *stdcon* "~S at ~m ~m ~m (~m away)~%" (res-lump-struct e 'name string) (-> e trans x) (-> e trans y) (-> e trans z) (vector-vector-distance start-pos (-> e trans)))
)
)
)
)
)
)
)
)
)
#f)

View File

@ -8,12 +8,10 @@ Although it contains a `curve`, the knot part is not populated, so it's just tre
a bunch of line segments from the control points.
The child class curve-control does fill out the knot data and is a proper b-spline.
These path-controls are typically allocated on a process heap."
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
(num-cverts int32 :overlay-at (-> curve num-cverts))
(cverts uint32 :overlay-at (-> curve cverts))
((flags path-control-flag)
(name symbol)
(process process-drawable)
(curve curve :inline)
)
(:methods
(new (symbol type process symbol float entity symbol) _type_)