Get working on OSX
[clnl] / src / main / interface.lisp
index ad0976264cae0e82215a65a9c6f1b0e1ed7c1961..27d5eed3ebec4e1b33a25fc5c2e9c2cc4e41850a 100644 (file)
@@ -4,7 +4,6 @@
 (defvar *world-dims* '(:xmin -5 :xmax 5 :ymin -5 :ymax 5))
 
 (defvar *turtle-list* nil)
-(car clnl-nvm::*turtles*)
 
 ; It may be useful to keep windows around
 (defvar *glut-window-opened* nil)
  (mapcar
   (lambda (turtle)
    (let
-    ((color (nl-color->rgb (clnl-nvm::turtle-color turtle))))
+    ((color (nl-color->rgb (getf turtle :color))))
     (gl:color (car color) (cadr color) (caddr color)))
    (gl:with-pushed-matrix
-    (gl:translate (* (clnl-nvm::turtle-xcor turtle) *patch-size*) (* (clnl-nvm::turtle-ycor turtle) *patch-size*) 0)
-    (gl:rotate (clnl-nvm::turtle-heading turtle) 0 0 -1)
+    (gl:translate (* (getf turtle :xcor) *patch-size*) (* (getf turtle :ycor) *patch-size*) 0)
+    (gl:rotate (getf turtle :heading) 0 0 -1)
     (gl:call-list *turtle-list*)))
-  clnl-nvm::*turtles*)
+  (clnl-nvm:current-state))
  (gl:flush))
 
 (defun display ()
@@ -61,7 +60,7 @@
  (cl-glut:post-redisplay))
 
 (defun close-func ()
- (sb-ext:exit))
+ (sb-ext:exit :abort t))
 
 (defun reshape (width height)
  (when (and (/= 0 width) (/= 0 height))
   (gl:end)))
 
 (defun run ()
+ "RUN => RESULT
+
+ARGUMENTS AND VALUES:
+
+  RESULT: undefined, should never get here
+
+DESCRIPTION:
+
+  RUN runs the view in an external window.
+
+  This should be run inside another thread as it starts the glut main-loop.
+  Closing this window will then cause the entire program to terminate."
  ; I do this because I don't know who or what in the many layers
  ; is causing the floating point errors, but I definitely don't
  ; want to investigate until simply ignoring them becomes a problem.
  (sb-int:with-float-traps-masked (:invalid)
   (cl-glut:init)
-  (gl:clear-color 0 0 0 1)
   (cl-glut:init-window-size
    (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin)))))
    (floor (* *patch-size* (1+ (- (getf *world-dims* :ymax) (getf *world-dims* :ymin))))))
-  (setf *glut-window-opened* t)
-  (cl-glut:create-window "CLNL Test Window")
   (cl-glut:init-display-mode :double :rgba)
+  (cl-glut:create-window "CLNL Test Window")
+  (setf *glut-window-opened* t)
+  (gl:clear-color 0 0 0 1)
   (cl-glut:display-func (cffi:get-callback 'display))
   (glut:reshape-func (cffi:callback reshape))
   (cl-glut:idle-func (cffi:get-callback 'idle))
   (cl-glut:main-loop)))
 
 (defun export-view ()
+ "EXPORT-VIEW => IMAGE-DATA
+
+ARGUMENTS AND VALUES:
+
+  IMAGE-DATA: A vector, pixel data as returned by opengls readPixels
+
+DESCRIPTION:
+
+  EXPORT-VIEW returns the current view in raw data of RGBA pixels.
+
+  Each pixel is made up of 4 bytes of data, which an be walked over.  The number
+  of pixels is the current width x height.  Converting to some other image format
+  is a matter of pulling that information out and putting it into whatever format
+  you like.
+
+  This requires opengl to run, but can be used with xvfb in a headless mode."
  (sb-int:with-float-traps-masked (:invalid)
   (when (not *glut-window-opened*)
    (cl-glut:init)
-   (gl:clear-color 0 0 0 1)
    (cl-glut:init-window-size 1 1)
    (cl-glut:create-window "CLNL Test Window")
+   (gl:clear-color 0 0 0 1)
    (set-turtle-list)
    (setf *glut-window-opened* t))
   (let
    ((fbo (first (gl:gen-framebuffers 1)))
     (render-buf (first (gl:gen-renderbuffers 1)))
-    (width 143)  ; Hard coded for now, yay v1 (if you see this comment in a year, please cry for me)
-    (height 143)
    ;(width (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin))))))
    ;(height (floor (* *patch-size* (1+ (- (getf *world-dims* :ymax) (getf *world-dims* :ymin))))))
-    )
+    (width 143)  ; Hard coded for now, yay v1 (if you see this comment in a year, please cry for me)
+    (height 143))
    (gl:bind-framebuffer :framebuffer fbo)
    (gl:bind-renderbuffer :renderbuffer render-buf)
    (gl:renderbuffer-storage :renderbuffer :rgba8 width height)