diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 5ed9149..fe7009c 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -184,8 +184,8 @@ (defun draw-map (win) "Draw a portion of the game map in an ncurses window" - ;;FIXME request each patch char singly from the server - doing it all - ;; in one batch seems to take too many resources + ;;XXX request each patch char singly from the server - doing it all + ;; in one batch seems to take too many resources? (setf (croatoan:.color-pair win) '(:white :black)) (croatoan:box win) (croatoan:move win 1 1) @@ -194,7 +194,7 @@ ;; It's a bit ugly that I have to do a `read-from-string` here, ;; but see the server-side function `get-map' for details (submap (read-from-string - (query-server "map" map-width map-height)))) + (query-server "map" map-width map-height)))) (dotimes (h map-height) (dotimes (w map-width) (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 5ed9149..fe7009c 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -184,8 +184,8 @@ (defun draw-map (win) "Draw a portion of the game map in an ncurses window" - ;;FIXME request each patch char singly from the server - doing it all - ;; in one batch seems to take too many resources + ;;XXX request each patch char singly from the server - doing it all + ;; in one batch seems to take too many resources? (setf (croatoan:.color-pair win) '(:white :black)) (croatoan:box win) (croatoan:move win 1 1) @@ -194,7 +194,7 @@ ;; It's a bit ugly that I have to do a `read-from-string` here, ;; but see the server-side function `get-map' for details (submap (read-from-string - (query-server "map" map-width map-height)))) + (query-server "map" map-width map-height)))) (dotimes (h map-height) (dotimes (w map-width) (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) diff --git a/server/item-methods.lisp b/server/item-methods.lisp index 2e6afbd..997e983 100644 --- a/server/item-methods.lisp +++ b/server/item-methods.lisp @@ -10,6 +10,19 @@ (in-package :naledi-ya-africa) +(defmethod move ((a animal) dir) + (let* ((here (coord (.x a) (.y a))) + (target (coordsindir (.x a) (.y a) dir)) + (target-patch (coord target))) + (cond ((null target-patch) + (logf 3 "~S is attempting to move out of bounds ~S" a target)) + ((patch-occupant target-patch) + (logf 3 "~S is moving onto occupied patch ~S (~S)" + a target (patch-occupant target-patch))) + (T (setf (patch-occupant here) NIL) + (setf (patch-occupant target-patch) a) + (setf (.x a) (first target) (.y a) (second target)))))) + ;; Default `update' and `action' methods are NOP (defmethod update ((i item))) (defmethod action ((i item))) @@ -34,6 +47,7 @@ (defmethod random-move ((a animal)) "Move in a random direction within the species' habitat niche" + ;;TODO rewrite with `move' (do* ((dir (random-elt *directions*) (random-elt *directions*)) (next-patch (patchindir (.x a) (.y a) dir) (patchindir (.x a) (.y a) dir)) diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 5ed9149..fe7009c 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -184,8 +184,8 @@ (defun draw-map (win) "Draw a portion of the game map in an ncurses window" - ;;FIXME request each patch char singly from the server - doing it all - ;; in one batch seems to take too many resources + ;;XXX request each patch char singly from the server - doing it all + ;; in one batch seems to take too many resources? (setf (croatoan:.color-pair win) '(:white :black)) (croatoan:box win) (croatoan:move win 1 1) @@ -194,7 +194,7 @@ ;; It's a bit ugly that I have to do a `read-from-string` here, ;; but see the server-side function `get-map' for details (submap (read-from-string - (query-server "map" map-width map-height)))) + (query-server "map" map-width map-height)))) (dotimes (h map-height) (dotimes (w map-width) (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) diff --git a/server/item-methods.lisp b/server/item-methods.lisp index 2e6afbd..997e983 100644 --- a/server/item-methods.lisp +++ b/server/item-methods.lisp @@ -10,6 +10,19 @@ (in-package :naledi-ya-africa) +(defmethod move ((a animal) dir) + (let* ((here (coord (.x a) (.y a))) + (target (coordsindir (.x a) (.y a) dir)) + (target-patch (coord target))) + (cond ((null target-patch) + (logf 3 "~S is attempting to move out of bounds ~S" a target)) + ((patch-occupant target-patch) + (logf 3 "~S is moving onto occupied patch ~S (~S)" + a target (patch-occupant target-patch))) + (T (setf (patch-occupant here) NIL) + (setf (patch-occupant target-patch) a) + (setf (.x a) (first target) (.y a) (second target)))))) + ;; Default `update' and `action' methods are NOP (defmethod update ((i item))) (defmethod action ((i item))) @@ -34,6 +47,7 @@ (defmethod random-move ((a animal)) "Move in a random direction within the species' habitat niche" + ;;TODO rewrite with `move' (do* ((dir (random-elt *directions*) (random-elt *directions*)) (next-patch (patchindir (.x a) (.y a) dir) (patchindir (.x a) (.y a) dir)) diff --git a/server/player.lisp b/server/player.lisp index 506e38c..76a462c 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -35,10 +35,6 @@ ;;TODO ) -(defmethod move ((h human) dir) - ;;TODO - ) - ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 5ed9149..fe7009c 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -184,8 +184,8 @@ (defun draw-map (win) "Draw a portion of the game map in an ncurses window" - ;;FIXME request each patch char singly from the server - doing it all - ;; in one batch seems to take too many resources + ;;XXX request each patch char singly from the server - doing it all + ;; in one batch seems to take too many resources? (setf (croatoan:.color-pair win) '(:white :black)) (croatoan:box win) (croatoan:move win 1 1) @@ -194,7 +194,7 @@ ;; It's a bit ugly that I have to do a `read-from-string` here, ;; but see the server-side function `get-map' for details (submap (read-from-string - (query-server "map" map-width map-height)))) + (query-server "map" map-width map-height)))) (dotimes (h map-height) (dotimes (w map-width) (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) diff --git a/server/item-methods.lisp b/server/item-methods.lisp index 2e6afbd..997e983 100644 --- a/server/item-methods.lisp +++ b/server/item-methods.lisp @@ -10,6 +10,19 @@ (in-package :naledi-ya-africa) +(defmethod move ((a animal) dir) + (let* ((here (coord (.x a) (.y a))) + (target (coordsindir (.x a) (.y a) dir)) + (target-patch (coord target))) + (cond ((null target-patch) + (logf 3 "~S is attempting to move out of bounds ~S" a target)) + ((patch-occupant target-patch) + (logf 3 "~S is moving onto occupied patch ~S (~S)" + a target (patch-occupant target-patch))) + (T (setf (patch-occupant here) NIL) + (setf (patch-occupant target-patch) a) + (setf (.x a) (first target) (.y a) (second target)))))) + ;; Default `update' and `action' methods are NOP (defmethod update ((i item))) (defmethod action ((i item))) @@ -34,6 +47,7 @@ (defmethod random-move ((a animal)) "Move in a random direction within the species' habitat niche" + ;;TODO rewrite with `move' (do* ((dir (random-elt *directions*) (random-elt *directions*)) (next-patch (patchindir (.x a) (.y a) dir) (patchindir (.x a) (.y a) dir)) diff --git a/server/player.lisp b/server/player.lisp index 506e38c..76a462c 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -35,10 +35,6 @@ ;;TODO ) -(defmethod move ((h human) dir) - ;;TODO - ) - ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/server/server.lisp b/server/server.lisp index 3fe01ae..328afd2 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -47,8 +47,8 @@ ;;; WORLD OBJECT (let ((world NIL)) - ;;TODO we need to keep track of the current world map (i.e. patch chars and colours), - ;; otherwise player map requests will take way too long to serve + ;;XXX do we need to keep track of the current world map (i.e. patch chars + ;; and colours),or player map requests will take way too long to serve? (defun set-world (w) (setf world w)) (defun world-size () (length world)) @@ -158,7 +158,7 @@ (save-world) ;XXX not yet implemented (incf uptime) (sleep (/ *framerate* 1000)) - (when running (update-loop))) ;;requires Tail-Call Optimization + (when running (update-loop))) ;;CAVE requires Tail-Call Optimization (defun run-server () "Start a server, listening for connections" @@ -241,10 +241,9 @@ (login name passwd)))) (defun get-map (swidth sheight) - "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" + "Return a 3D array (x-coord, y-coord, character/colour) of the visible map" ;;TODO It's too inefficient to compile a new map for every player at every - ;; request. Keep a central map? - ;;FIXME exhausts the heap?! -> only return one patch char at a time + ;; request. Keep a central map? -> XXX Is this indeed the case? ;;XXX implement of "field of view" for each player? (let* ((plr (player-human (get-player (thread-player)))) (width (read-from-string swidth)) @@ -252,7 +251,7 @@ (x0 (- (.x plr) (halve width))) (y0 (- (.y plr) (halve height))) (submap (make-array (list width height 2)))) - (dotimes (h height) + (dotimes (h height submap) ;;XXX remove submap again of doesn't work (dotimes (w width) (let ((p (coord (+ w x0 1) (+ h y0 1))) (next-char #\space) (next-col ':black)) @@ -262,14 +261,14 @@ (when p (setf next-char (biome-char (patch-biome p)) next-col (biome-col (patch-biome p))))) (setf (aref submap w h 0) next-char - (aref submap w h 1) next-col)))) + (aref submap w h 1) next-col)))))) ;;XXX Arrays are pretty-printed with linebreaks, this causes a ;; client-side error (as the client only expects one line). ;; The following code takes apart such a pretty print and puts it ;; back together without linebreaks. However, this means that the ;; server returns a map string enclosed in _two_ quotation marks, ;; so the client has to perform an additional call to `read-from-string` - (string-from-list (split-string (to-string submap) #\newline) ""))) + ;;(string-from-list (split-string (to-string submap) #\newline) ""))) (defun describe-patch (&optional (x 0) (y 0)) "Return a set of lines describing the patch at these coordinates." @@ -291,6 +290,7 @@ (defun move-player (dir) "Move a player in the given direction" (let ((plr (player-human (get-player (thread-player))))) + ;;TODO replace cond with read-from-string? (cond ((equalp dir "n") (move plr 'n)) ((equalp dir "ne") (move plr 'ne)) ((equalp dir "e") (move plr 'e)) diff --git a/TODO b/TODO index 24330d9..9a5f63d 100644 --- a/TODO +++ b/TODO @@ -27,8 +27,6 @@ -> SEVERE -* Heap exhaustion on map reload! - * `terminate` hangs when a player is still logged in * world thread type error: "The value -1 is not of type unsigned-byte when binding diff --git a/client/user-interface.lisp b/client/user-interface.lisp index 5ed9149..fe7009c 100644 --- a/client/user-interface.lisp +++ b/client/user-interface.lisp @@ -184,8 +184,8 @@ (defun draw-map (win) "Draw a portion of the game map in an ncurses window" - ;;FIXME request each patch char singly from the server - doing it all - ;; in one batch seems to take too many resources + ;;XXX request each patch char singly from the server - doing it all + ;; in one batch seems to take too many resources? (setf (croatoan:.color-pair win) '(:white :black)) (croatoan:box win) (croatoan:move win 1 1) @@ -194,7 +194,7 @@ ;; It's a bit ugly that I have to do a `read-from-string` here, ;; but see the server-side function `get-map' for details (submap (read-from-string - (query-server "map" map-width map-height)))) + (query-server "map" map-width map-height)))) (dotimes (h map-height) (dotimes (w map-width) (let ((pch (aref submap w h 0)) (pcol (aref submap w h 1))) diff --git a/server/item-methods.lisp b/server/item-methods.lisp index 2e6afbd..997e983 100644 --- a/server/item-methods.lisp +++ b/server/item-methods.lisp @@ -10,6 +10,19 @@ (in-package :naledi-ya-africa) +(defmethod move ((a animal) dir) + (let* ((here (coord (.x a) (.y a))) + (target (coordsindir (.x a) (.y a) dir)) + (target-patch (coord target))) + (cond ((null target-patch) + (logf 3 "~S is attempting to move out of bounds ~S" a target)) + ((patch-occupant target-patch) + (logf 3 "~S is moving onto occupied patch ~S (~S)" + a target (patch-occupant target-patch))) + (T (setf (patch-occupant here) NIL) + (setf (patch-occupant target-patch) a) + (setf (.x a) (first target) (.y a) (second target)))))) + ;; Default `update' and `action' methods are NOP (defmethod update ((i item))) (defmethod action ((i item))) @@ -34,6 +47,7 @@ (defmethod random-move ((a animal)) "Move in a random direction within the species' habitat niche" + ;;TODO rewrite with `move' (do* ((dir (random-elt *directions*) (random-elt *directions*)) (next-patch (patchindir (.x a) (.y a) dir) (patchindir (.x a) (.y a) dir)) diff --git a/server/player.lisp b/server/player.lisp index 506e38c..76a462c 100644 --- a/server/player.lisp +++ b/server/player.lisp @@ -35,10 +35,6 @@ ;;TODO ) -(defmethod move ((h human) dir) - ;;TODO - ) - ;; INVENTORY HANDLING FUNCTIONS ;;TODO convert to methods diff --git a/server/server.lisp b/server/server.lisp index 3fe01ae..328afd2 100644 --- a/server/server.lisp +++ b/server/server.lisp @@ -47,8 +47,8 @@ ;;; WORLD OBJECT (let ((world NIL)) - ;;TODO we need to keep track of the current world map (i.e. patch chars and colours), - ;; otherwise player map requests will take way too long to serve + ;;XXX do we need to keep track of the current world map (i.e. patch chars + ;; and colours),or player map requests will take way too long to serve? (defun set-world (w) (setf world w)) (defun world-size () (length world)) @@ -158,7 +158,7 @@ (save-world) ;XXX not yet implemented (incf uptime) (sleep (/ *framerate* 1000)) - (when running (update-loop))) ;;requires Tail-Call Optimization + (when running (update-loop))) ;;CAVE requires Tail-Call Optimization (defun run-server () "Start a server, listening for connections" @@ -241,10 +241,9 @@ (login name passwd)))) (defun get-map (swidth sheight) - "Return a 3d array (x-coord, y-coord, character/colour) of the visible map" + "Return a 3D array (x-coord, y-coord, character/colour) of the visible map" ;;TODO It's too inefficient to compile a new map for every player at every - ;; request. Keep a central map? - ;;FIXME exhausts the heap?! -> only return one patch char at a time + ;; request. Keep a central map? -> XXX Is this indeed the case? ;;XXX implement of "field of view" for each player? (let* ((plr (player-human (get-player (thread-player)))) (width (read-from-string swidth)) @@ -252,7 +251,7 @@ (x0 (- (.x plr) (halve width))) (y0 (- (.y plr) (halve height))) (submap (make-array (list width height 2)))) - (dotimes (h height) + (dotimes (h height submap) ;;XXX remove submap again of doesn't work (dotimes (w width) (let ((p (coord (+ w x0 1) (+ h y0 1))) (next-char #\space) (next-col ':black)) @@ -262,14 +261,14 @@ (when p (setf next-char (biome-char (patch-biome p)) next-col (biome-col (patch-biome p))))) (setf (aref submap w h 0) next-char - (aref submap w h 1) next-col)))) + (aref submap w h 1) next-col)))))) ;;XXX Arrays are pretty-printed with linebreaks, this causes a ;; client-side error (as the client only expects one line). ;; The following code takes apart such a pretty print and puts it ;; back together without linebreaks. However, this means that the ;; server returns a map string enclosed in _two_ quotation marks, ;; so the client has to perform an additional call to `read-from-string` - (string-from-list (split-string (to-string submap) #\newline) ""))) + ;;(string-from-list (split-string (to-string submap) #\newline) ""))) (defun describe-patch (&optional (x 0) (y 0)) "Return a set of lines describing the patch at these coordinates." @@ -291,6 +290,7 @@ (defun move-player (dir) "Move a player in the given direction" (let ((plr (player-human (get-player (thread-player))))) + ;;TODO replace cond with read-from-string? (cond ((equalp dir "n") (move plr 'n)) ((equalp dir "ne") (move plr 'ne)) ((equalp dir "e") (move plr 'e)) diff --git a/server/world.lisp b/server/world.lisp index 548fafc..786c040 100644 --- a/server/world.lisp +++ b/server/world.lisp @@ -44,7 +44,7 @@ (defun init-matrix (size) "Create a square matrix of empty patches" - ;;FIXME change this to arrays for performance + ;;XXX change this to arrays for performance (logf 4 "~&Creating a ~S/~S matrix." size size) (do ((y 0 (1+ y)) (world NIL) (row NIL NIL)) ((= y size) world)