Skip to content

Commit

Permalink
fix some entity decomp + improve battle hud to track specific tasks (#…
Browse files Browse the repository at this point in the history
…1455)

* entity decomp and update battle hud code

* disable lag compensation in pc port

* delete unnecessary forward decls

* make battle hud track specific tasks

* fix mem leak + debug flying-lurker hud

* improve battle hud lights and fix bug

* tests
  • Loading branch information
ManDude authored Jun 16, 2022
1 parent 5da5c29 commit 0e2320c
Show file tree
Hide file tree
Showing 109 changed files with 705 additions and 687 deletions.
83 changes: 41 additions & 42 deletions decompiler/config/all-types.gc

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions decompiler/config/jak1_ntsc_black_label/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,6 @@
],
"(method 12 art-group)": [[13, "a0", "art-joint-anim"]],
"(method 0 path-control)": [["_stack_", 16, "res-tag"]],
"(method 0 curve-control)": [[[13, 55], "s3", "entity"]],
"nav-mesh-connect": [
[[4, 15], "s2", "entity-actor"],
[19, "v1", "entity"],
[20, "v1", "entity-links"],
[72, "v1", "entity"],
[73, "v1", "entity-links"],
[76, "a0", "entity"],
[77, "a0", "entity-links"]
],
"add-debug-point": [
[125, "a3", "pointer"],
[[27, 144], "a0", "(pointer uint64)"],
Expand Down
1 change: 1 addition & 0 deletions goal_src/engine/data/art-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@

;; "art" is an overly general parent class of all art data.
;; it can be either a container of arts (art-group) or a single art (art-element)
(declare-type res-lump basic)
(deftype art (basic)
((name string :offset 8)
(length int32 :offset-assert 12)
Expand Down
2 changes: 1 addition & 1 deletion goal_src/engine/debug/viewer.gc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
#f
)

(defun birth-viewer ((arg0 process) (arg1 entity))
(defun birth-viewer ((arg0 process) (arg1 entity-actor))
(set! (-> arg0 type) viewer)
(let ((t9-0 init-entity))
viewer
Expand Down
109 changes: 39 additions & 70 deletions goal_src/engine/entity/actor-link-h.gc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
;; dgos: GAME, ENGINE

;; The exact details of actor-link-h are not yet understood, but this system caches lookups for entities/process.
;; Each entity has a res-lump. Some entities may reference other entities. This is done with an element in a res-lump
;; than contains named lists (possibly of size 1) of other entities. These lists may store entities by a name, or by an
;; Some entities may reference other entities. This is done with an element in a res-lump/entity that contains
;; named lists (possibly of size 1) of other entities. These lists may store entities by a name, or by an
;; actor id (AID).

;; This process is slow: it involves going from a process, to its entity, to doing a res-lump, deciding if you have an AID/string,
;; This process is slow: it involves going from a process, to its entity, to doing a lookup, deciding if you have an AID/string,
;; then looking up the other actor by name, or AID. Lookup by name is extremely slow, as it involves checking each actor's name
;; a res lookup per every actor in every level. Lookup by aid isn't bad, but is still a binary search through all actors.
;; per every actor in every level. Lookup by aid isn't bad, but is still a binary search through all actors.

;; The next-actor and prev-actor res build a linked list of actors.

Expand Down Expand Up @@ -95,12 +95,14 @@

(defmethod next-actor entity-actor ((obj entity-actor))
"Utility function to look up the next actor in the list, assuming we don't have actor-link-info yet."
(declare (inline))
;; look up reference to next-actor - this is slow.
(entity-actor-lookup obj 'next-actor 0)
)

(defmethod prev-actor entity-actor ((obj entity-actor))
"Look up previous actor in the list"
(declare (inline))
(entity-actor-lookup obj 'prev-actor 0)
)

Expand All @@ -110,15 +112,9 @@
(let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
(set! (-> obj process) proc)

;; set next (likely next-actor inlined)
(let ((ent (-> proc entity)))
(set! (-> obj next) (entity-actor-lookup (the-as res-lump ent) 'next-actor 0))
)

;; set prev (likely prev-actor inlined)
(let ((a0-2 (-> proc entity)))
(set! (-> obj prev) (entity-actor-lookup (the-as res-lump a0-2) 'prev-actor 0))
)
;; set next and prev
(set! (-> obj next) (next-actor (-> proc entity)))
(set! (-> obj prev) (prev-actor (-> proc entity)))
obj
)
)
Expand All @@ -139,30 +135,18 @@
(defmethod get-next-process actor-link-info ((obj actor-link-info))
"Get the process for the next, if it exists."
;; we can't easily get to the actor-link-info of the next, so we have to grab it from entity-links.
(the-as process
(and (-> obj next) (-> (the-as entity-links (-> obj next extra)) process))
)
(the-as process (and (-> obj next) (-> obj next extra process)))
)

(defmethod get-prev-process actor-link-info ((obj actor-link-info))
"Get the process for the prev, if it exists"
(the-as process
(and (-> obj prev) (-> (the-as entity-links (-> obj prev extra)) process))
)
(the-as process (and (-> obj prev) (-> obj prev extra process)))
)

(defmethod link-to-next-and-prev-actor actor-link-info ((obj actor-link-info))
"Redo the linking in the constructor by looking up the next/prev actor."
(let ((a0-1 (-> obj process entity)))
(set! (-> obj next)
(entity-actor-lookup (the-as res-lump a0-1) 'next-actor 0)
)
)
(let ((a0-2 (-> obj process entity)))
(set! (-> obj prev)
(entity-actor-lookup (the-as res-lump a0-2) 'prev-actor 0)
)
)
(set! (-> obj next) (next-actor (-> obj process entity)))
(set! (-> obj prev) (prev-actor (-> obj process entity)))
(-> obj next)
)

Expand All @@ -176,7 +160,7 @@
(if (arg0 s3-0 arg1)
(return (the-as int #f))
)
(set! s3-0 (entity-actor-lookup s3-0 'next-actor 0))
(set! s3-0 (next-actor s3-0))
)
)
0
Expand All @@ -191,33 +175,28 @@
(if (arg0 s3-0 arg1)
(return (the-as int #f))
)
(set! s3-0 (entity-actor-lookup s3-0 'prev-actor 0))
(set! s3-0 (prev-actor s3-0))
)
)
0
)

(defmethod apply-all actor-link-info
((obj actor-link-info) (arg0 (function entity-actor object object)) (arg1 object))
(defmethod apply-all actor-link-info ((obj actor-link-info) (arg0 (function entity-actor object object)) (arg1 object))
"Apply to all entities. Starts at the back and hits everyone, including this object."
;; start at us (next may give us #f here, so can't do that.)
(let ((s4-0 (-> obj process entity)))
;; while there is a prev...
(while (let ((a0-2 s4-0))
(entity-actor-lookup (the-as res-lump a0-2) 'prev-actor 0)
)
(while (prev-actor s4-0)
;; set prev (this is stupid, they do the slow lookup twice!)
(set! s4-0 (entity-actor-lookup (the-as res-lump s4-0) 'prev-actor 0))
(set! s4-0 (prev-actor s4-0))
)

;; now iterate forward.
(while s4-0
(if (arg0 (the-as entity-actor s4-0) arg1)
(if (arg0 s4-0 arg1)
(return (the-as int #f))
)
(let ((a0-4 s4-0))
(set! s4-0 (entity-actor-lookup (the-as res-lump a0-4) 'next-actor 0))
)
(set! s4-0 (next-actor s4-0))
)
)
0
Expand All @@ -229,11 +208,11 @@
(let ((iter (-> obj next))
(result (the object #f)))
(while iter
(let ((proc (-> (the entity-links (-> iter extra)) process)))
(let ((proc (-> iter extra process)))
(when proc
(set! result (or (send-event proc message) result))
)
(set! iter (entity-actor-lookup iter 'next-actor 0))
(set! iter (next-actor iter))
)
)
result
Expand All @@ -246,11 +225,11 @@
(let ((iter (-> obj prev))
(result (the object #f)))
(while iter
(let ((proc (-> (the entity-links (-> iter extra)) process)))
(let ((proc (-> iter extra process)))
(when proc
(set! result (or (send-event proc message) result))
)
(set! iter (entity-actor-lookup iter 'prev-actor 0))
(set! iter (prev-actor iter))
)
)
result
Expand All @@ -264,7 +243,7 @@
;; do we have a next?
(when a0-1
;; get the actual process
(let ((a0-2 (-> (the-as entity-links (-> a0-1 extra)) process)))
(let ((a0-2 (-> a0-1 extra process)))
;; do we have a process?
(when a0-2
(send-event a0-2 message)
Expand All @@ -280,7 +259,7 @@

(let ((a0-1 (-> obj prev)))
(when a0-1
(let ((a0-2 (-> (the-as entity-links (-> a0-1 extra)) process)))
(let ((a0-2 (-> a0-1 extra process)))
(when a0-2
(send-event a0-2 message)
)
Expand Down Expand Up @@ -310,17 +289,13 @@
(count 0)
)
;; get back to the beginning.
(while (let ((a0-2 actor))
(entity-actor-lookup (the-as res-lump a0-2) 'prev-actor 0)
)
(set! actor (entity-actor-lookup (the-as res-lump actor) 'prev-actor 0))
(while (prev-actor actor)
(set! actor (prev-actor actor))
)
;; iterate and set the count
(while actor
(+! count 1)
(let ((a0-3 actor))
(set! actor (entity-actor-lookup (the-as res-lump a0-3) 'next-actor 0))
)
(set! actor (next-actor actor))
)
count
)
Expand All @@ -335,8 +310,8 @@
(let ((current-bit 1))

;; seek to beginning
(while (let ((a0-2 actor)) (entity-actor-lookup a0-2 'prev-actor 0))
(set! actor (entity-actor-lookup actor 'prev-actor 0))
(while (prev-actor actor)
(set! actor (prev-actor actor))
)

;; loop over actors
Expand All @@ -346,11 +321,9 @@
(set! mask (logior mask current-bit))
)
;; next
(let ((a0-3 actor))
(set! actor (entity-actor-lookup a0-3 'next-actor 0))
)
(set! actor (next-actor actor))
;; next bit
(set! current-bit (* current-bit 2))
(set! current-bit (ash current-bit 1))
)
)
mask
Expand All @@ -364,17 +337,13 @@
(count 0)
)
;; go to beginning (why not count here???)
(while (let ((a0-2 actor))
(entity-actor-lookup (the-as res-lump a0-2) 'prev-actor 0)
)
(set! actor (entity-actor-lookup (the-as res-lump actor) 'prev-actor 0))
(while (prev-actor actor)
(set! actor (prev-actor actor))
)
;; go forward, until we hit this actor
(while (!= actor this-actor)
(+! count 1)
(let ((a0-3 actor))
(set! actor (entity-actor-lookup (the-as res-lump a0-3) 'next-actor 0))
)
(set! actor (next-actor actor))
)
count
)
Expand All @@ -383,7 +352,7 @@
(defun actor-link-subtask-complete-hook ((arg0 entity-actor) (arg1 (pointer symbol)))
"Sets arg1 if the thing is complete. Does not continue the apply if the complete perm is set."
(cond
((logtest? (-> (the-as entity-links (-> arg0 extra)) perm status) (entity-perm-status complete))
((logtest? (-> arg0 extra perm status) (entity-perm-status complete))
(set! (-> arg1 0) #t)
#f
)
Expand All @@ -397,7 +366,7 @@
(defun actor-link-dead-hook ((arg0 entity-actor) (arg1 (pointer symbol)))
"Sets arg1 is the thing is dead. Does not continue the apply if the dead perm is set."
(cond
((logtest? (-> (the-as entity-links (-> arg0 extra)) perm status) (entity-perm-status dead))
((logtest? (-> arg0 extra perm status) (entity-perm-status dead))
(set! (-> arg1 0) #t)
#f
)
Expand All @@ -419,7 +388,7 @@
;; look up the alt actor
(let ((a0-3 (entity-actor-lookup (the-as res-lump (-> arg0 entity)) 'alt-actor alt-actor-idx)))
(if (or (not a0-3)
(zero? (logand (-> (the-as entity-links (-> a0-3 extra)) perm status) (entity-perm-status complete)))
(zero? (logand (-> a0-3 extra perm status) (entity-perm-status complete)))
)
(+! incomplete-count 1)
)
Expand Down
14 changes: 9 additions & 5 deletions goal_src/engine/entity/entity.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@
;;`(empty)
)

(defun init-entity ((proc process) (ent entity))
(defun init-entity ((proc process) (ent entity-actor))
"This function starts up an entity!
The process should not be activated yet."

Expand All @@ -1241,7 +1241,7 @@


;; TODO
(define-extern birth-viewer (function process entity object))
(define-extern birth-viewer (function process entity-actor object))

(defmacro obj-etype? (&rest types)
`(or ,@(apply (lambda (x) `(begin (define-extern ,x type) (type-type? (-> obj etype) ,x))) types))
Expand Down Expand Up @@ -1297,7 +1297,7 @@
obj
)

(defun entity-deactivate-handler ((arg0 process) (arg1 entity))
(defun entity-deactivate-handler ((arg0 process) (arg1 entity-actor))
"Handle a deactivation in the entity.
The entity directly stores a process so it should remove that after deactivating."
(when (= arg0 (-> arg1 extra process))
Expand Down Expand Up @@ -1650,8 +1650,12 @@
)
)
(when (not (paused?))
(let ((s5-1 (-> *display* frames (-> *display* last-screen) frame run-time)))
(let ((f0-5 (fmax 327680.0 (fmin (+ 327680.0 (* 204.8 (the float (- 7000 s5-1)))) (-> *ACTOR-bank* birth-dist)))))
;; NOTE : get rid of lag compensation in PC port, it's not helpful
(let ((s5-1 (#if PC_PORT
0
(-> *display* frames (-> *display* last-screen) frame run-time)
)))
(let ((f0-5 (fmax (meters 80) (fmin (+ (meters 80) (* (meters 0.05) (the float (- 7000 s5-1)))) (-> *ACTOR-bank* birth-dist)))))
(seek! (-> *ACTOR-bank* pause-dist) f0-5 (* 81920.0 (-> *display* seconds-per-frame)))
)
(seekl! (-> *ACTOR-bank* birth-max) (the int (lerp-scale 25.0 1.0 (the float s5-1) 2000.0 7000.0)) 10)
Expand Down
Loading

0 comments on commit 0e2320c

Please sign in to comment.