Files
jak-project/goal_src/jak1/engine/common-obs/orb-cache.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

344 lines
12 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
(bundles "GAME.CGO")
(require "engine/common-obs/collectables.gc")
(require "engine/common-obs/baseplat.gc")
;; name: orb-cache.gc
;; name in dgo: orb-cache
;; dgos: GAME, COMMON, L1
;; DECOMP BEGINS
(deftype orb-cache-top (baseplat)
((active-distance float)
(inactive-distance float)
(money-list handle 60)
(money-pos-list float 60)
(money-pos-actual float 60)
(platform-pos float)
(root-pos float)
(money int32)
(activated symbol)
)
(:methods
(pos-logic (_type_ symbol) symbol)
(calculate-pos (_type_ symbol) none)
)
(:states
(orb-cache-top-activate symbol)
(orb-cache-top-complete symbol)
(orb-cache-top-idle symbol)
)
)
(defskelgroup *orb-cache-top-sg* orb-cache-top orb-cache-top-lod0-jg orb-cache-top-idle-ja
((orb-cache-top-lod0-mg (meters 20)) (orb-cache-top-lod1-mg (meters 999999)))
:bounds (static-spherem 0 0 0 4)
)
(defstate orb-cache-top-idle (orb-cache-top)
:event (behavior ((proc process) (argc int) (message symbol) (block event-message-block))
(case message
(('eco-blue)
(process-entity-status! self (entity-perm-status complete) #t)
(dotimes (gp-0 5)
(spawn-projectile-blue *target*)
)
(increment-success-for-hint (text-id sidekick-hint-orb-cache-top))
(go orb-cache-top-activate #f)
)
(else
(plat-event proc argc message block)
)
)
)
:trans (behavior ()
(if (and (and *target* (>= 20480.0 (vector-vector-distance (-> self root trans) (-> *target* control trans))))
(not (send-event *target* 'query 'powerup (pickup-type eco-blue)))
)
(level-hint-spawn
(text-id sidekick-hint-orb-cache-top)
"sksp0009"
(the-as entity #f)
*entity-pool*
(game-task none)
)
)
)
:code (behavior ((arg0 symbol))
(if (and (not arg0) (-> self child))
(sound-play "close-orb-cash")
)
(dotimes (gp-1 (-> self money))
(let ((a0-4 (handle->process (-> self money-list gp-1))))
(if a0-4
(deactivate a0-4)
)
)
)
(process-entity-status! self (entity-perm-status complete) #f)
(ja :group! orb-cache-top-idle-ja :num! (identity (ja-aframe 0.0 0)))
(transform-post)
(anim-loop)
)
)
(defmethod baseplat-method-22 ((this orb-cache-top))
(if (< 4096.0 (- (-> this basetrans y) (-> this root-pos)))
(activate! (-> this smush) -1.0 60 150 1.0 1.0)
(activate! (-> this smush) -0.5 60 150 1.0 1.0)
)
(set! (-> this bouncing) #t)
(logclear! (-> this mask) (process-mask sleep))
0
(none)
)
(defmethod calculate-pos ((this orb-cache-top) (arg0 symbol))
(let ((f0-0 0.0))
(when arg0
(set! f0-0 (+ 10240.0 (* 6144.0 (the float (+ (-> this money) -1)))))
(if (< f0-0 2048.0)
(set! f0-0 2048.0)
)
)
(set! (-> this platform-pos) (+ (-> this root-pos) f0-0))
(let ((f0-2 (+ -6144.0 f0-0)))
(dotimes (v1-5 (-> this money))
(set! (-> this money-pos-list v1-5) (+ (-> this root-pos) f0-2))
(set! f0-2 (+ -6144.0 f0-2))
)
)
)
0
(none)
)
(defmethod pos-logic ((this orb-cache-top) (arg0 symbol))
(dotimes (s4-0 (-> this money))
(when (not (handle->process (-> this money-list s4-0)))
(dotimes (v1-6 (-> this money))
(when (< s4-0 v1-6)
(set! (-> this money-list (+ v1-6 -1)) (-> this money-list v1-6))
(set! (-> this money-pos-actual (+ v1-6 -1)) (-> this money-pos-actual v1-6))
)
)
(+! (-> this money) -1)
(calculate-pos this arg0)
(+! s4-0 -1)
(let ((v1-15 (-> this entity extra perm)))
(logior! (-> v1-15 status) (entity-perm-status user-set-from-cstage))
(+! (-> v1-15 user-int16 0) 1)
)
)
)
(let ((s4-1 (new 'stack-no-clear 'vector))
(s5-1 #t)
)
(let ((s3-0 #f))
(let ((f28-0 (- (-> this basetrans y) (-> this root-pos)))
(f30-0 (- (-> this platform-pos) (-> this root-pos)))
)
(when (zero? (-> this money))
(set! f30-0 2048.0)
(set! s3-0 #t)
)
(when (and (< f30-0 15155.2)
(and *target* (>= 16384.0 (vector-vector-distance (-> this root trans) (-> *target* control trans))))
(< (-> (target-pos 0) y) (-> this basetrans y))
)
(set! f30-0 (if (< 14131.2 f28-0)
15155.2
f28-0
)
)
(set! s3-0 #f)
)
(seek! (-> this basetrans y) (+ (-> this root-pos) f30-0) (* 40960.0 (seconds-per-frame)))
(if (not (= (-> this basetrans y) (+ (-> this root-pos) f30-0)))
(set! s5-1 #f)
)
)
(dotimes (s2-0 (-> this money))
(set! (-> s4-1 quad)
(-> (the-as process-drawable (handle->process (-> this money-list s2-0))) root trans quad)
)
(seek! (-> this money-pos-actual s2-0) (-> this money-pos-list s2-0) (* 40960.0 (seconds-per-frame)))
(if (not (= (-> this money-pos-actual s2-0) (-> this money-pos-list s2-0)))
(set! s5-1 #f)
)
(if (>= (-> this money-pos-actual s2-0) (+ -8192.0 (-> this root-pos)))
(set! (-> s4-1 y) (-> this money-pos-actual s2-0))
(set! (-> s4-1 y) (+ -8192.0 (-> this root-pos)))
)
(send-event (handle->process (-> this money-list s2-0)) 'trans s4-1)
)
(set! s3-0 (and s5-1 s3-0))
(if s3-0
(go orb-cache-top-complete #f)
)
)
s5-1
)
)
(defstate orb-cache-top-activate (orb-cache-top)
:event plat-event
:exit (behavior ()
(process-entity-status! self (entity-perm-status bit-3) #f)
)
:trans plat-trans
:code (behavior ((arg0 symbol))
(process-entity-status! self (entity-perm-status bit-3) #t)
(calculate-pos self arg0)
(if arg0
(set! (-> self basetrans y) (-> self platform-pos))
(sound-play "open-orb-cash")
)
(dotimes (s5-1 (-> self money))
(let ((s4-1 (new 'stack-no-clear 'vector)))
(set! (-> s4-1 quad) (-> self basetrans quad))
(set! (-> s4-1 y) (-> self money-pos-list s5-1))
(set! (-> self money-pos-actual s5-1) (-> s4-1 y))
(set! (-> self money-list s5-1)
(ppointer->handle
(process-spawn money :init money-init-by-other-no-bob s4-1 *null-vector* 5 1.0 (-> self entity) :to self)
)
)
)
)
(loop
(calculate-pos self #t)
(while (not (or (not *target*)
(< (-> self inactive-distance) (vector-vector-xz-distance (-> self root trans) (-> *target* control trans)))
)
)
(pos-logic self #t)
(suspend)
)
(calculate-pos self #f)
(while (and (not (and (and *target*
(>= (-> self active-distance) (vector-vector-xz-distance (-> self root trans) (-> *target* control trans)))
)
(let ((a1-11 (new 'stack-no-clear 'event-message-block)))
(set! (-> a1-11 from) self)
(set! (-> a1-11 num-params) 2)
(set! (-> a1-11 message) 'query)
(set! (-> a1-11 param 0) (the-as uint 'powerup))
(set! (-> a1-11 param 1) (the-as uint 3))
(or (send-event-function *target* a1-11) (-> self activated))
)
)
)
(not (pos-logic self #f))
)
(suspend)
)
(if (not (and (and *target*
(>= (-> self active-distance) (vector-vector-xz-distance (-> self root trans) (-> *target* control trans)))
)
(let ((a1-14 (new 'stack-no-clear 'event-message-block)))
(set! (-> a1-14 from) self)
(set! (-> a1-14 num-params) 2)
(set! (-> a1-14 message) 'query)
(set! (-> a1-14 param 0) (the-as uint 'powerup))
(set! (-> a1-14 param 1) (the-as uint 3))
(or (send-event-function *target* a1-14) (-> self activated))
)
)
)
(go orb-cache-top-idle arg0)
)
)
)
:post plat-post
)
(defstate orb-cache-top-complete (orb-cache-top)
:event plat-event
:trans plat-trans
:code (behavior ((arg0 symbol))
(if (not arg0)
(sound-play "close-orb-cash")
)
(ja :group! orb-cache-top-idle-ja :num! (identity (ja-aframe 0.0 0)))
(new 'stack-no-clear 'vector)
(set! (-> self basetrans y) (+ 2048.0 (-> self root-pos)))
(anim-loop)
)
:post plat-post
)
(defmethod init-from-entity! ((this orb-cache-top) (arg0 entity-actor))
(let ((a0-1 (-> this entity)))
(if (when a0-1
(let ((a0-2 (-> a0-1 extra perm task)))
(if a0-2
(= a0-2 (game-task none))
)
)
)
(set! (-> this entity extra perm task) (game-task complete))
)
)
(let ((s4-0 (new 'process 'collide-shape-moving this (collide-list-enum hit-by-player))))
(set! (-> s4-0 dynam) (copy *standard-dynamics* 'process))
(set! (-> s4-0 reaction) default-collision-reaction)
(set! (-> s4-0 no-reaction)
(the-as (function collide-shape-moving collide-shape-intersect vector vector none) nothing)
)
(alloc-riders s4-0 1)
(let ((s3-0 (new 'process 'collide-shape-prim-mesh s4-0 (the-as uint 0) (the-as uint 0))))
(set! (-> s3-0 prim-core collide-as) (collide-kind ground-object blue-eco-suck))
(set! (-> s3-0 collide-with) (collide-kind target))
(set! (-> s3-0 prim-core action) (collide-action solid rider-plat-sticky))
(set! (-> s3-0 prim-core offense) (collide-offense indestructible))
(set! (-> s3-0 transform-index) 0)
(set-vector! (-> s3-0 local-sphere) 0.0 0.0 0.0 11468.8)
(set-root-prim! s4-0 s3-0)
)
(set! (-> s4-0 nav-radius) (* 0.75 (-> s4-0 root-prim local-sphere w)))
(backup-collide-with-as s4-0)
(set! (-> this root) s4-0)
)
(process-drawable-from-entity! this arg0)
(logclear! (-> this mask) (process-mask actor-pause))
(initialize-skeleton this *orb-cache-top-sg* '())
(logior! (-> this skel status) (janim-status inited))
(update-transforms! (-> this root))
(baseplat-method-21 this)
(set! (-> this money) (res-lump-value (-> this entity) 'orb-cache-count int :default (the-as uint128 20)))
(set! (-> this active-distance) 61440.0)
(set! (-> this inactive-distance) 245760.0)
(set! (-> this root-pos) (-> this basetrans y))
(set! (-> this platform-pos) (-> this root-pos))
(set! (-> this activated)
(the-as
symbol
(and (-> this entity) (logtest? (-> this entity extra perm status) (entity-perm-status complete)))
)
)
(let ((v1-39 (-> this entity extra perm)))
(logior! (-> v1-39 status) (entity-perm-status user-set-from-cstage))
(set! (-> this money) (- (-> this money) (-> v1-39 user-int16 0)))
)
(dotimes (v1-42 (-> this money))
(set! (-> this money-list v1-42) (the-as handle #f))
)
(cond
((zero? (-> this money))
(go orb-cache-top-complete #t)
)
((and (-> this entity) (logtest? (-> this entity extra perm status) (entity-perm-status complete)))
(go orb-cache-top-activate #t)
)
(else
(go orb-cache-top-idle #f)
)
)
(none)
)