mirror of
https://github.com/open-goal/jak-project
synced 2026-08-20 22:35:07 -04:00
159 lines
6.0 KiB
Common Lisp
159 lines
6.0 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
(bundles "ENGINE.CGO" "GAME.CGO")
|
|
(require "engine/entity/res-h.gc")
|
|
(require "kernel/gcommon.gc")
|
|
(require "engine/util/types-h.gc")
|
|
|
|
;; Level data contains a list of "entity" objects.
|
|
;; An entity-actor tells the game engine to spawn a process of a certain type with
|
|
;; certain parameters.
|
|
;; An entity-camera is a region with predefined camera setings
|
|
;; An entity-ambient is a region with some game setting like music/rendering changes.
|
|
|
|
(defun-extern entity-by-name string entity)
|
|
(defun-extern entity-by-type type entity-actor)
|
|
(defun-extern entity-by-aid uint entity)
|
|
|
|
(define-extern reset-actors (function symbol none))
|
|
(define-extern *spawn-actors* symbol)
|
|
(define-extern reset-cameras (function none))
|
|
(define-extern process-by-ename (function string process))
|
|
(define-extern entity-birth-no-kill (function entity none))
|
|
|
|
;; DECOMP BEGINS
|
|
|
|
;; toggles for generating actor visibility data.
|
|
;; a somewhat broken feature for computing the bounding box of where an actor can
|
|
;; be based on watching where it goes.
|
|
(define *generate-actor-vis* #f)
|
|
(define *generate-actor-vis-start* #f)
|
|
(define *generate-actor-vis-output* #f)
|
|
|
|
;; Sixteen bytes of persistent per-entity state.
|
|
;; The first 8 are user-defined, and the last 8 have shared meanings.
|
|
(deftype entity-perm (structure)
|
|
((user-object object 2)
|
|
(user-uint64 uint64 :overlay-at (-> user-object 0))
|
|
(user-float float 2 :overlay-at (-> user-object 0))
|
|
(user-int32 int32 2 :overlay-at (-> user-object 0))
|
|
(user-uint32 uint32 2 :overlay-at (-> user-object 0))
|
|
(user-int16 int16 4 :overlay-at (-> user-object 0))
|
|
(user-uint16 uint16 4 :overlay-at (-> user-object 0))
|
|
(user-int8 int8 8 :overlay-at (-> user-object 0))
|
|
(user-uint8 uint8 8 :overlay-at (-> user-object 0))
|
|
(status entity-perm-status)
|
|
(dummy uint8 1)
|
|
(task game-task)
|
|
(aid actor-id)
|
|
(quad uint128 :overlay-at (-> user-object 0)))
|
|
:pack-me
|
|
(:methods
|
|
(update-perm! (_type_ symbol entity-perm-status) _type_)))
|
|
|
|
;; Runtime link between a static entity resource and its live process.
|
|
;; prev-link and next-link iterate through the links in a level's entity list.
|
|
(deftype entity-links (structure)
|
|
((prev-link entity-links)
|
|
(next-link entity-links)
|
|
(entity entity)
|
|
(process process)
|
|
(level level)
|
|
(vis-id int32)
|
|
(trans vector :inline)
|
|
(perm entity-perm :inline)
|
|
(status uint16 :overlay-at (-> perm status))
|
|
(aid actor-id :overlay-at (-> perm aid))
|
|
(task game-task :overlay-at (-> perm task)))
|
|
(:methods
|
|
(birth? (_type_ vector) symbol)))
|
|
|
|
(deftype entity-perm-array (inline-array-class)
|
|
((data entity-perm :inline :dynamic)))
|
|
|
|
(set! (-> entity-perm-array heap-base) (the-as uint 16))
|
|
|
|
(deftype entity-links-array (inline-array-class)
|
|
((data entity-links :inline :dynamic)))
|
|
|
|
(set! (-> entity-links-array heap-base) (the-as uint 64))
|
|
|
|
;; Base placed entity: resource data plus its world position and actor id.
|
|
(deftype entity (res-lump)
|
|
((trans vector :inline)
|
|
(aid uint32))
|
|
(:methods
|
|
(birth! (_type_) _type_)
|
|
(kill! (_type_) _type_)
|
|
(add-to-level! (_type_ level-group level actor-id) none)
|
|
(remove-from-level! (_type_ level-group) _type_)
|
|
(get-level (_type_) level)))
|
|
|
|
(deftype entity-camera (entity)
|
|
((quat quaternion :inline)))
|
|
|
|
;; ambient parameters, very flexible.
|
|
(deftype entity-ambient-data (structure)
|
|
((user-object object 3)
|
|
(function (function drawable-ambient vector none))
|
|
(quad uint128 :overlay-at (-> user-object 0))
|
|
(user-uint64 uint64 1 :overlay-at (-> user-object 0))
|
|
(user-float float 3 :overlay-at (-> user-object 0))
|
|
(user-int32 int32 3 :overlay-at (-> user-object 0))
|
|
(user-uint32 uint32 3 :overlay-at (-> user-object 0))
|
|
(user-int16 int16 6 :overlay-at (-> user-object 0))
|
|
(user-uint16 uint16 6 :overlay-at (-> user-object 0))
|
|
(user-int8 int8 12 :overlay-at (-> user-object 0))
|
|
(user-uint8 uint8 12 :overlay-at (-> user-object 0))))
|
|
|
|
(deftype entity-ambient-data-array (inline-array-class)
|
|
((data entity-ambient-data :inline :dynamic)))
|
|
|
|
(set! (-> entity-ambient-data-array heap-base) (the-as uint 16))
|
|
|
|
;; placement of an ambient.
|
|
(deftype entity-ambient (entity)
|
|
((ambient-data entity-ambient-data :overlay-at extra))
|
|
(:methods
|
|
(draw-debug (_type_) none)
|
|
(birth-ambient! (_type_) none)))
|
|
|
|
;; A placed entity. This inherits position and res-lump settings from
|
|
;; the parent type and adds in the info needed to spawn an actor.
|
|
;; putting nav-mesh in the entity base type is a bit odd.
|
|
(deftype entity-actor (entity)
|
|
((nav-mesh nav-mesh)
|
|
(etype type) ;; type of process to spawn
|
|
(task game-task) ;; associated task
|
|
(vis-id uint16) ;; visibility ID
|
|
(vis-id-signed int16 :overlay-at vis-id)
|
|
(quat quaternion :inline))
|
|
(:methods
|
|
(next-actor (_type_) entity-actor)
|
|
(prev-actor (_type_) entity-actor)
|
|
(debug-print (_type_ symbol type) none)
|
|
(set-or-clear-status! (_type_ entity-perm-status symbol) none)))
|
|
|
|
;; Actor creation table entry: process type, load dependencies, pool, and per-process heap size.
|
|
;; This is only needed to override the defaults, which is usually only done to change process
|
|
;; pool settings or heap sizes.
|
|
(deftype entity-info (basic)
|
|
((ptype type)
|
|
(package basic)
|
|
(art-group pair)
|
|
(pool basic)
|
|
(heap-size int32)))
|
|
|
|
(define-extern entity-nav-login (function entity-actor none))
|
|
;; default entity-nav-login for now... a little suspicious that this is needed
|
|
(if (zero? entity-nav-login) (set! entity-nav-login (the-as (function entity-actor none) nothing)))
|
|
|
|
;; Dynamic actor population limits. Processes pause outside pause-dist, eligible entities can be
|
|
;; born inside birth-dist, and birth-max caps the lifecycle changes processed during one update.
|
|
(deftype actor-bank (basic)
|
|
((pause-dist float)
|
|
(birth-dist float)
|
|
(birth-max int32)))
|
|
|
|
(define *ACTOR-bank* (new 'static 'actor-bank :pause-dist (meters 50) :birth-dist (meters 220) :birth-max 10))
|