Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void zz_system::tick_time ()
- {
- if (use_fixed_framerate) {
- add_time(80);
- }
- #ifdef USE_SMOOTH_FRAMERATE
- else {
- static float accum_error = 0; // accumulated diff error
- const zz_time MAX_ACCUM_ERROR = ZZ_TICK_PER_SEC / 1; // max error = 1 sec delay
- const zz_time MIN_ACCUM_ERROR = ZZ_TICK_PER_SEC / 10; // min error = .1 sec delay
- const int MIN_FRAMERATE = 5; // not to get slower than min_framerate
- const zz_time MAX_DIFF = ZZ_TICK_PER_SEC / MIN_FRAMERATE; // time(1sec) / frame
- const zz_time ERROR_MAX_DIFF = ZZ_TICK_PER_SEC*1; // 1 sec
- zz_time now = timer.get_time();
- zz_time diff = now - last_time_; // new real diff
- if (use_force_diff_time) {
- diff = force_diff_time;
- use_force_diff_time = false;
- force_diff_time = 0;
- }
- if (diff > ERROR_MAX_DIFF) { // zhotest
- diff = ERROR_MAX_DIFF;
- }
- if (0) {
- if (diff > MAX_DIFF) {
- accum_error += diff - MAX_DIFF;
- if (accum_error > MAX_ACCUM_ERROR) { // if error exceeded max error
- diff = zz_time(accum_error) + MAX_DIFF;
- accum_error = 0;
- }
- else {
- diff = MAX_DIFF;
- }
- }
- else {
- if (accum_error < MIN_ACCUM_ERROR) {
- diff += zz_time(accum_error);
- accum_error = 0;
- }
- else {
- diff += MIN_ACCUM_ERROR;
- accum_error -= float(MIN_ACCUM_ERROR);
- assert(accum_error >= 0);
- }
- }
- }
- else if (1) {
- const zz_time ACCUM_ERROR_FULL = 2 * ZZ_TICK_PER_SEC; // not to exceed 2 sec
- const float KP = .3f; // magic constants. damper
- zz_time extra_add = 0;
- accum_error += float(diff); // it's current time
- if (accum_error > ACCUM_ERROR_FULL) {
- extra_add = zz_time(accum_error) - ACCUM_ERROR_FULL;
- accum_error = ACCUM_ERROR_FULL;
- }
- assert(accum_error <= ACCUM_ERROR_FULL);
- assert(KP <= 1.0f);
- diff = zz_time (KP * accum_error * accum_error / ACCUM_ERROR_FULL);
- accum_error -= diff;
- diff += extra_add;
- assert(accum_error >= 0);
- }
- set_current_time(now); // update current_time and last_time
- last_time = now - diff; // overwrite last_time set by set_current_time
- last_time_ = now;
- //ZZ_LOG("system: tick_time(). diff(%10d),last(%10d), now(%10d)\n", diff, last_time, now);
- //ZZ_LOG("%f, \n", accum_error);
- //ZZ_LOG("%d, \n", diff);
- }
- #else // NON SMOOTH FRAMERATE
- else { // dynamic frame rate
- set_current_time();
- }
- #endif
- }
Add Comment
Please, Sign In to add comment