Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frame rate within a frame rate - Better!
#1
A while back I started a discussion on determining frames rates within other frame rates here:

https://qb64phoenix.com/forum/showthread.php?tid=1107

The method I came up with for Pac-Man I thought was quite clever. Turns out not so much. Not only is it ugly (string manipulation) but it only worked for one global frame rate. If another global rate was needed the entire set of strings need to be recreated. Ugly, yes, but functional for the game.

I have a project I'm working on that needs the ability to have the global FPS change at any time but still have the ability to know when lower frame rates change within that global frame rate, in real time. So, while investigating (and pulling my hair out for an hour) my son walks up and asks, "What ya doing?"

I explain to him what I'm trying to accomplish. He listens, says "huh?", then wanders off. Ten minutes later he came back with a super simple solution! (He's autistic on the Asperger's scale and his mind amazes me)

The code below contains a function called FrameChange that can report lower frame rates within a global frame in real time, even if the global frame rate changes. Now I have to go back to my Pac-Man code and put this in place of my ugly solution. His solution is so freaking simple.

Code: (Select All)
' A better frame counter
' By Brandon Ritchie
' 01/31/23

' The function FrameChange determines lower frame rates within a global frame rate.
' The function will return -1 when a lower frame rate increases to the next frame number.

DIM GlobalFPS AS INTEGER
DIM Frame AS INTEGER
DIM FPS(23) AS INTEGER
DIM Count(23) AS INTEGER
DIM i AS INTEGER

GlobalFPS = 60 ' change to any value above 45 - the individual frame rates will remain constant
'                (above 45 simply because example rates below are from 2 to 46)

DO '             begin proof of concept demo
    _LIMIT 10 '  or use GlobalFPS (10 used to slow things down)
    CLS
    Frame = Frame + 1
    IF Frame = GlobalFPS THEN Frame = 0 ' reset global frame counter when last frame reached
    LOCATE 1, 2: PRINT "Global "; _TRIM$(STR$(GlobalFPS)); " FPS >"; Frame
    FOR i = 1 TO 23
        IF Frame = 0 THEN Count(i) = 0 '  reset count when frame resets
        IF FrameChange(GlobalFPS, i * 2, Frame) THEN Count(i) = Count(i) + 1
        LOCATE i + 1, 2
        PRINT _TRIM$(STR$(i * 2)); " FPS >"; Count(i);
    NEXT i
LOOP UNTIL _KEYDOWN(27) ' press ESC to exit

'----------------------------------------------------------------------------

FUNCTION FrameChange (Global AS INTEGER, Target AS INTEGER, Frame AS INTEGER)

    ' Global = global frame rate
    ' Target = target frame rate
    ' Frame  = the current global frame (0 to Global-1)
    ' Returns -1 (true) if target frame changes within the global frame rate

    DIM Fraction AS SINGLE
    DIM x AS SINGLE '

    FrameChange = 0
    Fraction = Target / Global
    x = Frame * Fraction
    IF INT(x) <> INT(x - Fraction) THEN FrameChange = -1

END FUNCTION
Reply
#2
Albert Einstein was like "Huh?" many times while he had to go to school too. It indicates a genius hears something for the first time but then quickly figures it out afterward.

This is an interesting concept going on in what seems to be a simple arcade game quite easy to program, given the development tools available. I guess with eg. Lua Love frame rate for anything is nothing to worry about as long as "critical section" interprets the fewest lines possible. A game like Pac-Man should have been doable on QB64 SDL, this is what I believed when I started using it. Then I figured out what was wrong when I attempted to create a simple music sequencer. Trying to play more than one wave file at a time was all over the place, and I couldn't get _SNDPLAY to cooperate on tight timing. Then I created a "vector synthesizer" which sounded off when a "joystick" hit at least one of the corners. It was messy having to use _SNDRAW to produce the sound and there was serious latency with the visuals. I wanted it to be like Logo but with sound.

Now with the hotrod GPU's and this programming system's ability to use hardware pages, someone might be able to do that one-man MMORPG after all...
Reply




Users browsing this thread: 1 Guest(s)