public abstract class GameScriptingEngine
extends java.lang.Object
implements java.lang.Runnable
| Modifier and Type | Field and Description |
|---|---|
static org.mini2Dx.lockprovider.Locks |
LOCK_PROVIDER |
static GameScriptingEngine |
MOST_RECENT_INSTANCE
Returns the most recently created
GameScriptingEngine |
| Constructor and Description |
|---|
GameScriptingEngine()
Constructs a scripting engine backed by a thread pool with the maximum
amount of concurrent scripts set to 2.
|
GameScriptingEngine(boolean sandboxed)
Constructs a scripting engine backed by a thread pool with the maximum
amount of concurrent scripts set to the amount of processors + 1.
|
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
boolean sandboxed)
Constructs a scripting engine backed by a thread pool with the maximum
amount of concurrent scripts set to 2.
|
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
int maxConcurrentScripts)
Constructs a scripting engine backed by a thread pool.
|
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
int maxConcurrentScripts,
boolean sandboxed)
Constructs a scripting engine backed by a thread pool.
|
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider) |
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider,
boolean sandboxed) |
GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider,
ThreadPoolProvider threadPoolProvider,
boolean sandboxed) |
GameScriptingEngine(int maxConcurrentScripts)
Constructs a scripting engine backed by a thread pool.
|
GameScriptingEngine(int maxConcurrentScripts,
boolean sandboxed)
Constructs a scripting engine backed by a thread pool.
|
GameScriptingEngine(int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider) |
GameScriptingEngine(int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider,
boolean sandboxed) |
GameScriptingEngine(ThreadPoolProvider threadPoolProvider) |
GameScriptingEngine(ThreadPoolProvider threadPoolProvider,
boolean sandboxed) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelAllQueuedGameFutures()
Removes all currently queued
GameFutures without sending skipFuture event |
void |
cancelAllQueuedInteractiveScripts()
Clears all interactive scripts queued
|
void |
cancelAllQueuedInteractiveScripts(boolean notifyListeners)
Clears all interactive scripts queued
|
void |
cancelAllQueuedNonInteractiveScripts()
Clears all non-interactive scripts queued
|
void |
cancelAllQueuedNonInteractiveScripts(boolean notifyListeners)
Clears all non-interactive scripts queued
|
void |
cancelAllQueuedScripts()
Removes all currently queued
GameFutures without sending skipFuture event |
void |
cancelAllQueuedScripts(boolean notifyListeners)
Removes all currently queued
GameFutures without sending skipFuture event |
void |
cancelAllRunningGameFutures()
Removes all currently running
GameFutures without sending skipFuture event |
void |
cancelQueuedScript(int scriptId)
Removes all currently queued scripts with a given script ID
|
void |
cancelQueuedScript(int scriptId,
boolean notifyListeners)
Removes all currently queued scripts with a given script ID
|
void |
cancelQueuedScriptByTaskId(int taskId)
Removes a specific queued script by its task ID
|
void |
cancelQueuedScriptByTaskId(int taskId,
boolean notifyListeners)
Removes a specific queued script by its task ID
|
int |
compileScript(java.lang.String scriptContent)
Compiles a script for execution.
|
int |
compileScript(java.lang.String filepath,
java.io.InputStream inputStream)
Compiles a script for execution.
|
int |
compileScript(java.lang.String filepath,
java.lang.String scriptContent)
Compiles a script for execution.
|
protected abstract ScriptExecutorPool<?> |
createScriptExecutorPool(ClasspathScriptProvider classpathScriptProvider,
int poolSize,
boolean sandboxing) |
void |
dispose()
Shuts down the thread pool and cleans up resources
|
void |
dispose(boolean interruptScripts)
Shuts down the thread pool and cleans up resources
|
int |
getCompiledScriptId(java.lang.String filepath)
Returns the script ID for a given filepath
|
java.util.List<java.lang.String> |
getRunningScripts()
Returns the list of currently running scripts.
|
int |
getTotalInteractiveScriptsQueued()
Returns the total interactive scripts queued
|
int |
getTotalNonInteractiveScriptsQueued()
Returns the total non-interactive scripts queued
|
int |
getTotalScriptsQueued()
Returns the total scripts (interactive + non-interactive) queued
|
int |
invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings)
Queues a compiled script for execution in the engine's thread pool
|
int |
invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
Queues a compiled script for execution in the engine's thread pool
|
int |
invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority)
Queues a compiled script for execution in the engine's thread pool
|
int |
invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority,
boolean interactive)
Queues a compiled script for execution in the engine's thread pool
|
void |
invokeCompiledScriptSync(int taskId,
int scriptId,
ScriptBindings scriptBindings)
Executes a compiled script synchronously on the thread calling this method.
|
void |
invokeCompiledScriptSync(int taskId,
int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
Executes a compiled script synchronously on the thread calling this method.
|
int |
invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings)
Compiles and queues a script for execution in the engine's thread pool
|
int |
invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
Compiles and queues a script for execution in the engine's thread pool
|
int |
invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority)
Compiles and queues a script for execution in the engine's thread pool
|
abstract boolean |
isEmbeddedSynchronousScriptSupported()
Checks if scripts can be synchronously run within other scripts
|
boolean |
isInteractiveScriptRunning()
Returns true if interactive script is running
|
abstract boolean |
isSandboxingSupported()
Checks if sandboxing is supported by the
GameScriptingEngine
implementation |
void |
run()
This should not be invoked by the developer.
|
void |
setCancelReallocatedFutures(boolean cancelReallocatedFutures)
Sets if newly
GameFutures should cancel a previously scheduled
GameFuture with the same ID. |
void |
skipAllQueuedGameFutures()
Skips all currently queued
GameFutures |
void |
skipAllRunningGameFutures()
Skips all currently running
GameFutures |
void |
skipAllScripts()
Skips all currently running scripts
|
void |
skipOrCancelScript(int scriptId)
Cancels a queued script or skips it if it is currently running
|
void |
skipOrCancelScriptByTaskId(int taskId)
Cancels a specific invocation of a script by its task ID, or skips it if it is currently running
|
void |
skipScript(int scriptId)
Skips all running instances of a script
|
void |
skipScriptByTaskId(int taskId)
Skips a specific running instance of a script
|
void |
update(float delta)
Updates all
GameFutures |
public static GameScriptingEngine MOST_RECENT_INSTANCE
GameScriptingEnginepublic static org.mini2Dx.lockprovider.Locks LOCK_PROVIDER
public GameScriptingEngine()
public GameScriptingEngine(ThreadPoolProvider threadPoolProvider)
public GameScriptingEngine(int maxConcurrentScripts)
maxConcurrentScripts - The maximum amount of concurrently running scripts. WARNING:
this is a 'requested' amount and may be less due to the amount
of available processors on the player's machine.public GameScriptingEngine(int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider)
public GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, int maxConcurrentScripts)
classpathScriptProvider - The auto-generated ClasspathScriptProvider for the gamemaxConcurrentScripts - The maximum amount of concurrently running scripts. WARNING:
this is a 'requested' amount and may be less due to the amount
of available processors on the player's machine.public GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, int maxConcurrentScripts, ThreadPoolProvider threadPoolProvider)
public GameScriptingEngine(boolean sandboxed)
sandboxed - True if script sandboxing should be enabledpublic GameScriptingEngine(ThreadPoolProvider threadPoolProvider, boolean sandboxed)
public GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, boolean sandboxed)
classpathScriptProvider - The auto-generated ClasspathScriptProvider for the gamesandboxed - True if script sandboxing should be enabledpublic GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, ThreadPoolProvider threadPoolProvider, boolean sandboxed)
public GameScriptingEngine(int maxConcurrentScripts,
boolean sandboxed)
maxConcurrentScripts - The maximum amount of concurrently running scripts. WARNING:
this is a 'requested' amount and may be less due to the amount
of available processors on the player's machine.sandboxed - True if script sandboxing should be enabledpublic GameScriptingEngine(int maxConcurrentScripts,
ThreadPoolProvider threadPoolProvider,
boolean sandboxed)
public GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, int maxConcurrentScripts, boolean sandboxed)
classpathScriptProvider - The auto-generated ClasspathScriptProvider for the gamemaxConcurrentScripts - The maximum amount of concurrently running scripts. WARNING:
this is a 'requested' amount and may be less due to the amount
of available processors on the player's machine.sandboxed - True if script sandboxing should be enabledpublic GameScriptingEngine(ClasspathScriptProvider classpathScriptProvider, int maxConcurrentScripts, ThreadPoolProvider threadPoolProvider, boolean sandboxed)
public void dispose()
public void dispose(boolean interruptScripts)
interruptScripts - True if running scripts should be interruptedpublic abstract boolean isSandboxingSupported()
GameScriptingEngine
implementationpublic abstract boolean isEmbeddedSynchronousScriptSupported()
protected abstract ScriptExecutorPool<?> createScriptExecutorPool(ClasspathScriptProvider classpathScriptProvider, int poolSize, boolean sandboxing)
public void update(float delta)
GameFuturesdelta - The time (in seconds) since the last frame updatepublic void run()
update(float)
instead.run in interface java.lang.Runnablepublic void skipAllScripts()
public void skipScript(int scriptId)
scriptId - The ID of the script to skippublic void skipScriptByTaskId(int taskId)
taskId - The ID of the task to skippublic void skipAllRunningGameFutures()
GameFuturespublic void skipAllQueuedGameFutures()
GameFuturespublic void cancelAllRunningGameFutures()
GameFutures without sending skipFuture eventpublic void cancelAllQueuedGameFutures()
GameFutures without sending skipFuture eventpublic void cancelAllQueuedScripts()
GameFutures without sending skipFuture eventpublic void cancelAllQueuedScripts(boolean notifyListeners)
GameFutures without sending skipFuture eventnotifyListeners - If true will notify invocation listeners of script cancellationpublic void cancelQueuedScript(int scriptId)
public void cancelQueuedScriptByTaskId(int taskId)
public void cancelQueuedScript(int scriptId,
boolean notifyListeners)
notifyListeners - If true will notify invocation listeners of script cancellationpublic void cancelQueuedScriptByTaskId(int taskId,
boolean notifyListeners)
notifyListeners - If true will notify invocation listeners of script cancellationpublic void cancelAllQueuedInteractiveScripts()
public void cancelAllQueuedNonInteractiveScripts()
public void cancelAllQueuedInteractiveScripts(boolean notifyListeners)
notifyListeners - If true will send the scriptSkipped event any listener associated with a cancelled invokepublic void cancelAllQueuedNonInteractiveScripts(boolean notifyListeners)
notifyListeners - If true will send the scriptSkipped event any listener associated with a cancelled invokepublic void skipOrCancelScript(int scriptId)
scriptId - The script IDpublic void skipOrCancelScriptByTaskId(int taskId)
taskId - The task IDpublic int compileScript(java.lang.String filepath,
java.lang.String scriptContent)
throws InsufficientCompilersException
InsufficientCompilersException.
Note: If the filepath has already been compiled, the script will not be compiled and the previous compilation is used.filepath - The filepath to store for the scriptscriptContent - The text contents of the scriptInsufficientCompilersException - Thrown if there are no script compilers availableInsufficientCompilersException - Thrown if there are no script compilers availablepublic int compileScript(java.lang.String scriptContent)
throws InsufficientCompilersException
InsufficientCompilersException.scriptContent - The text contents of the scriptInsufficientCompilersException - Thrown if there are no script compilers availableInsufficientCompilersException - Thrown if there are no script compilers availablepublic int getCompiledScriptId(java.lang.String filepath)
filepath - The filepath to lookuppublic int compileScript(java.lang.String filepath,
java.io.InputStream inputStream)
throws InsufficientCompilersException,
java.io.IOException
InsufficientCompilersExceptioninputStream - The InputStream to read the script contents fromInsufficientCompilersException - Thrown if there are no script compilers availablejava.io.IOException - Throw if the InputStream could not be read or closedpublic int invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings)
scriptId - The id of the script to runscriptBindings - The variable bindings for the scriptpublic int invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
scriptId - The id of the script to runscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation
resultspublic int invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority)
scriptId - The id of the script to runscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation resultspriority - The script execution priority (higher value = higher priority)public int invokeCompiledScript(int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority,
boolean interactive)
scriptId - The id of the script to runscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation resultspriority - The script execution priority (higher value = higher priority)public int invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings)
throws InsufficientCompilersException
scriptContent - The text content of the scriptscriptBindings - The variable bindings for the scriptInsufficientCompilersException - Thrown if there are no script compilers availablepublic int invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
throws InsufficientCompilersException
scriptContent - The text content of the scriptscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation
resultsInsufficientCompilersException - Thrown if there are no script compilers availablepublic int invokeScript(java.lang.String scriptContent,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener,
int priority)
throws InsufficientCompilersException
scriptContent - The text content of the scriptscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation
resultspriority - The script execution priority (higher value = higher priority)InsufficientCompilersException - Thrown if there are no script compilers availablepublic void invokeCompiledScriptSync(int taskId,
int scriptId,
ScriptBindings scriptBindings)
ScriptExecutors are available this will block
until one is availabletaskId - The task idscriptId - The script idscriptBindings - The variable bindings for the scriptpublic void invokeCompiledScriptSync(int taskId,
int scriptId,
ScriptBindings scriptBindings,
ScriptInvocationListener invocationListener)
ScriptExecutors are available this will block
until one is availabletaskId - The task idscriptId - The script idscriptBindings - The variable bindings for the scriptinvocationListener - A ScriptInvocationListener to list for invocation
resultspublic java.util.List<java.lang.String> getRunningScripts()
public int getTotalScriptsQueued()
public int getTotalInteractiveScriptsQueued()
public int getTotalNonInteractiveScriptsQueued()
public boolean isInteractiveScriptRunning()
public void setCancelReallocatedFutures(boolean cancelReallocatedFutures)
GameFutures should cancel a previously scheduled
GameFuture with the same ID. IDs attempt be unique but if there
are GameFutures that never complete IDs may come into conflict
after millions of generated GameFutures. Defaults to true.cancelReallocatedFutures - True if existing GameFutures with same ID should be
cancelled