Mercurial > cortex
comparison 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 |
comparison
equal
deleted
inserted
replaced
64:ab1fee4280c3 | 65:4b5f00110d8c |
---|---|
52 "World Creation, abstracion over jme3's input system, and REPL | 52 "World Creation, abstracion over jme3's input system, and REPL |
53 driven exception handling" | 53 driven exception handling" |
54 {:author "Robert McIntyre"} | 54 {:author "Robert McIntyre"} |
55 | 55 |
56 (:use (clojure.contrib (def :only (defvar)))) | 56 (:use (clojure.contrib (def :only (defvar)))) |
57 (:use [pokemon [lpsolve :only [constant-map]]]) | |
58 (:use [clojure.contrib [str-utils :only [re-gsub]]]) | 57 (:use [clojure.contrib [str-utils :only [re-gsub]]]) |
59 | 58 |
60 (:import com.aurellem.capture.IsoTimer) | 59 (:import com.aurellem.capture.IsoTimer) |
61 | 60 |
62 (:import com.jme3.math.Vector3f) | 61 (:import com.jme3.math.Vector3f) |
73 (:import com.jme3.input.controls.ActionListener) | 72 (:import com.jme3.input.controls.ActionListener) |
74 (:import com.jme3.renderer.queue.RenderQueue$ShadowMode) | 73 (:import com.jme3.renderer.queue.RenderQueue$ShadowMode) |
75 (:import org.lwjgl.input.Mouse)) | 74 (:import org.lwjgl.input.Mouse)) |
76 #+end_src | 75 #+end_src |
77 | 76 |
78 ** General Settings | 77 ** General Settings |
79 #+srcname: settings | 78 #+srcname: settings |
80 #+begin_src clojure | 79 #+begin_src clojure |
81 (in-ns 'cortex.world) | 80 (in-ns 'cortex.world) |
82 | 81 |
83 (defvar *app-settings* | 82 (defvar *app-settings* |
102 =Application= whenever they extend that class. However, | 101 =Application= whenever they extend that class. However, |
103 =AssetManagers= are useful on their own to create objects/ materials, | 102 =AssetManagers= are useful on their own to create objects/ materials, |
104 independent from any particular application. =(asset-manager)= makes | 103 independent from any particular application. =(asset-manager)= makes |
105 object creation less tightly bound to a particular Application | 104 object creation less tightly bound to a particular Application |
106 Instance. | 105 Instance. |
107 | |
108 | 106 |
109 ** Exception Protection | 107 ** Exception Protection |
110 #+srcname: exceptions | 108 #+srcname: exceptions |
111 #+begin_src clojure | 109 #+begin_src clojure |
112 (in-ns 'cortex.world) | 110 (in-ns 'cortex.world) |
142 ** Input | 140 ** Input |
143 #+srcname: input | 141 #+srcname: input |
144 #+begin_src clojure | 142 #+begin_src clojure |
145 (in-ns 'cortex.world) | 143 (in-ns 'cortex.world) |
146 | 144 |
145 (defn static-integer? | |
146 "does the field represent a static integer constant?" | |
147 [#^java.lang.reflect.Field field] | |
148 (and (java.lang.reflect.Modifier/isStatic (.getModifiers field)) | |
149 (integer? (.get field nil)))) | |
150 | |
151 (defn integer-constants [class] | |
152 (filter static-integer? (.getFields class))) | |
153 | |
154 (defn-memo constant-map | |
155 "Takes a class and creates a map of the static constant integer | |
156 fields with their names. This helps with C wrappers where they have | |
157 just defined a bunch of integer constants instead of enums" | |
158 [class] | |
159 (let [integer-fields (integer-constants class)] | |
160 (into (sorted-map) | |
161 (zipmap (map #(.get % nil) integer-fields) | |
162 (map #(.getName %) integer-fields))))) | |
163 | |
147 (defn all-keys | 164 (defn all-keys |
148 "Uses reflection to generate a map of string names to jme3 trigger | 165 "Uses reflection to generate a map of string names to jme3 trigger |
149 objects, which govern input from the keyboard and mouse" | 166 objects, which govern input from the keyboard and mouse" |
150 [] | 167 [] |
151 (let [inputs (pokemon.lpsolve/constant-map KeyInput)] | 168 (let [inputs (constant-map KeyInput)] |
152 (assoc | 169 (assoc |
153 (zipmap (map (fn [field] | 170 (zipmap (map (fn [field] |
154 (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs)) | 171 (.toLowerCase (re-gsub #"_" "-" field))) (vals inputs)) |
155 (map (fn [val] (KeyTrigger. val)) (keys inputs))) | 172 (map (fn [val] (KeyTrigger. val)) (keys inputs))) |
156 ;;explicitly add mouse controls | 173 ;;explicitly add mouse controls |
176 #+end_src | 193 #+end_src |
177 | 194 |
178 These functions are for controlling the world through the keyboard and | 195 These functions are for controlling the world through the keyboard and |
179 mouse. | 196 mouse. |
180 | 197 |
181 I reuse =constant-map= from [[../../pokemon-types/html/lpsolve.html#sec-3-2-4][=pokemon.lpsolve=]] to get the numerical | 198 =constant-map= gets the numerical values for all the keys defined in |
182 values for all the keys defined in the =KeyInput= class. The | 199 the =KeyInput= class. |
183 documentation for =constant-map= is: | |
184 | |
185 #+begin_src clojure :results output :exports both | |
186 (doc pokemon.lpsolve/constant-map) | |
187 #+end_src | |
188 | |
189 #+results: | |
190 : ------------------------- | |
191 : pokemon.lpsolve/constant-map | |
192 : ([class]) | |
193 : Takes a class and creates a map of the static constant integer | |
194 : fields with their names. This helps with C wrappers where they have | |
195 : just defined a bunch of integer constants instead of enums | |
196 | 200 |
197 #+begin_src clojure :exports both :results verbatim | 201 #+begin_src clojure :exports both :results verbatim |
198 (take 5 (vals (pokemon.lpsolve/constant-map KeyInput))) | 202 (take 5 (vals (cortex.world/constant-map KeyInput))) |
199 #+end_src | 203 #+end_src |
200 | 204 |
201 #+results: | 205 #+results: |
202 : ("KEY_ESCAPE" "KEY_1" "KEY_2" "KEY_3" "KEY_4") | 206 : ("KEY_ESCAPE" "KEY_1" "KEY_2" "KEY_3" "KEY_4") |
203 | 207 |