Skip to content

Commit 628f935

Browse files
committed
program state and bots lifecycle overview
1 parent 4fede41 commit 628f935

File tree

7 files changed

+130
-6
lines changed

7 files changed

+130
-6
lines changed

sphinx/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
sphinx-autobuild
22
sphinx_design
33
sphinx-copybutton
4-
sphinx-inline-tabs
54
furo

sphinx/source/bots/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ Specifically, bots cannot cheat - no more than a regular player could.
88

99
.. toctree::
1010
setup
11+
programOverview
1112
troubleshooting
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
Program Overview
2+
================
3+
High-level look at basic bot program.
4+
5+
Environment Variables
6+
---------------------
7+
Some variables that may alter the behavior of your bot program.
8+
9+
- ``UNNATURAL_ROOT`` - path to the ``bin`` folder that contains the shared library.
10+
- ``UNNATURAL_CONNECT_LOBBY`` - id of Steam lobby to connect to.
11+
- ``UNNATURAL_CONNECT_ADDR`` - IP address or domain name to connect to.
12+
- ``UNNATURAL_CONNECT_PORT`` - port of the game server to connect to.
13+
14+
Program Lifecycle
15+
-----------------
16+
At start, you are in full control of the program.
17+
18+
Initialization
19+
^^^^^^^^^^^^^^
20+
21+
- You need to change current working directory to the ``bin`` directory in the game installation.
22+
Without it, the game will be unable to load maps and assets, even if it might load the shared library.
23+
24+
.. warning::
25+
Do *not* change current working directory once configured.
26+
27+
- Next you load the shared library.
28+
29+
.. tab-set::
30+
31+
.. tab-item:: Python
32+
:sync: python
33+
34+
TODO
35+
36+
.. tab-item:: C#
37+
:sync: csharp
38+
39+
The library is automatically loaded when you first access the global ``Game`` object.
40+
This happens inside the ``Bot`` constructor.
41+
42+
- Setup all your callbacks now.
43+
You may also set some parameters for the connection.
44+
45+
Connect
46+
^^^^^^^
47+
There are multiple ways to connect to a server.
48+
The usual approach is to first try reconnecting, in case the game has crashed previously.
49+
Second, you connect to an existing server using the parameters provided in the environment variables, if any.
50+
Third, you spin up your own server.
51+
52+
Alternatively, you may implement your own logic to determine how to connect to a server.
53+
54+
No matter the method, the game will now take control over the program.
55+
Your program is blocked until the network connection closes.
56+
All your further actions will happen inside callbacks only.
57+
58+
Game Loop
59+
^^^^^^^^^
60+
All your registered callbacks are now called, when appropriate.
61+
Notably, the ``Update`` callback is periodically called, no matter the game state.
62+
This is where you keep track of the state of the game, and perform any of your actions.
63+
64+
.. warning::
65+
The ``Update`` callback, and some other, may be called before the game has actually started (eg. in ``Session``), or when the map is not yet ``Loaded``.
66+
Be mindful of what operations are valid in these circumstances.
67+
68+
You may prematurely close the connection with the ``Disconnect`` function.
69+
This will do a graceful closing of the connection, that is, you will get some additional callbacks called.
70+
After that the connect function will return.
71+
72+
Finalization
73+
^^^^^^^^^^^^
74+
When the connection function returns, the network connection has already been closed, and you take back control over the program.
75+
You may do any cleanup operations, for example you may save some statistics from the game.
76+
Ultimately, you should unload the shared library, and exit the program.
77+
78+
It may be tempting to just loop and connect again to next server, however this is strongly discouraged.

sphinx/source/bots/setup.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Setup
2-
====
2+
=====
33
You can write your bot in any language, as long as it can load a dynamic/shared library (.dll/.so).
44
The shared library is distributed together with the game.
55

66
The uwapi repository contains c/c++ headers for all functions and structures provided by the library.
7-
Furthermore, it contains convenient wrappers for Python and for C# for quicker start.
7+
Furthermore, it contains convenient wrappers for Python and C# for easy start.
88

99
.. important::
1010
Copy ``steam_appid.txt`` into the ``bin`` folder.
@@ -17,6 +17,16 @@ You will find the ``steam_appid.txt`` in the uwapi repository.
1717
Copy it into the ``bin`` folder, next to the game executable.
1818

1919
.. important::
20-
If your Steam games are in non-default location, define environment variable ``UNNATURAL_ROOT`` to the directory containing the library.
20+
If you installed Unnatural World in non-default location, define environment variable ``UNNATURAL_ROOT`` to the directory containing the library.
2121

22-
The default path on Windows: ``C:\Program Files (x86)\Steam\steamapps\common\Unnatural Worlds\bin``, on linux: ``~/.steam/steam/steamapps/common/Unnatural Worlds/bin``.
22+
.. tab-set::
23+
24+
.. tab-item:: Windows
25+
:sync: windows
26+
27+
Default path: ``C:\Program Files (x86)\Steam\steamapps\common\Unnatural Worlds\bin``
28+
29+
.. tab-item:: Linux
30+
:sync: linux
31+
32+
Default path: ``~/.steam/steam/steamapps/common/Unnatural Worlds/bin``

sphinx/source/concepts/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Glossary and explanation of concepts used throughout this documentation and in t
66
map
77
prototypes
88
ecs
9+
programState
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Program State
2+
=============
3+
The program state is controlled by several independent variables.
4+
5+
Game State
6+
----------
7+
8+
- ``None`` - the game is initializing.
9+
- ``Session`` - players are connecting, and are negotiating the map and other settings. An admin will start the game.
10+
- ``Preparation`` - countdown before the game actually starts. This alerts players to get ready.
11+
- ``Game`` - game is in progress.
12+
- ``Finish`` - game is over. Winners and defeated have been declared.
13+
14+
Map State
15+
---------
16+
17+
- ``None`` - no map is set to load.
18+
- ``Downloading`` - the map is not available locally and is being downloaded.
19+
- ``Loading`` - the map is being loaded.
20+
- ``Loaded`` - map is fully available. This is the only state when you can access any of the functions that interact with the map.
21+
- ``Unloading`` - the map is being unloaded.
22+
- ``Error`` - loading a map has encountered an error. Loading is cancelled.
23+
24+
.. warning::
25+
Do *not* access any of the map-related functions unless the map is ``Loaded``.
26+
27+
Accessing any of the map-related functions when the map is *not* ``Loaded`` will crash the game, since all data are loaded concurrently.
28+
29+
Connection State
30+
----------------
31+
32+
- ``None`` - there is no connection. Do *not* send any commands.
33+
- ``Connecting`` - connection is being attempted. You may send commands, they will be delivered once the connection is established.
34+
- ``Connected`` - connection has been fully established. We are receiving data, and can send commands.
35+
- ``Error`` - connection has been closed or broken. Do *not* send any commands.
36+

sphinx/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
'sphinx.ext.githubpages',
2121
'sphinx_design',
2222
'sphinx_copybutton',
23-
"sphinx_inline_tabs",
2423
]
2524

2625
templates_path = ['_templates']

0 commit comments

Comments
 (0)