Castle Game Engine: CastleLevels: Class TGameSceneManager

# Class TGameSceneManager
Description | Hierarchy | Fields | Methods | Properties
## Unit CastleLevels ## Declaration `type TGameSceneManager = class(TCastleSceneManager)` ## Description Scene manager that can comfortably load and manage a 3D game level. It really adds only one new method to TCastleSceneManager: LoadLevel, see it's documentation to know what it gives you. It also exposes Logic and Info properties corresponding to the currently loaded level. ## Hierarchy TComponent TInputListener TUIControl TUIRectangularControl TCastleAbstractViewport TCastleSceneManager TGameSceneManager ## Overview ### Methods
| `destructor Destroy; override;`
| `procedure LoadLevel(const LevelName: string);`
| `procedure LoadLevel(const AInfo: TLevelInfo);`
| `procedure UnloadLevel;`
### Properties
| `property Logic: TLevelLogic read FLogic;`
| `property Info: TLevelInfo read FInfo;`
## Description ### Methods
| `destructor Destroy; override;`
| `procedure LoadLevel(const LevelName: string);`
Load game level. Set scene manager 3D items: Clear all 3D items from TCastleSceneManager.Items list (except TCastleSceneManager.Player), clear Camera and TCastleSceneManager.MainScene as well. Then load a new main scene and camera, adding to TCastleSceneManager.Items all 3D resources (creatures and items) defined by placeholders named CasRes* in the main level 3D file. Make sure 3D resources are ready: Resources are T3DResource instances on Resources list. They are heavy (in terms of memory use and preparation time), so you don't want to just load everything for every level. This method makes sure that all resources required by this level are prepared. All resources requested in level.xml file (in <resources> element in level.xml), as well as resources requested in player.xml file, as well as resources with AlwaysPrepared (usually: all possible items that can be dropped from player inventory on any level) will be prepared. Initialize move limits and water volume from placeholders. Special object names CasMoveLimit and CasWater (in the future: CasWater* with any suffix) in the main scene 3D model determine the places where player can go and where water is. When CasMoveLimit object is missing, we calculate it to include the level bounding box, with some additional space above (to allow flying). Initialize sectors and waypoints from placeholders. Special shape names CasSector* and CasWaypoint* can be used in level 3D model to help creature AI. You can add and name such shapes in 3D modeler, like Blender, and they will be automatically understood by the engine when loading level. Objects named CasSector<index>[_<ignored>] define sectors. The geometry of a sector with given <index> is set to be the sum of all CasSector<index>* boxes. Sectors are numbered from 0. Objects named CasWaypoint[<ignored>] define waypoints. Each waypoint is stored as a 3D point, this point is the middle of the bounding box of the object named CasWaypoint[<ignored>]. After extracting from level 3D model, sectors and waypoints are then connected together by TSectorList.LinkToWaypoints. The idea is that you can go from one sector to the other through the waypoint that is placed on the border of both of them. Prepare everything possible for rendering and collision detection to avoid later preparing things on-demand (which would cause unpleasant delay during gameplay). E.g. prepares octree and OpenGL resources. The overloaded version with a LevelName string searches the Levels list for a level with given name (and raises exception if it cannot be found). It makes sense if you filled the Levels list before, usually by Levels.LoadFromFiles call. So you can easily define a level in your data with `name="xxx"` in the `level.xml` file, and then you can load it by `LoadLevel('xxx')` call. It's important to note that you do not have to use this method to make a 3D game. You may as well just load the 3D scene yourself, and add things to TCastleSceneManager.Items and TCastleSceneManager.MainScene directly. This method is just a very comfortable way to set your 3D world in one call — but it's not the only way.
| `procedure LoadLevel(const AInfo: TLevelInfo);`
| `procedure UnloadLevel;`
Release everything loaded by LoadLevel, clearing the 3D world (only Player is left). You do not have to call this in normal circumstances, as each LoadLevel automatically clears previous 3D world. If fact, you should not call this in normal circumstances: calling this prevents the next LoadLevel to reuse resources that were needed by both old and new level. Call this only if you really want to conserve memory right now. Or when you want to force reload of resources at next LoadLevel call (for example, if you changed AnimationSmoothness, it is useful — otherwise the old animations will remain loaded with old AnimationSmoothness setting).
### Properties
| `property Logic: TLevelLogic read FLogic;`
Level logic and state.
| `property Info: TLevelInfo read FInfo;`
Level information, independent from current level state.
Generated by PasDoc 0.13.0 on 2015-06-15 04:43:10