Author Topic: ... what?  (Read 2055 times)

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 341
  • Aoooooooo - the werewolves of London!
    • View Profile
... what?
« on: 2011-Feb-06 »
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

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4144
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: ... what?
« Reply #1 on: 2011-Feb-06 »
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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1774
    • View Profile
    • Homepage
Re: ... what?
« Reply #2 on: 2011-Feb-06 »
Since you get half the fps you expect, are you mabe calling showscreen twice by accident?

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 341
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: ... what?
« Reply #3 on: 2011-Feb-06 »
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.




« Last Edit: 2011-Feb-06 by Darmakwolf »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4144
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: ... what?
« Reply #4 on: 2011-Feb-06 »
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.

Offline Crivens

  • Prof. Inline
  • *****
  • Posts: 913
    • View Profile
Re: ... what?
« Reply #5 on: 2011-Feb-06 »
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

« Last Edit: 2011-Feb-06 by Crivens »
Current fave quote: Cause you like musicians and I like people with boobs.

Offline BdR

  • Dr. Type
  • ****
  • Posts: 303
    • View Profile
    • BdR Games
Re: ... what?
« Reply #6 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.
« Last Edit: 2011-Feb-06 by BdR »

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 341
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: ... what?
« Reply #7 on: 2011-Feb-06 »
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!

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
Re: ... what?
« Reply #8 on: 2011-Feb-10 »
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]