21
Modifications / Robot Arena 2 - What goes on behind the GUI
« on: July 25, 2009, 03:22:13 PM »
Long post with lots of text. It is not guaranteed to be all comprehensive or correct.
When the Robot Arena 2 executable is loaded. The first thing it does that is related to Python is to load the Main.py found in the Scripts folder. The Main.py starts by importing all the C++ commands that is avaliable in Python form, the plus library. It also reroutes all console output from Python scripts to the Debug box, which makes this an excellent place to add a file output to.
It then initiates the loading of Arenas followed by AI. The Arena and AI folder is interpreted by Python, which starts by reading __init__.py. The Practice arena is the first to be loaded. After that, the loading of all avaliable AI begins which continues by creating a list containing all bindings, which is what bindings.py does. In order to draw up all the GUI portions, the game queries the gib files found under the UI folder. These contain instructions on how to draw up all the elements on the screen.
In order to populate the Player and the AI teams, the game queries the Teams.txt and fills up the slots accordingly. Unfortunately it does not create the folders (Team1, Team2... and so on) if they are missing, leading to problems with creating new teams in-game since the data cannot be saved in a nonexisting path. All components and textures are also loaded at this stage.
When a match is started, the Arena chosen is created by the game. Which gets its basic properties from the SuperArena in __init__.py. The resulting Arena is a combination of the python code for the Arena and the SuperArena takes care of the sections that are not defined in the current Arenas own python code.
This is followed by a cleaning up of the AI stack which disables all running AI by emptying the running_ai global variable. The game then reads the name of the AI bot and queries the Binding list created earlier for the AI script to be loaded.
Every AI gets the Invert and Unstuck tactics assigned to themselves by the __init__.py, or SuperAI. All AIs are additions to the SuperAI, which provides basic functionality to the AI. The code in the SuperAI can be overridden by adding the same section in your own AI.
The Arena and AI are activated and the code under the Activate section is run. During the match the code under the Tick section for both the Arena and the AI is run. Usually the time between each tick is 250ms for an Arena and 125ms for an AI. This continues until Winners are declared, or the game quit by user.
When the Robot Arena 2 executable is loaded. The first thing it does that is related to Python is to load the Main.py found in the Scripts folder. The Main.py starts by importing all the C++ commands that is avaliable in Python form, the plus library. It also reroutes all console output from Python scripts to the Debug box, which makes this an excellent place to add a file output to.
Code: [Select]
class giScript_stdout:
def write(self, s):
giScript.debug_stdout(s)
output = file("debug.txt", "a")
output.write(str(s))
class giScript_stderr:
def __init__(self):
self.count = 0
def write(self, s):
self.count += 1
output = file("debug.txt", "a")
output.write(str(s))
giScript.debug_stderr(s)
def flush(self):
pass
It then initiates the loading of Arenas followed by AI. The Arena and AI folder is interpreted by Python, which starts by reading __init__.py. The Practice arena is the first to be loaded. After that, the loading of all avaliable AI begins which continues by creating a list containing all bindings, which is what bindings.py does. In order to draw up all the GUI portions, the game queries the gib files found under the UI folder. These contain instructions on how to draw up all the elements on the screen.
In order to populate the Player and the AI teams, the game queries the Teams.txt and fills up the slots accordingly. Unfortunately it does not create the folders (Team1, Team2... and so on) if they are missing, leading to problems with creating new teams in-game since the data cannot be saved in a nonexisting path. All components and textures are also loaded at this stage.
When a match is started, the Arena chosen is created by the game. Which gets its basic properties from the SuperArena in __init__.py. The resulting Arena is a combination of the python code for the Arena and the SuperArena takes care of the sections that are not defined in the current Arenas own python code.
This is followed by a cleaning up of the AI stack which disables all running AI by emptying the running_ai global variable. The game then reads the name of the AI bot and queries the Binding list created earlier for the AI script to be loaded.
Every AI gets the Invert and Unstuck tactics assigned to themselves by the __init__.py, or SuperAI. All AIs are additions to the SuperAI, which provides basic functionality to the AI. The code in the SuperAI can be overridden by adding the same section in your own AI.
The Arena and AI are activated and the code under the Activate section is run. During the match the code under the Tick section for both the Arena and the AI is run. Usually the time between each tick is 250ms for an Arena and 125ms for an AI. This continues until Winners are declared, or the game quit by user.