示例#1
0
bool Forest::animate(GlView & view)
{
    Glib::TimeVal delta = m_model.m_mainWindow.time();
    delta.subtract(m_lastUpdate);
    m_lastUpdate = m_model.m_mainWindow.time();
    m_cal3dModel.onUpdate(delta.as_double());
    return true;
}
示例#2
0
// rearrange unselected shapes in random sequence
bool Model::AutoArrange(vector<Gtk::TreeModel::Path> &path)
{
  // all shapes
  vector<Shape*>   allshapes;
  vector<Matrix4d> transforms;
  objtree.get_all_shapes(allshapes, transforms);

  // selected shapes
  vector<Shape*>   selshapes;
  vector<Matrix4d> seltransforms;
  objtree.get_selected_shapes(path, selshapes, seltransforms);

  // get unselected shapes
  vector<Shape*>   unselshapes;
  vector<Matrix4d> unseltransforms;

  for(uint s=0; s < allshapes.size(); s++) {
    bool issel = false;
    for(uint ss=0; ss < selshapes.size(); ss++)
      if (selshapes[ss] == allshapes[s]) {
	issel = true; break;
      }
    if (!issel) {
      unselshapes.    push_back(allshapes[s]);
      unseltransforms.push_back(transforms[s]);
    }
  }

  // find place for unselected shapes
  int num = unselshapes.size();
  vector<int> rand_seq(num,1); // 1,1,1...
  partial_sum(rand_seq.begin(), rand_seq.end(), rand_seq.begin()); // 1,2,3,...,N

  Glib::TimeVal timeval;
  timeval.assign_current_time();
  srandom((unsigned long)(timeval.as_double()));
  random_shuffle(rand_seq.begin(), rand_seq.end()); // shuffle

  for(int s=0; s < num; s++) {
    int index = rand_seq[s]-1;
    // use selshapes as vector to fill up
    Vector3d trans = FindEmptyLocation(selshapes, seltransforms, unselshapes[index]);
    selshapes.push_back(unselshapes[index]);
    seltransforms.push_back(unseltransforms[index]); // basic transform, not shape
    selshapes.back()->transform3D.move(trans);
    CalcBoundingBoxAndCenter();
  }
  ModelChanged();
  return true;
}
示例#3
0
void Shape::draw_geometry(uint max_triangles)
{

  bool listDraw = (max_triangles == 0); // not in preview mode
  bool haveList = gl_List >= 0;

  if (!listDraw && haveList) {
    if (gl_List>=0)
      glDeleteLists(gl_List,1);
    gl_List = -1;
    haveList = false;
  }
  if (listDraw && !haveList) {
    gl_List = glGenLists(1);
    glNewList(gl_List, GL_COMPILE);
  }
  if (!listDraw || !haveList) {
	uint step = 1;
	if (max_triangles>0) step = floor(triangles.size()/max_triangles);
	step = max((uint)1,step);

	glBegin(GL_TRIANGLES);
	for(size_t i=0;i<triangles.size();i+=step)
	{
		glNormal3dv(triangles[i].Normal);
		glVertex3dv(triangles[i].A);
		glVertex3dv(triangles[i].B);
		glVertex3dv(triangles[i].C);
	}
	glEnd();
  }
  if (listDraw && !haveList) {
    glEndList();
  }

  if (listDraw && gl_List >= 0) { // have stored list
    Glib::TimeVal starttime, endtime;
    if (!slow_drawing) {
      starttime.assign_current_time();
    }
    glCallList(gl_List);
    if (!slow_drawing) {
      endtime.assign_current_time();
      Glib::TimeVal usedtime = endtime-starttime;
      if (usedtime.as_double() > 0.2) slow_drawing = true;
    }
    return;
  }
}
示例#4
0
void Window::vComputeFrameskip(int _iRate)
{
    static Glib::TimeVal uiLastTime;
    static int iFrameskipAdjust = 0;

    Glib::TimeVal uiTime;
    uiTime.assign_current_time();

    if (m_bWasEmulating) {
        if (m_bAutoFrameskip) {
            Glib::TimeVal uiDiff = uiTime - uiLastTime;
            const int iWantedSpeed = 100;
            int iSpeed = iWantedSpeed;

            if (uiDiff != Glib::TimeVal(0, 0)) {
                iSpeed = (1000000 / _iRate) / (uiDiff.as_double() * 1000);
            }

            if (iSpeed >= iWantedSpeed - 2) {
                iFrameskipAdjust++;
                if (iFrameskipAdjust >= 3) {
                    iFrameskipAdjust = 0;
                    if (systemFrameSkip > 0) {
                        systemFrameSkip--;
                    }
                }
            } else {
                if (iSpeed < iWantedSpeed - 20) {
                    iFrameskipAdjust -= ((iWantedSpeed - 10) - iSpeed) / 5;
                } else if (systemFrameSkip < 9) {
                    iFrameskipAdjust--;
                }

                if (iFrameskipAdjust <= -4) {
                    iFrameskipAdjust = 0;
                    if (systemFrameSkip < 9) {
                        systemFrameSkip++;
                    }
                }
            }
        }
    } else {
        m_bWasEmulating = true;
    }

    uiLastTime = uiTime;
}
示例#5
0
uint32_t systemGetClock()
{
    Glib::TimeVal time;
    time.assign_current_time();
    return time.as_double() * 1000;
}
示例#6
0
int main(int argc, char* argv[]){
  // Some variables...
  int numberOfThreads;
  int duration;
  int i;
  Glib::Thread** threads;
  const char* config_file = NULL;
  int debug_level = -1;
  Arc::LogStream logcerr(std::cerr);

  // Process options - quick hack, must use Glib options later
  while(argc >= 3) {
    if(strcmp(argv[1],"-c") == 0) {
      config_file = argv[2];
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-d") == 0) {
      debug_level=Arc::string_to_level(argv[2]);
      argv[2]=argv[0]; argv+=2; argc-=2;
    } else if(strcmp(argv[1],"-r") == 0) {
      alwaysReconnect=true; argv+=1; argc-=1;
    } else {
      break;
    };
  } 
  if(debug_level >= 0) {
    Arc::Logger::getRootLogger().setThreshold((Arc::LogLevel)debug_level);
    Arc::Logger::getRootLogger().addDestination(logcerr);
  }
  // Extract command line arguments.
  if (argc!=4){
    std::cerr << "Wrong number of arguments!" << std::endl
	      << std::endl
	      << "Usage:" << std::endl
	      << "perftest [-c config] [-d debug] [-r] url threads duration" << std::endl
	      << std::endl
	      << "Arguments:" << std::endl
	      << "url       The url of the service." << std::endl
	      << "threads   The number of concurrent requests." << std::endl
	      << "duration  The duration of the test in seconds." << std::endl
	      << "-c config The file containing client chain XML configuration with " << std::endl
              << "          'soap' entry point and HOSTNAME, PORTNUMBER and PATH " << std::endl
              << "           keyword for hostname, port and HTTP path of 'echo' service." << std::endl
	      << "-d debug   The textual representation of desired debug level. Available " << std::endl
              << "           levels: DEBUG, VERBOSE, INFO, WARNING, ERROR, FATAL." << std::endl
	      << "-r         If specified close connection and reconnect after " << std::endl
              << "           every request." << std::endl;
    exit(EXIT_FAILURE);
  }
  url_str = std::string(argv[1]);
  numberOfThreads = atoi(argv[2]);
  duration = atoi(argv[3]);

  // Start threads.
  run=true;
  finishedThreads=0;
  //Glib::thread_init();
  mutex=new Glib::Mutex;
  threads = new Glib::Thread*[numberOfThreads];
  for (i=0; i<numberOfThreads; i++)
    threads[i]=Glib::Thread::create(sigc::ptr_fun(sendRequests),true);

  // Sleep while the threads are working.
  Glib::usleep(duration*1000000);

  // Stop the threads
  run=false;
  while(finishedThreads<numberOfThreads)
    Glib::usleep(100000);

  // Print the result of the test.
  Glib::Mutex::Lock lock(*mutex);
  totalRequests = completedRequests+failedRequests;
  totalTime = completedTime+failedTime;
  std::cout << "========================================" << std::endl;
  std::cout << "URL: "
	    << url_str << std::endl;
  std::cout << "Number of threads: "
	    << numberOfThreads << std::endl;
  std::cout << "Duration: "
	    << duration << " s" << std::endl;
  std::cout << "Number of requests: "
	    << totalRequests << std::endl;
  std::cout << "Completed requests: "
	    << completedRequests << " ("
	    << Round(completedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Failed requests: "
	    << failedRequests << " ("
	    << Round(failedRequests*100.0/totalRequests)
	    << "%)" << std::endl;
  std::cout << "Completed requests per second: "
            << Round(completedRequests/duration)
            << std::endl;
  std::cout << "Average response time for all requests: "
	    << Round(1000*totalTime.as_double()/totalRequests)
	    << " ms" << std::endl;
  if (completedRequests!=0)
    std::cout << "Average response time for completed requests: "
	      << Round(1000*completedTime.as_double()/completedRequests)
	      << " ms" << std::endl;
  if (failedRequests!=0)
    std::cout << "Average response time for failed requests: "
	      << Round(1000*failedTime.as_double()/failedRequests)
	      << " ms" << std::endl;
  std::cout << "========================================" << std::endl;

  return 0;
}
示例#7
0
bool SimVoteWindow::loadConfiguration(std::string pass)
{
	bool loginOk = false;

	if (VotingCentersWrapper::getInstance()->isInstall())
	{
		VotingCenter votingCenter;
		VotingCentersWrapper::getInstance()->getInstallationVotingCenter(votingCenter);
		votingCenterName = votingCenter.getCode();
	}

	std::cout << "Center : " << votingCenterName << std::endl;

	loginOk = MachineOperationManager::getInstance()->authentication(votingCenterName, pass, true);

	//Load precalculate other info needed for the VM
	try
	{
		if(loginOk)

		{

		loginOk = false;

		electoralConfiguration->loadAllData();
		Smartmatic::SAES::Printing::VotePrintDocument::calculateMax(electoralConfiguration);

		std::string openingDateTime = electoralConfiguration->getVotingDevice()->getFirstVotingDevice().getOperation_modes().getOperation_mode()[0].getOpening_date_time();
		std::string closingDateTime = electoralConfiguration->getVotingDevice()->getFirstVotingDevice().getOperation_modes().getOperation_mode()[0].getClosing_date_time();

		Glib::TimeVal openingTime;
		Glib::TimeVal closingTime;

		openingTime.assign_from_iso8601(openingDateTime);
		double openingD = openingTime.as_double();

		closingTime.assign_from_iso8601(closingDateTime);
		double closingD = closingTime.as_double();

		Smartmatic::SAES::Security::Encryption::getInstance()->setMachineTime(openingD + (openingD + closingD)/2);

		Smartmatic::SAES::Voting::OperationStatus::Current()->init();
		Glib::ustring openingCode = Smartmatic::SAES::Voting::OperationStatus::Current()->getElectionStatusWrapper()->getOpeningCode();
		Smartmatic::System::GuidClass openCodeGUID = Smartmatic::System::GuidClass::Parse(openingCode);
		Smartmatic::SAES::Security::Encryption::getInstance()->setOpeningCode(openCodeGUID);

		//Clear previous language
		ElectionInstalationLanguages::getInstance()->clearLanguage();

		Smartmatic::SAES::Voting::Election::Languages::LanguageSequence & sequence (electoralConfiguration->getLanguages().getLanguage());

		for (Smartmatic::SAES::Voting::Election::Languages::LanguageIterator it = sequence.begin(); it != sequence.end(); ++it)
		{
			ElectionInstalationLanguages::getInstance()->addInstallationLanguages((*it));
			Smartmatic::SAES::Voting::SetLanguageFunctionality::setNewVotingLanguageByLanguageCountry(it->getLanguage(),it->getCountry());
			break;
		}


		loginOk = true;
		}
	}
	catch(ElectionException & ex)
	{

		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;

	}
	catch(VotingDeviceException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(CryptoException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(SignedException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(XmlException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(GuIdException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(FileSystemException & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(std::exception & ex)
	{
		std::cout << "FATAL "<<__func__<< ex.what() << std::endl;
	}
	catch(...)
	{
		std::cout << "FATAL "<<__func__<< "Unknown exception" << std::endl;
	}



	return loginOk;
}