MainLoop
Abstract base class for the game's main loop.
Abstract base class for the game's main loop.
MainLoop is the abstract base class for a Reckfell project's game loop. It is inherited by EntityTree, which is the default game loop implementation used in Reckfell projects, though it is also possible to write and use one's own MainLoop subclass instead of the scene tree.
Upon the application start, a MainLoop implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a EntityTree is created) unless a MainLoop Script is provided from the command line (with e.g. reckfell -s my_loop.cs) or the ProjectSettings.application/run/main_loop_type project setting is overwritten.
Here is an example script implementing a simple MainLoop:
using Reckfell;
[GlobalClass]
public partial class CustomMainLoop : MainLoop
{
private double _timeElapsed = 0;
public override void _Initialize()
{
ReckfellApi.Print("Initialized:");
ReckfellApi.Print($" Starting Time: {_timeElapsed}");
}
public override bool _Process(double delta)
{
_timeElapsed += delta;
// Return true to end the main loop.
return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Key.Escape);
}
private void _Finalize()
{
ReckfellApi.Print("Finalized:");
ReckfellApi.Print($" End Time: {_timeElapsed}");
}
}Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
MainLoopConstructor
public MainLoop();Methods4
_Finalizevoid
public virtual void _Finalize();Called before the program exits.
_Initializevoid
public virtual void _Initialize();Called once during initialization.
_PhysicsProcessbool
public virtual bool _PhysicsProcess(double delta);Called each physics tick. delta is the logical time between physics ticks in seconds and is equal to Engine.TimeScale / Engine.PhysicsTicksPerSecond. Equivalent to Entity._PhysicsProcess.
If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next step.
Note: MainLoop._PhysicsProcess may be called up to Engine.MaxPhysicsStepsPerFrame times per (idle) frame. This step limit may be reached when the engine is suffering performance issues.
Note: Accumulated delta may diverge from real world seconds.
| Name | Type | Default |
|---|---|---|
delta | double | — |
bool_Processbool
public virtual bool _Process(double delta);Called on each idle frame, prior to rendering, and after physics ticks have been processed. delta is the time between frames in seconds. Equivalent to Entity._Process.
If implemented, the method must return a boolean value. true ends the main loop, while false lets it proceed to the next frame.
Note: When the engine is struggling and the frame rate is lowered, delta will increase. When delta is increased, it's capped at a maximum of Engine.TimeScale * Engine.MaxPhysicsStepsPerFrame / Engine.PhysicsTicksPerSecond. As a result, accumulated delta may not represent real world time.
Note: When --fixed-fps is enabled or the engine is running in Movie Maker mode (see MovieWriter), process delta will always be the same for every frame, regardless of how much time the frame took to render.
Note: Frame delta may be post-processed by OS.DeltaSmoothing if this is enabled for the project.
| Name | Type | Default |
|---|---|---|
delta | double | — |
boolSignals and events1
OnRequestPermissionsResultEvent
public event MainLoop.OnRequestPermissionsResultEventHandler OnRequestPermissionsResult;Emitted when a user responds to a permission request.
| Name | Type | Default |
|---|---|---|
permission | string | — |
granted | bool | — |
Fields and constants12
NotificationApplicationFocusInField
public const long NotificationApplicationFocusIn = 2016;Notification received from the OS when the application is focused, i.e. when changing the focus from the OS desktop or a thirdparty application to any open window of the Reckfell instance. Implemented on desktop and mobile platforms.
NotificationApplicationFocusOutField
public const long NotificationApplicationFocusOut = 2017;Notification received from the OS when the application is defocused, i.e. when changing the focus from any open window of the Reckfell instance to the OS desktop or a thirdparty application. Implemented on desktop and mobile platforms.
NotificationApplicationPausedField
public const long NotificationApplicationPaused = 2015;Notification received from the OS when the application is paused. Specific to the Android and iOS platforms. Note: On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
NotificationApplicationPipModeEnteredField
public const long NotificationApplicationPipModeEntered = 2019;Notification received when the application enters picture-in-picture mode.
NotificationApplicationPipModeExitedField
public const long NotificationApplicationPipModeExited = 2020;Notification received when the application exits picture-in-picture mode.
NotificationApplicationResumedField
public const long NotificationApplicationResumed = 2014;Notification received from the OS when the application is resumed. Specific to the Android and iOS platforms.
NotificationCrashField
public const long NotificationCrash = 2012;Notification received from Reckfell's crash handler when the engine is about to crash. Implemented on desktop platforms if the crash handler is enabled.
NotificationOsImeUpdateField
public const long NotificationOsImeUpdate = 2013;Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string). Implemented on desktop and web platforms.
NotificationOsMemoryWarningField
public const long NotificationOsMemoryWarning = 2009;Notification received from the OS when the application is exceeding its allocated memory. Specific to the iOS platform.
NotificationTextServerChangedField
public const long NotificationTextServerChanged = 2018;Notification received when text server is changed.
NotificationTranslationChangedField
public const long NotificationTranslationChanged = 2010;Notification received when translations may have changed. Can be triggered by the user changing the locale. Can be used to respond to language changes, for example to change the UI strings on the fly. Useful when working with the built-in translation support, like ReckfellObject.Tr.
NotificationWMAboutField
public const long NotificationWMAbout = 2011;Notification received from the OS when a request for "About" information is sent. Specific to the macOS platform.