Documente Academic
Documente Profesional
Documente Cultură
Supervised by: Dr. Tony White School of Computer Science Carleton University Ottawa, Canada
Abstract
The goal of this project is to create a multiplayer game that uses both a computer screen and an Android device to convey information to its players. The main focus will be producing software that will provide a zero-configuration networking experience to the user, through the use of service discovery. The local area network service discovery will be handled by the Bonjour library, and the remote through a simple name server registration setup. Messaging will be handled by the RabbitMQ library with JSON being used for serialization. The game will use OpenGL ES 1.1 for Android and the whole project will be programmed in Java. With the imminent release of the Wii-U and the rising popularity of smart televisions, we will soon see a rise in the number of multi-screen applications being released. It is for this reason that I have chosen to create an application of the sort for my project. A few problems arise when creating a multi-screen application, due to the involvement of multiple devices. The first problem is discovery of devices and the second is communication between said devices. With this project, I hope to provide an implementation of such an application by using a combination of pre-existing technologies. From this project I hope to acquire a better understanding of the technologies required in order to develop both locally and remotely distributed applications, and to learn how to create an application that requires very little configuration in order to begin the communication between devices. In addition to this, I want to apply my knowledge of DirectX in order to learn how to implement games with OpenGL on a handheld device.
Page 2
Acknowledgement
There are a few people at this point that I would like to recognize, for making some of contribution to this project. First of all, I would like to thank Dr. Tony White for his patience and help starting me off on the right track, and for the interest in these subjects that I acquired during his Comp 4104 class. I would also like to thank my family, for their motivation along the way and my friends, for allowing me to ignore them for a while.
Page 3
Table of Contents
Abstract ........................................................................................................................................... 2 Acknowledgement .......................................................................................................................... 3 Game Description ........................................................................................................................... 5 Introduction................................................................................................................................. 5 Game Rules and Player Interaction ......................................................................................... 5 Graphics and Input ...................................................................................................................... 5 Service Discovery Description ......................................................................................................... 7 Messaging Protocol Description ................................................................................................... 10 Code Documentation .................................................................................................................... 11 Half-Sync/ Half-Async ................................................................................................................ 11 Message Queues ....................................................................................................................... 11 Reactor Pattern ......................................................................................................................... 12 Pipe and Filter ........................................................................................................................... 12 Model View Controller .............................................................................................................. 12 Project Results .............................................................................................................................. 13 Concepts and Technologies Learned ............................................................................................ 14 Future Work .................................................................................................................................. 15 Conclusion ..................................................................................................................................... 15 Appendices.................................................................................................................................... 15 Submission Contents ................................................................................................................. 15 Required Tools........................................................................................................................... 15 Project Setup ............................................................................................................................. 16 References ...................................................................................................................................... 1 Page 4
Game Description
Introduction
The given name for the game that users will experience is Maze Racer, where players navigate their way through a maze simultaneously in pursuit of a goal. The maze in focus will be randomly generated at the start of each session, and only through the clever use of both visual outputs will a player succeed. Each player with their own android device will have their own view of the three dimensional world from a first person perspective and a two dimensional shared view of the world from a birds eye view. This game has been created to show how older, simpler games can be designed from a newer perspective. The main goal of this game is to show how having a personalized perspective for each player can affect the mechanics of a Game Rules and Player Interaction At the beginning of each game, players are placed into a randomly generated maze. A single golden star will be placed inside of the level, and players must race to be the first to acquire it. When the golden star is taken by a player, a new one will randomly spawn in the maze and the process will restart however, players will not revert to their starting places. In order to win the game, a single player must be the first to collect five golden stars.
Page 5
viewed. When using the Android client, a player can move around the world by sliding their finger on the screen in the direction they wish to go.
Players will get an eagles-view of the maze from the PC Client, as the screen is shared between everyone in the game. The game on the PC is rendered in 2-D, using Javas Swing components. There is no input for the PC, as everyone controls the game from their own Android device.
Page 6
discovery over a WAN, another scheme must be used which in this case is a simple name server setup. Lobbies that are hosting games will register themselves with an external static server, adding them to a list with all of the other lobbies that are hosting a game as well. When a lobby is created, it will do two things. The first thing that the lobby will do is to broadcast its service over the local network using the Bonjour library, allowing phones on the local network to find it. The next thing a lobby will do is register itself with the static name server over the WAN, allowing other lobbies to discover itself.
Page 8
Page 9
GameStatusEvent
Int actionType
RegisterLobbyEvent
GetLobbyEvent
ReturnLobbyEvent
Page 10
Code Documentation
Several patterns of code design were used in the creation of this project; this section will give an overview of these concepts and then show how they are used in combination.
Half-Sync/ Half-Async
This half-sync / half-async pattern decouples asynchronous and synchronous service processing in concurrent systems. [1] This structure is used in order to allow asynchronous messaging to interact with the rest of the program, a synchronous service. In order to combine these two layers, a third queuing layer is necessary to provide a way to control the flow of both incoming and outgoing messages.
Message Queues
The messaging of the program is entirely handled through implementation of message queues, specifically RabbitMQ. Message queues provide a necessary service that simplifies the structure of how messages are sent between clients and allows this to become an asynchronous process. A consumer/producer pattern is the underlying structure of message queues. After creating a queue, a producer will add to it and a consumer will remove this allows messages to be passed from one client to another in an asynchronous fashion.
Page 11
Reactor Pattern
The reactor design pattern allows for asynchronous messages to be dispatched to the program model in a synchronous format. It also provides a way to determine which event handlers will be used in conjunction with which event types. Event handlers are loaded upon start time through class reflection, determined by the names given in a configuration file. The reactor will follow a continuous cycle after it has been initialized in one or possibly more threads; each thread will remove an event from the incoming queue, determine the event handler that is associated with that event and then carry out the action that is specified in the handler.
Page 12
When changes are made to the model, it will notify the Observer and the correct changes to the interface will be made.
Project Results
What I accomplished with this project is less than I had wanted to, but for the most part I have learned what I have wanted to. My implementation of the project did not quite come through with the success that I had hoped, I managed to get ZeroConfig networking implemented fully as well as learning how to use JSON for message protocols and RabbitMQ message queues for communication. The combination of these technologies allowed me to create a working game lobby, but I wasnt actually able to get the game working. I was able to fully implement the ZeroConf networking, Android clients can discover PC clients and join lobbies as well as the game. Once they are in the game they can change their ready state.
Page 13
This project managed to be a moderate success, but I felt as though I didnt get as much done that I would have liked to. When I started this project, I had several goals that I wanted to accomplish. The first thing that I wished to learn was how to develop an Android application, which I now have a further grasp on. I have learned how to make some basic applications including lists and buttons, as well as including OpenGL. I discovered the difficult process of testing applications for Android on a PC, that it is almost necessary to have a physical device when building your application.
I wanted to learn how to create a program in OpenGL, which I found that I had quite enough success with. I managed to implement the basic levels of my game inside using OpenGL, but was not able to spend much time polishing or completing what I had wanted to even though I had learned how it had worked.
learn about, as it can simplify so many applications that I can think about developing. JSON is also a helpful tool, as it is being used everywhere; it really changed how I think about messaging across different clients.
Future Work
In the future, there is still some work to be done to getting my project to a finished state. There isnt much left when it comes down to it, but there is still more work to be done on game mechanics as well as finishing the protocol for the actual game. I would like to make it so that the name server registration works properly, it is only a few steps from being complete and once that is finished, multiple lobbies can connect and games can actually be played across the web.
Conclusion
The most important thing that I learned from this project is to not take more than I can handle. I feel that I decided to do too many things, and many parts were nearly implemented but it just did not mesh together properly taking away from the experience. I learned that I would like to spend more of my time in the future learning about networking, and how it can be used in order to make tasks while working easier.
Appendices
Submission Contents
The zip file that is included with this report contains the following eclipse projects: MSAndroidClient the client that is run on Android devices MSPCClient the client for game lobbies that is run on the PC MSServer the name server that lobbies use for registration
Required Tools
Several tools are required in order to properly run this software. Page 15
Java SDK 1.7 is required for the PC Clients, and 1.6 for Android devices[2] Android SDK with API level 16 or higher[3] ADB Plugin for Eclipse[3] RabbitMQ server version 3.0.4[4] Erlang AMQP client library protocol version 0-9-1[4]
Project Setup
In order to run this project, the three project folders must be imported into the IDE. To run the PC Client, the PCClient class must be run normally from inside of Eclipse. Any android client that is to be launched must have an actual device connected to the computer, in order to take advantage of the ZeroConf networking. For the first time running an android client, the main activity must be run from Eclipse.
Page 16
References
[1] "Architecture and Design of Dependable Systems TIARDIPOSA2: Half-Sync / Half-Async Archictectural Pattern," Aarhus University, 2012. [Online]. Available: http://kurser.iha.dk/ee-ict-master/tiardi/Slides/ARDI5-POSA2-HalfSyncHalfAsync.pdf. [Accessed 7 February 2013]. [2] "Oracle Technology Network Downloads," [Online]. Available: http://www.oracle.com/technetwork/java/javase/downloads/index.html. [3] "Android Devoppers Website," [Online]. Available: http://developer.android.com/sdk/index.html. [4] "RabbitMQ Downloads," [Online]. Available: http://www.rabbitmq.com/download.html.
List of Figures
Figure 1 - View of Game on Android Device ................................................................................... 6 Figure 2 - View of Game on PC ....................................................................................................... 7 Figure 3 - Diagram of Network Connectivity .................................................................................. 9 Figure 4 - Table Displaying the Messaging Protocol ..................................................................... 10 Figure 5 - DIagram of Half-Sync/Half-Async pattern .................................................................... 11
Page 2
Page 3