Made room for more case studies
This commit is contained in:
parent
fcd57d0fd9
commit
b17fe79344
1 changed files with 183 additions and 151 deletions
334
report.lyx
334
report.lyx
|
@ -3510,6 +3510,12 @@ and distribution of erlang nodes on physical nodes.
|
||||||
with third parties are also discussed here.
|
with third parties are also discussed here.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
The chapter ends with case studies of particular features of the GGS.
|
||||||
|
The case studies serve as concrete examples of the implementations outlined
|
||||||
|
in the rest of this chapter.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
Overview of the prototype
|
Overview of the prototype
|
||||||
\end_layout
|
\end_layout
|
||||||
|
@ -5583,6 +5589,11 @@ reference "sec:Communication-with-the-GDL-VM"
|
||||||
.
|
.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
The code which is run in the VM is uploaded to the GGS prior to each game.
|
||||||
|
Allowing the clients to upload code allows clients to run any game.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Subsection
|
\begin_layout Subsection
|
||||||
The database module
|
The database module
|
||||||
\begin_inset CommandInset label
|
\begin_inset CommandInset label
|
||||||
|
@ -5701,157 +5712,6 @@ key "webstorage:website"
|
||||||
interface to the database backend.
|
interface to the database backend.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Subsection
|
|
||||||
A case study
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
So what happens when a client sends a typical game command? Let us look
|
|
||||||
at one particular example of a chat client sending the message to change
|
|
||||||
the nick of a user (we will discuss a example implementation in JavaScript
|
|
||||||
in section
|
|
||||||
\begin_inset CommandInset ref
|
|
||||||
LatexCommand ref
|
|
||||||
reference "sec:Example-of-a-GGS-app"
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
).
|
|
||||||
Every communication between modules happens asynchronously, nothing is
|
|
||||||
blocking, which is very important in concurrent systems.
|
|
||||||
It is probably much easier to follow the steps by following them on
|
|
||||||
\begin_inset CommandInset ref
|
|
||||||
LatexCommand vref
|
|
||||||
reference "fig:The-layout-of"
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
Client packages a Game-Command into a package which conforms to the protocol
|
|
||||||
structure the GGS is using and sends it over the network
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The player module, which is coupled to the TCP-module to react on incoming
|
|
||||||
messages accepts the message and forwards the raw data to the protocol
|
|
||||||
parser module
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The protocol parser parses the message and brings it into the format of
|
|
||||||
the internal GGS presentation of such a message, which is just a specialized
|
|
||||||
Erlang tuple
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The protocol parser sends this Erlang touple back to the player module
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The player module checks if it is a Server-Command or a Game-Command.
|
|
||||||
In our example it is a Game-Command and it sends the message to the table
|
|
||||||
module
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The table module sends it to its own Game VM
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The Game VM module calls the function
|
|
||||||
\emph on
|
|
||||||
playerCommand(
|
|
||||||
\begin_inset Quotes eld
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
278d5002-77d6-11e0-b772-af884def5349
|
|
||||||
\begin_inset Quotes erd
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
,
|
|
||||||
\begin_inset Quotes eld
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
nick
|
|
||||||
\begin_inset Quotes erd
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
,
|
|
||||||
\begin_inset Quotes eld
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
Peter
|
|
||||||
\begin_inset Quotes erd
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
)
|
|
||||||
\emph default
|
|
||||||
within the JavaScript VM
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The JavaScript VM (JSVM) - at this stage Googles V8 JavaScript Engine -
|
|
||||||
evaluates the function within the sandboxed game context which has been
|
|
||||||
established earlier during the setup of the game.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
In the example in section
|
|
||||||
\begin_inset CommandInset ref
|
|
||||||
LatexCommand ref
|
|
||||||
reference "sec:Example-of-a-GGS-app"
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
we see that the GGS-functions
|
|
||||||
\emph on
|
|
||||||
GGS.localStorage.setItem(key, value)
|
|
||||||
\emph default
|
|
||||||
and
|
|
||||||
\emph on
|
|
||||||
GGS.localStorage(key)
|
|
||||||
\emph default
|
|
||||||
are used.
|
|
||||||
Both are callbacks coupled to the database module functions.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
Data is being read from and written to the database and handed over to the
|
|
||||||
JSVM via the database module
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
In the example the
|
|
||||||
\emph on
|
|
||||||
GGS.sendCommandToAll()
|
|
||||||
\emph default
|
|
||||||
is being called then which is a callback to a function of the table module
|
|
||||||
which iterates through its player list and sends the command to every player
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The table module sends every player instance the message to send the message
|
|
||||||
with the change of a nickname of a particular user to its own client.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The player module asks the protocol module to create a message conforming
|
|
||||||
to the protocol which is being used
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The protocol module creates a string according to the protocol and returns
|
|
||||||
it to the player module
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Enumerate
|
|
||||||
The player module sends the message with help of the gen_tcp module to the
|
|
||||||
client
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
Communication with the GDL VM
|
Communication with the GDL VM
|
||||||
\begin_inset CommandInset label
|
\begin_inset CommandInset label
|
||||||
|
@ -6689,6 +6549,178 @@ Hot code replacement is a technique used to update systems while they are
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
|
Case studies
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Subsection
|
||||||
|
Typical communication
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
So what happens when a client sends a typical game command? Let us look
|
||||||
|
at one particular example of a chat client sending the message to change
|
||||||
|
the nick of a user (we will discuss a example implementation in JavaScript
|
||||||
|
in section
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand ref
|
||||||
|
reference "sec:Example-of-a-GGS-app"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
).
|
||||||
|
Every communication between modules happens asynchronously, nothing is
|
||||||
|
blocking, which is very important in concurrent systems.
|
||||||
|
It is probably much easier to follow the steps by following them on
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand vref
|
||||||
|
reference "fig:The-layout-of"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
Client packages a Game-Command into a package which conforms to the protocol
|
||||||
|
structure the GGS is using and sends it over the network
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The player module, which is coupled to the TCP-module to react on incoming
|
||||||
|
messages accepts the message and forwards the raw data to the protocol
|
||||||
|
parser module
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The protocol parser parses the message and brings it into the format of
|
||||||
|
the internal GGS presentation of such a message, which is just a specialized
|
||||||
|
Erlang tuple
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The protocol parser sends this Erlang touple back to the player module
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The player module checks if it is a Server-Command or a Game-Command.
|
||||||
|
In our example it is a Game-Command and it sends the message to the table
|
||||||
|
module
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The table module sends it to its own Game VM
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The Game VM module calls the function
|
||||||
|
\emph on
|
||||||
|
playerCommand(
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
278d5002-77d6-11e0-b772-af884def5349
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
,
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
nick
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
,
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
Peter
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
)
|
||||||
|
\emph default
|
||||||
|
within the JavaScript VM
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The JavaScript VM (JSVM) - at this stage Googles V8 JavaScript Engine -
|
||||||
|
evaluates the function within the sandboxed game context which has been
|
||||||
|
established earlier during the setup of the game.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
In the example in section
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand ref
|
||||||
|
reference "sec:Example-of-a-GGS-app"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
we see that the GGS-functions
|
||||||
|
\emph on
|
||||||
|
GGS.localStorage.setItem(key, value)
|
||||||
|
\emph default
|
||||||
|
and
|
||||||
|
\emph on
|
||||||
|
GGS.localStorage(key)
|
||||||
|
\emph default
|
||||||
|
are used.
|
||||||
|
Both are callbacks coupled to the database module functions.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
Data is being read from and written to the database and handed over to the
|
||||||
|
JSVM via the database module
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
In the example the
|
||||||
|
\emph on
|
||||||
|
GGS.sendCommandToAll()
|
||||||
|
\emph default
|
||||||
|
is being called then which is a callback to a function of the table module
|
||||||
|
which iterates through its player list and sends the command to every player
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The table module sends every player instance the message to send the message
|
||||||
|
with the change of a nickname of a particular user to its own client.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The player module asks the protocol module to create a message conforming
|
||||||
|
to the protocol which is being used
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The protocol module creates a string according to the protocol and returns
|
||||||
|
it to the player module
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Enumerate
|
||||||
|
The player module sends the message with help of the gen_tcp module to the
|
||||||
|
client
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Subsection
|
||||||
|
Initialization of a game
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset Note Note
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
Fill this in!
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Subsection
|
||||||
Example of a GGS server application in JavaScript
|
Example of a GGS server application in JavaScript
|
||||||
\begin_inset CommandInset label
|
\begin_inset CommandInset label
|
||||||
LatexCommand label
|
LatexCommand label
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue