| 703 | } |
| 704 | |
| 705 | static void do_cycle(color_ostream &out) { |
| 706 | DEBUG(cycle,out).print("running {} cycle\n", plugin_name); |
| 707 | |
| 708 | // mark that we have recently run |
| 709 | cycle_timestamp = world->frame_counter; |
| 710 | |
| 711 | record_coverage(out); |
| 712 | |
| 713 | if (*cur_year_tick % 10 == 0) { |
| 714 | season_tick_throttled = false; |
| 715 | if (*cur_year_tick % 1000 == 0) { |
| 716 | DEBUG(cycle,out).print("resetting coverage tracking\n"); |
| 717 | tick_coverage = {}; |
| 718 | } |
| 719 | if (*cur_year_tick == 0) |
| 720 | refresh_birthday_triggers(); |
| 721 | } |
| 722 | |
| 723 | uint32_t unpaused_fps = Core::getInstance().perf_counters.getUnpausedFps(); |
| 724 | int32_t real_fps = std::max(1, static_cast<int32_t>(std::min(static_cast<uint32_t>(INT32_MAX), unpaused_fps))); |
| 725 | int32_t target_fps = config.get_int(CONFIG_TARGET_FPS); |
| 726 | if (real_fps >= target_fps) { |
| 727 | timeskip_deficit = 0.0F; |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | float desired_timeskip = get_desired_timeskip(real_fps, target_fps) + timeskip_deficit; |
| 732 | int32_t timeskip = std::max(0, clamp_timeskip(int32_t(desired_timeskip))); |
| 733 | |
| 734 | // don't let our deficit grow unbounded if we can never catch up |
| 735 | timeskip_deficit = std::min(desired_timeskip - float(timeskip), 100.0F); |
| 736 | |
| 737 | DEBUG(cycle,out).print("cur_year_tick: {}, real_fps: {}, timeskip: ({}, +{:.2f})\n", *cur_year_tick, real_fps, timeskip, timeskip_deficit); |
| 738 | if (timeskip <= 0) |
| 739 | return; |
| 740 | |
| 741 | *cur_year_tick += timeskip; |
| 742 | *cur_year_tick_advmode += timeskip * 144; |
| 743 | |
| 744 | adjust_units(out, timeskip); |
| 745 | adjust_activities(out, timeskip); |
| 746 | adjust_buildings(out, timeskip); |
| 747 | adjust_items(out, timeskip); |
| 748 | } |
| 749 | |
| 750 | ///////////////////////////////////////////////////// |
| 751 | // event logic |
no test coverage detected