Skip to content

Application control

Alessandro Febretti edited this page Feb 23, 2015 · 33 revisions

module omega

Last revision: ver. 6.2 1 February 2015

These functions control execution and can be used to start stop and clean scripts, and to execute deferred code.

(v5.3) setClearColor(Color c)

Sets the color used to clear the frame buffer. See Color

(v5.3) clearColor(bool enabled)

Enables or disables color buffer clearing at the beginning of each frame

(v5.3) clearDepth(bool enabled)

Enables or disables depth buffer clearing at the beginning of each frame

oexit()

Exits the application

isMaster()

Returns True if the script is executing on the master node of a cluster display system.

(v6.4) isHeadless()

Returns True if the application is running in headless mode, i.e. without a display system.

queueCommand(script)

Queues a script command for execution. The command will be executed during the next update cycle.

broadcastCommand(script)

For cluster systems only. When executed on the master node, it tells all the slaves (and itself) to execute the specified command. Useful to implement event handlers after some code executed only on the master node (i.e. caching of remote data). A broadcastCommand call executed on a slave node does nothing. A call on a non-cluster environment behaves like queueCommand.

Example:

	import urllib
	# On the master node, fetch an image somewhere on the internet
	if(isMaster())
		urllib.urlretrieve("http://www.digimouth.com/news/media/2011/09/google-logo.jpg", "local-image.jpg")
		# Call this when you are done
		broadcastCommand('onImageLoaded()')
	
	# This will be called on all nodes once the image is loaded. You can open the image here.
	# (Assuming use of a shared filesystem in your cluster installation)
	def onImageLoaded():
		img = loadImage("local-image.jpg")

olaunch(string commands)

Spawns a new process which executed the specified command. The command can be the name of another executable or operating system command.

orun(string scriptPath)

Runs an external script. The script is executed immediately. The script path accepts two macros:

  • OMEGA_DATA_ROOT will be substituted with the default data directory for the omegalib installation
  • OMEGA_APP_ROOT will be substituted with the application directory for the installation (set throguh CMake at build configuration time)

oclean()

Stops the current script, cleans the engine and get everything back to its initial state.

ocleanrun(script)

Like orun, but performs a cleanup first. Useful for runtime switching to a different application.

String ogetexecpath()

(v5.1) Returns the path to the current omegalib executable.

MissionControlClient getMissionControlClient()

Returns a MissionControlClient instance if this application is running a mission control client. Returns None otherwise. Applications can start a mission control client when launched with the --mc client or --mc @host:port options specified. See the and CommandLine pages for more information.

string getHostname()

Gets the name of the host running the slave instance of omegalib

bool isHostInTileSection(string host, int x, int y, int w, int h)

Returns true if the specified host owns at least a tile in the specified tile rectangle. Example:

	# Prints TRUE on hosts that are within the tile rectangle [1,1 -> 2,1]
	if(isHostInTileSection(getHostname(), 1, 1, 2, 1) print('TRUE')

setTilesEnabled(int x, int y, int w, int h, bool enabled)

Enables or disables rendering for the specified tile region. Tiles need to be part of a tile grid to be controllable with this function.

(v6.2) setTileNamesEnabled(string tileNames)

Enables tiles based on their name. Accepts a string of space-separated tile names. Any tile not passed in the string will be disabled.

bool isEventDispatchEnabled(), setEventDispatchEnabled(bool value)

TODO

Quick Commands

requires v6.0

Quick commands can be used as shortcuts to longer scripts. A quick command is defined by a short command string, a call string, number of arguments and optional description. The call string can contain tokens in the form %n% that will be substituted by arguments passed to the quick command. The last argument to a quick command will be formed by joining all remaining tokens in the quick command call, allowing to pass long string containing spaces.

Basic example

> addQuickCommand('add', 'print("%1% + %2% = {0}".format(%1% + %2%))', 2, 'addition')
> :add 1 2
1 + 2 = 3

String joining

> addQuickCommand('s', 'print("%1% - %2% - %3%")', 3, '')
> :s arg1 arg2 remainder argments here
arg1 - arg2 - remainder argments here
Method(s) Description
addQuickCommand(string cmd, string call, int args, string description) Adds a new quick command with name cmd executing code call with the specified number of arguments and description
removeQuickCommand(cmd) Removes quick command cmd
Clone this wiki locally