- Joined
- Jul 10, 2007
- Messages
- 6,306
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
set threadSyncer = CreateUnit(Player(0), UNIT_SYNC_ID, 999999, 999999, 0) doesn't work as the same as your code ?Troll-Brain, yours has mass syncs for each integer. It may be viable for syncing booleans, but I think that a near instant sync of 2500 32 bit integers trumps 32*2500 syncs of the same amount of data using unit selections (each sync also having an associated firing trigger). And yes, I am talking about syncing -(2^31) 2500 times >;o, all 32 bits filled rawr.
library Thread /* v1.0.0.0
*************************************************************************************
*
* This script allows one to sync up threads between players. It is most useful for
* preventing players from desyncing due to heavy local code blocks as well as syncing
* up large streams of data.
*
************************************************************************************
*
* SETTINGS
*/
globals
/*
* This unit can be retrieved from the map attached to this thread. Copy and paste
* the unit in the map into target map and then put the unit type id of that unit here.
*/
private constant integer UNIT_SYNC_ID = 'h001'
endglobals
/*
************************************************************************************
*
* struct Thread
*
* readonly boolean synced
* - Loop until this is true
*
* static method create takes nothing returns Thread
* method destroy takes nothing returns nothing
*
* method sync takes nothing returns nothing
* - Call from local player when that local player's operation is complete
*
* Examples
*
* local Thread thread = Thread.create()
*
* loop
* if (GetLocalPlayer() == targetPlayer) then
* //the hefty operation here should segment how much it does per iteration
* //too much per iteration and slower computers will desync from the sheer magnitude
* //of the operation
* //this will have to be fine tuned based on the size of the operation
* if (doHeftyOperation()) then
* call thread.sync()
* endif
* endif
*
* call TriggerSyncReady()
* exitwhen thread.synced
* endloop
*
* call thread.destroy()
*
*************************************************************************************/
struct Thread
private unit threadSyncer
private static trigger syncThreadTrigger
readonly boolean synced
static method create takes nothing returns thistype
local thistype this = allocate()
if threadSyncer == null then
static if LIBRARY_UnitIndexer then
set UnitIndexer.enabled = false
endif
set threadSyncer = CreateUnit(Player(0), UNIT_SYNC_ID, WorldBounds.maxX, WorldBounds.maxY, 0)
call SetUnitUserData(threadSyncer, this)
call PauseUnit(threadSyncer, true)
call SetUnitPosition(threadSyncer, 99999, 99999)
call TriggerRegisterUnitEvent(syncThreadTrigger, threadSyncer, EVENT_UNIT_SELECTED)
static if LIBRARY_UnitIndexer then
set UnitIndexer.enabled = true
endif
endif
return this
endmethod
method destroy takes nothing returns nothing
set synced = false
call deallocate()
endmethod
/*
* Call within a local block
*/
method sync takes nothing returns nothing
call SelectUnit(threadSyncer, true)
call SelectUnit(threadSyncer, false)
endmethod
private static method syncThread takes nothing returns boolean
local thistype this = GetUnitUserData(GetTriggerUnit())
set synced = true
return false
endmethod
/*
* Struct Initialization
*/
private static method onInit takes nothing returns nothing
set syncThreadTrigger = CreateTrigger()
call TriggerAddCondition(syncThreadTrigger, Filter(function thistype.syncThread))
endmethod
endstruct
endlibrary
Can you give an example situation where this might be useful?
Hmm, I'm very confused about this resource. I don't quite get why you would need that or even what it exactly does?
Can you give an example situation where this might be useful?
Wasn't meant as an offense ... I just don't know when you would have "heavy local blocks" that desync... usually all stuff you do locally is fast as hell anyway. Don't know. Maybe its interesting for your external data read stuff. Can't really think of a situation.if you don't know where it would be useful, then you personally have no use for it =)
I already explained where it would be useful in the docs. If you don't understand, go study more JASS =).
It's funny how you keep to avoid the question.
Basically we are asking for a concrete example of usage.
Give a map where you would need to sync hundred of integers.
There is no need to test this. I have already tested it and use it for perfect data synchronization.
It works.
lol.
It is possible to add a 13th unit to the selection by triggers.
I was expecting to see some code and something to actually test the system =o
I guess I'll write that myself.
* */uses/*
*
* * Alloc * hiveworkshop.com/forums/jass-resources-412/snippet-alloc-192348/
* */ WorldBounds /* hiveworkshop.com/forums/jass-resources-412/snippet-worldbounds-180494/
struct Test extends array
implement I
endstruct
module I
endmodule
