7b3c5af9949d

Type hinting.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 16 Aug 2011 20:17:33 -0400
parents fb4326dadfe8
children b1007d01decd
branches/tags (none)
files src/clojurecraft/core.clj src/clojurecraft/in.clj src/clojurecraft/out.clj

Changes

diff -r fb4326dadfe8 -r 7b3c5af9949d src/clojurecraft/core.clj
--- a/src/clojurecraft/core.clj	Tue Aug 16 19:56:29 2011 -0400
+++ b/src/clojurecraft/core.clj	Tue Aug 16 20:17:33 2011 -0400
@@ -70,7 +70,7 @@
 
 (defn location-handler [bot]
   (let [conn (:connection bot)
-        outqueue (:outqueue bot)]
+        outqueue ^LinkedBlockingQueue (:outqueue bot)]
     (while (nil? (:exit @conn))
       (let [player (:player bot)
             location (:loc @player)]
@@ -82,7 +82,7 @@
 
 (defn output-handler [bot]
   (let [conn (:connection bot)
-        outqueue (:outqueue bot)]
+        outqueue ^LinkedBlockingQueue (:outqueue bot)]
     (while (nil? (:exit @conn))
       (let [packet (.poll outqueue 1 TimeUnit/SECONDS)]
         (when packet
@@ -92,7 +92,7 @@
 
 (defn action-handler [bot]
   (let [conn (:connection bot)
-        actionqueue (:actionqueue bot)]
+        actionqueue ^LinkedBlockingQueue (:actionqueue bot)]
     (while (nil? (:exit @conn))
       (let [action (.poll actionqueue 1 TimeUnit/SECONDS)]
         (when action
@@ -106,7 +106,7 @@
         in (DataInputStream. (.getInputStream socket))
         out (DataOutputStream. (.getOutputStream socket))
         conn (ref {:in in :out out})
-        outqueue (LinkedBlockingQueue.)
+        outqueue ^LinkedBlockingQueue (LinkedBlockingQueue.)
         actionqueue (LinkedBlockingQueue.)
         world (get-world server)
         bot (Bot. conn username outqueue actionqueue nil world (ref {})
diff -r fb4326dadfe8 -r 7b3c5af9949d src/clojurecraft/in.clj
--- a/src/clojurecraft/in.clj	Tue Aug 16 19:56:29 2011 -0400
+++ b/src/clojurecraft/in.clj	Tue Aug 16 20:17:33 2011 -0400
@@ -2,6 +2,7 @@
   (:use [clojurecraft.util])
   (:use [clojurecraft.mappings])
   (:use [clojurecraft.chunks])
+  (:import (java.io DataInputStream))
   (:require [clojurecraft.data])
   (:require [clojurecraft.events :as events])
   (:import [clojurecraft.data Location Entity Chunk])
@@ -10,7 +11,7 @@
 ; Reading Data ---------------------------------------------------------------------
 (defn- -read-byte-bare [conn]
   (io!
-    (let [b (.readByte (:in @conn))]
+    (let [b (.readByte ^DataInputStream (:in @conn))]
       b)))
 
 (defn- -read-byte [conn]
@@ -19,7 +20,7 @@
 (defn- -read-bytearray-bare [conn size]
   (io!
     (let [ba (byte-array size)]
-         (.read (:in @conn) ba 0 size)
+         (.read ^DataInputStream (:in @conn) ba 0 size)
          ba)))
 
 (defn- -read-bytearray [conn size]
@@ -27,17 +28,17 @@
 
 (defn- -read-int [conn]
   (io!
-    (let [i (.readInt (:in @conn))]
+    (let [i (.readInt ^DataInputStream (:in @conn))]
       (Integer. i))))
 
 (defn- -read-long [conn]
   (io!
-    (let [l (.readLong (:in @conn))]
+    (let [l (.readLong ^DataInputStream (:in @conn))]
       (Long. l))))
 
 (defn- -read-short [conn]
   (io!
-    (let [s (.readShort (:in @conn))]
+    (let [s (.readShort ^DataInputStream (:in @conn))]
       (Short. s))))
 
 (defn- -read-shortarray [conn size]
@@ -45,28 +46,28 @@
 
 (defn- -read-bool [conn]
   (io!
-    (let [b (.readBoolean (:in @conn))]
+    (let [b (.readBoolean ^DataInputStream (:in @conn))]
       (Boolean. b))))
 
 (defn- -read-double [conn]
   (io!
-    (let [d (.readDouble (:in @conn))]
+    (let [d (.readDouble ^DataInputStream (:in @conn))]
       (Double. d))))
 
 (defn- -read-float [conn]
   (io!
-    (let [f (.readFloat (:in @conn))]
+    (let [f (.readFloat ^DataInputStream (:in @conn))]
       (Float. f))))
 
 (defn- -read-string-utf8 [conn]
   (io!
-    (let [s (.readUTF (:in @conn))]
+    (let [s (.readUTF ^DataInputStream (:in @conn))]
       s)))
 
 (defn- -read-string-ucs2 [conn]
   (io!
-    (let [str-len (.readShort (:in @conn))
-          s (doall (apply str (repeatedly str-len #(.readChar (:in @conn)))))]
+    (let [str-len (.readShort ^DataInputStream (:in @conn))
+          s (doall (apply str (repeatedly str-len #(.readChar ^DataInputStream (:in @conn)))))]
       s)))
 
 (defn- -read-metadata [conn]
@@ -400,7 +401,7 @@
         (alter chunks assoc coords chunk)
         chunk)))
 
-(defn- -update-world-with-data [{{chunks :chunks} :world} x y z types meta light sky]
+(defn- -update-world-with-data [{{chunks :chunks} :world} x y z ^bytes types meta light sky]
   (dosync (let [chunk-coords (coords-of-chunk-containing x z)
                 chunk (-get-or-make-chunk chunks chunk-coords)
                 start-index (block-index-in-chunk x y z)]
diff -r fb4326dadfe8 -r 7b3c5af9949d src/clojurecraft/out.clj
--- a/src/clojurecraft/out.clj	Tue Aug 16 19:56:29 2011 -0400
+++ b/src/clojurecraft/out.clj	Tue Aug 16 20:17:33 2011 -0400
@@ -1,41 +1,42 @@
 (ns clojurecraft.out
   (:use [clojurecraft.util])
-  (:use [clojurecraft.mappings]))
+  (:use [clojurecraft.mappings])
+  (:import (java.io DataOutputStream)))
 
 ; Writing Data ---------------------------------------------------------------------
 (defn- -write-byte [conn i]
-  (io! (.writeByte (:out @conn) (int i))))
+  (io! (.writeByte ^DataOutputStream (:out @conn) (int i))))
 
 (defn- -write-bytearray [conn ba]
-  (io! (.write (:out @conn) (byte-array (map byte ba)) 0 (count ba))))
+  (io! (.write ^DataOutputStream (:out @conn) (byte-array (map byte ba)) 0 (count ba))))
 
 (defn- -write-short [conn i]
-  (io! (.writeShort (:out @conn) (short i))))
+  (io! (.writeShort ^DataOutputStream (:out @conn) (short i))))
 
 (defn- -write-shortarray [conn sa]
   (doall (map #(-write-short %) sa)))
 
 (defn- -write-int [conn i]
-  (io! (.writeInt (:out @conn) (int i))))
+  (io! (.writeInt ^DataOutputStream (:out @conn) (int i))))
 
 (defn- -write-long [conn i]
-  (io! (.writeLong (:out @conn) (long i))))
+  (io! (.writeLong ^DataOutputStream (:out @conn) (long i))))
 
 (defn- -write-double [conn i]
-  (io! (.writeDouble (:out @conn) (double i))))
+  (io! (.writeDouble ^DataOutputStream (:out @conn) (double i))))
 
 (defn- -write-float [conn i]
-  (io! (.writeFloat (:out @conn) (float i))))
+  (io! (.writeFloat ^DataOutputStream (:out @conn) (float i))))
 
 (defn- -write-string-utf8 [conn s]
-  (io! (.writeUTF (:out @conn) s)))
+  (io! (.writeUTF ^DataOutputStream (:out @conn) s)))
 
 (defn- -write-string-ucs2 [conn s]
   (-write-short conn (count s))
-  (io! (.writeChars (:out @conn) s)))
+  (io! (.writeChars ^DataOutputStream (:out @conn) s)))
 
 (defn- -write-bool [conn b]
-  (io! (.writeBoolean (:out @conn) b)))
+  (io! (.writeBoolean ^DataOutputStream (:out @conn) b)))
 
 (defn- -write-metadata [conn m]
   ; TODO: Implement this.
@@ -267,7 +268,7 @@
 
 ; Writing Wrappers -----------------------------------------------------------------
 (defn- flushc [conn]
-  (doto (:out @conn) (.flush)))
+  (doto ^DataOutputStream (:out @conn) (.flush)))
 
 (defn write-packet [bot packet-type payload]
   (let [conn (:connection bot)