From 246213c8a25efd4f471343a46e91e7b8eb52b327 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Sat, 9 Mar 2013 09:27:42 -0600 Subject: [PATCH] Initial integration with Slick2d, including hot code reloading --- project.clj | 10 +++++++++- src/hottub/core.clj | 5 +++++ src/hottub/slick.clj | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/hottub/core.clj create mode 100644 src/hottub/slick.clj diff --git a/project.clj b/project.clj index 5cf403d..1c62f32 100644 --- a/project.clj +++ b/project.clj @@ -1,3 +1,11 @@ (defproject hottub "1.0.0-SNAPSHOT" :description "Hot Tub Time Machine Game Engine" - :dependencies [[org.clojure/clojure "1.5.0"]]) \ No newline at end of file + :aot [hottub.slick] + :main hottub.core + :native-path "native" + :jvm-opts ["-Djava.library.path=native"] + :dependencies [[org.clojure/clojure "1.5.0"] + [ns-tracker "0.2.1"] + [org.clojars.jyaan/slick "247.1"] + [org.clojars.jyaan/slick-native "247.1"] + [org.clojars.jyaan/slick-lwjgl "247.1"]]) diff --git a/src/hottub/core.clj b/src/hottub/core.clj new file mode 100644 index 0000000..1466f80 --- /dev/null +++ b/src/hottub/core.clj @@ -0,0 +1,5 @@ +(ns hottub.core + (:require [hottub.slick :as slick])) + +(defn -main [& args] + (slick/start-game "test-game" :game)) diff --git a/src/hottub/slick.clj b/src/hottub/slick.clj new file mode 100644 index 0000000..e885fcf --- /dev/null +++ b/src/hottub/slick.clj @@ -0,0 +1,39 @@ +(ns hottub.slick + (:import [org.newdawn.slick AppGameContainer]) + (:use ns-tracker.core)) + +(defmulti update-game (fn [state delta] (:state state))) +(defmulti render-game (fn [state graphics] (:state state))) + +(def modified-namespaces (ns-tracker ["src" "test"])) + +(gen-class + :name hottub.slick.Game + :prefix game- + :init create + :constructors {[String clojure.lang.Keyword clojure.lang.PersistentArrayMap] [String]} + :state state + :extends org.newdawn.slick.BasicGame) + +(defn game-create [title startstate value] + [[title] (ref (assoc (or value {}) :state startstate))]) + +(defn game-init [this container]) + +(defn game-update [this container delta] + (doseq [ns-sym (modified-namespaces)] + (require ns-sym :reload)) + (dosync + (if-let [statenew (update-game @(.state this) delta)] + (ref-set (.state this) (assoc @(.state this) :state statenew))))) + +(defn game-render [this container graphics] + (render-game @(.state this) graphics)) + +(defmethod update-game :default [state delta]) +(defmethod render-game :default [state graphics]) + +(defn start-game [title startstate & [value]] + (let [game (hottub.slick.Game. title startstate value) + container (AppGameContainer. game 640 480 false)] + (.start container)))