;;-*-Lisp-*-
(in-package goal)

;; name: cam-layout.gc
;; name in dgo: cam-layout
;; dgos: GAME

;; +++pad-buttons-u64
(defenum pad-buttons-u64
  :type uint64
  :bitfield #t
  :copy-entries pad-buttons
  )
;; ---pad-buttons-u64


;; +++clm-item-action-options
(defenum clm-item-action-options
  :type uint64
  :bitfield #t
  (clm0 0)
  (clm1 1)
  (clm2 2)
  (clm3 3)
  (clm4 4)
  (clm5 5)
  (clm6 6)
  (clm7 7)
  )
;; ---clm-item-action-options


(declare-type clm basic)
(define-extern *clm-edit* clm)
(define-extern *clm* clm)
(define-extern *clm-spline-attr* clm)
(define-extern *clm-intro-attr* clm)
(define-extern *clm-index-attr* clm)
(define-extern *clm-focalpull-attr* clm)
(define-extern *clm-select* clm)

;; DECOMP BEGINS

;; this file is debug only
(declare-file (debug))

(define *camera-layout-blink* #f)

(deftype cam-layout-bank (basic)
  ((spline-t     float)
   (spline-step  float)
   (intro-t      float)
   (intro-step   float)
   (debug-t      float)
   (debug-step   float)
   )
  )


(define *CAM_LAYOUT-bank* (new 'static 'cam-layout-bank
                            :spline-t 0.01
                            :spline-step 0.0016666667
                            :intro-t 0.01
                            :intro-step 0.0016666667
                            :debug-t 0.01
                            :debug-step 0.0033333334
                            )
        )

(define *camera-layout-message-ypos* 30)

(deftype clm-basic (basic)
  ()
  )


(deftype clm-item-action (structure)
  ((button       pad-buttons-u64)
   (options      clm-item-action-options)
   (func         symbol)
   (parm0        int32)
   (parm0-sym    symbol  :overlay-at parm0)
   (parm1        symbol)
   (parm1-basic  basic   :overlay-at parm1)
   )
  )


(deftype clm-item (clm-basic)
  ((description    string)
   (button-symbol  symbol)
   (action         clm-item-action  :inline)
   )
  )


(deftype clm-list-item (basic)
  ((description    string)
   (track-val      symbol)
   (val-func       symbol)
   (val-parm0      int32)
   (val-parm0-sym  symbol  :overlay-at val-parm0)
   (val-parm1      symbol)
   (actions        (array clm-item-action))
   )
  )


(deftype clm-list (clm-basic)
  ((tracker        symbol)
   (cur-list-item  int32)
   (items          (array clm-list-item))
   )
  )


(deftype clm (basic)
  ((title  string)
   (items  (array clm-basic))
   )
  )


(define *volume-point-current* 0)

(define *volume-point* (new 'debug 'vector-array 1000))

(define *volume-normal-current* 0)

(define *volume-normal* (new 'debug 'vector-array 600))

(deftype volume-descriptor-array (inline-array-class)
  ((data  plane-volume  :inline :dynamic)
   )
  )


(set! (-> volume-descriptor-array heap-base) (the-as uint 24))

(define *volume-descriptor-current* 0)

(define *volume-descriptor* (the-as vol-control (new 'debug 'volume-descriptor-array 100)))

(deftype cam-layout (process)
  ((cam-entity       entity-camera)
   (num-entities     int32)
   (cur-entity       int32)
   (num-volumes      int32)
   (cur-volume       int32)
   (first-pvol       int32)
   (first-cutoutvol  int32)
   (res-key          float)
   )
  (:states
    cam-layout-active
    )
  )


(defun cam-layout-print ((arg0 int) (arg1 int) (arg2 string))
  (let* ((s5-0 (-> *display* frames (-> *display* on-screen) debug-buf))
         (gp-0 (-> s5-0 base))
         )
    (draw-string-xy arg2 s5-0 arg0 arg1 (font-color white) (font-flags shadow kerning))
    (let ((a3-2 (-> s5-0 base)))
      (when (!= gp-0 a3-2)
        (let ((v1-6 (the-as object (-> s5-0 base))))
          (set! (-> (the-as dma-packet v1-6) dma) (new 'static 'dma-tag :id (dma-tag-id next)))
          (set! (-> (the-as dma-packet v1-6) vif0) (new 'static 'vif-tag))
          (set! (-> (the-as dma-packet v1-6) vif1) (new 'static 'vif-tag))
          (set! (-> s5-0 base) (&+ (the-as pointer v1-6) 16))
          )
        (dma-bucket-insert-tag
          (-> *display* frames (-> *display* on-screen) bucket-group)
          (bucket-id debug)
          gp-0
          (the-as (pointer dma-tag) a3-2)
          )
        )
      )
    )
  )

(defun cam-layout-intersect-dist ((arg0 vector) (arg1 vector) (arg2 vector))
  (let ((f0-1 (vector-dot arg1 arg0))
        (f1-1 (vector-dot arg2 arg0))
        )
    (if (< 0.00001 (fabs f1-1))
        (/ (- (-> arg0 w) f0-1) f1-1)
        409600000.0
        )
    )
  )

;; WARN: new jak 2 until loop case, check carefully
(defbehavior cam-layout-entity-volume-info-create cam-layout ((arg0 entity-camera) (arg1 symbol))
  (local-vars
    (sv-16 res-tag)
    (sv-160 vector)
    (sv-164 float)
    (sv-168 int)
    (sv-176 vector)
    (sv-192 vector)
    (sv-208 vector)
    (sv-224 vector)
    (sv-240 vector)
    (sv-256 int)
    (sv-272 int)
    (sv-288 int)
    )
  (let ((s4-0 0))
    (until #f
      (set! sv-16 (new 'static 'res-tag))
      (let ((s3-0 (the-as (inline-array vector) ((method-of-type res-lump get-property-data)
                                                 arg0
                                                 arg1
                                                 'exact
                                                 (the float s4-0)
                                                 (the-as pointer #f)
                                                 (& sv-16)
                                                 *res-static-buf*
                                                 )
                          )
                  )
            )
        (cond
          (s3-0
            (when (>= *volume-descriptor-current* 100)
              (format 0 "ERROR <GMJ>: camera editing out of volume descriptors~%")
              (return #f)
              )
            (let ((s2-0 (-> *volume-descriptor* pos-vol *volume-descriptor-current*)))
              (set! (-> s2-0 volume-type) arg1)
              (set! (-> s2-0 point-count) 0)
              (set! (-> s2-0 first-point) (the-as (pointer vector) (-> *volume-point* data *volume-point-current*)))
              (set! (-> s2-0 normal-count) 0)
              (set! (-> s2-0 first-normal) (the-as (pointer vector) (-> *volume-normal* data *volume-normal-current*)))
              (set! *volume-descriptor-current* (+ *volume-descriptor-current* 1))
              (+! (-> self num-volumes) 1)
              (dotimes (s1-0 (the-as int (-> sv-16 elt-count)))
                (set! sv-192 (new 'stack-no-clear 'vector))
                (set! (-> sv-192 quad) (the-as uint128 0))
                (set! sv-208 (new 'stack-no-clear 'vector))
                (set! (-> sv-208 quad) (the-as uint128 0))
                (set! sv-224 (new 'stack-no-clear 'vector))
                (set! (-> sv-224 quad) (the-as uint128 0))
                (set! sv-240 (new 'stack-no-clear 'vector))
                (set! (-> sv-240 quad) (the-as uint128 0))
                0.0
                0.0
                0.0
                (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0))
                (let ((s0-0 (new-stack-vector0)))
                  (set! sv-256 0)
                  (set! sv-272 0)
                  (while (< sv-272 (the-as int (-> sv-16 elt-count)))
                    (when (!= s1-0 sv-272)
                      (vector-float*! sv-192 (-> s3-0 sv-272) (-> s3-0 sv-272 w))
                      (vector-cross! sv-208 (-> s3-0 sv-272) (-> s3-0 s1-0))
                      (vector-normalize! sv-208 1.0)
                      (vector-cross! sv-224 sv-208 (-> s3-0 sv-272))
                      (vector-normalize! sv-224 1.0)
                      (let ((f0-6 (cam-layout-intersect-dist (-> s3-0 s1-0) sv-192 sv-224)))
                        (when (!= f0-6 409600000.0)
                          (vector+float*! sv-240 sv-192 sv-224 f0-6)
                          (set! sv-160 (new-stack-vector0))
                          (set! sv-164 (the-as float 0.0))
                          (set! sv-168 0)
                          (set! sv-176 (new-stack-vector0))
                          (vector-copy! sv-160 sv-240)
                          (set! sv-288 0)
                          (while (< sv-288 (the-as int (-> sv-16 elt-count)))
                            (when (and (!= sv-288 s1-0) (!= sv-288 sv-272))
                              (let ((f0-8 (cam-layout-intersect-dist (-> s3-0 sv-288) sv-160 sv-208)))
                                (cond
                                  ((= f0-8 409600000.0)
                                   )
                                  ((zero? sv-168)
                                   (vector+float*! sv-160 sv-160 sv-208 f0-8)
                                   (vector-copy! sv-176 (-> s3-0 sv-288))
                                   (set! sv-164 (the-as float 8192000.0))
                                   (set! sv-168 1)
                                   )
                                  ((begin (vector-float*! sv-240 sv-208 f0-8) (>= (vector-dot sv-240 sv-176) 0.0))
                                   )
                                  ((>= (vector-dot sv-240 (-> s3-0 sv-288)) 0.0)
                                   (when (< (fabs f0-8) (fabs sv-164))
                                     (set! sv-164 f0-8)
                                     (set! sv-168 (+ sv-168 1))
                                     )
                                   )
                                  (else
                                    (vector+float*! sv-160 sv-160 sv-208 f0-8)
                                    (vector-copy! sv-176 (-> s3-0 sv-288))
                                    (set! sv-168 (+ sv-168 1))
                                    (if (< (fabs f0-8) (fabs sv-164))
                                        (set! sv-164 (- sv-164 f0-8))
                                        (set! sv-164 (the-as float 0.0))
                                        )
                                    )
                                  )
                                )
                              )
                            (set! sv-288 (+ sv-288 1))
                            )
                          (cond
                            ((zero? sv-168)
                             )
                            ((= sv-164 0.0)
                             )
                            (else
                              (dotimes (v1-87 (the-as int (-> sv-16 elt-count)))
                                (when (and (!= v1-87 s1-0) (!= v1-87 sv-272))
                                  (if (< 4096.0 (- (vector-dot sv-160 (-> s3-0 v1-87)) (-> s3-0 v1-87 w)))
                                      (goto cfg-47)
                                      )
                                  )
                                )
                              (vector+float*! sv-240 sv-160 sv-208 sv-164)
                              (cond
                                ((>= *volume-point-current* 999)
                                 (format 0 "ERROR <GMJ>: camera editing out of volume points~%")
                                 )
                                (else
                                  (vector-copy! (-> *volume-point* data *volume-point-current*) sv-160)
                                  (vector-copy! (-> *volume-point* data (+ *volume-point-current* 1)) sv-240)
                                  (set! *volume-point-current* (+ *volume-point-current* 2))
                                  (+! (-> s2-0 point-count) 2)
                                  )
                                )
                              (vector+! s0-0 s0-0 sv-160)
                              (vector+! s0-0 s0-0 sv-240)
                              (set! sv-256 (+ sv-256 2))
                              sv-256
                              )
                            )
                          )
                        )
                      )
                    (label cfg-47)
                    (set! sv-272 (+ sv-272 1))
                    )
                  (when (nonzero? sv-256)
                    (vector-float*! s0-0 s0-0 (/ 1.0 (the float sv-256)))
                    (cond
                      ((>= *volume-normal-current* 599)
                       (format 0 "ERROR <GMJ>: camera editing out of volume normals~%")
                       )
                      (else
                        (vector-copy! (-> *volume-normal* data *volume-normal-current*) s0-0)
                        (vector-copy! (-> *volume-normal* data (+ *volume-normal-current* 1)) (-> s3-0 s1-0))
                        (set! *volume-normal-current* (+ *volume-normal-current* 2))
                        (set! (-> s2-0 normal-count) (+ (-> s2-0 normal-count) 2))
                        )
                      )
                    )
                  )
                )
              )
            )
          (else
            (return #f)
            )
          )
        )
      (+! s4-0 1)
      )
    )
  #f
  )

(defbehavior cam-layout-entity-volume-info cam-layout ()
  (dotimes (gp-0 (-> self num-volumes))
    (cond
      ((and (= gp-0 (-> self cur-volume))
            (= *camera-layout-blink* 'volume)
            (not (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
            )
       )
      (else
        (let ((s5-0 (-> *volume-descriptor* pos-vol gp-0)))
          (let ((a0-8 (new 'static 'vector4w :w #x80)))
            (cond
              ((= (-> s5-0 volume-type) 'vol)
               (set! (-> a0-8 x) 0)
               (set! (-> a0-8 y) 192)
               (set! (-> a0-8 z) 0)
               0
               )
              ((= (-> s5-0 volume-type) 'pvol)
               (set! (-> a0-8 x) 128)
               (set! (-> a0-8 y) 128)
               (set! (-> a0-8 z) 128)
               )
              ((= (-> s5-0 volume-type) 'cutoutvol)
               (set! (-> a0-8 x) 192)
               (set! (-> a0-8 y) 0)
               (set! (-> a0-8 z) 0)
               0
               )
              )
            (camera-line-setup a0-8)
            )
          (let ((s4-0 (-> s5-0 first-point)))
            (dotimes (s3-0 (/ (-> s5-0 point-count) 2))
              (camera-line-draw (the-as vector s4-0) (the-as vector (&-> s4-0 4)))
              (set! s4-0 (&-> s4-0 8))
              )
            )
          )
        )
      )
    )
  #f
  )

(defun v-slrp! ((arg0 vector) (arg1 vector) (arg2 vector) (arg3 float))
  (let ((s2-0 (new-stack-vector0))
        (s1-0 (new-stack-vector0))
        (s0-0 (new-stack-vector0))
        )
    0.0
    0.0
    0.0
    0.0
    (cond
      ((< 1.0 arg3)
       (set! arg3 1.0)
       )
      ((< arg3 0.0)
       (set! arg3 0.0)
       )
      )
    (vector-normalize-copy! s2-0 arg1 1.0)
    (vector-normalize-copy! s1-0 arg2 1.0)
    (vector-cross! s0-0 s2-0 s1-0)
    (let* ((f30-0 (vector-length s0-0))
           (f28-0 (asin f30-0))
           )
      (vector-float*! arg0 arg1 (/ (sin (* (- 1.0 arg3) f28-0)) f30-0))
      (vector+float*! arg0 arg0 arg2 (/ (sin (* arg3 f28-0)) f30-0))
      )
    )
  )

(deftype interp-test-info (structure)
  ((from    vector  :inline)
   (to      vector  :inline)
   (origin  vector  :inline)
   (color   vector4w)
   (axis    vector)
   (disp    string)
   )
  )


(defun interp-test ((arg0 (function vector vector vector float vector float none)) (arg1 interp-test-info))
  (let ((s3-0 (new-stack-vector0))
        (s5-0 (new-stack-vector0))
        )
    (arg0 s3-0 (-> arg1 from) (-> arg1 to) 0.0 (-> arg1 axis) 65536.0)
    (vector+! s3-0 s3-0 (-> arg1 origin))
    (dotimes (s2-0 10)
      (vector-copy! s5-0 s3-0)
      (arg0 s3-0 (-> arg1 from) (-> arg1 to) (* 0.1 (+ 1.0 (the float s2-0))) (-> arg1 axis) 65536.0)
      (vector+! s3-0 s3-0 (-> arg1 origin))
      (camera-line s3-0 s5-0 (-> arg1 color))
      )
    (arg0 s5-0 (-> arg1 from) (-> arg1 to) (-> *CAM_LAYOUT-bank* debug-t) (-> arg1 axis) 65536.0)
    (format *stdcon* "~S  ~f~%" (-> arg1 disp) (vector-length s5-0))
    (vector+! s5-0 s5-0 (-> arg1 origin))
    (camera-line (-> arg1 origin) s5-0 (-> arg1 color))
    (camera-cross (new 'static 'vector :y 1024.0) (new 'static 'vector :z 1024.0) s5-0 (-> arg1 color) (meters 1))
    )
  (none)
  )

(defun interp-test-deg ((arg0 (function vector vector vector vector float none)) (arg1 interp-test-info))
  (let ((s3-0 (new-stack-vector0))
        (s5-0 (new-stack-vector0))
        )
    (arg0 s3-0 (-> arg1 from) (-> arg1 to) (-> arg1 axis) 0.0)
    (vector+! s3-0 s3-0 (-> arg1 origin))
    (dotimes (s2-0 10)
      (vector-copy! s5-0 s3-0)
      (arg0 s3-0 (-> arg1 from) (-> arg1 to) (-> arg1 axis) (* 182.04445 (* 18.0 (+ 1.0 (the float s2-0)))))
      (vector+! s3-0 s3-0 (-> arg1 origin))
      (camera-line s3-0 s5-0 (-> arg1 color))
      )
    (arg0 s5-0 (-> arg1 from) (-> arg1 to) (-> arg1 axis) (* 182.04445 (* 180.0 (-> *CAM_LAYOUT-bank* debug-t))))
    (format *stdcon* "~S  ~f~%" (-> arg1 disp) (vector-length s5-0))
    (vector+! s5-0 s5-0 (-> arg1 origin))
    (camera-line (-> arg1 origin) s5-0 (-> arg1 color))
    (camera-cross (new 'static 'vector :y 1024.0) (new 'static 'vector :z 1024.0) s5-0 (-> arg1 color) (meters 1))
    )
  (none)
  )

;; WARN: Function cam-layout-entity-info has a return type of none, but the expression builder found a return statement.
(defun cam-layout-entity-info ((arg0 entity-actor))
  (if (not arg0)
      (return #f)
      )
  (let ((s5-0 (new-stack-matrix0))
        (s4-0 (new-stack-vector0))
        )
    (when (and (cam-slave-get-vector-with-offset arg0 s4-0 'trans)
               (or (!= *camera-layout-blink* 'camera) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
               )
      (cam-slave-get-rot arg0 s5-0)
      (camera-fov-frame s5-0 s4-0 (* 0.5 (cam-slave-get-fov arg0)) 0.75 1.0 (new 'static 'vector4w :z #xff :w #x80))
      )
    )
  (let ((s5-1 (new-stack-vector0)))
    (if (and (cam-slave-get-vector-with-offset arg0 s5-1 'pivot)
             (or (!= *camera-layout-blink* 'pivot) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
             )
        (camera-cross
          (new 'static 'vector :y 1024.0)
          (new 'static 'vector :z 1024.0)
          s5-1
          (new 'static 'vector4w :x #x80 :w #x80)
          (meters 1)
          )
        )
    )
  (let ((s5-2 (new-stack-vector0)))
    (if (and (cam-slave-get-vector-with-offset arg0 s5-2 'align)
             (or (!= *camera-layout-blink* 'align) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
             )
        (camera-cross
          (new 'static 'vector :y 1024.0)
          (new 'static 'vector :z 1024.0)
          s5-2
          (new 'static 'vector4w :y #x80 :w #x80)
          (meters 1)
          )
        )
    )
  (let ((s5-3 (new-stack-vector0)))
    (if (and (cam-slave-get-vector-with-offset arg0 s5-3 'interesting)
             (or (!= *camera-layout-blink* 'interesting)
                 (logtest? (-> *display* real-frame-clock integral-frame-counter) 8)
                 )
             )
        (camera-cross
          (new 'static 'vector :y 1024.0)
          (new 'static 'vector :z 1024.0)
          s5-3
          (new 'static 'vector4w :x #x80 :z #x80 :w #x80)
          (meters 1)
          )
        )
    )
  (let ((s3-1 (new 'stack 'curve))
        (s2-0 (new-stack-vector0))
        (s5-4 (new-stack-vector0))
        (s4-1 (new-stack-vector0))
        )
    (when (and (get-curve-data! arg0 s3-1 'campath 'campath-k -1000000000.0)
               (or (!= *camera-layout-blink* 'spline) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
               )
      (cond
        ((cam-slave-get-vector-with-offset arg0 s4-1 'pivot)
         (curve-get-pos! s5-4 0.0 s3-1)
         (vector-! s4-1 s4-1 s5-4)
         )
        (else
          (vector-copy!
            s4-1
            (the-as
              vector
              ((method-of-type res-lump get-property-struct)
               arg0
               'spline-offset
               'interp
               -1000000000.0
               s4-1
               (the-as (pointer res-tag) #f)
               *res-static-buf*
               )
              )
            )
          )
        )
      (curve-get-pos! s5-4 0.0 s3-1)
      (vector+! s5-4 s5-4 s4-1)
      (dotimes (s1-1 8)
        (vector-copy! s2-0 s5-4)
        (curve-get-pos! s5-4 (* 0.125 (the float (+ s1-1 1))) s3-1)
        (vector+! s5-4 s5-4 s4-1)
        (camera-line s2-0 s5-4 (new 'static 'vector4w :x #xff :y #xff :w #x80))
        )
      (curve-get-pos! s5-4 (-> *CAM_LAYOUT-bank* spline-t) s3-1)
      (vector+! s5-4 s5-4 s4-1)
      (camera-cross
        (new 'static 'vector :y 1024.0)
        (new 'static 'vector :z 1024.0)
        s5-4
        (new 'static 'vector4w :x #xff :y #xff :w #x80)
        (meters 1)
        )
      )
    )
  (let ((s3-2 (new 'stack 'curve))
        (s2-1 (new-stack-vector0))
        (s5-5 (new-stack-vector0))
        (s4-2 (new-stack-vector0))
        (s1-2 (new 'stack 'curve))
        )
    (when (and (get-curve-data! arg0 s3-2 'intro 'intro-k -1000000000.0)
               (or (!= *camera-layout-blink* 'intro) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
               )
      (cond
        ((cam-slave-get-vector-with-offset arg0 s4-2 'pivot)
         (curve-get-pos! s5-5 1.0 s3-2)
         (vector-! s4-2 s4-2 s5-5)
         )
        ((get-curve-data! arg0 s1-2 'campath 'campath-k -1000000000.0)
         (curve-get-pos! s4-2 0.0 s1-2)
         (curve-get-pos! s5-5 1.0 s3-2)
         (vector-! s4-2 s4-2 s5-5)
         )
        ((cam-slave-get-vector-with-offset arg0 s4-2 'trans)
         (curve-get-pos! s5-5 1.0 s3-2)
         (vector-! s4-2 s4-2 s5-5)
         )
        )
      (curve-get-pos! s5-5 0.0 s3-2)
      (vector+! s5-5 s5-5 s4-2)
      (dotimes (s1-3 8)
        (vector-copy! s2-1 s5-5)
        (curve-get-pos! s5-5 (* 0.125 (the float (+ s1-3 1))) s3-2)
        (vector+! s5-5 s5-5 s4-2)
        (camera-line s2-1 s5-5 (new 'static 'vector4w :z #xff :w #x80))
        )
      (curve-get-pos! s5-5 (-> *CAM_LAYOUT-bank* intro-t) s3-2)
      (vector+! s5-5 s5-5 s4-2)
      (camera-cross
        (new 'static 'vector :y 1024.0)
        (new 'static 'vector :z 1024.0)
        s5-5
        (new 'static 'vector4w :z #xff :w #x80)
        (meters 1)
        )
      (curve-get-pos! s5-5 (cam-slave-get-float arg0 'intro-exitValue 0.0) s3-2)
      (vector+! s5-5 s5-5 s4-2)
      (camera-cross
        (new 'static 'vector :y 1024.0)
        (new 'static 'vector :z 1024.0)
        s5-5
        (new 'static 'vector4w :z #xff :w #x80)
        (meters 1)
        )
      )
    )
  (let ((s2-3 (res-lump-data arg0 'campoints pointer :time 1.0))
        (v1-73 (res-lump-struct arg0 'campoints-offset structure))
        (s4-3 (new 'stack-no-clear 'vector))
        (s3-3 (new 'stack-no-clear 'vector))
        (s5-6 (new 'static 'vector))
        )
    (when (and s2-3
               (or (!= *camera-layout-blink* 'index) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
               )
      (cond
        (v1-73
          (vector+! s4-3 (the-as vector (&+ s2-3 0)) (the-as vector v1-73))
          (vector+! s3-3 (the-as vector (&+ s2-3 16)) (the-as vector v1-73))
          )
        (else
          (set! (-> s4-3 quad) (-> (the-as (pointer uint128) (&+ s2-3 0))))
          (set! (-> s3-3 quad) (-> (the-as (pointer uint128) (&+ s2-3 16))))
          )
        )
      (camera-line s4-3 s3-3 (new 'static 'vector4w :y #x80 :w #x80))
      (vector-lerp-clamp! s5-6 s4-3 s3-3 (-> *CAM_LAYOUT-bank* spline-t))
      (camera-cross
        (new 'static 'vector :y 1024.0)
        (new 'static 'vector :z 1024.0)
        s5-6
        (new 'static 'vector4w :x #xff :y #xff :w #x80)
        (meters 1)
        )
      )
    )
  (let ((s4-4 (res-lump-data arg0 'focalpull pointer :time 1.0))
        (s5-7 (new 'static 'vector))
        )
    (when (and s4-4
               (or (!= *camera-layout-blink* 'focalpull) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
               )
      (camera-line
        (the-as vector (&+ s4-4 0))
        (the-as vector (&+ s4-4 16))
        (new 'static 'vector4w :y #xff :z #xff :w #x80)
        )
      (vector-lerp-clamp!
        s5-7
        (the-as vector (&+ s4-4 0))
        (the-as vector (&+ s4-4 16))
        (-> *CAM_LAYOUT-bank* spline-t)
        )
      (camera-cross
        (new 'static 'vector :y 1024.0)
        (new 'static 'vector :z 1024.0)
        s5-7
        (new 'static 'vector4w :y #xff :z #xff :w #x80)
        (meters 1)
        )
      )
    )
  (let ((s5-8 (new 'stack 'interp-test-info))
        (s4-5 (new-stack-vector0))
        )
    (when (and (cam-slave-get-vector-with-offset arg0 (-> s5-8 origin) 'pivot)
               (cam-slave-get-vector-with-offset arg0 (-> s5-8 to) 'align)
               (cam-slave-get-vector-with-offset arg0 (-> s5-8 from) 'trans)
               )
      (camera-line (-> s5-8 from) (-> s5-8 origin) (new 'static 'vector4w :x #x80 :y #x80 :z #x80 :w #x80))
      (camera-line (-> s5-8 to) (-> s5-8 origin) (new 'static 'vector4w :x #x80 :y #x80 :z #x80 :w #x80))
      (vector-! (-> s5-8 from) (-> s5-8 from) (-> s5-8 origin))
      (vector-! (-> s5-8 to) (-> s5-8 to) (-> s5-8 origin))
      (vector-cross! s4-5 (-> s5-8 from) (-> s5-8 to))
      (vector-normalize! s4-5 8192.0)
      (vector+! s4-5 s4-5 (-> s5-8 origin))
      (camera-line (-> s5-8 origin) s4-5 (new 'static 'vector4w :x #x80 :y #x80 :z #x80 :w #x80))
      (when (not (paused?))
        (+! (-> *CAM_LAYOUT-bank* debug-t) (-> *CAM_LAYOUT-bank* debug-step))
        (if (< 1.0 (-> *CAM_LAYOUT-bank* debug-t))
            (set! (-> *CAM_LAYOUT-bank* debug-t) 0.0)
            )
        )
      (set! (-> s5-8 axis) #f)
      (set! (-> s5-8 disp) "li")
      (set! (-> s5-8 color) (new 'static 'vector4w :x #xff :w #x80))
      (interp-test (the-as (function vector vector vector float vector float none) vector-lerp!) s5-8)
      (set! (-> s5-8 disp) "si")
      (set! (-> s5-8 color) (new 'static 'vector4w :y #xff :w #x80))
      (interp-test (the-as (function vector vector vector float vector float none) v-slrp!) s5-8)
      (set! (-> s5-8 disp) "si2")
      (set! (-> s5-8 color) (new 'static 'vector4w :z #xff :w #x80))
      (interp-test (the-as (function vector vector vector float vector float none) v-slrp2!) s5-8)
      (set! (-> s5-8 disp) "si3")
      (set! (-> s5-8 color) (new 'static 'vector4w :x #xff :z #xff :w #x80))
      (interp-test-deg (the-as (function vector vector vector vector float none) v-slrp3!) s5-8)
      (set! (-> s5-8 axis) (-> *camera* local-down))
      (set! (-> s5-8 disp) "si2d")
      (set! (-> s5-8 color) (new 'static 'vector4w :y #xff :z #xff :w #x80))
      (interp-test (the-as (function vector vector vector float vector float none) v-slrp2!) s5-8)
      (set! (-> s5-8 disp) "si3d")
      (set! (-> s5-8 color) (new 'static 'vector4w :x #xff :y #xff :w #x80))
      (interp-test-deg (the-as (function vector vector vector vector float none) v-slrp3!) s5-8)
      )
    )
  (none)
  )

(defun clmf-button-test ()
  (cam-layout-print 16 *camera-layout-message-ypos* "button test")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (set-setting! 'master-options 'set 0.0 32)
  #f
  )

(defun clmf-bna ()
  (cam-layout-print 16 *camera-layout-message-ypos* "button not applicable")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (set-setting! 'master-options 'set 0.0 32)
  #t
  )

(defun clmf-implement ()
  (cam-layout-print 16 *camera-layout-message-ypos* "button not implemented yet")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (set-setting! 'master-options 'set 0.0 32)
  #t
  )

(defun clmf-input ((arg0 vector) (arg1 vector) (arg2 int))
  (vector-reset! arg0)
  (vector-reset! arg1)
  (cond
    ((cpad-hold? arg2 l3)
     (set! (-> arg0 z)
           (- (-> arg0 z) (analog-input (the-as int (-> *cpad-list* cpads arg2 rightx)) 128.0 48.0 110.0 1.0))
           )
     )
    (else
      (set! (-> arg0 y)
            (- (-> arg0 y) (analog-input (the-as int (-> *cpad-list* cpads arg2 rightx)) 128.0 48.0 110.0 1.0))
            )
      (+! (-> arg0 x) (analog-input (the-as int (-> *cpad-list* cpads arg2 righty)) 128.0 48.0 110.0 1.0))
      (set! (-> arg1 x)
            (- (-> arg1 x) (analog-input (the-as int (-> *cpad-list* cpads arg2 leftx)) 128.0 48.0 110.0 1.0))
            )
      (when (logtest? (-> *camera* settings master-options) (cam-master-options READ_BUTTONS))
        (if (cpad-hold? arg2 r1)
            (set! (-> arg1 y)
                  (+ 0.5 (analog-input (the-as int (-> *cpad-list* cpads arg2 abutton (abutton-idx r1))) 0.0 32.0 230.0 0.5) (-> arg1 y)) ;; og:preserve-this abutton indexing
                  )
            )
        )
      (when (logtest? (-> *camera* settings master-options) (cam-master-options READ_BUTTONS))
        (if (cpad-hold? arg2 l1)
            (set! (-> arg1 y)
                  (- (-> arg1 y) (+ 0.5 (analog-input (the-as int (-> *cpad-list* cpads arg2 abutton (abutton-idx l1))) 0.0 32.0 230.0 0.5))) ;; og:preserve-this abutton indexing
                  )
            )
        )
      (set! (-> arg1 z)
            (- (-> arg1 z) (analog-input (the-as int (-> *cpad-list* cpads arg2 lefty)) 128.0 48.0 110.0 1.0))
            )
      )
    )
  (let ((s5-1 (new-stack-matrix0)))
    (let ((a2-8 (new-stack-vector0)))
      (set! (-> a2-8 y) -1.0)
      (forward-down-nopitch->inv-matrix s5-1 (-> *math-camera* inv-camera-rot fvec) a2-8)
      )
    (vector-matrix*! arg1 arg1 s5-1)
    )
  arg1
  )

(defbehavior clmf-pos-rot cam-layout ((arg0 symbol) (arg1 symbol))
  (local-vars (s2-0 structure) (s3-1 structure) (sv-192 matrix))
  (cam-layout-print 16 *camera-layout-message-ypos* "x/z pos: left stick, down: l1, up: r1")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (when (and arg1 (nonzero? arg1))
    (cam-layout-print 16 *camera-layout-message-ypos* "x/y rot: right stick")
    (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
    (cam-layout-print 16 *camera-layout-message-ypos* "z rot: press left stick & move right")
    (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
    )
  (let ((s5-0 (new-stack-vector0))
        (s4-0 (new-stack-vector0))
        )
    (set! s3-1
          (cond
            ((or (zero? arg0) (not arg0))
             (the-as structure #f)
             )
            (else
              (if (not (res-lump-struct (-> self cam-entity) arg0 structure))
                  (add-data!
                    (-> self cam-entity)
                    (new 'static 'res-tag :name arg0 :key-frame -1000000000.0 :elt-count #x1 :inlined? #x1 :elt-type vector)
                    (the-as pointer (new 'static 'vector))
                    )
                  )
              (set! s3-1 (res-lump-struct (-> self cam-entity) arg0 structure))
              (when (and (not s3-1) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
                (clear *temp-string*)
                (format *temp-string* "ERROR <GMJ>: can't add ~A" 'vector)
                (cam-layout-print 120 100 *temp-string*)
                )
              s3-1
              )
            )
          )
    (set! s2-0
          (cond
            ((or (zero? arg1) (not arg1))
             (the-as structure #f)
             )
            (else
              (if (not (res-lump-struct (-> self cam-entity) arg1 structure))
                  (add-data!
                    (-> self cam-entity)
                    (new 'static 'res-tag :name arg1 :key-frame -1000000000.0 :elt-count #x1 :inlined? #x1 :elt-type quaternion)
                    (the-as pointer (quaternion-identity! (new 'static 'quaternion)))
                    )
                  )
              (set! s2-0 (res-lump-struct (-> self cam-entity) arg1 structure))
              (when (and (not s2-0) (logtest? (-> *display* real-frame-clock integral-frame-counter) 8))
                (clear *temp-string*)
                (format *temp-string* "ERROR <GMJ>: can't add ~A" 'quaternion)
                (cam-layout-print 120 100 *temp-string*)
                )
              s2-0
              )
            )
          )
    (let ((s1-1 (new 'stack-no-clear 'matrix)))
      (set! sv-192 (new 'stack-no-clear 'matrix))
      (let ((s0-1 (new 'stack-no-clear 'quaternion)))
        (if (not s3-1)
            (return #f)
            )
        (clmf-input s5-0 s4-0 0)
        (vector+float*! (the-as vector s3-1) (the-as vector s3-1) s4-0 409.6)
        (cond
          ((not arg1)
           (the-as quaternion #f)
           )
          ((zero? arg1)
           (the-as quaternion #f)
           )
          (else
            (cam-slave-get-rot (the-as entity-actor (-> self cam-entity)) sv-192)
            (vector-float*! s5-0 s5-0 100.0)
            (matrix-rotate-x! s1-1 (- (-> s5-0 x)))
            (matrix*! sv-192 s1-1 sv-192)
            (matrix-rotate-y! s1-1 (-> s5-0 y))
            (matrix*! sv-192 sv-192 s1-1)
            (matrix-rotate-z! s1-1 (- (-> s5-0 z)))
            (matrix*! sv-192 s1-1 sv-192)
            (matrix->quaternion s0-1 sv-192)
            (quaternion-inverse! (the-as quaternion s2-0) (the-as quaternion (-> self cam-entity connect)))
            (quaternion*! (the-as quaternion s2-0) s0-1 (the-as quaternion s2-0))
            (quaternion-normalize! (the-as quaternion s2-0))
            )
          )
        )
      )
    )
  (set-setting! 'master-options 'set 0.0 32)
  #t
  )

(defbehavior clmf-next-volume cam-layout ((arg0 int))
  (if (zero? (-> self num-volumes))
      (return #f)
      )
  (set! (-> self cur-volume) (mod (+ arg0 (-> self cur-volume)) (-> self num-volumes)))
  (while (< (-> self cur-volume) 0)
    (+! (-> self cur-volume) (-> self num-volumes))
    )
  #t
  )

(defun clmf-next-vol-dpad ()
  (local-vars (a0-1 int))
  (cam-layout-print 16 *camera-layout-message-ypos* "dpad selects volume")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (cond
    ((cpad-pressed? 0 down)
     (set! a0-1 1)
     )
    ((cpad-pressed? 0 right)
     (set! a0-1 1)
     )
    ((cpad-pressed? 0 up)
     (set! a0-1 -1)
     )
    ((cpad-pressed? 0 left)
     (set! a0-1 -1)
     )
    (else
      (set! a0-1 0)
      )
    )
  (clmf-next-volume a0-1)
  (set-setting! 'master-options 'set 0.0 32)
  #t
  )

(defun clmf-to-edit-cam ()
  (clmf-next-volume 0)
  (set! *clm* *clm-edit*)
  #t
  )

(define *last-cur-entity* -1)

(defbehavior clmf-next-entity cam-layout ((arg0 int))
  (let ((v1-0 (/ arg0 8)))
    (when (zero? (-> self num-entities))
      (set! (-> self cam-entity) #f)
      (return #f)
      )
    (if (= (- v1-0) (-> self num-entities))
        (set! v1-0 -1)
        )
    (if (= v1-0 (-> self num-entities))
        (set! v1-0 1)
        )
    (set! (-> self cur-entity) (mod (+ v1-0 (-> self cur-entity)) (-> self num-entities)))
    )
  (while (< (-> self cur-entity) 0)
    (+! (-> self cur-entity) (-> self num-entities))
    )
  (set! *last-cur-entity* (-> self cur-entity))
  (let ((v1-8 (-> self cur-entity))
        (a0-13 (-> *camera-engine* alive-list next0))
        )
    *camera-engine*
    (let ((a1-3 (-> a0-13 next0)))
      (while (!= a0-13 (-> *camera-engine* alive-list-end))
        (let ((a0-14 (-> (the-as connection a0-13) param1)))
          (cond
            ((zero? v1-8)
             (set! (-> self cam-entity) (the-as entity-camera a0-14))
             (set! *volume-descriptor-current* 0)
             (set! *volume-point-current* 0)
             (set! *volume-normal-current* 0)
             (set! (-> self num-volumes) 0)
             (cam-layout-entity-volume-info-create (-> self cam-entity) 'vol)
             (set! (-> self first-pvol) (-> self num-volumes))
             (cam-layout-entity-volume-info-create (-> self cam-entity) 'pvol)
             (set! (-> self first-cutoutvol) (-> self num-volumes))
             (cam-layout-entity-volume-info-create (-> self cam-entity) 'cutoutvol)
             (set! (-> *CAM_LAYOUT-bank* intro-step) (cam-slave-get-intro-step (-> self cam-entity)))
             (return #f)
             )
            (else
              (+! v1-8 -1)
              )
            )
          )
        (set! a0-13 a1-3)
        *camera-engine*
        (set! a1-3 (-> a1-3 next0))
        )
      )
    )
  #t
  )

(defun clmf-to-spline-attr ()
  (set! *clm* *clm-spline-attr*)
  #t
  )

(defun clmf-to-intro-attr ()
  (set! *clm* *clm-intro-attr*)
  #t
  )

(defun clmf-to-index-attr ()
  (set! *clm* *clm-index-attr*)
  #t
  )

(defun clmf-to-focalpull-attr ()
  (set! *clm* *clm-focalpull-attr*)
  #t
  )

(defbehavior clmf-to-edit cam-layout ()
  (set! (-> self res-key) -1000000000.0)
  (set! *clm* *clm-edit*)
  #t
  )

(defun clmf-to-select ()
  (set! *camera-layout-blink* #f)
  (set! *clm* *clm-select*)
  #t
  )

(defbehavior clmf-look-through cam-layout ()
  (set! (-> *camera-other-fov* data) (cam-slave-get-fov (-> self cam-entity)))
  (cam-slave-get-vector-with-offset (the-as entity-actor (-> self cam-entity)) *camera-other-trans* 'trans)
  (vector-copy! *camera-other-root* *camera-other-trans*)
  (cam-slave-get-rot (the-as entity-actor (-> self cam-entity)) *camera-other-matrix*)
  (set! *camera-look-through-other* 10)
  (set-setting! 'master-options 'set 0.0 32)
  #f
  )

(defun fov->maya ((arg0 float))
  (if (= arg0 0.0)
      0.0
      (/ 12.700255 (tan (/ arg0 2)))
      )
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-cam-rot ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s3-0 (-> arg2 quat))
        (s5-0 (res-lump-struct arg2 'rot-offset vector))
        )
    (if arg0
        (format #t "setup rot ~f ~f ~f ~f~%" (-> s3-0 x) (-> s3-0 y) (-> s3-0 z) (-> s3-0 w))
        )
    (when s5-0
      (if arg0
          (format #t "rot offset ~f ~f ~f ~f~%" (-> s5-0 x) (-> s5-0 y) (-> s5-0 z) (-> s5-0 w))
          )
      (format
        arg1
        "  tag rot-offset             ~f ~f ~f ~f // vector (quaternion)~%"
        (-> s5-0 x)
        (-> s5-0 y)
        (-> s5-0 z)
        (-> s5-0 w)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-cam-trans ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s1-0 (-> arg2 trans))
        (s5-0 (method-of-type res-lump get-property-struct))
        (s2-0 arg2)
        )
    (format (clear *res-key-string*) "~S~S" 'trans '-offset)
    (let ((s5-1 (the-as object (s5-0
                                 s2-0
                                 (string->symbol *res-key-string*)
                                 'interp
                                 -1000000000.0
                                 (the-as structure #f)
                                 (the-as (pointer res-tag) #f)
                                 *res-static-buf*
                                 )
                        )
                )
          )
      (let ((s2-1 (the-as object (res-lump-struct arg2 'translation_info vector)))
            (s3-1 (new-stack-vector0))
            )
        (if arg0
            (format #t "setup trans ~M ~M ~M (maya)~%" (-> s1-0 x) (-> s1-0 y) (-> s1-0 z))
            )
        (vector-copy! s3-1 s1-0)
        (when (the-as vector s5-1)
          (if arg0
              (format
                #t
                "offset ~M ~M ~M (added)~%"
                (-> (the-as vector s5-1) x)
                (-> (the-as vector s5-1) y)
                (-> (the-as vector s5-1) z)
                )
              )
          (vector+! s3-1 s3-1 (the-as vector s5-1))
          )
        (when (the-as vector s2-1)
          (if arg0
              (format
                #t
                "level-trans ~M ~M ~M (subtracted)~%"
                (-> (the-as vector s2-1) x)
                (-> (the-as vector s2-1) y)
                (-> (the-as vector s2-1) z)
                )
              )
          (vector-! s3-1 s3-1 (the-as vector s2-1))
          )
        (set! s2-1 (or (the-as vector s5-1) s2-1))
        (set! arg0 (and (the-as symbol s2-1) arg0))
        (if arg0
            (format #t "final trans ~M ~M ~M (maya)~%" (-> s3-1 x) (-> s3-1 y) (-> s3-1 z))
            )
        )
      (if (the-as vector s5-1)
          (format
            arg1
            "  tag trans-offset           METERS(~M) METERS(~M) METERS(~M) 1.0 // vector~%"
            (-> (the-as vector s5-1) x)
            (-> (the-as vector s5-1) y)
            (-> (the-as vector s5-1) z)
            )
          )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-pivot ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s2-0 (res-lump-struct arg2 'pivot vector))
        (s4-0 (method-of-type res-lump get-property-struct))
        )
    (format (clear *res-key-string*) "~S~S" 'pivot '-offset)
    (let ((s5-1 (the-as vector (s4-0
                                 arg2
                                 (string->symbol *res-key-string*)
                                 'interp
                                 -1000000000.0
                                 (the-as structure #f)
                                 (the-as (pointer res-tag) #f)
                                 *res-static-buf*
                                 )
                        )
                )
          (s4-1 (new-stack-vector0))
          )
      (when s2-0
        (if s5-1
            (vector+! s4-1 s2-0 s5-1)
            (vector-copy! s4-1 s2-0)
            )
        (if arg0
            (format #t "setup pivot ~M ~M ~M~%" (-> s2-0 x) (-> s2-0 y) (-> s2-0 z))
            )
        (when s5-1
          (when arg0
            (format #t "offset ~M ~M ~M~%" (-> s5-1 x) (-> s5-1 y) (-> s5-1 z))
            (format #t "final pivot ~M ~M ~M~%" (-> s4-1 x) (-> s4-1 y) (-> s4-1 z))
            )
          (format
            arg1
            "  tag pivot-offset           METERS(~M) METERS(~M) METERS(~M) 1.0 // vector~%"
            (-> s5-1 x)
            (-> s5-1 y)
            (-> s5-1 z)
            )
          )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-align ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s2-0 (res-lump-struct arg2 'align vector))
        (s4-0 (method-of-type res-lump get-property-struct))
        )
    (format (clear *res-key-string*) "~S~S" 'align '-offset)
    (let ((s5-1 (the-as vector (s4-0
                                 arg2
                                 (string->symbol *res-key-string*)
                                 'interp
                                 -1000000000.0
                                 (the-as structure #f)
                                 (the-as (pointer res-tag) #f)
                                 *res-static-buf*
                                 )
                        )
                )
          (s4-1 (new-stack-vector0))
          )
      (when s2-0
        (if s5-1
            (vector+! s4-1 s2-0 s5-1)
            (vector-copy! s4-1 s2-0)
            )
        (if arg0
            (format #t "setup align ~M ~M ~M~%" (-> s2-0 x) (-> s2-0 y) (-> s2-0 z))
            )
        (when s5-1
          (when arg0
            (format #t "offset ~M ~M ~M~%" (-> s5-1 x) (-> s5-1 y) (-> s5-1 z))
            (format #t "final align ~M ~M ~M~%" (-> s4-1 x) (-> s4-1 y) (-> s4-1 z))
            )
          (format
            arg1
            "  tag align-offset           METERS(~M) METERS(~M) METERS(~M) 1.0 // vector~%"
            (-> s5-1 x)
            (-> s5-1 y)
            (-> s5-1 z)
            )
          )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-interesting ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s2-0 (res-lump-struct arg2 'interesting vector))
        (s4-0 (method-of-type res-lump get-property-struct))
        )
    (format (clear *res-key-string*) "~S~S" 'interesting '-offset)
    (let ((s5-1 (the-as vector (s4-0
                                 arg2
                                 (string->symbol *res-key-string*)
                                 'interp
                                 -1000000000.0
                                 (the-as structure #f)
                                 (the-as (pointer res-tag) #f)
                                 *res-static-buf*
                                 )
                        )
                )
          (s4-1 (new-stack-vector0))
          )
      (when s2-0
        (if s5-1
            (vector+! s4-1 s2-0 s5-1)
            (vector-copy! s4-1 s2-0)
            )
        (if arg0
            (format #t "setup interesting ~M ~M ~M~%" (-> s2-0 x) (-> s2-0 y) (-> s2-0 z))
            )
        (when s5-1
          (when arg0
            (format #t "offset ~M ~M ~M~%" (-> s5-1 x) (-> s5-1 y) (-> s5-1 z))
            (format #t "final interesting ~M ~M ~M~%" (-> s4-1 x) (-> s4-1 y) (-> s4-1 z))
            )
          (format
            arg1
            "  tag interesting-offset           METERS(~M) METERS(~M) METERS(~M) 1.0 // vector~%"
            (-> s5-1 x)
            (-> s5-1 y)
            (-> s5-1 z)
            )
          )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-fov ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f28-0 (res-lump-float arg2 'fov))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'fov '-offset)
    (let ((f30-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (cond
        ((= f28-0 0.0)
         (if arg0
             (format #t "setup fov deg 0.0 (defaults to 64.0)~%")
             )
         (set! f28-0 11650.845)
         )
        (arg0
          (format #t "setup fov deg ~R (~f in maya)~%" f28-0 (fov->maya f28-0))
          )
        )
      (when (!= f30-0 0.0)
        (when arg0
          (format #t "offset ~R~%" f30-0)
          (format #t "final ~R (~f in maya) ~%" (+ f28-0 f30-0) (fov->maya (+ f28-0 f30-0)))
          )
        (format arg1 "  tag fov-offset             DEG(~R)                           // float~%" f30-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-focalpull ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'focalpull))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'focalpull '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup focalpull deg ~R (~f in maya)~%" f30-0 (fov->maya f30-0))
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~R~%" f28-0)
          (format #t "final ~R (~f in maya) ~%" (+ f30-0 f28-0) (fov->maya (+ f30-0 f28-0)))
          )
        (format arg1 "  tag focalpull-offset       DEG(~R)                           // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-flags ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s4-0 (res-lump-value arg2 'flags uint128 :time -1000000000.0))
        (s5-0 (method-of-type res-lump get-property-value))
        (s1-0 arg2)
        )
    (format (clear *res-key-string*) "~S~S" 'flags '-on)
    (let ((s5-1 (s5-0
                  s1-0
                  (string->symbol *res-key-string*)
                  'interp
                  -1000000000.0
                  (the-as uint128 0)
                  (the-as (pointer res-tag) #f)
                  *res-static-buf*
                  )
                )
          (s1-1 (method-of-type res-lump get-property-value))
          )
      (format (clear *res-key-string*) "~S~S" 'flags '-off)
      (let ((s3-1 (s1-1
                    arg2
                    (string->symbol *res-key-string*)
                    'interp
                    -1000000000.0
                    (the-as uint128 0)
                    (the-as (pointer res-tag) #f)
                    *res-static-buf*
                    )
                  )
            )
        (when arg0
          (format #t "setup flags ")
          (cam-slave-options->string (the-as cam-slave-options s4-0) #t)
          (format #t "~%")
          (format #t "forced on ")
          (cam-slave-options->string (the-as cam-slave-options s5-1) #t)
          (format #t "~%")
          (format #t "forced off ")
          (cam-slave-options->string (the-as cam-slave-options s3-1) #t)
          (format #t "~%")
          (let ((s4-1 (logclear (logior s4-0 s5-1) s3-1)))
            (format #t "final ")
            (cam-slave-options->string (the-as cam-slave-options s4-1) #t)
            )
          (format #t "~%")
          )
        (format arg1 "  tag flags-on               0x~X                              // int32~%" s5-1)
        (format arg1 "  tag flags-off              0x~X                              // int32~%" s3-1)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-focalpull-flags ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s4-0 (res-lump-value arg2 'focalpull-flags uint128 :time -1000000000.0))
        (s5-0 (method-of-type res-lump get-property-value))
        (s1-0 arg2)
        )
    (format (clear *res-key-string*) "~S~S" 'focalpull-flags '-on)
    (let ((s5-1 (s5-0
                  s1-0
                  (string->symbol *res-key-string*)
                  'interp
                  -1000000000.0
                  (the-as uint128 0)
                  (the-as (pointer res-tag) #f)
                  *res-static-buf*
                  )
                )
          (s1-1 (method-of-type res-lump get-property-value))
          )
      (format (clear *res-key-string*) "~S~S" 'focalpull-flags '-off)
      (let ((s3-1 (s1-1
                    arg2
                    (string->symbol *res-key-string*)
                    'interp
                    -1000000000.0
                    (the-as uint128 0)
                    (the-as (pointer res-tag) #f)
                    *res-static-buf*
                    )
                  )
            )
        (when arg0
          (format #t "setup focalpull-flags ")
          (cam-index-options->string (the-as cam-index-options s4-0) #t)
          (format #t "~%")
          (format #t "forced on ")
          (cam-index-options->string (the-as cam-index-options s5-1) #t)
          (format #t "~%")
          (format #t "forced off ")
          (cam-index-options->string (the-as cam-index-options s3-1) #t)
          (format #t "~%")
          (let ((s4-1 (logclear (logior s4-0 s5-1) s3-1)))
            (format #t "final ")
            (cam-index-options->string (the-as cam-index-options s4-1) #t)
            )
          (format #t "~%")
          )
        (format arg1 "  tag focalpull-flags-on               0x~X                              // int32~%" s5-1)
        (format arg1 "  tag focalpull-flags-off              0x~X                              // int32~%" s3-1)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-campoints-flags ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s4-0 (res-lump-value arg2 'campoints-flags uint128 :time -1000000000.0))
        (s5-0 (method-of-type res-lump get-property-value))
        (s1-0 arg2)
        )
    (format (clear *res-key-string*) "~S~S" 'campoints-flags '-on)
    (let ((s5-1 (s5-0
                  s1-0
                  (string->symbol *res-key-string*)
                  'interp
                  -1000000000.0
                  (the-as uint128 0)
                  (the-as (pointer res-tag) #f)
                  *res-static-buf*
                  )
                )
          (s1-1 (method-of-type res-lump get-property-value))
          )
      (format (clear *res-key-string*) "~S~S" 'campoints-flags '-off)
      (let ((s3-1 (s1-1
                    arg2
                    (string->symbol *res-key-string*)
                    'interp
                    -1000000000.0
                    (the-as uint128 0)
                    (the-as (pointer res-tag) #f)
                    *res-static-buf*
                    )
                  )
            )
        (when arg0
          (format #t "setup campoints-flags ")
          (cam-index-options->string (the-as cam-index-options s4-0) #t)
          (format #t "~%")
          (format #t "forced on ")
          (cam-index-options->string (the-as cam-index-options s5-1) #t)
          (format #t "~%")
          (format #t "forced off ")
          (cam-index-options->string (the-as cam-index-options s3-1) #t)
          (format #t "~%")
          (let ((s4-1 (logclear (logior s4-0 s5-1) s3-1)))
            (format #t "final ")
            (cam-index-options->string (the-as cam-index-options s4-1) #t)
            )
          (format #t "~%")
          )
        (format arg1 "  tag campoints-flags-on               0x~X                              // int32~%" s5-1)
        (format arg1 "  tag campoints-flags-off              0x~X                              // int32~%" s3-1)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-introsplinetime ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f28-0 (res-lump-float arg2 'intro-time))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'intro-time '-offset)
    (let ((f30-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (cond
        ((= f28-0 0.0)
         (if arg0
             (format #t "setup intro-time 0.0 (defaults to 1 sec)~%")
             )
         (set! f28-0 1.0)
         )
        (arg0
          (format #t "setup intro-time ~f~%" f28-0)
          )
        )
      (when (!= f30-0 0.0)
        (when arg0
          (format #t "offset ~f~%" f30-0)
          (format #t "final ~f~%" (+ f28-0 f30-0))
          )
        (format arg1 "  tag intro-time-offset      SECONDS(~f)                      // float~%" f30-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-introsplineexitval ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'intro-exitValue))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'intro-exitValue '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (when arg0
        (if (= f30-0 0.0)
            (format #t "setup intro-exitValue 0.0 (defaults to 0.5)~%")
            (format #t "setup intro-exitValue ~f~%" f30-0)
            )
        )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~f~%" f28-0)
          (format #t "final ~f~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag intro-exitValue-offset ~f                               // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-interptime ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'interpTime))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'interpTime '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup interpTime ~f~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~f~%" f28-0)
          (format #t "final ~f~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag interpTime-offset     SECONDS(~f)                      // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-splineoffset ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (when (and (not (res-lump-struct arg2 'pivot structure)) (res-lump-struct arg2 'spline-offset vector))
    (let ((s5-1 (res-lump-struct arg2 'spline-offset vector)))
      (when s5-1
        (if arg0
            (format #t "spline offset ~M ~M ~M~%" (-> s5-1 x) (-> s5-1 y) (-> s5-1 z))
            )
        (format
          arg1
          "  tag spline-offset          METERS(~M) METERS(~M) METERS(~M) 1.0  // vector~%"
          (-> s5-1 x)
          (-> s5-1 y)
          (-> s5-1 z)
          )
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-spline-follow-dist-offset ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'spline-follow-dist-offset)))
    (when (the int f30-0)
      (if arg0
          (format #t "spline follow dist offset ~M~%" f30-0)
          )
      (format arg1 "  tag spline-follow-dist-offset          METERS(~M)~%" f30-0)
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-campointsoffset ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((s5-0 (res-lump-struct arg2 'campoints-offset vector)))
    (when s5-0
      (if arg0
          (format #t "index offset ~M ~M ~M~%" (-> s5-0 x) (-> s5-0 y) (-> s5-0 z))
          )
      (format
        arg1
        "  tag campoints-offset          METERS(~M) METERS(~M) METERS(~M) 1.0  // vector~%"
        (-> s5-0 x)
        (-> s5-0 y)
        (-> s5-0 z)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-tiltAdjust ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'tiltAdjust))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'tiltAdjust '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup tiltAdjust deg ~R~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~R~%" f28-0)
          (format #t "final ~R~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag tiltAdjust-offset      DEG(~R)                           // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-stringMinLength ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'stringMinLength))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'stringMinLength '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup stringMinLength ~M~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~M~%" f28-0)
          (format #t "final ~M~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag stringMinLength-offset METERS(~M)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-stringMaxLength ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'stringMaxLength))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'stringMaxLength '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup stringMaxLength ~M~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~M~%" f28-0)
          (format #t "final ~M~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag stringMaxLength-offset METERS(~M)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-stringMinHeight ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'stringMinHeight))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'stringMinHeight '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup stringMinHeight ~M~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~M~%" f28-0)
          (format #t "final ~M~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag stringMinHeight-offset METERS(~M)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-stringMaxHeight ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'stringMaxHeight))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'stringMaxHeight '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup stringMaxHeight ~M~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~M~%" f28-0)
          (format #t "final ~M~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag stringMaxHeight-offset METERS(~M)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-stringCliffHeight ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'stringCliffHeight))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'stringCliffHeight '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup stringCliffHeight ~M~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~M~%" f28-0)
          (format #t "final ~M~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag stringCliffHeight-offset METERS(~M)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

;; WARN: Return type mismatch object vs none.
(defun cam-layout-save-maxAngle ((arg0 symbol) (arg1 string) (arg2 entity-actor))
  (let ((f30-0 (res-lump-float arg2 'maxAngle))
        (s3-0 (method-of-type res-lump get-property-value-float))
        )
    (format (clear *res-key-string*) "~S~S" 'maxAngle '-offset)
    (let ((f28-0 (s3-0
                   arg2
                   (string->symbol *res-key-string*)
                   'interp
                   -1000000000.0
                   0.0
                   (the-as (pointer res-tag) #f)
                   *res-static-buf*
                   )
                 )
          )
      (if arg0
          (format #t "setup maxAngle ~R~%" f30-0)
          )
      (when (!= f28-0 0.0)
        (when arg0
          (format #t "offset ~R~%" f28-0)
          (format #t "final ~R~%" (+ f30-0 f28-0))
          )
        (format arg1 "  tag maxAngle-offset DEG(~R)                            // float~%" f28-0)
        )
      )
    )
  (none)
  )

(defbehavior clmf-save-single cam-layout ((arg0 entity-camera) (arg1 symbol) (arg2 symbol))
  (clear *temp-string*)
  (if arg2
      (format *temp-string* "db/caminfo/~s.cam" (res-lump-struct arg0 'name structure))
      (format *temp-string* "db/caminfo/garbage")
      )
  (let ((s4-2 (new 'stack 'file-stream *temp-string* 'write)))
    (if arg1
        (format #t "---------camera '~S'------------~%" (res-lump-struct arg0 'name structure))
        )
    (format s4-2 "#include /jak3/db/config/standard.m2d~%")
    (format s4-2 "camera ~s {~%" (res-lump-struct arg0 'name structure))
    (cam-layout-save-cam-rot arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-cam-trans arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-pivot arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-align arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-interesting arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-fov arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-focalpull arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-flags arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-introsplinetime arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-introsplineexitval arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-interptime arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-splineoffset arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-spline-follow-dist-offset arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-campointsoffset arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-tiltAdjust arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-stringMinLength arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-stringMaxLength arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-stringMinHeight arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-stringMaxHeight arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-stringCliffHeight arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-maxAngle arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-campoints-flags arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (cam-layout-save-focalpull-flags arg1 (the-as string s4-2) (the-as entity-actor arg0))
    (format s4-2 "}~%")
    (file-stream-close s4-2)
    )
  )

(defbehavior clmf-save-one cam-layout ((arg0 symbol))
  (let ((s5-1 (logtest? (the-as int arg0) 8))
        (gp-1 (logtest? (the-as int arg0) 16))
        )
    (if s5-1
        (format #t "~%~%~%=================================~%")
        )
    (clmf-save-single (-> self cam-entity) s5-1 gp-1)
    (if s5-1
        (format #t "===============================~%~%~%~%")
        )
    (if gp-1
        (format #t "'~S' save completed~%" (res-lump-struct (-> self cam-entity) 'name structure))
        )
    )
  #t
  )

(defbehavior clmf-save-all cam-layout ((arg0 symbol))
  (let ((s5-1 (logtest? (the-as int arg0) 8))
        (gp-1 (logtest? (the-as int arg0) 16))
        )
    (if s5-1
        (format #t "~%~%~%=================================~%")
        )
    (let ((v1-5 (-> *camera-engine* alive-list next0)))
      *camera-engine*
      (let ((s4-0 (-> v1-5 next0)))
        (while (!= v1-5 (-> *camera-engine* alive-list-end))
          (let ((a0-4 (-> (the-as connection v1-5) param1)))
            (clmf-save-single (the-as entity-camera a0-4) s5-1 gp-1)
            )
          (set! v1-5 s4-0)
          *camera-engine*
          (set! s4-0 (-> s4-0 next0))
          )
        )
      )
    (if s5-1
        (format #t "===============================~%~%~%~%")
        )
    (if gp-1
        (format #t "camera save all completed~%")
        )
    )
  #t
  )

(deftype clmf-cam-flag-toggle-info (structure)
  ((key        float)
   (force-on   int32)
   (force-off  int32)
   )
  )


(defbehavior clmf-cam-flag-toggle cam-layout ((arg0 int) (arg1 int))
  (let ((s4-0 (/ arg0 8))
        (gp-0 (new 'stack 'clmf-cam-flag-toggle-info))
        )
    (set! (-> gp-0 key) (-> self res-key))
    (cond
      ((and (= arg1 'vol-flags) (>= (-> self res-key) (the float (-> self first-cutoutvol))))
       (set! (-> gp-0 key) (- (-> gp-0 key) (the float (-> self first-cutoutvol))))
       (set! arg1 (the-as int 'cutoutvol-flags))
       )
      ((and (= arg1 'vol-flags) (>= (-> self res-key) (the float (-> self first-pvol))))
       (set! (-> gp-0 key) (- (-> gp-0 key) (the float (-> self first-pvol))))
       (set! arg1 (the-as int 'pvol-flags))
       )
      )
    (let ((s3-0 (method-of-type res-lump get-property-value))
          (s2-0 (-> self cam-entity))
          )
      (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-on)
      (set! (-> gp-0 force-on) (the-as int (s3-0
                                             s2-0
                                             (string->symbol *res-key-string*)
                                             'exact
                                             (-> gp-0 key)
                                             (the-as uint128 0)
                                             (the-as (pointer res-tag) #f)
                                             *res-static-buf*
                                             )
                                       )
            )
      )
    (let ((s3-1 (method-of-type res-lump get-property-value))
          (s2-1 (-> self cam-entity))
          )
      (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-off)
      (set! (-> gp-0 force-off) (the-as int (s3-1
                                              s2-1
                                              (string->symbol *res-key-string*)
                                              'exact
                                              (-> gp-0 key)
                                              (the-as uint128 0)
                                              (the-as (pointer res-tag) #f)
                                              *res-static-buf*
                                              )
                                        )
            )
      )
    (cond
      ((logtest? (-> gp-0 force-off) s4-0)
       (logclear! (-> gp-0 force-off) s4-0)
       (logior! (-> gp-0 force-on) s4-0)
       (let* ((s4-1 (-> self cam-entity))
              (s3-2 (method-of-object s4-1 add-32bit-data!))
              (s2-2 (logior (shl #x10000 32) (shr (shl (the-as int int32) 32) 32)))
              (s1-2 (shl (the-as int (-> gp-0 key)) 32))
              )
         (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-off)
         (s3-2
           s4-1
           (the-as
             res-tag
             (make-u128 s2-2 (logior s1-2 (shr (shl (the-as int (string->symbol *res-key-string*)) 32) 32)))
             )
           (-> gp-0 force-off)
           )
         )
       (let* ((s4-2 (-> self cam-entity))
              (s3-3 (method-of-object s4-2 add-32bit-data!))
              (s2-3 (logior (shl #x10000 32) (shr (shl (the-as int int32) 32) 32)))
              (s1-3 (shl (the-as int (-> gp-0 key)) 32))
              )
         (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-on)
         (s3-3
           s4-2
           (the-as
             res-tag
             (make-u128 s2-3 (logior s1-3 (shr (shl (the-as int (string->symbol *res-key-string*)) 32) 32)))
             )
           (-> gp-0 force-on)
           )
         )
       )
      ((logtest? (-> gp-0 force-on) s4-0)
       (logclear! (-> gp-0 force-on) s4-0)
       (let* ((s4-3 (-> self cam-entity))
              (s3-4 (method-of-object s4-3 add-32bit-data!))
              (s2-4 (logior (shl #x10000 32) (shr (shl (the-as int int32) 32) 32)))
              (s1-4 (shl (the-as int (-> gp-0 key)) 32))
              )
         (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-on)
         (s3-4
           s4-3
           (the-as
             res-tag
             (make-u128 s2-4 (logior s1-4 (shr (shl (the-as int (string->symbol *res-key-string*)) 32) 32)))
             )
           (-> gp-0 force-on)
           )
         )
       )
      (else
        (logior! (-> gp-0 force-off) s4-0)
        (let* ((s4-4 (-> self cam-entity))
               (s3-5 (method-of-object s4-4 add-32bit-data!))
               (s2-5 (logior (shl #x10000 32) (shr (shl (the-as int int32) 32) 32)))
               (s1-5 (shl (the-as int (-> gp-0 key)) 32))
               )
          (format (clear *res-key-string*) "~S~S" (the-as object arg1) '-off)
          (s3-5
            s4-4
            (the-as
              res-tag
              (make-u128 s2-5 (logior s1-5 (shr (shl (the-as int (string->symbol *res-key-string*)) 32) 32)))
              )
            (-> gp-0 force-off)
            )
          )
        )
      )
    )
  #t
  )

(defbehavior clmf-cam-flag cam-layout ((arg0 string) (arg1 uint) (arg2 uint))
  (let ((s5-0 (/ (the-as int arg1) 8))
        (f30-0 (-> self res-key))
        )
    (cond
      ((and (= arg2 'vol-flags) (>= (-> self res-key) (the float (-> self first-cutoutvol))))
       (set! f30-0 (- f30-0 (the float (-> self first-cutoutvol))))
       (set! arg2 (the-as uint 'cutoutvol-flags))
       )
      ((and (= arg2 'vol-flags) (>= (-> self res-key) (the float (-> self first-pvol))))
       (set! f30-0 (- f30-0 (the float (-> self first-pvol))))
       (set! arg2 (the-as uint 'pvol-flags))
       )
      )
    (let ((s3-0 (method-of-type res-lump get-property-value))
          (s2-0 (-> self cam-entity))
          )
      (format (clear *res-key-string*) "~S~S" (the-as object arg2) '-off)
      (cond
        ((logtest? (s3-0
                     s2-0
                     (string->symbol *res-key-string*)
                     'exact
                     f30-0
                     (the-as uint128 0)
                     (the-as (pointer res-tag) #f)
                     *res-static-buf*
                     )
                   s5-0
                   )
         (format arg0 ": off")
         )
        ((let ((s3-1 (method-of-type res-lump get-property-value))
               (s2-1 (-> self cam-entity))
               )
           (format (clear *res-key-string*) "~S~S" (the-as object arg2) '-on)
           (logtest? (s3-1
                       s2-1
                       (string->symbol *res-key-string*)
                       'exact
                       f30-0
                       (the-as uint128 0)
                       (the-as (pointer res-tag) #f)
                       *res-static-buf*
                       )
                     s5-0
                     )
           )
         (format arg0 ": on")
         )
        ((not (logtest? ((method-of-type res-lump get-property-value)
                         (-> self cam-entity)
                         (the-as symbol arg2)
                         'exact
                         f30-0
                         (the-as uint128 0)
                         (the-as (pointer res-tag) #f)
                         *res-static-buf*
                         )
                        s5-0
                        )
              )
         (format arg0 ": off(maya)")
         )
        (else
          (format arg0 ": on(maya)")
          )
        )
      )
    )
  #t
  )

(defbehavior clmf-cam-float-adjust cam-layout ((arg0 symbol) (arg1 (pointer float)))
  (cam-layout-print 16 *camera-layout-message-ypos* "left stick adjusts value")
  (set! *camera-layout-message-ypos* (+ *camera-layout-message-ypos* 14))
  (let ((f30-0 (res-lump-float (-> self cam-entity) arg0))
        (f0-0 (-> arg1 0))
        )
    (if (= f0-0 0.0)
        (set! f0-0 1.0)
        )
    (let ((f0-2 (+ f30-0 (analog-input (the-as int (-> *cpad-list* cpads 0 leftx)) 128.0 48.0 110.0 f0-0))))
      (add-32bit-data!
        (-> self cam-entity)
        (new 'static 'res-tag :name arg0 :key-frame -1000000000.0 :elt-count #x1 :elt-type float)
        f0-2
        )
      )
    )
  (set-setting! 'master-options 'set 0.0 32)
  #t
  )

(defbehavior clmf-cam-meters cam-layout ((arg0 meters) (arg1 symbol))
  (let ((f0-0 (cam-slave-get-float (-> self cam-entity) arg1 0.0)))
    (format arg0 ": ~M" f0-0)
    )
  #t
  )

(defbehavior clmf-cam-fov cam-layout ((arg0 degrees) (arg1 symbol))
  (format arg0 ": ~R" (cam-slave-get-fov (-> self cam-entity)))
  #t
  )

(defbehavior clmf-cam-deg cam-layout ((arg0 degrees) (arg1 symbol))
  (format arg0 ": ~R" (cam-slave-get-float (-> self cam-entity) arg1 0.0))
  #t
  )

(defbehavior clmf-cam-intro-time cam-layout ((arg0 float) (arg1 symbol))
  (let ((f30-0 (cam-slave-get-intro-step (-> self cam-entity))))
    (format arg0 ": ~f" (/ 0.016666668 f30-0))
    (set! (-> *CAM_LAYOUT-bank* intro-step) f30-0)
    )
  #t
  )

(defbehavior clmf-cam-interp-time cam-layout ((arg0 float) (arg1 symbol))
  (format arg0 ": ~f" (cam-slave-get-interp-time (-> self cam-entity)))
  #t
  )

(defbehavior clmf-cam-float cam-layout ((arg0 float) (arg1 symbol))
  (format arg0 ": ~f" (cam-slave-get-float (-> self cam-entity) arg1 0.0))
  #t
  )

(defbehavior clmf-cam-string cam-layout ((arg0 string) (arg1 symbol))
  (local-vars (sv-16 res-tag))
  (format arg0 ":")
  (set! sv-16 (new 'static 'res-tag))
  (let ((s5-1 (res-lump-data (-> self cam-entity) arg1 pointer :tag-ptr (& sv-16))))
    (when s5-1
      (dotimes (s4-0 (the-as int (-> sv-16 elt-count)))
        (format arg0 " ~S" (-> (the-as (pointer uint32) (&+ s5-1 (* s4-0 4)))))
        )
      )
    )
  #t
  )

(define *clm-focalpull-attr*
  (new 'static 'clm
    :title "---focalpull attributes--"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "    ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func '*clm-edit*
          )
        )
      (new 'static 'clm-item
        :description "adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "radial    "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 16
            :val-parm1 'focalpull-flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 16
                :parm1 'focalpull-flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "spherical "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 8
            :val-parm1 'focalpull-flags
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :options (clm-item-action-options clm0)
                                                              :func 'clmf-cam-flag-toggle
                                                              :parm0 8
                                                              :parm1 'focalpull-flags
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-index-attr*
  (new 'static 'clm
    :title "---index attributes--"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "    ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func '*clm-edit*
          )
        )
      (new 'static 'clm-item
        :description "adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "radial    "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 16
            :val-parm1 'campoints-flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 16
                :parm1 'campoints-flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "spherical "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 8
            :val-parm1 'campoints-flags
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :options (clm-item-action-options clm0)
                                                              :func 'clmf-cam-flag-toggle
                                                              :parm0 8
                                                              :parm1 'campoints-flags
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-intro-attr*
  (new 'static 'clm
    :title "---intro attributes--"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "    ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func '*clm-edit*
          )
        )
      (new 'static 'clm-item
        :description "adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "time     "
            :track-val #f
            :val-func 'clmf-cam-intro-time
            :val-parm0-sym 'intro-time
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'intro-time-offset
                :parm1-basic (new 'static 'bfloat :data 0.01)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "exitValue"
            :track-val #f
            :val-func 'clmf-cam-float
            :val-parm0-sym 'intro-exitValue
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :func 'clmf-cam-float-adjust
                                                              :parm0-sym 'intro-exitValue-offset
                                                              :parm1-basic (new 'static 'bfloat :data 0.001)
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-spline-attr*
  (new 'static 'clm
    :title "---spline attributes--"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "    ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func '*clm-edit*
          )
        )
      (new 'static 'clm-item
        :description "adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "followDist"
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'spline-follow-dist
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :func 'clmf-cam-float-adjust
                                                              :parm0-sym 'spline-follow-dist-offset
                                                              :parm1-basic (new 'static 'bfloat :data 409.6)
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-cam-attr*
  (new 'static 'clm
    :title "---camera attributes--"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "    ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func '*clm-edit*
          )
        )
      (new 'static 'clm-item
        :description "adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "drag       "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x400
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x400
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "fov        "
            :track-val #f
            :val-func 'clmf-cam-fov
            :val-parm0-sym 'fov
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'fov-offset
                :parm1-basic (new 'static 'bfloat :data 91.022224)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "focalpull  "
            :track-val #f
            :val-func 'clmf-cam-deg
            :val-parm0-sym 'focalpull
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'focalpull-offset
                :parm1-basic (new 'static 'bfloat :data 91.022224)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "interpTime "
            :track-val #f
            :val-func 'clmf-cam-interp-time
            :val-parm0-sym 'interpTime
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'interpTime-offset
                :parm1-basic (new 'static 'bfloat :data 0.01)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "sameSide   "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 16
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 16
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "spherical  "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 32
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 32
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "MinLength  "
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'stringMinLength
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'stringMinLength-offset
                :parm1-basic (new 'static 'bfloat :data 409.6)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "MaxLength  "
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'stringMaxLength
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'stringMaxLength-offset
                :parm1-basic (new 'static 'bfloat :data 409.6)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "MinHeight  "
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'stringMinHeight
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'stringMinHeight-offset
                :parm1-basic (new 'static 'bfloat :data 409.6)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "MaxHeight  "
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'stringMaxHeight
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'stringMaxHeight-offset
                :parm1-basic (new 'static 'bfloat :data 409.6)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "cliffHeight"
            :track-val #f
            :val-func 'clmf-cam-meters
            :val-parm0-sym 'stringCliffHeight
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'stringCliffHeight-offset
                :parm1-basic (new 'static 'bfloat :data 409.6)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "alternates "
            :track-val #f
            :val-func 'clmf-cam-string
            :val-parm0-sym 'alternates
            :actions (new 'static 'boxed-array :type clm-item-action)
            )
          (new 'static 'clm-list-item
            :description "maxAngle   "
            :track-val #f
            :val-func 'clmf-cam-deg
            :val-parm0-sym 'maxAngle
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'maxAngle-offset
                :parm1-basic (new 'static 'bfloat :data 91.022224)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "shrinkAngle"
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x4000
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x4000
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "noRotate   "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x20000
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x20000
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "tiltAdjust "
            :track-val #f
            :val-func 'clmf-cam-deg
            :val-parm0-sym 'tiltAdjust
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :func 'clmf-cam-float-adjust
                :parm0-sym 'tiltAdjust-offset
                :parm1-basic (new 'static 'bfloat :data 91.022224)
                )
              )
            )
          (new 'static 'clm-list-item
            :description "stickyAngle"
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x40000
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x40000
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "easeSpline "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x1000000
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x1000000
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "jumpPitch  "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x80
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-cam-flag-toggle
                :parm0 #x80
                :parm1 'flags
                )
              )
            )
          (new 'static 'clm-list-item
            :description "rapid      "
            :track-val #f
            :val-func 'clmf-cam-flag
            :val-parm0 #x800000
            :val-parm1 'flags
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :options (clm-item-action-options clm0)
                                                              :func 'clmf-cam-flag-toggle
                                                              :parm0 #x800000
                                                              :parm1 'flags
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-cam-lookthrough*
  (new 'static 'clm
    :title "---cam-lookthrough---"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "       "
        :button-symbol 'x
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 x)
          :options (clm-item-action-options clm2)
          :func 'clmf-look-through
          )
        )
      (new 'static 'clm-item
        :description "     ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func 'clmf-to-edit
          )
        )
      (new 'static 'clm-item
        :description "pos/rot"
        :button-symbol 'x
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 x)
          :options (clm-item-action-options clm3)
          :func 'clmf-pos-rot
          :parm0-sym 'trans-offset
          :parm1 'rot-offset
          )
        )
      (new 'static 'clm-item
        :description " adjust"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func #f)
        )
      (new 'static 'clm-list
        :tracker #f
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "fov"
            :track-val #f
            :val-func 'clmf-cam-fov
            :val-parm0-sym 'fov
            :actions (new 'static 'boxed-array :type clm-item-action (new 'static 'clm-item-action
                                                              :button (pad-buttons-u64 x)
                                                              :func 'clmf-cam-float-adjust
                                                              :parm0-sym 'fov-offset
                                                              :parm1-basic (new 'static 'bfloat :data 91.022224)
                                                              )
                                                            )
            )
          )
        )
      )
    )
  )

(define *clm-edit*
  (new 'static 'clm
    :title "---edit---"
    :items (new 'static 'boxed-array :type clm-basic
      (new 'static 'clm-item
        :description "        ok"
        :button-symbol 'square
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 square)
          :options (clm-item-action-options clm0)
          :func 'clmf-to-select
          )
        )
      (new 'static 'clm-item
        :description "attributes"
        :button-symbol 'x
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 x) :options (clm-item-action-options clm0) :func #f)
        )
      (new 'static 'clm-item
        :description " edit part"
        :button-symbol 'circle
        :action (new 'static 'clm-item-action
          :button (pad-buttons-u64 circle)
          :options (clm-item-action-options clm0)
          :func #f
          )
        )
      (new 'static 'clm-item
        :description "scale/next"
        :button-symbol 'r2
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func #f)
        )
      (new 'static 'clm-item
        :description "   pos/rot"
        :button-symbol 'l2
        :action (new 'static 'clm-item-action :button (pad-buttons-u64 l2) :func #f)
        )
      (new 'static 'clm-list
        :tracker '*camera-layout-blink*
        :items (new 'static 'boxed-array :type clm-list-item
          (new 'static 'clm-list-item
            :description "camera   "
            :track-val 'camera
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func '*clm-cam-attr*
                )
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func '*clm-cam-lookthrough*)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-bna)
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 l2)
                :func 'clmf-pos-rot
                :parm0-sym 'trans-offset
                :parm1 'rot-offset
                )
              )
            )
          (new 'static 'clm-list-item
            :description "align    "
            :track-val 'align
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-bna)
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 l2)
                :func 'clmf-pos-rot
                :parm0-sym 'align-offset
                :parm1 #f
                )
              )
            )
          (new 'static 'clm-list-item
            :description "pivot    "
            :track-val 'pivot
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-bna)
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 l2)
                :func 'clmf-pos-rot
                :parm0-sym 'pivot-offset
                :parm1 #f
                )
              )
            )
          (new 'static 'clm-list-item
            :description "interesting"
            :track-val 'interesting
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action :button (pad-buttons-u64 x) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-bna)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-bna)
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 l2)
                :func 'clmf-pos-rot
                :parm0-sym 'interesting-offset
                :parm1 #f
                )
              )
            )
          (new 'static 'clm-list-item
            :description "spline   "
            :track-val 'spline
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-to-spline-attr
                )
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-implement)
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 l2)
                :func 'clmf-pos-rot
                :parm0-sym 'spline-offset
                :parm1 #f
                )
              )
            )
          (new 'static 'clm-list-item
            :description "intro    "
            :track-val 'intro
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-to-intro-attr
                )
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 l2) :func 'clmf-implement)
              )
            )
          (new 'static 'clm-list-item
            :description "index    "
            :track-val 'index
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-to-index-attr
                )
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 l2) :func 'clmf-pos-rot :parm0-sym 'campoints-offset)
              )
            )
          (new 'static 'clm-list-item
            :description "focalpull"
            :track-val 'focalpull
            :val-func #f
            :actions (new 'static 'boxed-array :type clm-item-action
              (new 'static 'clm-item-action
                :button (pad-buttons-u64 x)
                :options (clm-item-action-options clm0)
                :func 'clmf-to-focalpull-attr
                )
              (new 'static 'clm-item-action :button (pad-buttons-u64 circle) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 r2) :func 'clmf-implement)
              (new 'static 'clm-item-action :button (pad-buttons-u64 l2) :func 'clmf-implement)
              )
            )
          )
        )
      )
    )
  )

(define *clm-save-all*
  (new 'static 'clm :title "---save all?---" :items (new 'static 'boxed-array :type clm-basic
                                                      (new 'static 'clm-item
                                                        :description " save all"
                                                        :button-symbol 'x
                                                        :action (new 'static 'clm-item-action
                                                          :button (pad-buttons-u64 x)
                                                          :options (clm-item-action-options clm0)
                                                          :func 'clmf-save-all
                                                          :parm0 16
                                                          )
                                                        )
                                                      (new 'static 'clm-item
                                                        :description "print all"
                                                        :button-symbol 'square
                                                        :action (new 'static 'clm-item-action
                                                          :button (pad-buttons-u64 square)
                                                          :options (clm-item-action-options clm0)
                                                          :func 'clmf-save-all
                                                          :parm0 8
                                                          )
                                                        )
                                                      (new 'static 'clm-item
                                                        :description "     done"
                                                        :button-symbol 'triangle
                                                        :action (new 'static 'clm-item-action
                                                          :button (pad-buttons-u64 triangle)
                                                          :options (clm-item-action-options clm0)
                                                          :func 'clmf-to-select
                                                          )
                                                        )
                                                      )
                    )
  )

(define *clm-save-one*
  (new 'static 'clm :title "---single save?---" :items (new 'static 'boxed-array :type clm-basic
                                                         (new 'static 'clm-item
                                                           :description " single save"
                                                           :button-symbol 'x
                                                           :action (new 'static 'clm-item-action
                                                             :button (pad-buttons-u64 x)
                                                             :options (clm-item-action-options clm0)
                                                             :func 'clmf-save-one
                                                             :parm0 16
                                                             )
                                                           )
                                                         (new 'static 'clm-item
                                                           :description "single print"
                                                           :button-symbol 'square
                                                           :action (new 'static 'clm-item-action
                                                             :button (pad-buttons-u64 square)
                                                             :options (clm-item-action-options clm0)
                                                             :func 'clmf-save-one
                                                             :parm0 8
                                                             )
                                                           )
                                                         (new 'static 'clm-item
                                                           :description "        done"
                                                           :button-symbol 'triangle
                                                           :action (new 'static 'clm-item-action
                                                             :button (pad-buttons-u64 triangle)
                                                             :options (clm-item-action-options clm0)
                                                             :func 'clmf-to-select
                                                             )
                                                           )
                                                         )
                    )
  )

(define *clm-select*
  (new 'static 'clm :title "---camera---" :items (new 'static 'boxed-array :type clm-basic
                                                   (new 'static 'clm-item
                                                     :description "    edit"
                                                     :button-symbol 'x
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 x)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func 'clmf-to-edit-cam
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "save one"
                                                     :button-symbol 'triangle
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 triangle)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func '*clm-save-one*
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "    quit"
                                                     :button-symbol 'circle
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 circle)
                                                       :options (clm-item-action-options clm0 clm4)
                                                       :func 'cam-layout-stop
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "    next"
                                                     :button-symbol 'down
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 down)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func 'clmf-next-entity
                                                       :parm0 8
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "    prev"
                                                     :button-symbol 'up
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 up)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func 'clmf-next-entity
                                                       :parm0 -8
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "  next 5"
                                                     :button-symbol 'right
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 right)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func 'clmf-next-entity
                                                       :parm0 40
                                                       )
                                                     )
                                                   (new 'static 'clm-item
                                                     :description "  prev 5"
                                                     :button-symbol 'left
                                                     :action (new 'static 'clm-item-action
                                                       :button (pad-buttons-u64 left)
                                                       :options (clm-item-action-options clm0 clm1)
                                                       :func 'clmf-next-entity
                                                       :parm0 -40
                                                       )
                                                     )
                                                   )
                    )
  )

(define *clm* *clm-select*)

(defbehavior cam-layout-do-action cam-layout ((arg0 clm-item-action))
  (let ((s5-0 (-> arg0 func value)))
    (cond
      ((not s5-0)
       #f
       )
      ((zero? s5-0)
       #f
       )
      ((and (not (-> self cam-entity)) (logtest? (-> arg0 options) (clm-item-action-options clm1)))
       #f
       )
      ((and (logtest? (-> arg0 options) (clm-item-action-options clm3))
            (logtest? (the-as pad-buttons-u64 (-> *cpad-list* cpads 0 button0-abs 0)) (-> arg0 button))
            )
       #f
       )
      ((and (not (logtest? (-> arg0 options) (clm-item-action-options clm2 clm3 clm4)))
            (logtest? (-> arg0 options) (clm-item-action-options clm0))
            (not (logtest? (the-as pad-buttons-u64 (-> *cpad-list* cpads 0 button0-rel 0)) (-> arg0 button)))
            )
       #f
       )
      ((and (not (logtest? (-> arg0 options) (clm-item-action-options clm0 clm2 clm3 clm4)))
            (not (logtest? (the-as pad-buttons-u64 (-> *cpad-list* cpads 0 button0-abs 0)) (-> arg0 button)))
            )
       #f
       )
      ((and (logtest? (-> arg0 options) (clm-item-action-options clm4))
            (let ((a1-3 (-> *cpad-list* cpads 0)))
              (not (logtest? (the-as pad-buttons-u64 (logclear (-> a1-3 button0-abs 1) (-> a1-3 button0-abs 0)))
                             (-> arg0 button)
                             )
                   )
              )
            )
       #f
       )
      ((type? s5-0 clm)
       (set! *clm* (the-as clm s5-0))
       #t
       )
      ((type? s5-0 function)
       ((the-as (function int symbol object) s5-0) (-> arg0 parm0) (-> arg0 parm1))
       )
      )
    )
  )

(defbehavior cam-layout-function-call cam-layout ((arg0 symbol) (arg1 string) (arg2 int) (arg3 basic))
  (let ((gp-0 (-> arg0 value)))
    (cond
      ((not gp-0)
       )
      ((zero? gp-0)
       )
      ((type? gp-0 function)
       ((the-as (function string int basic object) gp-0) arg1 arg2 arg3)
       )
      )
    )
  #f
  )

(defbehavior cam-layout-do-menu cam-layout ((arg0 clm))
  (set! *camera-layout-message-ypos* 30)
  (+! (-> *CAM_LAYOUT-bank* spline-t) (-> *CAM_LAYOUT-bank* spline-step))
  (if (< 1.01 (-> *CAM_LAYOUT-bank* spline-t))
      (set! (-> *CAM_LAYOUT-bank* spline-t) -0.09)
      )
  (+! (-> *CAM_LAYOUT-bank* intro-t) (-> *CAM_LAYOUT-bank* intro-step))
  (if (< 1.01 (-> *CAM_LAYOUT-bank* intro-t))
      (set! (-> *CAM_LAYOUT-bank* intro-t) -0.09)
      )
  (let ((s5-0 30))
    (let ((s4-0 (cam-state-from-entity (-> self cam-entity))))
      (set-setting! 'master-options 'clear 0.0 32)
      (let ((s3-0 (-> self cam-entity)))
        (clear *temp-string*)
        (if s3-0
            (format *temp-string* "\"~S\"~%" (res-lump-struct s3-0 'name structure))
            )
        )
      (if (not s4-0)
          (format *temp-string* "no cameras in this level")
          (format *temp-string* "~S" (-> s4-0 name))
          )
      )
    (cam-layout-print 320 s5-0 *temp-string*)
    (let ((s5-1 (+ s5-0 28)))
      (clear *temp-string*)
      (format *temp-string* "~S~%" (-> arg0 title))
      (cam-layout-print 320 s5-1 *temp-string*)
      (let ((s4-1 (+ s5-1 14)))
        (dotimes (s5-2 (-> arg0 items length))
          (cond
            ((type? (-> arg0 items s5-2) clm-list)
             (clear *temp-string*)
             (format *temp-string* "------------")
             (cam-layout-print 320 s4-1 *temp-string*)
             (let ((s4-2 (+ s4-1 14)))
               (let ((s3-1 (the-as clm-list (-> arg0 items s5-2))))
                 (dotimes (s2-1 (-> s3-1 items length))
                   (clear *temp-string*)
                   (format
                     *temp-string*
                     "~S~S"
                     (if (= s2-1 (-> s3-1 cur-list-item))
                         "> "
                         "  "
                         )
                     (-> s3-1 items s2-1 description)
                     )
                   (cam-layout-function-call
                     (-> s3-1 items s2-1 val-func)
                     *temp-string*
                     (-> s3-1 items s2-1 val-parm0)
                     (the-as basic (-> s3-1 items s2-1 val-parm1))
                     )
                   (cam-layout-print 320 s4-2 *temp-string*)
                   (+! s4-2 14)
                   )
                 )
               (clear *temp-string*)
               (format *temp-string* "------------")
               (cam-layout-print 320 s4-2 *temp-string*)
               (set! s4-1 (+ s4-2 14))
               )
             )
            ((and (not (-> self cam-entity))
                  (logtest? (-> (the-as clm-item (-> arg0 items s5-2)) action options) (clm-item-action-options clm1))
                  )
             )
            ((logtest? (-> (the-as clm-item (-> arg0 items s5-2)) action options) (clm-item-action-options clm2))
             )
            (else
              (let ((s3-2 (-> arg0 items s5-2)))
                (clear *temp-string*)
                (format
                  *temp-string*
                  "~S: ~A~%"
                  (-> (the-as clm-item s3-2) description)
                  (if (logtest? (-> (the-as clm-item (-> arg0 items s5-2)) action options) (clm-item-action-options clm3))
                      'default
                      (-> (the-as clm-item s3-2) button-symbol)
                      )
                  )
                )
              (cam-layout-print 320 s4-1 *temp-string*)
              (+! s4-1 14)
              )
            )
          )
        )
      )
    )
  (if (= *master-mode* 'menu)
      (goto cfg-65)
      )
  (dotimes (s5-3 (-> arg0 items length))
    (cond
      ((type? (-> arg0 items s5-3) clm-list)
       (let ((s4-3 (-> arg0 items s5-3))
             (s3-3 0)
             )
         (if (-> (the-as clm-list s4-3) tracker)
             (set! (-> (the-as clm-list s4-3) tracker value)
                   (-> (the-as clm-list s4-3) items (-> (the-as clm-list s4-3) cur-list-item) track-val)
                   )
             )
         (dotimes (s2-2 (-> (the-as clm-list s4-3) items (-> (the-as clm-list s4-3) cur-list-item) actions length))
           (if (cam-layout-do-action
                 (-> (the-as clm-list s4-3) items (-> (the-as clm-list s4-3) cur-list-item) actions s2-2)
                 )
               (goto cfg-65)
               )
           )
         (cond
           ((cpad-pressed? 0 down)
            (set! s3-3 1)
            )
           ((cpad-pressed? 0 right)
            (set! s3-3 1)
            )
           ((cpad-pressed? 0 up)
            (set! s3-3 -1)
            )
           ((cpad-pressed? 0 left)
            (set! s3-3 -1)
            )
           )
         (when (nonzero? s3-3)
           (set! (-> (the-as clm-list s4-3) cur-list-item)
                 (mod (+ (-> (the-as clm-list s4-3) cur-list-item) s3-3) (-> (the-as clm-list s4-3) items length))
                 )
           (while (< (-> (the-as clm-list s4-3) cur-list-item) 0)
             (+! (-> (the-as clm-list s4-3) cur-list-item) (-> (the-as clm-list s4-3) items length))
             )
           (goto cfg-65)
           )
         )
       )
      ((cam-layout-do-action (-> (the-as clm-item (-> arg0 items s5-3)) action))
       (goto cfg-65)
       )
      )
    )
  (label cfg-65)
  #f
  )

(defstate cam-layout-active (cam-layout)
  :code (behavior ()
    (until #f
      (cam-layout-entity-info (the-as entity-actor (-> self cam-entity)))
      (cam-layout-do-menu *clm*)
      (suspend)
      )
    #f
    )
  )

(defbehavior cam-layout-init cam-layout ()
  (set! (-> self res-key) -1000000000.0)
  (set! (-> self num-entities) 0)
  (let ((v1-2 (-> *camera-engine* alive-list next0)))
    *camera-engine*
    (let ((a0-2 (-> v1-2 next0)))
      (while (!= v1-2 (-> *camera-engine* alive-list-end))
        (-> (the-as connection v1-2) param1)
        (+! (-> self num-entities) 1)
        (set! v1-2 a0-2)
        *camera-engine*
        (set! a0-2 (-> a0-2 next0))
        )
      )
    )
  (set! (-> self cur-entity) *last-cur-entity*)
  (clmf-next-entity 0)
  (set! *clm* *clm-select*)
  (go cam-layout-active)
  )

(defun cam-layout-stop ()
  (set! *cam-layout* #f)
  (kill-by-name "cam-layout" *active-pool*)
  )

(defun cam-layout-start ()
  (let ((a0-1 (new 'global 'file-stream "dd_next/caminfo/garbage" 'read)))
    (file-stream-close a0-1)
    )
  (cond
    ((not *cam-layout*)
     (let ((v1-4 (process-spawn-function cam-layout cam-layout-init :name "cam-layout" :from *camera-dead-pool*)))
       (cond
         (v1-4
           (logclear! (-> v1-4 0 mask) (process-mask freeze pause menu))
           (set! *cam-layout* #t)
           (set! *camera-layout-blink* #f)
           )
         (else
           (format 0 "ERROR <GMJ>: no process available to start cam editing mode~%")
           )
         )
       )
     )
    (else
      (format 0 "ERROR <GMJ>: cam editing mode already started~%")
      )
    )
  *cam-layout*
  )

(defun cam-layout-restart ()
  (cam-layout-stop)
  (cam-layout-start)
  )
