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

;; definition for function plane-volume-intersect-dist
(defun plane-volume-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
        )
    )
  )

;; definition for method 9 of type plane-volume
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; WARN: Stack slot offset 148 signed mismatch
;; Used lq/sq
(defmethod dummy-9 plane-volume ((obj plane-volume) (arg0 symbol) (arg1 vector-array) (arg2 vector-array))
  (local-vars
    (sv-144 vector)
    (sv-148 float)
    (sv-152 int)
    (sv-160 vector)
    (sv-176 vector)
    (sv-192 vector)
    (sv-208 vector)
    (sv-224 vector)
    (sv-240 int)
    (sv-256 int)
    )
  (set! (-> obj volume-type) arg0)
  (set! (-> obj point-count) 0)
  (set! (-> obj first-point) (the-as (pointer vector) (-> arg1 data (-> arg1 length))))
  (set! (-> obj normal-count) 0)
  (set! (-> obj first-normal) (the-as (pointer vector) (-> arg2 data (-> arg2 length))))
  (dotimes (s3-0 (-> obj num-planes))
    (set! sv-176 (new 'stack-no-clear 'vector))
    (set! (-> sv-176 quad) (the-as uint128 0))
    (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))
    0.0
    0.0
    0.0
    (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0))
    (let ((s1-0 (new-stack-vector0))
          (s0-0 0)
          (s2-0 (-> obj plane))
          )
      (set! sv-240 0)
      (while (< sv-240 (-> obj num-planes))
        (when (!= s3-0 sv-240)
          (vector-float*! sv-176 (the-as vector (-> s2-0 sv-240)) (-> s2-0 sv-240 w))
          (vector-cross! sv-192 (the-as vector (-> s2-0 sv-240)) (the-as vector (-> s2-0 s3-0)))
          (vector-normalize! sv-192 1.0)
          (vector-cross! sv-208 sv-192 (the-as vector (-> s2-0 sv-240)))
          (vector-normalize! sv-208 1.0)
          (let ((f0-4 (plane-volume-intersect-dist (-> s2-0 s3-0) sv-176 sv-208)))
            (when (!= f0-4 409600000.0)
              (vector+float*! sv-224 sv-176 sv-208 f0-4)
              (set! sv-144 (new-stack-vector0))
              (set! sv-148 0.0)
              (set! sv-152 0)
              (set! sv-160 (new-stack-vector0))
              (set! (-> sv-144 quad) (-> sv-224 quad))
              (set! sv-256 0)
              (while (< sv-256 (-> obj num-planes))
                (when (and (!= sv-256 s3-0) (!= sv-256 sv-240))
                  (let ((f30-0 (plane-volume-intersect-dist (-> s2-0 sv-256) sv-144 sv-192)))
                    (cond
                      ((= f30-0 409600000.0)
                       )
                      ((zero? sv-152)
                       (vector+float*! sv-144 sv-144 sv-192 f30-0)
                       (set! (-> sv-160 quad) (-> s2-0 sv-256 quad))
                       (set! sv-148 8192000.0)
                       (set! sv-152 1)
                       )
                      ((begin (vector-float*! sv-224 sv-192 f30-0) (>= (vector-dot sv-224 sv-160) 0.0))
                       )
                      ((>= (vector-dot sv-224 (the-as vector (-> s2-0 sv-256))) 0.0)
                       (when (< (fabs f30-0) (fabs sv-148))
                         (set! sv-148 f30-0)
                         (set! sv-152 (+ sv-152 1))
                         )
                       )
                      (else
                        (vector+float*! sv-144 sv-144 sv-192 f30-0)
                        (set! (-> sv-160 quad) (-> s2-0 sv-256 quad))
                        (set! sv-152 (+ sv-152 1))
                        (if (< (fabs f30-0) (fabs sv-148))
                            (set! sv-148 (- sv-148 f30-0))
                            (set! sv-148 0.0)
                            )
                        )
                      )
                    )
                  )
                (set! sv-256 (+ sv-256 1))
                )
              (cond
                ((zero? sv-152)
                 )
                ((= sv-148 0.0)
                 )
                (else
                  (dotimes (v1-70 (-> obj num-planes))
                    (when (and (!= v1-70 s3-0) (!= v1-70 sv-240))
                      (if (< 4096.0 (- (vector-dot sv-144 (the-as vector (-> s2-0 v1-70))) (the-as float (-> s2-0 v1-70 w))))
                          (goto cfg-42)
                          )
                      )
                    )
                  (vector+float*! sv-224 sv-144 sv-192 sv-148)
                  (cond
                    ((< (-> arg1 allocated-length) (+ (-> arg1 length) 2))
                     (format 0 "ERROR <AG>: vol-control #x~X out of volume points~%" obj)
                     )
                    (else
                      (set! (-> arg1 data (-> arg1 length) quad) (-> sv-144 quad))
                      (set! (-> arg1 data (+ (-> arg1 length) 1) quad) (-> sv-224 quad))
                      (+! (-> arg1 length) 2)
                      (+! (-> obj point-count) 2)
                      )
                    )
                  (vector+! s1-0 s1-0 sv-144)
                  (vector+! s1-0 s1-0 sv-224)
                  (+! s0-0 2)
                  )
                )
              )
            )
          )
        (label cfg-42)
        (set! sv-240 (+ sv-240 1))
        )
      (when (nonzero? s0-0)
        (vector-float*! s1-0 s1-0 (/ 1.0 (the float s0-0)))
        (cond
          ((< (-> arg2 allocated-length) (+ (-> arg2 length) 2))
           (format 0 "ERROR <AG>: vol-control #x~X out of volume normals~%" obj)
           )
          (else
            (set! (-> arg2 data (-> arg2 length) quad) (-> s1-0 quad))
            (set! (-> arg2 data (+ (-> arg2 length) 1) quad) (-> s2-0 s3-0 quad))
            (+! (-> arg2 length) 2)
            (let ((v1-112 (+ (-> obj normal-count) 2)))
              (set! (-> obj normal-count) v1-112)
              v1-112
              )
            )
          )
        )
      )
    )
  #f
  )

;; definition for method 10 of type plane-volume
;; INFO: Return type mismatch int vs none.
(defmethod debug-draw plane-volume ((obj plane-volume))
  (let* ((v1-0 (-> obj volume-type))
         (s5-0 (cond
                 ((= v1-0 'vol)
                  (the-as uint #x8000c000)
                  )
                 ((= v1-0 'pvol)
                  (the-as uint #x80808080)
                  )
                 (else
                   (the-as uint #x800000c0)
                   )
                 )
               )
         (s4-0 (-> obj first-point))
         )
    (dotimes (s3-0 (/ (-> obj point-count) 2))
      (add-debug-line
        #t
        (bucket-id debug-no-zbuf)
        (the-as vector s4-0)
        (the-as vector (&-> s4-0 4))
        (the-as rgba s5-0)
        #f
        (the-as rgba -1)
        )
      (set! s4-0 (&-> s4-0 8))
      )
    )
  0
  (none)
  )

;; definition for method 11 of type plane-volume
(defmethod dummy-11 plane-volume ((obj plane-volume) (arg0 vector) (arg1 float))
  (dotimes (v1-0 (-> obj num-planes))
    (if (< arg1 (- (vector-dot arg0 (the-as vector (-> obj plane v1-0))) (the-as float (-> obj plane v1-0 w))))
        (return #f)
        )
    )
  #t
  )

;; definition for method 9 of type vol-control
;; INFO: Return type mismatch int vs symbol.
(defmethod dummy-9 vol-control ((obj vol-control))
  (with-pp
    (let ((a0-1 obj))
      (when (and (and *display-vol-marks* (logtest? (-> a0-1 flags) 1)) (logtest? (-> obj flags) 2))
        (when (zero? (-> obj debug-point))
          (let ((s5-0 pp))
            (set! pp (-> obj process))
            (let ((s4-0 0))
              (dotimes (v1-8 (-> obj pos-vol-count))
                (+! s4-0 (-> obj pos-vol v1-8 num-planes))
                )
              (dotimes (v1-11 (-> obj neg-vol-count))
                (+! s4-0 (-> obj neg-vol v1-11 num-planes))
                )
              (set! (-> obj debug-point) (new 'debug 'vector-array (* 10 s4-0)))
              (set! (-> obj debug-normal) (new 'debug 'vector-array (* 10 s4-0)))
              )
            (set! pp s5-0)
            )
          (set! (-> obj debug-point length) 0)
          (set! (-> obj debug-normal length) 0)
          (dotimes (s5-1 (-> obj pos-vol-count))
            (dummy-9 (-> obj pos-vol s5-1) 'vol (-> obj debug-point) (-> obj debug-normal))
            )
          (dotimes (s5-2 (-> obj neg-vol-count))
            (dummy-9 (-> obj neg-vol s5-2) 'vol (-> obj debug-point) (-> obj debug-normal))
            )
          )
        (dotimes (s5-3 (-> obj pos-vol-count))
          (debug-draw (-> obj pos-vol s5-3))
          )
        (dotimes (s5-4 (-> obj neg-vol-count))
          (debug-draw (-> obj neg-vol s5-4))
          )
        )
      )
    (the-as symbol 0)
    )
  )

;; definition for method 10 of type vol-control
(defmethod dummy-10 vol-control ((obj vol-control) (arg0 vector))
  (dotimes (s4-0 (-> obj neg-vol-count))
    (if (dummy-11 (-> obj neg-vol s4-0) arg0 0.0)
        (return #f)
        )
    )
  (dotimes (s4-1 (-> obj pos-vol-count))
    (if (dummy-11 (-> obj pos-vol s4-1) arg0 0.0)
        (return #t)
        )
    )
  #f
  )
