From e64414d9d0152b96bbb0d9fcfccff3a46b6a5b2c Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 24 Sep 2022 12:27:02 -0400 Subject: [PATCH] d/jak2: finish `drawable-group` | `drawable-inline-array` | `drawable-tree` and `path` (#1899) --- .github/scripts/update-file-progress.py | 35 -- .github/scripts/update-gallery.py | 63 --- decompiler/ObjectFile/ObjectFileDB_IR2.cpp | 7 +- .../jak1_ntsc_black_label/type_casts.jsonc | 2 - decompiler/config/jak2/all-types.gc | 134 ++++- .../jak2/anonymous_function_types.jsonc | 2 +- decompiler/config/jak2/hacks.jsonc | 1 - decompiler/config/jak2/stack_structures.jsonc | 5 +- decompiler/config/jak2/type_casts.jsonc | 91 +--- decompiler/config/jak2/var_names.jsonc | 332 +++++++----- decompiler/config/jak2_ntsc_v1.jsonc | 2 +- goal_src/goal-lib.gc | 4 + goal_src/jak1/engine/gfx/font.gc | 5 - goal_src/jak2/engine/draw/drawable-group-h.gc | 22 +- goal_src/jak2/engine/draw/drawable-group.gc | 89 +++ .../jak2/engine/draw/drawable-inline-array.gc | 22 + goal_src/jak2/engine/draw/drawable-tree.gc | 81 +++ goal_src/jak2/engine/geometry/path-h.gc | 50 +- goal_src/jak2/engine/geometry/path.gc | 480 +++++++++++++++++ scripts/gsrc/update-from-decomp.py | 18 +- .../jak1/engine/gfx/sky/sky-tng_REF.gc | 2 +- .../reference/jak1/engine/gfx/vis/bsp_REF.gc | 2 +- .../jak1/levels/rolling/rolling-obs_REF.gc | 2 +- .../jak1/levels/swamp/swamp-rat-nest_REF.gc | 2 +- .../reference/jak2/engine/anim/joint_REF.gc | 2 +- .../jak2/engine/draw/drawable-group-h_REF.gc | 7 +- .../jak2/engine/draw/drawable-group_REF.gc | 105 ++++ .../engine/draw/drawable-inline-array_REF.gc | 37 ++ .../jak2/engine/draw/drawable-tree_REF.gc | 91 ++++ .../jak2/engine/geometry/path-h_REF.gc | 44 +- .../jak2/engine/geometry/path_REF.gc | 510 ++++++++++++++++++ .../reference/jak2/engine/level/bsp_REF.gc | 2 +- .../jak2/engine/target/surface-h_REF.gc | 2 +- 33 files changed, 1852 insertions(+), 401 deletions(-) delete mode 100644 .github/scripts/update-file-progress.py delete mode 100644 .github/scripts/update-gallery.py create mode 100644 test/decompiler/reference/jak2/engine/draw/drawable-group_REF.gc create mode 100644 test/decompiler/reference/jak2/engine/draw/drawable-inline-array_REF.gc create mode 100644 test/decompiler/reference/jak2/engine/draw/drawable-tree_REF.gc create mode 100644 test/decompiler/reference/jak2/engine/geometry/path_REF.gc diff --git a/.github/scripts/update-file-progress.py b/.github/scripts/update-file-progress.py deleted file mode 100644 index cbdb3b15f..000000000 --- a/.github/scripts/update-file-progress.py +++ /dev/null @@ -1,35 +0,0 @@ -import glob - -src_files = glob.glob("./goal_src/**/*.g[cs]", recursive=True) - -# Find how many of each have been started - -src_files_started = 0 -src_files_finished = 0 -data_files_started = 0 - -for f in src_files: - with open(f, "r") as temp_file: - lines = temp_file.readlines() - line_count = len(lines) - if line_count > 7: - # Check to see if there are any TODOs - if any("TODO" in string for string in lines): - src_files_finished = src_files_finished + 1 - else: - src_files_started = src_files_started + 1 - -import json -with open('./docs/gh-pages-proj/src/config/progress.json', 'r+', encoding='utf-8') as f: - data = { - 'jak1': { - 'fileProgress': { - 'src_files_total': len(src_files), - 'src_files_finished': src_files_finished, - 'src_files_started': src_files_started - } - } - } - f.seek(0) - json.dump(data, f, ensure_ascii=False, indent=2) - f.truncate() diff --git a/.github/scripts/update-gallery.py b/.github/scripts/update-gallery.py deleted file mode 100644 index c6bc332fe..000000000 --- a/.github/scripts/update-gallery.py +++ /dev/null @@ -1,63 +0,0 @@ -import glob -import os -from pathlib import Path -import json - -galleryLinks = { - 'jak1': { - 'name': "Jak 1", - 'media': [], - }, - 'jak2': { - 'name': "Jak 2", - 'media': [], - }, - 'jak3': { - 'name': "Jak 3", - 'media': [], - }, - 'jakx': { - 'name': "Jak X", - 'media': [], - }, - 'misc': { - 'name': "Miscellaneous", - 'media': [], - } -} - -def get_links(key, folder_to_search): - if os.path.isdir(folder_to_search): - files = glob.glob(folder_to_search + "/*.png", recursive=True) - files.extend(glob.glob(folder_to_search + "/*.jpg", recursive=True)) - files.extend(glob.glob(folder_to_search + "/*.jpeg", recursive=True)) - for f in files: - galleryLinks[key]["media"].append({ - 'fileName': os.path.basename(f), - 'timestamp': Path(f).stem.split("_")[1], - 'caption': Path(f).stem.split("_")[0].replace("-", " ").title(), - 'video': False - }) - # get videos potentially - if os.path.exists("{}/videos.json".format(folder_to_search)): - with open("{}/videos.json".format(folder_to_search), 'r') as f: - data = json.load(f) - for video in data: - galleryLinks[key]["media"].append({ - 'link': video["link"].replace("watch?v=", "embed/"), - 'timestamp': video["timestamp"], - 'video': True - }) - # sort by timestamp - galleryLinks[key]["media"].sort(key=lambda x: x["timestamp"], reverse=True) - -get_links('jak1', './docs/gh-pages-proj/src/assets/gallery/jak1') -get_links('jak2', './docs/gh-pages-proj/src/assets/gallery/jak2') -get_links('jak3', './docs/gh-pages-proj/src/assets/gallery/jak3') -get_links('jakx', './docs/gh-pages-proj/src/assets/gallery/jakx') -get_links('misc', './docs/gh-pages-proj/src/assets/gallery/misc') - -with open('./docs/gh-pages-proj/src/config/gallery.json', 'r+', encoding='utf-8') as f: - f.seek(0) - json.dump(galleryLinks, f, ensure_ascii=False, indent=2) - f.truncate() diff --git a/decompiler/ObjectFile/ObjectFileDB_IR2.cpp b/decompiler/ObjectFile/ObjectFileDB_IR2.cpp index 2bb1006b9..159395d0e 100644 --- a/decompiler/ObjectFile/ObjectFileDB_IR2.cpp +++ b/decompiler/ObjectFile/ObjectFileDB_IR2.cpp @@ -609,7 +609,12 @@ void ObjectFileDB::ir2_register_usage_pass(int seg, ObjectFileData& data) { } lg::error("Bad register dependency on {} in {}", x.to_charp(), func.name()); - func.warnings.warning("Function may read a register that is not set: {}", x.to_string()); + if (x.to_string() == "f31") { + func.warnings.warning("Function may read a register that is not set: {}", + x.to_string()); + } else { + func.warnings.error("Function may read a register that is not set: {}", x.to_string()); + } } } } diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 9381ad623..547274013 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -6504,11 +6504,9 @@ "(method 16 drawable-tree)": [ [[1, 4], "v1", "drawable-inline-array-node"], - //[4, "a1", "int"], [11, "v1", "(pointer int8)"], [[29, 34], "t0", "drawable-inline-array-node"], [31, "t2", "drawable-inline-array-node"], - //[[34,36], "a1", "int"], [36, "t1", "(pointer int8)"], [[9, 42], "a2", "(pointer int8)"] ], diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index c4ca7a000..0b3a0a366 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -8022,7 +8022,7 @@ (draw (_type_ _type_ display-frame) none 10) (drawable-method-11 () none 11) ;; (collide-with-box (_type_ int collide-list) none 11) (drawable-method-12 () none 12) ;; (collide-y-probe (_type_ int collide-list) none 12) - (collect-stats (_type_) none 13) ;; (collide-ray (_type_ int collide-list) none 13) + (collect-stats (_type_) none 13) (debug-draw (_type_ drawable display-frame) none 14) (unpack-vis (_type_ (pointer int8) (pointer int8)) (pointer int8) 15) ;; (collect-regions (_type_ sphere int region-prim-list) none 16) @@ -8048,15 +8048,20 @@ (deftype drawable-group (drawable) - ((length int16 :offset 6) + ((length int16 :offset 6) (data drawable :dynamic :offset-assert 32) ) :method-count-assert 17 :size-assert #x20 :flag-assert #x1100000020 - ;; Failed to read fields. (:methods - ;; (new (symbol type int) _type_ 0) + (new "Create a new [[drawable-group]] which can hold the provided number of [[drawable]]s" (symbol type int) _type_ 0) + ;; TODO - child docstrings + ;; collect-stats "For each [[drawable]] that is visible (see [[vis-cull]]) and within the defined `bsphere` (see [[sphere-cull]]), call the respective [[drawable::13]]" + ;; debug-draw "For each [[drawable]] that is visible (see [[vis-cull]]) and within the defined `bsphere` (see [[sphere-cull]]), call the respective [[drawable::14]]" + ;; unpack-vis "Calls [[drawable::15]] for each [[drawable]] and TODO sets the second arg as the result. This means that the overall result will be that of the last [[drawable::15]] call" + ;; debug-draw "For each [[drawable]] that is visible (see [[vis-cull]]) and within the defined `bsphere` (see [[sphere-cull]]), call the respective [[drawable::10]]" + ;; login "For each [[drawable]], call [[drawable::9]]" ) ) @@ -8071,6 +8076,7 @@ :method-count-assert 17 :size-assert #x20 :flag-assert #x1100000020 + ;; NOTE - all methods (except for `length`) are stubs (:methods ) ) @@ -8130,6 +8136,14 @@ (deftype drawable-tree-array (drawable-group) ((trees drawable-tree :dynamic :offset 32 :score 100)) :flag-assert #x1100000020 + (:methods + ;; TODO - child docstrings + ;; "draw - Based on the `display?` symbol in the [[*level*]]'s [[*draw-index*]], draw (see [[drawable::10]] anything that is NOT: + ;; - `'special` + ;; - [[#f]]" + ;; collect-stats "For each [[drawable-tree]] call the respective [[drawable::13]]" + ;; debug-draw "For each [[drawable-tree]] call the respective [[drawable::14]]" + ) ) @@ -20636,12 +20650,14 @@ ) (deftype path-control (basic) - ((flags path-control-flag :offset-assert 4) ;; guessed by decompiler - (name symbol :offset-assert 8) ;; guessed by decompiler - (process process-drawable :offset-assert 12) ;; guessed by decompiler + "An abstraction around a [[curve]], providing tools such as: + - debug drawing + - conveniant vertex accessing + - vertex finding/searching algorithms" + ((flags path-control-flag :offset-assert 4) + (name symbol :offset-assert 8) + (process process-drawable :offset-assert 12) (curve curve :inline :offset-assert 16) - (num-cverts int32 :offset 20) - (cverts (inline-array vector) :offset 16) ;; guessed by decompiler ) :method-count-assert 27 :size-assert #x24 @@ -20649,33 +20665,105 @@ (:methods (new (symbol type process symbol float entity symbol) _type_ 0) (debug-draw (_type_) none 9) - (path-control-method-10 () none 10) ;; (eval-path-curve-div! (_type_ vector float symbol) vector 10) - (path-control-method-11 () none 11) ;; (get-random-point (_type_ vector) vector 11) - (path-control-method-12 () none 12) ;; (TODO-RENAME-12 (_type_ vector float) vector 12) - (path-control-method-13 () none 13) ;; (eval-path-curve! (_type_ vector float symbol) vector 13) - (path-control-method-14 () none 14) ;; (TODO-RENAME-14 (_type_ vector float) vector 14) - (path-control-method-15 () none 15) ;; (length-as-float (_type_) float 15) - (path-control-method-16 () none 16) ;; (path-distance (_type_) float 16) + (get-point-in-path! + "Depending on the value of `idx`, the result can be quite different: + - if `idx` is less than `0.0` - return the first vertex in the path + - if `idx` is greater than the number of vertices in the path, return the last vertex + - if `search-type` is equal to `exact` OR `idx` is an integral number (ex 1.0), return that vertex + - otherwise, do a linear interpolation between the vertex at `idx` (truncated) and the next vertex + using the fractional component of `idx` as the interpolant, return this result + + @param! ret The [[vector]] that is used to hold the return value + @param idx Either the vertex index or also partially the interpolant in a LERP + @param search-type The only recognized value is `exact` + @returns Either a distinct vertex along the path, or some fractional point between two vertices" + (_type_ vector float symbol) vector 10) + (get-random-point + "Attempts to retrieve a random point along the path, returns the [[*null-vector*]] if no vertices are defined" + (_type_ vector) vector :behavior process 11) + (displacement-between-two-points-copy! + "Calls [[path-control::26]] with the provided args + @see [[path-control::26]]" + (_type_ vector float float) vector 12) + (displacement-between-two-points-normalized! + "Calls [[path-control::26], with the provided `idx` + @param! ret The [[vector]] the result is stored within + @param idx The vertex index + @returns The resulting displacement vector, normalized + @see [[path-control::26]]" + (_type_ vector float) vector 13) + (get-point-at-percent-along-path! + "@param! ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path + @param search-type The only recognized value is `exact` + @returns the point closest to some arbitrary percentage along the path + @see [[path-control::10]]" + (_type_ vector float symbol) vector 14) + (displacement-between-points-at-percent-scaled! + "Calls [[path-control::12], with the `idx` at a given percent along the path + @param ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path to find the first index + @param mag Multiplied by the number of points in the path and scales the resulting vector + @returns The displacement between the last two points of the path scaled to the magnitude equal to the number of points in the path" + (_type_ vector float float) vector 15) + (displacement-between-points-at-percent-normalized! + "Calls [[path-control::13], with the `idx` at a given percent along the path + @param! ret The [[vector]] the result is stored within + @param percent The percentage along the path + @returns The resulting displacement vector, normalized + @see [[path-control::13]] + @see [[path-control::14]]" + (_type_ vector float) vector 16) (get-num-segments (_type_) float 17) - (path-control-method-18 () none 18) ;; (should-display? (_type_) symbol 18) - (get-num-verts (_type_) int 19) ;; (TODO-RENAME-19 (_type_) float 19) - (path-distance-equal-spacing (_type_ float) float 20) ;; (TODO-RENAME-20 (_type_) float 20) + (total-distance + "Calcuate the total path length by summing the distance between each adjacent [[curve]] vertex" + (_type_) float 18) + (get-num-verts (_type_) int 19) + (path-distance-equal-spacing (_type_ float) float 20) (average-segment-length (_type_ float) float 21) - (path-control-method-22 () none 22) - (path-control-method-23 () none 23) - (path-control-method-24 () none 24) + (get-furthest-point-on-path + "@param point The point to calculate distance from + @returns the `vertex-idx.interpolant` value to the point on the path furthest away from the `point` + @see [[path-control::10]]" + (_type_ vector) float 22) + (get-path-percentage-at-furthest-point + "@param point The point to calculate distance from + @returns the percentage of path completion from the point on the path furthest away from the `point` + @see [[path-control::14]]" + (_type_ vector) float 23) + (path-control-method-24 "TODO" (_type_ vector) vector 24) (should-display-marks? (_type_) symbol 25) - (path-control-method-26 () none 26) + (displacement-between-two-points! + "Return value can differ quite a bit: + - If [[path-control-flag::4]] is set OR there are less than 2 vertices OR `idx` is less than `0.0` - return [[*null-vector*]] + - Otherwise, find the scaled (by `mag`) displacement vector between two points in the path: + - If `idx` is not beyond the second last vertex, the result is between vertex `idx` and `idx+1` + - else, the result is between the second last vertex and the last + + @param! ret The [[vector]] that is used to hold the return value + @param idx The vertex index + @param mag The magnitude to scale the resulting displacement vector by + @returns The displacement [[vector]] between two points in the path, the last 2, or the [[*null-vector*]]" + (_type_ vector float float) vector 26) ) ) (deftype curve-control (path-control) + "Identical in terms of data to a [[path-control]] but has different implementation" () :method-count-assert 27 :size-assert #x24 :flag-assert #x1b00000024 (:methods (new (symbol type process symbol float) _type_ 0) + ;; TODO - child docstrings + ;; 10 + ;; 12 - "Calls [[path-control::26]] with the `idx` at a given percent along the path @see [[path-control::26]]" + ;; 26 + ;; 15 + ;; 16 + ;; 13 - different, just calls [[curve-evaluate!]] + ;; 18 - "Returns total path length of the [[curve]], will lazily calculate and set the [[curve]]'s `length` via [[curve::4]]" ) ) diff --git a/decompiler/config/jak2/anonymous_function_types.jsonc b/decompiler/config/jak2/anonymous_function_types.jsonc index 04a4a9a53..c36ebedbf 100644 --- a/decompiler/config/jak2/anonymous_function_types.jsonc +++ b/decompiler/config/jak2/anonymous_function_types.jsonc @@ -331,5 +331,5 @@ [11, "(function process none)"], [59, "(function process none)"], [56, "(function process-drawable none)"] - ] + ] } diff --git a/decompiler/config/jak2/hacks.jsonc b/decompiler/config/jak2/hacks.jsonc index 9143ad137..18e437f81 100644 --- a/decompiler/config/jak2/hacks.jsonc +++ b/decompiler/config/jak2/hacks.jsonc @@ -223,7 +223,6 @@ "bg", "update-sound-banks", "entity-remap-names" - ], // If format is used with the wrong number of arguments, diff --git a/decompiler/config/jak2/stack_structures.jsonc b/decompiler/config/jak2/stack_structures.jsonc index 626efc9ce..ffc569408 100644 --- a/decompiler/config/jak2/stack_structures.jsonc +++ b/decompiler/config/jak2/stack_structures.jsonc @@ -778,7 +778,10 @@ ], "(method 19 load-state)": [[16, ["inline-array", "level-buffer-state", 6]]], "(method 17 load-state)": [[16, "script-context"]], - "(method 26 level-group)": [[64, "vector"], [80, "vector"]], + "(method 26 level-group)": [ + [64, "vector"], + [80, "vector"] + ], // placeholder "placeholder-do-not-add-below": [] } diff --git a/decompiler/config/jak2/type_casts.jsonc b/decompiler/config/jak2/type_casts.jsonc index 641dc2638..777bc4430 100644 --- a/decompiler/config/jak2/type_casts.jsonc +++ b/decompiler/config/jak2/type_casts.jsonc @@ -1512,9 +1512,7 @@ [[55, 59], "s0", "(inline-array vector)"] ], // shrubbery - "shrub-upload-view-data": [ - [[8, 16], "a0", "dma-packet"] - ], + "shrub-upload-view-data": [[[8, 16], "a0", "dma-packet"]], "shrub-do-init-frame": [ [[12, 21], "a0", "dma-packet"], [[26, 29], "a0", "dma-packet"], @@ -1536,9 +1534,7 @@ [[33, 41], "a0", "dma-packet"], [[47, 55], "a0", "dma-packet"] ], - "draw-drawable-tree-instance-shrub": [ - [86, "a0", "drawable-group"] - ], + "draw-drawable-tree-instance-shrub": [[86, "a0", "drawable-group"]], "draw-prototype-inline-array-shrub": [ [[13, 56], "v1", "prototype-bucket-shrub"], [[102, 114], "a0", "shrub-near-packet"], @@ -1555,9 +1551,7 @@ [[677, 718], "gp", "prototype-bucket-shrub"], [[696, 706], "a1", "prototype-bucket-shrub"] ], - "(method 8 drawable-tree-instance-shrub)": [ - [54, "v1", "drawable-group"] - ], + "(method 8 drawable-tree-instance-shrub)": [[54, "v1", "drawable-group"]], "(method 13 drawable-tree-instance-shrub)": [ [[12, 151], "gp", "prototype-bucket-shrub"], [19, "a1", "drawable-group"], @@ -1571,10 +1565,7 @@ [23, "a2", "(pointer int32)"], [28, "a3", "(inline-array texture-masks)"] ], - "init-dma-test": [ - [29, "v1", "(inline-array qword)"] - ], - + "init-dma-test": [[29, "v1", "(inline-array qword)"]], "drawable-load": [[[25, 28], "s5", "drawable"]], "art-load": [[[13, 16], "s5", "art"]], "art-group-load-check": [[[43, 53], "s3", "art-group"]], @@ -1615,7 +1606,10 @@ [14, "v1", "gui-connection"] ], "(method 10 gui-control)": [[[4, 32], "s3", "gui-connection"]], - "(method 10 bsp-header)": [[49, "a3", "(pointer uint128)"]], + "(method 10 bsp-header)": [ + [43, "a1", "terrain-context"], + [31, "a0", "terrain-context"] + ], "bsp-camera-asm": [ [26, "v1", "pointer"], [[26, 63], "t1", "bsp-node"], @@ -2243,57 +2237,35 @@ "(anon-function 54 script)": [[66, "v1", "entity-actor"]], "(anon-function 53 script)": [[40, "v1", "entity-actor"]], "(anon-function 71 script)": [[4, "v1", "symbol"]], - "command-get-float": [ - [20, "gp", "bfloat"] - ], - "command-get-int": [ - [17, "gp", "bfloat"] - ], - "letterbox": [ - [[27, 33], "v1", "dma-packet"] - ], - "blackout": [ - [[18, 23], "v1", "dma-packet"] - ], + "letterbox": [[[27, 33], "v1", "dma-packet"]], + "blackout": [[[18, 23], "v1", "dma-packet"]], "(method 12 level)": [ [[182, 185], "a0", "texture-anim-array"], [343, "a0", "symbol"], [93, "t9", "(function level none)"], [[314, 322], "a1", "type"] ], - "bg": [ - [47, "a0", "symbol"] - ], + "bg": [[47, "a0", "symbol"]], "(method 10 load-state)": [ [436, "v1", "level"], [442, "v1", "level"] ], - "(method 14 level-group)": [ - [[53, 61], "a0", "entity-actor"] - ], + "(method 14 level-group)": [[[53, 61], "a0", "entity-actor"]], "(method 27 level-group)": [ [[112, 122], "s3", "entity-actor"], ["_stack_", 32, "vector"], ["_stack_", 36, "vector"] ], - "expand-vis-box-with-point":[ - [[10, 40], "v1", "(inline-array vector)"] - ], + "expand-vis-box-with-point": [[[10, 40], "v1", "(inline-array vector)"]], "check-for-rougue-process": [ - [[103,115], "v1", "part-tracker"], + [[103, 115], "v1", "part-tracker"], [[126, 140], "v1", "part-spawner"], [[153, 169], "v1", "process-drawable"], [[178, 194], "v1", "process-drawable"] ], - "process-drawable-scale-from-entity!": [ - [15, "v1", "vector"] - ], - "reset-actors": [ - [161, "s3", "(function level symbol none)"] - ], - "process-status-bits": [ - [[12, 58], "s3", "process-drawable"] - ], + "process-drawable-scale-from-entity!": [[15, "v1", "vector"]], + "reset-actors": [[161, "s3", "(function level symbol none)"]], + "process-status-bits": [[[12, 58], "s3", "process-drawable"]], "(method 26 level-group)": [ [134, "v0", "(pointer actor-group)"], // [135, "s2", "actor-group"], @@ -2306,12 +2278,8 @@ ["_stack_", 20, "vector"], ["_stack_", 24, "vector"] ], - "set-graphics-mode": [ - [[0, 100], "gp", "gs-bank"] - ], - "(method 3 entity-nav-mesh)": [ - [7, "t9", "(function object object)"] - ], + "set-graphics-mode": [[[0, 100], "gp", "gs-bank"]], + "(method 3 entity-nav-mesh)": [[7, "t9", "(function object object)"]], "draw-actor-marks": [ [20, "gp", "part-spawner"], [[29, 273], "gp", "process-drawable"], @@ -2325,39 +2293,34 @@ [639, "a0", "drawable-inline-array-region-prim"], [688, "a0", "drawable-inline-array-region-prim"], [705, "a0", "drawable-inline-array-region-prim"], - [[690, 694], "a0", "drawable-region-prim"] ], "build-masks": [ [[18, 22], "a1", "drawable-tree-tfrag"], [24, "a2", "drawable-inline-array-tfrag"], [[27, 31], "a2", "(inline-array tfragment)"], - [[38, 42], "a1", "drawable-tree-tfrag-trans"], [44, "a2", "drawable-inline-array-tfrag"], [[47, 51], "a2", "(inline-array tfragment)"], - - [[58, 62], "a1", "drawable-tree-tfrag-water"], [64, "a2", "drawable-inline-array-tfrag"], [[67, 71], "a2", "(inline-array tfragment)"], - - [[78, 79], "a1", "drawable-tree-instance-tie"], [123, "a1", "drawable-tree-instance-shrub"], [[129, 133], "a2", "(inline-array prototype-bucket-shrub)"] ], - - "(method 10 bsp-header)": [ - [43, "a1", "terrain-context"], - [31, "a0", "terrain-context"] - ], - "history-draw": [ [151, "a0", "uint"], ["_stack_", 24, "pat-surface"] ], - + "(method 14 drawable-group)": [[19, "s5", "drawable-group"]], + "(method 15 drawable-tree)": [ + [[1, 4], "v1", "drawable-inline-array-node"], + [[29, 34], "t0", "drawable-inline-array-node"], + [[28, 32], "t2", "drawable-inline-array-node"], + [[42, 46], "t2", "(pointer int8)"] + ], + "(method 14 drawable-tree-array)": [[11, "s5", "drawable-tree-array"]], // placeholder "placeholder-do-not-add-below": [] } diff --git a/decompiler/config/jak2/var_names.jsonc b/decompiler/config/jak2/var_names.jsonc index 331e8e201..5af6a9a03 100644 --- a/decompiler/config/jak2/var_names.jsonc +++ b/decompiler/config/jak2/var_names.jsonc @@ -7,19 +7,16 @@ "v1-25": "resource-mem" } }, - "(method 0 lightning-control)": { "vars": { "gp-0": ["obj", "lightning-control"] } }, - "(method 0 align-control)": { "vars": { "v0-0": ["obj", "align-control"] } }, - "(method 16 nav-mesh)": { "args": ["obj", "ray"], "vars": { @@ -39,12 +36,9 @@ "f0-10": "heading-dot" } }, - - // sprite "(method 0 sprite-aux-list)": { "args": ["allocation", "type-to-make", "size"] }, - "(method 0 sprite-array-2d)": { "args": ["allocation", "type-to-make", "group-0-size", "group-1-size"], "vars": { @@ -53,7 +47,6 @@ "a2-3": "adgif-data-size" } }, - "(method 0 sprite-array-3d)": { "args": ["allocation", "type-to-make", "group-0-size", "group-1-size"], "vars": { @@ -62,30 +55,24 @@ "a2-3": "adgif-data-size" } }, - "sprite-setup-header": { "args": ["hdr", "num-sprites"] }, - "add-to-sprite-aux-list": { "args": ["system", "sprite-info", "sprite-vec", "arg3"], "vars": { "v1-3": "aux-list" } }, - "sprite-setup-frame-data": { "args": ["data", "tbp-offset"] }, - "sprite-set-3d-quaternion!": { "args": ["sprite", "quat"] }, - "sprite-get-3d-quaternion!": { "args": ["out", "sprite"] }, - "sprite-add-matrix-data": { "args": ["dma-buff", "matrix-mode"], "vars": { @@ -97,14 +84,12 @@ "a1-20": "hvdf-idx" } }, - "sprite-add-frame-data": { "args": ["dma-buff", "tbp-offset"], "vars": { "a0-1": ["pkt", "dma-packet"] } }, - "sprite-add-2d-chunk": { "args": [ "sprites", @@ -123,7 +108,6 @@ "v1-7": ["pkt4", "dma-packet"] } }, - "sprite-add-2d-all": { "args": ["sprites", "dma-buff", "group-idx"], "vars": { @@ -132,7 +116,6 @@ "s3-0": "mscal-addr" } }, - "sprite-add-3d-chunk": { "args": ["sprites", "start-sprite-idx", "num-sprites", "dma-buff"], "vars": { @@ -145,7 +128,6 @@ "v1-7": ["pkt4", "dma-packet"] } }, - "sprite-add-3d-all": { "args": ["sprites", "dma-buff", "group-idx"], "vars": { @@ -153,7 +135,6 @@ "s3-0": "remaining-sprites" } }, - "sprite-draw": { "args": ["disp"], "vars": { @@ -171,16 +152,12 @@ "v1-34": "mem-use" } }, - "sprite-release-user-hvdf": { "args": ["idx"] }, - "sprite-get-user-hvdf": { "args": ["idx"] }, - - // sprite-distort "sprite-distorter-generate-tables": { "vars": { "gp-0": "tbls", @@ -193,11 +170,9 @@ "s5-0": "ientry-idx" } }, - "sprite-init-distorter": { "args": ["dma-buff"] }, - "sprite-draw-distorters": { "args": ["dma-buff"], "vars": { @@ -214,21 +189,17 @@ "v1-26": "clip-result" } }, - "(method 18 mood-control)": { "vars": { "v0-3": ["lightning-sound-id", "sound-id"] } }, - "(method 10 mood-control)": { "args": ["obj", "cloud-target", "fog-target", "cloud-speed", "fog-speed"] }, - "(method 11 mood-control)": { "args": ["obj", "min-cloud", "max-cloud", "min-fog", "max-fog"] }, - "copy-mood-exterior": { "vars": { "a1-4": ["a1-4", "(inline-array vector)"], @@ -236,19 +207,16 @@ "a0-2": ["a0-2", "(inline-array vector)"] } }, - "update-mood-strip": { "vars": { "s4-1": ["s4-1", "(pointer float)"] } }, - "update-mood-ruins": { "vars": { "gp-1": ["gp-1", "(pointer float)"] } }, - "desaturate-mood-colors": { "vars": { "a0-8": ["mood-colors", "(inline-array mood-color)"] @@ -259,20 +227,15 @@ "v1-2": "current-gun" } }, - "(method 10 cylinder)": { "args": ["obj", "ray1", "ray2"] }, - "ripple-make-request": { "args": ["waveform", "effect"] }, - "command-get-entity": { "args": ["search", "fallback"] }, - - // debug "transform-float-point": { "args": ["in", "out"] }, @@ -622,8 +585,6 @@ "s5-0": ["shader", "adgif-shader"] } }, - - // debug-sphere "make-debug-sphere-table": { "args": ["points", "h-lines", "v-lines"], "vars": { @@ -647,8 +608,6 @@ "sv-36": "point-3" } }, - - // shrubbery "shrub-num-tris": { "args": "shrub" }, @@ -708,7 +667,6 @@ "a0-14": ["a0-14", "shrub-near-packet"] } }, - "(method 10 cam-setting-data)": { "vars": { "v1-5": ["v1-5", "handle"], @@ -719,27 +677,22 @@ "v1-112": ["v1-112", "handle"] } }, - "(method 17 setting-control)": { "vars": { "v1-84": ["v1-84", "task-mask"] } }, - "(method 18 setting-control)": { "vars": { "a0-147": ["a0-147", "process-focusable"] } }, - "glst-insert-before": { "args": ["list", "curr", "new"] }, - "glst-insert-after": { "args": ["list", "curr", "new"] }, - "matrix-local->world": { "args": ["smooth?"] }, @@ -800,7 +753,6 @@ "add-nav-sphere": { "args": ["nav", "sphere", "max-spheres"] }, - "texture-bpp": { "args": ["tex-fmt"] }, @@ -827,7 +779,10 @@ }, "(method 10 texture-page)": { "args": ["obj", "num-segments", "upload-offset"], - "vars": { "v1-0": "offset", "a2-1": "i" } + "vars": { + "v1-0": "offset", + "a2-1": "i" + } }, "(method 16 texture-pool)": { "args": ["obj", "seg", "num-words"] @@ -949,7 +904,9 @@ }, "texture-page-level-allocate": { "args": ["pool", "tpage", "heap", "tpage-id"], - "vars": { "s2-0": "common-page-slot-id" } + "vars": { + "s2-0": "common-page-slot-id" + } }, "texture-page-size-check": { "args": ["pool", "lev", "silent"] @@ -1057,101 +1014,214 @@ "s1-4": ["nav-visnode", "mysql-nav-visnode"] } }, - "(method 18 level)": { + "(method 18 level)": { "vars": { - "s5-0" :"mem-mode", - "v1-5":"slot-in-borrow-from-lev", - "a0-4":"borrow-from-lev-idx", - "a1-3":"maybe-borrow-from-lev", - "a2-5":"check-slot-idx", - "a2-7":"found-borrow", - "a1-4":"borrow-from-lev", - "s2-0":"memory-unused?", - "v1-17":"bits-to-use", - "s4-0":"heap-size", - "s3-0":"offset-in-level-heap" + "s5-0": "mem-mode", + "v1-5": "slot-in-borrow-from-lev", + "a0-4": "borrow-from-lev-idx", + "a1-3": "maybe-borrow-from-lev", + "a2-5": "check-slot-idx", + "a2-7": "found-borrow", + "a1-4": "borrow-from-lev", + "s2-0": "memory-unused?", + "v1-17": "bits-to-use", + "s4-0": "heap-size", + "s3-0": "offset-in-level-heap" } }, "level-update-after-load": { "args": ["lev", "lstate"], "vars": { - "s3-0":"drawable-trees", - "s5-0":"start-time", - "v1-5":"current-time", - "s1-0":"login-state-pos", - "s2-0":"current-tree", - "s1-1":"tree-array-idx", - "v1-40":"art-group-array-idx", - "s2-1":"current-ag", - "s0-0":"current-array", - "s2-3":"proto-array", - "s0-1":"protos", - "sv-32":"proto", - "sv-48":"geom-idx", - "a0-56":"geom", - "s1-2":"proto2-idx", - "v1-134":"proto2", - "s0-2":"envmap-shader", - "v0-7":"envmap-tex", - "v1-155":"lev-bsp", - "f0-6":"close-dist", - "f1-3":"far-dist", - "v1-122":"borrower-idx", - "a0-104":"borrower-heap", - "v1-225":"end-time" + "s3-0": "drawable-trees", + "s5-0": "start-time", + "v1-5": "current-time", + "s1-0": "login-state-pos", + "s2-0": "current-tree", + "s1-1": "tree-array-idx", + "v1-40": "art-group-array-idx", + "s2-1": "current-ag", + "s0-0": "current-array", + "s2-3": "proto-array", + "s0-1": "protos", + "sv-32": "proto", + "sv-48": "geom-idx", + "a0-56": "geom", + "s1-2": "proto2-idx", + "v1-134": "proto2", + "s0-2": "envmap-shader", + "v0-7": "envmap-tex", + "v1-155": "lev-bsp", + "f0-6": "close-dist", + "f1-3": "far-dist", + "v1-122": "borrower-idx", + "a0-104": "borrower-heap", + "v1-225": "end-time" } }, - "(method 10 load-state)": { "vars": { - "v1-0":"discarded-level", - "s5-0":"most-recent-load-order", - "s4-0":"unload-attempt", - "a0-2":"unload-idx", - "a1-0":"unload-candidate-idx", - "a2-3":"unload-candidate-lev", - "a3-5":"still-wanted", - "s3-0":"lev-to-unload", - "a0-10":"all-levels-inactive", - "s5-1":"no-levels-at-all", - "v1-8":"desired-levels", - "a0-17":"want-lev-idx", - "s4-1":"want-lev-idx-to-load", - "s3-1":"new-lev", - "s5-2":"want-lev-i", - "s4-2":"lev-i", - "s3-2":"lev", - "v1-122":"lev-for-vis", - "a0-53":"num-vis-levs" + "v1-0": "discarded-level", + "s5-0": "most-recent-load-order", + "s4-0": "unload-attempt", + "a0-2": "unload-idx", + "a1-0": "unload-candidate-idx", + "a2-3": "unload-candidate-lev", + "a3-5": "still-wanted", + "s3-0": "lev-to-unload", + "a0-10": "all-levels-inactive", + "s5-1": "no-levels-at-all", + "v1-8": "desired-levels", + "a0-17": "want-lev-idx", + "s4-1": "want-lev-idx-to-load", + "s3-1": "new-lev", + "s5-2": "want-lev-i", + "s4-2": "lev-i", + "s3-2": "lev", + "v1-122": "lev-for-vis", + "a0-53": "num-vis-levs" } }, - "bsp-camera-asm": { "vars": { - "a3-0":"cam-pos-i1", - "a3-1":"cam-pos-32", - "a3-2":"cam-pos-16", - "a3-3":"cam-pos-8", - "a3-4":"cam-pos-8m", - "v1-0":"nodes", - "a2-0":"nidx", - "t1-1":"node", - "t3-0":"front-min", - "t6-0":"front-min-compare", - "t0-2":"front-max", - "t4-0":"front-max-compare", - "t2-0":"back-min", - "t7-0":"back-min-compare", - "t0-3":"back-max", - "t5-0":"back-max-compare", - "t0-4":"front-idx", - "t6-1":"not-f-min", - "t7-1":"not-b-min", - "t3-1":"f-flag", - "t4-2":"f-in-box", - "t5-2":"b-in-box", - "t2-1":"b-flag", - "t1-2":"back-idx" + "a3-0": "cam-pos-i1", + "a3-1": "cam-pos-32", + "a3-2": "cam-pos-16", + "a3-3": "cam-pos-8", + "a3-4": "cam-pos-8m", + "v1-0": "nodes", + "a2-0": "nidx", + "t1-1": "node", + "t3-0": "front-min", + "t6-0": "front-min-compare", + "t0-2": "front-max", + "t4-0": "front-max-compare", + "t2-0": "back-min", + "t7-0": "back-min-compare", + "t0-3": "back-max", + "t5-0": "back-max-compare", + "t0-4": "front-idx", + "t6-1": "not-f-min", + "t7-1": "not-b-min", + "t3-1": "f-flag", + "t4-2": "f-in-box", + "t5-2": "b-in-box", + "t2-1": "b-flag", + "t1-2": "back-idx" } + }, + "(method 0 drawable-group)": { + "args": ["allocation", "type-to-make", "length"], + "vars": { + "v0-0": "new-obj" + } + }, + "(method 2 drawable-group)": { + "vars": { + "s5-0": "idx" + } + }, + "(method 8 drawable-group)": { + "vars": { + "v1-6": "obj-size", + "s3-0": "idx" + } + }, + "(method 9 drawable-group)": { + "vars": { + "s5-0": "idx" + } + }, + "(method 10 drawable-group)": { + "vars": { + "s3-0": "idx" + } + }, + "(method 13 drawable-group)": { + "vars": { + "s5-0": "idx" + } + }, + "(method 14 drawable-group)": { + "vars": { + "s3-0": "idx" + } + }, + "(method 15 drawable-group)": { + "vars": { + "s4-0": "idx" + } + }, + "(method 14 drawable-tree-array)": { + "vars": { + "s3-0": "idx" + } + }, + "(method 13 drawable-tree-array)": { + "vars": { + "s5-0": "idx" + } + }, + "(method 10 drawable-tree-array)": { + "vars": { + "s3-0": "idx" + } + }, + "(method 10 path-control)": { + "args": ["obj", "ret", "idx", "search-type"], + "vars": { + "a1-1": "num-vertices", + "f0-3": "vert-idx" + } + }, + "(method 14 path-control)": { + "args": ["obj", "ret", "percent", "search-type"] + }, + "(method 26 path-control)": { + "args": ["obj", "ret", "idx", "mag"], + "vars": { + "v1-0": "num-vertices", + "f0-3": "vert-idx", + "f0-4": "capped-idx" + } + }, + "(method 13 curve-control)": { + "args": ["obj", "ret", "idx"] + }, + "(method 16 curve-control)": { + "args": ["obj", "ret", "percent"] + }, + "(method 15 curve-control)": { + "args": ["obj", "ret", "idx", "mag"] + }, + "(method 12 path-control)": { + "args": ["obj", "ret", "idx", "mag"] + }, + "(method 15 path-control)": { + "args": ["obj", "ret", "percent", "mag"] + }, + "(method 13 path-control)": { + "args": ["obj", "ret", "idx"] + }, + "(method 12 curve-control)": { + "args": ["obj", "ret", "percent", "mag"] + }, + "(method 16 path-control)": { + "args": ["obj", "ret", "percent", "mag"] + }, + "(method 22 path-control)": { + "args": ["obj", "point"], + "vars": { + "f30-0": "furthest-dist", + "s3-0": "given-point", + "s2-0": "closest-point", + "f0-5": "dist-to-point", + "s4-0": "next-point", + "s5-0": "curr-point", + "s1-0": "idx", + "f28-0": "vert-idx" + } + }, + "(method 23 path-control)": { + "args": ["obj", "point"] } } diff --git a/decompiler/config/jak2_ntsc_v1.jsonc b/decompiler/config/jak2_ntsc_v1.jsonc index 9e543fc4c..873b2858f 100644 --- a/decompiler/config/jak2_ntsc_v1.jsonc +++ b/decompiler/config/jak2_ntsc_v1.jsonc @@ -7,7 +7,7 @@ // if you want to filter to only some object names. // it will make the decompiler much faster. - "allowed_objects": ["level", "bsp", "entity", "process-drawable"], + "allowed_objects": [], "banned_objects": ["effect-control", "time-of-day"], //////////////////////////// diff --git a/goal_src/goal-lib.gc b/goal_src/goal-lib.gc index b5e08c860..9f8fd6f60 100644 --- a/goal_src/goal-lib.gc +++ b/goal_src/goal-lib.gc @@ -645,6 +645,10 @@ `(&-> (the-as (pointer ,t) ,addr) ,@fields) ) +(defmacro sext32 (in) + `(sar (shl ,in 32) 32) + ) + (defmacro shift-arith-right-32 (result in sa) `(set! ,result (sext32 (sar (logand #xffffffff (the-as int ,in)) ,sa))) ) diff --git a/goal_src/jak1/engine/gfx/font.gc b/goal_src/jak1/engine/gfx/font.gc index 41227aa63..d4f2f8ac5 100644 --- a/goal_src/jak1/engine/gfx/font.gc +++ b/goal_src/jak1/engine/gfx/font.gc @@ -48,15 +48,10 @@ ) ) - (defmacro .addu (result a b) `(set! ,result (sext32 (logand (+ (the-as int ,a) (the-as int ,b)) #xffffffff))) ) -(defmacro sext32 (in) - `(sar (shl ,in 32) 32) - ) - (defmacro .sra (result in sa) `(set! ,result (sext32 (sar (logand #xffffffff (the-as int ,in)) ,sa))) ) diff --git a/goal_src/jak2/engine/draw/drawable-group-h.gc b/goal_src/jak2/engine/draw/drawable-group-h.gc index a18c847d6..bdb7599da 100644 --- a/goal_src/jak2/engine/draw/drawable-group-h.gc +++ b/goal_src/jak2/engine/draw/drawable-group-h.gc @@ -5,6 +5,8 @@ ;; name in dgo: drawable-group-h ;; dgos: ENGINE, GAME +;; DECOMP BEGINS + (deftype drawable-group (drawable) ((length int16 :offset 6) (data drawable :dynamic :offset-assert 32) @@ -12,23 +14,7 @@ :method-count-assert 17 :size-assert #x20 :flag-assert #x1100000020 - ) - -(defmethod inspect drawable-group ((obj drawable-group)) - (when (not obj) - (return obj) + (:methods + (new (symbol type int) _type_ 0) ) - (format #t "[~8x] ~A~%" obj (-> obj type)) - (format #t "~1Tid: ~D~%" (-> obj id)) - (format #t "~1Tbsphere: ~`vector`P~%" (-> obj bsphere)) - (format #t "~1Tlength: ~D~%" (-> obj length)) - (format #t "~1Tdata[0] @ #x~X~%" (-> obj data)) - (dotimes (s5-0 (-> obj length)) - (format #t "~T [~D]~1Tdata: ~A~%" s5-0 (-> obj data s5-0)) - ) - obj ) - - - - diff --git a/goal_src/jak2/engine/draw/drawable-group.gc b/goal_src/jak2/engine/draw/drawable-group.gc index afb8926b2..1c4c9d42b 100644 --- a/goal_src/jak2/engine/draw/drawable-group.gc +++ b/goal_src/jak2/engine/draw/drawable-group.gc @@ -7,3 +7,92 @@ ;; DECOMP BEGINS +(defmethod new drawable-group ((allocation symbol) (type-to-make type) (length int)) + "Create a new [[drawable-group]] which can hold the provided number of [[drawable]]s" + (let ((new-obj (object-new allocation type-to-make (the-as int (+ (-> type-to-make size) (* length 4)))))) + (set! (-> new-obj length) length) + new-obj + ) + ) + +(defmethod print drawable-group ((obj drawable-group)) + (format #t "#<~A @ #x~X [~D]" (-> obj type) obj (-> obj length)) + (dotimes (idx (-> obj length)) + (format #t " ~A" (-> obj data idx)) + ) + (format #t ">") + obj + ) + +(defmethod length drawable-group ((obj drawable-group)) + (-> obj length) + ) + +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of drawable-group ((obj drawable-group)) + (the-as int (+ (-> drawable-group size) (* (-> obj length) 4))) + ) + +(defmethod mem-usage drawable-group ((obj drawable-group) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 1 (-> arg0 length))) + (set! (-> arg0 data 0 name) "drawable-group") + (+! (-> arg0 data 0 count) 1) + (let ((obj-size (asize-of obj))) + (+! (-> arg0 data 0 used) obj-size) + (+! (-> arg0 data 0 total) (logand -16 (+ obj-size 15))) + ) + (dotimes (idx (-> obj length)) + (mem-usage (-> obj data idx) arg0 arg1) + ) + obj + ) + +(defmethod login drawable-group ((obj drawable-group)) + (dotimes (idx (-> obj length)) + (login (-> obj data idx)) + ) + obj + ) + +(defmethod draw drawable-group ((obj drawable-group) (arg0 drawable-group) (arg1 display-frame)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (draw (-> obj data idx) (-> arg0 data idx) arg1) + ) + ) + ) + 0 + (none) + ) + +(defmethod collect-stats drawable-group ((obj drawable-group)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (collect-stats (-> obj data idx)) + ) + ) + ) + 0 + (none) + ) + +(defmethod debug-draw drawable-group ((obj drawable-group) (arg0 drawable) (arg1 display-frame)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (debug-draw (-> obj data idx) (-> (the-as drawable-group arg0) data idx) arg1) + ) + ) + ) + 0 + (none) + ) + +(defmethod unpack-vis drawable-group ((obj drawable-group) (arg0 (pointer int8)) (arg1 (pointer int8))) + (dotimes (idx (-> obj length)) + (set! arg1 (unpack-vis (-> obj data idx) arg0 arg1)) + ) + arg1 + ) diff --git a/goal_src/jak2/engine/draw/drawable-inline-array.gc b/goal_src/jak2/engine/draw/drawable-inline-array.gc index 105eb5ae6..a1b885a4e 100644 --- a/goal_src/jak2/engine/draw/drawable-inline-array.gc +++ b/goal_src/jak2/engine/draw/drawable-inline-array.gc @@ -7,3 +7,25 @@ ;; DECOMP BEGINS +(defmethod length drawable-inline-array ((obj drawable-inline-array)) + (-> obj length) + ) + +(defmethod login drawable-inline-array ((obj drawable-inline-array)) + obj + ) + +(defmethod draw drawable-inline-array ((obj drawable-inline-array) (arg0 drawable-inline-array) (arg1 display-frame)) + 0 + (none) + ) + +(defmethod collect-stats drawable-inline-array ((obj drawable-inline-array)) + 0 + (none) + ) + +(defmethod debug-draw drawable-inline-array ((obj drawable-inline-array) (arg0 drawable) (arg1 display-frame)) + 0 + (none) + ) diff --git a/goal_src/jak2/engine/draw/drawable-tree.gc b/goal_src/jak2/engine/draw/drawable-tree.gc index 8cd078b06..809f11144 100644 --- a/goal_src/jak2/engine/draw/drawable-tree.gc +++ b/goal_src/jak2/engine/draw/drawable-tree.gc @@ -7,3 +7,84 @@ ;; DECOMP BEGINS +(defmethod draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable-tree-array) (arg1 display-frame)) + (case (-> *level* draw-level *draw-index* display?) + (('special #f) + ) + (else + (dotimes (idx (-> obj length)) + (draw (-> obj trees idx) (-> arg0 trees idx) arg1) + ) + ) + ) + 0 + (none) + ) + +(defmethod collect-stats drawable-tree-array ((obj drawable-tree-array)) + (dotimes (idx (-> obj length)) + (collect-stats (-> obj trees idx)) + ) + 0 + (none) + ) + +(defmethod debug-draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable) (arg1 display-frame)) + (dotimes (idx (-> obj length)) + (debug-draw (-> obj trees idx) (-> (the-as drawable-tree-array arg0) trees idx) arg1) + ) + 0 + (none) + ) + +(defmethod unpack-vis drawable-tree ((obj drawable-tree) (arg0 (pointer int8)) (arg1 (pointer int8))) + (local-vars (t5-1 uint)) + (let* ((v1-0 (the-as drawable-inline-array-node (-> obj data 0))) + (a3-1 (/ (-> v1-0 data 0 id) 8)) + (t0-0 (-> v1-0 length)) + (v1-1 (&+ arg0 a3-1)) + (a3-3 (/ (+ t0-0 7) 8)) + ) + (dotimes (t0-1 a3-3) + (let ((t1-0 (-> arg1 0))) + (set! arg1 (&-> arg1 1)) + (set! (-> v1-1 0) t1-0) + ) + (set! v1-1 (&-> v1-1 1)) + ) + ) + (let ((v1-5 (+ (-> obj length) -1))) + (when (nonzero? v1-5) + (dotimes (a3-5 v1-5) + (let* ((t0-4 (-> obj data a3-5)) + (t2-0 (the-as drawable-inline-array-node (-> obj data (+ a3-5 1)))) + (t1-5 (/ (-> (the-as drawable-inline-array-node t0-4) data 0 id) 8)) + (t2-2 (/ (-> t2-0 data 0 id) 8)) + (t0-5 (-> (the-as drawable-inline-array-node t0-4) length)) + (t1-6 (&+ arg0 t1-5)) + (t2-3 (the-as object (&+ arg0 t2-2))) + ) + (loop + (let ((t3-0 (-> t1-6 0))) + (set! t1-6 (&-> t1-6 1)) + (let ((t4-0 128)) + (label cfg-7) + (b! (zero? (logand t3-0 t4-0)) cfg-9 :delay (set! t5-1 (the-as uint (-> arg1 0)))) + (set! arg1 (&-> arg1 1)) + (set! (-> (the-as (pointer int8) t2-3) 0) (the-as int t5-1)) + (label cfg-9) + (+! t0-5 -1) + (b! (zero? t0-5) cfg-12 :delay (shift-arith-right-32 t4-0 t4-0 1)) + (b! (nonzero? (the-as uint t4-0)) cfg-7 :delay (set! t2-3 (&-> (the-as (pointer int8) t2-3) 1))) + ) + ) + ) + ) + (label cfg-12) + (nop!) + 0 + ) + ) + ) + arg1 + ) diff --git a/goal_src/jak2/engine/geometry/path-h.gc b/goal_src/jak2/engine/geometry/path-h.gc index 0f9ed46a3..c5115eed5 100644 --- a/goal_src/jak2/engine/geometry/path-h.gc +++ b/goal_src/jak2/engine/geometry/path-h.gc @@ -19,12 +19,14 @@ ;; DECOMP BEGINS (deftype path-control (basic) - ((flags path-control-flag :offset-assert 4) - (name symbol :offset-assert 8) - (process process-drawable :offset-assert 12) - (curve curve :inline :offset-assert 16) - (num-cverts int32 :offset 20) - (cverts (inline-array vector) :offset 16) + "An abstraction around a [[curve]], providing tools such as: + - debug drawing + - conveniant vertex accessing + - vertex finding/searching algorithms" + ((flags path-control-flag :offset-assert 4) + (name symbol :offset-assert 8) + (process process-drawable :offset-assert 12) + (curve curve :inline :offset-assert 16) ) :method-count-assert 27 :size-assert #x24 @@ -32,28 +34,31 @@ (:methods (new (symbol type process symbol float entity symbol) _type_ 0) (debug-draw (_type_) none 9) - (path-control-method-10 () none 10) - (path-control-method-11 () none 11) - (path-control-method-12 () none 12) - (path-control-method-13 () none 13) - (path-control-method-14 () none 14) - (path-control-method-15 () none 15) - (path-control-method-16 () none 16) + (get-point-in-path! (_type_ vector float symbol) vector 10) + (get-random-point (_type_ vector) vector :behavior process 11) + (displacement-between-two-points-copy! (_type_ vector float float) vector 12) + (displacement-between-two-points-normalized! (_type_ vector float) vector 13) + (get-point-at-percent-along-path! (_type_ vector float symbol) vector 14) + (displacement-between-points-at-percent-scaled! (_type_ vector float float) vector 15) + (displacement-between-points-at-percent-normalized! (_type_ vector float) vector 16) (get-num-segments (_type_) float 17) - (path-control-method-18 () none 18) + (total-distance (_type_) float 18) (get-num-verts (_type_) int 19) (path-distance-equal-spacing (_type_ float) float 20) (average-segment-length (_type_ float) float 21) - (path-control-method-22 () none 22) - (path-control-method-23 () none 23) - (path-control-method-24 () none 24) + (get-furthest-point-on-path (_type_ vector) float 22) + (get-path-percentage-at-furthest-point (_type_ vector) float 23) + (path-control-method-24 (_type_ vector) vector 24) (should-display-marks? (_type_) symbol 25) - (path-control-method-26 () none 26) + (displacement-between-two-points! (_type_ vector float float) vector 26) ) ) + + (set! (-> path-control method-table 9) nothing) (deftype curve-control (path-control) + "Identical in terms of data to a [[path-control]] but has different implementation" () :method-count-assert 27 :size-assert #x24 @@ -63,6 +68,10 @@ ) ) + +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; WARN: Return type mismatch object vs path-control. (defmethod new path-control ((allocation symbol) (type-to-make type) (arg0 process) @@ -148,7 +157,7 @@ ) (defmethod get-num-verts path-control ((obj path-control)) - (the-as int (-> obj curve num-cverts)) + (-> obj curve num-cverts) ) (defmethod path-distance-equal-spacing path-control ((obj path-control) (arg0 float)) @@ -185,7 +194,7 @@ ) (when (not (get-curve-data! s3-1 (-> gp-0 curve) arg1 s2-0 arg2)) (cond - ((> (the-as int (-> gp-0 curve num-cverts)) 0) + ((> (-> gp-0 curve num-cverts) 0) (set! (-> gp-0 type) path-control) ) (else @@ -200,4 +209,3 @@ gp-0 ) ) - diff --git a/goal_src/jak2/engine/geometry/path.gc b/goal_src/jak2/engine/geometry/path.gc index 3ca5fd05c..3e59b2b75 100644 --- a/goal_src/jak2/engine/geometry/path.gc +++ b/goal_src/jak2/engine/geometry/path.gc @@ -7,3 +7,483 @@ ;; DECOMP BEGINS +(defmethod debug-draw path-control ((obj path-control)) + (cond + ((logtest? (-> obj flags) (path-control-flag not-found)) + (when (and (type? (-> obj process) process-drawable) *display-entity-errors*) + (let ((s5-0 add-debug-text-3d) + (s4-0 #t) + (s3-0 318) + ) + (format (clear *temp-string*) "path data error in ~S" (-> obj process name)) + (s5-0 + s4-0 + (the-as bucket-id s3-0) + *temp-string* + (-> obj process root trans) + (font-color precursor-#ec3b00) + (the-as vector2h #f) + ) + ) + ) + ) + ((let ((a0-5 obj)) + (and *display-path-marks* (logtest? (-> a0-5 flags) (path-control-flag display))) + ) + (dotimes (s5-1 (-> obj curve num-cverts)) + (let ((s4-1 (-> obj curve cverts s5-1))) + (if (and (logtest? (-> obj flags) (path-control-flag draw-line)) (< s5-1 (+ (-> obj curve num-cverts) -1))) + (add-debug-line + #t + (bucket-id debug-no-zbuf1) + s4-1 + (-> obj curve cverts (+ s5-1 1)) + (new 'static 'rgba :r #xff :g #x80 :a #x80) + #f + (the-as rgba -1) + ) + ) + (if (logtest? (-> obj flags) (path-control-flag draw-point)) + (add-debug-x #t (bucket-id debug-no-zbuf1) s4-1 (new 'static 'rgba :r #xff :a #x80)) + ) + (when (logtest? (-> obj flags) (path-control-flag draw-text)) + (let ((s3-1 add-debug-text-3d) + (s2-1 #t) + (s1-0 318) + ) + (format (clear *temp-string*) "~D" s5-1) + (s3-1 s2-1 (the-as bucket-id s1-0) *temp-string* s4-1 (font-color gold-#ba9200) (the-as vector2h #f)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +(defmethod total-distance path-control ((obj path-control)) + "Calcuate the total path length by summing the distance between each adjacent [[curve]] vertex" + (let ((f30-0 0.0)) + (dotimes (s5-0 (+ (-> obj curve num-cverts) -1)) + (+! f30-0 (vector-vector-distance (-> obj curve cverts s5-0) (-> obj curve cverts (+ s5-0 1)))) + ) + f30-0 + ) + ) + +(defmethod total-distance curve-control ((obj curve-control)) + "Calcuate the total path length by summing the distance between each adjacent [[curve]] vertex" + (let ((f0-0 (-> obj curve length))) + (when (= f0-0 0.0) + (set! f0-0 (curve-length (-> obj curve))) + (set! (-> obj curve length) f0-0) + ) + f0-0 + ) + ) + +(defmethod get-point-in-path! path-control ((obj path-control) (ret vector) (idx float) (search-type symbol)) + "Depending on the value of `idx`, the result can be quite different: + - if `idx` is less than `0.0` - return the first vertex in the path + - if `idx` is greater than the number of vertices in the path, return the last vertex + - if `search-type` is equal to `exact` OR `idx` is an integral number (ex 1.0), return that vertex + - otherwise, do a linear interpolation between the vertex at `idx` (truncated) and the next vertex + using the fractional component of `idx` as the interpolant, return this result + + @param! ret The [[vector]] that is used to hold the return value + @param idx Either the vertex index or also partially the interpolant in a LERP + @param search-type The only recognized value is `exact` + @returns Either a distinct vertex along the path, or some fractional point between two vertices" + (let ((num-vertices (-> obj curve num-cverts)) + (vert-idx (the float (the int idx))) + ) + (cond + ((< idx 0.0) + (set! (-> ret quad) (-> obj curve cverts 0 quad)) + ) + ((>= vert-idx (the float (+ num-vertices -1))) + (set! (-> ret quad) (-> obj curve cverts (+ num-vertices -1) quad)) + ) + ((or (= search-type 'exact) (= vert-idx idx)) + (set! (-> ret quad) (-> obj curve cverts (the int vert-idx) quad)) + ) + (else + (vector-lerp! + ret + (-> obj curve cverts (the int vert-idx)) + (-> obj curve cverts (the int (+ 1.0 vert-idx))) + (- idx vert-idx) + ) + ) + ) + ) + ret + ) + +(defmethod get-random-point path-control ((obj path-control) (arg0 vector)) + "Attempts to retrieve a random point along the path, returns the [[*null-vector*]] if no vertices are defined" + (cond + ((> (-> obj curve num-cverts) 0) + (let ((a0-2 (rand-vu-int-count (-> obj curve num-cverts)))) + (set! (-> arg0 quad) (-> obj curve cverts a0-2 quad)) + ) + ) + (else + (format #t "WARNING: method get-random-point called on a path-control object with no vertices.~%") + (if self + (format #t "current process is ~A~%" (-> self name)) + ) + (set! (-> arg0 quad) (-> *null-vector* quad)) + ) + ) + arg0 + ) + +(defmethod get-point-at-percent-along-path! path-control ((obj path-control) (ret vector) (percent float) (search-type symbol)) + "@param! ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path + @param search-type The only recognized value is `exact` + @returns the point closest to some arbitrary percentage along the path + @see [[path-control::10]]" + (get-point-in-path! obj ret (* percent (the float (+ (-> obj curve num-cverts) -1))) search-type) + ) + +(defmethod get-point-at-percent-along-path! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 symbol)) + "@param! ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path + @param search-type The only recognized value is `exact` + @returns the point closest to some arbitrary percentage along the path + @see [[path-control::10]]" + (if (zero? (logand (-> obj flags) (path-control-flag not-found))) + (curve-evaluate! + arg0 + arg1 + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + ) + arg0 + ) + +(defmethod get-point-in-path! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 symbol)) + "Depending on the value of `idx`, the result can be quite different: + - if `idx` is less than `0.0` - return the first vertex in the path + - if `idx` is greater than the number of vertices in the path, return the last vertex + - if `search-type` is equal to `exact` OR `idx` is an integral number (ex 1.0), return that vertex + - otherwise, do a linear interpolation between the vertex at `idx` (truncated) and the next vertex + using the fractional component of `idx` as the interpolant, return this result + + @param! ret The [[vector]] that is used to hold the return value + @param idx Either the vertex index or also partially the interpolant in a LERP + @param search-type The only recognized value is `exact` + @returns Either a distinct vertex along the path, or some fractional point between two vertices" + (if (zero? (logand (-> obj flags) (path-control-flag not-found))) + (curve-evaluate! + arg0 + (/ arg1 (the float (+ (-> obj curve num-cverts) -1))) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + ) + arg0 + ) + +(defmethod displacement-between-two-points! path-control ((obj path-control) (ret vector) (idx float) (mag float)) + "Return value can differ quite a bit: + - If [[path-control-flag::4]] is set OR there are less than 2 vertices OR `idx` is less than `0.0` - return [[*null-vector*]] + - Otherwise, find the scaled (by `mag`) displacement vector between two points in the path: + - If `idx` is not beyond the second last vertex, the result is between vertex `idx` and `idx+1` + - else, the result is between the second last vertex and the last + + @param! ret The [[vector]] that is used to hold the return value + @param idx The vertex index + @param mag The magnitude to scale the resulting displacement vector by + @returns The displacement [[vector]] between two points in the path, the last 2, or the [[*null-vector*]]" + (let ((num-vertices (-> obj curve num-cverts)) + (vert-idx (the float (the int idx))) + ) + (cond + ((or (logtest? (-> obj flags) (path-control-flag not-found)) (< num-vertices 2) (< idx 0.0)) + (vector-reset! ret) + ) + (else + (let ((capped-idx (fmin vert-idx (the float (+ num-vertices -2))))) + (vector-! ret (-> obj curve cverts (the int (+ 1.0 capped-idx))) (-> obj curve cverts (the int capped-idx))) + ) + (vector-float*! ret ret mag) + ) + ) + ) + ret + ) + +(defmethod displacement-between-two-points-copy! path-control ((obj path-control) (ret vector) (idx float) (mag float)) + "Calls [[path-control::26]] with the provided args + @see [[path-control::26]]" + (displacement-between-two-points! obj ret idx mag) + ) + +(defmethod displacement-between-points-at-percent-scaled! path-control ((obj path-control) (ret vector) (percent float) (mag float)) + "Calls [[path-control::12], with the `idx` at a given percent along the path + @param ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path to find the first index + @param mag Multiplied by the number of points in the path and scales the resulting vector + @returns The displacement between the last two points of the path scaled to the magnitude equal to the number of points in the path" + (displacement-between-two-points-copy! + obj + ret + (* percent (the float (+ (-> obj curve num-cverts) -1))) + (* mag (the float (+ (-> obj curve num-cverts) -1))) + ) + ) + +(defmethod displacement-between-two-points-normalized! path-control ((obj path-control) (ret vector) (idx float)) + "Calls [[path-control::26], with the provided `idx` + @param! ret The [[vector]] the result is stored within + @param idx The vertex index + @returns The resulting displacement vector, normalized + @see [[path-control::26]]" + (displacement-between-two-points! obj ret idx 1.0) + (vector-normalize! ret 1.0) + ) + +(defmethod displacement-between-points-at-percent-normalized! path-control ((obj path-control) (ret vector) (percent float)) + "Calls [[path-control::13], with the `idx` at a given percent along the path + @param! ret The [[vector]] the result is stored within + @param percent The percentage along the path + @returns The resulting displacement vector, normalized + @see [[path-control::13]] + @see [[path-control::14]]" + (displacement-between-two-points-normalized! obj ret (* percent (the float (+ (-> obj curve num-cverts) -1)))) + ) + +(defmethod displacement-between-two-points! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 float)) + "Return value can differ quite a bit: + - If [[path-control-flag::4]] is set OR there are less than 2 vertices OR `idx` is less than `0.0` - return [[*null-vector*]] + - Otherwise, find the scaled (by `mag`) displacement vector between two points in the path: + - If `idx` is not beyond the second last vertex, the result is between vertex `idx` and `idx+1` + - else, the result is between the second last vertex and the last + + @param! ret The [[vector]] that is used to hold the return value + @param idx The vertex index + @param mag The magnitude to scale the resulting displacement vector by + @returns The displacement [[vector]] between two points in the path, the last 2, or the [[*null-vector*]]" + (when (zero? (logand (-> obj flags) (path-control-flag not-found))) + (let ((s4-0 (new 'stack-no-clear 'vector))) + (curve-evaluate! + arg0 + arg1 + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (cond + ((< arg1 (- 1.0 arg2)) + (curve-evaluate! + s4-0 + (+ arg1 arg2) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (vector-! arg0 s4-0 arg0) + ) + (else + (curve-evaluate! + s4-0 + (- arg1 arg2) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (vector-! arg0 arg0 s4-0) + ) + ) + ) + ) + ) + +(defmethod displacement-between-two-points-copy! curve-control ((obj curve-control) (ret vector) (percent float) (mag float)) + "Calls [[path-control::26]] with the provided args + @see [[path-control::26]]" + (displacement-between-two-points! obj ret (/ percent (the float (+ (-> obj curve num-cverts) -1))) mag) + ) + +(defmethod displacement-between-points-at-percent-scaled! curve-control ((obj curve-control) (ret vector) (idx float) (mag float)) + "Calls [[path-control::12], with the `idx` at a given percent along the path + @param ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path to find the first index + @param mag Multiplied by the number of points in the path and scales the resulting vector + @returns The displacement between the last two points of the path scaled to the magnitude equal to the number of points in the path" + (displacement-between-two-points! obj ret idx mag) + ) + +(defmethod displacement-between-points-at-percent-normalized! curve-control ((obj curve-control) (ret vector) (percent float)) + "Calls [[path-control::13], with the `idx` at a given percent along the path + @param! ret The [[vector]] the result is stored within + @param percent The percentage along the path + @returns The resulting displacement vector, normalized + @see [[path-control::13]] + @see [[path-control::14]]" + (displacement-between-two-points! obj ret percent 0.01) + (vector-normalize! ret 1.0) + ) + +(defmethod displacement-between-two-points-normalized! curve-control ((obj curve-control) (ret vector) (idx float)) + "Calls [[path-control::26], with the provided `idx` + @param! ret The [[vector]] the result is stored within + @param idx The vertex index + @returns The resulting displacement vector, normalized + @see [[path-control::26]]" + (displacement-between-points-at-percent-normalized! + obj + ret + (/ idx (the float (+ (-> obj curve num-cverts) -1))) + ) + ) + +(defmethod get-furthest-point-on-path path-control ((obj path-control) (point vector)) + "@param point The point to calculate distance from + @returns the `vertex-idx.interpolant` value to the point on the path furthest away from the `point` + @see [[path-control::10]]" + (let ((curr-point (new 'stack-no-clear 'vector)) + (next-point (new 'stack-no-clear 'vector)) + (given-point (new 'stack-no-clear 'vector)) + (furthest-dist 4096000000.0) + (vert-idx 0.0) + ) + (let ((closest-point (new 'stack-no-clear 'vector))) + (set! (-> given-point quad) (-> point quad)) + (set! (-> given-point y) 0.0) + (get-point-in-path! obj next-point 0.0 'interp) + (set! (-> next-point y) 0.0) + (dotimes (idx (+ (-> obj curve num-cverts) -1)) + (set! (-> curr-point quad) (-> next-point quad)) + (get-point-in-path! obj next-point (the float (+ idx 1)) 'interp) + (set! (-> next-point y) 0.0) + (let ((dist-to-point (vector-segment-distance-point! given-point curr-point next-point closest-point))) + (when (< dist-to-point furthest-dist) + (set! furthest-dist dist-to-point) + (set! vert-idx + (+ (/ (vector-vector-xz-distance closest-point curr-point) (vector-vector-xz-distance next-point curr-point)) + (the float idx) + ) + ) + ) + ) + ) + ) + vert-idx + ) + ) + +(defmethod get-path-percentage-at-furthest-point path-control ((obj path-control) (point vector)) + "@param point The point to calculate distance from + @returns the percentage of path completion from the point on the path furthest away from the `point` + @see [[path-control::14]]" + (/ (get-furthest-point-on-path obj point) (the float (+ (-> obj curve num-cverts) -1))) + ) + +(defmethod debug-draw curve-control ((obj curve-control)) + (cond + ((logtest? (-> obj flags) (path-control-flag not-found)) + (when (and (type? (-> obj process) process-drawable) *display-entity-errors*) + (let ((s5-0 add-debug-text-3d) + (s4-0 #t) + (s3-0 318) + ) + (format (clear *temp-string*) "curve data error in ~S" (-> obj process name)) + (s5-0 + s4-0 + (the-as bucket-id s3-0) + *temp-string* + (-> obj process root trans) + (font-color precursor-#ec3b00) + (the-as vector2h #f) + ) + ) + ) + ) + ((let ((a0-5 obj)) + (and *display-path-marks* (logtest? (-> a0-5 flags) (path-control-flag display))) + ) + (if (and (logtest? (-> obj flags) (path-control-flag draw-line)) (> (-> obj curve num-cverts) 0)) + (add-debug-curve2 #t (bucket-id debug-no-zbuf1) (-> obj curve) (new 'static 'rgba :r #xff :g #x80 :a #x80) #f) + ) + (dotimes (s5-1 (-> obj curve num-cverts)) + (let ((s4-1 (-> obj curve cverts s5-1))) + (if (logtest? (-> obj flags) (path-control-flag draw-point)) + (add-debug-x #t (bucket-id debug-no-zbuf1) s4-1 (new 'static 'rgba :r #xff :a #x80)) + ) + (when (logtest? (-> obj flags) (path-control-flag draw-text)) + (let ((s3-1 add-debug-text-3d) + (s2-1 #t) + (s1-0 318) + ) + (format (clear *temp-string*) "~D" s5-1) + (s3-1 s2-1 (the-as bucket-id s1-0) *temp-string* s4-1 (font-color gold-#ba9200) (the-as vector2h #f)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +(defmethod path-control-method-24 path-control ((obj path-control) (arg0 vector)) + "TODO" + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (-> obj curve num-cverts))) + (let ((f30-0 (/ 1.0 (the float s4-0)))) + (set-vector! arg0 0.0 0.0 0.0 0.0) + (dotimes (s3-0 s4-0) + (let ((s2-0 arg0)) + (let ((s1-0 arg0) + (v1-4 (get-point-in-path! obj (new 'stack-no-clear 'vector) (the float s3-0) 'interp)) + (f0-7 f30-0) + ) + (.lvf vf2 (&-> v1-4 quad)) + (.lvf vf1 (&-> s1-0 quad)) + (let ((v1-5 f0-7)) + (.mov vf3 v1-5) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> s2-0 quad) vf4) + ) + ) + ) + (dotimes (s3-1 s4-0) + (let ((f0-10 + (vector-vector-distance arg0 (get-point-in-path! obj (new 'stack-no-clear 'vector) (the float s3-1) 'interp)) + ) + ) + (if (< (-> arg0 w) f0-10) + (set! (-> arg0 w) (+ 4096.0 f0-10)) + ) + ) + ) + ) + arg0 + ) + ) diff --git a/scripts/gsrc/update-from-decomp.py b/scripts/gsrc/update-from-decomp.py index c40c9b92e..bcb1db64a 100644 --- a/scripts/gsrc/update-from-decomp.py +++ b/scripts/gsrc/update-from-decomp.py @@ -93,6 +93,7 @@ lines_to_ignore = [ ";; failed to figure", ";; Used lq/sq", ";; this part is debug only", + ";; WARN: Return type mismatch int vs none" ] if decomp_ignore_errors: @@ -180,6 +181,19 @@ else: if args.preserve: handle_dangling_blocks(comments, final_lines, debug_lines) -# Step 4: Write it out +# Step 4.a: Remove excessive new-lines from the end of the output, only leave a single empty new-line +lines_to_ignore = 0 +i = len(final_lines) - 1 +while i > 0 and (final_lines[i] == "\n" or final_lines[i] == "0\n"): + print(final_lines[i]) + lines_to_ignore = lines_to_ignore + 1 + i = i - 1 + +print("ignoring - {}".format(lines_to_ignore)) + +# Step 4.b: Write it out with open(gsrc_path, "w") as f: - f.writelines(final_lines) + i = 0 + while i + lines_to_ignore < len(final_lines): + f.write(final_lines[i]) + i = i + 1 diff --git a/test/decompiler/reference/jak1/engine/gfx/sky/sky-tng_REF.gc b/test/decompiler/reference/jak1/engine/gfx/sky/sky-tng_REF.gc index 405f356d1..bbcdd7cb4 100644 --- a/test/decompiler/reference/jak1/engine/gfx/sky/sky-tng_REF.gc +++ b/test/decompiler/reference/jak1/engine/gfx/sky/sky-tng_REF.gc @@ -149,7 +149,7 @@ ;; definition for function close-sky-buffer ;; INFO: Used lq/sq ;; INFO: Return type mismatch pointer vs none. -;; WARN: Function may read a register that is not set: ra +;; ERROR: Function may read a register that is not set: ra ;; ERROR: Unsupported inline assembly instruction kind - [jr ra] (defun close-sky-buffer ((arg0 dma-buffer)) (local-vars (ra-0 none)) diff --git a/test/decompiler/reference/jak1/engine/gfx/vis/bsp_REF.gc b/test/decompiler/reference/jak1/engine/gfx/vis/bsp_REF.gc index 643cbdbcf..d268a6421 100644 --- a/test/decompiler/reference/jak1/engine/gfx/vis/bsp_REF.gc +++ b/test/decompiler/reference/jak1/engine/gfx/vis/bsp_REF.gc @@ -396,7 +396,7 @@ ;; definition for function bsp-camera-asm ;; INFO: Return type mismatch int vs none. -;; WARN: Function may read a register that is not set: a2 +;; ERROR: Function may read a register that is not set: a2 (defun bsp-camera-asm ((bsp-hdr bsp-header) (camera-pos vector)) (local-vars (v1-1 float) (real-node bsp-node)) (rlet ((vf1 :class vf) diff --git a/test/decompiler/reference/jak1/levels/rolling/rolling-obs_REF.gc b/test/decompiler/reference/jak1/levels/rolling/rolling-obs_REF.gc index 69c5353c8..a871ecb83 100644 --- a/test/decompiler/reference/jak1/levels/rolling/rolling-obs_REF.gc +++ b/test/decompiler/reference/jak1/levels/rolling/rolling-obs_REF.gc @@ -873,7 +873,7 @@ ;; definition for function race-time-save ;; ERROR: Type Propagation failed: Failed type prop at op 6 ((set! v1 (l.wu (+ a0 -4)))): Could not get type of load: (set! v1 (l.wu (+ a0 -4))). ;; ERROR: Type analysis failed -;; WARN: Function may read a register that is not set: a2 +;; ERROR: Function may read a register that is not set: a2 (defun race-time-save ((a0-0 race-time) (a1-0 task-control)) (local-vars (v0-0 none) diff --git a/test/decompiler/reference/jak1/levels/swamp/swamp-rat-nest_REF.gc b/test/decompiler/reference/jak1/levels/swamp/swamp-rat-nest_REF.gc index b4d9f6914..d6711ad4b 100644 --- a/test/decompiler/reference/jak1/levels/swamp/swamp-rat-nest_REF.gc +++ b/test/decompiler/reference/jak1/levels/swamp/swamp-rat-nest_REF.gc @@ -943,7 +943,7 @@ swamp-rat-nest-default-event-handler ;; definition for function swamp-rat-nest-spawn-rat ;; INFO: Used lq/sq ;; INFO: Return type mismatch (pointer process) vs (pointer swamp-rat). -;; WARN: Function may read a register that is not set: t2 +;; ERROR: Function may read a register that is not set: t2 (defbehavior swamp-rat-nest-spawn-rat swamp-rat-nest () (local-vars (t2-0 none)) (the-as diff --git a/test/decompiler/reference/jak2/engine/anim/joint_REF.gc b/test/decompiler/reference/jak2/engine/anim/joint_REF.gc index 8ca36e0df..29dd4d2ae 100644 --- a/test/decompiler/reference/jak2/engine/anim/joint_REF.gc +++ b/test/decompiler/reference/jak2/engine/anim/joint_REF.gc @@ -1459,7 +1459,7 @@ ) ;; definition for function cspace<-parented-transformq-joint! -;; WARN: Function may read a register that is not set: ra +;; ERROR: Function may read a register that is not set: ra ;; ERROR: Unsupported inline assembly instruction kind - [jr ra] ;; ERROR: Unsupported inline assembly instruction kind - [jr ra] (defun cspace<-parented-transformq-joint! ((arg0 cspace) (arg1 transformq)) diff --git a/test/decompiler/reference/jak2/engine/draw/drawable-group-h_REF.gc b/test/decompiler/reference/jak2/engine/draw/drawable-group-h_REF.gc index b94d6ba6a..b9295548b 100644 --- a/test/decompiler/reference/jak2/engine/draw/drawable-group-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/draw/drawable-group-h_REF.gc @@ -9,6 +9,9 @@ :method-count-assert 17 :size-assert #x20 :flag-assert #x1100000020 + (:methods + (new (symbol type int) _type_ 0) + ) ) ;; definition for method 3 of type drawable-group @@ -31,7 +34,3 @@ ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak2/engine/draw/drawable-group_REF.gc b/test/decompiler/reference/jak2/engine/draw/drawable-group_REF.gc new file mode 100644 index 000000000..51b2c5ba7 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/draw/drawable-group_REF.gc @@ -0,0 +1,105 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 0 of type drawable-group +(defmethod new drawable-group ((allocation symbol) (type-to-make type) (length int)) + "Create a new [[drawable-group]] which can hold the provided number of [[drawable]]s" + (let ((new-obj (object-new allocation type-to-make (the-as int (+ (-> type-to-make size) (* length 4)))))) + (set! (-> new-obj length) length) + new-obj + ) + ) + +;; definition for method 2 of type drawable-group +(defmethod print drawable-group ((obj drawable-group)) + (format #t "#<~A @ #x~X [~D]" (-> obj type) obj (-> obj length)) + (dotimes (idx (-> obj length)) + (format #t " ~A" (-> obj data idx)) + ) + (format #t ">") + obj + ) + +;; definition for method 4 of type drawable-group +(defmethod length drawable-group ((obj drawable-group)) + (-> obj length) + ) + +;; definition for method 5 of type drawable-group +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of drawable-group ((obj drawable-group)) + (the-as int (+ (-> drawable-group size) (* (-> obj length) 4))) + ) + +;; definition for method 8 of type drawable-group +(defmethod mem-usage drawable-group ((obj drawable-group) (arg0 memory-usage-block) (arg1 int)) + (set! (-> arg0 length) (max 1 (-> arg0 length))) + (set! (-> arg0 data 0 name) "drawable-group") + (+! (-> arg0 data 0 count) 1) + (let ((obj-size (asize-of obj))) + (+! (-> arg0 data 0 used) obj-size) + (+! (-> arg0 data 0 total) (logand -16 (+ obj-size 15))) + ) + (dotimes (idx (-> obj length)) + (mem-usage (-> obj data idx) arg0 arg1) + ) + obj + ) + +;; definition for method 9 of type drawable-group +(defmethod login drawable-group ((obj drawable-group)) + (dotimes (idx (-> obj length)) + (login (-> obj data idx)) + ) + obj + ) + +;; definition for method 10 of type drawable-group +;; WARN: Return type mismatch int vs none. +(defmethod draw drawable-group ((obj drawable-group) (arg0 drawable-group) (arg1 display-frame)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (draw (-> obj data idx) (-> arg0 data idx) arg1) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 13 of type drawable-group +;; WARN: Return type mismatch int vs none. +(defmethod collect-stats drawable-group ((obj drawable-group)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (collect-stats (-> obj data idx)) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 14 of type drawable-group +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw drawable-group ((obj drawable-group) (arg0 drawable) (arg1 display-frame)) + (when (vis-cull (-> obj id)) + (when (sphere-cull (-> obj bsphere)) + (dotimes (idx (-> obj length)) + (debug-draw (-> obj data idx) (-> (the-as drawable-group arg0) data idx) arg1) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 15 of type drawable-group +(defmethod unpack-vis drawable-group ((obj drawable-group) (arg0 (pointer int8)) (arg1 (pointer int8))) + (dotimes (idx (-> obj length)) + (set! arg1 (unpack-vis (-> obj data idx) arg0 arg1)) + ) + arg1 + ) diff --git a/test/decompiler/reference/jak2/engine/draw/drawable-inline-array_REF.gc b/test/decompiler/reference/jak2/engine/draw/drawable-inline-array_REF.gc new file mode 100644 index 000000000..9dad167a8 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/draw/drawable-inline-array_REF.gc @@ -0,0 +1,37 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 4 of type drawable-inline-array +(defmethod length drawable-inline-array ((obj drawable-inline-array)) + (-> obj length) + ) + +;; definition for method 9 of type drawable-inline-array +(defmethod login drawable-inline-array ((obj drawable-inline-array)) + obj + ) + +;; definition for method 10 of type drawable-inline-array +;; WARN: Return type mismatch int vs none. +(defmethod draw drawable-inline-array ((obj drawable-inline-array) (arg0 drawable-inline-array) (arg1 display-frame)) + 0 + (none) + ) + +;; definition for method 13 of type drawable-inline-array +;; WARN: Return type mismatch int vs none. +(defmethod collect-stats drawable-inline-array ((obj drawable-inline-array)) + 0 + (none) + ) + +;; definition for method 14 of type drawable-inline-array +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw drawable-inline-array ((obj drawable-inline-array) (arg0 drawable) (arg1 display-frame)) + 0 + (none) + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/draw/drawable-tree_REF.gc b/test/decompiler/reference/jak2/engine/draw/drawable-tree_REF.gc new file mode 100644 index 000000000..2ae38a813 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/draw/drawable-tree_REF.gc @@ -0,0 +1,91 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 10 of type drawable-tree-array +;; WARN: Return type mismatch int vs none. +(defmethod draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable-tree-array) (arg1 display-frame)) + (case (-> *level* draw-level *draw-index* display?) + (('special #f) + ) + (else + (dotimes (idx (-> obj length)) + (draw (-> obj trees idx) (-> arg0 trees idx) arg1) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 13 of type drawable-tree-array +;; WARN: Return type mismatch int vs none. +(defmethod collect-stats drawable-tree-array ((obj drawable-tree-array)) + (dotimes (idx (-> obj length)) + (collect-stats (-> obj trees idx)) + ) + 0 + (none) + ) + +;; definition for method 14 of type drawable-tree-array +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw drawable-tree-array ((obj drawable-tree-array) (arg0 drawable) (arg1 display-frame)) + (dotimes (idx (-> obj length)) + (debug-draw (-> obj trees idx) (-> (the-as drawable-tree-array arg0) trees idx) arg1) + ) + 0 + (none) + ) + +;; definition for method 15 of type drawable-tree +(defmethod unpack-vis drawable-tree ((obj drawable-tree) (arg0 (pointer int8)) (arg1 (pointer int8))) + (local-vars (t5-1 uint)) + (let* ((v1-0 (the-as drawable-inline-array-node (-> obj data 0))) + (a3-1 (/ (-> v1-0 data 0 id) 8)) + (t0-0 (-> v1-0 length)) + (v1-1 (&+ arg0 a3-1)) + (a3-3 (/ (+ t0-0 7) 8)) + ) + (dotimes (t0-1 a3-3) + (let ((t1-0 (-> arg1 0))) + (set! arg1 (&-> arg1 1)) + (set! (-> v1-1 0) t1-0) + ) + (set! v1-1 (&-> v1-1 1)) + ) + ) + (let ((v1-5 (+ (-> obj length) -1))) + (when (nonzero? v1-5) + (dotimes (a3-5 v1-5) + (let* ((t0-4 (-> obj data a3-5)) + (t2-0 (the-as drawable-inline-array-node (-> obj data (+ a3-5 1)))) + (t1-5 (/ (-> (the-as drawable-inline-array-node t0-4) data 0 id) 8)) + (t2-2 (/ (-> t2-0 data 0 id) 8)) + (t0-5 (-> (the-as drawable-inline-array-node t0-4) length)) + (t1-6 (&+ arg0 t1-5)) + (t2-3 (the-as object (&+ arg0 t2-2))) + ) + (loop + (let ((t3-0 (-> t1-6 0))) + (set! t1-6 (&-> t1-6 1)) + (let ((t4-0 128)) + (label cfg-7) + (b! (zero? (logand t3-0 t4-0)) cfg-9 :delay (set! t5-1 (the-as uint (-> arg1 0)))) + (set! arg1 (&-> arg1 1)) + (set! (-> (the-as (pointer int8) t2-3) 0) (the-as int t5-1)) + (label cfg-9) + (+! t0-5 -1) + (b! (zero? t0-5) cfg-12 :delay (shift-arith-right-32 t4-0 t4-0 1)) + (b! (nonzero? (the-as uint t4-0)) cfg-7 :delay (set! t2-3 (&-> (the-as (pointer int8) t2-3) 1))) + ) + ) + ) + ) + (label cfg-12) + (nop!) + 0 + ) + ) + ) + arg1 + ) diff --git a/test/decompiler/reference/jak2/engine/geometry/path-h_REF.gc b/test/decompiler/reference/jak2/engine/geometry/path-h_REF.gc index c66c444f2..e5510fb06 100644 --- a/test/decompiler/reference/jak2/engine/geometry/path-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/geometry/path-h_REF.gc @@ -3,12 +3,14 @@ ;; definition of type path-control (deftype path-control (basic) - ((flags path-control-flag :offset-assert 4) - (name symbol :offset-assert 8) - (process process-drawable :offset-assert 12) - (curve curve :inline :offset-assert 16) - (num-cverts int32 :offset 20) - (cverts (inline-array vector) :offset 16) + "An abstraction around a [[curve]], providing tools such as: + - debug drawing + - conveniant vertex accessing + - vertex finding/searching algorithms" + ((flags path-control-flag :offset-assert 4) + (name symbol :offset-assert 8) + (process process-drawable :offset-assert 12) + (curve curve :inline :offset-assert 16) ) :method-count-assert 27 :size-assert #x24 @@ -16,23 +18,23 @@ (:methods (new (symbol type process symbol float entity symbol) _type_ 0) (debug-draw (_type_) none 9) - (path-control-method-10 () none 10) - (path-control-method-11 () none 11) - (path-control-method-12 () none 12) - (path-control-method-13 () none 13) - (path-control-method-14 () none 14) - (path-control-method-15 () none 15) - (path-control-method-16 () none 16) + (get-point-in-path! (_type_ vector float symbol) vector 10) + (get-random-point (_type_ vector) vector :behavior process 11) + (displacement-between-two-points-copy! (_type_ vector float float) vector 12) + (displacement-between-two-points-normalized! (_type_ vector float) vector 13) + (get-point-at-percent-along-path! (_type_ vector float symbol) vector 14) + (displacement-between-points-at-percent-scaled! (_type_ vector float float) vector 15) + (displacement-between-points-at-percent-normalized! (_type_ vector float) vector 16) (get-num-segments (_type_) float 17) - (path-control-method-18 () none 18) + (total-distance (_type_) float 18) (get-num-verts (_type_) int 19) (path-distance-equal-spacing (_type_ float) float 20) (average-segment-length (_type_ float) float 21) - (path-control-method-22 () none 22) - (path-control-method-23 () none 23) - (path-control-method-24 () none 24) + (get-furthest-point-on-path (_type_ vector) float 22) + (get-path-percentage-at-furthest-point (_type_ vector) float 23) + (path-control-method-24 (_type_ vector) vector 24) (should-display-marks? (_type_) symbol 25) - (path-control-method-26 () none 26) + (displacement-between-two-points! (_type_ vector float float) vector 26) ) ) @@ -58,6 +60,7 @@ ;; definition of type curve-control (deftype curve-control (path-control) + "Identical in terms of data to a [[path-control]] but has different implementation" () :method-count-assert 27 :size-assert #x24 @@ -176,9 +179,8 @@ ) ;; definition for method 19 of type path-control -;; WARN: Return type mismatch int32 vs int. (defmethod get-num-verts path-control ((obj path-control)) - (the-as int (-> obj curve num-cverts)) + (-> obj curve num-cverts) ) ;; definition for method 20 of type path-control @@ -218,7 +220,7 @@ ) (when (not (get-curve-data! s3-1 (-> gp-0 curve) arg1 s2-0 arg2)) (cond - ((> (the-as int (-> gp-0 curve num-cverts)) 0) + ((> (-> gp-0 curve num-cverts) 0) (set! (-> gp-0 type) path-control) ) (else diff --git a/test/decompiler/reference/jak2/engine/geometry/path_REF.gc b/test/decompiler/reference/jak2/engine/geometry/path_REF.gc new file mode 100644 index 000000000..fc221fd09 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/geometry/path_REF.gc @@ -0,0 +1,510 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for method 9 of type path-control +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw path-control ((obj path-control)) + (cond + ((logtest? (-> obj flags) (path-control-flag not-found)) + (when (and (type? (-> obj process) process-drawable) *display-entity-errors*) + (let ((s5-0 add-debug-text-3d) + (s4-0 #t) + (s3-0 318) + ) + (format (clear *temp-string*) "path data error in ~S" (-> obj process name)) + (s5-0 + s4-0 + (the-as bucket-id s3-0) + *temp-string* + (-> obj process root trans) + (font-color precursor-#ec3b00) + (the-as vector2h #f) + ) + ) + ) + ) + ((let ((a0-5 obj)) + (and *display-path-marks* (logtest? (-> a0-5 flags) (path-control-flag display))) + ) + (dotimes (s5-1 (-> obj curve num-cverts)) + (let ((s4-1 (-> obj curve cverts s5-1))) + (if (and (logtest? (-> obj flags) (path-control-flag draw-line)) (< s5-1 (+ (-> obj curve num-cverts) -1))) + (add-debug-line + #t + (bucket-id debug-no-zbuf1) + s4-1 + (-> obj curve cverts (+ s5-1 1)) + (new 'static 'rgba :r #xff :g #x80 :a #x80) + #f + (the-as rgba -1) + ) + ) + (if (logtest? (-> obj flags) (path-control-flag draw-point)) + (add-debug-x #t (bucket-id debug-no-zbuf1) s4-1 (new 'static 'rgba :r #xff :a #x80)) + ) + (when (logtest? (-> obj flags) (path-control-flag draw-text)) + (let ((s3-1 add-debug-text-3d) + (s2-1 #t) + (s1-0 318) + ) + (format (clear *temp-string*) "~D" s5-1) + (s3-1 s2-1 (the-as bucket-id s1-0) *temp-string* s4-1 (font-color gold-#ba9200) (the-as vector2h #f)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 18 of type path-control +(defmethod total-distance path-control ((obj path-control)) + "Calcuate the total path length by summing the distance between each adjacent [[curve]] vertex" + (let ((f30-0 0.0)) + (dotimes (s5-0 (+ (-> obj curve num-cverts) -1)) + (+! f30-0 (vector-vector-distance (-> obj curve cverts s5-0) (-> obj curve cverts (+ s5-0 1)))) + ) + f30-0 + ) + ) + +;; definition for method 18 of type curve-control +(defmethod total-distance curve-control ((obj curve-control)) + "Calcuate the total path length by summing the distance between each adjacent [[curve]] vertex" + (let ((f0-0 (-> obj curve length))) + (when (= f0-0 0.0) + (set! f0-0 (curve-length (-> obj curve))) + (set! (-> obj curve length) f0-0) + ) + f0-0 + ) + ) + +;; definition for method 10 of type path-control +;; INFO: Used lq/sq +(defmethod get-point-in-path! path-control ((obj path-control) (ret vector) (idx float) (search-type symbol)) + "Depending on the value of `idx`, the result can be quite different: + - if `idx` is less than `0.0` - return the first vertex in the path + - if `idx` is greater than the number of vertices in the path, return the last vertex + - if `search-type` is equal to `exact` OR `idx` is an integral number (ex 1.0), return that vertex + - otherwise, do a linear interpolation between the vertex at `idx` (truncated) and the next vertex + using the fractional component of `idx` as the interpolant, return this result + + @param! ret The [[vector]] that is used to hold the return value + @param idx Either the vertex index or also partially the interpolant in a LERP + @param search-type The only recognized value is `exact` + @returns Either a distinct vertex along the path, or some fractional point between two vertices" + (let ((num-vertices (-> obj curve num-cverts)) + (vert-idx (the float (the int idx))) + ) + (cond + ((< idx 0.0) + (set! (-> ret quad) (-> obj curve cverts 0 quad)) + ) + ((>= vert-idx (the float (+ num-vertices -1))) + (set! (-> ret quad) (-> obj curve cverts (+ num-vertices -1) quad)) + ) + ((or (= search-type 'exact) (= vert-idx idx)) + (set! (-> ret quad) (-> obj curve cverts (the int vert-idx) quad)) + ) + (else + (vector-lerp! + ret + (-> obj curve cverts (the int vert-idx)) + (-> obj curve cverts (the int (+ 1.0 vert-idx))) + (- idx vert-idx) + ) + ) + ) + ) + ret + ) + +;; definition for method 11 of type path-control +;; INFO: Used lq/sq +(defmethod get-random-point path-control ((obj path-control) (arg0 vector)) + "Attempts to retrieve a random point along the path, returns the [[*null-vector*]] if no vertices are defined" + (cond + ((> (-> obj curve num-cverts) 0) + (let ((a0-2 (rand-vu-int-count (-> obj curve num-cverts)))) + (set! (-> arg0 quad) (-> obj curve cverts a0-2 quad)) + ) + ) + (else + (format #t "WARNING: method get-random-point called on a path-control object with no vertices.~%") + (if self + (format #t "current process is ~A~%" (-> self name)) + ) + (set! (-> arg0 quad) (-> *null-vector* quad)) + ) + ) + arg0 + ) + +;; definition for method 14 of type path-control +(defmethod get-point-at-percent-along-path! path-control ((obj path-control) (ret vector) (percent float) (search-type symbol)) + "@param! ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path + @param search-type The only recognized value is `exact` + @returns the point closest to some arbitrary percentage along the path + @see [[path-control::10]]" + (get-point-in-path! obj ret (* percent (the float (+ (-> obj curve num-cverts) -1))) search-type) + ) + +;; definition for method 14 of type curve-control +(defmethod get-point-at-percent-along-path! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 symbol)) + "@param! ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path + @param search-type The only recognized value is `exact` + @returns the point closest to some arbitrary percentage along the path + @see [[path-control::10]]" + (if (zero? (logand (-> obj flags) (path-control-flag not-found))) + (curve-evaluate! + arg0 + arg1 + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + ) + arg0 + ) + +;; definition for method 10 of type curve-control +(defmethod get-point-in-path! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 symbol)) + "Depending on the value of `idx`, the result can be quite different: + - if `idx` is less than `0.0` - return the first vertex in the path + - if `idx` is greater than the number of vertices in the path, return the last vertex + - if `search-type` is equal to `exact` OR `idx` is an integral number (ex 1.0), return that vertex + - otherwise, do a linear interpolation between the vertex at `idx` (truncated) and the next vertex + using the fractional component of `idx` as the interpolant, return this result + + @param! ret The [[vector]] that is used to hold the return value + @param idx Either the vertex index or also partially the interpolant in a LERP + @param search-type The only recognized value is `exact` + @returns Either a distinct vertex along the path, or some fractional point between two vertices" + (if (zero? (logand (-> obj flags) (path-control-flag not-found))) + (curve-evaluate! + arg0 + (/ arg1 (the float (+ (-> obj curve num-cverts) -1))) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + ) + arg0 + ) + +;; definition for method 26 of type path-control +(defmethod displacement-between-two-points! path-control ((obj path-control) (ret vector) (idx float) (mag float)) + "Return value can differ quite a bit: + - If [[path-control-flag::4]] is set OR there are less than 2 vertices OR `idx` is less than `0.0` - return [[*null-vector*]] + - Otherwise, find the scaled (by `mag`) displacement vector between two points in the path: + - If `idx` is not beyond the second last vertex, the result is between vertex `idx` and `idx+1` + - else, the result is between the second last vertex and the last + + @param! ret The [[vector]] that is used to hold the return value + @param idx The vertex index + @param mag The magnitude to scale the resulting displacement vector by + @returns The displacement [[vector]] between two points in the path, the last 2, or the [[*null-vector*]]" + (let ((num-vertices (-> obj curve num-cverts)) + (vert-idx (the float (the int idx))) + ) + (cond + ((or (logtest? (-> obj flags) (path-control-flag not-found)) (< num-vertices 2) (< idx 0.0)) + (vector-reset! ret) + ) + (else + (let ((capped-idx (fmin vert-idx (the float (+ num-vertices -2))))) + (vector-! ret (-> obj curve cverts (the int (+ 1.0 capped-idx))) (-> obj curve cverts (the int capped-idx))) + ) + (vector-float*! ret ret mag) + ) + ) + ) + ret + ) + +;; definition for method 12 of type path-control +(defmethod displacement-between-two-points-copy! path-control ((obj path-control) (ret vector) (idx float) (mag float)) + "Calls [[path-control::26]] with the provided args + @see [[path-control::26]]" + (displacement-between-two-points! obj ret idx mag) + ) + +;; definition for method 15 of type path-control +(defmethod displacement-between-points-at-percent-scaled! path-control ((obj path-control) (ret vector) (percent float) (mag float)) + "Calls [[path-control::12], with the `idx` at a given percent along the path + @param ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path to find the first index + @param mag Multiplied by the number of points in the path and scales the resulting vector + @returns The displacement between the last two points of the path scaled to the magnitude equal to the number of points in the path" + (displacement-between-two-points-copy! + obj + ret + (* percent (the float (+ (-> obj curve num-cverts) -1))) + (* mag (the float (+ (-> obj curve num-cverts) -1))) + ) + ) + +;; definition for method 13 of type path-control +(defmethod displacement-between-two-points-normalized! path-control ((obj path-control) (ret vector) (idx float)) + "Calls [[path-control::26], with the provided `idx` + @param! ret The [[vector]] the result is stored within + @param idx The vertex index + @returns The resulting displacement vector, normalized + @see [[path-control::26]]" + (displacement-between-two-points! obj ret idx 1.0) + (vector-normalize! ret 1.0) + ) + +;; definition for method 16 of type path-control +(defmethod displacement-between-points-at-percent-normalized! path-control ((obj path-control) (ret vector) (percent float)) + "Calls [[path-control::13], with the `idx` at a given percent along the path + @param! ret The [[vector]] the result is stored within + @param percent The percentage along the path + @returns The resulting displacement vector, normalized + @see [[path-control::13]] + @see [[path-control::14]]" + (displacement-between-two-points-normalized! obj ret (* percent (the float (+ (-> obj curve num-cverts) -1)))) + ) + +;; definition for method 26 of type curve-control +(defmethod displacement-between-two-points! curve-control ((obj curve-control) (arg0 vector) (arg1 float) (arg2 float)) + "Return value can differ quite a bit: + - If [[path-control-flag::4]] is set OR there are less than 2 vertices OR `idx` is less than `0.0` - return [[*null-vector*]] + - Otherwise, find the scaled (by `mag`) displacement vector between two points in the path: + - If `idx` is not beyond the second last vertex, the result is between vertex `idx` and `idx+1` + - else, the result is between the second last vertex and the last + + @param! ret The [[vector]] that is used to hold the return value + @param idx The vertex index + @param mag The magnitude to scale the resulting displacement vector by + @returns The displacement [[vector]] between two points in the path, the last 2, or the [[*null-vector*]]" + (when (zero? (logand (-> obj flags) (path-control-flag not-found))) + (let ((s4-0 (new 'stack-no-clear 'vector))) + (curve-evaluate! + arg0 + arg1 + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (cond + ((< arg1 (- 1.0 arg2)) + (curve-evaluate! + s4-0 + (+ arg1 arg2) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (vector-! arg0 s4-0 arg0) + ) + (else + (curve-evaluate! + s4-0 + (- arg1 arg2) + (-> obj curve cverts) + (-> obj curve num-cverts) + (-> obj curve knots) + (-> obj curve num-knots) + ) + (vector-! arg0 arg0 s4-0) + ) + ) + ) + ) + ) + +;; definition for method 12 of type curve-control +(defmethod displacement-between-two-points-copy! curve-control ((obj curve-control) (ret vector) (percent float) (mag float)) + "Calls [[path-control::26]] with the provided args + @see [[path-control::26]]" + (displacement-between-two-points! obj ret (/ percent (the float (+ (-> obj curve num-cverts) -1))) mag) + ) + +;; definition for method 15 of type curve-control +(defmethod displacement-between-points-at-percent-scaled! curve-control ((obj curve-control) (ret vector) (idx float) (mag float)) + "Calls [[path-control::12], with the `idx` at a given percent along the path + @param ret The [[vector]] that is used to hold the return value + @param percent The percentage along the path to find the first index + @param mag Multiplied by the number of points in the path and scales the resulting vector + @returns The displacement between the last two points of the path scaled to the magnitude equal to the number of points in the path" + (displacement-between-two-points! obj ret idx mag) + ) + +;; definition for method 16 of type curve-control +(defmethod displacement-between-points-at-percent-normalized! curve-control ((obj curve-control) (ret vector) (percent float)) + "Calls [[path-control::13], with the `idx` at a given percent along the path + @param! ret The [[vector]] the result is stored within + @param percent The percentage along the path + @returns The resulting displacement vector, normalized + @see [[path-control::13]] + @see [[path-control::14]]" + (displacement-between-two-points! obj ret percent 0.01) + (vector-normalize! ret 1.0) + ) + +;; definition for method 13 of type curve-control +(defmethod displacement-between-two-points-normalized! curve-control ((obj curve-control) (ret vector) (idx float)) + "Calls [[path-control::26], with the provided `idx` + @param! ret The [[vector]] the result is stored within + @param idx The vertex index + @returns The resulting displacement vector, normalized + @see [[path-control::26]]" + (displacement-between-points-at-percent-normalized! + obj + ret + (/ idx (the float (+ (-> obj curve num-cverts) -1))) + ) + ) + +;; definition for method 22 of type path-control +;; INFO: Used lq/sq +(defmethod get-furthest-point-on-path path-control ((obj path-control) (point vector)) + "@param point The point to calculate distance from + @returns the `vertex-idx.interpolant` value to the point on the path furthest away from the `point` + @see [[path-control::10]]" + (let ((curr-point (new 'stack-no-clear 'vector)) + (next-point (new 'stack-no-clear 'vector)) + (given-point (new 'stack-no-clear 'vector)) + (furthest-dist 4096000000.0) + (vert-idx 0.0) + ) + (let ((closest-point (new 'stack-no-clear 'vector))) + (set! (-> given-point quad) (-> point quad)) + (set! (-> given-point y) 0.0) + (get-point-in-path! obj next-point 0.0 'interp) + (set! (-> next-point y) 0.0) + (dotimes (idx (+ (-> obj curve num-cverts) -1)) + (set! (-> curr-point quad) (-> next-point quad)) + (get-point-in-path! obj next-point (the float (+ idx 1)) 'interp) + (set! (-> next-point y) 0.0) + (let ((dist-to-point (vector-segment-distance-point! given-point curr-point next-point closest-point))) + (when (< dist-to-point furthest-dist) + (set! furthest-dist dist-to-point) + (set! vert-idx + (+ (/ (vector-vector-xz-distance closest-point curr-point) (vector-vector-xz-distance next-point curr-point)) + (the float idx) + ) + ) + ) + ) + ) + ) + vert-idx + ) + ) + +;; definition for method 23 of type path-control +(defmethod get-path-percentage-at-furthest-point path-control ((obj path-control) (point vector)) + "@param point The point to calculate distance from + @returns the percentage of path completion from the point on the path furthest away from the `point` + @see [[path-control::14]]" + (/ (get-furthest-point-on-path obj point) (the float (+ (-> obj curve num-cverts) -1))) + ) + +;; definition for method 9 of type curve-control +;; WARN: Return type mismatch int vs none. +(defmethod debug-draw curve-control ((obj curve-control)) + (cond + ((logtest? (-> obj flags) (path-control-flag not-found)) + (when (and (type? (-> obj process) process-drawable) *display-entity-errors*) + (let ((s5-0 add-debug-text-3d) + (s4-0 #t) + (s3-0 318) + ) + (format (clear *temp-string*) "curve data error in ~S" (-> obj process name)) + (s5-0 + s4-0 + (the-as bucket-id s3-0) + *temp-string* + (-> obj process root trans) + (font-color precursor-#ec3b00) + (the-as vector2h #f) + ) + ) + ) + ) + ((let ((a0-5 obj)) + (and *display-path-marks* (logtest? (-> a0-5 flags) (path-control-flag display))) + ) + (if (and (logtest? (-> obj flags) (path-control-flag draw-line)) (> (-> obj curve num-cverts) 0)) + (add-debug-curve2 #t (bucket-id debug-no-zbuf1) (-> obj curve) (new 'static 'rgba :r #xff :g #x80 :a #x80) #f) + ) + (dotimes (s5-1 (-> obj curve num-cverts)) + (let ((s4-1 (-> obj curve cverts s5-1))) + (if (logtest? (-> obj flags) (path-control-flag draw-point)) + (add-debug-x #t (bucket-id debug-no-zbuf1) s4-1 (new 'static 'rgba :r #xff :a #x80)) + ) + (when (logtest? (-> obj flags) (path-control-flag draw-text)) + (let ((s3-1 add-debug-text-3d) + (s2-1 #t) + (s1-0 318) + ) + (format (clear *temp-string*) "~D" s5-1) + (s3-1 s2-1 (the-as bucket-id s1-0) *temp-string* s4-1 (font-color gold-#ba9200) (the-as vector2h #f)) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 24 of type path-control +(defmethod path-control-method-24 path-control ((obj path-control) (arg0 vector)) + "TODO" + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (-> obj curve num-cverts))) + (let ((f30-0 (/ 1.0 (the float s4-0)))) + (set-vector! arg0 0.0 0.0 0.0 0.0) + (dotimes (s3-0 s4-0) + (let ((s2-0 arg0)) + (let ((s1-0 arg0) + (v1-4 (get-point-in-path! obj (new 'stack-no-clear 'vector) (the float s3-0) 'interp)) + (f0-7 f30-0) + ) + (.lvf vf2 (&-> v1-4 quad)) + (.lvf vf1 (&-> s1-0 quad)) + (let ((v1-5 f0-7)) + (.mov vf3 v1-5) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> s2-0 quad) vf4) + ) + ) + ) + (dotimes (s3-1 s4-0) + (let ((f0-10 + (vector-vector-distance arg0 (get-point-in-path! obj (new 'stack-no-clear 'vector) (the float s3-1) 'interp)) + ) + ) + (if (< (-> arg0 w) f0-10) + (set! (-> arg0 w) (+ 4096.0 f0-10)) + ) + ) + ) + ) + arg0 + ) + ) diff --git a/test/decompiler/reference/jak2/engine/level/bsp_REF.gc b/test/decompiler/reference/jak2/engine/level/bsp_REF.gc index 5b9386e45..9e9ce29a9 100644 --- a/test/decompiler/reference/jak2/engine/level/bsp_REF.gc +++ b/test/decompiler/reference/jak2/engine/level/bsp_REF.gc @@ -505,7 +505,7 @@ ;; definition for function print-collide-stats ;; WARN: Return type mismatch int vs none. -;; WARN: Function may read a register that is not set: t0 +;; ERROR: Function may read a register that is not set: t0 (defun print-collide-stats () (local-vars (t0-0 none)) (format *stdcon* "~0k~%count cycles instr icache dcache vu0/to/from~%") diff --git a/test/decompiler/reference/jak2/engine/target/surface-h_REF.gc b/test/decompiler/reference/jak2/engine/target/surface-h_REF.gc index faa946ee8..0891cbb41 100644 --- a/test/decompiler/reference/jak2/engine/target/surface-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/target/surface-h_REF.gc @@ -208,7 +208,7 @@ ) ;; definition for method 2 of type surface -;; WARN: Function may read a register that is not set: t3 +;; ERROR: Function may read a register that is not set: t3 (defmethod print surface ((obj surface)) (local-vars (t3-0 none)) (format