JPThread

JPThread

Execute a single function over several frames
Version : 2.0
Price : $20
State : Out

Changelog

v2.0

  • Now compatible with ShiVa 2.0.
  • Plugin API compiled for Mac and Linux in addition to Windows : it will provide API completion in the Script module in ShiVa Editor for each of these operating systems.
  • Now uses a user token instead of an email to activate

v1.2

  • Optimized for ShiVa 1.9.2

v1.1

  • JPThread.create now takes the parameters of the function.

API

--JPThread API JPThread.activate ( sUserToken, sActivationKey ) sID = JPThread.create ( fFunction, vOptParam0, vOptParam1, vOptParam2, vOptParam3, vOptParam4, vOptParam5, vOptParam6, vOptParam7, vOptParam8, vOptParam9, vOptParam10, vOptParam11, vOptParam12, vOptParam13, vOptParam14, vOptParam15 ) JPThread.addYieldPoint ( ) JPThread.cancel ( sID ) JPThread.pause ( sID ) JPThread.resume ( sID ) JPThread.cancelAllThreads ( ) JPThread.pauseAllThreads ( ) JPThread.resumeAllThreads ( )

Description

JPThread is another magic pack, allowing you to think your game conception in a new manner. It allows you to execute the code of a function over several frames.

JPThread.create ( this.preloadSceneResources )
function MyAIModel.preloadSceneResources ( ) for i = 0, table.getSize ( this.tTextures ( ) ) - 1 do local sTextute = table.getAt ( this.tTextures ( ), i ) application.forceResourceToStayLoaded ( sTexture, application.kResourceTypeTexture, true ) JPThread.addYieldPoint ( ) end end

As a result, the loading process will be executed over several frames, at a speed of 1 texture loading per frame. Your game execution will be much more fluid. JPThread.addYieldPoint ( ) mean the function execution pauses here and will start from here at the next frame. Of course, you can add this call several times in your function code.

Here is a screenshot of the Performance Reporter in ShiVa, you can see clearly that the function does not create a freeze at all as it is executed over several frames:

JPThread performance comparison This feature is also very useful in many other cases, think for instance how you currently load a file into the cache. Now, you will be able to do the whole process with a single function call:

function MyAIModel.loadFile ( sFile, sUrl ) cache.addFile ( sFile, sUrl ) while ( cache.getFileStatus ( sFile ) >= 0 and cache.getFileStatus ( sFile ) < 1 ) do JPThread.addYieldPoint ( ) end local nStatus = cache.getFileStatus ( sFile ) if ( nStatus == 1 ) then --Success else --Fail end end

This pack is really powerful.