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

;; definition of type path-control
(deftype path-control (basic)
  ((flags      path-control-flag             :offset-assert   4)
   (name       symbol                        :offset-assert   8)
   (process    process-drawable              :offset-assert  12)
   (curve      curve                 :inline :offset-assert  16)
   (num-cverts int32                         :offset         20)
   (cverts     (inline-array vector)         :offset         16)
   )
  :method-count-assert 21
  :size-assert         #x24
  :flag-assert         #x1500000024
  (:methods
    (new (symbol type process symbol float) _type_ 0)
    (dummy-9 (_type_) none 9)
    (eval-path-curve-div! (_type_ vector float symbol) vector 10)
    (get-random-point (_type_ vector) vector 11)
    (TODO-RENAME-12 (_type_ vector float) vector 12)
    (eval-path-curve! (_type_ vector float symbol) vector 13)
    (TODO-RENAME-14 (_type_ vector float) vector 14)
    (length-as-float (_type_) float 15)
    (path-distance (_type_) float 16)
    (get-num-verts (_type_) int 17)
    (should-display? (_type_) symbol 18)
    (TODO-RENAME-19 (_type_) float 19)
    (TODO-RENAME-20 (_type_) float 20)
    )
  )

;; definition for method 3 of type path-control
(defmethod inspect path-control ((obj path-control))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tflags: #x~X~%" (-> obj flags))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tprocess: ~A~%" (-> obj process))
  (format #t "~Tcurve: #<curve @ #x~X>~%" (&-> obj cverts))
  (format #t "~Tnum-cverts: ~D~%" (-> obj curve num-cverts))
  (format #t "~Tcverts: #x~X~%" (-> obj cverts))
  obj
  )

;; definition of type curve-control
(deftype curve-control (path-control)
  ()
  :method-count-assert 21
  :size-assert         #x24
  :flag-assert         #x1500000024
  (:methods
    (new (symbol type process symbol float) _type_ 0)
    )
  )

;; definition for method 3 of type curve-control
(defmethod inspect curve-control ((obj curve-control))
  (format #t "[~8x] ~A~%" obj (-> obj type))
  (format #t "~Tflags: #x~X~%" (-> obj flags))
  (format #t "~Tname: ~A~%" (-> obj name))
  (format #t "~Tprocess: ~A~%" (-> obj process))
  (format #t "~Tcurve: #<curve @ #x~X>~%" (&-> obj cverts))
  (format #t "~Tnum-cverts: ~D~%" (-> obj curve num-cverts))
  (format #t "~Tcverts: #x~X~%" (-> obj cverts))
  obj
  )

;; definition for method 0 of type path-control
;; INFO: Return type mismatch object vs path-control.
;; Used lq/sq
(defmethod new path-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
  (local-vars (tag res-tag))
  (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
    (when (zero? obj)
      (go process-drawable-art-error "memory")
      (set! obj (the-as path-control 0))
      (goto cfg-9)
      )
    (set! (-> obj process) (the-as process-drawable proc))
    (set! (-> obj name) name)
    (let ((ent (-> proc entity)))
      (when (= name 'path)
        (let ((lookup-entity (entity-actor-lookup ent 'path-actor 0)))
          (if lookup-entity
              (set! ent lookup-entity)
              )
          )
        )
      (set! tag (new 'static 'res-tag))
      (let ((data (res-lump-data ent name pointer :tag-ptr (& tag) :time time)))
        (cond
          (data
            (set! (-> obj cverts) (the-as (inline-array vector) data))
            (set! (-> obj curve num-cverts) (the-as int (-> tag elt-count)))
            )
          (else
            (logior! (-> obj flags) (path-control-flag not-found))
            (set! (-> obj cverts) (the-as (inline-array vector) #f))
            (set! (-> obj curve num-cverts) 0)
            0
            )
          )
        )
      )
    (label cfg-9)
    (the-as path-control obj)
    )
  )

;; definition for method 18 of type path-control
(defmethod should-display? path-control ((obj path-control))
  (and *display-path-marks* (logtest? (-> obj flags) (path-control-flag display)))
  )

;; definition for method 15 of type path-control
(defmethod length-as-float path-control ((obj path-control))
  (the float (+ (-> obj curve num-cverts) -1))
  )

;; definition for method 17 of type path-control
(defmethod get-num-verts path-control ((obj path-control))
  (-> obj curve num-cverts)
  )

;; definition for method 0 of type curve-control
(defmethod new curve-control ((allocation symbol) (type-to-make type) (proc process) (name symbol) (time float))
  (let ((obj (object-new allocation type-to-make (the-as int (-> type-to-make size)))))
    (set! (-> obj process) (the-as process-drawable proc))
    (set! (-> obj name) name)
    (let* ((ent (-> proc entity))
           (v1-2 name)
           (s2-0 (cond
                   ((= v1-2 'path)
                    'path-k
                    )
                   (else
                     (let ((s2-1 string->symbol))
                       (format (clear *temp-string*) "~A-k" name)
                       (s2-1 *temp-string*)
                       )
                     )
                   )
                 )
           )
      (let ((lookup-entity (entity-actor-lookup ent 'path-actor 0)))
        (if lookup-entity
            (set! ent lookup-entity)
            )
        )
      (when (not (get-curve-data! ent (the-as curve (&-> obj cverts)) name s2-0 time))
        (cond
          ((> (-> obj curve num-cverts) 0)
           (set! (-> obj type) path-control)
           )
          (else
            (logior! (-> obj flags) (path-control-flag not-found))
            (set! (-> obj cverts) (the-as (inline-array vector) #f))
            (set! (-> obj curve num-cverts) 0)
            0
            )
          )
        )
      )
    obj
    )
  )

;; failed to figure out what this is:
0
