mirror of
https://github.com/open-goal/jak-project
synced 2026-08-16 05:09:45 -04:00
784cd5debb
* temp * menu text * wip * recognize handle to process * more
96 lines
2.7 KiB
Common Lisp
96 lines
2.7 KiB
Common Lisp
;;-*-Lisp-*-
|
|
(in-package goal)
|
|
|
|
;; name: text.gc
|
|
;; name in dgo: text
|
|
;; dgos: GAME, ENGINE
|
|
|
|
(define *game-text-word* (new 'global 'string 256 (the string '#f)))
|
|
(define *game-text-line* (new 'global 'string 256 (the string '#f)))
|
|
(define *level-text-file-load-flag* '#t)
|
|
|
|
;; allocate the game text heap if it isn't already allocated.
|
|
(when (= 0 (-> *common-text-heap* base))
|
|
(let ((heap *common-text-heap*))
|
|
(set! (-> heap base) (malloc 'global 34816))
|
|
(set! (-> heap current) (-> heap base))
|
|
(set! (-> heap top-base) (&+ (-> heap base) 34816))
|
|
(set! (-> heap top) (-> heap top-base))
|
|
)
|
|
)
|
|
|
|
(defmethod length game-text-info ((obj game-text-info))
|
|
"Get the length (number of strings) in a game-text-info."
|
|
(-> obj length)
|
|
)
|
|
|
|
(defmethod asize-of game-text-info ((obj game-text-info))
|
|
(the int (+ (-> obj type size) (* 8 (-> obj length))))
|
|
)
|
|
|
|
(defmethod inspect game-text-info ((obj game-text-info))
|
|
(format '#t "[~8x] ~A~%" obj (-> obj type))
|
|
(format '#t "~Tlength: ~D~%" (-> obj length))
|
|
(format '#t "~Tdata[~D]: @ #x~X~%" (-> obj length) (-> obj data))
|
|
|
|
(let ((i 0))
|
|
(while (< i (-> obj length))
|
|
(format '#t "~T [~D] #x~X ~A~%" i (-> obj data i id) (-> obj data i text))
|
|
(+! i 1)
|
|
)
|
|
)
|
|
obj
|
|
)
|
|
|
|
;; todo method 8
|
|
;; todo method 9
|
|
|
|
(defmethod lookup-text! game-text-info ((obj game-text-info) (arg0 game-text-id) (arg1 symbol))
|
|
"Look up text by ID. Will return the string.
|
|
If the ID can't be found, and arg1 is #t, it will return #f,
|
|
otherwise the temp string UNKNOWN ID <id number>"
|
|
|
|
;; binary search for it
|
|
(let* ((a1-1 0) ;; min
|
|
(a3-0 (+ (-> obj length) 1)) ;; max
|
|
(v1-2 (/ (+ a1-1 a3-0) 2)) ;; mid
|
|
)
|
|
(let ((t0-0 -1)) ;; last time's lookup
|
|
(while (and (!= (-> obj data v1-2 id) arg0) (!= v1-2 t0-0)) ;; while we haven't found it/not the same as last time
|
|
(if (< arg0 (-> obj data v1-2 id))
|
|
(set! a3-0 v1-2) ;; bisect, right
|
|
(set! a1-1 v1-2) ;; bisect, left
|
|
)
|
|
(set! t0-0 v1-2) ;; remeber last time
|
|
(set! v1-2 (/ (+ a1-1 a3-0) 2)) ;; midpoint for next time
|
|
)
|
|
)
|
|
(cond
|
|
((!= (-> obj data v1-2 id) arg0) ;; didn't find it :(
|
|
(cond
|
|
(arg1
|
|
(the-as string #f)
|
|
)
|
|
(else
|
|
(format (clear *temp-string*) "UNKNOWN ID ~D" arg0)
|
|
*temp-string*
|
|
)
|
|
)
|
|
)
|
|
(else
|
|
(-> obj data v1-2 text) ;; found it!
|
|
)
|
|
)
|
|
)
|
|
)
|
|
;; todo text-is-loading
|
|
;; todo load-game-text-info
|
|
;; todo load-level-text-files
|
|
;; todo draw-debug-text-box
|
|
;; todo set-font-color-alpha
|
|
;; todo print-game-text-scaled
|
|
;; todo print-game-text
|
|
;; todo disable-level-text-file-loading
|
|
;; todo enable-level-text-file-loading
|
|
|