Exemple #1
0
QString Task::toText() const {
    QString timeString = timeToString(getTotalTime());

    return QString("%1 (%2)")
            .arg(getName())
            .arg(timeString);
}
void UpdateThreadContext::update()
{
    lastTime = currentTime;
    currentTime = timeGetRaw();

    lastTicks = currentTicks;
    currentTicks = static_cast<uint64_t>(getTotalTime() / getTickTime());
}
float ElapsedTimer::getTime() const
{
	assert(m_startTime != YAM_TIME_TYPE(-1) ); // You must call reset atleast once before first call to getTime.
	YAM_TIME_TYPE curTime = getTotalTime();

	float deltaTime = float(curTime-m_startTime)/float(getTimeScale());
	assert( deltaTime >= 0.0f ); // WTF? 
	return deltaTime;
}	
	SkeletalAnimation::SkeletalAnimation(const InitInfo &initInfo, const Skeleton &owner) :
		skeleton(owner),
		totalTime(getTotalTime(initInfo.keyframeSequences))
	{
		HASSERT(initInfo.keyframeSequences.size() == owner.numJoints);
		
		keyframeSequences = uninitializedAlloc<SkeletonJointKeyframeSequence>(initInfo.keyframeSequences.size());
		for (uint i = 0; i < initInfo.keyframeSequences.size(); i++)
			new(&keyframeSequences[i]) SkeletonJointKeyframeSequence(initInfo.keyframeSequences[i]);
	}
Exemple #5
0
int readFromPipe(int inputPipe, char * buffer, int * terminalPid, TerminalList * termlist) {
  int len;
  int op;
  int statsPipe;
  double totalTime;
  TESTTRUE((read(inputPipe, &op, sizeof(int))==sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
  printf("\nNew operation:\n");
  printf("op: %d\n", op);
  if (op==0) {
    TESTTRUE((read(inputPipe, &len, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("len: %d\n", len);
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("pid: %d\n", *terminalPid);
    TESTTRUE((read(inputPipe, buffer, len) == len), "Erro no formato do pipe (" _AT_ ")\n");
    buffer[len]=0;
    return 0;
  } else if (op==1) { //informacao que foi criado um novo terminal
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    lst_insert(termlist, *terminalPid);
    printf("pid: %d\n", *terminalPid);
    return 1;
  } else if (op==2) { //informacao que foi fechado um terminal
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    lst_remove(termlist, *terminalPid);
    printf("pid: %d\n", *terminalPid);
    return 2;
  } else if (op==3) { //informacao que e para se fechar a par-shell
    exitCalled = 1;
    return 3;
  } else if (op==4)  {//recebeu um stats
    TESTTRUE((read(inputPipe, &len, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("len: %d\n", len);
    TESTTRUE((read(inputPipe, terminalPid, sizeof(int)) == sizeof(int)), "Erro no formato do pipe (" _AT_ ")\n");
    printf("pid: %d\n", *terminalPid);
    TESTTRUE((read(inputPipe, buffer, len) == len), "Erro no formato do pipe (" _AT_ ")\n");
    buffer[len]=0;
    if ((statsPipe = open(buffer, O_WRONLY)) < 0) {
      fprintf(stderr, "Erro ao abrir o ficheiro de output " INPUT_FILE "\n");
      exit(EXIT_FAILURE);
    }
    totalTime = getTotalTime();
    if (write(statsPipe, (char*)&runningProcesses, sizeof(int)) != sizeof(int)) {
      fprintf(stderr, "Warning: erro a escrever para um pipe\n");
    }
    if (write(statsPipe, (char*)&totalTime, sizeof(double)) != sizeof(double)) {
      fprintf(stderr, "Warning: erro a escrever para um pipe \n");
    }
    if (close(statsPipe)) {
      fprintf(stderr, "Warning: erro ao fechar um pipe \n");
    }
    return 4;
  }
  fprintf(stderr,"Warning: Unknown operator!\n");
  return -1;
}
void
ILSGlobalSolverSequential::optimize (vector < ROUTE_DATA_TYPE > &route, int once) {
    unsigned long   temp;
    INIT_TRACEF temp = routeLength (route, coords);
    bestGlobalMinimaLengths.push_back (temp);
    bestGlobalMinima.push_back (route);
    trace ("[%s] Initial minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
           localSolver->getDescription().c_str(), bestGlobalMinima.size(),
           bestGlobalMinimaLengths.back(),
           100.0 * (double) bestGlobalMinimaLengths.back() / (double) solution);
    tracef ("%ld, %.5f\n", bestGlobalMinimaLengths.back(),
            100.0 * (double) bestGlobalMinimaLengths.back() / (double) solution);

    do {
        localSolver->optimize (route, bestGlobalMinimaLengths);
        temp = routeLength (route, coords);

        if (temp < bestGlobalMinimaLengths.back() ) {
            bestGlobalMinimaLengths.push_back (temp);
            bestGlobalMinima.push_back (route);
            trace
            ("[%s] New global minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
             localSolver->getDescription().c_str(), bestGlobalMinima.size(),
             bestGlobalMinimaLengths.back(),
             100.0 * (double) bestGlobalMinimaLengths.back() /
             (double) solution);
            tracef ("%ld, %.5f\n", bestGlobalMinimaLengths.back(),
                    100.0 * (double) bestGlobalMinimaLengths.back() /
                    (double) solution);

        } else {
            route = bestGlobalMinima.back();
        }

        if (once == 1)
            break;

        randomPerturbation (route);
    } while ( (solution * (1.0f + error) < bestGlobalMinimaLengths.back() )
              && (timelimit == 0 || (getTotalTime() < timelimit) ) );
}
VideoFrame VideoBuffer::getVideoFrame(float pct){
    return getVideoFrame(getLastTimestamp()-(getInitTime()+getTotalTime()*pct));
}
void MPlayerMediaWidget::readStandardOutput()
{
	QByteArray data = process.readAllStandardOutput();
	standardError.write(data); // forward
	standardError.flush();

	if ((data == "\n") || (data.indexOf("\n\n") >= 0)) {
		process.write("pausing_keep_force get_property path\n");
	}

	bool videoPropertiesChanged = false;
	QStringList audioStreams = getAudioStreams();
	bool audioStreamsChanged = false;
	QStringList subtitles = getSubtitles();
	bool subtitlesChanged = false;

	foreach (const QByteArray &line, data.split('\n')) {
		if (line.startsWith("VO: ")) {
			videoPropertiesChanged = true;
			continue;
		}

		if (line.startsWith("audio stream: ")) {
			int begin = 14;
			int end = line.indexOf(' ', begin);

			if (end < 0) {
				end = line.size();
			}

			int audioStreamIndex = line.mid(begin, end - begin).toInt();

			while (audioStreams.size() < audioStreamIndex) {
				audioStreams.append(QString::number(audioStreams.size() + 1));
			}

			while (audioIds.size() < audioStreamIndex) {
				audioIds.append(-1);
			}

			audioStreams.erase(audioStreams.begin() + audioStreamIndex,
				audioStreams.end());
			audioIds.erase(audioIds.begin() + audioStreamIndex, audioIds.end());
			QString audioStream;
			begin = line.indexOf("language: ");

			if (begin >= 0) {
				begin += 10;
				end = line.indexOf(' ', begin);

				if (end < 0) {
					end = line.size();
				}

				audioStream = line.mid(begin, end - begin);
			}

			if (audioStream.isEmpty()) {
				audioStream = QString::number(audioStreams.size() + 1);
			}

			int audioId = -1;
			begin = line.indexOf("aid: ");

			if (begin >= 0) {
				begin += 5;
				end = line.indexOf('.', begin);

				if (end < 0) {
					end = line.size();
				}

				audioId = line.mid(begin, end - begin).toInt();
			}

			audioStreams.append(audioStream);
			audioIds.append(audioId);
			audioStreamsChanged = true;
			continue;
		}

		if (line.startsWith("subtitle ")) {
			int begin = line.indexOf("( sid ): ");

			if (begin < 0) {
				continue;
			}

			begin += 9;
			int end = line.indexOf(' ', begin);

			if (end < 0) {
				end = line.size();
			}

			int subtitleIndex = line.mid(begin, end - begin).toInt();

			while (subtitles.size() < subtitleIndex) {
				subtitles.append(QString::number(subtitles.size() + 1));
			}

			subtitles.erase(subtitles.begin() + subtitleIndex, subtitles.end());
			QString subtitle;
			begin = line.indexOf("language: ");

			if (begin >= 0) {
				begin += 10;
				end = line.indexOf(' ', begin);

				if (end < 0) {
					end = line.size();
				}

				subtitle = line.mid(begin, end - begin);
			}

			if (subtitle.isEmpty()) {
				subtitle = QString::number(subtitles.size() + 1);
			}

			subtitles.append(subtitle);
			subtitlesChanged = true;
			continue;
		}

		if (line == "ANS_path=(null)") {
			switch (getPlaybackStatus()) {
			case MediaWidget::Idle:
				break;
			case MediaWidget::Playing:
			case MediaWidget::Paused:
				playbackFinished();
				break;
			}

			resetState();
			continue;
		}

		if (line.startsWith("ANS_length=")) {
			int totalTime = (line.mid(11).toFloat() * 1000 + 0.5);
			updateCurrentTotalTime(getCurrentTime(), totalTime);
			continue;
		}

		if (line.startsWith("ANS_time_pos=")) {
			int currentTime = (line.mid(13).toFloat() * 1000 + 0.5);
			updateCurrentTotalTime(currentTime, getTotalTime());
			continue;
		}

		if (line.startsWith("ANS_width=")) {
			videoWidth = line.mid(10).toInt();

			if (videoWidth < 0) {
				videoWidth = 0;
			}

			continue;
		}

		if (line.startsWith("ANS_height=")) {
			videoHeight = line.mid(11).toInt();

			if (videoHeight < 0) {
				videoHeight = 0;
			}

			continue;
		}

		if (line.startsWith("ANS_aspect=")) {
			videoAspectRatio = line.mid(11).toFloat();

			if ((videoAspectRatio > 0.01) && (videoAspectRatio < 100)) {
				// ok
			} else {
				videoAspectRatio = (videoWidth / float(videoHeight));

				if ((videoAspectRatio > 0.01) && (videoAspectRatio < 100)) {
					// ok
				} else {
					videoAspectRatio = 1;
				}
			}

			updateVideoWidgetGeometry();
			continue;
		}

		if (line.startsWith("ANS_switch_audio=")) {
			int audioId = line.mid(17).toInt();
			updateCurrentAudioStream(audioIds.indexOf(audioId));
			continue;
		}

		if (line.startsWith("ANS_sub=")) {
			int currentSubtitle = line.mid(8).toInt();
			updateCurrentSubtitle(currentSubtitle);
			continue;
		}
	}

	if (videoPropertiesChanged) {
		process.write("pausing_keep_force get_property width\n"
			"pausing_keep_force get_property height\n"
			"pausing_keep_force get_property aspect\n");
	}

	if (audioStreamsChanged) {
		updateAudioStreams(audioStreams);
		process.write("pausing_keep_force get_property switch_audio\n");
	}

	if (subtitlesChanged) {
		updateSubtitles(subtitles);
		process.write("pausing_keep_force get_property sub\n");
	}
}
Exemple #9
0
AudioFrame * myAudioBuffer::getAudioFrame(float pct) {
    return getAudioFrame(getLastTimestamp()-(getInitTime()+getTotalTime()*pct));
}
void
ILSGlobalSolverMT::optimize (vector < ROUTE_DATA_TYPE > &route, int once) {
    unsigned long   temp;
    INIT_TRACEF temp = routeLength (route, coords);
    bestLocalMinimaLengths.push_back (temp);
    bestLocalMinima.push_back (route);

    // initial solution
    if (bestGlobalMinimaLengths.empty() ) {
        pthread_mutex_lock (&globalRouteMutex);

        if (bestGlobalMinimaLengths.empty() ) {
            bestGlobalMinimaLengths.push_back (temp);
            bestGlobalMinima.push_back (route);

            if (comm == 1) {
                trace
                ("[%s] Initial global minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
                 localSolver->getDescription().c_str(), bestGlobalMinima.size(),
                 bestGlobalMinimaLengths.back(),
                 100.0 * (double) bestGlobalMinimaLengths.back() /
                 (double) solution);
                tracef ("%ld, %.5f\n", bestGlobalMinimaLengths.back(),
                        100.0 * (double) bestGlobalMinimaLengths.back() /
                        (double) solution);
            }
        }

        pthread_mutex_unlock (&globalRouteMutex);
    }

    if (comm != 1) {
        trace
        ("[%s] Initial local minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
         localSolver->getDescription().c_str(), bestLocalMinima.size(),
         bestLocalMinimaLengths.back(),
         100.0 * (double) bestLocalMinimaLengths.back() / (double) solution);
        tracef ("%ld, %.5f\n", bestLocalMinimaLengths.back(),
                100.0 * (double) bestLocalMinimaLengths.back() / (double) solution);
    }

    do {
        if (comm == 1) {
            // read the best solution
            if (bestGlobalMinimaLengths.back() < bestGlobalMinimaLengths.back() ) {
                bestGlobalMinimaLengths.push_back (bestGlobalMinimaLengths.back() );
                bestGlobalMinima.push_back (bestGlobalMinima.back() );
                route = bestGlobalMinima.back();
            }
        }

        localSolver->optimize (route, bestGlobalMinimaLengths);
        temp = routeLength (route, coords);

        if (temp < bestLocalMinimaLengths.back() ) {
            bestLocalMinimaLengths.push_back (temp);
            bestLocalMinima.push_back (route);

            if (comm != 1 && !args->showLocalOptimizationInfo) {
                trace
                ("[%s] New local minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
                 localSolver->getDescription().c_str(), bestLocalMinima.size(),
                 bestLocalMinimaLengths.back(),
                 100.0 * (double) bestLocalMinimaLengths.back() /
                 (double) solution);
                tracef ("%ld, %.5f\n", bestLocalMinimaLengths.back(),
                        100.0 * (double) bestLocalMinimaLengths.back() /
                        (double) solution);
            }

            if (temp < bestGlobalMinimaLengths.back() ) {
                pthread_mutex_lock (&globalRouteMutex);

                if (temp < bestGlobalMinimaLengths.back() ) {
                    bestGlobalMinimaLengths.push_back (temp);
                    bestGlobalMinima.push_back (route);

                    if ( (comm == 1 || args->pthreads > 1)
                            && !args->showLocalOptimizationInfo) {
                        trace
                        ("[%s] New global minimum (%ld) -> Length: %ld = %.5f%% of the target\n",
                         localSolver->getDescription().c_str(),
                         bestGlobalMinima.size(), bestGlobalMinimaLengths.back(),
                         100.0 * (double) bestGlobalMinimaLengths.back() /
                         (double) solution);
                        tracef ("%ld, %.5f\n", bestGlobalMinimaLengths.back(),
                                100.0 * (double) bestGlobalMinimaLengths.back() /
                                (double) solution);
                    }
                }

                pthread_mutex_unlock (&globalRouteMutex);
            }

        } else {
            if (comm == 1) {
                route = bestGlobalMinima.back();

            } else {
                route = bestLocalMinima.back();
            }
        }

        if (once == 1)
            break;

        randomPerturbation (route);
    } while ( (solution * (1.0f + error) < bestGlobalMinimaLengths.back() )
              && (timelimit == 0 || (getTotalTime() < timelimit) ) );
}
void GPUTrafficManager::_Step()
{
  bool flits_in_flight = false;
  for(int c = 0; c < _classes; ++c) {
    flits_in_flight |= !_total_in_flight_flits[c].empty();
  }
  if(flits_in_flight && (_deadlock_timer++ >= _deadlock_warn_timeout)){
    _deadlock_timer = 0;
    cout << "WARNING: Possible network deadlock.\n";
  }
  
  vector<map<int, Flit *> > flits(_subnets);
  
  for ( int subnet = 0; subnet < _subnets; ++subnet ) {
    for ( int n = 0; n < _nodes; ++n ) {
      Flit * const f = _net[subnet]->ReadFlit( n );
      if ( f ) {
        if(f->watch) {
          *gWatchOut << GetSimTime() << " | "
          << "node" << n << " | "
          << "Ejecting flit " << f->id
          << " (packet " << f->pid << ")"
          << " from VC " << f->vc
          << "." << endl;
        }

        if(g_hpcl_comp_config.hpcl_comp_en == 0) {
          g_icnt_interface->WriteOutBuffer(subnet, n, f);
          //added by kh(030816)
          g_hpcl_network_anal->add_sample(hpcl_network_anal::NORMAL_FLIT_NO, 1);
          ///

        } else {
	  //added by kh (030816)
	  //(2.1.a) all reply flits (even write reply) are injected to decompressor for maintaining the order of flits.
	  //coming from the same vc
	  //Decompression: WRITE_REPLY should go through decomp, although no data is compressed.
	  //READ_REPLY = {f1,f2,f3,f4,f5}, WRITE_REPLY = {f6}
	  //Problematic case queue: f1,f2,f6,f3,f4,f5.
	  if(f->type == Flit::READ_REPLY || f->type == Flit::WRITE_REPLY) {	//only sm receives

	    assert(g_hpcl_global_decomp_pl_2B[n]);
	    //inject a flit to decompressor
	    hpcl_comp_pl_data* pl_data = new hpcl_comp_pl_data;
	    pl_data->add_comp_pl_data(f);
	    g_hpcl_global_decomp_pl_2B[n]->set_input_data(pl_data);

	    //added by kh (030316)
	    //set vc info to compressed flits.
	    for(int i = 0; i < f->compressed_other_flits.size(); i++) {
	      Flit* cf = f->compressed_other_flits[i];
	      assert(cf);
	      cf->vc = f->vc;
	    }
	    ///
	    //delete pl_data;

	    //added by kh (030816)
	    g_hpcl_network_anal->add_sample(hpcl_network_anal::NORMAL_FLIT_NO, 1);

	    if(f->compressed_other_flits.size() > 0) {
	      g_hpcl_network_anal->add_sample(hpcl_network_anal::READ_REPLY_COMP_FLIT_NO, f->compressed_other_flits.size()+1);
	    } else {
	      g_hpcl_network_anal->add_sample(hpcl_network_anal::READ_REPLY_UNCOMP_FLIT_NO, 1);
	    }
	    ///

	  } else if(f->type == Flit::CTRL_MSG) {	//(2.2.a) all ctrl flits are injected to decompressor

	    //std::cout << "f->id " << f->id << " f->src " << f->src << " f->dest " << f->dest << " node " << n << std::endl;
	    hpcl_comp_pl_data* pl_data = new hpcl_comp_pl_data;
	    pl_data->add_comp_pl_data(f);
	    g_hpcl_global_decomp_pl_2B[n]->set_input_data(pl_data);

	    //added by kh (030816)
	    g_hpcl_network_anal->add_sample(hpcl_network_anal::CTRL_FLIT_NO,1);
	    ///

	  } else {

	    g_icnt_interface->WriteOutBuffer(subnet, n, f);

	    //added by kh (030816)
	    g_hpcl_network_anal->add_sample(hpcl_network_anal::NORMAL_FLIT_NO, 1);
	    ///

	  }
	  ///
        }
      }
      

      g_icnt_interface->Transfer2BoundaryBuffer(subnet, n);
      Flit* const ejected_flit = g_icnt_interface->GetEjectedFlit(subnet, n);
      if (ejected_flit) {
        if(ejected_flit->head)
          assert(ejected_flit->dest == n);
        if(ejected_flit->watch) {
          *gWatchOut << GetSimTime() << " | "
          << "node" << n << " | "
          << "Ejected flit " << ejected_flit->id
          << " (packet " << ejected_flit->pid
          << " VC " << ejected_flit->vc << ")"
          << "from ejection buffer." << endl;
        }
        flits[subnet].insert(make_pair(n, ejected_flit));
        if((_sim_state == warming_up) || (_sim_state == running)) {
          ++_accepted_flits[ejected_flit->cl][n];
          if(ejected_flit->tail) {
            ++_accepted_packets[ejected_flit->cl][n];
          }
        }
      }
    
      // Processing the credit From the network
      Credit * const c = _net[subnet]->ReadCredit( n );
      if ( c ) {
#ifdef TRACK_FLOWS
        for(set<int>::const_iterator iter = c->vc.begin(); iter != c->vc.end(); ++iter) {
          int const vc = *iter;
          assert(!_outstanding_classes[n][subnet][vc].empty());
          int cl = _outstanding_classes[n][subnet][vc].front();
          _outstanding_classes[n][subnet][vc].pop();
          assert(_outstanding_credits[cl][subnet][n] > 0);
          --_outstanding_credits[cl][subnet][n];
        }
#endif
        _buf_states[n][subnet]->ProcessCredit(c);
        c->Free();
      }
    }
    _net[subnet]->ReadInputs( );
  }


  if(g_hpcl_comp_config.hpcl_comp_en == 1)
  {
    //added by kh (030816)
    //(2.3) Decompressor
    for(int i = 0; i < g_hpcl_global_decomp_pl_2B.size(); i++)
    {
      if(!g_hpcl_global_decomp_pl_2B[i])	continue;

      g_hpcl_global_decomp_pl_2B[i]->run(getTime()+getTotalTime());
      hpcl_comp_pl_data* comp_pl_data = g_hpcl_global_decomp_pl_2B[i]->get_output_data();
      Flit* flit = comp_pl_data->get_flit_ptr();
      if(flit) {
	int subnet = 0;
	assert(flit->const_dest == i);
	//std::cout << "Flit " << flit->id << " type " << flit->type << " is out from decomp" << std::endl;
	/*
	std::cout << GetSimTime() << "| MYEJECT | node " << i << " Flit " << flit->id << " type " << flit->type << " tail " << flit->tail << " vc " << flit->vc;
	if(flit->type == Flit::ANY_TYPE)	std::cout << " ctrl " << std::endl;
	else				std::cout << " mf " << ((mem_fetch*)flit->data)->get_request_uid() << std::endl;
	*/

	//std::cout << "Flit " << flit->id << " enc_status " << flit->m_enc_status;
	#ifdef CORRECTNESS_CHECK
	if(flit->m_enc_status == 1) {
	  std::cout << "dec_status " << flit->check_correctness() << std::endl;
	  if(flit->check_correctness() == false) {

	    printf("flit %d has incorrect decoding!\n", flit->id);

	    printf("\traw_data = ");
	    for(int k = flit->raw_data.size()-1; k >=0; k--) {
		    printf("%02x", flit->raw_data[k]);
	    }
	    printf("\n");

	    printf("\tdec_data = ");
	    for(int k = flit->decomp_data.size()-1; k >=0; k--) {
		    printf("%02x", flit->decomp_data[k]);
	    }
	    printf("\n");
	  }
	}
	#endif

	g_icnt_interface->WriteOutBuffer(subnet, i, flit);
      }

      //reset output data
      g_hpcl_global_decomp_pl_2B[i]->reset_output_data();
    }
    ///


    //added by kh (030816)
    //(1.2.c) generate/inject ctrl flit is injected to NI injection buffer
    for(int i = 0; i < g_hpcl_global_comp_pl_2B.size(); i++)
    {
      if(!g_hpcl_global_comp_pl_2B[i])	continue;
      if(g_hpcl_global_comp_pl_2B[i]->has_out_dict_ctrl_msg() == false)	continue;
      if(g_hpcl_global_comp_pl_2B[i]->get_state() == hpcl_comp_pl<unsigned short>::HPCL_COMP_RUN)	continue;

      hpcl_dict_ctrl_msg<unsigned short>* ctrl_msg = g_hpcl_global_comp_pl_2B[i]->front_out_dict_ctrl_msg();
      int packet_size = 1;	//1 flit
      Flit::FlitType packet_type = Flit::CTRL_MSG;
      void* data = NULL;
      assert(ctrl_msg->get_dest_node()>=0);
      int subnet = 0;
      int response_size = 32; 	//32bytes

      //send ctrl from MC
      int sender_device_id = -1;
      if(g_mc_placement_config.is_mc_node(i)) {
	sender_device_id = g_mc_placement_config.get_mc_node_index(i) + 56;	//56 SMs and 8 MCs
      }
      assert(sender_device_id >= 0);

      int sender_node_id = i;
      int receiver_node_id = ctrl_msg->get_dest_node();
      int receiver_device_id = g_mc_placement_config.get_sm_node_index(receiver_node_id);

      assert(sender_node_id>=0);
      assert(receiver_node_id>=0);
      if(g_icnt_interface->HasBuffer(sender_device_id, response_size)) {
	//std::cout << getTime()+getTotalTime() << " | " << " PUSH2 | " << " input " << sender_device_id << " output " << receiver_device_id << " ctrl_msg " << ctrl_msg->get_id();
	//std::cout << std::endl;
	_GeneratePacket(sender_node_id, -1, 0, getTime(), subnet, packet_size, packet_type, ctrl_msg, receiver_node_id);
	g_hpcl_global_comp_pl_2B[i]->pop_out_dict_ctrl_msg();

  //      std::cout << "ctrl_msg | id " << ctrl_msg->get_id();
  //      std::cout << " | src_node " << ctrl_msg->get_src_node();
  //      std::cout << " | dest_node " << ctrl_msg->get_dest_node();
  //      std::cout << " | word_index " << ctrl_msg->get_word_index();
  //      std::cout << " | word " << ctrl_msg->get_new_word() << std::endl;;
  //
  //      g_hpcl_global_comp_pl_2B[i]->validate_word(ctrl_msg->get_dest_node(), ctrl_msg->get_word_index(), ctrl_msg->get_new_word());
      }
    }
    ///

  }

// GPGPUSim will generate/inject packets from interconnection interface
#if 0
  if ( !_empty_network ) {
    _Inject();
  }
#endif
  
  for(int subnet = 0; subnet < _subnets; ++subnet) {
    
    for(int n = 0; n < _nodes; ++n) {
      
      Flit * f = NULL;
      
      BufferState * const dest_buf = _buf_states[n][subnet];
      
      int const last_class = _last_class[n][subnet];
      
      int class_limit = _classes;
      
      if(_hold_switch_for_packet) {
        list<Flit *> const & pp = _input_queue[subnet][n][last_class];
        if(!pp.empty() && !pp.front()->head &&
           !dest_buf->IsFullFor(pp.front()->vc)) {
          f = pp.front();
          assert(f->vc == _last_vc[n][subnet][last_class]);
          
          // if we're holding the connection, we don't need to check that class
          // again in the for loop
          --class_limit;
        }
      }
      
      for(int i = 1; i <= class_limit; ++i) {
        
        int const c = (last_class + i) % _classes;
        
        list<Flit *> const & pp = _input_queue[subnet][n][c];
        
        if(pp.empty()) {
          continue;
        }
        
        Flit * const cf = pp.front();
        assert(cf);
        assert(cf->cl == c);
        assert(cf->subnetwork == subnet);

        if(g_hpcl_comp_config.hpcl_comp_en == 1) {
	  //added by kh (030816)
	  //If compressor is busy with compressing flits of a packet,
	  //don't inject a head flit of a new packet to the busy compressor
	  //compressor is only for read reply, but write reply goes through the compressor to avoid intermixed flits from different packets
	  //Thus, the following filtering is not restricted to read reply, thus we have no flit type checking to read reply.
	  if(g_mc_placement_config.is_mc_node(n) == true && cf->head == true) {
	    if(g_hpcl_global_comp_pl_2B[n] && g_hpcl_global_comp_pl_2B[n]->get_state() == hpcl_comp_pl<unsigned short>::HPCL_COMP_RUN) {
	      f = NULL;
	      break;
	    }
	  }
	  ///
        }

        if(f && (f->pri >= cf->pri)) {
          continue;
        }
        
        //KH: routing output port is decided here.
        if(cf->head && cf->vc == -1) { // Find first available VC
          
          //std::cout << "_Step is called!!!!" << std::endl;
          //assert(1 == 0);

          OutputSet route_set;
          _rf(NULL, cf, -1, &route_set, true);
          set<OutputSet::sSetElement> const & os = route_set.GetSet();
          assert(os.size() == 1);
          OutputSet::sSetElement const & se = *os.begin();
          assert(se.output_port == -1);
          int vc_start = se.vc_start;
          int vc_end = se.vc_end;
          int vc_count = vc_end - vc_start + 1;
          if(_noq) {
            assert(_lookahead_routing);
            const FlitChannel * inject = _net[subnet]->GetInject(n);
            const Router * router = inject->GetSink();
            assert(router);
            int in_channel = inject->GetSinkPort();
            

            // NOTE: Because the lookahead is not for injection, but for the
            // first hop, we have to temporarily set cf's VC to be non-negative
            // in order to avoid seting of an assertion in the routing function.
            cf->vc = vc_start;
            _rf(router, cf, in_channel, &cf->la_route_set, false);
            cf->vc = -1;
            
            if(cf->watch) {
              *gWatchOut << GetSimTime() << " | "
              << "node" << n << " | "
              << "Generating lookahead routing info for flit " << cf->id
              << " (NOQ)." << endl;
            }
            set<OutputSet::sSetElement> const sl = cf->la_route_set.GetSet();
            assert(sl.size() == 1);
            int next_output = sl.begin()->output_port;
            vc_count /= router->NumOutputs();
            vc_start += next_output * vc_count;
            vc_end = vc_start + vc_count - 1;
            assert(vc_start >= se.vc_start && vc_start <= se.vc_end);
            assert(vc_end >= se.vc_start && vc_end <= se.vc_end);
            assert(vc_start <= vc_end);
          }
          if(cf->watch) {
            *gWatchOut << GetSimTime() << " | " << FullName() << " | "
            << "Finding output VC for flit " << cf->id
            << ":" << endl;
          }
          for(int i = 1; i <= vc_count; ++i) {
            int const lvc = _last_vc[n][subnet][c];
            int const vc =
            (lvc < vc_start || lvc > vc_end) ?
            vc_start :
            (vc_start + (lvc - vc_start + i) % vc_count);
            assert((vc >= vc_start) && (vc <= vc_end));
            if(!dest_buf->IsAvailableFor(vc)) {
              if(cf->watch) {
                *gWatchOut << GetSimTime() << " | " << FullName() << " | "
                << "  Output VC " << vc << " is busy." << endl;
              }
            } else {
              if(dest_buf->IsFullFor(vc)) {
                if(cf->watch) {
                  *gWatchOut << GetSimTime() << " | " << FullName() << " | "
                  << "  Output VC " << vc << " is full." << endl;
                }
              } else {
                if(cf->watch) {
                  *gWatchOut << GetSimTime() << " | " << FullName() << " | "
                  << "  Selected output VC " << vc << "." << endl;
                }
                cf->vc = vc;
                break;
              }
            }
          }
        }
        
        if(cf->vc == -1) {
          if(cf->watch) {
            *gWatchOut << GetSimTime() << " | " << FullName() << " | "
            << "No output VC found for flit " << cf->id
            << "." << endl;
          }
        } else {
          if(dest_buf->IsFullFor(cf->vc)) {
            if(cf->watch) {
              *gWatchOut << GetSimTime() << " | " << FullName() << " | "
              << "Selected output VC " << cf->vc
              << " is full for flit " << cf->id
              << "." << endl;
            }
          } else {
            f = cf;
          }
        }
      }
      
      if(f) {
        
        assert(f->subnetwork == subnet);
        
        int const c = f->cl;
        
        if(f->head) {
          
          if (_lookahead_routing) {
            if(!_noq) {
              const FlitChannel * inject = _net[subnet]->GetInject(n);
              const Router * router = inject->GetSink();
              assert(router);
              int in_channel = inject->GetSinkPort();
              _rf(router, f, in_channel, &f->la_route_set, false);
              if(f->watch) {
                *gWatchOut << GetSimTime() << " | "
                << "node" << n << " | "
                << "Generating lookahead routing info for flit " << f->id
                << "." << endl;
              }
            } else if(f->watch) {
              *gWatchOut << GetSimTime() << " | "
              << "node" << n << " | "
              << "Already generated lookahead routing info for flit " << f->id
              << " (NOQ)." << endl;
            }
          } else {
            f->la_route_set.Clear();
          }
          
          dest_buf->TakeBuffer(f->vc);
          _last_vc[n][subnet][c] = f->vc;
        }
        
        _last_class[n][subnet] = c;
        
        _input_queue[subnet][n][c].pop_front();
        
#ifdef TRACK_FLOWS
        ++_outstanding_credits[c][subnet][n];
        _outstanding_classes[n][subnet][f->vc].push(c);
#endif
        

        if(g_hpcl_comp_config.hpcl_comp_en == 0) {
	  dest_buf->SendingFlit(f);
        } else {
	  //added by kh(030816)
	  //(1.1.a) send a head flit first: update buffer state
	  if(g_mc_placement_config.is_mc_node(n) == true && f->type == Flit::READ_REPLY) {
	      if(f->head)	dest_buf->SendingFlit(f);
	      //skip for other flits
	  } else {
	      dest_buf->SendingFlit(f);
	  }
	  ///
        }

        if(_pri_type == network_age_based) {
          f->pri = numeric_limits<int>::max() - _time;
          assert(f->pri >= 0);
        }
        
        if(f->watch) {
          *gWatchOut << GetSimTime() << " | "
          << "node" << n << " | "
          << "Injecting flit " << f->id
          << " into subnet " << subnet
          << " at time " << _time
          << " with priority " << f->pri
          << "." << endl;
        }
        f->itime = _time;
        
        // Pass VC "back"
        if(!_input_queue[subnet][n][c].empty() && !f->tail) {
          Flit * const nf = _input_queue[subnet][n][c].front();
          nf->vc = f->vc;
        }
        
        if((_sim_state == warming_up) || (_sim_state == running)) {
          ++_sent_flits[c][n];

          //added by kh(070215)
          ++_sent_flits_net[subnet][n];


          if(f->head) {
            ++_sent_packets[c][n];

            //added by kh(030816)
            if(f->type < Flit::ANY_TYPE) {
	      //added by kh(121715)
	      if(g_mc_placement_config.is_sm_node(n)) {
		  ((mem_fetch*)f->data)->set_status(HEAD_FLIT_INJECTED_TO_INJECT_BUF_IN_SM, _time);

		  //added by kh(122815)
		  double req_queuing_lat_in_sm = _time - ((mem_fetch*)f->data)->get_timestamp(HEAD_FLIT_INJECTED_TO_NI_INPUT_BUF_IN_SM);
		  g_hpcl_network_anal->add_sample(hpcl_network_anal::REQ_QUEUING_LAT_IN_SM, req_queuing_lat_in_sm);
		  ///

	      } else if(g_mc_placement_config.is_mc_node(n)) {
		  ((mem_fetch*)f->data)->set_status(HEAD_FLIT_INJECTED_TO_INJECT_BUF_IN_MEM, _time);
		  //added by kh(122815)
		  double rep_queuing_lat_in_mc = _time - ((mem_fetch*)f->data)->get_timestamp(HEAD_FLIT_INJECTED_TO_NI_INPUT_BUF_IN_MEM);
		  g_hpcl_network_anal->add_sample(hpcl_network_anal::REP_QUEUING_LAT_IN_MC, rep_queuing_lat_in_mc);
		  ///
	      }
	      ///
            }
          }
        }
        
#ifdef TRACK_FLOWS
        ++_injected_flits[c][n];
#endif
        
        if(g_hpcl_comp_config.hpcl_comp_en == 0) {

	  _net[subnet]->WriteFlit(f, n);

        } else {
	  //added by kh (021416)
	  //Compression
	  //(1.1.b) flits but a head flit are injected to the compressor
	  if(g_mc_placement_config.is_mc_node(n) == true && f->type == Flit::READ_REPLY) {

	     hpcl_comp_pl_data* pl_data = NULL;

	     //A head flit is found. It means other flits are in _input_queue now.
	     //flits move from _input_queue to compressor by force.
	     //Those flits are sent to network in different paths such that we set info for
	     //flit navigation here.
	     if(f->head == true) {
		assert(!_input_queue[subnet][n][c].empty());
		Flit * body_flit = _input_queue[subnet][n][c].front();
		_input_queue[subnet][n][c].pop_front();

		if(_pri_type == network_age_based) {
		  body_flit->pri = numeric_limits<int>::max() - _time;
		  assert(body_flit->pri >= 0);
		}
		body_flit->itime = _time;

		// Pass VC "back" for next flit
		if(!_input_queue[subnet][n][c].empty() && !body_flit->tail) {
		  Flit * const nf = _input_queue[subnet][n][c].front();
		  nf->vc = body_flit->vc;
		}

		++_sent_flits[c][n];
		++_sent_flits_net[subnet][n];

		pl_data = new hpcl_comp_pl_data;
		pl_data->add_comp_pl_data(body_flit);
		g_hpcl_global_comp_pl_2B[n]->set_input_data(pl_data);
		//delete pl_data;

		//(1.1.a)	send a head flit first
		_net[subnet]->WriteFlit(f, n);

	    } else {

		pl_data = new hpcl_comp_pl_data;
		pl_data->add_comp_pl_data(f);
		g_hpcl_global_comp_pl_2B[n]->set_input_data(pl_data);
		//delete pl_data;
	    }


	    //(1.2.a) words in a flit are pushed to a queue in a compressor
	    if(pl_data) {

		Flit* flit = pl_data->get_flit_ptr();
		assert(flit);

		//Use receiver's id as global dict index
		int global_dict_index = flit->const_dest;

		//Push words to be updated to word_queue (this is done at zero-time)
		vector<unsigned short> word_list;
		g_hpcl_global_comp_pl_2B[n]->decompose(flit->raw_data, word_list);
		for(int i = 0; i < word_list.size(); i++)
		  g_hpcl_global_comp_pl_2B[n]->push_word_to_queue(word_list[i], global_dict_index);

		delete pl_data;
	    }

	  } else if (g_mc_placement_config.is_mc_node(n) == true && f->type == Flit::CTRL_MSG) {


	      hpcl_dict_ctrl_msg<unsigned short>* ctrl_msg = (hpcl_dict_ctrl_msg<unsigned short>*)f->data;

	      /*
	      std::cout << "ctrl_msg | id " << ctrl_msg->get_id();
	      std::cout << " | src_node " << ctrl_msg->get_src_node();
	      std::cout << " | dest_node " << ctrl_msg->get_dest_node();
	      std::cout << " | word_index " << ctrl_msg->get_word_index();
	      std::cout << " | word " << ctrl_msg->get_new_word();
	      std::cout << " | n " << n;
	      std::cout << std::endl;;
	      */

	      g_hpcl_global_comp_pl_2B[n]->release_word(ctrl_msg->get_dest_node(), ctrl_msg->get_word_index(), ctrl_msg->get_new_word());
	      g_hpcl_global_comp_pl_2B[n]->validate_word(ctrl_msg->get_dest_node(), ctrl_msg->get_word_index(), ctrl_msg->get_new_word());

	      _net[subnet]->WriteFlit(f, n);

	  } else {

	      _net[subnet]->WriteFlit(f, n);
	  }
	  ///
        }
      }
    }
  }

  if(g_hpcl_comp_config.hpcl_comp_en == 1) {

    //added by kh(030816)
    //(1.3) Compression: Pipelined Compression
    for(int i = 0; i < g_hpcl_global_comp_pl_2B.size(); i++)
    {
      if(!g_hpcl_global_comp_pl_2B[i])	continue;

      //(1.2.b) words in the queue are updated to dictionary, when idle state
      //(1.2.d) ctrl msgs for words with frequency (>= threshold) are generated in compressor's run function, when idle state
      g_hpcl_global_comp_pl_2B[i]->run(getTime()+getTotalTime());
      hpcl_comp_pl_data* comp_pl_rsl = g_hpcl_global_comp_pl_2B[i]->get_output_data();
      Flit* flit = comp_pl_rsl->get_flit_ptr();
      if(flit) {
	//std::cout << "node " << i << " flit->id " << flit->id << std::endl;

	//(1.1.c) flits are injected from the compressor to an input buffer
	if(HasBufferSpace(i, flit)) {
	  SendFlitToBuffer(i, flit);		//for credit management.
	  SendFlitToNetwork(i, flit);
	  //std::cout << "\t" << " send flit " << flit->id << std::endl;

	  if(g_hpcl_global_comp_pl_2B[i]->get_comp_done() == true)
	  {
	      assert(g_hpcl_global_comp_pl_2B[i]->get_state() == hpcl_comp_pl<unsigned short>::HPCL_COMP_RUN);
	      g_hpcl_global_comp_pl_2B[i]->set_state(hpcl_comp_pl<unsigned short>::HPCL_COMP_IDLE);
	      g_hpcl_global_comp_pl_2B[i]->reset_comp_done();
	  }

	  //reset output data
	  g_hpcl_global_comp_pl_2B[i]->reset_output_data();

	} else {
	  //std::cout << "\t" << " cannot send flit " << flit->id << " due to no space!!!!!!!!!!" << std::endl;
	}
      }
    }
    ///

  }

  //Send the credit To the network
  for(int subnet = 0; subnet < _subnets; ++subnet) {
    for(int n = 0; n < _nodes; ++n) {
      map<int, Flit *>::const_iterator iter = flits[subnet].find(n);
      if(iter != flits[subnet].end()) {
        Flit * const f = iter->second;

        f->atime = _time;

        //added by kh(070715)
        if(f->tail) {

          //added by kh(030816)
	  if(f->type < Flit::ANY_TYPE) {
	    //added by kh(121715)
	    if(g_mc_placement_config.is_sm_node(n)) {
	      //std::cout << "mf's id: " << ((mem_fetch*)f->data)->get_request_uid() << ", time: " << _time << std::endl;
	      ((mem_fetch*)f->data)->set_status(TAIL_FLIT_EJECTED_FROM_EJECT_BUF_IN_SM, _time);
	      //added by kh(122815)
	      double rep_net_lat = _time - ((mem_fetch*)f->data)->get_timestamp(HEAD_FLIT_INJECTED_TO_INJECT_BUF_IN_MEM);
	      g_hpcl_network_anal->add_sample(hpcl_network_anal::REP_NET_LAT, rep_net_lat);
	      ///

	    } else if(g_mc_placement_config.is_mc_node(n)) {
	      ((mem_fetch*)f->data)->set_status(TAIL_FLIT_EJECTED_FROM_EJECT_BUF_IN_MEM, _time);

	      //added by kh(122815)
	      double req_net_lat = _time - ((mem_fetch*)f->data)->get_timestamp(HEAD_FLIT_INJECTED_TO_INJECT_BUF_IN_SM);
	      g_hpcl_network_anal->add_sample(hpcl_network_anal::REQ_NET_LAT, req_net_lat);
	      ///
	    }
          }
        }
        ///

        if(f->watch) {
          *gWatchOut << GetSimTime() << " | "
          << "node" << n << " | "
          << "Injecting credit for VC " << f->vc
          << " into subnet " << subnet
          << "." << endl;
        }
        

        if(g_hpcl_comp_config.hpcl_comp_en == 0) {

          Credit * const c = Credit::New();
	  c->vc.insert(f->vc);
	  _net[subnet]->WriteCredit(c, n);

        } else {
	  //added by kh(030816)
	  if(f->type == Flit::READ_REPLY) {
	      if(f->tail == false && f->m_enc_status == 1) {

	      } else {
		Credit * const c = Credit::New();
		c->vc.insert(f->vc);
		_net[subnet]->WriteCredit(c, n);
		//std::cout << "\tf->vc " << f->vc << " f->id " << f->id << std::endl;
	      }

	  } else {
	    Credit * const c = Credit::New();
	    c->vc.insert(f->vc);
	    _net[subnet]->WriteCredit(c, n);
	  }
	  ///
        }

#ifdef TRACK_FLOWS
        ++_ejected_flits[f->cl][n];
#endif
        
        _RetireFlit(f, n);
      }
    }
    flits[subnet].clear();
    // _InteralStep here
    _net[subnet]->Evaluate( );					//run router's pipeline
    _net[subnet]->WriteOutputs( );				//send flits..
  }
  
  ++_time;
  assert(_time);
  if(gTrace){
    cout<<"TIME "<<_time<<endl;
  }
  
}
Exemple #12
0
	//--------------------------------------------------------------
	void SequenceRamses::setFrameForTime(float time)
	{
		return setFrameAtPercent(time / getTotalTime());
	}
void ElapsedTimer::reset()
{
	m_startTime = getTotalTime();
}
Exemple #14
0
void Application::run()
{
	mWindow.create(sf::VideoMode(800, 600), "MiniLD 61");
#ifdef NDEBUG
	mWindow.setFramerateLimit(200);
#endif

	mGameView = sf::View(sf::Vector2f(), sf::Vector2f(2048, 2500));
	mUIView = mWindow.getDefaultView();
	{
		sf::Vector2f size = (sf::Vector2f)mWindow.getSize();
		mUIView.setSize(size);
		mUIView.setCenter(size / 2.f);

		mGameView.setSize(mGameView.getSize().y * (size.x / size.y), mGameView.getSize().y);
	}

#ifdef NDEBUG
	mState.changeState<IntroState>();
#else
	mState.changeState<MenuState>();
	static_cast<MenuState*>(mState.getCurrentState())->pushPane(new MainMenuPane);
#endif

	sf::Clock frameTimer;
	sf::Event ev;
	sf::Text profilingText("", sf::getDefaultFont(), 10U);

	float dt, extraDT = 0;
	float totalTime = 0;

	{ // Prime the profiling tree
		PROFILE_NAMED("Frame");
		{ PROFILE_NAMED("Tick"); }
		{ PROFILE_NAMED("Update"); }
		{ PROFILE_NAMED("Draw"); }
	} Profiler::resetBlocks();

	auto root = Profiler::getRoot()->getChild("Frame");

	while (mWindow.isOpen())
	{ Profiler::startBlock("Frame");
		dt = frameTimer.restart().asSeconds();
		extraDT += dt;

		while (mWindow.pollEvent(ev))
		{ PROFILE_NAMED("Events");
			mState.handle_event(ev);

			if (ev.type == sf::Event::Resized)
			{
				sf::Vector2f size(ev.size.width, ev.size.height);

				mUIView.setSize(size);
				mUIView.setCenter(size / 2.f);

				mGameView.setSize(mGameView.getSize().y * (size.x / size.y), mGameView.getSize().y);
			}
			else if (ev.type == sf::Event::Closed)
				mWindow.close();
		}

		while (extraDT >= TICK_LENGTH)
		{ PROFILE_NAMED("Tick");
			mState.fixed_update(TICK_LENGTH);

			extraDT -= TICK_LENGTH;
		}

		PROFILE_CALL("Update", mState.variadic_update(dt));

		mWindow.clear();

		mWindow.setView(mGameView);

		PROFILE_CALL("Draw", mState.draw(mWindow));

		mWindow.setView(mUIView);
		
		PROFILE_CALL("DrawUI", mState.drawUI(mWindow));
		mWindow.draw(profilingText);

		mWindow.display();

		Profiler::endBlock(); // Frame

		if (root->getTotalTime() >= std::chrono::seconds(1))
		{
			std::ostringstream oss;
			oss << *root << std::endl;
			profilingText.setString(oss.str());

			Profiler::resetBlocks();
		}

		// State manager is without state, might as well die nicely
		if (mState.getCurrentState() == nullptr)
			mWindow.close();
	}
}
Exemple #15
0
void Simulation::draw(render::Context& context)
{
    context.setStencilBuffer(getWorldSize().getWidth().value(), getWorldSize().getHeight().value());

    // Render modules
    m_modules.draw(*this, context);

    // Draw objects
    for (auto& obj : m_objects)
    {
        Assert(obj);
        if (obj->isVisible())
            obj->draw(context);
    }

#if defined(CECE_ENABLE_RENDER) && defined(CECE_ENABLE_BOX2D_PHYSICS) && defined(CECE_ENABLE_BOX2D_PHYSICS_DEBUG)
    if (isDrawPhysics())
        m_world.DrawDebugData();
#endif

#if CONFIG_RENDER_TEXT_ENABLE
    context.disableStencilBuffer();

    if (isSimulationTimeRender())
    {
        if (!m_font)
        {
            m_font.create(context, g_fontData);
            m_font->setSize(getFontSize());
        }

        OutStringStream oss;
        {
            auto time = getTotalTime().value();
            unsigned int seconds = time;
            unsigned int milliseconds = static_cast<unsigned int>(time * 1000) % 1000;

            const unsigned int hours = seconds / (60 * 60);
            seconds %= (60 * 60);
            const unsigned int minutes = seconds / 60;
            seconds %= 60;

            if (hours)
            {
                oss << std::setw(2) << std::setfill('0') << hours << ":";
                oss << std::setw(2) << std::setfill('0') << minutes << ":";
            }
            else if (minutes)
            {
                oss << std::setw(2) << std::setfill('0') << minutes << ":";
            }

            oss << std::setw(2) << std::setfill('0') << seconds << ".";
            oss << std::setw(3) << std::setfill('0') << milliseconds;
        }

        if (hasUnlimitedIterations())
        {
            oss << " (" << getIteration() << " / -)";
        }
        else
        {
            oss << " (" << getIteration() << " / " << getIterations() << ")";
        }

        m_font->draw(context, oss.str(), getFontColor());
    }
#endif
}
Exemple #16
0
bool Simulation::update(units::Duration dt)
{
    // Initialize simulation
    if (!isInitialized())
        initialize();

    // Increase step number
    m_iteration++;
    m_totalTime += dt;

    // Clear all stored forces
    for (auto& obj : m_objects)
        obj->setForce(Zero);

    // Update modules
    updateModules(dt);

    // Update objects
    updateObjects(dt);

    // Detect object that leaved the scene
    detectDeserters();

    // Delete unused objects
    deleteObjects();

    // Store data
    if (m_dataOutObjects)
    {
        for (const auto& object : m_objects)
        {
            const auto pos = object->getPosition();
            const auto vel = object->getVelocity();

            *m_dataOutObjects <<
                // iteration
                getIteration() << ";" <<
                // totalTime
                getTotalTime() << ";" <<
                // id
                object->getId() << ";" <<
                // typeName
                object->getTypeName() << ";" <<
                // posX
                pos.getX() << ";" <<
                // posY
                pos.getY() << ";" <<
                // velX
                vel.getX() << ";" <<
                // velY
                vel.getY() << "\n"
            ;
        }
    }

#ifdef CECE_ENABLE_BOX2D_PHYSICS
    {
        auto _ = measure_time("sim.physics", TimeMeasurementIterationOutput(this));

        m_world.Step(getPhysicsEngineTimeStep().value(), 10, 10);
    }
#endif

    return (hasUnlimitedIterations() || getIteration() <= getIterations());
}