PlayMusic() causing lag

Status
Not open for further replies.

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,223
I recently made a minor system which is supposed to play 'battle music' when entering combat. However it lags once I enter combat.

  • unit enters combat
    • Events
      • Game - CS_combat_event becomes Equal to 1.00
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (CS_entering_unit is in CS_group) Equal to False
        • Then - Actions
          • Custom script: if isNormalMusic(currentMusic) then
          • Custom script: set currentMusic = battleMusic[GetRandomInt(1, battleCount)]
          • Custom script: call PlayMusic(currentMusic)
          • Custom script: endif
        • Else - Actions
If I remove the PlayMusic(currentMusic) it doesn't lag. Or freeze rather. The game freeze for like one second.
 
Level 25
Joined
May 11, 2007
Messages
4,650
You should play it once so that the game loads it up.
Like when playing special effects at loadup once, so that you don't get the freeze when they're played for the first time.

"To provide a smooth loading of assets for a typical game session, it is important that the engine does as much work as possible to load those assets before the session begins. By doing this, the player's experience is not disturbed by interruptions as the engine tries to load assets in the middle of a session, often causing "hitching", lag or delays in rendering. With precaching, the assets are already loaded and are immediately ready for use. To do this, entities must declare and precache the assets they intend to use before the session starts. There are multiple utility functions in place to achieve this. "
https://developer.valvesoftware.com/wiki/Precaching_Assets
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,223
Hm, doesn't seem to work..
JASS:
                //inside the onInit method
	        call PlayMusic(battleMusic[1])
		call PlayMusic(battleMusic[2])
		call PlayMusic(battleMusic[3])
		//---------------------------------
		call PlayMusic(normalMusic[1])
		call PlayMusic(normalMusic[2])
		call PlayMusic(normalMusic[3])
		call PlayMusic(normalMusic[4])
		call PlayMusic(normalMusic[5])

still freezes. Should I provide the test map?
 
Level 25
Joined
May 11, 2007
Messages
4,650
If you play them as a sound and not as music, it doesn't lag (I tested with the GUI version), so you would need to save the music into a sound variable that you can play and stop when playing your music.

It's not the Dmg detection, as I tested with replacing it with player chat commands.

I don't know why it works with sound and not with the music type.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
You must play your sound at 0.01 game time or 0.00 game time, not at map initialization.

Also using sound instead of music helps.
 
Status
Not open for further replies.
Top