Skip to content

Script Engine

ZilverBlade edited this page Apr 9, 2024 · 21 revisions

Index

  1. Game Loop
  2. Scripting
    1. Script Classes
    2. Script Attributes
      1. Editor
      2. Network
    3. Networking
      1. Connection, Relevance and Roles
      2. Field Replication
      3. Method Replication (RPC)

Glossary

  • C# calls static methods in the convention Namespace.Class.Subclass.Method(parameters), however to distinguish namespaces from class scopes, methods and fields, in this documentation it is written as Namespace.Class::Subclass::Method(parameters) (similar to C++ scope style).
  • Certain words are written in bold to stand out, avoiding confusion or error with certain concepts by grabbing your eye’s attention.

1. Game Loop

  • Shard3D runs with a single threaded game loop, everything gets called in a defined order, however it is planned to separate the game logic and physics from the renderer (1 game thread, 1 renderer thread).
  • Renderer calls always get called at the end of the loop
  • Physics runs with a fixed step rate configurable in the engine_settings.ini (default is 120Hz). It may run multiple times per frame or it may even skip a frame! (depending on the framerate)
  • When physics is stepped in a frame, it's done before the C# script step except for LLevel::PreFixedTickEvent(float ts) (Shard3D.Scriptable) (this also means that fixed tick methods will be called before their variable tick counterparts)
  • Physics body transform interpolation occurs every frame after physics step (if occurred) and before script engine step (this also means before the fixed step events)

2. Scripting

2.i. Script Classes

  • Scripts derive from 3 base classes: LLevel, LGameMode, AActor (Shard3D.Scriptable)
  • L is the prefix stating it’s a singleton inside the level, thus there may only be one instance.
  • A is the prefix stating it’s an actor, which is a scriptable prefab actor, it may have multiple instances.

AActor: Has multiple derived classes: AController (Inherits AActor, IGhostActor, INetworkReplicatesServerOwner, INetworkOwnableActor) Only class that is allowed to poll user inputs and manage renderer data Can possess APawn (AController::PossessPawn(APawn pawn) and AController::UnpossessPawn(APawn pawn)) Must be activated by AController::Activate(PlayerIndex playerIndex) (set playerIndex to PlayerIndex.Player0 as local multiplayer is not supported yet) APawn (Inherits AActor, INetworkReplicatesEveryone, INetworkOwnableActor) Nothing special in this class, other than a convenient class to be associated with a controller (e.g. server can automatically understand which pawns belong to which clients) AProp (currently unused) AGameState (currently unused) APlayerState (currently unused) BeginEvent() (called when level simulation starts, only called once solely for actors that already existed before the level started simulation!) EndEvent() (called when the level simulation ends, only called once solely for actors that survived until the end of the simulation!) SpawnEvent() (called when actor is spawned) KillEvent() (called when actor is destroyed) TickEvent(float dt) (called every game loop, is not stable, as it has a variable delta time and should be used when integration can be done with a variable frame time)

PhysicsTickEvent(float ts) (called at the same rate as the physics step, may be called several times per frame, or it may be skipped in a frame as it runs at a fixed step rate, should be used for integration that requires a fixed time step. Warning, this does not mean that the values get interpolated like the physics positions do, if interpolation between steps is requires, you should do that in a variable frametime tick event (e.g. AActor::TickEvent(), LLevel::PostTickEvent())) LLevel: Is set in the WorldSceneInfoComponent BeginEvent() (called before any other begin event, it is the first event called) EndEvent() (called after every end event, it is the last event called) PreTickEvent(float dt) (called before any AActor::TickEvent(float dt)) PostTickEvent(float dt) (called after every AActor::TickEvent(float dt)) PrePhysicsTickEvent(float ts) (called before any AActor::PhysicsTickEvent(float ts)) PostPhysicsTickEvent(float ts) (called after every AActor::PhysicsTickEvent(float ts)) LGameMode Is set in the WorldSceneInfoComponent N is the prefix stating it is a networking related method NClientConnectingEvent(AController controller) (client has connected and their respective default controller prefab) NClientDisconnectedEvent(AController controller) (client has disconnected)

Clone this wiki locally