Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » Separating Logic from Drawing Part 2

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Separating Logic from Drawing Part 2
Dario ff
Member #10,065
August 2008
avatar

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.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

AMCerasoli
Member #11,955
May 2010
avatar

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
avatar

42ºC! lucky? well, only the ones who have an air conditioner unit, I have one! :D

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Thomas Fjellstrom
Member #476
June 2000
avatar

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...

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

OnlineCop
Member #7,919
October 2006
avatar

#SelectExpand
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 


Go to: