|
This thread is locked; no one can reply to it. |
1
2
|
Separating Logic from Drawing Part 2 |
Dario ff
Member #10,065
August 2008
|
If we're going to talk about weather now, let me add that it's 28C over here, and the news report that it's over 42C on the capital city. TranslatorHack 2010, a human translation chain in a.cc. |
AMCerasoli
Member #11,955
May 2010
|
Well yes... my problem was solve, In Fact I Just Finished to talk with Bill Gates, he called me to tell me that he wants to buy my Algorithm... I'm millionaire... So... I got to go... I need to buy a ticket to Hawaii... CYA.. PS: What? 28ºC?... You're a lucky guy....
|
Paul whoknows
Member #5,081
September 2004
|
42ºC! lucky? well, only the ones who have an air conditioner unit, I have one! ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Thomas Fjellstrom
Member #476
June 2000
|
Paul whoknows said: 42ºC! lucky? well, only the ones who have an air conditioner unit, I have one! Not when you have to pay 10-20c/kWh. And the AC is a little too small to do the job so it eats up more power than spec'ed... -- |
OnlineCop
Member #7,919
October 2006
|
1 delta_time = get_current_time() - old_delta_time;
2 old_delta_time = get_current_time();
3
4 if (logic_framerate(delta_time) == true) {
5 process_logic(delta_time);
6 }
7
8 if (display_framerate(delta_time) == true) {
9 update_display(delta_time);
10 }
11
12 ...
13}
14
15void process_logic(double dt)
16{
17 static currently_processed_logic = 0;
18
19 // If the application is suspended, then resumed, 'dt' can sometimes be VERY large
20 // and so, give a maximum amount of time that we will "skip" before resuming normal
21 // logic updates
22 if (dt > TIME_CLAMP)
23 dt = TIME_CLAMP;
24
25 // Run until we hit this give time
26 double continue_until_time = get_current_time() + dt;
27
28 unsigned int num_logic_entities = logic_entities.size();
29 do {
30 logic_entities[currently_processed_logic].update(dt);
31
32 // Update the next logic item, rolling back to 0 when all items have been processed
33 if (currently_processed_logic < num_logic_entities)
34 currently_processed_logic++;
35 else
36 currently_processed_logic = 0;
37 } while (get_current_time() < continue_until_time);
38}
39
40...
This is just pseudo-code. Essentially, the logic() portion is only given a fixed amount of time in which it can update everything. If it gets it done in time, great. If not, the function exits, the draw() function will possibly be drawn (and those elements would not have been updated/moved), and you will have to wait until the next logic update is called before the remainder of those items are updated. It's not perfect, but then you can use it to explicitly limit the amount of time your functions can suck up the processor.
|
|
1
2
|