![]() |
Angel
A 2D Game Prototyping Engine
|
The central class that manages all aspects of the simulation. More...
#include <World.h>
Inheritance diagram for World:Classes | |
| struct | RenderableLayerPair |
Public Member Functions | |
| bool | Initialize (unsigned int windowWidth=1024, unsigned int windowHeight=768, String windowName="Angel Engine", bool antiAliasing=false, bool fullScreen=false, bool resizable=false) |
| std::vector< Vec3ui > | GetVideoModes () |
| void | AdjustWindow (int windowWidth, int windowHeight, const String &windowName) |
| void | MoveWindow (int xPosition, int yPosition) |
| bool | SetupPhysics (const Vector2 &gravity=Vector2(0,-10), const Vector2 &maxVertex=Vector2(100.0f, 100.0f), const Vector2 &minVertex=Vector2(-100.0f,-100.0f)) |
| void | Destroy () |
| void | ResetWorld () |
| void | StartGame () |
| void | StopGame () |
| void | ScriptExec (const String &code) |
| void | LoadLevel (const String &levelName) |
| const float | GetDT () |
| const bool | StopSimulation () |
| const bool | StartSimulation () |
| void | SetBackgroundColor (const Color &bgColor) |
| void | Add (Renderable *newElement, int layer=0) |
| void | Add (Renderable *newElement, const String &layer) |
| void | Remove (Renderable *oldElement) |
| void | UpdateLayer (Renderable *element, int newLayer) |
| void | UpdateLayer (Renderable *element, const String &newLayerName) |
| void | NameLayer (const String &name, int number) |
| const int | GetLayerByName (const String &name) |
| RenderLayers & | GetLayers () |
| void | RegisterConsole (Console *console) |
| Console * | GetConsole () |
| b2World & | GetPhysicsWorld () |
| const bool | IsPhysicsSetUp () |
| void | WakeAllPhysics () |
| virtual void | BeginContact (b2Contact *contact) |
| virtual void | EndContact (b2Contact *contact) |
| void | SetSideBlockers (bool turnOn, float restitution=-1.0f) |
| float | GetCurrentTimeSeconds () |
| float | GetTimeSinceSeconds (float lastTime) |
| void | DrawDebugLine (const Vector2 &a, const Vector2 &b, float time=5.f, const Color &color=Color(1.f, 0.f, 0.f)) |
| void | PurgeDebugDrawing () |
| const bool | IsSimulationOn () |
| void | SetGameManager (GameManager *gameManager) |
| GameManager * | GetGameManager () |
| RenderableIterator | GetFirstRenderable () |
| RenderableIterator | GetLastRenderable () |
| void | UnloadAll () |
| virtual void | ReceiveMessage (Message *m) |
| const bool | IsHighResScreen () |
| void | SetHighResolutionScreen (bool highRes) |
| void | TickAndRender () |
Static Public Member Functions | |
| static World & | GetInstance () |
Protected Member Functions | |
| float | CalculateNewDT () |
| void | UpdateRenderables (float frame_dt) |
| void | CleanupRenderables () |
| void | DrawRenderables () |
| void | Simulate (bool simRunning) |
| void | ProcessDeferredAdds () |
| void | ProcessDeferredLayerChanges () |
| void | ProcessDeferredRemoves () |
| void | RunPhysics (float frame_dt) |
| void | UpdateDebugItems (float frame_dt) |
| void | DrawDebugItems () |
Static Protected Attributes | |
| static World * | s_World = NULL |
The World is the class that keeps track of all Renderables, handles the Update/Render loop, processes events, etc.
Like the Camera, it uses the singleton pattern; you can't actually declare a new instance of a TagCollection. To access the World, use "theWorld" to retrieve the singleton object. "theWorld" is defined in both C++ and Lua.
If you're not familiar with the singleton pattern, this paper is a good starting point. (Don't be afraid that it's written by Microsoft.)
| World & World::GetInstance | ( | ) | [static] |
| bool World::Initialize | ( | unsigned int | windowWidth = 1024, |
| unsigned int | windowHeight = 768, |
||
| String | windowName = "Angel Engine", |
||
| bool | antiAliasing = false, |
||
| bool | fullScreen = false, |
||
| bool | resizable = false |
||
| ) |
The initial call to get Angel up and running. Opens the window, sets up our display, and begins the Update/Render loop.
The values passed in here will be overridden by any values set in the Preferences, with the WindowSettings table. (See the Preferences documentation and the example preferences file in IntroGame for more information.)
| windowWidth | The desired width (in pixels) of the window |
| windowHeight | The desired height (in pixels) of the window |
| windowName | The string that should appear in the window's title bar |
| antiAliasing | Whether or not the window should be initialized with anti-aliasing |
| fullScreen | Whether the game should be started in fullscreen mode. Note that the resolution is determined from windowWidth and windowHeight, and that Angel will attempt to change the system's video mode accordingly. We don't do any detection of what modes are valid, so make sure you're feeding this a legitimate resolution. |
| resizable | Whether the user will be allowed to resize the game window 8 using the operating system's normal resize widgets. |
| std::vector< Vec3ui > World::GetVideoModes | ( | ) |
Queries the video drivers to get a list of supported video modes for fullscreen gameplay. You'll likely want to get a list of valid modes to give the player a choice of resolutions. (You can then save the selected mode as part of the preferences.)
| void World::AdjustWindow | ( | int | windowWidth, |
| int | windowHeight, | ||
| const String & | windowName | ||
| ) |
Changes the dimension of the window while the game is running. Note that the behavior is undefined if this method is called while in fullscreen mode.
| windowWidth | The new desired width |
| windowHeight | The new desired height |
| windowName | The new string to go in the window's title bar |
| void World::MoveWindow | ( | int | xPosition, |
| int | yPosition | ||
| ) |
Moves the window around on screen, relative to the system origin. Note that behavior is undefined if this method is called while in fullscreen mode.
| xPosition | The new x position offset from the system origin |
| yPosition | The new y position offset from the system origin |
| bool World::SetupPhysics | ( | const Vector2 & | gravity = Vector2(0, -10), |
| const Vector2 & | maxVertex = Vector2(100.0f, 100.0f), |
||
| const Vector2 & | minVertex = Vector2(-100.0f, -100.0f) |
||
| ) |
Intialize physics. If you're not using our built-in physics, you don't have to call this function, but no PhysicsActors will do anything until you do.
| gravity | The gravity vector that will be applied to all PhysicsActors |
| maxVertex | The maximum vertex at which PhysicsActors will simulate. Any PhysicsActors that go beyond this point will get "stuck" in the bounding box. |
| minVertex | The minimum vertex at which PhysicsActors will simulate. Any PhysicsActors that go beyond this point will get "stuck" in the bounding box. |
| void World::Destroy | ( | ) |
| void World::ResetWorld | ( | ) |
Removes all Actors from the world (pending a check to the GameManager::IsProtectedFromUnloadAll function) and resets the camera to its default positioning.
| void World::StartGame | ( | ) |
| void World::StopGame | ( | ) |
| void World::ScriptExec | ( | const String & | code | ) |
| void World::LoadLevel | ( | const String & | levelName | ) |
Loads a level from Config/Level/[levelName].lua.
Each section of a level file specifies an Actor to be added to the world. The name of the section will be the name of the Actor, and the values in each section will be applied in addition to (or overriding) the ones specified in the archetype. Check the Actor::Create function for more information on how archetypes are specified.
| levelName |
| const float World::GetDT | ( | ) |
| const bool World::StopSimulation | ( | ) |
Toggles the simulation off. Several classes and objects will still receive updates (GameManager, Console, Camera, etc.), but all standard Actors will not receive Update calls until you call World::StartSimulation.
| const bool World::StartSimulation | ( | ) |
Toggles the simulation back on.
| void World::SetBackgroundColor | ( | const Color & | bgColor | ) |
| void World::Add | ( | Renderable * | newElement, |
| int | layer = 0 |
||
| ) |
Add a Renderable to the World so it will start receiving Update and Render calls every frame.
| *newElement | The new object to insert into the world |
| layer | The layer at which to insert it |
| void World::Add | ( | Renderable * | newElement, |
| const String & | layer | ||
| ) |
Add a Renderable to the World with a named layer.
| *newElement | The new object to insert into the world |
| layer | The name of the layer at which to insert it |
| void World::Remove | ( | Renderable * | oldElement | ) |
Remove a Renderable from the World. Does not deallocate any memory; you're responsible for doing that yourself.
| *oldElement | The element to remove |
| void World::UpdateLayer | ( | Renderable * | element, |
| int | newLayer | ||
| ) |
Move a Renderable to a new layer
| element | The renderable to move |
| newLayer | Its new home |
| void World::UpdateLayer | ( | Renderable * | element, |
| const String & | newLayerName | ||
| ) |
Move a Renderable to a new layer by name
| element | The renderable to move |
| newLayerName | The name of its new home |
| void World::NameLayer | ( | const String & | name, |
| int | number | ||
| ) |
Lets you name layers for easier reference later. This name can be used by the World::Add and World::UpdateLayer functions.
| name | The string to assign as a layer name |
| number | The number to which this name should refer |
| const int World::GetLayerByName | ( | const String & | name | ) |
| RenderLayers& World::GetLayers | ( | ) | [inline] |
| void World::RegisterConsole | ( | Console * | console | ) |
| Console * World::GetConsole | ( | ) |
| b2World & World::GetPhysicsWorld | ( | ) |
| const bool World::IsPhysicsSetUp | ( | ) | [inline] |
Lets you know if physics have been appropriately initialized with the World::SetupPhysics function.
| void World::WakeAllPhysics | ( | ) |
| void World::BeginContact | ( | b2Contact * | contact | ) | [virtual] |
| void World::EndContact | ( | b2Contact * | contact | ) | [virtual] |
| void World::SetSideBlockers | ( | bool | turnOn, |
| float | restitution = -1.0f |
||
| ) |
When working with physics, oftentimes you want to keep objects from going beyond the edge of the visible screen. This function sets up objects to block the edges so they can't.
| turnOn | If true, side blockers are enabled, if false, they're disabled |
| restitution | The restitution of the blockers (how bouncy they are) |
| float World::GetCurrentTimeSeconds | ( | ) | [inline] |
| float World::GetTimeSinceSeconds | ( | float | lastTime | ) | [inline] |
| void World::PurgeDebugDrawing | ( | ) |
| const bool World::IsSimulationOn | ( | ) |
Check whether the simulation is running. See also StartSimulation() and StopSimulation().
| void World::SetGameManager | ( | GameManager * | gameManager | ) |
Set a GameManager object to be your high-level coordinator.
| gameManager | The new manager |
| GameManager* World::GetGameManager | ( | ) | [inline] |
Get the current registered manager
| RenderableIterator World::GetFirstRenderable | ( | ) | [inline] |
Get an iterator to start cycling through all the Renderables that have been added to the World.
| RenderableIterator World::GetLastRenderable | ( | ) | [inline] |
Get an iterator pointing to the last Renderable in the World.
| void World::UnloadAll | ( | ) |
Removes all Actors from the world (pending a check to the GameManager::IsProtectedFromUnloadAll function).
| void World::ReceiveMessage | ( | Message * | m | ) | [virtual] |
Implementation of the MessageListener::ReceiveMessage function. Used to get notifications of camera changes so the side blockers can be updated if they're enabled.
| m | The message being delivered. |
Implements MessageListener.
| const bool World::IsHighResScreen | ( | ) | [inline] |
| void World::SetHighResolutionScreen | ( | bool | highRes | ) | [inline] |
| void World::TickAndRender | ( | ) |


1.7.5.1