Arena
The Gorilla3D Arena is the multiplayer building block: a set of components that let several devices find each other on a network, agree on who is taking part, and play a turn based game together — without writing a line of socket code.
It sits on RTL App Tethering (System.Tether) and adds what an actual
application needs on top of it: a role, a message envelope, a member list,
seating and turn order — and the handful of repairs without which two devices
on an ordinary Wi-Fi never find each other at all.
Table of Contents
- Architecture
- The Pages of this Section
- Which Component Do I Need?
- Platform Support
- Units at a Glance
- Quick Start
- Installation
- See Also
Architecture
Three layers, each usable on its own. Pick the one that matches how much you want done for you.
TGorillaArenaMatch seating, turn order, host authority, state sync
| uses IGorillaArenaRules
v
TGorillaArenaSession role, transport, member list, one message channel
| TGorillaArenaMessage envelopes
v
TGorillaArenaManager pairing, profiles, users, mirrored entities
|
v
System.Tether RTL App Tethering (UDP discovery + TCP transport)
Both TGorillaArenaSession and TGorillaArenaMatch are components: drop one on
a form, wire its events in the object inspector, and the network half of a
multiplayer application is done.
Beside that stack sits the lobby directory, a small PHP endpoint that takes the place of reading an IP address out to somebody over the phone. It is optional and independent of everything above.
The Pages of this Section
| Page | Content |
|---|---|
| Arena Manager | TGorillaArenaManager: pairing, profiles, the user list, and mirrored entities |
| Session | TGorillaArenaSession: roles, transport, members, messages, and the network repairs |
| Match | TGorillaArenaMatch: seating, whose turn it is, host authority, state synchronisation |
| Rules | IGorillaArenaRules: writing the rules a match is played by |
| Lobby Directory | TGorillaArenaDirectory and the PHP endpoint behind it: pick a session from a list instead of typing an address |
Which Component Do I Need?
| You want | Use |
|---|---|
| Objects mirrored between devices over App Tethering, your own protocol on top | TGorillaArenaManager (not on Linux) |
| A group that finds each other and exchanges messages you define | TGorillaArenaSession |
| A turn based game — cards, dice, board | TGorillaArenaMatch |
Each one is a descendant of the one above it, so moving up a layer later costs
nothing: the properties and events of the lower layer stay exactly where they
were. Users, Items, Myself and their events come from
TGorillaArenaCustomManager and are there on every layer and every platform -
see Session.
Platform Support
| Platform | Arena | Note |
|---|---|---|
| Windows | Yes | |
| Android | Yes | Needs a multicast lock and, from API 31, the Bluetooth permission — both handled by TGorillaArenaSession |
| macOS / iOS | Yes | |
| Linux | Yes | Always over the Arena's own transport, atDirect - App Tethering has no Linux implementation |
App Tethering (atNetwork, atBluetooth) and the Arena's own transport
(atDirect) do not see each other. As soon as one participant runs Linux,
every device has to use atDirect - it is available on Windows, Android and
macOS as well. Only the raw TGorillaArenaManager does not exist on Linux;
sessions, matches, the lobby directory, users and items do. See
Session.
Units at a Glance
| Unit | Content |
|---|---|
Gorilla.Arena.Manager |
TGorillaArenaManager — tethering, pairing, users (not on Linux) |
Gorilla.Arena.Base |
TGorillaArenaCustomManager — users, items, Myself and their events, on every platform |
Gorilla.Arena.Net |
The Arena's own transport: UDP discovery, TCP to the host (atDirect) |
Gorilla.Arena.Entity |
TGorillaArenaEntity — an object mirrored to every participant |
Gorilla.Arena.User |
TGorillaArenaUser — a participant, with colour and position |
Gorilla.Arena.Session |
TGorillaArenaSession — role, transport, members, messaging |
Gorilla.Arena.Match |
TGorillaArenaMatch — seating, turns, host authority |
Gorilla.Arena.Directory |
TGorillaArenaDirectory — publishing a session to a lobby list, and joining one from it |
Gorilla.Arena.Rules |
IGorillaArenaRules, members, seating, scoreboard |
Gorilla.Arena.Message |
The wire envelope and the sequence gate |
Gorilla.Arena.JSONWrap |
The JSON backed object entities are built on |
Gorilla.Arena.Utils |
Colour and point conversion helpers |
Quick Start
A complete turn based game, minus the rules:
uses
Gorilla.Arena.Rules, Gorilla.Arena.Session, Gorilla.Arena.Match;
// --- setting up -----------------------------------------------------------
FMatch := TGorillaArenaMatch.Create(Self);
FMatch.MessageResource := 'MyGame'; // both sides need the same name
FMatch.AppVersion := 1; // raise it when a payload changes shape
FMatch.RulesComponent := MyRules1; // a TGorillaArenaRules on the form
FMatch.OnMembersChanged := MembersChanged; // somebody arrived or left
FMatch.OnMatchChanged := MatchChanged; // the state or the turn moved
FMatch.OnRemoteMove := RemoteMove; // somebody else moved
FMatch.OnNotice := Notice; // something to tell the user
// --- one device opens, the others join ------------------------------------
FMatch.OpenSession('Anna');
FMatch.JoinSession('Ben');
// --- playing --------------------------------------------------------------
FMatch.StartMatch(); // host only
if FMatch.IsMyTurn() then
begin
LMove := TJSONObject.Create();
LMove.AddPair('card', 'Q');
FMatch.SubmitMove(LMove); // takes ownership
end;
What to draw comes from Participants(), Scoreboard(), Headline(),
TurnMemberName() and InMatch.
Installation
The Arena ships with the GAMEPACKAGE edition of Gorilla3D. Install the package and the three components are on the tool palette under Gorilla3D Arena.
The units are compiled with GAME_PACKAGE, because the Arena is part of that
edition. On Linux Gorilla.Arena.Manager is left out and not registered - it
is App Tethering through and through; every other unit is in the package on
every platform. Gorilla.Arena.Net only needs Indy, which the package requires
everywhere. For tethering the requires clause adds tethering on every
platform but Linux, and IndyIPServer on Windows and macOS.
See Also
API Reference
- Gorilla.Arena.Manager — Tethering manager, pairing, users
- Gorilla.Arena.Session — Session component
- Gorilla.Arena.Match — Match component
- Gorilla.Arena.Rules — Rules interface, members, scoreboard
- Gorilla.Arena.Message — Wire envelope, sequence gate
- Gorilla.Arena.Entity — Mirrored entities
- Gorilla.Arena.User — Participants
- Gorilla.Arena.Base — Users, items and their events, on every platform
- Gorilla.Arena.Net — The Arena's own transport (
atDirect)
Related Topics
- Installation — Installing the Gorilla3D packages
- Dialogue System — Dialogue trees, which pair well with a shared session
- Inventory — Items a participant carries