saw792
Is known to say things. That is all.
- Reaction score
- 280
I'm working on a system to detect mouse scrolls using changes in the camera of each player. Naturally this is local data so it must be synced. The Sync library below is based on TSync by Toadcop.
Sync Library:Scroll Library:
Despite my syncing efforts it's still desyncing, although not on the first event fire (usually the second or third). I'm having trouble figuring out what could be causing it as the local variables are all 'globalised' correctly. It's possible that the SetUnitOwner() call being run locally from the SyncInt() function is causing issues but other than a dodgy timer there seems to be no way to stop calling it locally from the Scroll library (as I only want it to sync when the event fires for a player).
Any tips/things I'm forgetting to sync that you can see would be helpful.
Please don't post things like 'Check GetLocalPlayer() blocks' lest you face my wrath
Thanks
Sync Library:
JASS:
library Sync initializer Init
globals
private integer DATA = 0
private player P = null
private trigger T = CreateTrigger()
private unit array U
private string ZERO = "Z"
private integer ZEROABIL = 039;A000039;
private string ONE = "X"
private integer ONEABIL = 039;A001039;
private integer TOSYNC = 0
private integer DUMMYID = 039;h00E039;
private group SELECTED = CreateGroup()
private boolexpr FILTER
endglobals
private function Filt takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) != DUMMYID
endfunction
function SyncInt takes integer i, player p returns nothing
call GroupEnumUnitsSelected(SELECTED, GetLocalPlayer(), FILTER)
if GetLocalPlayer() == p then
set TOSYNC = i
call ClearSelection()
call SelectUnit(U[GetPlayerId(p)], true)
endif
endfunction
function GetSyncedInt takes nothing returns integer
return DATA
endfunction
function GetSyncedPlayer takes nothing returns player
return P
endfunction
function SyncAddCallback takes boolexpr callback returns nothing
call TriggerAddCondition(T, callback)
endfunction
private function SyncFinish takes nothing returns boolean
if GetSpellAbilityId() == ZEROABIL then
set DATA = 0
elseif GetSpellAbilityId() == ONEABIL then
set DATA = 1
endif
set P = GetOwningPlayer(GetTriggerUnit())
return true
endfunction
private function SyncHandler takes nothing returns boolean
if TOSYNC == 1 then
call ForceUIKey(ONE)
else
call ForceUIKey(ZERO)
endif
call ClearSelection()
call ForGroup(SELECTED, function SelectGroupBJEnum)
call GroupClear(SELECTED)
return false
endfunction
private function Init takes nothing returns nothing
local integer i = 11
set FILTER = Condition(function Filt)
loop
set U<i> = CreateUnit(Player(i), DUMMYID, 0, 0, 0)
if GetLocalPlayer() == Player(i) then
call TriggerRegisterUnitEvent(T, U<i>, EVENT_UNIT_SELECTED)
endif
exitwhen i == 0
set i = i - 1
endloop
call TriggerAddCondition(T, Condition(function SyncHandler))
set T = CreateTrigger()
loop
exitwhen i == 12
call TriggerRegisterUnitEvent(T, U<i>, EVENT_UNIT_SPELL_CAST)
set i = i + 1
endloop
call TriggerAddCondition(T, Condition(function SyncFinish))
endfunction
endlibrary</i></i></i>
JASS:
library Scroll initializer Init requires Sync, Event
globals
private real PERIOD = 0.02
endglobals
globals
private real DEFAULT_DISTANCE = 0
private camerasetup CAMSETUP = CreateCameraSetup()
private integer array PLAYERFIRE
private Event E
private boolean array B
endglobals
function TriggerRegisterPlayerScrollEvent takes trigger t, player p returns nothing
set E.register(t).data = GetPlayerId(p)
endfunction
function GetScrollingPlayer takes nothing returns player
return Player(E.getTriggeringEventReg().data)
endfunction
private function Fire takes nothing returns boolean
local integer i = GetPlayerId(GetSyncedPlayer())
set PLAYERFIRE<i> = GetSyncedInt()
call BJDebugMsg(I2S(PLAYERFIRE<i>))
if PLAYERFIRE<i> != 0 then
set PLAYERFIRE<i> = 0
set B<i> = true
call E.fire()
endif
return true
endfunction
private function Detect takes nothing returns nothing
local integer i = 11
loop
if GetLocalPlayer() == Player(i) then
if GetCameraField(CAMERA_FIELD_TARGET_DISTANCE) != DEFAULT_DISTANCE then
call CameraSetupApply(CAMSETUP, false, false)
set PLAYERFIRE<i> = PLAYERFIRE<i> + 1
if B<i> then
call SyncInt(PLAYERFIRE<i>, Player(i))
set B<i> = false
endif
endif
endif
exitwhen i == 0
set i = i - 1
endloop
endfunction
private function Init takes nothing returns nothing
local integer i = 11
set E = Event.create()
call SyncAddCallback(Condition(function Fire))
loop
set PLAYERFIRE<i> = 0
set B<i> = true
exitwhen i == 0
set i = i - 1
endloop
set DEFAULT_DISTANCE = GetCameraField(CAMERA_FIELD_TARGET_DISTANCE)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_TARGET_DISTANCE, DEFAULT_DISTANCE, 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_FARZ, GetCameraField(CAMERA_FIELD_FARZ), 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_ZOFFSET, GetCameraField(CAMERA_FIELD_ZOFFSET), 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_ANGLE_OF_ATTACK, bj_RADTODEG * GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK), 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_FIELD_OF_VIEW, bj_RADTODEG * GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW), 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_ROLL, bj_RADTODEG * GetCameraField(CAMERA_FIELD_ROLL), 0)
call CameraSetupSetField(CAMSETUP, CAMERA_FIELD_ROTATION, bj_RADTODEG * GetCameraField(CAMERA_FIELD_ROTATION), 0)
call TimerStart(CreateTimer(), PERIOD, true, function Detect)
endfunction
endlibrary</i></i></i></i></i></i></i></i></i></i></i></i>
Despite my syncing efforts it's still desyncing, although not on the first event fire (usually the second or third). I'm having trouble figuring out what could be causing it as the local variables are all 'globalised' correctly. It's possible that the SetUnitOwner() call being run locally from the SyncInt() function is causing issues but other than a dodgy timer there seems to be no way to stop calling it locally from the Scroll library (as I only want it to sync when the event fires for a player).
Any tips/things I'm forgetting to sync that you can see would be helpful.
Please don't post things like 'Check GetLocalPlayer() blocks' lest you face my wrath
Thanks