Changeset 577
- Timestamp:
- May 3, 2011, 3:02:52 PM (11 years ago)
- Location:
- abuse/trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/ant.cpp
r555 r577 481 481 wm->font()->put_string(screen,x,y,msg,wm->bright_color()); 482 482 wm->flush_screen(); 483 milli_wait(500);484 } 485 486 } 483 Timer now; now.WaitMs(500); 484 } 485 } 486 -
abuse/trunk/src/cop.cpp
r555 r577 1082 1082 1083 1083 wm->flush_screen(); 1084 milli_wait(4000); // wait 4 seconds1084 Timer now; now.WaitMs(4000); // wait 4 seconds 1085 1085 1086 1086 return NULL; -
abuse/trunk/src/demo.cpp
r555 r577 203 203 /* 204 204 fade_in(cache.img(cache.reg("art/help.spe","sell6",SPEC_IMAGE,1)),8); 205 milli_wait(2000);205 Timer now; now.WaitMs(2000); 206 206 fade_out(8); 207 207 */ -
abuse/trunk/src/game.cpp
r576 r577 1244 1244 delete blank; 1245 1245 fade_in(cache.img(cdc_logo), 32); 1246 1247 milli_wait(400);1246 Timer tmp; tmp.WaitMs(400); 1247 fade_out(32); 1248 1248 1249 1249 void *space_snd = LSymbol::FindOrCreate("SPACE_SND")->GetValue(); 1250 1251 fade_out(32);1252 milli_wait(100);1253 1254 1250 char *str = lstring_value(LSymbol::FindOrCreate("plot_start")->Eval()); 1255 1251 … … 1511 1507 } 1512 1508 1513 1514 1515 time_marker *led_last_time = NULL, *fps_mark_start = NULL; 1516 double avg_fps = 15.0, possible_fps = 15.0; 1509 time_marker *led_last_time = NULL; 1510 static float avg_fps = 15.0f, possible_fps = 15.0f; 1517 1511 1518 1512 void Game::toggle_delay() 1519 1513 { 1520 no_delay=!no_delay; 1521 if(no_delay) 1522 show_help(symbol_str("delay_off")); 1523 else show_help(symbol_str("delay_on")); 1524 avg_fps = possible_fps = 15.0; 1514 no_delay = !no_delay; 1515 show_help(symbol_str(no_delay ? "delay_off" : "delay_on")); 1516 avg_fps = possible_fps = 15.0f; 1525 1517 } 1526 1518 1527 1519 void Game::show_time() 1528 1520 { 1529 if(first_view && fps_on) 1530 { 1531 char str[10]; 1521 if (!first_view || !fps_on) 1522 return; 1523 1524 char str[16]; 1532 1525 sprintf(str, "%ld", (long)(avg_fps * 10.0)); 1533 1526 console_font->put_string(screen, first_view->cx1, first_view->cy1, str); … … 1535 1528 sprintf(str, "%d", total_active); 1536 1529 console_font->put_string(screen, first_view->cx1, first_view->cy1 + 10, str); 1537 }1538 1530 } 1539 1531 … … 1600 1592 } 1601 1593 1594 // FIXME: refactor this to use the Lol Engine main fixed-framerate loop? 1602 1595 int Game::calc_speed() 1603 1596 { 1597 static Timer frame_timer; 1598 static int first = 1; 1599 1600 if (first) 1601 { 1602 first = 0; 1603 return 0; 1604 } 1605 1606 // Find average fps for last 10 frames 1607 float fps = 1000.0f / Max(1.0f, frame_timer.PollMs()); 1608 1609 avg_fps = 0.9f * avg_fps + 0.1f * fps; 1610 possible_fps = 0.9f * possible_fps + 0.1f * fps; 1611 1612 if (avg_fps > 14) 1613 massive_frame_panic = Max(0, Min(20, massive_frame_panic - 1)); 1614 1604 1615 int ret = 0; 1605 if(fps_mark_start) 1606 { 1607 time_marker t; 1608 1609 // find average fps for last 10 frames 1610 double td = t.diff_time(fps_mark_start); 1611 if(td < 0.001) // something is rotten in the state of demark 1612 td = 0.001; 1613 1614 avg_fps = avg_fps * 9.0 / 10.0 + 1.0/(td * 10.0); 1615 possible_fps = possible_fps * 9.0 / 10.0 + 1.0/(td * 10.0); 1616 1617 if(avg_fps > 14) 1616 1617 if (dev & EDIT_MODE) 1618 { 1619 // ECS - Added this case and the wait. It's a cheap hack to ensure 1620 // that we don't exceed 30FPS in edit mode and hog the CPU. 1621 frame_timer.WaitMs(33); 1622 } 1623 else if (avg_fps > 15 && need_delay) 1624 { 1625 frame_panic = 0; 1626 if (!no_delay) 1618 1627 { 1619 if(massive_frame_panic > 20) 1620 massive_frame_panic = 20; 1621 else if(massive_frame_panic) 1622 massive_frame_panic--; 1628 frame_timer.WaitMs(1000.0f / 15); 1629 avg_fps -= 0.1f * fps; 1630 avg_fps += 0.1f * 15.0f; 1623 1631 } 1624 1625 if(avg_fps > 15 && ((dev & EDIT_MODE)==0 || need_delay)) 1626 { 1627 frame_panic = 0; 1628 int32_t stime=(int32_t)((1 / 15.0 - 1.0 / possible_fps)*1000.0); 1629 if(stime > 0 && !no_delay) 1630 { 1631 milli_wait(stime); 1632 avg_fps -= 1.0/(td * 10.0); // subtract out old estimate 1633 1634 time_marker t; 1635 1636 // find average fps for last 10 frames 1637 double td = t.diff_time(fps_mark_start); 1638 if(td < 0.00001) // something is rotten in the state of demark 1639 td = 0.00001; 1640 1641 avg_fps += 1.0/(td * 10.0); // add in new estimate 1642 } 1643 } 1644 else if(avg_fps < 14) 1645 { 1646 if(avg_fps < 10) 1647 massive_frame_panic++; 1648 frame_panic++; 1649 ret = 1; 1650 } 1651 else if(dev & EDIT_MODE) 1652 { 1653 // ECS - Added this case and the wait. It's a cheap hack to assure that 1654 // we don't exceed 30FPS in edit mode and hog the CPU. 1655 milli_wait(33); 1656 } 1657 1658 delete fps_mark_start; 1659 } 1660 fps_mark_start = new time_marker; 1632 } 1633 else if (avg_fps < 14) 1634 { 1635 if(avg_fps < 10) 1636 massive_frame_panic++; 1637 frame_panic++; 1638 // All is lost, don't sleep during this frame 1639 ret = 1; 1640 } 1641 1642 // Ignore our wait time, we're more interested in the frame time 1643 frame_timer.GetMs(); 1661 1644 return ret; 1662 1645 } … … 2119 2102 } 2120 2103 free_pframes(); 2121 if(fps_mark_start) delete fps_mark_start; fps_mark_start = NULL;2122 2104 delete pal; 2123 2105 free(object_names); … … 2449 2431 2450 2432 stat_man = new text_status_manager(); 2451 if (!get_option("-no_timer"))2452 timer_init();2453 2433 2454 2434 #if !defined __CELLOS_LV2__ … … 2472 2452 if (main_net_cfg && !main_net_cfg->notify_reset()) 2473 2453 { 2474 if (!get_option("-no_timer"))2475 timer_uninit();2476 2454 sound_uninit(); 2477 2455 exit(0); … … 2575 2553 delete chat; 2576 2554 2577 milli_wait(500);2555 Timer tmp; tmp.WaitMs(500); 2578 2556 2579 2557 delete small_render; small_render = NULL; … … 2622 2600 set_save_filename_prefix(NULL); 2623 2601 2624 if (!get_option("-no_timer"))2625 timer_uninit();2626 2627 2602 sound_uninit(); 2628 2603 -
abuse/trunk/src/imlib/timing.h
r555 r577 26 26 }; 27 27 28 void milli_wait(unsigned int wait_time); // sleep for a millisecond29 void timer_init();30 void timer_uninit();31 32 28 #endif 33 29 -
abuse/trunk/src/menu.cpp
r555 r577 257 257 wm->flush_screen(); 258 258 save->put_image(screen,mx+1,by1); 259 } else milli_wait(10);259 } else { Timer tmp; tmp.WaitMs(10); } 260 260 261 261 } while (!done); … … 694 694 { 695 695 // ECS - Added so that main menu doesn't grab 100% of CPU 696 milli_wait(30);696 Timer tmp; tmp.WaitMs(30); 697 697 } 698 698 -
abuse/trunk/src/netcfg.cpp
r555 r577 512 512 else 513 513 { 514 // No event waiting... We can't wait for long, because we are pretending to broadcast. 515 milli_wait(5); // ECS - Added so waiting in dialog doesn't use 100% of CPU 514 // No event waiting... We can't wait for long, because we are 515 // pretending to broadcast. 516 // ECS - Added so waiting in dialog doesn't use 100% of CPU 517 Timer tmp; tmp.WaitMs(5); 516 518 } 517 519 } -
abuse/trunk/src/sdlport/event.cpp
r555 r577 136 136 137 137 if (!ewaiting) 138 milli_wait( 1 ); // Sleep for 1 millisecond if there are no events 138 { 139 // Sleep for 1 millisecond if there are no events 140 Timer tmp; tmp.WaitMs(1); 141 } 139 142 } 140 143 -
abuse/trunk/src/sdlport/timing.cpp
r555 r577 65 65 } 66 66 67 void timer_init()68 {69 /* Do Nothing */70 }71 72 void timer_uninit()73 {74 /* Do Nothing */75 }76 77 void milli_wait( unsigned wait_time )78 {79 struct timespec ts = { 0, wait_time * 1000000 };80 nanosleep( &ts, NULL );81 }82
Note: See TracChangeset
for help on using the changeset viewer.