changeset 65:4b5f00110d8c

removed pokemon.lpsolve dependency
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Dec 2011 10:29:35 -0600
parents ab1fee4280c3
children 1381a6ebd08b
files org/body.org org/world.org
diffstat 2 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/org/body.org	Wed Nov 30 20:42:07 2011 -0700
     1.2 +++ b/org/body.org	Wed Dec 07 10:29:35 2011 -0600
     1.3 @@ -104,6 +104,7 @@
     1.4    
     1.5  #+end_src
     1.6  
     1.7 +* Motor Control
     1.8  #+srcname: motor-control
     1.9  #+begin_src clojure
    1.10  (in-ns 'cortex.body)
     2.1 --- a/org/world.org	Wed Nov 30 20:42:07 2011 -0700
     2.2 +++ b/org/world.org	Wed Dec 07 10:29:35 2011 -0600
     2.3 @@ -54,7 +54,6 @@
     2.4    {:author "Robert McIntyre"}
     2.5    
     2.6    (:use (clojure.contrib (def :only (defvar))))
     2.7 -  (:use [pokemon [lpsolve :only [constant-map]]])
     2.8    (:use [clojure.contrib [str-utils :only [re-gsub]]])
     2.9  
    2.10    (:import com.aurellem.capture.IsoTimer)
    2.11 @@ -75,7 +74,7 @@
    2.12    (:import org.lwjgl.input.Mouse))
    2.13  #+end_src    
    2.14      
    2.15 -** General Settings    
    2.16 +** General Settings
    2.17  #+srcname: settings    
    2.18  #+begin_src clojure 
    2.19  (in-ns 'cortex.world)
    2.20 @@ -105,7 +104,6 @@
    2.21  object creation less tightly bound to a particular Application
    2.22  Instance.
    2.23  
    2.24 -
    2.25  ** Exception Protection
    2.26  #+srcname: exceptions
    2.27  #+begin_src clojure
    2.28 @@ -144,11 +142,30 @@
    2.29  #+begin_src clojure
    2.30  (in-ns 'cortex.world)
    2.31  
    2.32 +(defn static-integer?
    2.33 +  "does the field represent a static integer constant?"
    2.34 +  [#^java.lang.reflect.Field field]
    2.35 +  (and (java.lang.reflect.Modifier/isStatic (.getModifiers field))
    2.36 +       (integer? (.get field nil))))
    2.37 +
    2.38 +(defn integer-constants [class]
    2.39 +  (filter static-integer? (.getFields class)))
    2.40 +
    2.41 +(defn-memo constant-map
    2.42 +  "Takes a class and creates a map of the static constant integer
    2.43 +  fields with their names.  This helps with C wrappers where they have
    2.44 +  just defined a bunch of integer constants instead of enums"
    2.45 +  [class]
    2.46 +     (let [integer-fields (integer-constants class)]
    2.47 +       (into (sorted-map)
    2.48 +	     (zipmap (map #(.get % nil) integer-fields)
    2.49 +		     (map #(.getName %) integer-fields)))))
    2.50 +
    2.51  (defn all-keys
    2.52    "Uses reflection to generate a map of string names to jme3 trigger
    2.53    objects, which govern input from the keyboard and mouse"
    2.54    []
    2.55 -  (let [inputs (pokemon.lpsolve/constant-map KeyInput)]
    2.56 +  (let [inputs (constant-map KeyInput)]
    2.57      (assoc
    2.58  	(zipmap (map (fn [field]
    2.59  		       (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs))
    2.60 @@ -178,24 +195,11 @@
    2.61  These functions are for controlling the world through the keyboard and
    2.62  mouse.
    2.63  
    2.64 -I reuse =constant-map= from [[../../pokemon-types/html/lpsolve.html#sec-3-2-4][=pokemon.lpsolve=]] to get the numerical
    2.65 -values for all the keys defined in the =KeyInput= class. The
    2.66 -documentation for =constant-map= is:
    2.67 -
    2.68 -#+begin_src clojure :results output :exports both
    2.69 -(doc pokemon.lpsolve/constant-map)
    2.70 -#+end_src
    2.71 -
    2.72 -#+results:
    2.73 -: -------------------------
    2.74 -: pokemon.lpsolve/constant-map
    2.75 -: ([class])
    2.76 -:   Takes a class and creates a map of the static constant integer
    2.77 -:   fields with their names.  This helps with C wrappers where they have
    2.78 -:   just defined a bunch of integer constants instead of enums
    2.79 +=constant-map= gets the numerical values for all the keys defined in
    2.80 +the =KeyInput= class. 
    2.81  
    2.82  #+begin_src clojure :exports both :results verbatim
    2.83 -(take 5 (vals (pokemon.lpsolve/constant-map KeyInput)))
    2.84 +(take 5 (vals (cortex.world/constant-map KeyInput)))
    2.85  #+end_src
    2.86  
    2.87  #+results: