• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How can I improve the efficience of these triggers?

Status
Not open for further replies.
Level 9
Joined
Apr 19, 2011
Messages
447
Hi.

I have some problems with the triggers of my main proyect. For now, I stopped creating new systems, and started fixing the various bugs on the already created ones. And right now, everything works fine, but I found that some triggers seem to lag.
I'm absolute sure that this lag is not caused by leaks or by rendering too much units/doodads. This lag only happens when certain triggers run, and I want you to check them and tell me how could I improve their efficience.


In my proyect, when the character has an encounter with an enemy group, they are taken to a battle arena, and a some variables and triggers have to be configurated to work with the battle system I created. This is the trigger that starts when one of those encounters begins (I chosed a random encounter. Everything is explained in the comments).
The game seems to lag when this runs:
  • Start Battle
    • Events
      • Unit - A unit comes within 200.00 of Aelan 0000 <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Triggering unit) Equal to Encounter_02_Treant
          • (Triggering unit) Equal to Encounter_02_Mantis_01
          • (Triggering unit) Equal to Encounter_02_Mantis_02
    • Actions
      • Trigger - Turn off (This trigger)
      • -------- Preventing the player to access the Main Menu during battle --------
      • Trigger - Turn off Main Menu Access <gen>
      • -------- Disabling the enemy detection system for this enemy group --------
      • Trigger - Turn off Sight Encounter 02 <gen>
      • Trigger - Turn off Chase Encounter 02 <gen>
      • Trigger - Turn off Restore Encounter 02 <gen>
      • Trigger - Turn off Guard Encounter 02 AELAN <gen>
      • Trigger - Turn off Guard Encounter 02 ENEMY <gen>
      • -------- Preventing the player from moving the characters after the encounter --------
      • Unit - Change ownership of Aelan 0000 <gen> to Player 2 (blue) and Preserve color
      • Unit - Change ownership of Ruy_Out_Battle to Player 2 (blue) and Preserve color
      • -------- Sounds and visuals --------
      • Unit - Order Encounter_02_Treant to Stop
      • Unit - Order Encounter_02_Mantis_01 to Stop
      • Unit - Order Encounter_02_Mantis_02 to Stop
      • Unit - Order Aelan 0000 <gen> to Stop
      • Unit - Order Ruy_Out_Battle to Stop
      • Animation - Play Aelan 0000 <gen>'s stand ready animation
      • Animation - Play Ruy_Out_Battle's stand ready animation
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • Si: Conditions
          • (Unit-type of (Triggering unit)) Equal to Treant
        • Then - Actions
          • Animation - Play (Triggering unit)'s Stand - 4 animation
          • Sound - Play Damaging_Treant <gen>
        • Other - Actions
      • -------- Disabling the camera control --------
      • Set CAMERA_CONTROL = False
      • -------- Disabling this encounter so it won't start again --------
      • Trigger - Turn off Encounter 02 Treant <gen>
      • Trigger - Turn off Encounter 02 Mantis 01 <gen>
      • Trigger - Turn off Encounter 02 Mantis 02 <gen>
      • -------- Locking the camera on the enemy --------
      • Camera - Lock camera target for Player 1 (red) to (Triggering unit), offset by (0.00, 0.00) using Default rotation
      • -------- Stopping the current music --------
      • Countdown Timer - Pause ARRAY_Timers_Music[1]
      • Sound - Stop music After fade-out
      • -------- Playing the battle music --------
      • Trigger - Run Storm Through Them <gen> (checking conditions)
      • Wait 2.00 seconds
      • Sound - Play Entering_Battle <gen>
      • -------- Fading the screen --------
      • Cinematic - Fade out over 0.25 seconds using texture White mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Wait 2.00 seconds
      • -------- When the player encounters some enemies, a ! symbol appears over their heads. This destroys those symbols --------
      • Special Effect - Destroy ARRAY_SYMBOLS[2]
      • Special Effect - Destroy ARRAY_SYMBOLS[3]
      • Special Effect - Destroy ARRAY_SYMBOLS[4]
      • -------- Checking if the player has 1 character or has 2, and creating those characters on the battle arena --------
      • -------- This also sets the camera for the battle --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ALONE Equal to False
        • Then - Actions
          • Set TempLoc = (Center of Aelan DOUBLE <gen>)
          • Unit - Create 1 Aelan (Battle) for Neutral pasive at TempLoc facing 90.00 degrees
          • Custom script: call RemoveLocation(udg_TempLoc)
          • Unit - Change color of (Last created unit) to Black
          • Set Aelan = (Last created unit)
          • Animation - Play Aelan's stand ready animation, using only Current animations
          • Set TempLoc = (Center of Ruy DOUBLE <gen>)
          • Unidad - Create 1 Ruy (Battle) for Neutral pasive at TempLoc facing 90.00 degrees
          • Custom script: call RemoveLocation(udg_TempLoc)
          • Unit - Change color of (Last created unit) to Black
          • Set Ruy = (Last created unit)
          • Animation - Play Ruy's stand ready animation, using only Current animations
          • Camera - Apply BATTLE Allies DOUBLE <gen> for Player 1 (red) over 0.00 seconds
        • Other - Actions
          • Set TempLoc = (Center of Aelan SOLO <gen>)
          • Unit - Create 1 Aelan (Battle) for Neutral pasive at TempLoc facing 90.00 degrees
          • Custom script: call RemoveLocation(udg_TempLoc)
          • Unit - Change color of (Last created unit) to Black
          • Set Aelan = (Last created unit)
          • Animation - Play Aelan's stand ready animation, using only Current animations
          • Camera - Aplicar BATTLE Allies SOLO <gen> for Player 1 (red) over 0.00 seconds
      • -------- Creating the enemy group on the battle arena --------
      • Set TempLoc = (Center of Monster 1 <gen>)
      • Unit - Create 1 Treant (Battle) for Player 9 (Grey) at TempLoc facing 270.00 degrees
      • Unit - Change color of (Last created unit) to Black
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set Monster_01 = (Last created unit)
      • Set TempLoc = (Center of Monster 2 <gen>)
      • Unit - Create 1 Mantis (Battle) for Player 9 (Gray) at TempLoc facing 270.00 degrees
      • Unit - Change color of (Last created unit) to Black
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set Monster_02 = (Last created unit)
      • Set TempLoc = (Center of Monster 3 <gen>)
      • Unit - Create 1 Mantis (Battle) for Player 9 (Gray) at TempLoc facing 270.00 degrees
      • Unit - Change color of (Last created unit) to Black
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set Monster_03 = (Last created unit)
      • -------- Unfading the screen --------
      • Cinematic - Fade out over 2.00 seconds using texture White mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Wait 0.25 seconds
      • -------- Fully healing the characters. The characters also begin the battles ar full HP and MP --------
      • Set HP_Aelan = HP_Aelan_Original
      • Set HP_Ruy = HP_Ruy_Original
      • Set MP_Aelan = MP_Aelan_Original
      • Set MP_Ruy = MP_Ruy_Original
      • -------- Setting the enemy stats for the battle system --------
      • Set Enemy_Number = 3
      • Set HP_Monster_01_Original = 40
      • Set HP_Monster_01 = 40
      • Set FRZ_Monster_01 = 8
      • Set RES_Monster_01 = 6
      • Set HP_Monster_02_Original = 20
      • Set HP_Monster_02 = 20
      • Set FRZ_Monster_02 = 14
      • Set RES_Monster_02 = 5
      • Set HP_Monster_03_Original = 20
      • Set HP_Monster_03 = 20
      • Set FRZ_Monster_03 = 14
      • Set RES_Monster_03 = 5
      • -------- Setting which AI the battle system has to use for the enemies --------
      • Set AI_01 = 0
      • Set AI_02 = 1
      • Set AI_03 = 1
      • Set AI_Attack_01 = 0
      • Set AI_Attack_02 = 1
      • Set AI_Attack_03 = 1
      • -------- Setting the ending data for the system --------
      • Set END = 2
      • -------- Starting the battle system --------
      • Trigger - Run START SYSTEM <gen> (checking conditions)

The second moment where the game seems to lag is when a battle ends. When the battle ends, some configurations have to be done to leave the battle system. This is divided in three different triggers:
  • End Battle
    • Events
    • Conditions
    • Actions
      • -------- Some selection settings. That trigger does NOT lag (I'm sure of it) --------
      • Set Selection = 0
      • Trigger - Run ARRAY_Selections[Selection] (ignoring conditions)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Monster_01_Dead Equal to True) and ((Monster_02_Dead Equal to True) and (Monster_03_Dead Equal to True))
        • Then - Actions
          • -------- Enabling cinematic mode and stopping the different possible battle musics --------
          • Cinematic - Turn cinematic mode On for Player group: Player 1 (red)
          • Countdown Timer - Pause ARRAY_Timers_Music[2]
          • Countdown Timer - Pause ARRAY_Timers_Music[3]
          • Countdown Timer - Pause ARRAY_Timers_Music[4]
          • Countdown Timer - Pause ARRAY_Timers_Music[7]
          • Countdown Timer - Pause ARRAY_Timers_Music[8]
          • Sound - Stop music After fade-out
          • -------- Reseting characters' animations --------
          • Animation - Reset Aelan's animation
          • Animation - Reset Ruy's animation
          • Wait 0.01 seconds
          • -------- Playing victory music --------
          • Sound - Play Fanfare <gen>
          • -------- Restoring the modifiers and bonuses that can be altered during battle --------
          • Set MOD_FRZ_Aelan = 1.00
          • Set MOD_FRZ_Ruy = 1.00
          • Set MOD_FRZ_Monster = 1.00
          • Set MOD_FRZ_Monster_01 = 1.00
          • Set MOD_FRZ_Monster_02 = 1.00
          • Set MOD_FRZ_Monster_03 = 1.00
          • Set MOD_RES_Aelan = 1.00
          • Set MOD_RES_Ruy = 1.00
          • Set MOD_RES_Monster = 1.00
          • Set MOD_RES_Monster_01 = 1.00
          • Set MOD_RES_Monster_02 = 1.00
          • Set MOD_RES_Monster_03 = 1.00
          • Set MOD_MAG_Aelan = 1.00
          • Set MOD_MAG_Ruy = 1.00
          • Set MOD_MAG_Monster = 1.00
          • Set MOD_MAG_Monster_01 = 1.00
          • Set MOD_MAG_Monster_02 = 1.00
          • Set MOD_MAG_Monster_03 = 1.00
          • Set MOD_ESP_Aelan = 1.00
          • Set MOD_ESP_Ruy = 1.00
          • Set MOD_ESP_Monster = 1.00
          • Set MOD_ESP_Monster_01 = 1.00
          • Set MOD_ESP_Monster_02 = 1.00
          • Set MOD_ESP_Monster_03 = 1.00
          • -------- Erasing the battle multiboard --------
          • Multiboard - Destroy BOARD_Battle
          • -------- Running the "Victory" trigger --------
          • Trigger - Run VICTORY <gen> (checking conditions)
        • Other - Actions
  • VICTORY
    • Events
    • Conditions
    • Actions
      • -------- Setting the monsters as dead --------
      • Set Monster_01_Dead = False
      • Set Monster_02_Dead = False
      • Set Monster_03_Dead = False
      • -------- Disabling the configurations for special battle cameras --------
      • Set Big_Battle = False
      • Set Huge_Battle = False
      • -------- Setting the experience reward --------
      • Set RESULT_EXP = ARRAY_Experience[END]
      • -------- Giving the experience to the characters the player has --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ALONE Equal to True
        • Then - Actions
          • Set EXP_Aelan = (EXP_Aelan + RESULT_EXP)
        • Other - Actions
          • Set EXP_Aelan = (EXP_Aelan + RESULT_EXP)
          • Set EXP_Ruy = (EXP_Ruy + RESULT_EXP)
      • -------- Fading out the screen --------
      • Cinematic - Fade out over 2.00 seconds using texture Black mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Wait 2.00 seconds
      • -------- Removing the enemies and the characters from the battle arena --------
      • Unit - Remove Monster_01 from the game
      • Unit - Remove Monster_02 from the game
      • Unit - Remove Monster_03 from the game
      • Unit - Remove Aelan from the game
      • Unit - Remove Ruy from the game
      • -------- Selection configurations --------
      • Set Selection = 0
      • Trigger - Run ARRAY_Selections[Selection] (ignoring conditions)
      • -------- Disabling the triggers that keep the camera locked --------
      • Trigger - Turn off Allies SOLO <gen>
      • Trigger - Turn off Allies DOUBLE <gen>
      • Trigger - Turn off Allies Big <gen>
      • Trigger - Turn off Allies Huge <gen>
      • Trigger - Turn off Monsters <gen>
      • Trigger - Turn off Monsters Big <gen>
      • Trigger - Turn off Monsters Huge <gen>
      • -------- Applying the victory screen camera and fading in --------
      • Camara - Apply RESULT SCREEN <gen> for Player 1 (red) over 0.00 seconds
      • Cinematic - Fade in over 2.00 seconds using texture Black mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • -------- Showing the floating texts of the victory screen --------
      • Set TempLoc = (Center of Text box 1 <gen>)
      • Floating Text - Create floating text that reads VICTORY at TempLoc with Z offset 50.00, using font size 25.00, color (70.00%, 70.00%, 100.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set RESULT_Text_01 = (Last created floating text)
      • Set TempLoc = (Center of Text box 3 <gen>)
      • Floating Text - Create floating text that reads ITEMS at TempLoc with Z offset 50.00, using font size 16.50, color (70.00%, 70.00%, 100.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set RESULT_Text_03 = (Last created floating text)
      • Wait 2.00 seconds
      • Set TempLoc = (Center of Text box 2 <gen>)
      • Floating Text - Create floating text that reads (You get + ((String(RESULT_EXP)) + EXP!)) at TempLoc with Z offset 50.00, using font size 15.00, color (100.00%, 60.00%, 0.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set RESULT_Text_02 = (Last created floating text)
      • Sound - Play Results <gen>
      • Wait 0.50 seconds
      • Set TempLoc = (Center of Text box 4 <gen>)
      • Floating Text - Create floating text that reads <Unavailable yet> at TempLoc with z offset 50.00, using font size 15.00, color (100.00%, 60.00%, 0.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set RESULT_Text_04 = (Last created floating text)
      • Sound - Stop Results <gen> Immediately
      • Sound - Play Results <gen>
      • Wait 0.50 seconds
      • Set TempLoc = (Center of Text box 5 <gen>)
      • Floating Text - Create floating text that reads Press [ESC] to... at TempLoc with Z offset 50.00, using font size 15.00, color (70.00%, 70.00%, 100.00%), and 0.00% transparency
      • Custom script: call RemoveLocation(udg_TempLoc)
      • Set RESULT_Text_05 = (Last created floating text)
      • -------- Allowing the player to leave the victory screen --------
      • Trigger - Turn on ARRAY_End[END]
In this case, the ARRAY_End trigger would be this one:
  • End Encounter 02
    • Events
      • Player - Player 1 (red) skips a cinematic sequence
    • Conditions
    • Actions
      • -------- Disabling the trigger and fading out --------
      • Trigger - Turn off (This trigger)
      • Cinematic - Fade out over 2.00 seconds using texture Black mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • Wait 2.00 seconds
      • -------- Stopping the victory music and playing the normal music --------
      • Sound - Stop music After fade-out
      • Trigger - Run Mangron Forest <gen> (checking conditions)
      • -------- Restoring the camera control --------
      • Camera - Lock camera target for Player (red) to Aelan 0000 <gen>, offset by (0.00, 0.00) using Default rotation
      • Camera - Set Player 1 (red)'s camera Angle of attack to 325.00 over 0.00 seconds
      • Set Camera_Height = 325.00
      • Set CAMERA_CONTROL = True
      • -------- Reconvering control over the characters --------
      • Unit - Change ownership of Aelan 0000 <gen> to Player 1 (red) and Preserve color
      • Unit - Change ownership of Ruy_Out_Battle to Player 1 (red) and Preserve color
      • -------- Disabling cinematic mode and fading in --------
      • Cinematic - Turn cinematic mode Off for Player group: Player 1 (red)
      • Cinematic - Fade in over 2.00 seconds using texture Black mask and color (100.00%, 100.00%, 100.00%) with 0.00% transparency
      • -------- Allowing the player to access the main menu --------
      • Trigger - Turn on Main Menu Access <gen>
      • -------- Selection configurations --------
      • Set Selection = 1
      • Trigger - Run ARRAY_Selections[Selection] (ignoring conditions)
      • -------- Erasing the victory screen --------
      • Floating Text - Destroy RESULT_Text_01
      • Floating Text - Destroy RESULT_Text_02
      • Floating Text - Destroy RESULT_Text_03
      • Floating Text - Destroy RESULT_Text_04
      • Floating Text - Destroy RESULT_Text_05
      • Wait 2.00 seconds
      • -------- Killing the enemies (the real ones, not the ones in the battle arena) --------
      • Unit - Kill Encounter_02_Treant
      • Unit - Kill Encounter_02_Mantis_01
      • Unit - Kill Encounter_02_Mantis_02
      • -------- Resetting the characters' animations --------
      • Animation - Reset Aelan's animation
      • Animation - Reset Ruy_Out_Battle's animation
I suppose that's it. When the game runs those triggers, it seems to lag, I don't clearly know why. What do you think I could do to improve their efficience?
Actually, the lag is the only thing that's pissing me off...

Regards
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Well, one way you could reduce the lag of a trigger, is to place wait actions in your trigger (like wait 1 second or something). This is to break up the trigger into pieces, the peoples computers don't process every action all at once (this creates a spike of lag).

You could also set large chunks of information into variables at map initialization and reference the variables in triggers. E.g. If you referenced unit variables a lot, you could set those units into a unit group variable, allowing the trigger reference those unit's faster.

Also, if some of your points dont move (E.g. Centre of a region) you can set those points in map initializtion. This means you dont need to set the point inside the trigger and hence less actions are performed.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Another thing that greatly increases lag (and load time) is a high amount of ability levels.
I've noticed you create some units, if those units have abilities with many levels, then it will indubitably create a lag spike.

It would be really weird if it is the trigger "End Battle" that lags, because it's mostly just setting variables, which shouldn't matter at all (at least not with reals).
The efficiency of the triggers themselves seems to be all right.
Perhaps you could break it down with waits and show a message after every wait, then you can pinpoint when the lag starts, which is always easier and more helpful than searching through a big trigger.
 
Level 9
Joined
Apr 19, 2011
Messages
447
Well, one way you could reduce the lag of a trigger, is to place wait actions in your trigger (like wait 1 second or something). This is to break up the trigger into pieces, the peoples computers don't process every action all at once (this creates a spike of lag).

Well, there are already some wait actions in the trigger... The only thing I can think of is some specific action that's creating a huge spike of lag. I just don't know which one...

You could also set large chunks of information into variables at map initialization and reference the variables in triggers. E.g. If you referenced unit variables a lot, you could set those units into a unit group variable, allowing the trigger reference those unit's faster.

Sadly, I can't do it that way. Of course I would do it if I had constant values in the variables. However, the values stored in the variables of those trigger change a lot during gameplay. I doubt I can do anything about this in the map initialization if the values are constantly changing.
And just one question: I didn't know that referencing units inside a unit group is faster than referencing them one by one (I don't really know a lot about these kind of efficiencies). Is it really faster?

Another thing that greatly increases lag (and load time) is a high amount of ability levels.
I've noticed you create some units, if those units have abilities with many levels, then it will indubitably create a lag spike.

Those units don't have any ability. So, I doubt that's the reason of the lag.

The efficiency of the triggers themselves seems to be all right.
Perhaps you could break it down with waits and show a message after every wait, then you can pinpoint when the lag starts, which is always easier and more helpful than searching through a big trigger.

I think I will use this trick to face the problem. I'll break it with waits and use messages to find the problematic actions that are creating the lag.
I'll post the result once I find something.


Thank you two for your help so far!

Regards
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Unit groups are actually pretty slow. Things like counting the units in a group are better done with an integer variable than with the group actions.
I would prefer referencing the units individually.

I hope you find the problem, I'm actually pretty interested in what can create the lag you experience.
 
Level 9
Joined
Apr 19, 2011
Messages
447
O.K... I found the problem (thanks to ap0calypse for his suggestions of breaking the trigger with waits and text messages). I would never imagine what was creating that lag. I don't even know if this is normal, or if it's an anomaly.

The problem is with this action:
  • Trigger - Run Storm Through Them <gen> (checking conditions)
This trigger is the following one:

  • Storm Through Them
    • Events
      • Time - ARRAY_Timers_Music[2] expires
    • Conditions
    • Actions
      • Sound - Stop music After fade out
      • Wait 0.01 seconds
      • Sound - Play Storm_Through_Them <gen>
      • Countdown Timer - Start ARRAY_Timers_Music[2] as a One shot timer that will expire in (Length of Storm_Through_Them <gen>) seconds
At first, I just used the "Sound - Play music" action to use musics in my proyect, but for some reason the music was not looping (it loops in every one of my proyects, I don't know why it doesn't loop in this one :confused:), so I created triggers and timers to manage the music.

However, this music is not imported into the map. Is imported in the campaign (my proyect is a campaign). I looked carefully at all the lag spikes I was experiencing, and I realized that they only happen when I change the music.
So, the problem is with the music. Is this normal? Is there something I can do? Importing the music in the map is not an option, the map's file size would be far higher than 20 MB, and won't run in the campaign.

What do you think?

Regards
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Well, I don't know much about playing music from a campaign, but you could compress the music to allow it to fit in your map. You could import the music into the map itself and play it for testing purposes only, however, I'm not sure why music would lag you game in the first place...?
 
Level 9
Joined
Apr 19, 2011
Messages
447
Well, I don't know much about playing music from a campaign, but you could compress the music to allow it to fit in your map. You could import the music into the map itself and play it for testing purposes only, however, I'm not sure why music would lag you game in the first place...?

I checked the music I'm using in the map. Approximately 40 MB. Right now, my map has a lot of imports, including a high quality loading screen (about 2 MB), and the file size is already about 7 MB. Maybe I'm wrong, but it's impossible to compress 40 MB of music in 1 MB. And I have to say that the music is one of the points where I don't want to sacrifice quality.

:vw_death:

I'm sure that the music is the problem. Just deleting all the "Sound - Play Music" actions of all the triggers was enough to remove the lag.
Seriously, isn't there a way to solve this apart from importing into the map (which is nearly imposible for me right now)?

Regards
 
Did you try playing them all on map initialization? (just use "Sound - Play Music" for all of them on map initialization, then stop music)

Maybe it is like the ability spike that you get when you first get an ability. idk. It is worth a shot. I haven't really experienced this problem before.

You may want to try optimizing it. You don't necessarily have to use the optimized version, but you should optimize one version down to a smaller size and test that one to see if it doesn't lag as much. That way, you will be sure that the music's size is the problem.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
I may know why. I have a music editting program, and it loads up a music file in a few seconds. However, I loaded an hour long song and it took maybe a minute to load the file. Perfectly logical, it had to load more data.

Considering your music file is 40MBs, I'm guessing it's either a really song, or a moderately long song at a high quality bit rate (given your not stupid enough to use a ".wav" file as a song). So pherhaps it's too much data for WC3 to process at once, hence causing lag.

This is just a guess, but you could cut the video into sections and play those, and you could also compress the song to something like 128KB bit rate (this won't affect the quality of the song). I'm certain if you played a shorter song of a lower bit rate, you wouldnt experience lag. I have songs played in my map and they don't lag.

If you don't know what any of this means, just ask and I'll explain further.
 
Level 9
Joined
Apr 19, 2011
Messages
447
Did you try playing them all on map initialization? (just use "Sound - Play Music" for all of them on map initialization, then stop music)

Maybe it is like the ability spike that you get when you first get an ability. idk. It is worth a shot. I haven't really experienced this problem before.

You may want to try optimizing it. You don't necessarily have to use the optimized version, but you should optimize one version down to a smaller size and test that one to see if it doesn't lag as much. That way, you will be sure that the music's size is the problem.

I tried what you said, I played all the musics at the map intialization. There was a really huge lag spike right in the map initialization. However (as I expected), the lag was still there during all the game. I already supposed this, because some of these musics play a lot of times during gameplay, and I always get a lag spike.

And what do you exactly mean with "optimize"? Remove the imports, and things like that, to decrease the file size of the map?

I may know why. I have a music editting program, and it loads up a music file in a few seconds. However, I loaded an hour long song and it took maybe a minute to load the file. Perfectly logical, it had to load more data.

Considering your music file is 40MBs, I'm guessing it's either a really song, or a moderately long song at a high quality bit rate (given your not stupid enough to use a ".wav" file as a song). So pherhaps it's too much data for WC3 to process at once, hence causing lag.

This is just a guess, but you could cut the video into sections and play those, and you could also compress the song to something like 128KB bit rate (this won't affect the quality of the song). I'm certain if you played a shorter song of a lower bit rate, you wouldnt experience lag. I have songs played in my map and they don't lag.

If you don't know what any of this means, just ask and I'll explain further.

You misunderstood me... It's not a single music file of 40 MB. There are various music files (like 11 or 12), that altogether sum 40 MB. So I don't think the problem is WC3 having to load huge quantities of data. The problem is another thing (one of the musics has a file size of 1 MB, and even when I play that, I get lag).

Regards
 
Level 9
Joined
Apr 19, 2011
Messages
447
Bumping the thread.

By the way, I found something interesting about this issue... It has nothing to do with the triggers, or with the map itself. I created a new campaign, imported all the music tracks, and then played some of them in-game. The result was the same, I had lag spikes again.
Any ideas?

Regards
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
I have this trigger in my map, and it does not lag at all.

  • Music System
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • MusicChecker Equal to False
        • Then - Actions
          • Set MusicChecker = True
          • Sound - Set Music to 95.00%
          • Sound - Play 21Terran1_Compressed3 <gen>
          • Wait 225.67 seconds
          • Sound - Stop the currently playing music theme
          • Sound - Stop music Immediately
          • Sound - Set Music to 0.00%
          • Wait 8.00 seconds
          • Trigger - Run (This trigger) (ignoring conditions)
        • Else - Actions
          • Set MusicChecker = False
          • Sound - Set Music to 95.00%
          • Sound - Play 13_terran_2_Compressed_1 <gen>
          • Wait 223.63 seconds
          • Sound - Stop the currently playing music theme
          • Sound - Stop music Immediately
          • Sound - Set Music to 0.00%
          • Wait 8.00 seconds
          • Trigger - Run (This trigger) (ignoring conditions)
I am aware that I'm on a higher end computer, but I've never heard anybody mention a lag of spike when the songs play.
These are both just under 1MB and roughly 3:30 in length. I can't understand why your songs seem to lag.

Maybe these questions may help somebody.

  • What sampling rate are your songs?

  • What bit rate are your songs?

  • What format are your songs in? (mp3, wav, etc)

  • How many channels do your songs have (Mono, stereo, or higher?)
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
Ok, I tested vigerously, lol. It turns out the fix is extremely simple. Your audio file is fine.

You need to add this line in before you play your song:

  • Sound - Stop music Immediately
I cannot explain why, but the game will spike heavily if you play music while there is already music playing. Note that you must stop the music "immediately" not "after fading".

Also, your music is needlessly a high bit rate. I made you a new song which is a smaller file size. The quality difference is not noticeable unless you have a great ear and have a good sound system. That will help you reduce the file size of your map by 3.6 MB.
 

Attachments

  • Mangron Forest (Compressed).mp3
    1.8 MB · Views: 71
Level 9
Joined
Apr 19, 2011
Messages
447
Ok, I tested vigerously, lol. It turns out the fix is extremely simple. Your audio file is fine.

You need to add this line in before you play your song:

  • Sound - Stop music Immediately
I cannot explain why, but the game will spike heavily if you play music while there is already music playing. Note that you must stop the music "immediately" not "after fading".

Also, your music is needlessly a high bit rate. I made you a new song which is a smaller file size. The quality difference is not noticeable unless you have a great ear and have a good sound system. That will help you reduce the file size of your map by 3.6 MB.

I LOVE YOU (Not literally XDD).

I was using this:
  • Sound - Stop music After fading
I changed it to "Immediately", and then worked perfectly, the lag was gone!!
Crap, I really wanted the music to fade before playing a new track, but I'll go on without that, for obvious reasons.
Technically, if I fade out a music, the game won't lag as long as I don't play a new music while the old one is still fading, right?

Also, thanks for reducing the bit rate of that track. However, right now I have another 14-15 music tracks, and in the near future I'll have a lot more, so would you mind telling me how did you reduce the bit rate? I think I can do it myself, I don't want to bother you.

Anyway, thank you very much for your help! I thought I would never get rid of this lag! Thanks as well to all the other people who helped me.:wink:

Regards
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Audacity is a good free audio-program.

MP3-files (recommended):
Follow this manual first (short and easy) - I personally like to have the LAME-folder inside my Audacity-folder so my program files doesn't get too big, but that's up to you.

Start up Audacity, open your music file and immediately select File -> Export.
As the file-type, choose MP3.
Under "Save" and "Cancel", you see the button "Options". Click this and change the quality to whatever you like (64 kbps is usually enough for instrumentals).
Click "save" and the rest should be clear.
 
Level 16
Joined
Mar 27, 2011
Messages
1,349
If you still wanted your music to fade before a new track, I guess you can still make it stop "after fading". You just need to add a "wait action" in there to play the music after it has finished fading. You just need to find out how long it takes for the music to fade out and have completely stopped.

I havn't actually tested this of course, but it seems logical. You could try it out.
 
Status
Not open for further replies.
Top