mirror of
https://github.com/open-goal/jak-project
synced 2026-08-09 02:49:19 -04:00
d1ece445d4
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.
166 lines
5.2 KiB
Common Lisp
166 lines
5.2 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
(bundles "ENGINE.CGO" "GAME.CGO")
|
|
|
|
(require "engine/draw/drawable-h.gc")
|
|
(require "engine/game/main-h.gc")
|
|
(require "engine/entity/actor-link-h.gc")
|
|
|
|
;; name: path-h.gc
|
|
;; name in dgo: path-h
|
|
;; dgos: GAME, ENGINE
|
|
|
|
(defenum path-control-flag
|
|
:bitfield #t
|
|
:type uint32
|
|
(display 0)
|
|
(draw-line 1) ;; TODO - only seen it used to control debug drawing so far
|
|
(draw-point 2) ;; TODO - only seen it used to control debug drawing so far
|
|
(draw-text 3) ;; TODO - only seen it used to control debug drawing so far
|
|
(not-found 4)
|
|
)
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
;; A path-control is a curve that can be loaded from res-lump/entities.
|
|
(deftype path-control (basic)
|
|
((flags path-control-flag)
|
|
(name symbol)
|
|
(process process-drawable)
|
|
(curve curve :inline)
|
|
(num-cverts int32 :overlay-at (-> curve num-cverts))
|
|
(cverts (inline-array vector) :overlay-at (-> curve cverts))
|
|
)
|
|
(:methods
|
|
(new (symbol type process symbol float) _type_)
|
|
(debug-draw (_type_) none)
|
|
(eval-path-curve-div! (_type_ vector float symbol) vector)
|
|
(get-random-point (_type_ vector) vector)
|
|
(path-control-method-12 (_type_ vector float) vector)
|
|
(eval-path-curve! (_type_ vector float symbol) vector)
|
|
(path-control-method-14 (_type_ vector float) vector)
|
|
(length-as-float (_type_) float)
|
|
(path-distance (_type_) float)
|
|
(get-num-verts (_type_) int)
|
|
(should-display? (_type_) symbol)
|
|
(path-control-method-19 (_type_) float)
|
|
(path-control-method-20 (_type_) float)
|
|
)
|
|
)
|
|
|
|
;; A curve-control is very similar, but also gets knots.
|
|
(deftype curve-control (path-control)
|
|
()
|
|
(:methods
|
|
(new (symbol type process symbol float) _type_)
|
|
)
|
|
)
|
|
|
|
|
|
(defmethod new path-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
|
|
(local-vars (tag res-tag))
|
|
(let ((this (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
|
|
|
|
(when (zero? this)
|
|
;; allocation failed.
|
|
(go process-drawable-art-error "memory")
|
|
(set! this (the-as path-control 0))
|
|
(goto cfg-9)
|
|
)
|
|
|
|
(set! (-> this process) (the-as process-drawable proc))
|
|
(set! (-> this name) name)
|
|
(let ((ent (-> proc entity)))
|
|
(when (= name 'path)
|
|
;; if we are a path, try to look up the path-actor.
|
|
(let ((lookup-entity (entity-actor-lookup (the-as res-lump ent) 'path-actor 0)))
|
|
(if lookup-entity
|
|
(set! ent lookup-entity)
|
|
)
|
|
)
|
|
)
|
|
|
|
;; look up the curve data
|
|
(set! tag (new 'static 'res-tag))
|
|
(let ((data (res-lump-data ent name pointer :tag-ptr (& tag) :time time)))
|
|
(cond
|
|
(data
|
|
;; success, we got some data
|
|
(set! (-> this cverts) (the-as (inline-array vector) data))
|
|
(set! (-> this curve num-cverts) (the-as int (-> tag elt-count)))
|
|
)
|
|
(else
|
|
;; did not find the data. Set flags and zero stuff
|
|
(logior! (-> this flags) (path-control-flag not-found))
|
|
(set! (-> this cverts) (the-as (inline-array vector) #f))
|
|
(set! (-> this curve num-cverts) 0)
|
|
0
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(label cfg-9)
|
|
(the-as path-control this)
|
|
)
|
|
)
|
|
|
|
(defmethod should-display? ((this path-control))
|
|
"Should we display path marks?"
|
|
(and *display-path-marks* (logtest? (-> this flags) (path-control-flag display)))
|
|
)
|
|
|
|
(defmethod length-as-float ((this path-control))
|
|
"Get the number of edges as a float"
|
|
(the float (+ (-> this curve num-cverts) -1))
|
|
)
|
|
|
|
(defmethod get-num-verts ((this path-control))
|
|
"Get the number of vertices"
|
|
(-> this curve num-cverts)
|
|
)
|
|
|
|
(defmethod new curve-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
|
|
(let ((this (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
|
|
(set! (-> this process) (the-as process-drawable proc))
|
|
(set! (-> this name) name)
|
|
(let* ((ent (-> proc entity))
|
|
(v1-2 name)
|
|
(s2-0 (cond
|
|
((= v1-2 'path)
|
|
'path-k ;; for knots?
|
|
)
|
|
(else
|
|
;; appends a -k to the symbol name.
|
|
(let ((s2-1 string->symbol))
|
|
(format (clear *temp-string*) "~A-k" name)
|
|
(s2-1 *temp-string*)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
(let ((lookup-entity (entity-actor-lookup ent 'path-actor 0)))
|
|
(if lookup-entity
|
|
(set! ent lookup-entity)
|
|
)
|
|
)
|
|
(when (not (get-curve-data! ent (-> this curve) name s2-0 time))
|
|
(cond
|
|
((> (-> this curve num-cverts) 0)
|
|
;; downgrade us to a path-control, we got cverts but no knots.
|
|
(set! (-> this type) path-control)
|
|
)
|
|
(else
|
|
;; couldn't get anything, mark as bad.
|
|
(logior! (-> this flags) (path-control-flag not-found))
|
|
(set! (-> this cverts) (the-as (inline-array vector) #f))
|
|
(set! (-> this curve num-cverts) 0)
|
|
0
|
|
)
|
|
)
|
|
)
|
|
)
|
|
this
|
|
)
|
|
)
|