Defining Sprites


An Overview of NetTour3D

Figure 32-2 shows the main objects involved in a NetTour3D world.

The application uses a threaded client/server model, much like the threaded chat application in Chapter 30.

The NetTour3D application is the client. It creates a WrapNetTour3D object to build the world and to handle communication with the TourServer server. The world consists of a checkerboard, background, lighting, and scenery loaded from a tour file with the help of a PropManager object (first used in Chapter 16). No 3D objects or images need to be transferred over the network; all the necessary 3D models are present on the client.

Figure 32-2. Objects in a NetTour3D world


WrapNetTour3D starts a TouristControls object to monitor the client's key presses, which move the client's local sprite (the ones colored blue in Figure 32-1) or adjust the third-person camera. TouristControls is unchanged from the Tour3D example in Chapter 18.WrapNetTour3D sends messages to the server, and the monitoring of messages coming from the server is delegated to a TourWatcher object. Most of these messages will be related to the creation and movement of distributed sprites (the sprites representing other clients, colored orange in Figure 32-1). TourWatcher manages these sprites and updates them in response to the server's messages.

TourServer creates a TourServerHandler thread for each client who connects to it and stores information about the connections in a shared TourGroup object in an ArrayList of TouristInfo objects. The main task of the server is to accept a message from one client and broadcast it to the others.

Class Diagrams for NetTour3D

Figure 32-3 shows class diagrams for the NetTour3D client application and the TourServer server. Only the class names are shown. Most of the classes in Figure 32-3 have been summarized.

CheckerFloor and ColouredTiles create the checkerboard floor. PropManager loads the scenery, and Obstacles sets up the obstacles specified in a tour file.

Figure 32-3. Class diagrams for NetTour3D and TourServer


All the code for this example (the NetTour3D client and TourServer server) is in the NetTour3D/ directory.


NetTour3D as a Simple NVE

The key elements that make up a fully featured NVE are spaces, users, objects, views, and the notions of consistency, real-time, dead reckoning, security, and scalability. How does NetTour3D measure up against these?

NetTour3D utilizes only one space (the checkerboard), and users all have the same appearance (but different names). The local and ghost avatars idea is present, called local and distributed sprites in this chapter. TourSprite manages the local sprite, and DistTourSprite manages a distributed sprite. The only view is a third-person camera. Objects in the form of scenery and obstacles can be easily added to the world, but they are static (not mobile, reactive, or intelligent). There is no way for NetTour3D users to interact. None of the NVE ideas of consistency, real-time, dead reckoning, security, and scalability are addressed here.

A TCP/IP client/server communication model is employed in NetTour3D, whereas a more realistic approach would include UDP multicasting and peer-to-peer elements and deploy some kind of connection manager.



Killer Game Programming in Java
Killer Game Programming in Java
ISBN: 0596007302
EAN: 2147483647
Year: 2006
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net