So here's the output from a quick blast at my current game:
Date Time QuerPerfFreq
Sep 11 2010 08:37:18 2610
Function Calls Tot.with childs[s] Exec.only[s] Av.Exe[s/call]
TVector_GetNextIndex 352821 0.000 0.000 0.000
Line 352821 0.000 0.000 0.000
TVector_Display 40411 0.000 0.000 0.000
TVector_Load 9 0.000 0.000 0.000
playGame 1 62.335 60.579 60.579
startLevel 3 0.000 0.000 0.000
__MainGameSub_ 1 65.938 0.017 0.017
playerCrashRock 3492 0.000 0.000 0.000
spawnPlayer 243 0.000 0.000 0.000
playerShotRock 4923 0.000 0.000 0.000
playerShotUFO 4923 0.000 0.000 0.000
displayHUD 3731 0.000 0.000 0.000
updatePlayerBullets 3731 0.000 0.000 0.000
playerShoot 94 0.000 0.000 0.000
explodePlayer 2 0.000 0.000 0.000
updateSparks 3731 0.000 0.000 0.000
createSparks 363 0.000 0.000 0.000
updatePlayer 3731 0.000 0.000 0.000
defineGlobals 1 0.052 0.052 0.052
loadRockVectors 1 0.002 0.000 0.000
cirColl 35140 0.000 0.000 0.000
startGame 1 0.001 0.001 0.001
displayMenu 1 3.501 3.400 3.400
CalculateKern_fancy 1 0.015 0.015 0.015
DrawChar 49518 0.000 0.000 0.000
DrawText 8747 0.001 0.001 0.000
RightText 3762 0.000 0.000 0.000
TextColor 209 0.000 0.000 0.000
TextAlpha 1 0.000 0.000 0.000
AddFont 1 0.030 0.014 0.014
updateRocks 3940 0.000 0.000 0.000
spawnRocks 15 0.000 0.000 0.000
updateExplosions 3731 0.000 0.000 0.000
explodeRock 28 0.000 0.000 0.000
spawnUFO 1 0.000 0.000 0.000
updateUFO 3731 0.000 0.000 0.000
Total 883860 131.875 64.079
Am I right in thinking that despite there being over 350,000 calls to TVector_GetNetIndex, because the times are all 0.00, it's not causing any particular delays in my code?
I'm just trying to figure out why I'm getting some rather random looking stuttering/lag on screen and some rather variable frame rates, despite having set the FPS limiter to 60. My FPS counter shows that the game is fluctuating constantly between about 49FPS and 97FPS. (it's an Asteroids game, so imagine the player just sitting in the middle with a few asteroids making their way across the screen. I'd have thought after a second or two, things would have calmed down and the game would run at a more or less constant rate. If I were constantly creating and destroying objects, I could maybe understand spikes and dips, but not when the game is sitting doing very little.
I appreciate it's a little difficult for you guys to guess stuff sithout seeing my code, but if you have any starting points that I can use to figure out what be causing this problem, I'd appreciate it.
Edit -> OK, so I've found the cause of the stuttering, but I'm not sure how to fix it.
When my game starts up, I use PlayMusic to set an MP3 file looping in the background. This plays whilst the player is on the menu screen, but I don't want it to play during the game. When the player starts the game proper, one of the last calls the menu function makes is to StopMusic. The music stops, but that's what introduces the lag.
As soon as I comment out the StopMusic command, I get a constant 60FPS all through my game. I've tried moving the StopMusic command around, but it doesn't seem to help. Anyone else had this, or is it just me?
Edit 2 -> Changed thread title to something more appropriate
That sounds odd. Just as a workaround, can you tell it to play a silent .mp3 instead of using StopSound? I know that's a bit counter-intuitive, but I'm all for "anything that works" in the short term while the problem is worked to find a proper solution.
So I stuck in a keyboard toggle to turn the music on and off, and as soon as it went off the frame counter went screwy, but as soon as I turned the music back on again, the counter stabilised.
I then changed it to toggle between playing music and a silent file, and the frame counter remained stable. Either my program is doing something very strange or StopMusic is sufferning from a bug.
Time for a bit of code I guess..
So my main file essentially does this:
PLAYMUSIC "Media/Audio/menuMusic.mp3", TRUE
WHILE TRUE
SELECT game.state$
CASE "menu"
displayMenu()
CASE "game"
playGame()
ENDSELECT
WEND
My menu function does this:
FUNCTION displayMenu:
WHILE game.state$ = "menu"
// display some menu screen stuff here
// wait for fire key to start game
IF KEY(44)
STOPMUSIC
startGame()
ENDIF
SHOWSCREEN
WEND
ENDFUNCTION
[code=glbasic]
Then we have the startGame function:
[code=glbasic]
FUNCTION startGame:
// set some variables for the start of the game
player.score = 0
player.lives = 4
game.currLevel = 1
game.extraLifeScore = 10000
game.state$="game"
// spawn player and start the level
spawnPlayer()
spawnUFO()
startLevel()
ENDFUNCTION
Finally we have the playGame funciton:
FUNCTION playGame:
WHILE game.state$ = "game"
updatePlayer()
updatePlayerBullets()
updateSparks()
updateRocks()
updateUFO()
updateExplosions()
displayHUD()
SHOWSCREEN
WEND
ENDFUNCTION
That should be pretty much everything for the game flow. I've tried moving the StopMusic command around, I've tried putting If IsMusicPlaying() to only stop the music if it's already playing, and nothing helps. I'm probably just overlooking something, but I can't see what.
One thing you can try : Put a SLEEP command of, say, 500 directly after the STOPMUSIC command. I'm wondering if the swap file is being tidied at just the wrong time...
Quote from: MrTAToad on 2010-Sep-11
One thing you can try : Put a SLEEP command of, say, 500 directly after the STOPMUSIC command. I'm wondering if the swap file is being tidied at just the wrong time...
Tried that, even increased it to SLEEP 1000, and I still get erratic frame rates :(
I was about to say that gamers wouldn't appreciate a 1/2 second lag whenever the music needs to be stopped, but this doesn't work anyway...
Testing on my PC, there seems to be a slight drop in the FPS rate when music is stopped, and I can hear my PC working slightly, but not erratic drops in frame rates... strange...
There is a slight lag when music loops too.
Quite noticeable too...
I cant think of a good reason why, if SLEEP doesn't help, FPS should decrease after music stops - unless it doesn't actually stop, and its still trying to play music.
Perhaps Gernot could shed some light on the problem...
I'm not too worried about a slight bit of lag when the music loops, as it's only on the menu screen, so it won't really be noticable.
For the moment I'm going with playing a 1 second non-looped silent MP3 as a replacement for the music. If I have to ship my game in that state, then so be it. It's only a freebie Asteroids clone to help me get to grips with GLB anyway.
Maybe a call to HIBERNATE aids? I have no idea why this might lag so hard.