Changed the name and moved Communication with the GDL VM after the structure of the GGS
This commit is contained in:
parent
4230b38c31
commit
e82339fd94
1 changed files with 460 additions and 452 deletions
912
report.lyx
912
report.lyx
|
@ -3642,7 +3642,7 @@ dispatcher module
|
||||||
\begin_inset Float figure
|
\begin_inset Float figure
|
||||||
wide false
|
wide false
|
||||||
sideways false
|
sideways false
|
||||||
status collapsed
|
status open
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
\begin_layout Plain Layout
|
||||||
\begin_inset ERT
|
\begin_inset ERT
|
||||||
|
@ -4063,455 +4063,6 @@ Here we can have a more in-depth look at why Erlang was used, and outline
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Section
|
|
||||||
Communication with external systems and applications
|
|
||||||
\begin_inset CommandInset label
|
|
||||||
LatexCommand label
|
|
||||||
name "sec:Communication-with-external"
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
A game launched on the GGS is run within a virtual machine.
|
|
||||||
For each programming language supported, there is a virtual machine that
|
|
||||||
interprets the game.
|
|
||||||
Furthermore an interface for communication between the GGS, the game and
|
|
||||||
the players playing the game is present.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
Callbacks written in Erlang are registered to the VM for the interface to
|
|
||||||
work.
|
|
||||||
It is only with the help of the interface that the game developer can access
|
|
||||||
the game state and send messages to the clients.
|
|
||||||
The interface provides access to three objects called
|
|
||||||
\emph on
|
|
||||||
world, players
|
|
||||||
\emph default
|
|
||||||
and
|
|
||||||
\emph on
|
|
||||||
localStorage
|
|
||||||
\emph default
|
|
||||||
.
|
|
||||||
The game state is safely stored in a database and retrieved for manipulation
|
|
||||||
by a call for the world object.
|
|
||||||
Interaction with the players is done by using the
|
|
||||||
\emph on
|
|
||||||
GGS.sendCommand(player_id, command, args)
|
|
||||||
\emph default
|
|
||||||
and
|
|
||||||
\emph on
|
|
||||||
GGS.
|
|
||||||
\emph default
|
|
||||||
sendCommandToAll(command, args).
|
|
||||||
The localStorage is a convenient way to store globals and other variables
|
|
||||||
seperated from the game state.
|
|
||||||
Unique id:s called gametokens are generated for hosted games so that they
|
|
||||||
are not mixed up.
|
|
||||||
\begin_inset ERT
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
|
|
||||||
\backslash
|
|
||||||
nomenclature{
|
|
||||||
\backslash
|
|
||||||
textbf{WebStorage}}{A new standard for letting websites store data on visitors'
|
|
||||||
computers}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Subsection
|
|
||||||
Exposing Erlang functionality to the GDL VM
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
\begin_inset Note Note
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
Prior to this section, the Erlang syntax has to be briefly explained.
|
|
||||||
I think the 'usage of erlang' section is a good place to do this in.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
\begin_inset Float algorithm
|
|
||||||
wide false
|
|
||||||
sideways false
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
\begin_inset ERT
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
|
|
||||||
\backslash
|
|
||||||
lstset{
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
language=Erlang,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
backgroundcolor=
|
|
||||||
\backslash
|
|
||||||
color{white},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
extendedchars=true,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
basicstyle=
|
|
||||||
\backslash
|
|
||||||
footnotesize
|
|
||||||
\backslash
|
|
||||||
ttfamily,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
showstringspaces=false,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
showspaces=false,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
numbers=left,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
numberstyle=
|
|
||||||
\backslash
|
|
||||||
footnotesize,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
numbersep=9pt,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
tabsize=2,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
breaklines=true,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
showtabs=false,
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
captionpos=b
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
|
|
||||||
\backslash
|
|
||||||
begin{lstlisting}[language=Erlang]
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
% @doc Exposes some GGS functions to JavaScript
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
expose(GameVM, Table) ->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
Global = erlv8_vm:global(GameVM),
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
Global:set_value("GGS", erlv8_object:new([
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"localStorage", erlv8_object:new([
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"setItem", fun(#erlv8_fun_invocation{}, [Key, Val])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_db:setItem(Table, local_storage, Key, Val)
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"getItem", fun(#erlv8_fun_invocation{}, [Key])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_db:getItem(Table, local_storage, Key)
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
% more functions ...
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
])},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"world", erlv8_object:new([
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"setItem", fun(#erlv8_fun_invocation{}, [Key, Val])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_db:setItem(Table, world, Key, Val),
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_table:send_command_to_all(
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
Table, {"world_set", Key ++ "=" ++ Val}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
)
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"getItem", fun(#erlv8_fun_invocation{}, [Key])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_db:getItem(Table, world, Key),
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
% more functions ...
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
])},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"sendCommand", fun(#erlv8_fun_invocation{}, [Player, Command, Args])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_table:send_command(Table, Player, {Command, Args})
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end},
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"sendCommandToAll", fun(#erlv8_fun_invocation{}, [Command, Args])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
ggs_table:send_command_to_all(Table, {Command, Args})
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
{"setTimeout", fun(#erlv8_fun_invocation{}, [Time, Function])->
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
timer:apply_after(Time, ?MODULE, call_js, [GameVM, Function])
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
end}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
% more functions ...
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
])).
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
|
|
||||||
|
|
||||||
\backslash
|
|
||||||
end{lstlisting}
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
\begin_inset Caption
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
\begin_inset CommandInset label
|
|
||||||
LatexCommand label
|
|
||||||
name "alg:exposing-erlang"
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
An example of how Erlang functionality is exposed to a JavaScript GDL
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
\begin_inset Note Note
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
TODO: Go in to more detail about how the world, player and localstorage
|
|
||||||
objects are implemented.
|
|
||||||
Also discuss localstorage and how it derives from the webstorage standard
|
|
||||||
in detail.
|
|
||||||
This is a great point on how we try to follow standards.
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Standard
|
|
||||||
\begin_inset Note Note
|
|
||||||
status open
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
My idea here is that we describe the erlang-js (which failed, but nontheless),
|
|
||||||
v8, UUID and other external communication.
|
|
||||||
We shouldn't describe sockets here though..
|
|
||||||
or..
|
|
||||||
maybe?
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\begin_layout Plain Layout
|
|
||||||
Also discuss how we allow GDLs to communicate with Erlang, this is
|
|
||||||
\begin_inset Quotes eld
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
external
|
|
||||||
\begin_inset Quotes erd
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
to thre GDL.
|
|
||||||
Discuss the GGS world object (there is a reference to this secxtion for
|
|
||||||
that purpose)
|
|
||||||
\end_layout
|
|
||||||
|
|
||||||
\end_inset
|
|
||||||
|
|
||||||
|
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
|
@ -5214,6 +4765,14 @@ The VM itself makes it possible for the game developer to program in the
|
||||||
\begin_layout Standard
|
\begin_layout Standard
|
||||||
This module does not affect game runtime but evaluates a new game state
|
This module does not affect game runtime but evaluates a new game state
|
||||||
and handles communication between the game and the players.
|
and handles communication between the game and the players.
|
||||||
|
A closer look at the structure of this model is given in
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand vref
|
||||||
|
reference "sec:Communication-with-the-GDL-VM"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Subsection
|
\begin_layout Subsection
|
||||||
|
@ -5485,6 +5044,455 @@ The player module sends the message with help of the gen_tcp module to the
|
||||||
client
|
client
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Section
|
||||||
|
Communication with the GDL VM
|
||||||
|
\begin_inset CommandInset label
|
||||||
|
LatexCommand label
|
||||||
|
name "sec:Communication-with-the-GDL-VM"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
A game launched on the GGS is run within a virtual machine.
|
||||||
|
For each programming language supported, there is a virtual machine that
|
||||||
|
interprets the game.
|
||||||
|
Furthermore an interface for communication between the GGS, the game and
|
||||||
|
the players playing the game is present.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
Callbacks written in Erlang are registered to the VM for the interface to
|
||||||
|
work.
|
||||||
|
It is only with the help of the interface that the game developer can access
|
||||||
|
the game state and send messages to the clients.
|
||||||
|
The interface provides access to three objects called
|
||||||
|
\emph on
|
||||||
|
world, players
|
||||||
|
\emph default
|
||||||
|
and
|
||||||
|
\emph on
|
||||||
|
localStorage
|
||||||
|
\emph default
|
||||||
|
.
|
||||||
|
The game state is safely stored in a database and retrieved for manipulation
|
||||||
|
by a call for the world object.
|
||||||
|
Interaction with the players is done by using the
|
||||||
|
\emph on
|
||||||
|
GGS.sendCommand(player_id, command, args)
|
||||||
|
\emph default
|
||||||
|
and
|
||||||
|
\emph on
|
||||||
|
GGS.
|
||||||
|
\emph default
|
||||||
|
sendCommandToAll(command, args).
|
||||||
|
The localStorage is a convenient way to store globals and other variables
|
||||||
|
seperated from the game state.
|
||||||
|
Unique id:s called gametokens are generated for hosted games so that they
|
||||||
|
are not mixed up.
|
||||||
|
\begin_inset ERT
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
nomenclature{
|
||||||
|
\backslash
|
||||||
|
textbf{WebStorage}}{A new standard for letting websites store data on visitors'
|
||||||
|
computers}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Subsection
|
||||||
|
Exposing Erlang functionality to the GDL VM
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset Note Note
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
Prior to this section, the Erlang syntax has to be briefly explained.
|
||||||
|
I think the 'usage of erlang' section is a good place to do this in.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset Float algorithm
|
||||||
|
wide false
|
||||||
|
sideways false
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
\begin_inset ERT
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
lstset{
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
language=Erlang,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
backgroundcolor=
|
||||||
|
\backslash
|
||||||
|
color{white},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
extendedchars=true,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
basicstyle=
|
||||||
|
\backslash
|
||||||
|
footnotesize
|
||||||
|
\backslash
|
||||||
|
ttfamily,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
showstringspaces=false,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
showspaces=false,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
numbers=left,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
numberstyle=
|
||||||
|
\backslash
|
||||||
|
footnotesize,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
numbersep=9pt,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
tabsize=2,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
breaklines=true,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
showtabs=false,
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
captionpos=b
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
begin{lstlisting}[language=Erlang]
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
% @doc Exposes some GGS functions to JavaScript
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
expose(GameVM, Table) ->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
Global = erlv8_vm:global(GameVM),
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
Global:set_value("GGS", erlv8_object:new([
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"localStorage", erlv8_object:new([
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"setItem", fun(#erlv8_fun_invocation{}, [Key, Val])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_db:setItem(Table, local_storage, Key, Val)
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"getItem", fun(#erlv8_fun_invocation{}, [Key])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_db:getItem(Table, local_storage, Key)
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
% more functions ...
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
])},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"world", erlv8_object:new([
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"setItem", fun(#erlv8_fun_invocation{}, [Key, Val])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_db:setItem(Table, world, Key, Val),
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_table:send_command_to_all(
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
Table, {"world_set", Key ++ "=" ++ Val}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
)
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"getItem", fun(#erlv8_fun_invocation{}, [Key])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_db:getItem(Table, world, Key),
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
% more functions ...
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
])},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"sendCommand", fun(#erlv8_fun_invocation{}, [Player, Command, Args])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_table:send_command(Table, Player, {Command, Args})
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end},
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"sendCommandToAll", fun(#erlv8_fun_invocation{}, [Command, Args])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
ggs_table:send_command_to_all(Table, {Command, Args})
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
{"setTimeout", fun(#erlv8_fun_invocation{}, [Time, Function])->
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
timer:apply_after(Time, ?MODULE, call_js, [GameVM, Function])
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
end}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
% more functions ...
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
])).
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
|
||||||
|
\backslash
|
||||||
|
end{lstlisting}
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
\begin_inset Caption
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
\begin_inset CommandInset label
|
||||||
|
LatexCommand label
|
||||||
|
name "alg:exposing-erlang"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
An example of how Erlang functionality is exposed to a JavaScript GDL
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset Note Note
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
TODO: Go in to more detail about how the world, player and localstorage
|
||||||
|
objects are implemented.
|
||||||
|
Also discuss localstorage and how it derives from the webstorage standard
|
||||||
|
in detail.
|
||||||
|
This is a great point on how we try to follow standards.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
\begin_inset Note Note
|
||||||
|
status open
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
My idea here is that we describe the erlang-js (which failed, but nontheless),
|
||||||
|
v8, UUID and other external communication.
|
||||||
|
We shouldn't describe sockets here though..
|
||||||
|
or..
|
||||||
|
maybe?
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
Also discuss how we allow GDLs to communicate with Erlang, this is
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
external
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
to thre GDL.
|
||||||
|
Discuss the GGS world object (there is a reference to this secxtion for
|
||||||
|
that purpose)
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Section
|
\begin_layout Section
|
||||||
Techniques for ensuring reliability
|
Techniques for ensuring reliability
|
||||||
\end_layout
|
\end_layout
|
||||||
|
@ -5919,7 +5927,7 @@ changeNick
|
||||||
function uses a feature of the GGS called localStorage (see section
|
function uses a feature of the GGS called localStorage (see section
|
||||||
\begin_inset CommandInset ref
|
\begin_inset CommandInset ref
|
||||||
LatexCommand ref
|
LatexCommand ref
|
||||||
reference "sec:Communication-with-external"
|
reference "sec:Communication-with-the-GDL-VM"
|
||||||
|
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
@ -5947,7 +5955,7 @@ GGS object
|
||||||
Implementation specifics of the GGS object are provided in
|
Implementation specifics of the GGS object are provided in
|
||||||
\begin_inset CommandInset ref
|
\begin_inset CommandInset ref
|
||||||
LatexCommand ref
|
LatexCommand ref
|
||||||
reference "sec:Communication-with-external"
|
reference "sec:Communication-with-the-GDL-VM"
|
||||||
|
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue