[Solved] Get player's current camera location?

Level 8
Joined
Aug 27, 2012
Messages
348
Can you provide an example of using it without GetLocalPlayer()? Doesn't seem possible from what I can see in the blizzard.j, as it doesn't have a player parameter(which usually means GetLocalPlayer is needed):

JASS:
constant native GetCameraTargetPositionX takes nothing returns real
 
If it would take a player paramter, this would mean it returns synchronous value, which is the same for all players.

For example:
set x = GetCameraTargetPositionX(Player_1)

^Now "x" has the value of Player_1's current x of his cam, and this "x" has now the same value for all players (globaly)

But now we don't have any player parameter:
set x = GetCameraTargetPositionX()

^Now, this means, the "x" is set localy for each client/player, and players have different values for "x". The value is asynchronous.

====

You use "If player == GetLocalPlayer()" ... to achieve asynchronous values or to execute operations client-specific, but in this case we already have async values.

GetCameraTargetPositionX will return Player_1's cam x for Player_1
and
GetCameraTargetPositionX will return Player_2's cam x for Player_2
...

all players will get their own cam "x" value.

====

The "problem" you may have is if you want to work with those values with all players, like for example you want that player_2 knows the "x" from player_1, or something alike.
Then you need to get this asynchronous value from player_1 and sync it for all players, so it gets the same value so it may be read properly.

Example:

if GetLocalPlayer() == Player_Blue then
---- set x_Player_Blue = GetCameraTargetPositionX()
endif

^Now "x_Player_Blue" was only assigned for Player_Blue and it has his own local x value.
Now we need to sync this "x_Player_Blue", so it gets the same value for all players, and then we may do something like "Move Player_1's cam to (x_Player_Blue, 0)" etc.
There are sync systems that might be used.
 
Level 8
Joined
Aug 27, 2012
Messages
348
I don't think I'm doing anything that can cause a desync, I'm basically getting the camera position so that I can adjust the camera height for the player if their camera is in certain regions that I specify, due to the wildly varying terrain heights in my map. I haven't tested my code, but as I'm not doing anything asynchronous, there should be no desync issues.

JASS:
scope UpdateCamHeight initializer OnInit

private function CB takes nothing returns nothing
local real x
local real y
local boolean b = false

    if GetLocalPlayer() == GetEnumPlayer() then
        set x = GetCameraTargetPositionX()
        set y = GetCameraTargetPositionY()
    
        if ((GetRectMinX(gg_rct_Normal_Area) <= x) and (x <= GetRectMaxX(gg_rct_Normal_Area)) and (GetRectMinY(gg_rct_Normal_Area) <= y) and (y <= GetRectMaxY(gg_rct_Normal_Area))) or ((GetRectMinX(gg_rct_Normal_Area_2) <= x) and (x <= GetRectMaxX(gg_rct_Normal_Area_2)) and (GetRectMinY(gg_rct_Normal_Area_2) <= y) and (y <= GetRectMaxY(gg_rct_Normal_Area_2))) or ((GetRectMinX(gg_rct_Normal_Area_3) <= x) and (x <= GetRectMaxX(gg_rct_Normal_Area_3)) and (GetRectMinY(gg_rct_Normal_Area_3) <= y) and (y <= GetRectMaxY(gg_rct_Normal_Area_3))) then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,2250.,.1)
        set b = true
        endif
    
        if not b and (GetRectMinX(gg_rct_Lake_Settlement) <= x) and (x <= GetRectMaxX(gg_rct_Lake_Settlement)) and (GetRectMinY(gg_rct_Lake_Settlement) <= y) and (y <= GetRectMaxY(gg_rct_Lake_Settlement)) then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,3600.,.1)
        set b = true
        endif
    
        if not b and (GetRectMinX(gg_rct_Mountain_Pass) <= x) and (x <= GetRectMaxX(gg_rct_Mountain_Pass)) and (GetRectMinY(gg_rct_Mountain_Pass) <= y) and (y <= GetRectMaxY(gg_rct_Mountain_Pass)) then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,3000.,.1)
        set b = true
        endif
    
        if not b and (GetRectMinX(gg_rct_Mountain_Area) <= x) and (x <= GetRectMaxX(gg_rct_Mountain_Area)) and (GetRectMinY(gg_rct_Mountain_Area) <= y) and (y <= GetRectMaxY(gg_rct_Mountain_Area)) then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,3000.,.1)
        set b = true
        endif
    
        if not b then
        call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE,2250.,.1)
        endif
    endif
 
endfunction

private function Handler takes nothing returns nothing
    call ForForce(bj_FORCE_ALL_PLAYERS,function CB)
endfunction

private function OnInit takes nothing returns nothing
local integer i = 0
    call TimerStart(NewTimer(),.03125,true,function Handler)
 
    loop
    exitwhen i == 12
    if GetLocalPlayer() == Player(i) then
        call SetCameraField(CAMERA_FIELD_FARZ,10000.,0.)
    endif
 
    set i = i + 1
    endloop
endfunction

endscope
 
Yep, seems so.

By the way, it seems you don't need/store cam values like Distance etc, into global variables, so you really only work localy.
->
This means you do this equaly for all players, and you won't need any loop, or any GetLocalPlayer() check; just do so once, and it will happen for each player, and for each player localy.

Example:
JASS:
loop
    exitwhen i == 12
    if GetLocalPlayer() == Player(i) then
        call SetCameraField(CAMERA_FIELD_FARZ,10000.,0.)
    endif
->
call SetCameraField(CAMERA_FIELD_FARZ,10000.,0.)

^Works for all players localy.
 
I don't think so because the "b" is only used for local operations; if you would do something like:

If b then
---- create unit
endif

^then it would be bad, because createunit is a action that affects the gameplay and all players. But local cam actions should not be relevant.

edit:

Async values alone don't cause desync, it depends what you do with them.
 
Level 8
Joined
Aug 27, 2012
Messages
348
What I mean is, if b returns true for player 1, then that means it will turn false at the end of the endif. Nothing in my code turns it to true again, so therefore it will break for the rest of the players, unless the code will run the code separately for every player, like an automatic ForForce(All Players)? In that case I can keep my locals?
 
Top