Class LogoSimulation
- All Implemented Interfaces:
edu.cnu.mdi.sim.Simulation
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
FieldsModifier and TypeFieldDescriptionstatic final floatDefault animation-angle increment, in degrees, advanced per step.static final intDefault safety cap on the number of steps (about 4.6 hours at the default rate).static final longDefault self-paced delay between steps, in milliseconds. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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 TypeMethodDescriptionvoidinit(edu.cnu.mdi.sim.SimulationContext ctx) voidsetEngine(edu.cnu.mdi.sim.SimulationEngine engine) Attach the engine so this simulation can post messages and request refreshes.voidsetMaxSteps(int maxSteps) Set a safety cap on the number of steps.booleanstep(edu.cnu.mdi.sim.SimulationContext ctx) floatTake 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, waitMethods inherited from interface edu.cnu.mdi.sim.Simulation
cancel, shutdown
-
Field Details
-
DEFAULT_MAX_STEPS
public static final int DEFAULT_MAX_STEPSDefault 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_STEPDefault animation-angle increment, in degrees, advanced per step.- See Also:
-
DEFAULT_STEP_SLEEP_MS
public static final long DEFAULT_STEP_SLEEP_MSDefault 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 stepstepSleepMs- 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
onSimulationRefreshhook; the increment side runs on the simulation thread instep. Both sides sharelockso a refresh can never observe a torn (partially-added) accumulation.- Returns:
- the accumulated animation-angle increment, in degrees, since the previous call
-
init
- Specified by:
initin interfaceedu.cnu.mdi.sim.Simulation- Throws:
Exception
-
step
- Specified by:
stepin interfaceedu.cnu.mdi.sim.Simulation- Throws:
Exception
-