Syncing issues + MouseScroll

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:
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 = 'A000'
    private string ONE = "X"
    private integer ONEABIL = 'A001'
    private integer TOSYNC = 0
    private integer DUMMYID = 'h00E'
    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>
Scroll Library:
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 :p

Thanks
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
JASS:
private real PERIOD = 0.02


You can't sync local data so fastly, use it each 1 second or so.
So in fact it can't be used like that.
 

saw792

Is known to say things. That is all.
Reaction score
280
Please read the code first. It doesn't sync every 0.02 seconds. It syncs only when the event actually occurs, and only when the previous occurence of the event has been synced already. I already stated that the actual data gets passed over correctly.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
When i worked on IsWar3Minimized i got a desync when i used GroupEnumUnitsSelected locally, it's the case here with SyncInt.
(Needs to be confirmed though, i've fixed the desync quickly)
 

saw792

Is known to say things. That is all.
Reaction score
280
Righto. How exactly did you fix the desync (or did you just remove the GroupEnum call)?

Hmm... could it have something to do with the filter function and boolexpr tables desyncronising? Not sure if that's possible.
 

saw792

Is known to say things. That is all.
Reaction score
280
Neither do I. I tested it with that line commented out, and no desync. I'm thinking the Sync library will need a SyncReady type function that does that.
 

saw792

Is known to say things. That is all.
Reaction score
280
Updated code, the SelectUnit was definitely causing a desync. It still desyncs however, just slightly later (only when the event is fired fairly quickly). Right now I'm still thinking it has something to do with the group (which I now realise will actually cause conflicts for multiple players as it isn't instant... but I'll fix that part later). Unfortunately I can only test it occasionally, so I've updated the code in case somebody else has an idea.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
ForceUI is lame, because it has delay, you can't call it many times in a short interval, it's not silent the player will notice it, plus it could be fucked up with a customkey.txt.
The only good thing seems to select dummies units, it's still not instant but the player can't notice it, but theoretically a player unit selection could be partially fucked up.

Currently i also need to sync local reals, i'm trying to use the gamecache which will be totally silent, but maybe slower.
If i win vs gamecache i will tell you, else i would submit a snippet with dummies units selection stuff anyway.
 

saw792

Is known to say things. That is all.
Reaction score
280
My syncing code is extremely quick, actually. About the same speed as an arroy key event, and much faster than gamecache syncing is.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
My syncing code is extremely quick, actually. About the same speed as an arroy key event, and much faster than gamecache syncing is.
But it doesn't work :p

Also i hate the ForceUI key thing since it's not silent, the user will notice it.
Even if the gamecache is slower i still prefer something totally silent.
But if we can't synch 12 local datas in less than 1 second (one for each player) with gamecache, then i will go with dummies units selection stuff.
 

saw792

Is known to say things. That is all.
Reaction score
280
It totally works... sortof not really...

Well the group isn't the problem. I'm totally depressed now :p
Still desyncs when group code is commented out.
 

saw792

Is known to say things. That is all.
Reaction score
280
I'm well aware I evaluate the trigger locally :p That's the entire point of the system, it wouldn't work otherwise. It's the same method used in TSync.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Finally i've made it with GameCache sync stuff.


JASS:
library SyncDatas initializer onInit

globals
    private trigger array Trig
    private gamecache array GC
    private timer array Tim
    private force Players
    private integer I
endglobals

private function Actions takes nothing returns nothing
    local integer i = I
    
    if GetLocalPlayer() == Player(i) then
        call StoreReal(GC[0],I2S(i),&quot;0&quot;,GetCameraTargetPositionX())
    endif
    call TriggerSyncStart()
    
    if GetLocalPlayer() == Player(i) then
        call SyncStoredReal(GC[0], I2S(i), &quot;0&quot;)
    endif

    call TriggerSyncReady()

    call BJDebugMsg(&quot;time elapsed == &quot; + R2S(TimerGetElapsed(Tim[0])))
    call BJDebugMsg(&quot;data of Player( &quot; + I2S(i) + &quot;) == &quot; + R2S(GetStoredReal(GC[0],I2S(i),&quot;0&quot;)))
    call BJDebugMsg(&quot; &quot;)
endfunction

private function Callback takes nothing returns nothing
    set I = GetPlayerId(GetEnumPlayer())
    call TriggerExecute(Trig<i>)
endfunction

private function DoTheSync takes nothing returns nothing
    call ForForce(Players,function Callback)
    call TimerStart(Tim[0],10.,false,null)
endfunction

private function onInit takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    
    call TriggerRegisterPlayerChatEvent(trig,Player(0),&quot;test&quot;,true)
    call TriggerAddAction(trig,function DoTheSync)
    set Players = CreateForce()
    set GC[0] = InitGameCache(SCOPE_PREFIX)
    set Tim[0] = CreateTimer()
    
    loop
    exitwhen i == 12
    
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER then
            call ForceAddPlayer(Players,Player(i))
            set Trig<i> = CreateTrigger()
            call TriggerAddAction(Trig<i>,function Actions)
            
        endif
    
    set i = i+1
    endloop
    

endfunction

endlibrary</i></i></i>


The needed time is about 0.5 s for 2 players and a good host.
It might be higher with a crappy connection and maybe also with more players.
Would be great if someone could test it with more players and a crappy host connection.

Ofc it's just a sample, not a snippet.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top