827c992e7b65

Clean up in.clj.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 21 Jul 2011 18:47:59 -0400
parents 8ce0defe8afc
children 2e6076224d34
branches/tags (none)
files src/clojurecraft/core.clj src/clojurecraft/in.clj todo.org

Changes

--- a/src/clojurecraft/core.clj	Thu Jul 21 18:42:21 2011 -0400
+++ b/src/clojurecraft/core.clj	Thu Jul 21 18:47:59 2011 -0400
@@ -89,7 +89,7 @@
 
 ; Scratch --------------------------------------------------------------------------
 ;(def bot (connect minecraft-local))
-;(act/move bot 2 0 0)
+;(act/move bot 1 0 2)
 ;(pprint @(:packet-counts-in bot))
 ;(pprint @(:packet-counts-out bot))
 ;(pprint (:player bot))
--- a/src/clojurecraft/in.clj	Thu Jul 21 18:42:21 2011 -0400
+++ b/src/clojurecraft/in.clj	Thu Jul 21 18:47:59 2011 -0400
@@ -19,69 +19,80 @@
 
 ; Reading Data ---------------------------------------------------------------------
 (defn- -read-byte [conn]
-  (let [b (.readByte (:in @conn))]
-    b))
+  (io! 
+    (let [b (.readByte (:in @conn))]
+      b)))
 
 (defn- -read-bytearray [conn size]
-  (let [ba (byte-array size)]
-    (.read (:in @conn) ba 0 size)
-    ba))
+  (io! 
+    (let [ba (byte-array size)]
+         (.read (:in @conn) ba 0 size)
+         ba)))
 
 (defn- -read-int [conn]
-  (let [i (.readInt (:in @conn))]
-    i))
+  (io! 
+    (let [i (.readInt (:in @conn))]
+      i)))
 
 (defn- -read-long [conn]
-  (let [i (.readLong (:in @conn))]
-    i))
+  (io! 
+    (let [i (.readLong (:in @conn))]
+      i)))
 
 (defn- -read-short [conn]
-  (let [i (.readShort (:in @conn))]
-    i))
+  (io!
+    (let [i (.readShort (:in @conn))]
+      i)))
 
 (defn- -read-shortarray [conn size]
   (doall (repeatedly size #(-read-short conn))))
 
 (defn- -read-bool [conn]
-  (let [b (.readBoolean (:in @conn))]
-    b))
+  (io!
+    (let [b (.readBoolean (:in @conn))]
+      b)))
 
 (defn- -read-double [conn]
-  (let [i (.readDouble (:in @conn))]
-    i))
+  (io!
+    (let [i (.readDouble (:in @conn))]
+      i)))
 
 (defn- -read-float [conn]
-  (let [i (.readFloat (:in @conn))]
-    i))
+  (io!
+    (let [i (.readFloat (:in @conn))]
+      i)))
 
 (defn- -read-string-utf8 [conn]
-  (let [s (.readUTF (:in @conn))]
-    s))
+  (io!
+    (let [s (.readUTF (:in @conn))]
+      s)))
 
 (defn- -read-string-ucs2 [conn]
-  (let [str-len (.readShort (:in @conn))
-                s (doall (apply str (repeatedly str-len #(.readChar (:in @conn)))))]
-    s))
+  (io!
+    (let [str-len (.readShort (:in @conn))
+          s (doall (apply str (repeatedly str-len #(.readChar (:in @conn)))))]
+      s)))
 
 (defn- -read-metadata [conn]
-  (loop [data []]
-    (let [x (-read-byte conn)]
-      (if (= x 127)
-        data
-        (case (bit-shift-right x 5)
-          0 (recur (conj data (-read-byte conn)))
-          1 (recur (conj data (-read-short conn)))
-          2 (recur (conj data (-read-int conn)))
-          3 (recur (conj data (-read-float conn)))
-          4 (recur (conj data (-read-string-ucs2 conn)))
-          5 (recur (conj data (assoc {}
-                                     :id (-read-short conn)
-                                     :count (-read-byte conn)
-                                     :damage (-read-short conn))))
-          6 (recur (conj data (assoc {}
-                                     :i (-read-int conn)
-                                     :j (-read-int conn)
-                                     :k (-read-int conn)))))))))
+  (io! 
+    (loop [data []]
+      (let [x (-read-byte conn)]
+        (if (= x 127)
+          data
+          (case (bit-shift-right x 5)
+            0 (recur (conj data (-read-byte conn)))
+            1 (recur (conj data (-read-short conn)))
+            2 (recur (conj data (-read-int conn)))
+            3 (recur (conj data (-read-float conn)))
+            4 (recur (conj data (-read-string-ucs2 conn)))
+            5 (recur (conj data (assoc {}
+                                       :id (-read-short conn)
+                                       :count (-read-byte conn)
+                                       :damage (-read-short conn))))
+            6 (recur (conj data (assoc {}
+                                       :i (-read-int conn)
+                                       :j (-read-int conn)
+                                       :k (-read-int conn))))))))))
 
 
 ; Reading Packets ------------------------------------------------------------------
--- a/todo.org	Thu Jul 21 18:42:21 2011 -0400
+++ b/todo.org	Thu Jul 21 18:47:59 2011 -0400
@@ -1,4 +1,4 @@
-* TODO Wrap all IO in io!.
+* DONE Wrap all IO in io!.
 * TODO Wrap class mutations in io!?
 * TODO Use Clojure's ugly keyword arguments.