Example #1
0
/* Advance game time by rate each second. Timer is stopped after after the time
 * has been advanced as requested.
 */
void TimedAdvance::timed(uint32 evtime)
{
    uint32 milliseconds = (evtime - prev_evtime) > 0 ? (evtime - prev_evtime) : 1;
    uint32 fraction = 1000 / milliseconds; // % of second
    uint32 minutes_per_fraction = rate / (fraction > 0 ? fraction : 1);
    bool hour_passed = false; // another hour has passed
    prev_evtime = evtime;

    for(uint32 m = 0; m < minutes_per_fraction; m++)
    {
        clock->inc_minute();
        minutes += 1;
        if(++minutes_this_hour > 59)
        {
            minutes_this_hour = 0;
            hour_passed = true;
        }
        if(time_passed())
            break;
    }
    Game::get_game()->time_changed();

    if(hour_passed && callback_target) // another hour has passed
        message(MESG_TIMED, &evtime);

    if(time_passed())
    {
        DEBUG(0,LEVEL_DEBUGGING,"~TimedAdvance(): now %02d:%02d\n", clock->get_hour(), clock->get_minute());
        if(callback_target && !hour_passed) // make sure to call target
            message(MESG_TIMED, &evtime);
        stop(); // done
    }
}
Example #2
0
int main(int argc, char *argv[]) {
  int i, return_value, size;
  struct timeval start, end, diff;/* Holds start, end and run time */  
  void *memstart, *memend;
  
  if(argc <2) size = MAXSIZE;
  else {
  	size = atoi(argv[1]);  	
  }
  if(size>MAXSIZE) size = MAXSIZE;  
  
  fprintf(stderr, "size: %d. ", size);
  return_value = gettimeofday(&start, NULL);
  if(return_value == -1){ perror("Couldn't get time"); exit(1); }
  
#ifdef MMAP
  memstart = endHeap();
#else
  memstart = (void *)sbrk(0);
#endif
  
  /* Malloc ints */
  for(i=0; i<size; i++) {
  	ints[i] = malloc(sizeof(int));
  }
  
  /* Malloc longs */
  for(i=0; i<size; i++) {
  	longs[i] = malloc(sizeof(long));
  }
  
   /* Free everything */
   for(i=0; i<size; i++) {
  	free(longs[i]);
  	free(ints[i]);
  } 
  
#ifdef MMAP
  memend = endHeap();
#else
  memend = (void *) sbrk(0);
#endif
  
  return_value = gettimeofday(&end, NULL);
  if(return_value == -1){ perror("Couldn't get time"); exit(1); }
  diff = time_passed(start, end);
  fprintf(stderr, "Exe time: %d:%.6d s\nMemory consumed: %ld\n",
          (int)diff.tv_sec, (int)diff.tv_usec, (unsigned long)(memend-memstart));
  return 0;
}
Example #3
0
BOOL gigaso_init(){
	if(4 == sizeof(void *)){
		my_assert(24 == sizeof(FileEntry), 0);
	}else{
		my_assert(40 == sizeof(FileEntry), 0);
	}
	breakpad_init();
	//request_dump();
	init_chinese();
	setlocale(LC_ALL, "");
	load_online_db(MAC_DRIVE_INDEX);
    //TODO: 根据mount情况得到onlinedb,然后load。
    printf("scan passed %d ms.\n",time_passed(scan));
	StartMonitorThread(MAC_DRIVE_INDEX);
	return 1;
}