• 🏆 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!

[vJASS] LockedCamera

Level 13
Joined
Nov 7, 2014
Messages
571
LockedCamera - instantly apply a camerasetup to a player and prevent him from moving it

use cases:
  • FSG - Full Screen GUI =)
  • BaD - being a d**k :/
  • UU - unforeseen use case o_O?

JASS:
library LockedCamera initializer locked_camera_init

globals
    timer array keep_locking_timers
    boolean array keep_locking_timer_is_paused
    integer keep_locking_timers_first_hid

    camerasetup array locked_cameras
endglobals

function locked_camera_init takes nothing returns nothing
    local integer i

    set i = 0
    loop
        exitwhen i >= bj_MAX_PLAYERS
        set keep_locking_timers[i] = CreateTimer()
        set keep_locking_timer_is_paused[i] = true
        set i = i + 1
    endloop

    set keep_locking_timers_first_hid = GetHandleId(keep_locking_timers[0])
endfunction

function keep_locking_player_view takes nothing returns nothing
    local integer pid = GetHandleId(GetExpiredTimer()) - keep_locking_timers_first_hid

    if Player(pid) == GetLocalPlayer() then
        // instantly change the player's view to the one of the camera
        call CameraSetupApplyForceDuration(locked_cameras[pid], true, 0)

        // in order to disable the player from fidgeting the camera with the arrow,
        // insert/delete and the page up/down keys, we need to enter the "panning mode"
        // this mode disables those keys, although the player can "get out" of this mode
        // by simple pressing the left mouse key, so that's why we need to keep locking
        // the player's view to the camera, and not just once
        // we also don't want the camera to move but that's what panning means, so
        // that's why we use SIGNED_INT32_MAX = 0x7F_FF_FF_FF = 2147483647
        call PanCameraToTimed(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF)
    endif
endfunction

function lock_player_view_to_camera takes player p, camerasetup c returns nothing
    local integer pid = GetPlayerId(p)
    local boolean is_timer_paused

    set locked_cameras[pid] = c

    if p == GetLocalPlayer() then
        call CameraSetupApplyForceDuration(c, true, 0)
        call PanCameraToTimed(0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF)
    endif

    if keep_locking_timer_is_paused[pid] then
        set keep_locking_timer_is_paused[pid] = false
        call TimerStart(keep_locking_timers[pid], 0.1, true, function keep_locking_player_view)
    endif
endfunction

function unlock_player_view takes player p returns nothing
    local integer pid = GetPlayerId(p)
    set keep_locking_timer_is_paused[pid] = true
    call PauseTimer(keep_locking_timers[pid])

    if p == GetLocalPlayer() then
        call CameraSetupApplyForceDuration(locked_cameras[pid], true, 0)
    endif
endfunction

endlibrary
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Level 23
Joined
Apr 16, 2012
Messages
4,041
you can write your code however you want, but this is public domain, code submitted into here has to comply with the rules set for this section, which includes following JPAG, which this does not.

The code should be not only usable(as in, bug free) but also readable.

This is like saying your style of coding spells is not giving a damn about leaks, and then calling mods nazis in spell section when they reject your resource because it leaks like a waterfall.

Directly from the rules:

Resources must follow convention. Learn more.
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
The code should be not only usable(as in, bug free) but also readable.

What if I told you code can be readable without strictly following a style of coding of your choosing?

This is like saying your style of coding spells is not giving a damn about leaks, and then calling mods nazis in spell section when they reject your resource because it leaks like a waterfall.

If someone actually claimed that and passed the 'style' requirement it would just fail at the performance rule instead.

I called the section nazi not the mods.
I think it's pretty accurate. "Oh you have blonde hair and blue eyes? wonderful." "Oh you have brown eyes? to the gas chamber! (graveyard)"
Looks different but it's the same, that's the definition of (code) style.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I did not choose the JPAG convention.

Last thing I will say to this is that it is also about consistency. When I copy 10 snippets/libraries from here, I do expect them all to follow the same convention, not to have to remember every resource's convention when using it. Imagine you have RegisterUnitIndexEvent(), but having locked_camera_init(this should be private function btw).

Its just not consistent.


I will not comment on this further, if you do not like JPAG being a requirement on Jass section, feel free to open thread in Admin or Moderator contact and discuss it with mods(I have no access to these sections).

Edit: to clarify on the graveyarding, If he says he will not update it to follow the rules, there is no point on holding it inside submissions, it can just as much go stashed into graveyard, and when he changes his mind, it can always be pulled from graveyard by the magic of resurrection.
 
Top