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.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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