Fully pivot to pirates, some UI
This commit is contained in:
		| @@ -5,7 +5,7 @@ | |||||||
|             :url "https://www.eclipse.org/legal/epl-2.0/"} |             :url "https://www.eclipse.org/legal/epl-2.0/"} | ||||||
|   :dependencies [[org.clojure/clojure "1.11.1"] |   :dependencies [[org.clojure/clojure "1.11.1"] | ||||||
|                  [seesaw "1.5.0"]] |                  [seesaw "1.5.0"]] | ||||||
|   :main ^:skip-aot space-sim.core |   :main ^:skip-aot age-of-sail.core | ||||||
|   :target-path "target/%s" |   :target-path "target/%s" | ||||||
|   :profiles {:uberjar {:aot :all |   :profiles {:uberjar {:aot :all | ||||||
|                        :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}) |                        :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}) | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| ;; you should be in space-sim.core> | ;; you should be in age-of-sail.core> | ||||||
|  |  | ||||||
| (def my-ship (ref {:position [0. 0.] | (def my-ship (ref {:position [0. 0.] | ||||||
|  |                    :name "Virgina Woolfe" | ||||||
|                    :heading (normalize [1.0 1.0]) |                    :heading (normalize [1.0 1.0]) | ||||||
|                    :slots [{:type :downwind-sail :length 2 :furl 1.0}] |                    :slots [{:type :downwind-sail :length 2 :furl 1.0}] | ||||||
|                    :velocity [1. 0.]})) |                    :velocity [1. 0.]})) | ||||||
| @@ -9,8 +10,7 @@ | |||||||
|  |  | ||||||
| (start-program) | (start-program) | ||||||
| @my-ship | @my-ship | ||||||
| (dosync (alter my-ship assoc :heading (normalize [0. 1.]))) |  | ||||||
| (stop-program) | (stop-program) | ||||||
|  |  | ||||||
|  |  | ||||||
| (show-ui) | (show-ui) | ||||||
|  | @tracked-ship | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| (ns space-sim.core | (ns age-of-sail.core | ||||||
|   (:require [space-sim.vec2 :refer :all] |   (:require [age-of-sail.vec2 :refer :all] | ||||||
|             [seesaw.core :refer :all] |             [seesaw.core :refer :all] | ||||||
|  |             [seesaw.bind :as b] | ||||||
|             [clojure.math :as math])) |             [clojure.math :as math])) | ||||||
| 
 | 
 | ||||||
| (def tickrate 100) | (def tickrate 100) | ||||||
| @@ -8,6 +9,10 @@ | |||||||
| (defonce ships (atom [])) | (defonce ships (atom [])) | ||||||
| (defonce program (atom nil)) | (defonce program (atom nil)) | ||||||
| 
 | 
 | ||||||
|  | (defn find-ship | ||||||
|  |   [ships name] | ||||||
|  |   (some #(when (= name (:name @%)) %) ships)) | ||||||
|  | 
 | ||||||
| (defn downwind-force | (defn downwind-force | ||||||
|   "Calculates the force for a single square downwind sail |   "Calculates the force for a single square downwind sail | ||||||
|   Force = furl × length² × dot(wind, heading)" |   Force = furl × length² × dot(wind, heading)" | ||||||
| @@ -18,13 +23,11 @@ | |||||||
|   [ship wind] |   [ship wind] | ||||||
|   (loop [slots (:slots ship) |   (loop [slots (:slots ship) | ||||||
|          force (zero)] |          force (zero)] | ||||||
|     (if (empty? slots) |     (if-let [slot (first slots)] | ||||||
|       force |       (if (= :downwind-sail (:type slot)) | ||||||
|       (let [slot (first slots) |         (recur (rest slots) (add force (downwind-force slot wind (:heading ship)))) | ||||||
|             tail (rest slots)] |         (recur (rest slots) force)) | ||||||
|         (if (= :downwind-sail (:type slot)) |       force))) | ||||||
|           (recur tail (add force (downwind-force slot wind (:heading ship)))) |  | ||||||
|           (recur tail force)))))) |  | ||||||
| 
 | 
 | ||||||
| (defn physics-step | (defn physics-step | ||||||
|   [ship wind] |   [ship wind] | ||||||
| @@ -50,21 +53,29 @@ | |||||||
|   [] |   [] | ||||||
|   (stop-program) |   (stop-program) | ||||||
|   (let [thread-continue (atom true)] |   (let [thread-continue (atom true)] | ||||||
|     (.start (Thread. (fn [] |     (.start | ||||||
|                        (while @thread-continue |      (Thread. | ||||||
|                          (tick @ships) |       (fn [] | ||||||
|                          (Thread/sleep (quot 1000 tickrate)))))) |         (while @thread-continue | ||||||
|  |           (tick @ships) | ||||||
|  |           (Thread/sleep (quot 1000 tickrate)))))) | ||||||
|     (reset! program thread-continue))) |     (reset! program thread-continue))) | ||||||
| 
 | 
 | ||||||
| ;; UI | ;; UI | ||||||
|  | (def tracked-ship (atom nil)) | ||||||
|  | 
 | ||||||
| (defn ship-chooser | (defn ship-chooser | ||||||
|   [] |   [] | ||||||
|   (let [namebox (text)] |   (let [name (text :columns 20)] | ||||||
|     (flow-panel :items ["Ship Name" namebox]) |     (b/bind (.getDocument name) (b/transform #(find-ship @ships %)) tracked-ship) | ||||||
|     (listen namebox :key-typed #()))) |     (flow-panel :items ["Ship Name" name]))) | ||||||
|  | 
 | ||||||
|  | (defn ship-info | ||||||
|  |   []) | ||||||
|  | 
 | ||||||
| (defn show-ui | (defn show-ui | ||||||
|   [] |   [] | ||||||
|   (-> (frame :title "Space Sim") pack! show!)) |   (-> (frame :title "Space Sim" :content (ship-chooser)) pack! show!)) | ||||||
| 
 | 
 | ||||||
| (defn -main | (defn -main | ||||||
|   [args] |   [args] | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| (ns space-sim.vec2 | (ns age-of-sail.vec2 | ||||||
|   (:require [clojure.math :as math])) |   (:require [clojure.math :as math])) | ||||||
| 
 | 
 | ||||||
| (defn zero | (defn zero | ||||||
		Reference in New Issue
	
	Block a user