Author Topic: consistant framerates?  (Read 2765 times)

0 Members and 1 Guest are viewing this topic.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
consistant framerates?
« on: January 13, 2012, 12:48:17 am »
if i were writing a processor-intensive program that had a lot of variance in framerates, how could make them stable?
interrupts would slow things down too much, wouldn't they? would measuring out the difference in number of cycles at any branch in the code and then adding in a wait for that long on the slower one work?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: consistant framerates?
« Reply #1 on: January 13, 2012, 12:51:54 am »
Maybe you could use interrupts to "trigger" (set a flag of some sort) routines in the main program?




Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: consistant framerates?
« Reply #2 on: January 13, 2012, 12:53:49 am »
if the interrupts are firing constantly and incrementing a counter and then storing another value, wouldn't that cause a lot of lag? how much, approximately, is it at the lowest speed?

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: consistant framerates?
« Reply #3 on: January 13, 2012, 10:02:19 am »
You could use the DS<( command for this.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: consistant framerates?
« Reply #4 on: January 13, 2012, 10:09:34 am »
if i were writing a processor-intensive program that had a lot of variance in framerates, how could make them stable?
interrupts would slow things down too much, wouldn't they? would measuring out the difference in number of cycles at any branch in the code and then adding in a wait for that long on the slower one work?

Interrupts wouldn't slow things down if you wrote your own routine. 

So let's say you want 15 frames per second, approximately.  You could have a counter set to 8 (An interrupt routine happens about 108 - 120 times per second, and 15 * 8 = 120), and decrease the counter everytime the interrupt routine runs.  Reset the counter to 8 when it reaches zero.  When you reach the end of your code that is looping, check to see if the counter is = to 8.  If not, don't loop again until it is.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: consistant framerates?
« Reply #5 on: January 14, 2012, 06:43:30 am »
Just to add to Hot_Dog's idea, I would have interrupt routine simply decrease a variable (call it "A") until it reaches zero and then just stop.  That's it.  In the regular code, just do the computation, and then right after add a "While A:End" so that it waits for the trigger if the computation was too quick.  Immediately after, set A to be 8 or whatever you need for the desired framerate and the counter will do its thing.  Here is the code:

Code: [Select]
:.Setup interrupt
:fnInt(INT,6)
:
:.Main loop
:While <GameLoop>
:  <Computation>
:  While A:End
:  8->A
:  <Update screen>
:End
:Return
:
:.Interrupt
:Lbl INT
:Return!If A
:-1->A
:Return

Replace "A" with an unused variable though...
___Axe_Parser___
Today the calculator, tomorrow the world!