Download Now
Forums

    Reference TSceneHost

    Declared in Codebot.Render.Scenes.pas on line 83

    TSceneHost runs scenes and provides what they share. A host makes itself current on its render thread with SetSceneHost, and scenes created on that thread use it. All of its properties are used from the render thread.
    A host calls PlatformDispatch from Codebot.Platform once a frame before updating its scene, so dialogs executed by the scene deliver their OnClose events on the render thread.
    A program which sets AssetKey keeps its assets in a dat file beside the program, when one is there, instead of in an assets folder. Such a program makes its dat file when it is started with --build-dat, which a host handles with BuildDat before it opens a window. See Codebot.Render.Assets.
      TSceneHost = class(TComponent)
      protected
        FCanvas: ICanvas;
        FFont: IFont;
        FTimer: IStopwatch;
        FTime: Double;
        FFrameRate: Integer;
        FMouseX: Float;
        FMouseY: Float;
        FWindow: IWindow;
        FVSync: Boolean;
        { The clipboard is PlatformClipboard unless a host overrides it }
        function GetClipboard: string; virtual;
        procedure SetClipboard(const Value: string); virtual;
        { Hosts which own an OpenGL context apply VSync to it }
        function GetVSync: Boolean; virtual;
        procedure SetVSync(Value: Boolean); virtual;
        function GetAssetKey: LongWord;
        procedure SetAssetKey(Value: LongWord);
        { BuildDat returns true if the program was started with --build-dat. The dat
          file has then been built from the assets folder and ExitCode set, and the
          host must end the program without running a scene. A host calls this
          before it creates a window. }
        function BuildDat: Boolean;
      public
        { The canvas used for vector graphics, sharing Ctx with the scenes }
        property Canvas: ICanvas read FCanvas;
        { The default font, which may be nil if it could not be loaded }
        property Font: IFont read FFont;
        { The timer shared by all scenes, calculated once at the start of a frame }
        property Timer: IStopwatch read FTimer;
        { The time of the current frame }
        property Time: Double read FTime;
        { Frames rendered in the last second }
        property FrameRate: Integer read FFrameRate;
        { The position of the last mouse event }
        property MouseX: Float read FMouseX;
        property MouseY: Float read FMouseY;
        { Text on the clipboard, read and written from the render thread }
        property Clipboard: string read GetClipboard write SetClipboard;
        { The window showing the scenes, which may be nil if the host has none }
        property Window: IWindow read FWindow;
        { When VSync is True each frame waits for the vertical sync of the display.
          It is used from the render thread. }
        property VSync: Boolean read GetVSync write SetVSync;
        { The key of the dat file holding the assets of the program, which is four
          bytes such as $A1B2C3D4. It is the same for every host, and is set before
          a scene is run. Zero, the default, means there is no key, and assets are
          then files in the assets folder. }
        property AssetKey: LongWord read GetAssetKey write SetAssetKey;
      end;

    See also

    Float in Codebot.System.pas
    ICanvas in Codebot.Render.Graphics.pas
    IFont in Codebot.Render.Graphics.pas
    IStopwatch in Codebot.System.pas
    IWindow in Codebot.Platform.pas