Documentation
¶
Overview ¶
graphics.gd/classdb/MainLoop is the abstract base class for a Godot project's game loop. It is inherited by graphics.gd/classdb/SceneTree, which is the default game loop implementation used in Godot projects, though it is also possible to write and use one's own graphics.gd/classdb/MainLoop subclass instead of the scene tree.
Upon the application start, a graphics.gd/classdb/MainLoop implementation must be provided to the OS; otherwise, the application will exit. This happens automatically (and a graphics.gd/classdb/SceneTree is created) unless a graphics.gd/classdb/MainLoop graphics.gd/classdb/Script is provided from the command line (with e.g. godot -s my_loop.gd) or the graphics.gd/classdb/ProjectSettings "application/run/main_loop_type" project setting is overwritten.
Here is an example script implementing a simple graphics.gd/classdb/MainLoop:
package main import ( "graphics.gd/classdb/Input" "graphics.gd/classdb/MainLoop" "graphics.gd/variant/Float" ) type MyMainLoop struct { MainLoop.Extension[MyMainLoop] timeElapsed Float.X } func (m *MyMainLoop) Initialize() { println("Initialized:") println(" Starting time: ", m.timeElapsed) } func (m *MyMainLoop) Process(delta Float.X) bool { m.timeElapsed += delta return Input.GetMouseButtonMask() != 0 || Input.IsKeyPressed(Input.KeyEscape) } func (m *MyMainLoop) Finalize() { println("Finalized:") println(" End time: ", m.timeElapsed) }
Index ¶
- Constants
- type Advanced
- type Any
- type Extension
- type ID
- type Implementation
- type Instance
- func (self Instance) AsMainLoop() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) ID() ID
- func (self Instance) OnOnRequestPermissionsResult(cb func(permission string, granted bool), flags ...Signal.Flags)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type Interface
Constants ¶
const NotificationApplicationFocusIn Object.Notification = 2016 //gd:MainLoop.NOTIFICATION_APPLICATION_FOCUS_IN
const NotificationApplicationFocusOut Object.Notification = 2017 //gd:MainLoop.NOTIFICATION_APPLICATION_FOCUS_OUT
const NotificationApplicationPaused Object.Notification = 2015 //gd:MainLoop.NOTIFICATION_APPLICATION_PAUSED
const NotificationApplicationResumed Object.Notification = 2014 //gd:MainLoop.NOTIFICATION_APPLICATION_RESUMED
const NotificationCrash Object.Notification = 2012 //gd:MainLoop.NOTIFICATION_CRASH
const NotificationOsImeUpdate Object.Notification = 2013 //gd:MainLoop.NOTIFICATION_OS_IME_UPDATE
const NotificationOsMemoryWarning Object.Notification = 2009 //gd:MainLoop.NOTIFICATION_OS_MEMORY_WARNING
const NotificationTextServerChanged Object.Notification = 2018 //gd:MainLoop.NOTIFICATION_TEXT_SERVER_CHANGED
const NotificationTranslationChanged Object.Notification = 2010 //gd:MainLoop.NOTIFICATION_TRANSLATION_CHANGED
const NotificationWmAbout Object.Notification = 2011 //gd:MainLoop.NOTIFICATION_WM_ABOUT
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this [Extension]See Interface for methods that can be overridden by T.
func (*Extension[T]) AsMainLoop ¶
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Implementation ¶
type Implementation = implementation
Implementation implements Interface with empty methods.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsMainLoop ¶
func (Instance) OnOnRequestPermissionsResult ¶
type Interface ¶
type Interface interface { // Called once during initialization. Initialize() // Called each physics tick. 'delta' is the logical time between physics ticks in seconds and is equal to [graphics.gd/classdb/Engine.TimeScale] / [graphics.gd/classdb/Engine.PhysicsTicksPerSecond]. Equivalent to [graphics.gd/classdb/Node.Instance.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: [Interface.PhysicsProcess] may be called up to [graphics.gd/classdb/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. PhysicsProcess(delta Float.X) bool // 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 [graphics.gd/classdb/Node.Instance.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 [graphics.gd/classdb/Engine.TimeScale] * [graphics.gd/classdb/Engine.MaxPhysicsStepsPerFrame] / [graphics.gd/classdb/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 [graphics.gd/classdb/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 [graphics.gd/classdb/OS.DeltaSmoothing] if this is enabled for the project. Process(delta Float.X) bool // Called before the program exits. Finalize() }