// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Delegate.h" #include "Engine/Core/Types/DateTime.h" #include "Engine/Scripting/ScriptingType.h" class TaskGraph; class JsonAsset; /// /// The main engine class. /// API_CLASS(Static) class FLAXENGINE_API Engine { DECLARE_SCRIPTING_TYPE_NO_SPAWN(Engine); public: /// /// The engine start time (local time). /// API_FIELD(ReadOnly) static DateTime StartupTime; /// /// True if app has focus (one of the windows is being focused). /// API_FIELD(ReadOnly) static bool HasFocus; /// /// Gets the current frame count since the start of the game. /// API_FIELD(ReadOnly) static uint64 FrameCount; public: /// /// Event called on engine fixed update. /// static Action FixedUpdate; /// /// Event called on engine update. /// static Action Update; /// /// Task graph for engine update. /// API_FIELD(ReadOnly) static TaskGraph* UpdateGraph; /// /// Event called after engine update. /// static Action LateUpdate; /// /// Event called after engine update. /// static Action LateFixedUpdate; /// /// Event called during frame rendering and can be used to invoke custom rendering with GPUDevice. /// static Action Draw; /// /// Event called during game loop when application gets paused (engine tick will be postponed until unpause). Used on platforms that support only one app on screen. /// static Action Pause; /// /// Event called during game loop when application gets unpaused (engine tick will continue). Used on platforms that support only one app on screen. /// static Action Unpause; public: /// /// The main engine function (must be called from platform specific entry point). /// /// The input application command line arguments. /// The application exit code. static int32 Main(const Char* cmdLine); /// /// Exits the engine. /// /// The exit code. static void Exit(int32 exitCode = -1); /// /// Requests normal engine exit. /// /// The exit code. API_FUNCTION() static void RequestExit(int32 exitCode = 0); public: /// /// Fixed update callback used by the physics simulation (fixed stepping). /// static void OnFixedUpdate(); /// /// Updates game and all engine services. /// static void OnUpdate(); /// /// Late update callback. /// static void OnLateUpdate(); /// /// Late fixed update callback. /// static void OnLateFixedUpdate(); /// /// Draw callback. /// static void OnDraw(); /// /// Called when engine exists. Disposes engine services and shuts down the engine. /// static void OnExit(); public: // Returns true if engine is running without main window (aka headless mode). API_PROPERTY() static bool IsHeadless(); // True if Engine is ready to work (init and not disposing) static bool IsReady(); static bool ShouldExit(); /// /// Returns true if the game is running in the Flax Editor; false if run from any deployment target. Use this property to perform Editor-related actions. /// API_PROPERTY() static bool IsEditor(); /// /// Gets the amount of frames rendered during last second known as Frames Per Second. User scripts updates or fixed updates for physics may run at a different frequency than scene rendering. Use this property to get an accurate amount of frames rendered during the last second. /// API_PROPERTY() static int32 GetFramesPerSecond(); /// /// Gets the application command line arguments. /// API_PROPERTY() static const String& GetCommandLine(); /// /// Gets the custom game settings asset referenced by the given key. /// /// The settings key. /// The returned asset. Returns null if key is invalid, cannot load asset or data is missing. API_FUNCTION() static JsonAsset* GetCustomSettings(const StringView& key); // The main window handle static Window* MainWindow; /// /// Brings focused to the game viewport (game can receive input). /// API_FUNCTION() static void FocusGameViewport(); /// /// Checks whenever the game viewport is focused by the user (eg. can receive input). /// API_PROPERTY() static bool HasGameViewportFocus(); private: static void OnPause(); static void OnUnpause(); };