Class SimulationEngineConfig

java.lang.Object
edu.cnu.mdi.sim.SimulationEngineConfig

public final class SimulationEngineConfig extends Object
Configuration for SimulationEngine.

Intervals are used to rate-limit EDT events so the simulation thread can run fast while UI updates remain smooth and responsive.

  • Field Details

    • DEFAULT_REFRESH_INTERVAL_MS

      public static final int DEFAULT_REFRESH_INTERVAL_MS
      See Also:
    • DEFAULT_PROGRESS_INTERVAL_MS

      public static final int DEFAULT_PROGRESS_INTERVAL_MS
      See Also:
    • DEFAULT_COOPERATIVE_YIELD_MS

      public static final int DEFAULT_COOPERATIVE_YIELD_MS
      See Also:
    • DEFAULT_AUTO_RUN

      public static final boolean DEFAULT_AUTO_RUN
      See Also:
    • refreshIntervalMs

      public final int refreshIntervalMs
      Target interval for posting refresh events to the EDT (milliseconds).

      Typical values: 16 (~60 Hz), 33 (~30 Hz), 50 (~20 Hz). Use 0 to disable periodic refresh.

    • progressIntervalMs

      public final int progressIntervalMs
      Target interval for posting progress "ping" events to the EDT (milliseconds).

      This is a fallback heartbeat. Many simulations will call SimulationEngine.postProgress(ProgressInfo) directly for determinate progress. Use 0 to disable periodic progress pings. If your simulation is determinate, you can set this to a large value (e.g., 1000 ms) to get occasional progress updates without flooding the EDT, or set to 0 to disable entirely and rely on explicit progress posts.

    • cooperativeYieldMs

      public final int cooperativeYieldMs
      Cooperative-yield rate limit for the simulation thread (milliseconds).

      Important: this value is not interpreted as "sleep this long each step". Instead, it acts as a minimum wall-clock interval between opportunities for the engine to yield CPU time.

      The engine implements this by calling Thread.yield() at most once per cooperativeYieldMs. This is intentionally light-weight: using park/sleep in a tight simulation loop can deschedule the thread and incur OS timer granularity delays (often orders of magnitude larger than the requested duration), which can devastate performance.

      Use 0 to disable cooperative yielding for maximum throughput. If you need to intentionally reduce CPU usage, try small values such as 1–10 ms.

    • autoRun

      public final boolean autoRun
      Whether the engine should transition to RUNNING immediately after READY.

      If false, the engine will stop at READY until SimulationEngine.requestResume() (or SimulationEngine.requestRun()) is called.

  • Constructor Details

    • SimulationEngineConfig

      public SimulationEngineConfig(int refreshIntervalMs, int progressIntervalMs, int cooperativeYieldMs, boolean autoRun)
      Create a configuration.
      Parameters:
      refreshIntervalMs - refresh interval in milliseconds (0 disables periodic refresh)
      progressIntervalMs - progress interval in milliseconds (0 disables periodic progress ping)
      cooperativeYieldMs - minimum interval between cooperative yields in milliseconds (0 disables yielding)
      autoRun - if true, RUNNING starts immediately after READY
  • Method Details

    • defaults

      public static SimulationEngineConfig defaults()
      Reasonable defaults for interactive graphics.
      Returns:
      default config (refresh ~30 Hz, progress ~5 Hz, no yield, autoRun disabled)