# HG changeset patch # User Robert McIntyre # Date 1323275375 21600 # Node ID 4b5f00110d8c0c98d134b4cb05a06ad4d7404ffb # Parent ab1fee4280c39a50328787d381b0a942d77ba82c removed pokemon.lpsolve dependency diff -r ab1fee4280c3 -r 4b5f00110d8c org/body.org --- a/org/body.org Wed Nov 30 20:42:07 2011 -0700 +++ b/org/body.org Wed Dec 07 10:29:35 2011 -0600 @@ -104,6 +104,7 @@ #+end_src +* Motor Control #+srcname: motor-control #+begin_src clojure (in-ns 'cortex.body) diff -r ab1fee4280c3 -r 4b5f00110d8c org/world.org --- a/org/world.org Wed Nov 30 20:42:07 2011 -0700 +++ b/org/world.org Wed Dec 07 10:29:35 2011 -0600 @@ -54,7 +54,6 @@ {:author "Robert McIntyre"} (:use (clojure.contrib (def :only (defvar)))) - (:use [pokemon [lpsolve :only [constant-map]]]) (:use [clojure.contrib [str-utils :only [re-gsub]]]) (:import com.aurellem.capture.IsoTimer) @@ -75,7 +74,7 @@ (:import org.lwjgl.input.Mouse)) #+end_src -** General Settings +** General Settings #+srcname: settings #+begin_src clojure (in-ns 'cortex.world) @@ -105,7 +104,6 @@ object creation less tightly bound to a particular Application Instance. - ** Exception Protection #+srcname: exceptions #+begin_src clojure @@ -144,11 +142,30 @@ #+begin_src clojure (in-ns 'cortex.world) +(defn static-integer? + "does the field represent a static integer constant?" + [#^java.lang.reflect.Field field] + (and (java.lang.reflect.Modifier/isStatic (.getModifiers field)) + (integer? (.get field nil)))) + +(defn integer-constants [class] + (filter static-integer? (.getFields class))) + +(defn-memo constant-map + "Takes a class and creates a map of the static constant integer + fields with their names. This helps with C wrappers where they have + just defined a bunch of integer constants instead of enums" + [class] + (let [integer-fields (integer-constants class)] + (into (sorted-map) + (zipmap (map #(.get % nil) integer-fields) + (map #(.getName %) integer-fields))))) + (defn all-keys "Uses reflection to generate a map of string names to jme3 trigger objects, which govern input from the keyboard and mouse" [] - (let [inputs (pokemon.lpsolve/constant-map KeyInput)] + (let [inputs (constant-map KeyInput)] (assoc (zipmap (map (fn [field] (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs)) @@ -178,24 +195,11 @@ These functions are for controlling the world through the keyboard and mouse. -I reuse =constant-map= from [[../../pokemon-types/html/lpsolve.html#sec-3-2-4][=pokemon.lpsolve=]] to get the numerical -values for all the keys defined in the =KeyInput= class. The -documentation for =constant-map= is: - -#+begin_src clojure :results output :exports both -(doc pokemon.lpsolve/constant-map) -#+end_src - -#+results: -: ------------------------- -: pokemon.lpsolve/constant-map -: ([class]) -: Takes a class and creates a map of the static constant integer -: fields with their names. This helps with C wrappers where they have -: just defined a bunch of integer constants instead of enums +=constant-map= gets the numerical values for all the keys defined in +the =KeyInput= class. #+begin_src clojure :exports both :results verbatim -(take 5 (vals (pokemon.lpsolve/constant-map KeyInput))) +(take 5 (vals (cortex.world/constant-map KeyInput))) #+end_src #+results: