G3D::GApp Class ReferenceFor each frame, the GApp has several tasks that can be implemented by overriding base class methods.
More...
#include <GApp.h>
List of all members.
|
Public Types |
| enum | Action { ACTION_NONE,
ACTION_QUIT,
ACTION_SHOW_CONSOLE
} |
Public Member Functions |
| virtual void | addWidget (const Widget::Ref &module) |
| Manipulator::Ref | cameraManipulator () const |
| virtual void | debugPrintf (const char *fmt...) G3D_CHECK_PRINTF_METHOD_ARGS |
| RealTime | desiredFrameDuration () const |
| float | desiredFrameRate () const |
| | GApp (const Settings &options=Settings(), GWindow *window=NULL) |
| const Stopwatch & | graphicsWatch () const |
| SimTime | idealSimTime () const |
| const Stopwatch & | logicWatch () const |
| const Stopwatch & | networkWatch () const |
| RealTime | realTime () const |
| virtual void | removeWidget (const Widget::Ref &module) |
| virtual void | renderDebugInfo () |
| int | run () |
| void | screenPrintf (const char *fmt...) G3D_CHECK_PRINTF_METHOD_ARGS |
| void | setCameraManipulator (const Manipulator::Ref &man) |
| virtual void | setDesiredFrameRate (float fps) |
| virtual void | setExitCode (int code=0) |
| virtual void | setIdealSimTime (SimTime s) |
| virtual void | setRealTime (RealTime r) |
| virtual void | setSimTime (SimTime s) |
| virtual void | setSimTimeRate (double s) |
| SimTime | simTime () const |
| double | simTimeRate () const |
| const Stopwatch & | simulationWatch () const |
| const Stopwatch & | userInputWatch () const |
| void | vscreenPrintf (const char *fmt, va_list argPtr) G3D_CHECK_VPRINTF_METHOD_ARGS |
| const Stopwatch & | waitWatch () const |
| GWindow * | window () const |
| virtual | ~GApp () |
Public Attributes |
| bool | autoResize |
| bool | catchCommonExceptions |
| GConsoleRef | console |
| std::string | dataDir |
| GFontRef | debugFont |
| Log * | debugLog |
| GuiPane * | debugPane |
| GuiWindow::Ref | debugWindow |
| GCamera | defaultCamera |
| FirstPersonManipulatorRef | defaultController |
| DeveloperWindow::Ref | developerWindow |
| Action | escapeKeyAction |
| bool | fastSwitchCamera |
| bool | manageUserInput |
| RenderDevice * | renderDevice |
| bool | showDebugText |
| bool | showRenderingStats |
| ToneMapRef | toneMap |
| UserInput * | userInput |
Protected Member Functions |
| virtual void | onAfterSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
| virtual void | onBeforeSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
| virtual void | onCleanup () |
| virtual void | onConsoleCommand (const std::string &cmd) |
| virtual bool | onEvent (const GEvent &event) |
| virtual void | onGraphics (RenderDevice *rd, Array< PosedModelRef > &posed3D, Array< PosedModel2DRef > &posed2D) |
| virtual void | onInit () |
| virtual void | onLogic () |
| virtual void | onNetwork () |
| virtual void | onPose (Array< PosedModelRef > &posed3D, Array< PosedModel2DRef > &posed2D) |
| virtual void | onSimulation (RealTime rdt, SimTime sdt, SimTime idt) |
| virtual void | onUserInput (class UserInput *userInput) |
| virtual void | onWait (RealTime cumulativeTime, RealTime frameDuration) |
| virtual void | processGEventQueue () |
Static Protected Member Functions |
| static void | staticConsoleCallback (const std::string &command, void *me) |
Protected Attributes |
| Array< std::string > | debugText |
| Manipulator::Ref | m_cameraManipulator |
| GMutex | m_debugTextMutex |
| bool | m_endProgram |
| int | m_exitCode |
| Stopwatch | m_graphicsWatch |
| Stopwatch | m_logicWatch |
| Stopwatch | m_networkWatch |
| Stopwatch | m_simulationWatch |
| Stopwatch | m_userInputWatch |
| Stopwatch | m_waitWatch |
| WidgetManager::Ref | m_widgetManager |
Friends |
| class | GWindow |
Classes |
| class | Settings |
Detailed Description
For each frame, the GApp 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:
-
Graphics
-
User Input
-
AI / Game Logic
-
Network receive (network send occurs wherever needed)
-
Physical simulation
-
Wait (sleep to maintain constant frame rate)
Other event handlers include onInit/onCleanup, onEvent for fine-grain event handling, and onConsoleCommand.
The onConsoleCommand handler allows you to add an in-game command console to your program. By default it is activated when '~' is pressed; you can also set the GApp::escapeAction to open the console on ESC. The console is a Widget, so you can completely disable it (e.g., in a release build of the program) by executing removeWidget(console).
To invoke a GApp and let it control the main loop, call run().
Member Enumeration Documentation
- Enumerator:
-
| ACTION_NONE |
|
| ACTION_QUIT |
|
| ACTION_SHOW_CONSOLE |
|
Constructor & Destructor Documentation
- Parameters:
-
| window | If null, a SDLWindow will be created for you. |
This argument is useful for substituting a different window system (e.g. GlutWindow)
| virtual G3D::GApp::~GApp |
( |
|
) |
[virtual] |
Member Function Documentation
| virtual void G3D::GApp::addWidget |
( |
const Widget::Ref & |
module |
) |
[virtual] |
Installs a module.
Actual insertion may be delayed until the next frame.
| virtual void G3D::GApp::debugPrintf |
( |
const char * |
fmt... |
) |
[virtual] |
| RealTime G3D::GApp::desiredFrameDuration |
( |
|
) |
const [inline] |
| float G3D::GApp::desiredFrameRate |
( |
|
) |
const [inline] |
| const Stopwatch& G3D::GApp::graphicsWatch |
( |
|
) |
const [inline] |
| SimTime G3D::GApp::idealSimTime |
( |
|
) |
const [inline] |
Simulation time that is always advanced by precisely the desiredFrameDuration * simTimeRate, regardless of the actual frame duration.
| const Stopwatch& G3D::GApp::logicWatch |
( |
|
) |
const [inline] |
| const Stopwatch& G3D::GApp::networkWatch |
( |
|
) |
const [inline] |
| virtual void G3D::GApp::onAfterSimulation |
( |
RealTime |
rdt, |
|
|
SimTime |
sdt, |
|
|
SimTime |
idt | |
|
) |
| | [inline, protected, virtual] |
Invoked after onSimulation is run on the installed GModules and GApp.
Not used by most programs.
| virtual void G3D::GApp::onBeforeSimulation |
( |
RealTime |
rdt, |
|
|
SimTime |
sdt, |
|
|
SimTime |
idt | |
|
) |
| | [inline, protected, virtual] |
Invoked before onSimulation is run on the installed GModules and GApp.
This is not used by most programs; it is primarily a hook for those performing extensive physical simulation on the GModules that need a setup and cleanup step.
| virtual void G3D::GApp::onCleanup |
( |
|
) |
[inline, protected, virtual] |
Unload/deallocate your data here.
Unlike the constructor, this catches common exceptions. It is called after the last frame is processed.
| virtual void G3D::GApp::onConsoleCommand |
( |
const std::string & |
cmd |
) |
[protected, virtual] |
Invoked when a user presses enter in the in-game console.
The default implementation ends the program if the command is "exit".
| virtual bool G3D::GApp::onEvent |
( |
const GEvent & |
event |
) |
[protected, virtual] |
It is recommended to override onUserInput() instead of this method.
Override if you need to explicitly handle events raw in the order they appear rather than once per frame by checking the current system state.
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.
Rendering callback used to paint the screen.
Called automatically.
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.
| virtual void G3D::GApp::onInit |
( |
|
) |
[inline, protected, virtual] |
Load your data here.
Unlike the constructor, this catches common exceptions. It is called before the first frame is processed.
| virtual void G3D::GApp::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::GApp::onNetwork |
( |
|
) |
[inline, protected, virtual] |
For a networked app, override this to implement your network message polling.
Called before onGraphics.
Append any models that you want rendered (you can also explicitly pose and render in your onGraphics method). The provided arrays will already contain posed models from any installed Widgets.
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::GApp::onUserInput |
( |
class UserInput * |
userInput |
) |
[protected, virtual] |
Routine for processing user input from the previous frame.
Default implementation does nothing.
| virtual void G3D::GApp::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::GApp::processGEventQueue |
( |
|
) |
[protected, virtual] |
Processes all pending events on the GWindow queue into the userInput.
| RealTime G3D::GApp::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::GApp::removeWidget |
( |
const Widget::Ref & |
module |
) |
[virtual] |
The actual removal of the module may be delayed until the next frame.
| virtual void G3D::GApp::renderDebugInfo |
( |
|
) |
[virtual] |
Called from GApplet::run immediately after doGraphics to render the debugging text.
Does nothing if debugMode is false. It is not usually necessary to override this method.
Call this to run the app.
| void G3D::GApp::screenPrintf |
( |
const char * |
fmt... |
) |
|
The manipulator that positions the defaultCamera every frame.
By default, this is set to the defaultController. This may be set to NULL to disable explicit camera positioning.
| virtual void G3D::GApp::setDesiredFrameRate |
( |
float |
fps |
) |
[inline, virtual] |
Change to invoke frame limiting via doWait.
Defaults to inf()
| virtual void G3D::GApp::setExitCode |
( |
int |
code = 0 |
) |
[virtual] |
Invoke to true to end the program at the end of the next event loop.
| virtual void G3D::GApp::setIdealSimTime |
( |
SimTime |
s |
) |
[inline, virtual] |
| virtual void G3D::GApp::setRealTime |
( |
RealTime |
r |
) |
[inline, virtual] |
| virtual void G3D::GApp::setSimTime |
( |
SimTime |
s |
) |
[inline, virtual] |
| virtual void G3D::GApp::setSimTimeRate |
( |
double |
s |
) |
[inline, virtual] |
| SimTime G3D::GApp::simTime |
( |
|
) |
const [inline] |
In-simulation time since init was called on this applet.
Takes into account simTimeSpeed. Automatically incremented after doSimulation.
| double G3D::GApp::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.
| const Stopwatch& G3D::GApp::simulationWatch |
( |
|
) |
const [inline] |
| static void G3D::GApp::staticConsoleCallback |
( |
const std::string & |
command, |
|
|
void * |
me | |
|
) |
| | [static, protected] |
| const Stopwatch& G3D::GApp::userInputWatch |
( |
|
) |
const [inline] |
| void G3D::GApp::vscreenPrintf |
( |
const char * |
fmt, |
|
|
va_list |
argPtr | |
|
) |
| | |
| const Stopwatch& G3D::GApp::waitWatch |
( |
|
) |
const [inline] |
| GWindow* G3D::GApp::window |
( |
|
) |
const [inline] |
Friends And Related Function Documentation
Member Data Documentation
When true and the window is resizable, automatically responds to SDL_RESIZE events by notifying the RenderDevice that the window has been resized and resetting the viewport to full screen.
(default is true)
When true, there is an assertion failure if an exception is thrown.
Default is true.
Strings that have been printed with screenPrintf.
Protected by m_debugTextMutex.
Add your own debugging controls to this window.
A default camera that is driven by the defaultController.
Allows first person (Quake game-style) control using the arrow keys or W,A,S,D and the mouse.
When true an GKey::ESCAPE keydown event quits the program.
(default is true)
Used to find the frame for defaultCamera.
When true, debugPrintf prints to the screen.
(default is true)
When true, renderDebugInfo prints the frame rate and other data to the screen.
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:45 2007 for G3D by
1.5.2
Hosted by
|