Class GameLogic
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidBlocks until the current main-loop iteration releases game-state access, then immediately releases it again.static voidstatic voidcheckClientThread(String operation) Throws if the current thread does not have game-state access.static voidenter()Marks the start of a native main-loop iteration and gives the client thread exclusive game-state access.static voidexit()Marks the end of a native main-loop iteration and releases one level of client-thread game-state access.static ThreadReturns the last thread observed entering the native main loop.static booleanReturns whether the current thread can safely access game state right now.static booleanReturns whether the current thread is the native client/main-loop thread.static booleanReturns whether the client thread is currently inside a main-loop iteration.static GameLogic.ClientAccessBlocks until exclusive game-state access is available.static GameLogic.ClientAccessPauseTemporarily releases all client-access holds owned by the current non-client thread, then restores them when the returned handle is closed.static GameLogic.ClientAccessAttempts to acquire exclusive game-state access without waiting.static booleantryWithIdleAccess(Runnable runnable) Attempts to run the supplied action with exclusive game-state access without waiting.static voidwithIdleAccess(Runnable runnable) Blocks until exclusive game-state access is available and runs the supplied action while holding it.static <T> TwithIdleAccess(Callable<T> callable) Blocks until exclusive game-state access is available and runs the supplied callable while holding it.
-
Constructor Details
-
GameLogic
public GameLogic()
-
-
Method Details
-
bind
-
enter
public static void enter()Marks the start of a native main-loop iteration and gives the client thread exclusive game-state access.This is intended for the main-loop hook only. Calls to this method must be paired with
exit()on the same thread. -
exit
public static void exit()Marks the end of a native main-loop iteration and releases one level of client-thread game-state access.This is intended for the main-loop hook only. It is tolerant of being called from a thread that does not currently hold the lock.
-
lockClientAccess
Blocks until exclusive game-state access is available.Use this for active script logic or required operations that must run with a consistent client snapshot. Avoid using it from optional services, telemetry, passive scripts, or the EDT, because queued callers can stall the next main-loop iteration.
- Returns:
- an access handle that must be closed by the caller
-
tryLockClientAccess
Attempts to acquire exclusive game-state access without waiting.Use this for opportunistic work such as passive scripts, telemetry, debug panels, and other tasks that can skip a pass when the client is busy.
- Returns:
- an access handle that must be closed by the caller, or
nullif access is currently unavailable
-
isClientThread
public static boolean isClientThread()Returns whether the current thread is the native client/main-loop thread.Client-thread code already has game-state access while inside the main-loop hook and should not block waiting for the lock again.
-
hasClientAccess
public static boolean hasClientAccess()Returns whether the current thread can safely access game state right now.This is true for the client thread and for non-client threads that currently hold
lockClientAccess()ortryLockClientAccess(). -
pauseClientAccess
Temporarily releases all client-access holds owned by the current non-client thread, then restores them when the returned handle is closed.Use this around blocking waits or sleeps inside code that already holds client access. This prevents a script from sleeping while holding the main game-state lock.
- Returns:
- a pause handle that must be closed to restore the previous hold count
-
isProcessing
public static boolean isProcessing()Returns whether the client thread is currently inside a main-loop iteration. -
getClientThread
Returns the last thread observed entering the native main loop. -
checkClientThread
Throws if the current thread does not have game-state access.Use this as a guard in low-level getters/setters that directly touch native client state.
- Parameters:
operation- a short name for the operation being guarded
-
awaitIdle
public static void awaitIdle()Blocks until the current main-loop iteration releases game-state access, then immediately releases it again.Use this only when the caller needs a synchronization point with the client loop and does not need to inspect state. Prefer
withIdleAccess(Runnable)if work must be performed while access is held. -
withIdleAccess
Blocks until exclusive game-state access is available and runs the supplied action while holding it.Use this for required short reads/writes from background threads. Keep the action small and never sleep or perform network/disk/UI work inside it. Optional callers should prefer
tryWithIdleAccess(Runnable).- Parameters:
runnable- work to run with client access
-
tryWithIdleAccess
Attempts to run the supplied action with exclusive game-state access without waiting.Use this for optional or repeatable work that can safely be skipped when the client is busy, such as telemetry, passive scripts, and debug snapshots.
- Parameters:
runnable- work to run if access is immediately available- Returns:
trueif the action ran, otherwisefalse
-
withIdleAccess
Blocks until exclusive game-state access is available and runs the supplied callable while holding it.Use this for required short reads that return a value. Keep the callable small and never sleep or perform network/disk/UI work inside it.
- Type Parameters:
T- the returned value type- Parameters:
callable- work to run with client access- Returns:
- the callable result
-