... what?

Previous topic - Next topic

Darmakwolf

I could just be having a bad day, but somehow my main project at the moment wont run at over 30 FPS. Just last night it was running at 60. I noticed it was running kind of choppy, so I used your simple FPS calculating routine, and it's definitely capping itself at 30 FPS. (29.9-30.1 or so.) I tried LIMITFPS. Seemingly, it always sets the max FPS to half of what I set limitfps to, but will NOT go over 30. e.g: LIMITFPS 20 gives me 10 FPS calculated. Is this just a freak accident, or is there something to this? I can't currently get it to go over 30. The project options say 60 FPS for both Windows and iPhone configurations. Help? o.o

Ian Price

Are you running something in a loop that shouldn't be? Are you displaying more stuff than you realise? Have you added functions recently that could have affected the FPS? Is there lots of complex maths going on?

Obviously something is amiss, as GLB doesn't slow down that much withour a good reason.

I suggest turning off functions/commenting out sections of code one by one (starting with most recent additions) and watching the FPS counter. I guarantee you'll soon find the cause.
I came. I saw. I played.

Moru

Since you get half the fps you expect, are you mabe calling showscreen twice by accident?

Darmakwolf

#3
nope... well I've done a little experimenting. Looks like the method by which I'm displaying scenes is somehow chopping fps? I have it set up like this - because this was working well for a while.

global scene$

then I'd simply set scene$ to whatever - like "credits" or "countdown" or "game"

while 1

if scene$ = "game"
<game code>
endif

if scene$ = "credits"
<credits code>
endif

showscreen

wend


Is this bad practice, and should showscreen be kept in each individual "scene" as a loop? It is possible that my experimental method this time around was a poor choice...


<edit>

I just regrouped each "scene" into its own "while scene$ =" chunk. Same result, even during just a simple intro splash. Something is amiss here. Not sure why it's happening all of a sudden.





Ian Price

Running everything in one loop like that is not the best practice and performance may be affected, but not by the 50% you're quoting. It also makes debugging tricky, as you are now discovering.

I would break down each element in the main game loop into a separate function/sub-routine, rather than having everything running in just that loop. Same goes for the credits, titlescreen etc. This makes it much easier to identify EXACTLY where the error lies.

Are you willing to post your source/media?
I came. I saw. I played.

Crivens

#5
Try using the CASE/SELECT command too. From speed tests I've done in other languages over the years it is faster than loads of IFs. At least use ELSEIF.

Also, again in other langauges (dunno about GLB, I'm too new to it and haven't had time to do the tests), I've seen faster use of integers over strings. In work for example old code (1989) used to use a similar technique to yours, using strings to do certain routines, but when we just changed to using integers it sped up by something like 4 times. All we did was substitute things like IF MODE$="1"... with IF MODE=1... Course, might not matter in GLB, but worth a speed test.

Weird how the same code slowed down though 50%. Sure it isn't something like a project setting, or using higher resolution textures, upping the number of sprites etc? Come to think of it, sure the PC isn't running a virus scan or something in the background? Oh, and also are you sure you aren't changing scene$ to "credits" within the "game" IF? Could then be doing twice as much stuff. Using a CASE or ELSEIF should sort that out if so.

Cheers

Current fave quote: Cause you like musicians and I like people with boobs.

BdR

#6
Quote from: Darmakwolf on 2011-Feb-06
Is this bad practice, and should showscreen be kept in each individual "scene" as a loop? It is possible that my experimental method this time around was a poor choice...
I suspect you've been programming in Flash as that uses a scenes as the basis of program flow.
Instead of a string variable as a scene/state indicator, I think it's better to use an integer variable type.

Because  the IF statement is run every single frame and string compare is relatively expensive in CPU use compared to a integer compare.
Here's what I usually do to create the overall project structure.

Code (glbasic) Select
SUB MainLoop:

  LOCAL iMain%, iRestart%
  iMain = -1

  WHILE (iMain <> 0)
    iMain = RunMainMenu() // will return what the player selected, 0=quit
    IF (iMain = 1)
      iRestart = -1
      WHILE (iRestart <> 0)
        iRestart = RunGame() // 0=quit, 1=player wants restart after gameover
      WEND
    ENDIF
    IF (iMain = 2)
      RunInstructions()
    ENDIF
    IF (iMain = 3)
      RunCredits()
    ENDIF
    // etc.
  WEND

ENDSUB

The RunGame() and RunCredits() function each have their own WHILE-WEND loop. And then also put the RunGame() function in separate source file along with all the game functions, and the RunCredits and RunInstructions also in a separate source file with all the menu stuff.

Darmakwolf

hehe - Flash? I don't dabble in the Dark Arts. If anything I was semi-used-to Ruby (RGSS, etc. which uses scenes in popular RPG makers.) I don't normally program this way, but it was working very well for a while. I'll give your suggestion(s) a try!

Slydog

Here's how I recommend doing it (scene$ is state%):

Code (glbasic) Select
CONSTANT STATE_GAME% = 1
CONSTANT STATE_CREDITS% = 2
CONSTANT STATE_EXIT% = 99

GLOBAL game_state% = STATE_GAME

WHILE game_state<>STATE_EXIT
  SELECT game_state
  CASE STATE_GAME;     Game()
  CASE STATE_CREDITS;  Credits()
  ENDSELECT

  SHOWSCREEN
WEND

FUNCTION Game%:
  IF condition = TRUE THEN game_state = STATE_CREDITS
ENDFUNCTION

FUNCTION Credits%:
  ...
  IF credits_over = TRUE THEN game_state = STATE_EXIT
ENDFUNCTION
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]