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

[JASS] Cinematic BJ function

Status
Not open for further replies.
Level 11
Joined
Dec 21, 2012
Messages
373
Greetings.
Well, I want to make a cinematic for my map, and I came across a function CinematicModeExBJ and looking at it, I don't even really know how to optimize it. It's a surprisingly good BJ function, as far as I have seen them:


JASS:
function CinematicModeExBJ takes boolean cineMode, force forForce, real interfaceFadeTime returns nothing
    // If the game hasn't started yet, perform interface fades immediately
    if (not bj_gameStarted) then
        set interfaceFadeTime = 0
    endif

    if (cineMode) then
        // Save the UI state so that we can restore it later.
        if (not bj_cineModeAlreadyIn) then
            set bj_cineModeAlreadyIn = true
            set bj_cineModePriorSpeed = GetGameSpeed()
            set bj_cineModePriorFogSetting = IsFogEnabled()
            set bj_cineModePriorMaskSetting = IsFogMaskEnabled()
            set bj_cineModePriorDawnDusk = IsDawnDuskEnabled()
            set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)
        endif

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ClearTextMessages()
            call ShowInterface(false, interfaceFadeTime)
            call EnableUserControl(false)
            call EnableOcclusion(false)
            call SetCineModeVolumeGroupsBJ()
        endif

        // Perform global changes
        call SetGameSpeed(bj_CINEMODE_GAMESPEED)
        call SetMapFlag(MAP_LOCK_SPEED, true)
        call FogMaskEnable(false)
        call FogEnable(false)
        call EnableWorldFogBoundary(false)
        call EnableDawnDusk(false)

        // Use a fixed random seed, so that cinematics play consistently.
        call SetRandomSeed(0)
    else
        set bj_cineModeAlreadyIn = false

        // Perform local changes
        if (IsPlayerInForce(GetLocalPlayer(), forForce)) then
            // Use only local code (no net traffic) within this block to avoid desyncs.
            call ShowInterface(true, interfaceFadeTime)
            call EnableUserControl(true)
            call EnableOcclusion(true)
            call VolumeGroupReset()
            call EndThematicMusic()
            call CameraResetSmoothingFactorBJ()
        endif

        // Perform global changes
        call SetMapFlag(MAP_LOCK_SPEED, false)
        call SetGameSpeed(bj_cineModePriorSpeed)
        call FogMaskEnable(bj_cineModePriorMaskSetting)
        call FogEnable(bj_cineModePriorFogSetting)
        call EnableWorldFogBoundary(true)
        call EnableDawnDusk(bj_cineModePriorDawnDusk)
        call SetRandomSeed(bj_cineModeSavedSeed)
    endif
endfunction


Like, there are some BJs inside, that can be changed (Though SetCineModeVolumeGroupsBJ() only really has required functions, so there's no point in replacing it with a bunch of code lines), but other than that, there are only the game settings.

And a question about the game settings in this function - will things like GameSpeed or Fog change, if I do not save them like this function does?
Also, I do not quite understand the "set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)" line. Can anyone tell what exactly it does?
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Why would you want to optimize it? Usually you start cinematics not very frequently, so performance should not be an issue. Saving a few function calls won't make a difference here.

And a question about the game settings in this function - will things like GameSpeed or Fog change, if I do not save them like this function does?
This function purposely changes them, so yes it will change them:
JASS:
// Perform global changes
        call SetGameSpeed(bj_CINEMODE_GAMESPEED)
        call SetMapFlag(MAP_LOCK_SPEED, true)
        call FogMaskEnable(false)
        call FogEnable(false)
        call EnableWorldFogBoundary(false)
        call EnableDawnDusk(false)
If you don't use them you don't need to revert them obviously.

Also, I do not quite understand the "set bj_cineModeSavedSeed = GetRandomInt(0, 1000000)" line. Can anyone tell what exactly it does?
During the cinematic mode random seed is fixed, so everytime it plays exactly the same things happens:
JASS:
// Use a fixed random seed, so that cinematics play consistently.
call SetRandomSeed(0)
The line simply stores new random seed, so you have normal random behaviour after the cinematic again.

Now it is important that this random seed is stored before the random seed is fixed to 0. Using set bj_cineModeSavedSeed = GetRandomInt(0, 1000000) after the seed has been fixed would always return the same value, so the seed would remain fixed, but at a different value.
 
Status
Not open for further replies.
Top