[decomp] math-camera (#491)

* decompile math camera

* missing line
This commit is contained in:
water111
2021-05-15 20:08:08 -04:00
committed by GitHub
parent af2836c452
commit 79d10979da
22 changed files with 1605 additions and 521 deletions
+1 -1
View File
@@ -777,7 +777,7 @@ void TypeSystem::add_builtin_types() {
// STRUCTURE
// structure new doesn't support dynamic sizing, which is kinda weird - it grabs the size from
// the type. Dynamic structures use new-dynamic-structure, which is used exactly once ever.
add_method(structure_type, "new", make_function_typespec({"symbol", "type"}, "structure"));
add_method(structure_type, "new", make_function_typespec({"symbol", "type"}, "_type_"));
// structure_type is a field-less StructureType, so we have to do this to match the runtime.
// structure_type->override_size_in_memory(4);
+11 -5
View File
@@ -53,10 +53,6 @@
namespace decompiler {
namespace {
bool debug_method_calls = false;
}
bool Form::has_side_effects() {
bool has_side_effect = false;
apply([&](FormElement* elt) {
@@ -3159,8 +3155,18 @@ void StackSpillStoreElement::push_to_stack(const Env& env, FormPool& pool, FormS
stack.push_form_element(pool.alloc_element<SetFormFormElement>(dst, src), true);
}
void VectorFloatLoadStoreElement::push_to_stack(const Env&, FormPool&, FormStack& stack) {
void VectorFloatLoadStoreElement::push_to_stack(const Env& env, FormPool& pool, FormStack& stack) {
mark_popped();
auto loc_as_deref = m_location->try_as_element<DerefElement>();
if (loc_as_deref) {
auto root = loc_as_deref->base();
auto atom = form_as_atom(root);
if (atom && atom->get_kind() == SimpleAtom::Kind::VARIABLE) {
loc_as_deref->set_base(pop_to_forms({atom->var()}, env, pool, stack, true).at(0));
}
}
stack.push_form_element(this, true);
}
+9 -5
View File
@@ -4468,14 +4468,18 @@
(define-extern *math-camera* math-camera) ;; unknown type
(define-extern *math-camera-fog-correction* fog-corrector) ;; unknown type
(define-extern init-for-transform function)
(define-extern move-target-from-pad (function transform int none))
(define-extern transform-point-vector! function)
(define-extern move-target-from-pad (function transform int transform))
(define-extern transform-point-vector! (function vector vector symbol))
(define-extern transform-point-qword! (function vector vector symbol))
(define-extern transform-point-vector-scale! (function vector vector float))
(define-extern init-for-transform (function matrix none))
(define-extern fog-corrector-setup (function fog-corrector math-camera none))
(define-extern math-cam-start-smoothing (function float float quaternion))
(define-extern update-math-camera (function math-camera symbol symbol math-camera))
(define-extern transform-point-qword! function)
(define-extern transform-point-vector-scale! function)
(define-extern sprite-distorter-generate-tables (function none))
;;(define-extern ntsc object) ;; unknown type
@@ -1,7 +1,5 @@
{
"gcommon": [
["L346", "uint64", true]
],
"gcommon": [["L346", "uint64", true]],
"gkernel": [
["L345", "_auto_", true],
@@ -18,11 +16,38 @@
"gstring": [["L170", "float", true]],
"math": [
["L41", "float", true]
"math": [["L41", "float", true]],
"vector-h": [
["L32", "vector", true],
["L31", "vector", true],
["L30", "vector", true],
["L29", "vector", true],
["L28", "vector", true],
["L27", "vector", true],
["L26", "vector", true]
],
"trigonometry" : [
"quaternion-h": [["L1", "quaternion", true]],
"euler-h": [
["L3", "_auto_", true],
["L2", "_auto_", true]
],
"transform": [["L11", "float", true]],
"quaternion": [
["L67", "vector", true],
["L68", "vector", true],
["L69", "vector", true],
["L70", "vector", true],
["L71", "vector", true],
["L72", "vector", true],
["L81", "float", true]
],
"trigonometry": [
["L98", "(pointer float)", true, 32],
["L99", "(pointer float)", true, 32],
["L104", "_auto_", true],
@@ -35,44 +60,16 @@
["L137", "float", true]
],
"vector-h": [
["L32", "vector", true],
["L31", "vector", true],
["L30", "vector", true],
["L29", "vector", true],
["L28", "vector", true],
["L27", "vector", true],
["L26", "vector", true]
],
"euler-h": [
["L3", "_auto_", true],
["L2", "_auto_", true]
],
"transform": [["L11", "float", true]],
"quaternion-h": [["L1", "quaternion", true]],
"quaternion": [
["L67", "vector", true],
["L68", "vector", true],
["L69", "vector", true],
["L70", "vector", true],
["L71", "vector", true],
["L72", "vector", true],
["L81", "float", true]
],
"video-h": [["L1", "video-parms", true]],
"dma": [["L56", "uint64", true]],
"dma-bucket": [["L10", "uint64", true]],
"video-h": [["L1", "video-parms", true]],
"pad": [
["L44", "float", true]
],
"dma-disasm": [["L148", "(array vif-disasm-element)", true]],
"pad": [["L44", "float", true]],
"gs": [
["L53", "gif-tag64", true],
["L51", "gif-tag-regs", true],
@@ -83,41 +80,17 @@
"level-h": [["L3", "level-group", true]],
"level-info": [
["L964", "level-load-info", true],
["L867", "level-load-info", true],
["L851", "level-load-info", true],
["L822", "level-load-info", true],
["L812", "level-load-info", true],
["L531", "level-load-info", true],
["L512", "level-load-info", true],
["L495", "level-load-info", true],
["L479", "level-load-info", true],
["L271", "level-load-info", true],
["L255", "level-load-info", true],
["L237", "level-load-info", true],
["L215", "level-load-info", true],
["L175", "level-load-info", true],
["L153", "level-load-info", true],
["L143", "level-load-info", true],
["L131", "level-load-info", true],
["L112", "level-load-info", true],
["L72", "level-load-info", true],
["L52", "level-load-info", true],
["L48", "level-load-info", true],
["L41", "level-load-info", true],
["L35", "level-load-info", true],
["L30", "level-load-info", true],
["L28", "level-load-info", true],
["L544", "level-load-info", true],
["L2", "pair", true]
],
"level-h": [
["L3", "level-group", true],
["L3", "_auto_", true]
],
"math-camera": [
["L39", "float", true],
["L41", "float", true],
["L59", "float", true]
],
"font-h": [
["L18", "matrix", true],
["L17", "font-work", true]
@@ -195,7 +168,7 @@
],
"ocean-frames": [["L1", "(pointer uint32)", true, 16384]],
"time-of-day-h": [["L2", "time-of-day-context", true]],
"game-info-h": [
@@ -205,9 +178,7 @@
"wind-h": [["L3", "_auto_", true]],
"dynamics-h": [
["L6", "_auto_", true]
],
"dynamics-h": [["L6", "_auto_", true]],
"surface-h": [
["L68", "_auto_", true],
@@ -251,9 +222,7 @@
"pat-h": [["L1", "(inline-array pat-mode-info)", true, 4]],
"fact-h": [
["L35", "_auto_", true]
],
"fact-h": [["L35", "_auto_", true]],
"sync-info": [
["L78", "float", true],
@@ -427,5 +396,35 @@
["L122", "float", true],
["L123", "float", true],
["L124", "float", true]
],
"level-info": [
["L964", "level-load-info", true],
["L867", "level-load-info", true],
["L851", "level-load-info", true],
["L822", "level-load-info", true],
["L812", "level-load-info", true],
["L531", "level-load-info", true],
["L512", "level-load-info", true],
["L495", "level-load-info", true],
["L479", "level-load-info", true],
["L271", "level-load-info", true],
["L255", "level-load-info", true],
["L237", "level-load-info", true],
["L215", "level-load-info", true],
["L175", "level-load-info", true],
["L153", "level-load-info", true],
["L143", "level-load-info", true],
["L131", "level-load-info", true],
["L112", "level-load-info", true],
["L72", "level-load-info", true],
["L52", "level-load-info", true],
["L48", "level-load-info", true],
["L41", "level-load-info", true],
["L35", "level-load-info", true],
["L30", "level-load-info", true],
["L28", "level-load-info", true],
["L544", "level-load-info", true],
["L2", "pair", true]
]
}
@@ -114,7 +114,10 @@
"forward-up-nopitch->quaternion": [[16, "matrix"]],
"forward-up->quaternion": [[16, "matrix"], [80, "vector"]],
"forward-up->quaternion": [
[16, "matrix"],
[80, "vector"]
],
"quaternion-from-two-vectors!": [[16, "vector"]],
@@ -124,24 +127,48 @@
"matrix-from-two-vectors-max-angle!": [[16, "vector"]],
"matrix-from-two-vectors-max-angle-partial!": [[16, "vector"]],
"matrix-from-two-vectors-partial-linear!": [[16, "vector"]],
"matrix-remove-z-rot": [[16, "vector"], [32, "matrix"]],
"matrix-remove-z-rot": [
[16, "vector"],
[32, "matrix"]
],
"matrix-rot-diff!": [[16, "quaternion"], [32, "quaternion"], [48, "quaternion"]],
"matrix-rot-diff!": [
[16, "quaternion"],
[32, "quaternion"],
[48, "quaternion"]
],
"quaternion-seek": [[16, "matrix"], [80, "matrix"], [144, "quaternion"]],
"quaternion-seek": [
[16, "matrix"],
[80, "matrix"],
[144, "quaternion"]
],
"vector-deg-seek": [[16, "matrix"]],
"vector-deg-slerp": [[16, "matrix"], [80, "vector"], [96, "vector"]],
"vector-deg-slerp": [
[16, "matrix"],
[80, "vector"],
[96, "vector"]
],
"circle-test": [[16, "sphere"], [32, "sphere"], [48, "vector"], [64, "vector"]],
"circle-test": [
[16, "sphere"],
[32, "sphere"],
[48, "vector"],
[64, "vector"]
],
"move-target-from-pad": [[16, "vector"], [32, "vector"], [48, "matrix"]],
"move-target-from-pad": [
[16, "vector"],
[32, "vector"],
[48, "matrix"]
],
"draw-sprite2d-xy": [[16, "draw-context"]],
"screen-gradient": [[16, "draw-context"]],
//"(method 0 fact-info)": [[16, "res-tag"]],
"(method 10 oscillating-vector)":[[16, "vector"]],
"(method 10 oscillating-vector)": [[16, "vector"]],
"show-mc-info": [[16, "mc-slot-info"]],
@@ -152,5 +179,13 @@
"(method 23 trsqv)": [[16, "vector"]],
"(method 24 trsqv)": [[16, "vector"]],
"vector-sincos!": [[16, "vector"]]
"vector-sincos!": [[16, "vector"]],
"init-for-transform": [
[16, "matrix"],
[80, "matrix"],
[144, "vector4s-3"],
[192, "vector"],
[208, "vector4s-3"]
]
}
@@ -1309,7 +1309,7 @@
},
"update-math-camera": {
"args": ["math-cam", "ignored", "aspect"],
"args": ["math-cam", "video-mode", "aspect"],
"vars": {
"f0-4": "temp1",
"v1-1": "elim1",
@@ -1324,11 +1324,11 @@
"f3-14": "one-plus-2y-squared",
"f2-9": "temp3",
"a0-2": "elim3",
"f2-11": "dx-rat",
"f1-5": "dy-rat",
"f0-10": "drat-sqr-len",
"f2-11": "near-x",
"f1-5": "near-y",
"f0-10": "near-corner-dist-sqr",
"f2-8": "unused-thing-2",
"f1-8": "d-temp",
"f1-8": "near-z",
"f0-12": "temp4",
"a0-6": "elim4",
"f1-12": "dx-rat-2",
@@ -1351,7 +1351,7 @@
"f2-16": "fog-constant-1",
"f3-23": "fog-constant-2",
"f0-12": "fog-contsant-3",
"f0-24": "fog-factor-1",
"f0-24": "fog-at-near-plane",
"f1-22": "fog-factor-2",
"f4-35": "cam-fov-mult",
"f5-19": "corrected-fog",
@@ -1376,6 +1376,15 @@
}
},
"move-target-from-pad": {
"args":["trans", "pad-idx"],
"vars": {
"s4-0":"local-trans",
"a0-5":"inv-cam-rot",
"s3-0":"cam-rot-mat"
}
},
"(method 13 profile-bar)": {
"args": ["obj", "buf", "bar-pos"],
"vars": {
@@ -148,3 +148,4 @@
- Invalid static pairs now have nice errors instead of exiting the compiler
- Added unsigned division (previously signed division was used for unsigned numbers)
- Use shifts (64-bit) for positive power of two multiply and divide. Otherwise use 32-bit. This matches GOAL.
- Allow setting a 64-bit or less memory location from a 128-bit variable (upper bits are discarded).
+574 -353
View File
@@ -5,6 +5,8 @@
;; name in dgo: math-camera
;; dgos: GAME, ENGINE
;; The fog-corrector stores a fog-end fog-start value that is somehow
;; corrected for the field of view.
(deftype fog-corrector (structure)
((fog-end float :offset-assert 0)
(fog-start float :offset-assert 4)
@@ -15,395 +17,614 @@
)
(defun fog-corrector-setup ((corrector fog-corrector) (math-cam math-camera))
"Set the fog-corrector from the math camera"
;; just apply the correction factor to the value is math cam.
(set! (-> corrector fog-end)
(* (-> math-cam fog-end) (-> math-cam fov-correction-factor))
)
(set! (-> corrector fog-start)
(* (-> math-cam fog-start) (-> math-cam fov-correction-factor))
)
"Set the fog corrector based on the supplied math-camera"
(set! (-> corrector fog-end) (* (-> math-cam fog-end) (-> math-cam fov-correction-factor)))
(set! (-> corrector fog-start) (* (-> math-cam fog-start) (-> math-cam fov-correction-factor)))
(none)
)
;; create the single global fog corrector
;; it appears to be unused.
(define *math-camera-fog-correction* (new 'global 'fog-corrector))
(define-extern sprite-distorter-generate-tables (function none))
(defun update-math-camera ((math-cam math-camera) (video-mode symbol) (aspect symbol))
(local-vars
(cam-mat matrix)
(cull-info cull-info)
(sprite-row-0 matrix)
(sprite-row-1 (pointer float))
(sprite-row-2 (pointer float))
(sprite-row-3 (pointer float))
(v1-15 vector)
(v1-17 int)
(v1-19 int)
(v1-20 int)
(v1-22 int)
(v1-23 int)
(pfog float)
(a0-10 vector)
(a0-11 int)
(vis-gif-0 vis-gif-tag)
(vis-gif-1 vis-gif-tag)
(vis-gif-1-again vis-gif-tag)
(vis-gif-1-again-again vis-gif-tag)
(a1-5 int)
(a1-6 int)
(y-rat float)
(drat-sqr-len float)
(fog-contsant-3 float)
(d-temp-2 float)
(d-temp-4 float)
(fog-constant-3 float)
(fog-at-d float)
(x-rat float)
(dy-rat float)
(d-temp float)
(dx-rat-2 float)
;;(dy-rat float)
(mid-range float)
(persp-x float)
(temp7 float)
(unused-x-thing float)
(y-thing float)
(dx-rat float)
(dx-rat-times-4 float)
(dy-rat-times-4 float)
(very-near float)
(hvdf-z float)
(persp-xx float)
(d-temp-3 float)
(d-temp-5 float)
(very-far float)
(persp-yy float)
(inverse-x-len float)
(inverse-y-len float)
(cam-fov-mult float)
(hvdf-w float)
(inverse-x-len-2 float)
(inverse-y-len-2 float)
(range-factor float)
(hvdf-x float)
(hvdf-y float)
)
"Compute some one-time camera constants. These should only change when changing aspect ratio."
;; Camera Math:
;; The camera transformation projects a point in space to the camera's projection plane.
;; The usual camera frustum is shown below:
;;
;; * <- the camera origin.
;; --- <- project the point onto this plane, the screen.
;; / | \
;; / | \
;; / | * \ <- some point in the world
;; The "x ratio" is the slope of frustum:
;; for a point on the frustum (px,pz), it satisfies x_ratio * pz = px.
;; Compute the x-ratio using half of the fov angle (the triangle is the midplane, frustum wall, and offset in x)
(set! (-> math-cam x-ratio) (tan (* 0.500000 (-> math-cam fov))))
;; The plane has the same aspect ratio as the screen, so we can derive the y-ratio
;; based on the game's aspect ratio setting.
;; the x/y ratio are frustum slopes
(set! (-> math-cam x-ratio) (tan (* 0.5 (-> math-cam fov))))
(if (= aspect 'aspect4x3)
(set! (-> math-cam y-ratio) (* 0.75 (-> math-cam x-ratio)))
(set! (-> math-cam y-ratio) (* 0.5625 (-> math-cam x-ratio)))
)
;; Eventually, we will want to cull things that are oustide of the view frustum.
;; To do this, we need to compute the equation of the planes for the sides of the frustum.
;; I'm not yet sure what these "x-fact" things are, but likely related to their culling strategy.
(set! x-rat (-> math-cam x-ratio))
(set! y-rat (-> math-cam y-ratio))
(set! cull-info (-> math-cam cull-info))
(set! unused-x-thing
(/ (+ 1.000000 (* (* 4.000000 x-rat) x-rat)) (+ 1.000000 (* x-rat x-rat)))
;; compute some culling constants. Not sure what these mean yet
(let ((x-rat (-> math-cam x-ratio))
(y-rat (-> math-cam y-ratio))
(cull-info (-> math-cam cull-info))
)
(set! y-thing
(/ (+ 1.000000 (* (* 4.000000 y-rat) y-rat)) (+ 1.000000 (* y-rat y-rat)))
)
(set!
(-> cull-info x-fact)
(/ (+ 1.000000 (* (* 4.000000 x-rat) x-rat))
(* x-rat (sqrtf (+ 1.000000 (* (* 16.000000 x-rat) x-rat))))
(let ((unused-x-thing (/ (+ 1.0 (* (* 4.0 x-rat) x-rat)) (+ 1.0 (* x-rat x-rat))))))
(let ((y-thing (/ (+ 1.0 (* (* 4.0 y-rat) y-rat)) (+ 1.0 (* y-rat y-rat)))))
(set! (-> cull-info x-fact)
(/ (+ 1.0 (* (* 4.0 x-rat) x-rat))
(* x-rat (sqrtf (+ 1.0 (* (* 16.0 x-rat) x-rat))))
)
)
(set! (-> cull-info y-fact)
(/ (+ 1.0 (* (* 4.0 y-rat) y-rat))
(* y-rat (sqrtf (+ 1.0 (* (* 16.0 y-rat) y-rat))))
)
)
(set! (-> cull-info z-fact)
(sqrtf (+ (* (* (* (+ -4.0 y-thing) (+ -4.0 y-thing)) y-rat) y-rat)
(* (+ -1.0 y-thing) (+ -1.0 y-thing))
)
)
)
)
)
(set!
(-> cull-info y-fact)
(/ (+ 1.000000 (* (* 4.000000 y-rat) y-rat))
(* y-rat (sqrtf (+ 1.000000 (* (* 16.000000 y-rat) y-rat))))
;; radius of sphere containing camera origin and intersection of near plane and frustum
(let* ((near-x (* x-rat (-> math-cam d)))
(near-y (* y-rat (-> math-cam d)))
(near-corner-dist-sqr (+ (* near-x near-x) (* near-y near-y)))
(near-z (-> math-cam d))
)
(set! (-> cull-info cam-radius) (sqrtf (+ near-corner-dist-sqr (* near-z near-z))))
)
)
(set! (-> cull-info z-fact)
(sqrtf (+ (* (* (* (+ -4.000000 y-thing) (+ -4.000000 y-thing)) y-rat) y-rat)
(* (+ -1.000000 y-thing) (+ -1.000000 y-thing))
)
)
;; frustum plane equations coefficients?
(let* ((dx-rat-2 (* (-> math-cam d) (-> math-cam x-ratio)))
(d-temp-2 (-> math-cam d))
(dx-rat-times-4 (* 4.0 dx-rat-2))
(d-temp-3 (-> math-cam d))
)
(let ((inverse-x-len (/ 1.0 (sqrtf (+ (* dx-rat-2 dx-rat-2) (* d-temp-2 d-temp-2)))))
(inverse-x-len-2 (/ 1.0 (sqrtf (+ (* dx-rat-times-4 dx-rat-times-4) (* d-temp-3 d-temp-3)))))
)
(set! (-> cull-info xz-dir-ax) (* dx-rat-2 inverse-x-len))
(set! (-> cull-info xz-dir-az) (* d-temp-2 inverse-x-len))
(set! (-> cull-info xz-dir-bx) (* dx-rat-times-4 inverse-x-len-2))
(set! (-> cull-info xz-dir-bz) (* d-temp-3 inverse-x-len-2))
)
(set!
(-> cull-info xz-cross-ab)
(- (* dx-rat-2 d-temp-3) (* d-temp-2 dx-rat-times-4))
)
)
;; this is the distance from the origin of the projection plane to the frustum, in x
(set! dx-rat (* x-rat (-> math-cam d)))
;; this is the distance from the origin of the projection plane to the frustum, in y
(set! dy-rat (* y-rat (-> math-cam d)))
;; this is the distance from the origin of the projection plane to the corner of the frustum
(set! drat-sqr-len (+ (* dx-rat dx-rat) (* dy-rat dy-rat)))
;; this is the distance from the origin (behind the projection plane)
;; to the farthest point of the intersection of the view frustum and the projection plane
(set! d-temp (-> math-cam d))
(set! (-> cull-info cam-radius) (sqrtf (+ drat-sqr-len (* d-temp d-temp))))
;; origin of projection plane to frustum, x
(set! dx-rat-2 (* (-> math-cam d) (-> math-cam x-ratio)))
(set! d-temp-2 (-> math-cam d))
;; ?? not sure what this is used for
(set! dx-rat-times-4 (* 4.000000 dx-rat-2))
(set! d-temp-3 (-> math-cam d))
;; 1/length(cam origin to frust x on projection plane)
(set! inverse-x-len
(/ 1.000000 (sqrtf (+ (* dx-rat-2 dx-rat-2) (* d-temp-2 d-temp-2))))
)
(set! inverse-x-len-2
(/ 1.000000
(sqrtf (+ (* dx-rat-times-4 dx-rat-times-4) (* d-temp-3 d-temp-3)))
(let* ((dy-rat (* (-> math-cam d) (-> math-cam y-ratio)))
(d-temp-4 (-> math-cam d))
(dy-rat-times-4 (* 4.0 dy-rat))
(d-temp-5 (-> math-cam d))
)
(let ((inverse-y-len (/ 1.0 (sqrtf (+ (* dy-rat dy-rat) (* d-temp-4 d-temp-4)))))
(inverse-y-len-2 (/ 1.0 (sqrtf (+ (* dy-rat-times-4 dy-rat-times-4) (* d-temp-5 d-temp-5)))))
)
(set! (-> cull-info yz-dir-ay) (* dy-rat inverse-y-len))
(set! (-> cull-info yz-dir-az) (* d-temp-4 inverse-y-len))
(set! (-> cull-info yz-dir-by) (* dy-rat-times-4 inverse-y-len-2))
(set! (-> cull-info yz-dir-bz) (* d-temp-5 inverse-y-len-2))
)
(set!
(-> cull-info yz-cross-ab)
(- (* dy-rat d-temp-5) (* d-temp-4 dy-rat-times-4))
)
)
)
)
(set! (-> cull-info xz-dir-ax) (* dx-rat-2 inverse-x-len)) ;; frustum normal x (scaled)
(set! (-> cull-info xz-dir-az) (* d-temp-2 inverse-x-len)) ;; normal z (scaled)
;; not sure what this "b" means, but it just seems like it's a much wider frustum?
(set! (-> cull-info xz-dir-bx) (* dx-rat-times-4 inverse-x-len-2))
(set! (-> cull-info xz-dir-bz) (* d-temp-3 inverse-x-len-2))
;; not sure why you'd want this, but okay.
(set! (-> cull-info xz-cross-ab) (- (* dx-rat-2 d-temp-3) (* d-temp-2 dx-rat-times-4)))
;; Repeat of the above math for y.
(set! dy-rat (* (-> math-cam d) (-> math-cam y-ratio)))
(set! d-temp-4 (-> math-cam d))
(set! dy-rat-times-4 (* 4.000000 dy-rat))
(set! d-temp-5 (-> math-cam d))
(set! inverse-y-len
(/ 1.000000 (sqrtf (+ (* dy-rat dy-rat) (* d-temp-4 d-temp-4))))
)
(set! inverse-y-len-2
(/ 1.000000
(sqrtf (+ (* dy-rat-times-4 dy-rat-times-4) (* d-temp-5 d-temp-5)))
)
)
(set! (-> cull-info yz-dir-ay) (* dy-rat inverse-y-len))
(set! (-> cull-info yz-dir-az) (* d-temp-4 inverse-y-len))
(set! (-> cull-info yz-dir-by) (* dy-rat-times-4 inverse-y-len-2))
(set! (-> cull-info yz-dir-bz) (* d-temp-5 inverse-y-len-2))
(set! (-> cull-info yz-cross-ab) (- (* dy-rat d-temp-5) (* d-temp-4 dy-rat-times-4)))
;; update the fog corrector.
;; fog setup
(fog-corrector-setup *math-camera-fog-correction* math-cam)
;; not sure why we do this here.
(set! cam-mat (matrix-identity! (-> math-cam camera-rot)))
(set! very-near 100.000000)
(set! very-far 16760631.000000) ;; this is ~4091.95 meters.
(set! fog-constant-3 16777115.000000) ;; unused.
;; reset camera rotation
(matrix-identity! (-> math-cam camera-rot))
;; this is actually fog.
(set! fog-at-d
(/ (* (-> math-cam d) (- (-> math-cam fog-min) (-> math-cam fog-max))) ;; fog of the plane
(- (-> *math-camera-fog-correction* fog-end) (-> *math-camera-fog-correction* fog-start)) ;; corrected fog.
)
(let ((fog-constant-1 100.0)
(fog-constant-2 16760631.0)
)
(set! mid-range (* -0.500000 (- very-far very-near)))
;; not sure what this is doing exactly
(set! range-factor
(/ mid-range
(* (-> math-cam d) (- (-> math-cam f) (-> math-cam d)))
)
)
(set! cam-fov-mult (-> math-cam fov-correction-factor))
(set! (-> math-cam perspective data 0)
(* cam-fov-mult
(- (/ (-> math-cam x-pix) ;; scale for pixels I guess?
(* (-> math-cam x-ratio) (-> math-cam d)) ;; width of frustum
(let ((f0-21 16777115.0)))
(let ((fog-at-near-plane
(/ (* (-> math-cam d) (- (-> math-cam fog-min) (-> math-cam fog-max)))
(- (-> *math-camera-fog-correction* fog-end)
(-> *math-camera-fog-correction* fog-start)
)
)
)
)
(set! (-> math-cam perspective data 5)
(* cam-fov-mult
(- (/ (-> math-cam y-pix) (* (-> math-cam y-ratio) (-> math-cam d))))
)
)
(set! (-> math-cam perspective data 10)
(* cam-fov-mult
(+ (-> math-cam f) (-> math-cam d))
range-factor
)
)
(set! (-> math-cam perspective data 11)
(* (/ cam-fov-mult (-> math-cam d)) fog-at-d)
)
(set! (-> math-cam perspective data 14)
(* -2.000000 range-factor (-> math-cam f) (-> math-cam d) cam-fov-mult)
)
(set! hvdf-x 2048.000000)
(set! hvdf-y 2048.000000)
(set! hvdf-w
(/ (- (* (-> *math-camera-fog-correction* fog-end) (-> math-cam fog-max))
(* (-> *math-camera-fog-correction* fog-start) (-> math-cam fog-min))
)
(fog-factor-2 (* -0.5 (- fog-constant-2 fog-constant-1)))
)
(let ((corrected-fog (/ fog-factor-2 (* (-> math-cam d) (- (-> math-cam f) (-> math-cam d)))))
(cam-fov-mult (-> math-cam fov-correction-factor))
)
(set! (-> math-cam perspective data 0)
(* cam-fov-mult
(- (/ (-> math-cam x-pix) (* (-> math-cam x-ratio) (-> math-cam d))))
)
)
(- (-> *math-camera-fog-correction* fog-end)
(-> *math-camera-fog-correction* fog-start)
(set! (-> math-cam perspective data 5)
(* cam-fov-mult
(- (/ (-> math-cam y-pix) (* (-> math-cam y-ratio) (-> math-cam d))))
)
)
(set! (-> math-cam perspective data 10)
(* (* cam-fov-mult (+ (-> math-cam f) (-> math-cam d))) corrected-fog)
)
(set! (-> math-cam perspective data 11)
(* (/ cam-fov-mult (-> math-cam d)) fog-at-near-plane)
)
(set! (-> math-cam perspective data 14)
(* (* (* (* -2.0 corrected-fog) (-> math-cam f)) (-> math-cam d))
cam-fov-mult
)
)
)
)
(set! hvdf-z (* 0.500000 (+ very-far very-near)))
(set! (-> math-cam hmge-scale data 0) (/ 1.000000 (-> math-cam x-clip)))
(set! (-> math-cam hmge-scale data 1) (/ 1.000000 (-> math-cam y-clip)))
(set! (-> math-cam hmge-scale data 2) (/ 1.000000 mid-range))
(set! (-> math-cam hmge-scale data 3) (/ 1.000000 fog-at-d))
(set! (-> math-cam inv-hmge-scale data 0) (-> math-cam x-clip))
(set! (-> math-cam inv-hmge-scale data 1) (-> math-cam y-clip))
(set! (-> math-cam inv-hmge-scale data 2) mid-range)
(set! (-> math-cam inv-hmge-scale data 3) fog-at-d)
(set! (-> math-cam hvdf-off data 0) hvdf-x)
(set! (-> math-cam hvdf-off data 1) hvdf-y)
(set! (-> math-cam hvdf-off data 2) hvdf-z)
(set! (-> math-cam hvdf-off data 3) hvdf-w)
(set! (-> math-cam guard data 0) (/ (-> math-cam x-clip) (-> math-cam x-pix)))
(set! (-> math-cam guard data 1) (/ (-> math-cam y-clip) (-> math-cam y-pix)))
(set! (-> math-cam guard data 2) 1.000000)
(set! (-> math-cam guard data 3) 1.000000)
(set! (-> math-cam isometric data 14) (- 16777215.000000 hvdf-z))
(set! (-> math-cam isometric data 15) fog-at-d)
(set! persp-xx (-> math-cam perspective data 0))
(set! persp-yy (-> math-cam perspective data 5))
(set! persp-x (* (the-as float #xbffff2e5) (-> math-cam perspective data 0)))
(set! sprite-row-0 (-> math-cam sprite-2d))
(set! (-> sprite-row-0 data 0) persp-x)
(set! (-> sprite-row-0 data 1) 0.000000)
(set! (-> sprite-row-0 data 2) 0.000000)
(set! (-> sprite-row-0 data 3) 0.000000)
(set! sprite-row-1 (&-> math-cam sprite-2d data 4))
(set! (-> sprite-row-1 0) 0.000000)
(set! (-> sprite-row-1 1) (- (* (/ persp-yy persp-xx) persp-x)))
(set! (-> sprite-row-1 2) 0.000000)
(set! (-> sprite-row-1 3) 0.000000)
(set! sprite-row-2 (&-> math-cam sprite-2d data 8))
(set! (-> sprite-row-2 0) 0.000000)
(set! (-> sprite-row-2 1) 0.000000)
(set! (-> sprite-row-2 2) (- persp-x))
(set! (-> sprite-row-2 3) 0.000000)
(set! sprite-row-3 (&-> math-cam sprite-2d data 12))
(set! (-> sprite-row-3 0) 0.000000)
(set! (-> sprite-row-3 1) 0.000000)
(set! (-> sprite-row-3 2) (* 500000000.000000 persp-x))
(set! (-> sprite-row-3 3) (* (* 60.000000 persp-x) (-> math-cam pfog0)))
(set! v1-15 (-> math-cam sprite-2d-hvdf))
(set! a0-10 (-> math-cam hvdf-off))
;;(.lq a0-11 0 a0-10)
;;(.sq a0-11 0 v1-15)
(rlet ((a0-11 :class vf))
(.lvf a0-11 a0-10)
(.svf v1-15 a0-11)
;; hvdf/hmge, no idea what these are
(let ((hvdf-x 2048.0)
(hvdf-y 2048.0)
(hvdf-w
(/ (- (* (-> *math-camera-fog-correction* fog-end) (-> math-cam fog-max))
(* (-> *math-camera-fog-correction* fog-start)
(-> math-cam fog-min)
)
)
(- (-> *math-camera-fog-correction* fog-end)
(-> *math-camera-fog-correction* fog-start)
)
)
)
)
(let ((hvdf-z (* 0.5 (+ fog-constant-2 fog-constant-1))))
(set! (-> math-cam hmge-scale x) (/ 1.0 (-> math-cam x-clip)))
(set! (-> math-cam hmge-scale y) (/ 1.0 (-> math-cam y-clip)))
(set! (-> math-cam hmge-scale z) (/ 1.0 fog-factor-2))
(set! (-> math-cam hmge-scale w) (/ 1.0 fog-at-near-plane))
(set! (-> math-cam inv-hmge-scale x) (-> math-cam x-clip))
(set! (-> math-cam inv-hmge-scale y) (-> math-cam y-clip))
(set! (-> math-cam inv-hmge-scale z) fog-factor-2)
(set! (-> math-cam inv-hmge-scale w) fog-at-near-plane)
(set! (-> math-cam hvdf-off x) hvdf-x)
(set! (-> math-cam hvdf-off y) hvdf-y)
(set! (-> math-cam hvdf-off z) hvdf-z)
(set! (-> math-cam hvdf-off w) hvdf-w)
(set! (-> math-cam guard x) (/ (-> math-cam x-clip) (-> math-cam x-pix)))
(set! (-> math-cam guard y) (/ (-> math-cam y-clip) (-> math-cam y-pix)))
(set! (-> math-cam guard z) 1.0)
(set! (-> math-cam guard w) 1.0)
(set! (-> math-cam isometric data 14) (- 16777215.0 hvdf-z))
)
(set! (-> math-cam isometric data 15) fog-at-near-plane)
;; perspective matrix
(let ((persp-xx (-> math-cam perspective data 0))
(persp-yy (-> math-cam perspective data 5))
(persp-x (* -1.9996 (-> math-cam perspective data 0)))
)
(let ((sprite-row-0 (-> math-cam sprite-2d)))
(set! (-> sprite-row-0 data 0) persp-x)
(set! (-> sprite-row-0 data 1) 0.0)
(set! (-> sprite-row-0 data 2) 0.0)
(set! (-> sprite-row-0 data 3) 0.0)
)
(let ((sprite-row-1 (&-> math-cam sprite-2d data 4)))
(set! (-> sprite-row-1 0) 0.0)
(set! (-> sprite-row-1 1) (- (* (/ persp-yy persp-xx) persp-x)))
(set! (-> sprite-row-1 2) 0.0)
(set! (-> sprite-row-1 3) 0.0)
)
(let ((sprite-row-2 (&-> math-cam sprite-2d data 8)))
(set! (-> sprite-row-2 0) 0.0)
(set! (-> sprite-row-2 1) 0.0)
(set! (-> sprite-row-2 2) (- persp-x))
(set! (-> sprite-row-2 3) 0.0)
)
(let ((sprite-row-3 (&-> math-cam sprite-2d data 12)))
(set! (-> sprite-row-3 0) 0.0)
(set! (-> sprite-row-3 1) 0.0)
(set! (-> sprite-row-3 2) (* 500000000.0 persp-x))
(set! (-> sprite-row-3 3) (* (* 60.0 persp-x) (-> math-cam pfog0)))
)
)
(let ((v1-15 (-> math-cam sprite-2d-hvdf)))
(set! (-> v1-15 quad) (-> math-cam hvdf-off quad))
)
(set! (-> math-cam sprite-2d-hvdf x) 2048.0)
(set! (-> math-cam sprite-2d-hvdf y) 2048.0)
(set! (-> math-cam sprite-2d-hvdf z) (-> math-cam hvdf-off z))
(set! (-> math-cam pfog0) fog-at-near-plane)
(set! (-> math-cam pfog1) hvdf-w)
)
)
)
(set! (-> math-cam sprite-2d-hvdf data 0) 2048.000000)
(set! (-> math-cam sprite-2d-hvdf data 1) 2048.000000)
(set! (-> math-cam sprite-2d-hvdf data 2) (-> math-cam hvdf-off data 2))
(set! (-> math-cam pfog0) fog-at-d)
(set! (-> math-cam pfog1) hvdf-w)
;; unused
;;(set! v1-17 0)
;;(set! v1-19 (shl #x301ec000 32))
;;(.pcpyld v1-20 r0-0 v1-19)
;;(set! v1-22 (shl #x303ec000 32))
;;(.pcpyld v1-23 r0-0 v1-22)
(set! pfog (-> math-cam pfog0))
(set! vis-gif-0 (-> math-cam vis-gifs 0))
(set! (-> vis-gif-0 fog0) (the-as uint pfog))
(set! (-> vis-gif-0 strip) #x301e4000)
(set! (-> vis-gif-0 regs) 1042)
(set! (-> vis-gif-0 fan) #x301ec000)
(set! vis-gif-1 (-> math-cam vis-gifs 1))
(set! (-> vis-gif-1 fog0) (the-as uint pfog))
(set! a1-5 (shl #x20164000 32))
;;(.pcpyld a1-6 r0-0 a1-5) no effect
(set! (-> vis-gif-1 strip) a1-5)
(set! (-> vis-gif-1 regs) 65)
(set! (-> vis-gif-1 fan) #x301ec000)
(set! vis-gif-1-again (-> math-cam vis-gifs 0))
(set! (-> vis-gif-1-again fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again strip) #x303e4000)
(set! (-> vis-gif-1-again regs) 1042)
(set! (-> vis-gif-1-again fan) #x303ec000)
(set! vis-gif-1-again-again (-> math-cam vis-gifs 0))
(set! (-> vis-gif-1-again-again fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again-again strip) #x303e4000)
(set! (-> vis-gif-1-again-again regs) 1042)
(set! (-> vis-gif-1-again-again fan) #x303ec000)
(if (nonzero? sprite-distorter-generate-tables)
(sprite-distorter-generate-tables)
)
math-cam
)
;; sets up some giftags, but they are totally wrong.
;; they use 32-bit variables to store 64-bit parts of the tag.
(let ((v1-17 0)))
(let ((v1-20 (make-u128 0 (shl #x301ec000 32)))))
(let ((v1-23 (make-u128 0 (shl #x303ec000 32)))))
(let ((pfog (-> math-cam pfog0)))
(let ((vis-gif-0 (-> math-cam vis-gifs)))
(set! (-> vis-gif-0 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-0 0 strip) (the-as uint #x301e4000))
(set! (-> vis-gif-0 0 regs) (the-as uint 1042))
(set! (-> vis-gif-0 0 fan) (the-as uint #x301ec000))
)
(let ((vis-gif-1 (-> math-cam vis-gifs 1)))
(set! (-> vis-gif-1 fog0) (the-as uint pfog))
(set! (-> vis-gif-1 strip) (make-u128 0 (shl #x20164000 32)))
(set! (-> vis-gif-1 regs) (the-as uint 65))
(set! (-> vis-gif-1 fan) (the-as uint #x301ec000))
)
(let ((vis-gif-1-again (-> math-cam vis-gifs)))
(set! (-> vis-gif-1-again 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again 0 strip) (the-as uint #x303e4000))
(set! (-> vis-gif-1-again 0 regs) (the-as uint 1042))
(set! (-> vis-gif-1-again 0 fan) (the-as uint #x303ec000))
)
(let ((vis-gif-1-again-again (-> math-cam vis-gifs)))
(set! (-> vis-gif-1-again-again 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again-again 0 strip) (the-as uint #x303e4000))
(set! (-> vis-gif-1-again-again 0 regs) (the-as uint 1042))
(set! (-> vis-gif-1-again-again 0 fan) (the-as uint #x303ec000))
)
)
(defmethod new math-camera ((allocation symbol) (type-to-make type))
"Allocate and initialize a math-camera.
NOTE: the result is full of nans due to fov-correction-factor being unset and defaulting to 0.
This matches what I remember from PS2 emulator stuff."
(local-vars (v1-2 vector) (obj math-camera))
(set! obj (object-new allocation type-to-make (the-as int (-> type-to-make size))))
(set! (-> obj d) 1024.000000) ;; near plane
(set! (-> obj f) 40960000.000000) ;; far plane (4096 meters)
(set! (-> obj fov) (the-as float #x46360b61)) ;; 64 degrees
(set! (-> obj x-pix) 256.000000)
;; not sure what this is, but it seems like there's a 4x wide clipping plane called "b"
(set! (-> obj x-clip) 1024.000000)
(set! (-> obj y-pix) 112.000000)
;; again, 4x wide clippin gthing
(set! (-> obj y-clip) 448.000000)
;; start fog at 10 meters
(set! (-> obj fog-start) 40960.000000)
;; end fog at 200 meters
(set! (-> obj fog-end) 819200.000000)
;; are these the actual fog values used?
(set! (-> obj fog-max) 255.000000)
(set! (-> obj fog-min) 150.000000)
(matrix-identity! (-> obj inv-camera-rot))
(matrix-identity! (-> obj camera-rot))
;;(set! v1-2 (-> obj trans))
;;(.sqc2 vf0 0 v1-2)
(vector-zero! (-> obj trans))
(set! (-> obj isometric data 0) 1.000000) ;; xx
(set! (-> obj isometric data 5) 0.500000) ;; yy
(set! (-> obj isometric data 10) -1.000000) ;; zz
(set! (-> obj reset) 1)
(set! (-> obj smooth-step) 0.000000)
(set! (-> obj smooth-t) 0.000000)
;; setup initial math camera
(update-math-camera obj 'ntsc 'aspect4x3)
;; update sprite stuff.
(if (nonzero? sprite-distorter-generate-tables)
(sprite-distorter-generate-tables)
)
math-cam
)
(define *math-camera* (new 'global 'math-camera))
(defun math-cam-start-smoothing ((arg0 float) (arg1 float))
"Unused camera smoothing"
(set! (-> *math-camera* smooth-step) (/ 1.0 arg0))
(set! (-> *math-camera* smooth-t) arg1)
(matrix->quaternion (-> *math-camera* inv-camera-rot-smooth-from) (-> *math-camera* inv-camera-rot-smooth))
)
(defun move-target-from-pad ((trans transform) (pad-idx int))
"Unused function to adjust trans based on inputs from the pad."
;; local-trans is the translation in the camera frame.
(let ((local-trans (new 'stack-no-clear 'vector)))
(set! (-> local-trans quad) (the-as uint128 0))
;; circle/square move camera relative x (left and right)
(set! (-> local-trans x)
(cond
((nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons circle)))
-80.0
)
((nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons square)))
80.0
)
(else
0.0
)
)
)
;; no way to move camera relative y (up/down)
(set! (-> local-trans y) 0.0)
;; in and out movement
(set! (-> local-trans z)
(cond
((nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons down)))
-80.0
)
((nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons up)))
80.0
)
(else
0.0
)
)
)
(set! (-> local-trans w) 1.0)
;; rotate this into world frame
(let ((inv-cam-rot (new-stack-vector0))
(cam-rot-mat (new-stack-matrix0)))
;; unused.
(vector-negate! inv-cam-rot (-> trans rot))
;; convert rotation to rotation matrix.
(matrix-rotate-zyx! cam-rot-mat (-> trans rot))
;; and rotate the translation.
(vector-matrix*! local-trans local-trans cam-rot-mat)
)
;; and update the transform
(vector+! (-> trans trans) (-> trans trans) local-trans)
)
;; don't forget to fix w.
(set! (-> trans trans w) 1.0)
;; global translation
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons r1)))
(set! (-> trans trans y) (+ 80.0 (-> trans trans y)))
)
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons r2)))
(set! (-> trans trans y) (+ -80.0 (-> trans trans y)))
)
;; rotation (don't allow camera roll)
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons x)))
(set! (-> trans rot x) (+ 546.13336 (-> trans rot x)))
)
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons triangle)))
(set! (-> trans rot x) (+ -546.13336 (-> trans rot x)))
)
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons left)))
(set! (-> trans rot y) (+ 546.13336 (-> trans rot y)))
)
(if (nonzero? (logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons right)))
(set! (-> trans rot y) (+ -546.13336 (-> trans rot y)))
)
trans
)
(defun transform-point-vector! ((arg0 vector) (arg1 vector))
"Apply camera transformation to a point."
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
;;(TODO.VCLIP vf31 vf31)
(let ((clip (vu-clip vf31 0)))
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
(zero? (logand clip 63))
)
)
)
(defun transform-point-qword! ((arg0 vector) (arg1 vector))
"Apply camera transformation to point, returning fixed point 28.4 position"
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
;;(TODO.VCLIP vf31 vf31)
(let ((clip (vu-clip vf31 0)))
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
;;(TODO.VFTOI4 vf28 vf28)
(vftoi4.xyzw vf28 vf28)
(.svf (&-> arg0 quad) vf28)
(zero? (logand clip 63))
)
)
)
(defun transform-point-vector-scale! ((arg0 vector) (arg1 vector))
(local-vars (v0-0 float))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
;;(TODO.VCLIP vf31 vf31) clip result was unused
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
;;(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
;;(let ((a0-2 (zero? (logand v1-7 63))))
;; )
(.mov v0-0 vf23)
v0-0
)
)
;; In the original game, init-for-transform stashed a bunch of stuff in registers, to be used by other functions.
;; In OpenGOAL, this seems risky so we're going to back up this manually:
(deftype transform-regs (structure)
((vf1 uint128)
(vf2 uint128)
(vf3 uint128)
(vf4 uint128)
(vf17 uint128)
(vf18 uint128)
(vf19 uint128)
(vf23 uint128)
(vf24 uint128)
(vf25 uint128)
(vf26 uint128)
(vf27 uint128)
(vf28 uint128)
(vf29 uint128)
)
)
(define *transform-regs* (new 'static 'transform-regs))
(defun init-for-transform ((arg0 matrix))
(rlet ((vf1 :class vf)
(vf17 :class vf)
(vf18 :class vf)
(vf19 :class vf)
(vf2 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(let ((gp-0 (new-stack-matrix0))
(s5-0 (new-stack-matrix0))
(s4-0 (new 'stack 'vector4s-3))
(s3-0 (new-stack-vector0))
(s2-0 (new 'stack 'vector4s-3))
)
(matrix*! s5-0 arg0 (-> *math-camera* camera-temp))
(matrix-3x3-inverse-transpose! gp-0 arg0)
(let ((v1-3 s3-0))
(set! (-> v1-3 x) 0.4)
(set! (-> v1-3 y) 0.4)
(set! (-> v1-3 z) 0.4)
(set! (-> v1-3 w) 1.0)
)
(let ((v1-4 (-> s4-0 data)))
(set! (-> v1-4 0) 1.0)
(set! (-> v1-4 1) 1.0)
(set! (-> v1-4 2) 1.0)
(set! (-> v1-4 3) 1.0)
)
(let ((v1-5 (&-> s4-0 data 4)))
(set! (-> v1-5 0) 0.0)
(set! (-> v1-5 1) 0.0)
(set! (-> v1-5 2) 0.0)
(set! (-> v1-5 3) 1.0)
)
(let ((v1-6 (&-> s4-0 data 8)))
(set! (-> v1-6 0) 0.0)
(set! (-> v1-6 1) 0.0)
(set! (-> v1-6 2) 0.0)
(set! (-> v1-6 3) 1.0)
)
(let ((v1-7 (-> s2-0 data)))
(set! (-> v1-7 0) 1.0)
(set! (-> v1-7 1) 0.0)
(set! (-> v1-7 2) 0.0)
(set! (-> v1-7 3) 1.0)
)
(let ((v1-8 (&-> s2-0 data 4)))
(set! (-> v1-8 0) 0.0)
(set! (-> v1-8 1) 1.0)
(set! (-> v1-8 2) 0.0)
(set! (-> v1-8 3) 1.0)
)
(let ((v1-9 (&-> s2-0 data 8)))
(set! (-> v1-9 0) 0.0)
(set! (-> v1-9 1) 0.0)
(set! (-> v1-9 2) 1.0)
(set! (-> v1-9 3) 1.0)
)
(.lvf vf7 (&-> *math-camera* hmge-scale quad))
(.lvf vf8 (&-> *math-camera* hvdf-off quad))
(.lvf vf9 (&-> *math-camera* giftex))
(let ((v1-13 255))
(.mov vf6 v1-13)
)
;;(.mov v1-14 vf6)
(.itof.vf vf6 vf6)
(set! (-> *transform-regs* vf1) (-> s5-0 vector 0 quad))
(set! (-> *transform-regs* vf2) (-> s5-0 vector 1 quad))
(set! (-> *transform-regs* vf3) (-> s5-0 vector 2 quad))
(set! (-> *transform-regs* vf4) (-> s5-0 vector 3 quad))
(set! (-> *transform-regs* vf17) (-> gp-0 vector 0 quad))
(set! (-> *transform-regs* vf18) (-> gp-0 vector 1 quad))
(set! (-> *transform-regs* vf19) (-> gp-0 vector 2 quad))
(set! (-> *transform-regs* vf23) (-> s2-0 quad 0))
(set! (-> *transform-regs* vf24) (-> s2-0 quad 1))
(set! (-> *transform-regs* vf25) (-> s2-0 quad 2))
(set! (-> *transform-regs* vf27) (-> s4-0 quad 0))
(set! (-> *transform-regs* vf28) (-> s4-0 quad 1))
(set! (-> *transform-regs* vf29) (-> s4-0 quad 2))
(set! (-> *transform-regs* vf26) (-> s3-0 quad))
)
(none)
)
)
+11
View File
@@ -56,3 +56,14 @@
)
dst
)
(defmacro new-stack-matrix0 ()
"Get a new matrix on the stack that's set to zero."
`(let ((mat (new 'stack-no-clear 'matrix)))
(set! (-> mat quad 0) (the-as uint128 0))
(set! (-> mat quad 1) (the-as uint128 0))
(set! (-> mat quad 2) (the-as uint128 0))
(set! (-> mat quad 3) (the-as uint128 0))
mat
)
)
+10
View File
@@ -683,6 +683,16 @@
dst
)
(defmacro new-stack-vector0 ()
"Get a stack vector that's set to 0.
This is more efficient than (new 'stack 'vector) because
this doesn't call the constructor."
`(let ((vec (new 'stack-no-clear 'vector)))
(set! (-> vec quad) (the-as uint128 0))
vec
)
)
(define *zero-vector* (new 'static 'vector :x 0. :y 0. :z 0. :w 0.))
(define-extern vector-identity! (function vector vector))
(define-extern vector-length (function vector float))
+56 -1
View File
@@ -5,4 +5,59 @@
;; name in dgo: vu1-macros
;; dgos: GAME, ENGINE
;; this file has no code!
;; this file has no code!
(defmacro vu-clip (vfr cf)
"Returns the result of VCLIP.
NOTE: this implementation is pretty inefficient.
If this ends up used a lot, it's probably worth rewriting.
"
`(let ((vec (new 'stack 'vector))
(flag ,cf)
)
(.svf vec ,vfr)
(let* ((w-plus (fabs (-> vec w)))
(w-minus (- 0.0 w-plus))
)
;; CF = CF << 6
(set! flag (logand #xffffff (shl flag 6)))
(when (> (-> vec x) w-plus)
(logior! flag 1)
)
(when (< (-> vec x) w-minus)
(logior! flag 2)
)
(when (> (-> vec y) w-plus)
(logior! flag 4)
)
(when (< (-> vec y) w-minus)
(logior! flag 8)
)
(when (> (-> vec z) w-plus)
(logior! flag 16)
)
(when (< (-> vec z) w-minus)
(logior! flag 32)
)
)
flag
)
)
(defmacro vftoi4.xyzw (dst src)
"convert to 28.4 integer. This does the multiply while the number is still
a float. This will have issues for very large floats, but it seems like this
is how PCSX2 does it as well, so maybe it's right?
NOTE: this is the only version of the instruction used in Jak 1, so we
don't need to worry about masks."
`(begin
(rlet ((temp :class vf))
(set! temp 16.0)
(.mul.x.vf temp ,src temp)
(.ftoi.vf ,dst temp)
)
)
)
+1 -1
View File
@@ -1407,6 +1407,6 @@
(.mov upper-xmm ,upper)
(.mov lower-xmm ,lower)
(.pcpyld result upper-xmm lower-xmm)
result
(the-as uint result)
)
)
+8
View File
@@ -169,6 +169,14 @@ Val* Compiler::do_set(const goos::Object& form, Val* dest, RegVal* src_in_reg, V
src_in_reg = src_128;
}
if (as_mem_deref->info.size != 16 && (src_in_reg->ireg().reg_class == RegClass::VECTOR_FLOAT ||
src_in_reg->ireg().reg_class == RegClass::INT_128)) {
auto fe = get_parent_env_of_type<FunctionEnv>(env);
auto src_gpr = fe->make_ireg(src_in_reg->type(), RegClass::GPR_64);
env->emit_ir<IR_RegSet>(src_gpr, src_in_reg);
src_in_reg = src_gpr;
}
// setting somewhere in memory
auto base = as_mem_deref->base;
auto base_as_mco = dynamic_cast<MemoryOffsetConstantVal*>(base);
@@ -415,7 +415,7 @@
(.mov upper-xmm ,upper)
(.mov lower-xmm ,lower)
(.pcpyld result upper-xmm lower-xmm)
result
(the uint result)
)
)
@@ -587,5 +587,4 @@
(define-extern vector-rad<-vector-deg! (function vector vector none))
(define-extern vector-rad<-vector-deg/2! (function vector vector int))
; process-drawable
(define-extern process-drawable-art-error symbol)
(define-extern sprite-distorter-generate-tables (function none))
@@ -0,0 +1,763 @@
;;-*-Lisp-*-
(in-package goal)
;; definition of type fog-corrector
(deftype fog-corrector (structure)
((fog-end float :offset-assert 0)
(fog-start float :offset-assert 4)
)
:method-count-assert 9
:size-assert #x8
:flag-assert #x900000008
)
;; definition for method 3 of type fog-corrector
(defmethod inspect fog-corrector ((obj fog-corrector))
(format #t "[~8x] ~A~%" obj 'fog-corrector)
(format #t "~Tfog-end: ~f~%" (-> obj fog-end))
(format #t "~Tfog-start: ~f~%" (-> obj fog-start))
obj
)
;; definition for function fog-corrector-setup
;; INFO: Return type mismatch float vs none.
(defun fog-corrector-setup ((corrector fog-corrector) (math-cam math-camera))
(set!
(-> corrector fog-end)
(* (-> math-cam fog-end) (-> math-cam fov-correction-factor))
)
(set!
(-> corrector fog-start)
(* (-> math-cam fog-start) (-> math-cam fov-correction-factor))
)
(none)
)
;; definition for symbol *math-camera-fog-correction*, type fog-corrector
(define *math-camera-fog-correction* (new 'global 'fog-corrector))
;; definition for function update-math-camera
;; Used lq/sq
(defun
update-math-camera
((math-cam math-camera) (video-mode symbol) (aspect symbol))
(set! (-> math-cam x-ratio) (tan (* 0.5 (-> math-cam fov))))
(if (= aspect 'aspect4x3)
(set! (-> math-cam y-ratio) (* 0.75 (-> math-cam x-ratio)))
(set! (-> math-cam y-ratio) (* 0.5625 (-> math-cam x-ratio)))
)
(let ((x-rat (-> math-cam x-ratio))
(y-rat (-> math-cam y-ratio))
(cull-info (-> math-cam cull-info))
)
(let
((unused-x-thing
(/ (+ 1.0 (* (* 4.0 x-rat) x-rat)) (+ 1.0 (* x-rat x-rat)))
)
)
)
(let ((y-thing (/ (+ 1.0 (* (* 4.0 y-rat) y-rat)) (+ 1.0 (* y-rat y-rat)))))
(set!
(-> cull-info x-fact)
(/
(+ 1.0 (* (* 4.0 x-rat) x-rat))
(* x-rat (sqrtf (+ 1.0 (* (* 16.0 x-rat) x-rat))))
)
)
(set!
(-> cull-info y-fact)
(/
(+ 1.0 (* (* 4.0 y-rat) y-rat))
(* y-rat (sqrtf (+ 1.0 (* (* 16.0 y-rat) y-rat))))
)
)
(set!
(-> cull-info z-fact)
(sqrtf
(+
(* (* (* (+ -4.0 y-thing) (+ -4.0 y-thing)) y-rat) y-rat)
(* (+ -1.0 y-thing) (+ -1.0 y-thing))
)
)
)
)
(let* ((near-x (* x-rat (-> math-cam d)))
(near-y (* y-rat (-> math-cam d)))
(near-corner-dist-sqr (+ (* near-x near-x) (* near-y near-y)))
(near-z (-> math-cam d))
)
(set!
(-> cull-info cam-radius)
(sqrtf (+ near-corner-dist-sqr (* near-z near-z)))
)
)
(let* ((dx-rat-2 (* (-> math-cam d) (-> math-cam x-ratio)))
(d-temp-2 (-> math-cam d))
(dx-rat-times-4 (* 4.0 dx-rat-2))
(d-temp-3 (-> math-cam d))
)
(let
((inverse-x-len
(/ 1.0 (sqrtf (+ (* dx-rat-2 dx-rat-2) (* d-temp-2 d-temp-2))))
)
(inverse-x-len-2
(/
1.0
(sqrtf (+ (* dx-rat-times-4 dx-rat-times-4) (* d-temp-3 d-temp-3)))
)
)
)
(set! (-> cull-info xz-dir-ax) (* dx-rat-2 inverse-x-len))
(set! (-> cull-info xz-dir-az) (* d-temp-2 inverse-x-len))
(set! (-> cull-info xz-dir-bx) (* dx-rat-times-4 inverse-x-len-2))
(set! (-> cull-info xz-dir-bz) (* d-temp-3 inverse-x-len-2))
)
(set!
(-> cull-info xz-cross-ab)
(- (* dx-rat-2 d-temp-3) (* d-temp-2 dx-rat-times-4))
)
)
(let* ((dy-rat (* (-> math-cam d) (-> math-cam y-ratio)))
(d-temp-4 (-> math-cam d))
(dy-rat-times-4 (* 4.0 dy-rat))
(d-temp-5 (-> math-cam d))
)
(let
((inverse-y-len
(/ 1.0 (sqrtf (+ (* dy-rat dy-rat) (* d-temp-4 d-temp-4))))
)
(inverse-y-len-2
(/
1.0
(sqrtf (+ (* dy-rat-times-4 dy-rat-times-4) (* d-temp-5 d-temp-5)))
)
)
)
(set! (-> cull-info yz-dir-ay) (* dy-rat inverse-y-len))
(set! (-> cull-info yz-dir-az) (* d-temp-4 inverse-y-len))
(set! (-> cull-info yz-dir-by) (* dy-rat-times-4 inverse-y-len-2))
(set! (-> cull-info yz-dir-bz) (* d-temp-5 inverse-y-len-2))
)
(set!
(-> cull-info yz-cross-ab)
(- (* dy-rat d-temp-5) (* d-temp-4 dy-rat-times-4))
)
)
)
(fog-corrector-setup *math-camera-fog-correction* math-cam)
(let ((v0-1 (matrix-identity! (-> math-cam camera-rot))))
)
(let ((fog-constant-1 100.0)
(fog-constant-2 16760631.0)
)
(let ((f0-21 16777115.0))
)
(let
((fog-at-near-plane
(/
(* (-> math-cam d) (- (-> math-cam fog-min) (-> math-cam fog-max)))
(-
(-> *math-camera-fog-correction* fog-end)
(-> *math-camera-fog-correction* fog-start)
)
)
)
(fog-factor-2 (* -0.5 (- fog-constant-2 fog-constant-1)))
)
(let
((corrected-fog
(/ fog-factor-2 (* (-> math-cam d) (- (-> math-cam f) (-> math-cam d))))
)
(cam-fov-mult (-> math-cam fov-correction-factor))
)
(set!
(-> math-cam perspective data 0)
(*
cam-fov-mult
(- (/ (-> math-cam x-pix) (* (-> math-cam x-ratio) (-> math-cam d))))
)
)
(set!
(-> math-cam perspective data 5)
(*
cam-fov-mult
(- (/ (-> math-cam y-pix) (* (-> math-cam y-ratio) (-> math-cam d))))
)
)
(set!
(-> math-cam perspective data 10)
(* (* cam-fov-mult (+ (-> math-cam f) (-> math-cam d))) corrected-fog)
)
(set!
(-> math-cam perspective data 11)
(* (/ cam-fov-mult (-> math-cam d)) fog-at-near-plane)
)
(set!
(-> math-cam perspective data 14)
(*
(* (* (* -2.0 corrected-fog) (-> math-cam f)) (-> math-cam d))
cam-fov-mult
)
)
)
(let ((hvdf-x 2048.0)
(hvdf-y 2048.0)
(hvdf-w
(/
(-
(* (-> *math-camera-fog-correction* fog-end) (-> math-cam fog-max))
(*
(-> *math-camera-fog-correction* fog-start)
(-> math-cam fog-min)
)
)
(-
(-> *math-camera-fog-correction* fog-end)
(-> *math-camera-fog-correction* fog-start)
)
)
)
)
(let ((hvdf-z (* 0.5 (+ fog-constant-2 fog-constant-1))))
(set! (-> math-cam hmge-scale x) (/ 1.0 (-> math-cam x-clip)))
(set! (-> math-cam hmge-scale y) (/ 1.0 (-> math-cam y-clip)))
(set! (-> math-cam hmge-scale z) (/ 1.0 fog-factor-2))
(set! (-> math-cam hmge-scale w) (/ 1.0 fog-at-near-plane))
(set! (-> math-cam inv-hmge-scale x) (-> math-cam x-clip))
(set! (-> math-cam inv-hmge-scale y) (-> math-cam y-clip))
(set! (-> math-cam inv-hmge-scale z) fog-factor-2)
(set! (-> math-cam inv-hmge-scale w) fog-at-near-plane)
(set! (-> math-cam hvdf-off x) hvdf-x)
(set! (-> math-cam hvdf-off y) hvdf-y)
(set! (-> math-cam hvdf-off z) hvdf-z)
(set! (-> math-cam hvdf-off w) hvdf-w)
(set! (-> math-cam guard x) (/ (-> math-cam x-clip) (-> math-cam x-pix)))
(set! (-> math-cam guard y) (/ (-> math-cam y-clip) (-> math-cam y-pix)))
(set! (-> math-cam guard z) 1.0)
(set! (-> math-cam guard w) 1.0)
(set! (-> math-cam isometric data 14) (- 16777215.0 hvdf-z))
)
(set! (-> math-cam isometric data 15) fog-at-near-plane)
(let ((persp-xx (-> math-cam perspective data 0))
(persp-yy (-> math-cam perspective data 5))
(persp-x (* -1.9996 (-> math-cam perspective data 0)))
)
(let ((sprite-row-0 (-> math-cam sprite-2d)))
(set! (-> sprite-row-0 data 0) persp-x)
(set! (-> sprite-row-0 data 1) 0.0)
(set! (-> sprite-row-0 data 2) 0.0)
(set! (-> sprite-row-0 data 3) 0.0)
)
(let ((sprite-row-1 (&-> math-cam sprite-2d data 4)))
(set! (-> sprite-row-1 0) 0.0)
(set! (-> sprite-row-1 1) (- (* (/ persp-yy persp-xx) persp-x)))
(set! (-> sprite-row-1 2) 0.0)
(set! (-> sprite-row-1 3) 0.0)
)
(let ((sprite-row-2 (&-> math-cam sprite-2d data 8)))
(set! (-> sprite-row-2 0) 0.0)
(set! (-> sprite-row-2 1) 0.0)
(set! (-> sprite-row-2 2) (- persp-x))
(set! (-> sprite-row-2 3) 0.0)
)
(let ((sprite-row-3 (&-> math-cam sprite-2d data 12)))
(set! (-> sprite-row-3 0) 0.0)
(set! (-> sprite-row-3 1) 0.0)
(set! (-> sprite-row-3 2) (* 500000000.0 persp-x))
(set! (-> sprite-row-3 3) (* (* 60.0 persp-x) (-> math-cam pfog0)))
)
)
(let ((v1-15 (-> math-cam sprite-2d-hvdf)))
(set! (-> v1-15 quad) (-> math-cam hvdf-off quad))
)
(set! (-> math-cam sprite-2d-hvdf x) 2048.0)
(set! (-> math-cam sprite-2d-hvdf y) 2048.0)
(set! (-> math-cam sprite-2d-hvdf z) (-> math-cam hvdf-off z))
(set! (-> math-cam pfog0) fog-at-near-plane)
(set! (-> math-cam pfog1) hvdf-w)
)
)
)
(let ((v1-17 0))
)
(let ((v1-20 (make-u128 0 (shl #x301ec000 32))))
)
(let ((v1-23 (make-u128 0 (shl #x303ec000 32))))
)
(let ((pfog (-> math-cam pfog0)))
(let ((vis-gif-0 (-> math-cam vis-gifs)))
(set! (-> vis-gif-0 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-0 0 strip) (the-as uint #x301e4000))
(set! (-> vis-gif-0 0 regs) (the-as uint 1042))
(set! (-> vis-gif-0 0 fan) (the-as uint #x301ec000))
)
(let ((vis-gif-1 (-> math-cam vis-gifs 1)))
(set! (-> vis-gif-1 fog0) (the-as uint pfog))
(set! (-> vis-gif-1 strip) (make-u128 0 (shl #x20164000 32)))
(set! (-> vis-gif-1 regs) (the-as uint 65))
(set! (-> vis-gif-1 fan) (the-as uint #x301ec000))
)
(let ((vis-gif-1-again (-> math-cam vis-gifs)))
(set! (-> vis-gif-1-again 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again 0 strip) (the-as uint #x303e4000))
(set! (-> vis-gif-1-again 0 regs) (the-as uint 1042))
(set! (-> vis-gif-1-again 0 fan) (the-as uint #x303ec000))
)
(let ((vis-gif-1-again-again (-> math-cam vis-gifs)))
(set! (-> vis-gif-1-again-again 0 fog0) (the-as uint pfog))
(set! (-> vis-gif-1-again-again 0 strip) (the-as uint #x303e4000))
(set! (-> vis-gif-1-again-again 0 regs) (the-as uint 1042))
(set! (-> vis-gif-1-again-again 0 fan) (the-as uint #x303ec000))
)
)
(if (nonzero? sprite-distorter-generate-tables)
(sprite-distorter-generate-tables)
)
math-cam
)
;; definition for method 0 of type math-camera
(defmethod new math-camera ((allocation symbol) (type-to-make type))
(rlet ((vf0 :class vf))
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let
((gp-0
(object-new allocation type-to-make (the-as int (-> type-to-make size)))
)
)
(set! (-> gp-0 d) 1024.0)
(set! (-> gp-0 f) 40960000.0)
(set! (-> gp-0 fov) 11650.845)
(set! (-> gp-0 x-pix) 256.0)
(set! (-> gp-0 x-clip) 1024.0)
(set! (-> gp-0 y-pix) 112.0)
(set! (-> gp-0 y-clip) 448.0)
(set! (-> gp-0 fog-start) 40960.0)
(set! (-> gp-0 fog-end) 819200.0)
(set! (-> gp-0 fog-max) 255.0)
(set! (-> gp-0 fog-min) 150.0)
(matrix-identity! (-> gp-0 inv-camera-rot))
(matrix-identity! (-> gp-0 camera-rot))
(.svf (&-> (-> gp-0 trans) quad) vf0)
(set! (-> gp-0 isometric data 0) 1.0)
(set! (-> gp-0 isometric data 5) 0.5)
(set! (-> gp-0 isometric data 10) -1.0)
(set! (-> gp-0 reset) 1)
(set! (-> gp-0 smooth-step) 0.0)
(set! (-> gp-0 smooth-t) 0.0)
(update-math-camera gp-0 'ntsc 'aspect4x3)
)
)
)
;; definition for symbol *math-camera*, type math-camera
(define *math-camera* (new 'global 'math-camera))
;; definition for function math-cam-start-smoothing
(defun math-cam-start-smoothing ((arg0 float) (arg1 float))
(set! (-> *math-camera* smooth-step) (/ 1.0 arg0))
(set! (-> *math-camera* smooth-t) arg1)
(matrix->quaternion
(-> *math-camera* inv-camera-rot-smooth-from)
(-> *math-camera* inv-camera-rot-smooth)
)
)
;; definition for function move-target-from-pad
;; Used lq/sq
(defun move-target-from-pad ((trans transform) (pad-idx int))
(rlet ((vf0 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((local-trans (new 'stack-no-clear 'vector)))
(set! (-> local-trans quad) (the-as uint128 0))
(set! (-> local-trans x) (cond
((nonzero?
(logand
(-> *cpad-list* cpads pad-idx button0-abs 0)
(pad-buttons circle)
)
)
-80.0
)
((nonzero?
(logand
(-> *cpad-list* cpads pad-idx button0-abs 0)
(pad-buttons square)
)
)
80.0
)
(else
0.0
)
)
)
(set! (-> local-trans y) 0.0)
(set! (-> local-trans z) (cond
((nonzero?
(logand
(-> *cpad-list* cpads pad-idx button0-abs 0)
(pad-buttons down)
)
)
-80.0
)
((nonzero?
(logand
(-> *cpad-list* cpads pad-idx button0-abs 0)
(pad-buttons up)
)
)
80.0
)
(else
0.0
)
)
)
(set! (-> local-trans w) 1.0)
(let ((inv-cam-rot (new 'stack-no-clear 'vector)))
(set! (-> inv-cam-rot quad) (the-as uint128 0))
(let ((cam-rot-mat (new 'stack-no-clear 'matrix)))
(set! (-> cam-rot-mat vector 0 quad) (the-as uint128 0))
(set! (-> cam-rot-mat vector 1 quad) (the-as uint128 0))
(set! (-> cam-rot-mat vector 2 quad) (the-as uint128 0))
(set! (-> cam-rot-mat vector 3 quad) (the-as uint128 0))
(vector-negate! inv-cam-rot (-> trans rot))
(matrix-rotate-zyx! cam-rot-mat (-> trans rot))
(vector-matrix*! local-trans local-trans cam-rot-mat)
)
)
(let ((a0-8 (-> trans trans)))
(let ((v1-23 (-> trans trans)))
(.mov.vf vf6 vf0 :mask #b1000)
(.lvf vf4 (&-> v1-23 quad))
)
(.lvf vf5 (&-> local-trans quad))
(.add.vf vf6 vf4 vf5 :mask #b111)
(.svf (&-> a0-8 quad) vf6)
)
)
(set! (-> trans trans w) 1.0)
(if
(nonzero?
(logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons r1))
)
(set! (-> trans trans y) (+ 80.0 (-> trans trans y)))
)
(if
(nonzero?
(logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons r2))
)
(set! (-> trans trans y) (+ -80.0 (-> trans trans y)))
)
(if
(nonzero?
(logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons x))
)
(set! (-> trans rot x) (+ 546.13336 (-> trans rot x)))
)
(if
(nonzero?
(logand
(-> *cpad-list* cpads pad-idx button0-abs 0)
(pad-buttons triangle)
)
)
(set! (-> trans rot x) (+ -546.13336 (-> trans rot x)))
)
(if
(nonzero?
(logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons left))
)
(set! (-> trans rot y) (+ 546.13336 (-> trans rot y)))
)
(if
(nonzero?
(logand (-> *cpad-list* cpads pad-idx button0-abs 0) (pad-buttons right))
)
(set! (-> trans rot y) (+ -546.13336 (-> trans rot y)))
)
trans
)
)
;; definition for function transform-point-vector!
;; WARN: Inline assembly instruction marked with TODO - [TODO.VCLIP]
;; WARN: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping]
(defun transform-point-vector! ((arg0 vector) (arg1 vector))
(local-vars (v1-7 int))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
(TODO.VCLIP vf31 vf31)
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
(zero? (logand v1-7 63))
)
)
;; definition for function transform-point-qword!
;; WARN: Inline assembly instruction marked with TODO - [TODO.VCLIP]
;; WARN: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping]
;; WARN: Inline assembly instruction marked with TODO - [TODO.VFTOI4]
(defun transform-point-qword! ((arg0 vector) (arg1 vector))
(local-vars (v1-7 int))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
(TODO.VCLIP vf31 vf31)
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(TODO.VFTOI4 vf28 vf28)
(.svf (&-> arg0 quad) vf28)
(zero? (logand v1-7 63))
)
)
;; definition for function transform-point-vector-scale!
;; WARN: Inline assembly instruction marked with TODO - [TODO.VCLIP]
;; WARN: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping]
(defun transform-point-vector-scale! ((arg0 vector) (arg1 vector))
(local-vars (v0-0 float) (v1-7 int))
(rlet ((acc :class vf)
(Q :class vf)
(vf0 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf30 :class vf)
(vf31 :class vf)
)
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(let ((v1-0 0))
)
(.lvf vf24 (&-> *math-camera* camera-temp vector 0 quad))
(.lvf vf25 (&-> *math-camera* camera-temp vector 1 quad))
(.lvf vf26 (&-> *math-camera* camera-temp vector 2 quad))
(.lvf vf27 (&-> *math-camera* camera-temp vector 3 quad))
(.lvf vf29 (&-> *math-camera* hmge-scale quad))
(.lvf vf30 (&-> *math-camera* hvdf-off quad))
(.lvf vf28 (&-> arg1 quad))
(.mul.x.vf acc vf24 vf28)
(.add.mul.y.vf acc vf25 vf28 acc)
(.add.mul.z.vf acc vf26 vf28 acc)
(.add.mul.w.vf vf28 vf27 vf0 acc)
(.add.w.vf vf23 vf0 vf0)
(.mul.vf vf31 vf28 vf29)
(TODO.VCLIP vf31 vf31)
(.div.vf Q vf0 vf31 :fsf #b11 :ftf #b11)
(.wait.vf)
(.cfc2.i v1-7 Clipping)
(.mul.vf vf28 vf28 Q :mask #b111)
(.mul.vf vf23 vf23 Q)
(.add.vf vf28 vf28 vf30)
(.max.x.vf vf28 vf28 vf0 :mask #b1000)
(.svf (&-> arg0 quad) vf28)
(let ((a0-2 (zero? (logand v1-7 63))))
)
(.mov v0-0 vf23)
v0-0
)
)
;; definition for function init-for-transform
;; INFO: Return type mismatch symbol vs none.
;; Used lq/sq
(defun init-for-transform ((arg0 matrix))
(local-vars (v1-14 float))
(rlet ((vf1 :class vf)
(vf17 :class vf)
(vf18 :class vf)
(vf19 :class vf)
(vf2 :class vf)
(vf23 :class vf)
(vf24 :class vf)
(vf25 :class vf)
(vf26 :class vf)
(vf27 :class vf)
(vf28 :class vf)
(vf29 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(let ((gp-0 (new 'stack-no-clear 'matrix)))
(set! (-> gp-0 vector 0 quad) (the-as uint128 0))
(set! (-> gp-0 vector 1 quad) (the-as uint128 0))
(set! (-> gp-0 vector 2 quad) (the-as uint128 0))
(set! (-> gp-0 vector 3 quad) (the-as uint128 0))
(let ((s5-0 (new 'stack-no-clear 'matrix)))
(set! (-> s5-0 vector 0 quad) (the-as uint128 0))
(set! (-> s5-0 vector 1 quad) (the-as uint128 0))
(set! (-> s5-0 vector 2 quad) (the-as uint128 0))
(set! (-> s5-0 vector 3 quad) (the-as uint128 0))
(let
((s4-0
((method-of-type vector4s-3 new)
(the-as symbol (new 'stack-no-clear 'vector4s-3))
vector4s-3
)
)
(s3-0 (new 'stack-no-clear 'vector))
)
(set! (-> s3-0 quad) (the-as uint128 0))
(let
((s2-0
((method-of-type vector4s-3 new)
(the-as symbol (new 'stack-no-clear 'vector4s-3))
vector4s-3
)
)
)
(matrix*! s5-0 arg0 (-> *math-camera* camera-temp))
(matrix-3x3-inverse-transpose! gp-0 arg0)
(let ((v1-3 s3-0))
(set! (-> v1-3 x) 0.4)
(set! (-> v1-3 y) 0.4)
(set! (-> v1-3 z) 0.4)
(set! (-> v1-3 w) 1.0)
)
(let ((v1-4 (-> s4-0 data)))
(set! (-> v1-4 0) 1.0)
(set! (-> v1-4 1) 1.0)
(set! (-> v1-4 2) 1.0)
(set! (-> v1-4 3) 1.0)
)
(let ((v1-5 (&-> s4-0 data 4)))
(set! (-> v1-5 0) 0.0)
(set! (-> v1-5 1) 0.0)
(set! (-> v1-5 2) 0.0)
(set! (-> v1-5 3) 1.0)
)
(let ((v1-6 (&-> s4-0 data 8)))
(set! (-> v1-6 0) 0.0)
(set! (-> v1-6 1) 0.0)
(set! (-> v1-6 2) 0.0)
(set! (-> v1-6 3) 1.0)
)
(let ((v1-7 (-> s2-0 data)))
(set! (-> v1-7 0) 1.0)
(set! (-> v1-7 1) 0.0)
(set! (-> v1-7 2) 0.0)
(set! (-> v1-7 3) 1.0)
)
(let ((v1-8 (&-> s2-0 data 4)))
(set! (-> v1-8 0) 0.0)
(set! (-> v1-8 1) 1.0)
(set! (-> v1-8 2) 0.0)
(set! (-> v1-8 3) 1.0)
)
(let ((v1-9 (&-> s2-0 data 8)))
(set! (-> v1-9 0) 0.0)
(set! (-> v1-9 1) 0.0)
(set! (-> v1-9 2) 1.0)
(set! (-> v1-9 3) 1.0)
)
(.lvf vf7 (&-> *math-camera* hmge-scale quad))
(.lvf vf8 (&-> *math-camera* hvdf-off quad))
(.lvf vf9 (&-> *math-camera* giftex))
(let ((v1-13 255))
(.mov vf6 v1-13)
)
(.mov v1-14 vf6)
(.itof.vf vf6 vf6)
(.lvf vf1 (&-> s5-0 vector 0 quad))
(.lvf vf2 (&-> s5-0 vector 1 quad))
(.lvf vf3 (&-> s5-0 vector 2 quad))
(.lvf vf4 (&-> s5-0 vector 3 quad))
(.lvf vf17 (&-> gp-0 vector 0 quad))
(.lvf vf18 (&-> gp-0 vector 1 quad))
(.lvf vf19 (&-> gp-0 vector 2 quad))
(.lvf vf23 (&-> s2-0 quad 0))
(.lvf vf24 (&-> s2-0 quad 1))
(.lvf vf25 (&-> s2-0 quad 2))
)
(.lvf vf27 (&-> s4-0 quad 0))
(.lvf vf28 (&-> s4-0 quad 1))
(.lvf vf29 (&-> s4-0 quad 2))
(.lvf vf26 (&-> s3-0 quad))
)
)
)
(none)
)
)
@@ -46,7 +46,7 @@
)
;; definition for symbol *default-lights*, type vu-lights
(define *default-lights* (the-as vu-lights (new 'global 'vu-lights)))
(define *default-lights* (new 'global 'vu-lights))
;; definition for function vu-lights-default!
(defun vu-lights-default! ((arg0 vu-lights))
@@ -94,7 +94,3 @@
)
arg0
)
@@ -60,9 +60,7 @@
)
(set! (-> *wind-work* wind-force s4-0) f0-5)
(let ((v1-14 (-> *wind-work* wind-array s4-0)))
(let ((a0-15 (-> arg0 wind-normal)))
(.lvf vf1 (&-> a0-15 quad))
)
(.lvf vf1 (&-> (-> arg0 wind-normal) quad))
(let ((a0-16 f0-5))
(.mov vf2 a0-16)
)
@@ -76,7 +74,3 @@
(none)
)
)
@@ -85,7 +85,7 @@
)
;; definition for symbol *identity-matrix*, type matrix
(define *identity-matrix* (the-as matrix (new 'global 'matrix)))
(define *identity-matrix* (new 'global 'matrix))
;; failed to figure out what this is:
(matrix-identity! *identity-matrix*)
@@ -254,12 +254,8 @@
)
(.lvf vf1 (&-> arg1 quad))
(.mul.vf vf3 vf1 vf1)
(let ((v1-0 *sin-poly-vec2*))
(.lvf vf10 (&-> v1-0 quad))
)
(let ((v1-1 *sin-poly-vec*))
(.lvf vf9 (&-> v1-1 quad))
)
(.lvf vf10 (&-> *sin-poly-vec2* quad))
(.lvf vf9 (&-> *sin-poly-vec* quad))
(.mul.vf vf4 vf3 vf1)
(.mul.vf vf5 vf3 vf3)
(.mul.x.vf acc vf1 vf10)
@@ -329,9 +325,7 @@
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(.lvf vf1 (&-> arg1 quad))
(.sub.vf vf2 vf2 vf2)
(let ((v1-0 *cos-poly-vec*))
(.lvf vf9 (&-> v1-0 quad))
)
(.lvf vf9 (&-> *cos-poly-vec* quad))
(.mul.vf vf3 vf1 vf1)
(.add.w.vf acc vf2 vf0)
(.mul.vf vf4 vf3 vf3)
@@ -369,16 +363,10 @@
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(.lvf vf1 (&-> arg2 quad))
(.sub.vf vf14 vf14 vf14)
(let ((v1-0 *sin-poly-vec2*))
(.lvf vf11 (&-> v1-0 quad))
)
(.lvf vf11 (&-> *sin-poly-vec2* quad))
(.mul.vf vf2 vf1 vf1)
(let ((v1-1 *sin-poly-vec*))
(.lvf vf10 (&-> v1-1 quad))
)
(let ((v1-2 *cos-poly-vec*))
(.lvf vf13 (&-> v1-2 quad))
)
(.lvf vf10 (&-> *sin-poly-vec* quad))
(.lvf vf13 (&-> *cos-poly-vec* quad))
(.mul.x.vf acc vf1 vf11)
(.mul.vf vf3 vf2 vf1)
(.mul.vf vf4 vf2 vf2)
@@ -850,7 +838,3 @@
)
)
)
@@ -52,7 +52,7 @@
)
;; definition for symbol *common-text-heap*, type kheap
(define *common-text-heap* (the-as kheap (new 'global 'kheap)))
(define *common-text-heap* (new 'global 'kheap))
;; definition for symbol *common-text*, type symbol
(define *common-text* #f)
@@ -60,4 +60,3 @@
;; failed to figure out what this is:
(let ((v0-3 0))
)
@@ -479,9 +479,7 @@
(set! (-> obj y-max) (* 0.5 arg3))
(set! (-> obj start-time) (the-as uint 0))
(set! (-> obj timer) 0)
(let ((v1-0 (-> obj value)))
(.svf (&-> v1-0 quad) vf0)
)
(.svf (&-> (-> obj value) quad) vf0)
(-> obj value)
)
)
@@ -521,18 +519,13 @@
(defmethod dummy-12 delayed-rand-vector ((obj delayed-rand-vector))
(rlet ((vf0 :class vf))
(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0))
(cond
((>=
(the-as int (- (-> *display* base-frame-counter) (-> obj start-time)))
(-> obj timer)
)
((method-of-type delayed-rand-vector dummy-10) obj)
)
(else
(let ((v1-5 (-> obj value)))
(.svf (&-> v1-5 quad) vf0)
)
(if
(>=
(the-as int (- (-> *display* base-frame-counter) (-> obj start-time)))
(-> obj timer)
)
((method-of-type delayed-rand-vector dummy-10) obj)
(.svf (&-> (-> obj value) quad) vf0)
)
(-> obj value)
)
@@ -561,17 +554,11 @@
)
)
(else
(let ((v1-2 (-> obj value)))
(.svf (&-> v1-2 quad) vf0)
)
(let ((v1-3 (-> obj target)))
(.svf (&-> v1-3 quad) vf0)
)
(.svf (&-> (-> obj value) quad) vf0)
(.svf (&-> (-> obj target) quad) vf0)
)
)
(let ((v1-4 (-> obj vel)))
(.svf (&-> v1-4 quad) vf0)
)
(.svf (&-> (-> obj vel) quad) vf0)
(set! (-> obj max-vel) arg2)
(set! (-> obj damping) arg3)
(set! (-> obj accel) arg1)
+4 -1
View File
@@ -15,7 +15,7 @@ namespace {
// list of object files to ignore during reference checks
const std::unordered_set<std::string> g_object_files_to_ignore_ref_checks = {
"pskernel", "geometry", "math-camera", "timer", "texture",
"pskernel", "geometry", "timer", "texture",
"ocean-tables", "ocean-frames", "time-of-day", "display"};
const std::unordered_set<std::string> g_object_files_to_ignore_decompiling = {
@@ -123,6 +123,9 @@ const std::unordered_set<std::string> skip_in_compiling = {
// gs
"(method 3 gif-tag)", // inspect for a 128-bit type.
// math camera
"transform-point-vector!", "transform-point-qword!", "transform-point-vector-scale!",
// display-h
"put-draw-env",