Beatmup Java package
Beatmup.Context Class Reference

Beatmup engine context. More...

Inheritance diagram for Beatmup.Context:
Beatmup.Object Beatmup.Android.Context

Public Member Functions

float performTask (Task task) throws CoreException
 Performs a given task in the main thread pool. More...
 
float performTask (Task task, int poolIndex) throws CoreException
 Performs a given task. More...
 
void repeatTask (Task task, boolean abortCurrent)
 Ensures a given task executed at least once. More...
 
void repeatTask (Task task, boolean abortCurrent, int poolIndex)
 Ensures a given task executed at least once in a specific thread pool. More...
 
int submitPersistentTask (Task task)
 Submits a persistent task in the main thread pool. More...
 
int submitPersistentTask (Task task, int poolIndex)
 Submits a persistent task in a specified thread pool. More...
 
void waitForJob (int job)
 Blocks until a given job in the main thread pool finishes. More...
 
void waitForJob (int job, int poolIndex)
 Blocks until a given job in the main thread pool finishes. More...
 
boolean abortJob (int job)
 Aborts a given submitted job. More...
 
boolean abortJob (int job, int poolIndex)
 Aborts a given submitted job. More...
 
void limitWorkerCount (int newCount)
 Sets maximum number of threads executing tasks in the main thread pool. More...
 
void limitWorkerCount (int newCount, int poolIndex)
 Sets maximum number of threads executing tasks in a given thread pool. More...
 
void check () throws CoreException
 Checks if the main thread pool is doing great: rethrows exceptions occurred during tasks execution, if any. More...
 
void check (int poolIndex) throws CoreException
 Checks if a specific thread pool is doing great: rethrows exceptions occurred during tasks execution, if any. More...
 
synchronized void dispose ()
 Destroys the native object. More...
 
Bitmap renderChessboard (int width, int height, int cellSize, PixelFormat pixelFormat)
 Renders a chessboard-like image. More...
 
Bitmap copyBitmap (Bitmap source, PixelFormat pixelFormat)
 Creates a copy of given bitmap. More...
 
IntPoint scanlineSearch (Bitmap bitmap, Color color, IntPoint start)
 Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color is met. More...
 
boolean isGPUQueried ()
 Tests whether the GPU was already queried. More...
 
boolean isGPUReady ()
 Tests whether the GPU was already queried and successfully initialized. More...
 
void recycleGPUGarbage ()
 Recycles GPU-managed resources that are ready to be disposed in a separate task. More...
 

Static Public Member Functions

static long getTotalRAMBytes ()
 

Static Public Attributes

static final IntPoint SCANLINE_SEARCH_NOT_FOUND = new IntPoint(-1, -1)
 Returned by Beatmup.Context.scanlineSearch() if no pixel of a specific color is found in the image. More...
 

Protected Member Functions

 Context (long handle)
 Creates a new context. More...
 
void watchBitmap (Bitmap bitmap)
 Adds a bitmap to the watch list. More...
 
synchronized void unwatchBitmap (Bitmap bitmap)
 Removes a bitmap from the watch list. More...
 

Additional Inherited Members

- Protected Attributes inherited from Beatmup.Object
long handle
 pointer to the native object More...
 

Detailed Description

Beatmup engine context.

Handles necessary data to interact with the engine through JNI layer

Definition at line 34 of file Context.java.

Constructor & Destructor Documentation

◆ Context()

Beatmup.Context.Context ( long  handle)
inlineprotected

Creates a new context.

Definition at line 219 of file Context.java.

219  {
220  super(handle);
221  eventListenerHandle = attachEventListener(handle);
222  bitmaps = new HashMap<>();
223  }
long handle
pointer to the native object
Definition: Object.java:25

Member Function Documentation

◆ performTask() [1/2]

float Beatmup.Context.performTask ( Task  task) throws CoreException
inline

Performs a given task in the main thread pool.

Parameters
taskThe task to run
Returns
execution time in ms.
Exceptions
CoreExceptionif the main thread pool has unprocessed exceptions thrown by previously executed tasks.

Definition at line 78 of file Context.java.

78  {
79  return performTask(handle, 0, task);
80  }

◆ performTask() [2/2]

float Beatmup.Context.performTask ( Task  task,
int  poolIndex 
) throws CoreException
inline

Performs a given task.

Parameters
taskThe task to run
poolIndexZero-based index of the thread pool to run the task in.
Returns
execution time in ms.
Exceptions
CoreExceptionif the thread pool has unprocessed exceptions thrown by previously executed tasks.

Definition at line 90 of file Context.java.

90  {
91  return performTask(handle, poolIndex, task);
92  }

◆ repeatTask() [1/2]

void Beatmup.Context.repeatTask ( Task  task,
boolean  abortCurrent 
)
inline

Ensures a given task executed at least once.

Parameters
taskthe task
abortCurrentif true and a task is running, the abort signal is sent.

Definition at line 100 of file Context.java.

100  {
101  repeatTask(handle, 0, task, abortCurrent);
102  }

◆ repeatTask() [2/2]

void Beatmup.Context.repeatTask ( Task  task,
boolean  abortCurrent,
int  poolIndex 
)
inline

Ensures a given task executed at least once in a specific thread pool.

Parameters
taskThe task
abortCurrentif true and a task is running, the abort signal is sent.
poolIndexIndex of the thread pool to run the task in

Definition at line 111 of file Context.java.

111  {
112  repeatTask(handle, poolIndex, task, abortCurrent);
113  }

◆ submitPersistentTask() [1/2]

int Beatmup.Context.submitPersistentTask ( Task  task)
inline

Submits a persistent task in the main thread pool.

Parameters
taskThe task
Returns
job index

Definition at line 121 of file Context.java.

121  {
122  return submitPersistentTask(handle, 0, task);
123  }

◆ submitPersistentTask() [2/2]

int Beatmup.Context.submitPersistentTask ( Task  task,
int  poolIndex 
)
inline

Submits a persistent task in a specified thread pool.

Parameters
taskThe task
poolIndexThread pool index
Returns
job index

Definition at line 132 of file Context.java.

132  {
133  return submitPersistentTask(handle, poolIndex, task);
134  }

◆ waitForJob() [1/2]

void Beatmup.Context.waitForJob ( int  job)
inline

Blocks until a given job in the main thread pool finishes.

Parameters
jobThe job

Definition at line 141 of file Context.java.

141  {
142  waitForJob(handle, 0, job);
143  }

◆ waitForJob() [2/2]

void Beatmup.Context.waitForJob ( int  job,
int  poolIndex 
)
inline

Blocks until a given job in the main thread pool finishes.

Parameters
jobThe job
poolIndexThread pool index

Definition at line 151 of file Context.java.

151  {
152  waitForJob(handle, poolIndex, job);
153  }

◆ abortJob() [1/2]

boolean Beatmup.Context.abortJob ( int  job)
inline

Aborts a given submitted job.

Parameters
jobThe job
Returns
true if the job was interrupted while running.

Definition at line 161 of file Context.java.

161  {
162  return abortJob(handle, 0, job);
163  }

◆ abortJob() [2/2]

boolean Beatmup.Context.abortJob ( int  job,
int  poolIndex 
)
inline

Aborts a given submitted job.

Parameters
jobThe job
poolIndexThread pool index
Returns
true if the job was interrupted while running.

Definition at line 172 of file Context.java.

172  {
173  return abortJob(handle, poolIndex, job);
174  }

◆ limitWorkerCount() [1/2]

void Beatmup.Context.limitWorkerCount ( int  newCount)
inline

Sets maximum number of threads executing tasks in the main thread pool.

Parameters
newCountthe new thread count limit

Definition at line 181 of file Context.java.

181  {
182  limitWorkerCount(handle, 0, newCount);
183  }

◆ limitWorkerCount() [2/2]

void Beatmup.Context.limitWorkerCount ( int  newCount,
int  poolIndex 
)
inline

Sets maximum number of threads executing tasks in a given thread pool.

Parameters
newCountthe new thread count limit
poolIndexindex of the thread pool

Definition at line 191 of file Context.java.

191  {
192  limitWorkerCount(handle, poolIndex, newCount);
193  }

◆ check() [1/2]

void Beatmup.Context.check ( ) throws CoreException
inline

Checks if the main thread pool is doing great: rethrows exceptions occurred during tasks execution, if any.

If no exception is thrown, the thread pool is okay.

Exceptions
CoreExceptionoccurred while running a task.

Definition at line 201 of file Context.java.

201  {
202  check(handle, 0);
203  }
void check()
Checks if the main thread pool is doing great: rethrows exceptions occurred during tasks execution,...
Definition: Context.java:201

◆ check() [2/2]

void Beatmup.Context.check ( int  poolIndex) throws CoreException
inline

Checks if a specific thread pool is doing great: rethrows exceptions occurred during tasks execution, if any.

If no exception is thrown, the thread pool is okay.

Parameters
poolIndexThe thread pool index
Exceptions
CoreExceptionoccurred while running a task.

Definition at line 212 of file Context.java.

212  {
213  check(handle, poolIndex);
214  }

◆ watchBitmap()

void Beatmup.Context.watchBitmap ( Bitmap  bitmap)
inlineprotected

Adds a bitmap to the watch list.

Parameters
bitmapthe new bitmap

Definition at line 230 of file Context.java.

230  {
231  synchronized (bitmaps) {
232  bitmaps.put(bitmap.handle, bitmap);
233  }
234  }

◆ unwatchBitmap()

synchronized void Beatmup.Context.unwatchBitmap ( Bitmap  bitmap)
inlineprotected

Removes a bitmap from the watch list.

Parameters
bitmapthe bitmap to remove

Definition at line 241 of file Context.java.

241  {
242  synchronized (bitmaps) {
243  bitmaps.remove(bitmap.handle);
244  }
245  }

◆ dispose()

synchronized void Beatmup.Context.dispose ( )
inline

Destroys the native object.

After the native object is destroyed, its Java counterpart likely becomes unusable.

Reimplemented from Beatmup.Object.

Reimplemented in Beatmup.Android.Context.

Definition at line 249 of file Context.java.

249  {
250  synchronized (bitmaps) {
251  for (Bitmap bitmap : bitmaps.values()) {
252  bitmap.dispose();
253  }
254  }
256  super.dispose();
257  detachEventListener(eventListenerHandle);
258  }
void recycleGPUGarbage()
Recycles GPU-managed resources that are ready to be disposed in a separate task.
Definition: Context.java:326

◆ renderChessboard()

Bitmap Beatmup.Context.renderChessboard ( int  width,
int  height,
int  cellSize,
PixelFormat  pixelFormat 
)
inline

Renders a chessboard-like image.

Parameters
widthoutput image width in pixels
heightoutput image height in pixels
cellSizechessboard cell size size in pixels
pixelFormatoutput image pixel format
Returns
image of chessboard with cells aligned with topleft corner

Definition at line 269 of file Context.java.

269  {
270  return new Bitmap(
271  this,
272  renderChessboard(handle, width, height, cellSize, pixelFormat.ordinal())
273  );
274  }

◆ copyBitmap()

Bitmap Beatmup.Context.copyBitmap ( Bitmap  source,
PixelFormat  pixelFormat 
)
inline

Creates a copy of given bitmap.

Parameters
sourcethe bitmap
pixelFormatpixel format of the copy
Returns
copy of the bitmap in the given pixel format

Definition at line 283 of file Context.java.

283  {
284  return new Bitmap(this, copyBitmap(source, pixelFormat.ordinal()));
285  }

◆ scanlineSearch()

IntPoint Beatmup.Context.scanlineSearch ( Bitmap  bitmap,
Color  color,
IntPoint  start 
)
inline

Goes through a bitmap in scanline order (left to right, top to bottom) until a pixel of a given color is met.

Parameters
bitmapthe bitmap to scan
colorthe color value to look for
startstarting pixel position
Returns
pixel position coming after the starting point in the scaline order, or SCANLINE_SEARCH_NOT_FOUND if no such pixel found till the end (right-bottom bitmap corner).

Definition at line 296 of file Context.java.

296  {
297  return scanlineSearchInt(bitmap.handle, start.x, start.y, color.r, color.g, color.b, color.a);
298  }

◆ isGPUQueried()

boolean Beatmup.Context.isGPUQueried ( )
inline

Tests whether the GPU was already queried.

Returns
true if the GPU was queried

Definition at line 309 of file Context.java.

309  {
310  return isGPUQueried(handle);
311  }
boolean isGPUQueried()
Tests whether the GPU was already queried.
Definition: Context.java:309

◆ isGPUReady()

boolean Beatmup.Context.isGPUReady ( )
inline

Tests whether the GPU was already queried and successfully initialized.

Returns
true if yes

Definition at line 318 of file Context.java.

318  {
319  return isGPUReady(handle);
320  }
boolean isGPUReady()
Tests whether the GPU was already queried and successfully initialized.
Definition: Context.java:318

◆ recycleGPUGarbage()

void Beatmup.Context.recycleGPUGarbage ( )
inline

Recycles GPU-managed resources that are ready to be disposed in a separate task.

Definition at line 326 of file Context.java.

326  {
328  }

◆ getTotalRAMBytes()

static long Beatmup.Context.getTotalRAMBytes ( )
inlinestatic
Returns
total size of RAM in bytes

Definition at line 334 of file Context.java.

334  {
335  return getTotalRam();
336  }

Member Data Documentation

◆ SCANLINE_SEARCH_NOT_FOUND

final IntPoint Beatmup.Context.SCANLINE_SEARCH_NOT_FOUND = new IntPoint(-1, -1)
static

Returned by Beatmup.Context.scanlineSearch() if no pixel of a specific color is found in the image.

Definition at line 341 of file Context.java.


The documentation for this class was generated from the following file: