Snippet CameraPanEvent

quraji

zap
Reaction score
144
CameraPanEvent
v1.0​

This is a singleplayer ONLY snippet, until I can figure out how to make it work in multiplayer as well (without desynchs).

Requirements:
-Jass NewGen
-Event by Jesus4Lyf

What is it?
It's an event to detect when a player pans his camera :thup:

JASS:
// CameraPanEvent - by quraji - v1.01
//
// What is it?
//     This library adds a CameraPanEvent event that will fire
//     when a player pans his camera.
//
// How do I use it?
//     Use the provided functions:
//     
//     TriggerRegisterCameraPanEvent(trigger whichTrigger)
//         - this will register the CameraPan event to whichTrigger
//         Ex:
//         local trigger t = CreateTrigger()
//         call TriggerRegisterCameraPanEvent(t)
//         call TriggerAddAction(t, function DoStuffOnCameraPan)
//
//     GetCameraPanEventPlayer()
//         - this will return the player that fired the event
//
//     The only thing you need to configure is UPDATE_PERIOD below.

library CameraPanEvent initializer init requires Event

// CONFIG
globals
    private constant real UPDATE_PERIOD = .1 // how quickly the system will react to a pan event
endglobals
// ENDCONFIG


globals
    player CameraPanEventPlayer
    
    private timer T = CreateTimer()
    private Event e
    private real camX
    private real camY
endglobals

private function update takes nothing returns nothing
    local real x = GetCameraTargetPositionX()
    local real y = GetCameraTargetPositionY()
    if (camX!=x or camY!=y) then
        set CameraPanEventPlayer = GetLocalPlayer()
        call e.fire()
    endif
    set camX = x
    set camY = y
endfunction

private function init takes nothing returns nothing
    set e = Event.create()
    set camX = GetStartLocationX(GetPlayerStartLocation(GetLocalPlayer())) // so the event doesn't fire as soon as the game loads
    set camY = GetStartLocationY(GetPlayerStartLocation(GetLocalPlayer()))
    call TimerStart(T, UPDATE_PERIOD, true, function update)
endfunction

function GetCameraPanEventPlayer takes nothing returns player
    return CameraPanEventPlayer
endfunction

function TriggerRegisterCameraPanEvent takes trigger whichTrigger returns nothing
    call e.register(whichTrigger)
endfunction

endlibrary


Changelog (because changelogs are fun):
v1.10 - Edited this to work better with single player (until I can figure out how to make it work in multiplayer)
v1.01 - Fixed a bug that would cause desynchs, thanks to Troll-Brain for pointing it out EDIT: Nevermind, I can't fix it at the moment
v1.00 - Release

Notes:
Thanks to Jesus4Lyf for the submission template which I copied.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I guess it would desynch if users have different cameras, which must be true in all maps except ones where you can't change the position of the camera (i can't imagine a such map though).
Because GetCameraTargetPositionX/y can already return a different value for each pc, no need of GetLocalPlayer to get a local value.

Then a trigger could be executed locally -> desynch
 

quraji

zap
Reaction score
144
I guess it would desynch if users have different cameras, which must be true in all maps except ones where you can't change the position of the camera (i can't imagine a such map though).
Because GetCameraTargetPositionX/y can already return a different value for each pc, no need of GetLocalPlayer to get a local value.

Then a trigger could be executed locally -> desynch

Thanks for pointing that out, I totally overlooked that.

Edit: I thought I fixed it but on second thought I don't think I did....I'm confused.

Edit2: Are globals sync'd? Can I set a global boolean from a local block and have it be the same value across all computers? If not, how am I going to check the camera position and fire the event with desynching?
 

Azlier

Old World Ghost
Reaction score
461
Technically, just technically, you can make a working event without the slowness of gamecache syncing. However, you can't provide any event responses besides the triggering player.

No, globals are not synced. Yours still desyncs, too.
 

quraji

zap
Reaction score
144
>No, globals are not synced. Yours still desyncs, too.
Didn't think so. And thought so.

>Technically, just technically, you can make a working event without the slowness of gamecache syncing. However, you can't provide any event responses besides the triggering player.

Eh?
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I think he talked about select locally unit(s) in order to sync local datas, since the event will fire on all computer.
But for synchronise a local real, it's probably a bit over-skilled.
We would need several dummies units for each players (oh yeah an other use of putting units outside the map :cool:) and several selections/de-selections.

Hmm, one per player to determine which player data is synchronised sounds enough, one to end the synchronisation, and the others to sync the data by itself.

And even if the host use a delay reducer and have a great connection, it will still takes some time, or not ?
At least the needed time will be directly linked to the delay.
 

Viikuna

No Marlo no game.
Reaction score
265
I think Toadcop made some selectio syncing system a while back.
 

Azlier

Old World Ghost
Reaction score
461
>without desync or delay

Not possible. Pick one or the other.
 

quraji

zap
Reaction score
144
That's just plain disappointing. To have it work great, then learn of this horrible desynch problem that I overlooked...at least it works in singleplayer :p

Can someone explain this method to somehow sync this? I don't really understand the little snippets of info that have been said so far..
 
Reaction score
341
You save the values inside gamecache, then use the sync functions to make them all the same.

I believe thats how it works.
 

Viikuna

No Marlo no game.
Reaction score
265
I dont think instant syncing of local data is even possible.


But yea, gamecache can be used to sync data. I also managed to find Toadcops TSync, if anyone is interested.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
But gamecache can synch only the host data thought, or at least the one will respond the fastest.
 

Azlier

Old World Ghost
Reaction score
461
Just because it's amazing doesn't mean it has no delay. It is not possible.

Gamecache syncing has delay.
 

Viikuna

No Marlo no game.
Reaction score
265
But gamecache can synch only the host data thought, or at least the one will respond the fastest.

Unless you call that syncing native thingy with GetLocalPlayer, am I rite? Isnt that how they used to do cheats with those fake DotA maps?

edit. Yea. TSync isnt instant either. Theres always delay, so you just cant sync stuff like camera x/y for every .025 sec for some camera system or something..
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
0.025 sounds far way to the truth, it would be more something like 0.3 s at very least.

One day i would test the sync local selection stuff with a good host and a delay reducer.
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
This is my old system which I extracted from the thread "Critic this snippet, please".

Would this still desynch?!

JASS:
library TriggerRegisterPlayerMoveCameraEvent initializer init

    globals
        private constant real PERIOD = 0.03215
        
        private trigger array Trigs
        private integer array wichP
        private real array prevX
        private real array prevY
        private integer Stack = 0
        
        private player TheMoving
    endglobals
    
    private function returnX takes player p returns real
        if GetLocalPlayer() == p then
            return GetCameraTargetPositionX()
        endif
    endfunction

    private function returnY takes player p returns real
        if GetLocalPlayer() == p then
            return GetCameraTargetPositionY()
        endif
    endfunction
    
    function TriggerRegisterPlayerMoveCameraEvent takes trigger t, player p returns nothing
        set Trigs[Stack] = t
        set wichP[Stack] = GetPlayerId(p)
        set Stack = Stack + 1
    endfunction
    
    function GetCurrentCameraMovingPlayer takes nothing returns player
        return TheMoving
    endfunction
    
    private function FireTriggers takes player p returns nothing
        local integer i = 0
        local integer c = GetPlayerId(p)
        set TheMoving = Player(c)
        loop
            if wichP<i> == c then
                call TriggerExecute(Trigs<i>)
            endif
            set i = i + 1
            exitwhen i == Stack
        endloop
    endfunction
    
    private function FireEvent takes nothing returns nothing
        local integer i = 0
        local real x
        local real y
        loop
            set x=returnX(Player(i))
            set y=returnY(Player(i))
            if x != prevX<i> or y != prevY<i> then
                call FireTriggers(Player(i))
            endif
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction
    
    private function init takes nothing returns nothing
        local integer i = 0
        call TimerStart(CreateTimer(), PERIOD, true, function FireEvent)
        loop
            if GetLocalPlayer() == Player(i) then
                set prevX<i> = GetCameraTargetPositionX()
                set prevY<i> = GetCameraTargetPositionY()
            endif
            set i = i + 1
            exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
    endfunction

endlibrary</i></i></i></i></i></i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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