• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Is 'Pan Camera (Timed)' safe?

Status
Not open for further replies.
Level 9
Joined
Jul 30, 2018
Messages
445
Hey!

Sorry, if this has been asked a lot, but I couldn't find a simple answer. I keep reading that panning camera can cause desync, so (at least) 'Pan Camera as Necessary (Timed)' should never be used, but is it different from just 'Pan Camera (Timed)'? Or are these both off limits?

I also read that the desync is caused because all players have different coordinates for their own camera, so is it then safe to pan each player's camera individually?

I'm not really planning on any fancy camera tricks, I just want to pan it on different units from time to time...
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
This is Pan Camera As Necessary:
JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
       // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
           // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
           // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
           // User is close enough, so don't touch the camera.
        endif
    endif
endfunction
This is Pan Camera (Timed):
JASS:
function PanCameraToTimedLocForPlayer takes player whichPlayer, location loc, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
       // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
    endif
endfunction
This is my understanding of the difference, someone correct me if I'm wrong. They are nearly identical functions with a difference in if statements, but the bugger of a problem is this line: GetCameraTargetPositionLoc(). Since that part of the code only executes for 1 player (and not on all players' machines), it locally creates a location (handle) and thus increases the handle counter for only that 1 player. This changes subsequent handle IDs for all new objects and if the handle ID of one of those new objects is referenced in code it will desync the game.

You can use Pan Camera (Timed) all you want.
 
Status
Not open for further replies.
Top