Skip to content

Instantly share code, notes, and snippets.

@griffi-gh
Created November 16, 2025 15:31
Show Gist options
  • Select an option

  • Save griffi-gh/ac27c4cdbe220d70d9db93c2e17b3240 to your computer and use it in GitHub Desktop.

Select an option

Save griffi-gh/ac27c4cdbe220d70d9db93c2e17b3240 to your computer and use it in GitHub Desktop.
using. /Verse.org
using. /Verse.org/Native
using. /Verse.org/SceneGraph
using. /Verse.org/Simulation
tickable<public> := interface() {
var Cancelable_PreTick<private>: ?cancelable = false;
var Cancelable_PostTick<private>: ?cancelable = false;
OnBeginSimulation<public>(Component: component):void =
TickEvents := Component.GetTickEvents();
set Cancelable_PreTick = option. TickEvents.PrePhysics.Subscribe(OnPreTick); # <- ignore error here
set Cancelable_PostTick = option. TickEvents.PostPhysics.Subscribe(OnPostTick); # <- ignore error here
OnEndSimulation<public>(Component: component):void =
if (Cancelable := Cancelable_PreTick?). Cancelable.Cancel();
if (Cancelable := Cancelable_PostTick?). Cancelable.Cancel();
set Cancelable_PreTick = false;
set Cancelable_PostTick = false;
OnPreTick<public>(Dt: float): void = {}
OnPostTick<public>(Dt: float): void = {}
}
@griffi-gh
Copy link
Author

example usage:

test_component<public> := class<final_super>(component, tickable) {
    OnBeginSimulation<override>(): void = (tickable:)OnBeginSimulation(Self);
    OnEndSimulation<override>(): void = (tickable:)OnEndSimulation(Self);

    OnPreTick<override>(Dt: float): void = {
        # ...
    }
    
    OnPostTick<override>(Dt: float): void = {
        # ...
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment