Game Development Reference
In-Depth Information
Cloud-based web
application(s)
Network
Messages
Game
Figure 10-1. Separation of game and tools communicating over the network
Recently, the browser has evolved from being a tool for viewing web sites to an ideal platform for building
desktop-quality applications. Browser vendors have adopted HTML5, WebSocket, and WebGL, and are quickly
filling in the missing pieces such as gamepad support and mouse locking (needed for first person shooter
mouse controls).
The rest of this chapter will present a foundation for building engine tools as browser applications, offer
sample applications, and provide technical details involved in building a WebSocket server and JSON-based remote
procedure call system.
Foundation
My proposal is to construct an API for engine tools (ET-API), built on a remote procedure call system using JSON
for data encoding and the recently standardized WebSocket protocol for network transmission. The tools will run in
a browser, so it is important that ET-API is easy to use from there. This section of the chapter will provide concrete
definitions of RPC, JSON, WebSocket, etc., while laying a foundation for moving engine tools to the cloud.
What exactly is a remote procedure call system? Simply put, it is a function call from one process to another.
The processes do not have to be running on the same machine or share the same architecture. When attempting to
understand RPC, it is helpful to first consider a local procedure call in a language like C/C++. When a local procedure
call occurs, the arguments are pushed onto the stack, then the program branches to the address of the function
being called. When the called function returns, the result is stored on the stack for the calling function to access. This
procedure call mechanism works because the caller, callee, and shared data live in the same address space and agree
on calling conventions that make use of the shared address space. In a remote procedure call system, the caller, callee,
and data do not share an address space and thus cannot share data by memory address. In other words, the calling
convention for a remote procedure call system must define not only how arguments are passed and returned, but also
the format the arguments are encoded in. In order to make a remote procedure call, you must marshal (encode) the
parameters for transmission over the network and pack them into a message for the remote system. Once the message
has been prepared, it is transported to the remote process. The return value(s) from an RPC are sent in a similar
manner but in the opposite direction.
Because the tools will be running inside a browser, it is important that you pick a data encoding scheme that is
native to the browser. I've chosen JavaScript Object Notation (JSON) data encoding. (JSON is text-only data encoding
that every browser can serialize JavaScript objects into and construct JavaScript objects from.) The primitive types are
the keywords null , true , and false , as well as decimal numbers and strings. In addition to the primitive types, JSON
has two collections. The first collection is an unordered key/value map. The second collection is an ordered list (or
array). Listing 10-1 shows some sample JSON from a player profile.
 
Search WWH ::




Custom Search