Files
jak-project/goal_src/jak1/engine/math/transformq-h.gc
T
Tyler Wilding d1ece445d4 Dependency graph work - Part 1 - Preliminary work (#3505)
Relates to #1353 

This adds no new functionality or overhead to the compiler, yet. This is
the preliminary work that has:
- added code to the compiler in several spots to flag when something is
used without being properly required/imported/whatever (disabled by
default)
- that was used to generate project wide file dependencies (some
circulars were manually fixed)
- then that graph underwent a transitive reduction and the result was
written to all `jak1` source files.

The next step will be making this actually produce and use a dependency
graph. Some of the reasons why I'm working on this:
- eliminates more `game.gp` boilerplate. This includes the `.gd` files
to some extent (`*-ag` files and `tpage` files will still need to be
handled) this is the point of the new `bundles` form. This should make
it even easier to add a new file into the source tree.
- a build order that is actually informed from something real and
compiler warnings that tell you when you are using something that won't
be available at build time.
- narrows the search space for doing LSP actions -- like searching for
references. Since it would be way too much work to store in the compiler
every location where every symbol/function/etc is used, I have to do
ad-hoc searches. By having a dependency graph i can significantly reduce
that search space.
- opens the doors for common shared code with a legitimate pattern.
Right now jak 2 shares code from the jak 1 folder. This is basically a
hack -- but by having an explicit require syntax, it would be possible
to reference arbitrary file paths, such as a `common` folder.

Some stats:
- Jak 1 has about 2500 edges between files, including transitives
- With transitives reduced at the source code level, each file seems to
have a modest amount of explicit requirements.

Known issues:
- Tracking the location for where `defmacro`s and virtual state
definitions were defined (and therefore the file) is still problematic.
Because those forms are in a macro environment, the reader does not
track them. I'm wondering if a workaround could be to search the
reader's text_db by not just the `goos::Object` but by the text
position. But for the purposes of finishing this work, I just statically
analyzed and searched the code with throwaway python code.
2024-05-12 12:37:59 -04:00

83 lines
3.6 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "ENGINE.CGO" "GAME.CGO")
(require "engine/math/quaternion-h.gc")
(require "engine/math/vector-h.gc")
(require "engine/math/transform-h.gc")
;; name: transformq-h.gc
;; name in dgo: transformq-h
;; dgos: GAME, ENGINE
;; DECOMP BEGINS
;; the transformq is a transform, but _replaces_ the rotation field with a quaternion.
;; it is much more commonly used than transform.
(deftype transformq (transform)
;; this overlays the rot field of transform.
((quat quaternion :inline :overlay-at (-> rot x))
)
)
;; trsq is the quaternion version of trs (trs is like a transform, but is basic.)
(deftype trsq (trs)
;; this overlays the rot field of trs.
((quat quaternion :inline :overlay-at (-> rot x))
)
)
;; Representing a translate/rotate/scale with a quaternion and a velocity.
;; This is often used as the base type for the position of a game object that can move around
;; so it has methods to do common control functions.
;; many of these functions assume that y is up and assume that roll/pitch is small
;; (a reasonable assumption for most in-game objects that don't do flips)
;; note: Jak's control uses this as a base class.
(deftype trsqv (trsq)
((pause-adjust-distance meters :offset 4) ;; hack: adjusts the distance where actor logic is paused, if this is an actor
(nav-radius meters :offset 8) ;; hack: the radius of the bounding sphere used by the navigate system.
(transv vector :inline) ;; velocity (meters/second)
(rotv vector :inline) ;; angular velocity (deg/second)
(scalev vector :inline) ;; scale velocity (unused?)
;; there's a hacky ~first-order orientation yaw control with hysteresis
;; it makes the yaw change smoothly and attempts to cancel out oscillations from the collision system
(dir-targ quaternion :inline) ;; direction target
(angle-change-time time-frame) ;; the time when we change rotation directions
(old-y-angle-diff float) ;; the amount we moved last time
)
(:methods
(seek-toward-heading-vec! (_type_ vector float time-frame) quaternion)
(set-heading-vec! (_type_ vector) quaternion)
(seek-to-point-toward-point! (_type_ vector float time-frame) quaternion)
(point-toward-point! (_type_ vector) quaternion)
(seek-toward-yaw-angle! (_type_ float float time-frame) quaternion)
(set-yaw-angle-clear-roll-pitch! (_type_ float) quaternion)
(set-roll-to-grav! (_type_ float) quaternion)
(set-roll-to-grav-2! (_type_ float) quaternion)
(rotate-toward-orientation! (_type_ quaternion float float) quaternion)
(set-quaternion! (_type_ quaternion) quaternion)
(set-heading-vec-clear-roll-pitch! (_type_ vector) quaternion)
(point-toward-point-clear-roll-pitch! (_type_ vector) quaternion)
(rot->dir-targ! (_type_) quaternion)
(y-angle (_type_) float)
(global-y-angle-to-point (_type_ vector) float)
(relative-y-angle-to-point (_type_ vector) float)
(roll-relative-to-gravity (_type_) float)
(set-and-limit-velocity (_type_ int vector float) trsqv)
(get-quaternion (_type_) quaternion)
)
)
(defmethod global-y-angle-to-point ((this trsqv) (arg0 vector))
"Get the angle in the xz plane from the position of this trsqv to the point arg0."
(vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans)))
)
(defmethod relative-y-angle-to-point ((this trsqv) (arg0 vector))
"Get the y angle between the current orientation and arg0."
(deg-diff (y-angle this) (vector-y-angle (vector-! (new 'stack-no-clear 'vector) arg0 (-> this trans))))
)