Package com.jme3.app.state
Class ConstantVerifierState
java.lang.Object
com.jme3.app.state.BaseAppState
com.jme3.app.state.ConstantVerifierState
- All Implemented Interfaces:
AppState
An AppState that periodically checks the values of various JME math constants
(e.g., `Vector3f.ZERO`, `Quaternion.IDENTITY`) against their known good values.
This is useful for detecting accidental modifications or "drift" of these
supposedly immutable constants during application runtime.
The state can be configured to report discrepancies using asserts, throwing runtime exceptions, or logging severe messages. The set of constants to check is configurable.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Defines how constant value discrepancies should be reported. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a verifier app state that will check all of the default JME math constants using `ErrorType.Assert`.Creates a verifier app state that will check all of the default JME math constants using the specified error reporting mechanism. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChecker
(Object constant, Object goodValue) Adds a new constant and its expected good value to the list of items to be checked.protected void
Iterates through all registered checkers and verifies the current values of the constants against their known good values.protected void
cleanup
(Application app) Called after the app state is detached or during application shutdown if the state is still attached.Returns the currently configured error reporting mechanism.protected void
initialize
(Application app) Called during initialization once the app state is attached and before onEnable() is called.protected void
Called when the state was previously enabled but is now disabled either because setEnabled(false) was called or the state is being cleaned up.protected void
onEnable()
Called when the state is fully enabled, ie: is attached and isEnabled() is true or when the setEnabled() status changes after the state is attached.void
Called after all rendering commands are flushed.void
setErrorType
(ConstantVerifierState.ErrorType errorType) Sets the error reporting mechanism to be used when a constant's value drifts.Methods inherited from class com.jme3.app.state.BaseAppState
cleanup, getApplication, getId, getState, getState, getState, getState, getStateManager, initialize, isEnabled, isInitialized, render, setEnabled, setId, stateAttached, stateDetached, update
-
Constructor Details
-
ConstantVerifierState
public ConstantVerifierState()Creates a verifier app state that will check all of the default JME math constants using `ErrorType.Assert`. -
ConstantVerifierState
Creates a verifier app state that will check all of the default JME math constants using the specified error reporting mechanism.- Parameters:
errorType
- The mechanism to use when a constant's value drifts.
-
-
Method Details
-
addChecker
Adds a new constant and its expected good value to the list of items to be checked. The `constant` and `goodValue` should be instances of the same class.- Parameters:
constant
- The JME constant object to monitor for drift (e.g., `Vector3f.ZERO`).goodValue
- An independent instance representing the expected correct value of the constant. This instance should match the initial value of `constant`.
-
setErrorType
Sets the error reporting mechanism to be used when a constant's value drifts.- Parameters:
errorType
- The desired error reporting type.
-
getErrorType
Returns the currently configured error reporting mechanism.- Returns:
- The current `ErrorType`.
-
initialize
Description copied from class:BaseAppState
Called during initialization once the app state is attached and before onEnable() is called.- Specified by:
initialize
in classBaseAppState
- Parameters:
app
- the application
-
cleanup
Description copied from class:BaseAppState
Called after the app state is detached or during application shutdown if the state is still attached. onDisable() is called before this cleanup() method if the state is enabled at the time of cleanup.- Specified by:
cleanup
in classBaseAppState
- Parameters:
app
- the application
-
onEnable
protected void onEnable()Description copied from class:BaseAppState
Called when the state is fully enabled, ie: is attached and isEnabled() is true or when the setEnabled() status changes after the state is attached.- Specified by:
onEnable
in classBaseAppState
-
onDisable
protected void onDisable()Description copied from class:BaseAppState
Called when the state was previously enabled but is now disabled either because setEnabled(false) was called or the state is being cleaned up.- Specified by:
onDisable
in classBaseAppState
-
postRender
public void postRender()Description copied from interface:AppState
Called after all rendering commands are flushed. This method will be called every render pass if theAppState
is both attached and enabled.- Specified by:
postRender
in interfaceAppState
- Overrides:
postRender
in classBaseAppState
-
checkValues
protected void checkValues()Iterates through all registered checkers and verifies the current values of the constants against their known good values. Reports any discrepancies based on the configured `ErrorType`.
-