Restructure, add laf
This commit is contained in:
parent
7342f6dbc8
commit
572726df7c
@ -4,7 +4,8 @@
|
|||||||
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
|
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
|
||||||
: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"]
|
||||||
|
[com.formdev/flatlaf "3.2.5"]]
|
||||||
:main ^:skip-aot age-of-sail.core
|
:main ^:skip-aot age-of-sail.core
|
||||||
:target-path "target/%s"
|
:target-path "target/%s"
|
||||||
:profiles {:uberjar {:aot :all
|
:profiles {:uberjar {:aot :all
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
(ns age-of-sail.core
|
(ns age-of-sail.core
|
||||||
(:require [age-of-sail.vec2 :refer :all]
|
(:require [age-of-sail.simulation :refer :all]
|
||||||
|
[age-of-sail.vec2 :refer :all]
|
||||||
[seesaw.core :refer :all]
|
[seesaw.core :refer :all]
|
||||||
[seesaw.bind :as b]
|
[seesaw.bind :as b])
|
||||||
[clojure.math :as math]))
|
(:import com.formdev.flatlaf.FlatDarculaLaf))
|
||||||
|
|
||||||
(def tickrate 100)
|
|
||||||
(def hardcoded-wind [0.1 3.0]) ;; A strong easternly wind!
|
(def hardcoded-wind [0.1 3.0]) ;; A strong easternly wind!
|
||||||
(defonce ships (atom []))
|
(defonce ships (atom []))
|
||||||
(def hooks (atom '()))
|
|
||||||
(defn subscribe!
|
|
||||||
"Adds a hook to the hooks"
|
|
||||||
[f]
|
|
||||||
(swap! hooks conj f))
|
|
||||||
|
|
||||||
(defn ship-names
|
(defn ship-names
|
||||||
"Gets the names from a list of ships"
|
"Gets the names from a list of ships"
|
||||||
@ -56,33 +51,8 @@
|
|||||||
|
|
||||||
(subscribe! #(tick @ships))
|
(subscribe! #(tick @ships))
|
||||||
|
|
||||||
;; Simulation controls
|
|
||||||
(defonce program (atom :stopped))
|
|
||||||
(defn game-loop
|
|
||||||
[]
|
|
||||||
(while (#{:running :paused} @program)
|
|
||||||
(when (= :running @program)
|
|
||||||
(doseq [hook @hooks]
|
|
||||||
(hook)))
|
|
||||||
(Thread/sleep (quot 1000 tickrate)))
|
|
||||||
(when-not (compare-and-set! program :killed :stopped)
|
|
||||||
(throw "Error: tried to stop a program that wasn't killed!")))
|
|
||||||
|
|
||||||
(defn pause-program
|
|
||||||
[]
|
|
||||||
(compare-and-set! program :running :paused))
|
|
||||||
|
|
||||||
(defn kill-program
|
|
||||||
[]
|
|
||||||
(compare-and-set! program :running :paused)
|
|
||||||
(compare-and-set! program :paused :killed))
|
|
||||||
|
|
||||||
(defn start-program
|
|
||||||
[]
|
|
||||||
(when (= (first (reset-vals! program :running)) :stopped)
|
|
||||||
(.start (Thread. game-loop))))
|
|
||||||
|
|
||||||
;; UI
|
;; UI
|
||||||
|
(FlatDarculaLaf/setup)
|
||||||
(defn ignore-args
|
(defn ignore-args
|
||||||
[f]
|
[f]
|
||||||
(fn [& _] (f)))
|
(fn [& _] (f)))
|
||||||
|
34
src/age_of_sail/simulation.clj
Normal file
34
src/age_of_sail/simulation.clj
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
(ns age-of-sail.simulation)
|
||||||
|
|
||||||
|
(def tickrate 100)
|
||||||
|
(def hooks (atom '()))
|
||||||
|
(defn subscribe!
|
||||||
|
"Adds a hook to the hooks"
|
||||||
|
[f]
|
||||||
|
(swap! hooks conj f))
|
||||||
|
|
||||||
|
(defonce program (atom :stopped))
|
||||||
|
|
||||||
|
(defn game-loop
|
||||||
|
[]
|
||||||
|
(while (#{:running :paused} @program)
|
||||||
|
(when (= :running @program)
|
||||||
|
(doseq [hook @hooks]
|
||||||
|
(hook)))
|
||||||
|
(Thread/sleep (quot 1000 tickrate)))
|
||||||
|
(when-not (compare-and-set! program :killed :stopped)
|
||||||
|
(throw "Error: tried to stop a program that wasn't killed!")))
|
||||||
|
|
||||||
|
(defn pause-program
|
||||||
|
[]
|
||||||
|
(compare-and-set! program :running :paused))
|
||||||
|
|
||||||
|
(defn kill-program
|
||||||
|
[]
|
||||||
|
(compare-and-set! program :running :paused)
|
||||||
|
(compare-and-set! program :paused :killed))
|
||||||
|
|
||||||
|
(defn start-program
|
||||||
|
[]
|
||||||
|
(when (= (first (reset-vals! program :running)) :stopped)
|
||||||
|
(.start (Thread. game-loop))))
|
Loading…
Reference in New Issue
Block a user