Class AbstractModule<T extends Time>

java.lang.Object
dev.engine.core.module.AbstractModule<T>
Type Parameters:
T - the update context type
All Implemented Interfaces:
Module<T>

public abstract class AbstractModule<T extends Time> extends Object implements Module<T>
Template-method base class for modules that enforces the lifecycle state machine.

Subclasses override the do* methods to provide custom behaviour at each lifecycle stage. All public lifecycle methods are final so that the state machine cannot be circumvented.

The only method a subclass must implement is

invalid reference
#doUpdate(Object)
; every other hook defaults to a no-op.
  • Constructor Details

    • AbstractModule

      public AbstractModule()
  • Method Details

    • onCreate

      public final void onCreate()
      Description copied from interface: Module
      Called once after registration. Allocate resources here.
      Specified by:
      onCreate in interface Module<T extends Time>
    • onInit

      public final void onInit(ModuleManager<T> manager)
      Description copied from interface: Module
      Called once after all dependencies are initialized.
      Specified by:
      onInit in interface Module<T extends Time>
      Parameters:
      manager - the module manager that owns this module
    • onUpdate

      public final void onUpdate(T context)
      Description copied from interface: Module
      Called per update tick with the strategy-produced context.
      Specified by:
      onUpdate in interface Module<T extends Time>
      Parameters:
      context - the update context for this tick
    • onDeinit

      public final void onDeinit()
      Description copied from interface: Module
      Called once before cleanup. Reverse of init.
      Specified by:
      onDeinit in interface Module<T extends Time>
    • onCleanup

      public final void onCleanup()
      Description copied from interface: Module
      Called once to release all resources.
      Specified by:
      onCleanup in interface Module<T extends Time>
    • setEnabled

      public final void setEnabled(boolean enabled)
    • doCreate

      protected void doCreate()
    • doInit

      protected void doInit(ModuleManager<T> manager)
    • doUpdate

      protected abstract void doUpdate(T context)
    • doDeinit

      protected void doDeinit()
    • doCleanup

      protected void doCleanup()
    • getModule

      protected final <M extends Module<T>> M getModule(Class<M> type)
    • getState

      public final ModuleState getState()
      Description copied from interface: Module
      Returns the current lifecycle state.
      Specified by:
      getState in interface Module<T extends Time>
      Returns:
      the module's current ModuleState
    • isEnabled

      public final boolean isEnabled()
      Description copied from interface: Module
      Returns whether this module is currently enabled for updates.
      Specified by:
      isEnabled in interface Module<T extends Time>
      Returns:
      true if the module is enabled, false otherwise