bw logo

Chapter 3. Implementing Progress Bars

Once the bar's GUI file has been generated, you can incorporate it to your game, both at the loading screen or during the transition due to a teleport.

3.1. Using the progress bar

Once the GUI file has been created, it is a simple task to display it in your game, and update its value.

3.1.1. Displaying the progress bar

The first step to have your game display the bar is to associate it with its GUI file, as illustrated below:

import GUI
progressBar = GUI.load( "guis/progress_bar.gui" )

And display it via method GUI.addRoot():

GUI.addRoot( progressBar)

If you derived your script from the class PyGUIBase, then you can also display the bar via the script's active method, as illustrated below:

progressBar.script.active(1)

3.1.2. Updating the progress bar

In order to update the progress bar, all you have to do is call the script method setProgress:

progressBar.script.setProgress( 0.18 )

The script will perform the relevant actions on the underlying GUI component.

3.2. Creating a progress bar for the game startup

Built into the client engine is a progress bar for tracking start-up. This can be used directly in your game, or just used as example code.

3.2.1. To enable the GUI-based application progress bar

Place the following entry in file <res>/resources.xml (where <res> is the first folder specified in environment variable BW_RES_PATH):

<system>
<loadingScreenGUI> folder/loading_screen.gui </loadingScreenGUI>
</system>

<res>/resources.xml—Defining file for the loading screen

3.2.2. What must my GUI script support?

The application will invoke your GUI script as it initialises. The loading screen/progress bar file must have the following interface:

def setProgress( self, value ):
    #change the progress bar here
    pass
def addMessage( self, str ):
    #display a loading message on-screen
    pass

Loading screen/progress bar file folder/loading_screen.gui

3.3. Creating a player teleport progress bar

There is a method called spaceLoadStatus(), which returns the percentage of the world that has been loaded. This feature can be used to update a progress bar when the player is teleporting to another part of world.

The method's signature is illustrated below:

BigWorld.spaceLoadStatus( distance )

To link your progress bar up to the chunk loading, you will have to poll this method, as illustrated below:

def progressCheck( self, endTime ):
    finished = (endTime < BigWorld.time())
    if not finished:
        status = BigWorld.spaceLoadStatus( self.distance ) 
        finished = (status > 0.95)
    if finished:
        self.setProgress(1.0) 
        self.component.fader.value = 0.0
        if self.callbackFn:
            BigWorld.callback( self.component.fader.speed, self.callbackFn )
        else:
            self.setProgress( status ) 
            BigWorld.callback( self.checkRate, Functor( self.progressCheck, endTime ) )

Updating the progress bar with chunk loading status

Note

While you have a space loading loading screen displayed, it is recommended that you disable rendering of the world by calling BigWorld.worldDrawEnabled(False). You can re-enable world rendering once the progress bar has completed by calling BigWorld.worldDrawEnabled(True). Besides disabling rendering while loading, it will also suppress warnings when files are accessed from the main thread (which is bad during game play, but is generally acceptable during the loading screen phase - see How To Avoid Files Being Loaded in the Main Thread).