diff org/world.org @ 65:4b5f00110d8c

removed pokemon.lpsolve dependency
author Robert McIntyre <rlm@mit.edu>
date Wed, 07 Dec 2011 10:29:35 -0600
parents 00d0e1639d4b
children 1381a6ebd08b
line wrap: on
line diff
     1.1 --- a/org/world.org	Wed Nov 30 20:42:07 2011 -0700
     1.2 +++ b/org/world.org	Wed Dec 07 10:29:35 2011 -0600
     1.3 @@ -54,7 +54,6 @@
     1.4    {:author "Robert McIntyre"}
     1.5    
     1.6    (:use (clojure.contrib (def :only (defvar))))
     1.7 -  (:use [pokemon [lpsolve :only [constant-map]]])
     1.8    (:use [clojure.contrib [str-utils :only [re-gsub]]])
     1.9  
    1.10    (:import com.aurellem.capture.IsoTimer)
    1.11 @@ -75,7 +74,7 @@
    1.12    (:import org.lwjgl.input.Mouse))
    1.13  #+end_src    
    1.14      
    1.15 -** General Settings    
    1.16 +** General Settings
    1.17  #+srcname: settings    
    1.18  #+begin_src clojure 
    1.19  (in-ns 'cortex.world)
    1.20 @@ -105,7 +104,6 @@
    1.21  object creation less tightly bound to a particular Application
    1.22  Instance.
    1.23  
    1.24 -
    1.25  ** Exception Protection
    1.26  #+srcname: exceptions
    1.27  #+begin_src clojure
    1.28 @@ -144,11 +142,30 @@
    1.29  #+begin_src clojure
    1.30  (in-ns 'cortex.world)
    1.31  
    1.32 +(defn static-integer?
    1.33 +  "does the field represent a static integer constant?"
    1.34 +  [#^java.lang.reflect.Field field]
    1.35 +  (and (java.lang.reflect.Modifier/isStatic (.getModifiers field))
    1.36 +       (integer? (.get field nil))))
    1.37 +
    1.38 +(defn integer-constants [class]
    1.39 +  (filter static-integer? (.getFields class)))
    1.40 +
    1.41 +(defn-memo constant-map
    1.42 +  "Takes a class and creates a map of the static constant integer
    1.43 +  fields with their names.  This helps with C wrappers where they have
    1.44 +  just defined a bunch of integer constants instead of enums"
    1.45 +  [class]
    1.46 +     (let [integer-fields (integer-constants class)]
    1.47 +       (into (sorted-map)
    1.48 +	     (zipmap (map #(.get % nil) integer-fields)
    1.49 +		     (map #(.getName %) integer-fields)))))
    1.50 +
    1.51  (defn all-keys
    1.52    "Uses reflection to generate a map of string names to jme3 trigger
    1.53    objects, which govern input from the keyboard and mouse"
    1.54    []
    1.55 -  (let [inputs (pokemon.lpsolve/constant-map KeyInput)]
    1.56 +  (let [inputs (constant-map KeyInput)]
    1.57      (assoc
    1.58  	(zipmap (map (fn [field]
    1.59  		       (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs))
    1.60 @@ -178,24 +195,11 @@
    1.61  These functions are for controlling the world through the keyboard and
    1.62  mouse.
    1.63  
    1.64 -I reuse =constant-map= from [[../../pokemon-types/html/lpsolve.html#sec-3-2-4][=pokemon.lpsolve=]] to get the numerical
    1.65 -values for all the keys defined in the =KeyInput= class. The
    1.66 -documentation for =constant-map= is:
    1.67 -
    1.68 -#+begin_src clojure :results output :exports both
    1.69 -(doc pokemon.lpsolve/constant-map)
    1.70 -#+end_src
    1.71 -
    1.72 -#+results:
    1.73 -: -------------------------
    1.74 -: pokemon.lpsolve/constant-map
    1.75 -: ([class])
    1.76 -:   Takes a class and creates a map of the static constant integer
    1.77 -:   fields with their names.  This helps with C wrappers where they have
    1.78 -:   just defined a bunch of integer constants instead of enums
    1.79 +=constant-map= gets the numerical values for all the keys defined in
    1.80 +the =KeyInput= class. 
    1.81  
    1.82  #+begin_src clojure :exports both :results verbatim
    1.83 -(take 5 (vals (pokemon.lpsolve/constant-map KeyInput)))
    1.84 +(take 5 (vals (cortex.world/constant-map KeyInput)))
    1.85  #+end_src
    1.86  
    1.87  #+results: