Reference TSceneController
Declared in Codebot.Render.Scenes.Controller.pas on line 57
TSceneController runs a scene in a TGraphicsBox.
The controller hooks the render events of the box, calling any handlers that were assigned before it. Scenes are created, updated and destroyed on the render thread with the context current:
1. OpenScene asks for a scene class from the main thread
2. The next OnRender frees the previous scene and creates the new one
3. The box reads the events of SDL and calls OnInput for each one, which
delivers key and mouse input to the scene
4. Every OnRender calculates the shared Timer once, then calls Update
with the frame time
5. OnRenderStop or CloseScene frees the scene
2. The next OnRender frees the previous scene and creates the new one
3. The box reads the events of SDL and calls OnInput for each one, which
delivers key and mouse input to the scene
4. Every OnRender calculates the shared Timer once, then calls Update
with the frame time
5. OnRenderStop or CloseScene frees the scene
When the scene has a StepInterval the box runs a step thread which calls Step on the scene. The step thread is stopped before the scene is freed.
The controller is the scene host. It is current on the render thread while the box renders, giving scenes the box Canvas and a default font loaded from 'fonts/roboto.ttf' in the assets folder.
Key and mouse events come from the SDL window of the box, the same as they do in an SDL application, and arrive on the render thread, so scene methods only ever run on that thread one at a time. The box is given focus when it is clicked so it receives key events. The keyboard, mouse and joysticks in Codebot.Hardware are scanned by the box before each frame.
Scenes use the clipboard and dialogs from Codebot.Platform.LCL, which reach the main thread themselves. Window is the form holding the box. Dialogs executed by a scene deliver OnClose on the render thread when the controller calls PlatformDispatch at the start of each frame.
The box must not be rendering when OpenScene first attaches it or when the controller is destroyed. Both are the case when the controller is created in a form's OnCreate and owned by the same form, because a form destroys its window, which stops the render thread, before it frees its components.
TSceneController = class(TSceneHost)
protected
function GetVSync: Boolean; override;
procedure SetVSync(Value: Boolean); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ OpenScene attaches the box if needed and runs a new scene of the class in
it. It can be called again to switch scenes. }
procedure OpenScene(Box: TGraphicsBox; SceneClass: TSceneClass);
{ CloseScene frees the running scene on the next frame }
procedure CloseScene;
{ The box the controller is attached to }
property Box: TGraphicsBox read FBox;
end;See also
TGraphicsBox in Codebot.Render.Controls.pas
TSceneClass in Codebot.Render.Scenes.pas
TSceneHost in Codebot.Render.Scenes.pas