Initial integration with Slick2d, including hot code reloading

This commit is contained in:
Jeremy Penner 2013-03-09 09:27:42 -06:00
parent 492b5393a1
commit 246213c8a2
3 changed files with 53 additions and 1 deletions

View file

@ -1,3 +1,11 @@
(defproject hottub "1.0.0-SNAPSHOT"
:description "Hot Tub Time Machine Game Engine"
:dependencies [[org.clojure/clojure "1.5.0"]])
: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"]])

5
src/hottub/core.clj Normal file
View file

@ -0,0 +1,5 @@
(ns hottub.core
(:require [hottub.slick :as slick]))
(defn -main [& args]
(slick/start-game "test-game" :game))

39
src/hottub/slick.clj Normal file
View file

@ -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)))