Mercurial > cortex
diff org/world.org @ 26:bbffa41a12a9
moved apply-map to util.org from world.org, fixed some grammar problems, made examples more concise
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 24 Oct 2011 05:41:50 -0700 |
parents | 775d97247dd0 |
children | 6372c108c5c6 |
line wrap: on
line diff
1.1 --- a/org/world.org Mon Oct 24 05:25:01 2011 -0700 1.2 +++ b/org/world.org Mon Oct 24 05:41:50 2011 -0700 1.3 @@ -193,52 +193,32 @@ 1.4 : fields with their names. This helps with C wrappers where they have 1.5 : just defined a bunch of integer constants instead of enums 1.6 1.7 +#+begin_src clojure :exports both :results verbatim 1.8 +(take 5 (vals (pokemon.lpsolve/constant-map KeyInput))) 1.9 +#+end_src 1.10 + 1.11 +#+results: 1.12 +: ("KEY_ESCAPE" "KEY_1" "KEY_2" "KEY_3" "KEY_4") 1.13 + 1.14 =(all-keys)= converts the constant names like =KEY_J= to the more 1.15 clojure-like =key-j=, and returns a map from these keys to 1.16 jMonkeyEngine =KeyTrigger= objects, which jMonkeyEngine3 uses as it's 1.17 abstraction over the physical keys. =all-keys= also adds the three 1.18 mouse button controls to the map. 1.19 1.20 - 1.21 #+begin_src clojure :exports both :results output 1.22 (require 'clojure.contrib.pprint) 1.23 (clojure.contrib.pprint/pprint 1.24 - (take 10 (keys (cortex.world/all-keys)))) 1.25 + (take 6 (cortex.world/all-keys))) 1.26 #+end_src 1.27 1.28 #+results: 1.29 -#+begin_example 1.30 -("key-n" 1.31 - "key-apps" 1.32 - "key-pgup" 1.33 - "key-f8" 1.34 - "key-o" 1.35 - "key-at" 1.36 - "key-f9" 1.37 - "key-0" 1.38 - "key-p" 1.39 - "key-subtract") 1.40 -#+end_example 1.41 - 1.42 -#+begin_src clojure :exports both :results output 1.43 -(clojure.contrib.pprint/pprint 1.44 - (take 10 (vals (cortex.world/all-keys)))) 1.45 -#+end_src 1.46 - 1.47 -#+results: 1.48 -#+begin_example 1.49 -(#<KeyTrigger com.jme3.input.controls.KeyTrigger@6ec21e52> 1.50 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@a54d24d> 1.51 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@1ba5e91b> 1.52 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@296af9cb> 1.53 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@2e3593ab> 1.54 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@3f71d740> 1.55 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@4aeacb4a> 1.56 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@7cc88db2> 1.57 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@52cee11e> 1.58 - #<KeyTrigger com.jme3.input.controls.KeyTrigger@c1da30b>) 1.59 -#+end_example 1.60 - 1.61 +: (["key-n" #<KeyTrigger com.jme3.input.controls.KeyTrigger@9f9fec0>] 1.62 +: ["key-apps" #<KeyTrigger com.jme3.input.controls.KeyTrigger@28edbe7f>] 1.63 +: ["key-pgup" #<KeyTrigger com.jme3.input.controls.KeyTrigger@647fd33a>] 1.64 +: ["key-f8" #<KeyTrigger com.jme3.input.controls.KeyTrigger@24f97188>] 1.65 +: ["key-o" #<KeyTrigger com.jme3.input.controls.KeyTrigger@685c53ff>] 1.66 +: ["key-at" #<KeyTrigger com.jme3.input.controls.KeyTrigger@4c3e2e5f>]) 1.67 1.68 1.69 ** World Creation 1.70 @@ -351,27 +331,15 @@ 1.71 ;; focus. 1.72 (.setPauseOnLostFocus false) 1.73 (.setSettings *app-settings*)))) 1.74 - 1.75 -(defn apply-map 1.76 - "Like apply, but works for maps and functions that expect an 1.77 - implicit map and nothing else as in (fn [& {}]). 1.78 - ------- Example ------- 1.79 - (defn demo [& {:keys [www] :or {www \"oh yeah\"} :as env}] 1.80 - (println www)) 1.81 - (apply-map demo {:www \"hello!\"}) 1.82 - -->\"hello\"" 1.83 - [fn m] 1.84 - (apply fn (reduce #(into %1 %2) [] m))) 1.85 - 1.86 #+end_src 1.87 1.88 1.89 =(world)= is the most important function here. It presents a more 1.90 -functional interface to the Application life-cycle, and all it's 1.91 -objects except =root-node= are plain clojure data structures. It's now 1.92 -possible to extend functionally by composing multiple functions 1.93 -together, and to add more keyboard-driven actions by combining clojure 1.94 -maps. 1.95 +functional interface to the Application life-cycle, and all its 1.96 +arguments except =root-node= are plain immutable clojure data 1.97 +structures. This makes it easier to extend functionally by composing 1.98 +multiple functions together, and to add more keyboard-driven actions 1.99 +by combining clojure maps. 1.100 1.101 1.102