Class TGameSceneManager

Unit

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

Overview

Methods

Protected procedure Notification(AComponent: TComponent; Operation: TOperation); override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public function Press(const Event: TInputPressRelease): Boolean; override;
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
Public procedure LoadLevel(const LevelName: string);
Public procedure LoadLevel(const AInfo: TLevelInfo);
Public procedure UnloadLevel;
Public function LevelProperties: TLevelProperties;

Properties

Public property Logic: TLevelLogic read FLogic;
Public property Info: TLevelInfo read FInfo;
Public property Sectors: TSectorList read FSectors;
Public property Water: TBox3D read FWater write FWater;
Public property Player: TPlayer read FPlayer write SetPlayer;

Description

Methods

Protected procedure Notification(AComponent: TComponent; Operation: TOperation); override;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public function Press(const Event: TInputPressRelease): Boolean; override;
 
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
 
Public 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.

Public procedure LoadLevel(const AInfo: TLevelInfo);
 
Public 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 BakedAnimationSmoothness, it is useful — otherwise the old animations will remain loaded with old BakedAnimationSmoothness setting).

Public function LevelProperties: TLevelProperties;

Instance of TLevelProperties to be passed to created creatures, items.

Properties

Public property Logic: TLevelLogic read FLogic;

Level logic and state.

Public property Info: TLevelInfo read FInfo;

Level information, independent from current level state.

Public property Sectors: TSectorList read FSectors;

Sectors and waypoints of this world, for AI in 3D. Initialized by LoadLevel. Nil if you never call LoadLevel.

Public property Water: TBox3D read FWater write FWater;

Water volume in the scene. It may be used by various 3D objects to indicate appropriate behavior — some things swim, some things drown and such. For now, this is only used by TPlayer class to detect swimming (and make appropriate sounds, special rendering, drowning and such).

For now, this is just a simple TBox3D. It will be extended to represent a set of flexible 3D volumes in the future.

Empty initially. Initialize it however you want.

Public property Player: TPlayer read FPlayer write SetPlayer;

Player in this 3D world. This serves various purposes:

  • This object never collides with the navigation. See TCastleSceneManager.AvoidNavigationCollisions.

  • Player transformation will be automatically synchronized with current TCastleAbstractViewport.Camera position. As such, TPlayer represents the volume of player in 1st person games.

  • For AI in CastleCreatures, hostile creatures will attack this player. So this determines the target position that creatures try to reach, where they shoot missiles etc. More advanced AI, with friendlies/companions, or cooperating factions of creatures, may have other mechanisms to determine who wants to attack who.

  • For items on level in CastleItems, this player will pick up the items lying on the ground, and will be able to equip weapons. This functionality may be generalized in the future, to allow anyone to pick up and carry and equip items.


Generated by PasDoc 0.15.0.