5 Replies - 406 Views - Last Post: 23 September 2013 - 11:25 AM Rate Topic: -----

#1 LunaRebirth  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 21-March 13

C++ - Doing something so many times per frame

Posted 22 September 2013 - 08:53 PM

So I had a really good idea today :P, well, I thought it was.

Is there some type of way to do something so many times per frame? Like the title says.

For example:
int timesCalled = 0;

void doStuff() {
     timesCalled +=1;
}

int main() {
     //...
     int frames = 0;
     while (true) {
          callStuff(10, doStuff);
          frames +=1;
     }
}

Let me explain this...
doStuff is telling what to do.
In this case, adding 1 to the amount of times doStuff has been called.
The int frames is telling how many frames has passed.
callStuff parameter 1 is saying how many times to call parameter 2.
So callStuff would tell doStuff to run through 10 times before the next frame adds.
The output (if in cout) would be...
frames: 0
timesCalled: 0
timesCalled: 1
timesCalled: 2
//timesCalled all the way to 10..
frames: 1

Is this possible to do?
If so... Can someone direct me to how to do this?

Is This A Good Question/Topic? 0
  • +

Replies To: C++ - Doing something so many times per frame

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3172
  • View blog
  • Posts: 9,610
  • Joined: 05-May 12

Re: C++ - Doing something so many times per frame

Posted 22 September 2013 - 08:58 PM

Yes it is possible.
These are two must read articles for aspiring game engine designers:
deWiTTERS Game Loop
The Game Loop

This topic would be more appropriate in the game programming forums. Let me know if you would like this to be moved.
Was This Post Helpful? 0
  • +
  • -

#3 LunaRebirth  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 21-March 13

Re: C++ - Doing something so many times per frame

Posted 23 September 2013 - 08:06 AM

Correct me if im wrong, but arent those just speeding a loop's process?

I was thinking if its possible to call something so many times per frame before continuing.
Something more specifically like
while (true) {
     callSomething(Amount, Void);
     frames +=1;
}

Amount being the amount of times its called before adding 1 to "frames".
So if Amount was 3, it would call "Void" 3 times before "frames +=1;"
Or if Amount was 600 or something, it would call "Void" 600 times before "frames +=1;".

Or even something like..
int main() {
     callSomething(10, Void);
     return 0;
}

So before exiting the application, it would call "Void" 10 times in one frame (Avoiding a loop, because a loop does something once per frame).


If this topic is more suitable in the game programming forums, its up to you if it should be moved:) I just want to figure this out, lol.

This post has been edited by LunaRebirth: 23 September 2013 - 08:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3172
  • View blog
  • Posts: 9,610
  • Joined: 05-May 12

Re: C++ - Doing something so many times per frame

Posted 23 September 2013 - 08:34 AM

Those are about getting the best usage of your hardware and balancing that with a great user experience. The implication of the discussion is that it is possible to skip drawing some frames if the frames don't change. That then means that you could use that time not used for rendering to do all the other game updates or stepping the AI along. That would then imply that it is possible to some actions multiple times before the frame is advanced.
Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,400
  • Joined: 19-February 09

Re: C++ - Doing something so many times per frame

Posted 23 September 2013 - 09:21 AM

View PostLunaRebirth, on 23 September 2013 - 04:06 PM, said:

I was thinking if its possible to call something so many times per frame before continuing.


Yes, that sounds a possibility, I found this article a while ago, might help.

Fix Your Timestep!
Was This Post Helpful? 0
  • +
  • -

#6 LunaRebirth  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 111
  • Joined: 21-March 13

Re: C++ - Doing something so many times per frame

Posted 23 September 2013 - 11:25 AM

I just had an idea.
Can i just do something like:
#include <iostream>
using namespace std;
int main() {
  int x = 0;
  int ao = 10;
  int frames = 0;
  while(true) {
    while(x < ao) {
      std::cout << "x: " << x << endl;
      x++;
    }
    std::cout << frames << endl;
    frames++;
  }
}

Or is that not as reliable?
I didnt think to use two while loops. This works on iPad C++ Compiler. Just.. Not sure if this is a very good way to do it.

This post has been edited by LunaRebirth: 23 September 2013 - 11:26 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1