Menu

Threads

g-dollar

AGE is composed of a fixed set of threads. Each thread works from its own message queue, and the threads communicate by passing messages. While a thread has no messages, it is sleeping.

Throughout, Game Object is referred to as GO.

Game Tasks

An abstract class extending java.lang.Thraed that represents an AGE thread, and most threads subclass this.

Task Message

An abstract class for all messages.

Task Channel

This interface represents the ability to receive messages.

Game Task with Channel

Abstract class extending GameTask that implements the core apartment thread message loop.

Game Cycle

Abstract class is the task running the main game engine "loop" and is the target of most messages.

This is the class you must subclass to implement a game.

Abstract Methods

The GameCycle class has several abstract methods that must be implemented. These methods function as callbacks.

  • startLoading: the SurfaceView resources are now initialized and GO loading can begin.
  • objectLoaded: a GO as completed the Install Pipeline; the GO and error status are passed as parameters.
  • gameStarting: the start game control message was received.

Update Lock

The Game Cycle task maintains the update lock so GO updates and the drawing cycle do not conflict. The update lock is held:

  • during a rendering
  • during a pipeline event (install, uninstall, event)
  • during a timer event
  • during an input event

At all other times the update lock is free.

Game Control

The Game Cycle task also handles game control messages (Play, Pause, etc.) and forwards game control messages to other tasks, e.g. to suspend timers etc. while the game is paused.

Framerate

This task is the timer for the desired framerate (in MS). Since AGE uses the SurfaceView in on-demand render mode, this task triggers a redraw at regular intervals.

It's desirable to adjust the framerate low when running on an emulator.

Resource Loader

This task executes the GO's load resources method so it can initialize model data and obtain GL objects. Once the GO is loaded, it is passed to the Game Cycle thread to continue the install pipeline.

Resources

Each GO is passed a Resources interface that provides access to application-defined resources, e.g. images, strings, etc.

GL objects like Shader and Texture are also Resources, and the framework manages the lifecycle of these "behind the scenes" when the GL context changes, and manages re-creation of cached resources when the GL context is destroyed and re-created.

Timer

This task handles all the timers in the system. The timer works on a time base which is the smallest unit of time that is waited. Timer intervals should be a multiple of the time base.

Timers that expire on the same "tick" are batched and sent to the Game Cycle thread so their handlers can execute. Timer events run with the update lock active.

It is desirable to adjust the time base longer when running in an emulator.

Surface View Renderer

Not a direct part of AGE, this is a "foreign" thread with AGE code attached to the RenderService. If it were not for this thread, AGE would not require synchronization.

When creating the SurfaceView, the AGE Renderer is attached, and it sends messages to the Game Cycle task at corresponding points in those callbacks, e.g. "surface ready".


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.