Skip to content

Commit

Permalink
d/j3: do a few mood related files and fix some issues along the way (
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser authored Feb 4, 2024
1 parent 2213602 commit 314f488
Show file tree
Hide file tree
Showing 44 changed files with 7,961 additions and 3,467 deletions.
2 changes: 1 addition & 1 deletion .vs/launch.vs.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@
"project" : "CMakeLists.txt",
"projectTarget" : "formatter.exe (bin\\formatter.exe)",
"name" : "Tools - Formatter - Inplace",
"args" : ["--write", "--file", "C:\\Users\\xtvas\\Repos\\opengoal\\jak-project\\goal_src\\jak2\\pc\\util\\popup-menu-h.gc"]
"args" : ["--write", "--file", "C:\\Users\\xtvas\\Repos\\opengoal\\jak-project\\decompiler_out\\jak3\\mood-h_disasm.gc"]
},
{
"type": "default",
Expand Down
6 changes: 5 additions & 1 deletion common/formatter/formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ std::optional<std::string> formatter::format_code(const std::string& source) {

// Get the root node of the syntax tree.
TSNode root_node = ts_tree_root_node(tree.get());
if (ts_node_is_null(root_node) || ts_node_has_error(root_node)) {
if (ts_node_is_null(root_node)) {
lg::error("null root node");
return std::nullopt;
} else if (ts_node_has_error(root_node)) {
lg::error("grammar parsing error, go figure it out!");
return std::nullopt;
}

Expand Down
11 changes: 7 additions & 4 deletions common/formatter/rules/rule_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ FormFormattingConfig new_flow_rule_prevent_inlining_indexes(
return cfg;
}

FormFormattingConfig new_binding_rule() {
FormFormattingConfig new_binding_rule(int form_head_width) {
FormFormattingConfig cfg;
cfg.hang_forms = false;
cfg.combine_first_two_lines = true;
auto binding_list_config = std::make_shared<FormFormattingConfig>();
binding_list_config->hang_forms = false;
binding_list_config->indentation_width = 1;
binding_list_config->indentation_width_for_index = [](FormFormattingConfig /*cfg*/, int index) {
binding_list_config->indentation_width_for_index = [form_head_width](FormFormattingConfig /*cfg*/,
int index) {
if (index == 0) {
return 0;
}
return 4;
return form_head_width;
};
binding_list_config->should_prevent_inlining = [](FormFormattingConfig /*config*/, int num_refs) {
// Only prevent inlining a binding list, if there are more than 1 bindings
Expand Down Expand Up @@ -87,13 +88,15 @@ const std::unordered_map<std::string, FormFormattingConfig> opengoal_form_config
{"defmethod", new_flow_rule(3)},
{"deftype", new_flow_rule_prevent_inlining_indexes(3, {3, 4, 5})},
{"defun", new_flow_rule(3)},
{"defun-debug", new_flow_rule(3)},
{"defbehavior", new_flow_rule(4)},
{"if", new_permissive_flow_rule()},
{"define", new_permissive_flow_rule()},
{"define-extern", new_permissive_flow_rule()},
{"defmacro", new_flow_rule(3)},
{"dotimes", new_flow_rule(2)},
{"let", new_binding_rule()},
{"let", new_binding_rule(4)},
{"rlet", new_binding_rule(5)},
{"when", new_flow_rule(2)},
{"with-dma-buffer-add-bucket", new_flow_rule(2)}};
} // namespace config
Expand Down
71 changes: 59 additions & 12 deletions decompiler/config/jak2/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -4638,7 +4638,7 @@
(define-extern vector-rotate-around-y! (function vector vector float vector))
(define-extern vector-rotate90-around-y! (function vector vector vector))
(define-extern vector-rotate-around-z! (function vector vector float vector))
(define-extern rotate-y<-vector+vector (function vector vector float))
(define-extern rotate-y<-vector+vector "Get the y rotation between vectors. These should have the same length." (function vector vector float))
(define-extern rotate-x<-vector+vector (function vector vector float))
(define-extern rotate-z<-vector+vector (function vector vector float))
(define-extern vector-cvt.w.s! (function vector vector vector))
Expand Down Expand Up @@ -14869,17 +14869,56 @@
;; some asm stuff, maybe needs mips2c.

(define-extern *light-hash-work* light-hash-work)
(define-extern light-slerp (function light light light float light))
(define-extern light-group-slerp (function light-group light-group light-group float light-group))
(define-extern light-group-process! (function vu-lights light-group vector vector none))
(define-extern light-slerp
"Linearly interpolate between two [[light]]s
@param! light-out The resultant
@param light-a One of the two lights
@param light-b One of the two lights
@param alpha Clamped to between `0.0` and `1.0`
@returns The interpolated [[light]]"
(function light light light float light))
(define-extern light-group-slerp
"Linearly interpolate between two [[light-groups]]s by calling [[light-slerp]] on each respective collection of lights
@param light-group-out The resultant
@param light-group-a One of the two [[light-group]]s
@param light-group-b One of the two [[light-group]]s
@param alpha
@returns The linearly interpolated [[light-group]]"
(function light-group light-group light-group float light-group))
(define-extern light-group-process!
"Unused, needlessly calls [[rotate-y<-vector+vector]] on the two [[vector]]s and calls [[vu-lights<-light-group!]]
@param vu-lights
@param light-group
@param vec1
@param vec2
@returns [[none]]"
(function vu-lights light-group vector vector none))
(define-extern *default-lights* vu-lights)
(define-extern vu-lights-default! (function vu-lights vu-lights))
(define-extern init-light-hash (function none))
(define-extern vu-lights-default!
"Setups up a default [[vu-lights]] instance
@param! lights
@returns [[vu-lights]]"
(function vu-lights vu-lights))
(define-extern init-light-hash
"Initializes the global [[*light-hash*]].
- Bucket array allocates `4096` bytes. (enough for 16,384 entries)
- Index array allocates `65536` bytes.
- Light sphere array allocates `16384` bytes. (enough for 256 light spheres)
@returns [[light-hash]]"
(function none))
(define-extern light-hash-count-items (function light-hash light-sphere none))
(define-extern light-hash-add-items (function light-hash light-sphere integer object))
(define-extern reset-light-hash (function light-hash none))
(define-extern reset-light-hash
"Resets the global [[*light-hash*]] back to having `0` lights, indicies, and buckets.
@returns [[none]]"
(function light-hash none))
(define-extern update-light-hash (function light-hash none))
(define-extern lookup-light-sphere-by-name (function string light-hash light-sphere))
(define-extern lookup-light-sphere-by-name
"Search through a given [[light-hash]]'s lights to find the one that matches the given name
@param name The name to look for
@param hash The hash to search through
@returns Either the [[light]] or [[#f]]"
(function string light-hash light-sphere))
(define-extern light-hash-get-bucket-index (function light-hash vector int))
(define-extern add-light-sphere-to-light-group (function object object object object object))

Expand Down Expand Up @@ -25971,19 +26010,27 @@
(define-extern *mood-direction-table* mood-direction-table)
(define-extern *mood-sky-table* mood-sky-table)
(define-extern *mood-interp-table* sky-color-day)
(define-extern init-mood-control (function mood-control none))
(define-extern *mood-control* mood-control)
(define-extern init-mood-control
"Given a [[mood-control]] initialize and set it up with default settings
@param! ctrl The [[mood-control]]
@returns [[none]]"
(function mood-control none))
(define-extern *mood-control* "The global [[mood-control]] which governs things like clouds, fog and weather (to some degree)" mood-control)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; mood-tables2 ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define-extern *overide-mood-color-table* mood-color-table)
(define-extern *overide-mood-fog-table* mood-fog-table)
(define-extern init-overide-table (function mood-table none))
(define-extern init-overide-table
"Similar to [[init-mood-table]], does the bare minimum to setup the given [[mood-table]]
@param! table The table to initialize
@returns [[none]]"
(function mood-table none))
(define-extern *overide-table* mood-table)
(define-extern print-mood-tables
"Print out the contents of the [[*overide-table*]]"
"Generates the GOAL code for defining the current state of [[*overide-table*]]"
(function none))
(define-extern desaturate-mood-colors
"Unused - Generate GOAL code for a new [[*overide-mood-color-table*]] definition that desaturates the color
Expand Down
72 changes: 71 additions & 1 deletion decompiler/config/jak2/ntsc_v1/var_names.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@
},
"desaturate-mood-colors": {
"vars": {
"a0-8": ["mood-colors", "(inline-array mood-color)"]
"a0-8": ["mood-colors", "(inline-array mood-color)"],
"v1-1": "data-idx",
"a1-3": "color-data",
"f1-2": "max-light-color",
"f0-4": "max-0th-light-color",
"gp-1": "_color-idx",
"v1-4": "color-idx"
}
},
"(method 12 fact-info-target)": {
Expand Down Expand Up @@ -4661,5 +4667,69 @@
"vars": {
"s4-0": ["exploder", "joint-exploder"]
}
},
"clear-mood-times": {
"args": ["mood-ctx"],
"vars": {
"v1-0": "idx"
}
},
"light-slerp": {
"args": ["light-out", "light-a", "light-b", "alpha"],
"vars": {
"s3-0": "clamped-alpha",
"f0-2": "extra-x-a",
"f1-2": "extra-x-b"
}
},
"light-group-slerp": {
"args": ["light-group-out", "light-group-a", "light-group-b", "alpha"],
"vars": {
"s2-0": "group-idx"
}
},
"light-group-process!": {
"args": ["vu-lights", "light-group", "vec1", "vec2"]
},
"vu-lights-default!": {
"args": ["lights"]
},
"lookup-light-sphere-by-name": {
"args": ["name", "hash"],
"vars": {
"s4-0": "num-lights",
"s3-0": "light"
}
},
"update-light-hash": {
"args": ["hash"],
"vars": {
"v1-0": "boundary"
}
},
"init-mood-control": {
"args": ["ctrl"]
},
"init-overide-table": {
"args": ["table"]
},
"print-mood-tables": {
"vars": {
"v1-2": "data-idx",
"gp-0": "_color-idx",
"v1-5": "color-idx",
"gp-1": "_fog-idx",
"v1-33": "fog-idx"
}
},
"desaturate-mood-fog": {
"vars": {
"arg0": "table-ptr",
"v1-2": "data-idx",
"a0-5": "fog-data",
"f0-2": "max-fog-val",
"gp-1": "_fog-idx",
"v1-5": "fog-idx"
}
}
}
Loading

0 comments on commit 314f488

Please sign in to comment.