Class LogoSimulation

java.lang.Object
edu.cnu.mdi.mdi3D.view3D.logoDemo.LogoSimulation
All Implemented Interfaces:
edu.cnu.mdi.sim.Simulation

public class LogoSimulation extends Object implements edu.cnu.mdi.sim.Simulation
Simulation wrapper for the rotating MDI-logo demo.

This class contains no UI code. It is executed on the simulation thread by the MDI simulation engine, exactly like AizawaSimulation and KineticsSimulation.

Unlike those two demos, this simulation has no numerical model to integrate — each step only advances a rotation angle by a fixed increment. Because that has essentially zero computational cost, step sleeps briefly before doing its (trivial) work, so the simulation thread self-paces instead of busy-spinning and consuming a full CPU core for no visual benefit. SimulationEngine applies no throttling of its own between step() calls, so a step body that is this cheap must pace itself.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    Default animation-angle increment, in degrees, advanced per step.
    static final int
    Default safety cap on the number of steps (about 4.6 hours at the default rate).
    static final long
    Default self-paced delay between steps, in milliseconds.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct the logo-spin simulation with the default rate.
    LogoSimulation(float degreesPerStep, long stepSleepMs)
    Construct the logo-spin simulation with an explicit rate.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    init(edu.cnu.mdi.sim.SimulationContext ctx)
     
    void
    setEngine(edu.cnu.mdi.sim.SimulationEngine engine)
    Attach the engine so this simulation can post messages and request refreshes.
    void
    setMaxSteps(int maxSteps)
    Set a safety cap on the number of steps.
    boolean
    step(edu.cnu.mdi.sim.SimulationContext ctx)
     
    float
    Take the animation-angle increment accumulated since the last call and reset the accumulator to zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface edu.cnu.mdi.sim.Simulation

    cancel, shutdown
  • Field Details

    • DEFAULT_MAX_STEPS

      public static final int DEFAULT_MAX_STEPS
      Default safety cap on the number of steps (about 4.6 hours at the default rate).
      See Also:
    • DEFAULT_DEGREES_PER_STEP

      public static final float DEFAULT_DEGREES_PER_STEP
      Default animation-angle increment, in degrees, advanced per step.
      See Also:
    • DEFAULT_STEP_SLEEP_MS

      public static final long DEFAULT_STEP_SLEEP_MS
      Default self-paced delay between steps, in milliseconds.
      See Also:
  • Constructor Details

    • LogoSimulation

      public LogoSimulation()
      Construct the logo-spin simulation with the default rate.
    • LogoSimulation

      public LogoSimulation(float degreesPerStep, long stepSleepMs)
      Construct the logo-spin simulation with an explicit rate.
      Parameters:
      degreesPerStep - animation-angle increment, in degrees, per step
      stepSleepMs - milliseconds to sleep at the start of each step, so the simulation thread self-paces instead of busy-spinning
  • Method Details

    • setEngine

      public void setEngine(edu.cnu.mdi.sim.SimulationEngine engine)
      Attach the engine so this simulation can post messages and request refreshes.
      Parameters:
      engine - the simulation engine, possibly null
    • setMaxSteps

      public void setMaxSteps(int maxSteps)
      Set a safety cap on the number of steps.
      Parameters:
      maxSteps - maximum number of steps; values less than 1 are promoted to 1
    • takePendingDelta

      public float takePendingDelta()
      Take the animation-angle increment accumulated since the last call and reset the accumulator to zero.

      Intended to be called only from an EDT-marshaled onSimulationRefresh hook; the increment side runs on the simulation thread in step. Both sides share lock so a refresh can never observe a torn (partially-added) accumulation.

      Returns:
      the accumulated animation-angle increment, in degrees, since the previous call
    • init

      public void init(edu.cnu.mdi.sim.SimulationContext ctx) throws Exception
      Specified by:
      init in interface edu.cnu.mdi.sim.Simulation
      Throws:
      Exception
    • step

      public boolean step(edu.cnu.mdi.sim.SimulationContext ctx) throws Exception
      Specified by:
      step in interface edu.cnu.mdi.sim.Simulation
      Throws:
      Exception