Class SimulationEngineConfig
SimulationEngine.
Intervals are used to rate-limit EDT events so the simulation thread can run fast while UI updates remain smooth and responsive.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanWhether the engine should transition to RUNNING immediately after READY.final intCooperative-yield rate limit for the simulation thread (milliseconds).static final booleanstatic final intstatic final intstatic final intfinal intTarget interval for posting progress "ping" events to the EDT (milliseconds).final intTarget interval for posting refresh events to the EDT (milliseconds). -
Constructor Summary
ConstructorsConstructorDescriptionSimulationEngineConfig(int refreshIntervalMs, int progressIntervalMs, int cooperativeYieldMs, boolean autoRun) Create a configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic SimulationEngineConfigdefaults()Reasonable defaults for interactive graphics.
-
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 refreshIntervalMsTarget 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 progressIntervalMsTarget 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 cooperativeYieldMsCooperative-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 percooperativeYieldMs. This is intentionally light-weight: usingpark/sleepin 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 autoRunWhether the engine should transition to RUNNING immediately after READY.If false, the engine will stop at READY until
SimulationEngine.requestResume()(orSimulationEngine.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
Reasonable defaults for interactive graphics.- Returns:
- default config (refresh ~30 Hz, progress ~5 Hz, no yield, autoRun disabled)
-