Skip to content

Gladius api reference

alankligman edited this page Apr 3, 2012 · 8 revisions

Gladius API Reference (under construction)

This page is under construction. We happily accept contributions!

Gladius

After importing gladius.js, a global name gladius is created on the window object. Use 'gladius.create' to obtain an engine instance.

create( options, callback )

Creates a new engine instance, passing options to the constructor and invoking callback that accepts the constructed engine instance as its only parameter.

Engine

An engine instance is returned from gladius.create. The engine contains some facilities for scheduling tasks (engine.scheduler), dispatching work units to workers using a thread pool (engine.threadpool), and a math library (engine.math) that provides functionality not available in JavaScript's Math. In addition, the engine manages a collection of entities.

Base

Base provides constructors to extend the engine with new components, resources, and services.

Core

Some core functionality is provided by the engine itself.

Graphics

Style and Conventions

Callbacks

Parts of the engine API are asynchronous, and some functions accept callbacks in their options. If the callback is invoked unconditionally it should be named callback:

f({
  callback: foo
});

If the callback is invoked only on success it should be named 'onsuccess', and there should be an additional parameter named 'onfailure' that is invoked otherwise:

g({
  onsuccess: foo,
  onfailure: bar
});

Some functions invoke their success callback multiple times. These functions accept an oncomplete callback that is invoked after the final onsuccess callback, and an onprogress callback that is invoked periodically to provided status.

h({
  onsuccess: foo,
  onfailure: bar,
  oncomplete: baz,
  onprogress: function( options ) {
    // We could update a progress bar here
  }
});