G3D::GApplet Class Reference#include <GApp.h>
List of all members.
Detailed Description
A self-contained mode of operation for an application; a "screen". One large-scale state of an application. For example, a game might have one GApplet subclass for the title screen, one for the main menu, one for the game itself, and one for the credits.
For each frame, the GApplet has several tasks that can be implemented by overriding base class methods. The use of cooperative, round-robbin scheduling avoids the need for threads in most applications. These tasks are:
-
doGraphics(G3D::RenderDevice*)
-
doUserInput(G3D::UserInput*)
-
doLogic()
-
doNetwork()
-
doSimulation(G3D::RealTime, G3D::SimTime)
-
doWait(G3D::RealTime cumulativeTime, G3D::RealTime desiredCumulativeTime)
To invoke a GApplet and let it control the main loop, call run(). To control the main loop explicitly, invoke beginRun on initialization, call oneFrame() from the main loop, and call endRun on cleanup.
Constructor & Destructor Documentation
| G3D::GApplet::GApplet |
( |
GApp * |
_app |
) |
|
|
|
|
- Parameters:
-
| _app | This is usually your own subclass of GApp. |
|
| virtual G3D::GApplet::~GApplet |
( |
|
) |
[inline, virtual] |
|
|
|
An empty virtual destructor for virtual methods. |
Member Function Documentation
|
|
Installs a module. Actual insertion may be delayed until the next frame.
Modules can be installed either on a GApp or a GApplet. Those installed on the GApp will be run by the GApplet every frame in addition to its own.
By default events have NORMAL_PRIORITY. HIGH_PRIORITY is only intended for debugging modules that need to temporarily superceed other components.
All modules within the same priority class receive events with undetermined priority. All high priority modules receive events before.
Event priority is important because a module can consume events, preventing other modules from observing them. For example, a debugging console might run at high priority so that it can consume arrow keys before they reach a normal priority first-person controller.
- BETA API Likely to receive incompatible changes in future releases.
|
| virtual void G3D::GApplet::beginRun |
( |
|
) |
[virtual] |
|
|
|
Usually you'll call GApplet::run instead. This is used by GApp.
Prepare for running. The default implementation sets endApplet to false, calls GApplet::onInit(), copies the debug camera position to the debug camera controller, |
| virtual void G3D_DEPRECATED G3D::GApplet::cleanup |
( |
|
) |
[inline, protected, virtual] |
|
|
|
Invoked at the end of every run call. Default implementation does nothing. - Deprecated:
|
| RealTime G3D::GApplet::desiredFrameDuration |
( |
|
) |
const [inline] |
|
| float G3D::GApplet::desiredFrameRate |
( |
|
) |
const [inline] |
|
| virtual void G3D_DEPRECATED G3D::GApplet::doGraphics |
( |
|
) |
[protected, virtual] |
|
|
|
Override and implement. The debugCamera's projection and object to world matrices are set by default; you can set other cameras as desired. RenderDevice::beginFrame and endFrame are called for you.
See demos/main.cpp for an example of overriding lights.
- Deprecated:
|
| virtual void G3D_DEPRECATED G3D::GApplet::doLogic |
( |
|
) |
[inline, protected, virtual] |
|
|
|
Update any state you need to here. This is a good place for AI code, for example. Called after network and user input, before simulation. - Deprecated:
|
| virtual void G3D_DEPRECATED G3D::GApplet::doNetwork |
( |
|
) |
[inline, protected, virtual] |
|
| virtual void G3D_DEPRECATED G3D::GApplet::doSimulation |
( |
RealTime |
rdt |
) |
[inline, protected, virtual] |
|
| void G3D_DEPRECATED G3D::GApplet::doUserInput |
( |
|
) |
[protected] |
|
|
|
Updates the userInput. Called from run. Rarely needs to be called by user programs.
Never overriden by a subclass. Instead, override GApp::processEvent to handle your own events.
- Deprecated:
- In 7.0, will be private and doUserInput will be a function you can override to handle events.
|
| virtual void G3D::GApplet::endRun |
( |
|
) |
[virtual] |
|
|
|
Default implementation poses the managed modules from the GApplet and GApp. |
| SimTime G3D::GApplet::idealSimTime |
( |
|
) |
const [inline] |
|
|
|
Simulation time that is always advanced by precisely the desiredFrameDuration * simTimeRate, regardless of the actual frame duration. |
| virtual void G3D_DEPRECATED G3D::GApplet::init |
( |
|
) |
[inline, protected, virtual] |
|
| virtual void G3D::GApplet::onCleanup |
( |
|
) |
[inline, protected, virtual] |
|
|
|
Invoked at the end of every run call. Default implementation does nothing. |
| virtual void G3D::GApplet::oneFrame |
( |
|
) |
[virtual] |
|
|
|
Usually you'll call GApplet::run instead. This is used by GApp.
A single frame of rendering, simulation, AI, events, networking, etc. Invokes the onXXX methods. For use with GWindows that require a main loop. This if your GWindow does not require control of the main loop, GApp will call this for you. |
| virtual bool G3D::GApplet::onEvent |
( |
const GEvent & |
event |
) |
[protected, virtual] |
|
|
|
It is recommended to override doUserInput instead of this method.
Override if you need to explicitly handle events in the order they appear.
Note that the userInput contains a record of all keys pressed/held, mouse, and joystick state, so you do not have to override this method to handle basic input events.
Return true if the event has been consumed (i.e., no-one else including GApp should process it further).
The default implementation does nothing. |
| virtual void G3D::GApplet::onGraphics |
( |
RenderDevice * |
rd |
) |
[protected, virtual] |
|
|
|
Rendering callback.
Override and implement. The debugCamera's projection and object to world matrices are set by default; you can set other cameras as desired. RenderDevice::beginFrame and endFrame are called for you.
Use getPosedModel() to obtain the installed GModules to be rendered.
See demos/main.cpp for an example of overriding lights. |
| virtual void G3D::GApplet::onInit |
( |
|
) |
[inline, protected, virtual] |
|
|
|
Invoked every time run is called. Default implementation resets timers and simTimeRate.
Sublcasses should invoke GApplet::init to reset the timers. |
| virtual void G3D::GApplet::onLogic |
( |
|
) |
[inline, protected, virtual] |
|
|
|
Update any state you need to here. This is a good place for AI code, for example. Called after network and user input, before simulation. |
| virtual void G3D::GApplet::onNetwork |
( |
|
) |
[protected, virtual] |
|
|
|
For a networked app, override this to implement your network message polling. |
| virtual void G3D::GApplet::onSimulation |
( |
RealTime |
rdt, |
|
|
SimTime |
sdt, |
|
|
SimTime |
idt |
|
) |
[inline, protected, virtual] |
|
|
|
Override this with your simulation code. Called from GApp::run.
Default implementation does nothing.
simTime(), idealSimTime() and realTime() are incremented after doSimulation is called, so at the beginning of call the current time is the end of the previous frame.
- Parameters:
-
| rdt | Elapsed real-world time since the last call to doSimulation. |
| sdt | Elapsed sim-world time since the last call to doSimulation, computed by multiplying the wall-clock time by the simulation time rate. |
| idt | Elapsed ideal sim-world time. Use this for perfectly reproducible timing results. Ideal time always advances by the desiredFrameDuration * simTimeRate, no matter how much wall-clock time has elapsed. |
|
| virtual void G3D::GApplet::onUserInput |
( |
class UserInput * |
userInput |
) |
[inline, protected, virtual] |
|
|
|
Routine for processing user input from the previous frame. |
| virtual void G3D::GApplet::onWait |
( |
RealTime |
cumulativeTime, |
|
|
RealTime |
frameDuration |
|
) |
[protected, virtual] |
|
|
|
Task to be used for frame rate limiting.
Overriding onWait is not recommended.
Frame rate limiting is useful to avoid overloading a maching that is running background tasks and for situations where fixed time steps are needed for simulation and there is no reason to render faster.
Default implementation System::sleep()s until cumulativeTime + time in wait is greater than or equal to frameDuration = 1 / desiredFrameRate. |
| virtual void G3D_DEPRECATED G3D::GApplet::processEvent |
( |
const GEvent & |
event |
) |
[inline, protected, virtual] |
|
| RealTime G3D::GApplet::realTime |
( |
|
) |
const [inline] |
|
|
|
Accumulated wall-clock time since init was called on this applet. Since this time is accumulated, it may drift from the true wall-clock obtained by System::time(). |
| virtual void G3D::GApplet::removeModule |
( |
const GModuleRef & |
module |
) |
[virtual] |
|
|
|
The actual removal of the module may be delayed until the next frame. - BETA API Likely to receive incompatible changes in future releases.
|
| virtual void G3D::GApplet::run |
( |
|
) |
[virtual] |
|
|
|
Run until app->endProgram or endApplet is set to true. Calls beginRun(), then oneFrame in a loop, then endRun().
Consider instead calling app->window()->pushLoopBody(applet), which allows you to push and pop additional applets.
For use with GWindows for which requiresMainLoop is false. On GWindows where requiresMainLoop is true, this will schedule the applet to run and return immediately. (This odd behavior is required for backwards compatibility; in version 7.00 it will change). |
| virtual void G3D::GApplet::setDesiredFrameRate |
( |
float |
fps |
) |
[inline, virtual] |
|
|
|
Change to invoke frame limiting via doWait. Defaults to inf() |
| virtual void G3D::GApplet::setIdealSimTime |
( |
SimTime |
s |
) |
[inline, virtual] |
|
| virtual void G3D::GApplet::setRealTime |
( |
RealTime |
r |
) |
[inline, virtual] |
|
| virtual void G3D::GApplet::setSimTime |
( |
SimTime |
s |
) |
[inline, virtual] |
|
| virtual void G3D::GApplet::setSimTimeRate |
( |
double |
s |
) |
[inline, virtual] |
|
| SimTime G3D::GApplet::simTime |
( |
|
) |
const [inline] |
|
|
|
In-simulation time since init was called on this applet. Takes into account simTimeSpeed. Automatically incremented after doSimulation. |
| double G3D::GApplet::simTimeRate |
( |
|
) |
const [inline] |
|
|
|
Amount of time that passes in simTime for every second of realTime. e.g., 1.0 == real-time, 2.0 == fast, 0.5 == slow, 0.0 = stop time. Default is 1.0. |
Member Data Documentation
|
|
Set to false to break out of the run() loop. |
The documentation for this class was generated from the following file:
Generated on Mon Jul 17 11:50:47 2006 for G3D by
1.4.5
Hosted by
|