doc/kishna.tex
changeset 361 1b87b1e0ae1d
parent 357 317fdf38790a
child 362 6c7b4deefdfb
equal deleted inserted replaced
360:359c80ebd964 361:1b87b1e0ae1d
   145 look like on the client side.
   145 look like on the client side.
   146 
   146 
   147 The network code is a bit complicated and has several layers. There
   147 The network code is a bit complicated and has several layers. There
   148 are some nice diagrams about the program structure in the doxygen
   148 are some nice diagrams about the program structure in the doxygen
   149 documentation.
   149 documentation.
       
   150 
       
   151 \subsection{Network}
       
   152 
       
   153 The network code is implemented as separate NetworkServer and NetworkClient modules, which use a common high-level
       
   154 network interface, NetworkSession and NetworkObject.
       
   155 
       
   156 The low-level details are implemented using ClanLib's CL\_IPAddress (referred to as NetworkAddress) and CL\_Socket.
       
   157 NetworkUDP provides an interface to send and receive NetworkPackets to/from specific NetworkAddress's across a 
       
   158 NetworkSocket. NetworkTCP provides a NetworkTCPTransport interface, which can send/receive NetworkPackets on a
       
   159 NetworkSocket (using NetworkBuffer to buffer socket I/O). NetworkTCPServer is a listen() socket which accepts client
       
   160 connections as NetworkTCPTransports, and NetworkTCPClient is a NetworkTCPTransport that's connect()'d to some address.
       
   161 
       
   162 NetworkSession encapsulates some simple application server/client behaviour, it can function as both a server, and
       
   163 represents remote NetworkSessions (either clients or servers) as NetworkNode objects. These then provide an interface
       
   164 to send and receive NetworkPackets on specific NetworkChannelDs, using either TCP or UDP as a reliable/unreliable
       
   165 transport.
       
   166 
       
   167 NetworkObject then implements a kind of object-oriented network protocol. A NetworkObjectController (with specific
       
   168 subclasses for server/client behaviour) uses a NetworkSession to send messages on a specific NetworkChannelID. This
       
   169 controller then creates and looks up NetworkObjects (again, with specific subclasses for server/client behaviour).
       
   170 Clients and servers can then communicate by having the server construct new NetworkObjects (which are allocated an
       
   171 unique id), and then sending NetworkPackets with a specific NetworkMessageID type on a specific object. The message is
       
   172 then delivered directly to the NetworkObject instance on the remote end of the connection, or a new NetworkObject is
       
   173 constructed using the data in the NetworkPacket. This enables an easy way to send events for specific objects, and
       
   174 referr to other objects in these messages.
       
   175 
       
   176 NetworkServer then implements a core NetworkServer class which has a NetworkSession and a
       
   177 NetworkObject\_ServerController. Players that connect are represented as NetworkServerPlayers, which inherit from
       
   178 LocalPlayer and NetworkObject\_Server. This class then overrides methods in Player to deliver messages on the Player
       
   179 object to the clients, or to create new NetworkServerProjectiles. NetworkServerProjectile inherits from Projectile and
       
   180 NetworkObject\_Server, and sends messages when constructed, upon hitting a player, and upon being destroyed.
       
   181 
       
   182 NetworkClient is a bit more complicated as it must handle both the LocalPlayer, and a number of RemotePlayers. Again,
       
   183 NetworkClient has a NetworkSession and a specialized NetworkClientController, which then creates objects of various
       
   184 other NetworkClientClasses upon receiving messages from the server.
       
   185 
       
   186 Two of these classes are NetworkClientLocalPlayer and NetworkClientRemotePlayer. Both inherit from
       
   187 NetworkClientPlayerBase, which inherits Player (virtually) and NetworkObject\_Client. NetworkClientLocalPlayer and
       
   188 NetworkClientRemotePlayer then also inherit LocalPlayer and Remote player virtually, respectively.
       
   189 NetworkClientPlayerBase contains the common methods that update the Player's state in response to messages received
       
   190 from the server. NetworkClientLocalPlayer overrides handleInput to send the input mask to the server, and
       
   191 NetworkClientRemotePlayer can handle remote clients disconnecting from the server.
       
   192 
       
   193 In addition, there is a NetworkClientProjectile class, which inherits from Projectile and NetworkObject\_Client.
       
   194 this is created when a Player fires a Weapon on the server, and handles events received from the server like the
       
   195 projectile hitting a player (inflicting damage), or being destroyed (by hitting the terrain or something similar).
       
   196 
       
   197 When the player first connects to the server, the server sends a large packet containing the terrain array to the
       
   198 client, which updates its own GameState world's terrain array with the received data.
       
   199 
       
   200 Currently, the client only sends handleInput using unreliable UDP messages, and the server only sends position updates
       
   201 (as sent in response to handleInput events) unreliably. All other events are sent using reliable TCP.
   150 
   202 
   151 \section{Data structures and algorithms}
   203 \section{Data structures and algorithms}
   152 
   204 
   153 \subsection{Basic data structures}
   205 \subsection{Basic data structures}
   154 
   206 
   288 it on to LocalPlayer, which then either handles it locally, or sends it to the remote server.
   340 it on to LocalPlayer, which then either handles it locally, or sends it to the remote server.
   289 
   341 
   290 Since some inputs like walking, aiming and moving up and down the rope are time-dependant, the InputHandler also tracks
   342 Since some inputs like walking, aiming and moving up and down the rope are time-dependant, the InputHandler also tracks
   291 how many milliseconds the input mask has been held, and this time delta is applied by LocalPlayer.
   343 how many milliseconds the input mask has been held, and this time delta is applied by LocalPlayer.
   292 
   344 
   293 \subsection{Network}
       
   294 
       
   295 The network code is implemented as separate NetworkServer and NetworkClient modules, which use a common high-level
       
   296 network interface, NetworkSession and NetworkObject.
       
   297 
       
   298 The low-level details are implemented using ClanLib's CL\_IPAddress (referred to as NetworkAddress) and CL\_Socket.
       
   299 NetworkUDP provides an interface to send and receive NetworkPackets to/from specific NetworkAddress's across a 
       
   300 NetworkSocket. NetworkTCP provides a NetworkTCPTransport interface, which can send/receive NetworkPackets on a
       
   301 NetworkSocket (using NetworkBuffer to buffer socket I/O). NetworkTCPServer is a listen() socket which accepts client
       
   302 connections as NetworkTCPTransports, and NetworkTCPClient is a NetworkTCPTransport that's connect()'d to some address.
       
   303 
       
   304 NetworkSession encapsulates some simple application server/client behaviour, it can function as both a server, and
       
   305 represents remote NetworkSessions (either clients or servers) as NetworkNode objects. These then provide an interface
       
   306 to send and receive NetworkPackets on specific NetworkChannelDs, using either TCP or UDP as a reliable/unreliable
       
   307 transport.
       
   308 
       
   309 NetworkObject then implements a kind of object-oriented network protocol. A NetworkObjectController (with specific
       
   310 subclasses for server/client behaviour) uses a NetworkSession to send messages on a specific NetworkChannelID. This
       
   311 controller then creates and looks up NetworkObjects (again, with specific subclasses for server/client behaviour).
       
   312 Clients and servers can then communicate by having the server construct new NetworkObjects (which are allocated an
       
   313 unique id), and then sending NetworkPackets with a specific NetworkMessageID type on a specific object. The message is
       
   314 then delivered directly to the NetworkObject instance on the remote end of the connection, or a new NetworkObject is
       
   315 constructed using the data in the NetworkPacket. This enables an easy way to send events for specific objects, and
       
   316 referr to other objects in these messages.
       
   317 
       
   318 NetworkServer then implements a core NetworkServer class which has a NetworkSession and a
       
   319 NetworkObject\_ServerController. Players that connect are represented as NetworkServerPlayers, which inherit from
       
   320 LocalPlayer and NetworkObject\_Server. This class then overrides methods in Player to deliver messages on the Player
       
   321 object to the clients, or to create new NetworkServerProjectiles. NetworkServerProjectile inherits from Projectile and
       
   322 NetworkObject\_Server, and sends messages when constructed, upon hitting a player, and upon being destroyed.
       
   323 
       
   324 NetworkClient is a bit more complicated as it must handle both the LocalPlayer, and a number of RemotePlayers. Again,
       
   325 NetworkClient has a NetworkSession and a specialized NetworkClientController, which then creates objects of various
       
   326 other NetworkClientClasses upon receiving messages from the server.
       
   327 
       
   328 Two of these classes are NetworkClientLocalPlayer and NetworkClientRemotePlayer. Both inherit from
       
   329 NetworkClientPlayerBase, which inherits Player (virtually) and NetworkObject\_Client. NetworkClientLocalPlayer and
       
   330 NetworkClientRemotePlayer then also inherit LocalPlayer and Remote player virtually, respectively.
       
   331 NetworkClientPlayerBase contains the common methods that update the Player's state in response to messages received
       
   332 from the server. NetworkClientLocalPlayer overrides handleInput to send the input mask to the server, and
       
   333 NetworkClientRemotePlayer can handle remote clients disconnecting from the server.
       
   334 
       
   335 In addition, there is a NetworkClientProjectile class, which inherits from Projectile and NetworkObject\_Client.
       
   336 this is created when a Player fires a Weapon on the server, and handles events received from the server like the
       
   337 projectile hitting a player (inflicting damage), or being destroyed (by hitting the terrain or something similar).
       
   338 
       
   339 When the player first connects to the server, the server sends a large packet containing the terrain array to the
       
   340 client, which updates its own GameState world's terrain array with the received data.
       
   341 
       
   342 Currently, the client only sends handleInput using unreliable UDP messages, and the server only sends position updates
       
   343 (as sent in response to handleInput events) unreliably. All other events are sent using reliable TCP.
       
   344 
       
   345 \section{Known bugs}
   345 \section{Known bugs}
   346 \begin{enumerate}
   346 \begin{enumerate}
   347 \item If player dies while rope is attached the rope will still be
   347 \item If player dies while rope is attached the rope will still be
   348     attached when the player spawns.
   348     attached when the player spawns.
   349 \item If rope is thrown without releasing it first, rope will pull worm
   349 \item If rope is thrown without releasing it first, rope will pull worm
   375 development, which was a good thing. The basic structure of the program is
   375 development, which was a good thing. The basic structure of the program is
   376 pretty much as the one we thought about while planning, although the Network
   376 pretty much as the one we thought about while planning, although the Network
   377 code ended up being a fair bit more simple-minded due to lack of time to
   377 code ended up being a fair bit more simple-minded due to lack of time to
   378 implement more UDP-based behaviour.
   378 implement more UDP-based behaviour.
   379 
   379 
       
   380 Currently, the program lacks an AI which was in the original plan and most of the optional features were also omitted. Liero clone proved to be, however, a very interesting software project and we are hoping to release Kishna Glista 2.0 one day.
       
   381 
   380 % References
   382 % References
   381 \begin{thebibliography}{99}
   383 \begin{thebibliography}{99}
   382 \bibitem{gaffer} Gaffer on games. Game
   384 \bibitem{gaffer} Gaffer on games. Game Physics. 2006. \\
   383   Physics. 2006. http://gafferongames.wordpress.com/game-physics/
   385  http://gafferongames.wordpress.com/game-physics/ (read: 2008-12-08)
   384   (read: 2008-12-08)
       
   385 \bibitem{fractal} Terrain texture generation.  http://www.gameprogrammer.com/fractal.html
   386 \bibitem{fractal} Terrain texture generation.  http://www.gameprogrammer.com/fractal.html
   386 \end{thebibliography}
   387 \end{thebibliography}
   387 
   388 
   388 \end{document}
   389 \end{document}