Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions ode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,51 @@
(in-package #:cl-ode)
(declaim (optimize (speed 3)))

(defvar *default-max-contacts* 25)
(defvar *default-max-contacts* 25)

(cffi:defcallback near-callback :void ((data :pointer)
(o1 :pointer)
(o2 :pointer))
(declare (ignore data))
(unless (pointer-eq o1 o2)


(close-callback (gethash (cffi:pointer-address o1) *object-hash*)
(gethash (cffi:pointer-address o2) *object-hash*))))


(cffi:defcallback moved-callback :void ((body :pointer))
(let ((body (gethash (cffi:pointer-address body) *object-hash*)))
(when (and body (move-handler body))
(body-moved-callback body))))


(defcfun-rename-function ("dBodySetMovedCallback") :void
(defcfun-rename-function ("dBodySetMovedCallback") :void
(body dBodyID)
(callback :pointer))


(defun near-handler (data o1 o2)

(unless (cffi:pointer-eq o1 o2)

(let* ((lisp-object1 (gethash (pointer-address o1) *object-hash*))
(lisp-object2 (gethash (pointer-address o2) *object-hash*)))

(when (and lisp-object1 lisp-object2)

(close-callback lisp-object1 lisp-object2)))))

(defvar *initialized* nil)

(defun init ()

(init-ode)
(setf *object-hash* (make-hash-table :test 'equal)))
(if (is-initialized?)
(warn "Will not attempt to initalize cl-ode as it seems to already be initialized")
(progn
(init-ode)
(setf *initialized* t)
(setf *object-hash* (make-hash-table :test 'equal))
t)))


(defun physics-step (world space)
Expand All @@ -51,10 +56,10 @@
(joint-group-empty (contact-group world)))

(defun uninit ()

(close-ode)
(when (is-initialized?)
(close-ode)
(setf *initialized* nil))
(setf *object-hash* nil))




(defun is-initialized? ()
*initialized*)
6 changes: 3 additions & 3 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(defpackage #:cl-ode
(:use #:cl #:cffi)
(:nicknames #:ode)
(:export
(:export

#:dReal #:dMass #:dVector3 #:dVector4 #:dMatrix3 #:dMatrix4 #:dMatrix6
#:dWorldID #:dSpaceID #:dBodyID #:dGeomID #:dJointID #:dJointGroupID
Expand All @@ -30,6 +30,7 @@
#:init
#:physics-step
#:uninit
#:is-initialized?
#:body #:pointer
#:enabled

Expand All @@ -41,5 +42,4 @@
#:close-callback
#:update
#:ray-length #:physics-spring #:springiness #:damping
#:horizontal #:vertical #:load-player-camera
))
#:horizontal #:vertical #:load-player-camera))