Ejemplo n.º 1
0
void main()
{
	glfwInit();

	// Create a window
	window = glfwCreateWindow(800, 800, "Jarvis March", nullptr, nullptr);
	glfwMakeContextCurrent(window);
	glfwSwapInterval(0);

	// Initializes most things needed before the main loop
	init();

	//Generate the point mesh
	Vertex pointVertex;
	pointVertex.x = pointVertex.y = pointVertex.z = pointVertex.r = 0.0f;
	pointVertex.g = pointVertex.b = pointVertex.a = 1.0f;

	//rope creation
	point = new struct Mesh(1, &pointVertex, GL_POINTS);

	//Scale the rope
	point->scale = glm::scale(point->scale, glm::vec3(1.0f));

	//Generate 25 rigidbodies
	for(int i = 0; i < 25; i++)
	{
		float x = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX)) - 0.5f;
		float y = (static_cast <float> (rand()) / static_cast <float> (RAND_MAX)) - 0.5f;

		bodies.push_back(RigidBody(glm::vec3(0.0f), glm::vec3(x, y, 0.0f)));
	}

	// Enter the main loop.
	while (!glfwWindowShouldClose(window))
	{
		//Check time will update the programs clock and determine if & how many times the physics must be updated
		checkTime();

		// Call the render function.
		renderScene();

		// Swaps the back buffer to the front buffer
		// Remember, you're rendering to the back buffer, then once rendering is complete, you're moving the back buffer to the front so it can be displayed.
		glfwSwapBuffers(window);

		// Checks to see if any events are pending and then processes them.
		glfwPollEvents();
	}

	// After the program is over, cleanup your data!
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	glDeleteProgram(program);
	// Note: If at any point you stop using a "program" or shaders, you should free the data up then and there.

	delete point;

	// Frees up GLFW memory
	glfwTerminate();
}
Ejemplo n.º 2
0
/*
 *  Simple busy loop delay, acurate +- 1 usec
 */
sysDelay(unsigned  int usecdelay)
{
    unsigned int ftop,fbot;
    getFutureTime(usecdelay, &ftop, &fbot );
    while (checkTime(ftop,fbot) != 1);  /* wait until time elapsed */
    return 0;
}
Ejemplo n.º 3
0
void	Client::seekParty()
{
  _seek = true;
  std::stringstream str;

  if (_lvl < 4)
    _partySize = 1;
  else if (_lvl < 6)
    _partySize = 3;
  else if (_lvl < 8)
    _partySize = 5;
  else
    _partySize = 0;

  str << "broadcast " << _id << " seek " << _lvl << "\n";
  while (_party != true || (_teammate.size() < _partySize && _leader == true))
    {
      checkTime();
      
      _lastCommand = BASIC;
      writeToSocket(str.str());
      
      if (_party != true || (_teammate.size() < _partySize && _leader == true))
      	{
      	  forkUntil(_time - 100);
      	  searchFood(_time + 100);
      	}
      _accept = false;
      _invite = false;
    }
}
Ejemplo n.º 4
0
void	Client::seekNextLvl(size_t lvl)
{
  if (_lvl == lvl)
    {
      _regroup = false;
      _here = false;
      getToNextLvl();
    }
  checkTime();
  if (_time < 1000)
    {
      _here = false;
      _regroup = false;
    }
  if (_here == false)
    {
      seekParty();
      if (_leader == false && _regroup == false)
      	{
      	  defineGoal(60, 0, 0, 0, 0, 0, 0);
      	  searchGoal();
      	}
      else
	{
	  look();
	  defineGoal(0, 0, 0, 0, 0, 0, 0);
	}
    }
  else
    look();
}
Ejemplo n.º 5
0
bool ErrorHandling::checkAddInput(vector<string>& input)
{	
	bool value = true;
	
	int inputNotGiven = 0;
	for(int counter = 0; counter < input.size() - 1; counter++)
	{
		if(input[counter] == "")
				++inputNotGiven;
	}
			
	if(inputNotGiven == 3)
	{
		cout << "\nInvalid input as no event detail has been mentioned.\n"; 
		performLogging("Invalid input as no event detail has been mentioned.");
		value = false;
	}

	if(value)
	{
		if(!checkDate(input[1]))
			value = false;

		if(!checkTime(input[2]))
			value = false;
	}
	return value;
}
Ejemplo n.º 6
0
void		Network::receiveFromServer()
{
  char		buf[BUFF_SIZE];
  std::string	entry;

  _safeEvents->setDrawing(true);
  while (_safeEvents->getDrawing())
    {
      FD_ZERO(&_rfds);
      FD_SET(_socket, &_rfds);
      if (select(_socket + 1, &_rfds, NULL, NULL, &_timeOut) == FAIL)
  	throw ZappyError::SystemError(errno, "Error : Select");
      if (FD_ISSET(_socket, &_rfds))
  	{
  	  bzero(buf, BUFF_SIZE);
	  while (strchr(buf, 10) == NULL)
	    if (recv(_socket, buf, BUFF_SIZE - 1, 0) <= 0)
	      throw ZappyError::SystemError(errno, "Error : Connection Lost");
	  entry = _remain + buf;
	  _remain.clear();
	  parseEntry(entry);
	  _commands.parseAllCommands(entry);
	}
      checkTime();
    }
}
Ejemplo n.º 7
0
HDAvidUtility::HDAvidUtility(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::HDAvidUtility)
{
    options = new QSettings("HDAvidUtility.ini", QSettings::IniFormat);
    loadSettings();
    if(checkTime())
    {
        transcode = new QProcess(this);
        transcodeTimer = new QTimer(this);
        licenseTimer = new QTimer(this);
        transcodeTimer->start(30000);
        licenseTimer->start(600000);

        ui->setupUi(this);

        ui->startButton->setEnabled(true);
        ui->stopButton->setDisabled(true);

        ui->actionStart->setEnabled(true);
        ui->actionStop->setDisabled(true);

        ui->inputLineEdit->setText(defaultInputFolder);
        ui->outputLineEdit->setText(defaultOutputFolder);

        createTrayIcon();

        connect(transcode, SIGNAL(finished(int)), this, SLOT(renameTranscodedFiles()));
        connect(transcodeTimer, SIGNAL(timeout()), this, SLOT(on_startButton_clicked()));
        connect(licenseTimer, SIGNAL(timeout()), this, SLOT(checkTime()));

        on_startButton_clicked();
    }
    else
    {
Ejemplo n.º 8
0
void ChargeTimer::onEvent(const event::Event& event)
{
    if ((event.id == EVENT_UPDATE_CHARGE_TIMER)
     || (event.id == EVENT_SETTINGS_CHANGED)
     || (event.id == EVENT_CONTROLLER_STATE && event.param == State::RUNNING))
        checkTime();
}
Ejemplo n.º 9
0
int AI::getEvalForFirstMovePossible(Map& map, int depth, Stone::E_COLOR color, int alpha, int beta,
                                    int &y, int &x) {

    // On parcours le Goban a la recherche du premier coup possible
    for (; y < Map::_MAPSIZE_Y; ++y)
    {
        for (; x < Map::_MAPSIZE_X; ++x)
        {
            checkTime();

            if (map[y][x].isEmpty())
            {
                // Copy de la map et des nombres de pierres capturées
                Map map_tmp = map;

                // On crée la pierre et on joue le coup
                char fake = 0;
                Referee::E_STATE ret = _referee.check(Stone(y, x, color), map_tmp, fake);

                // Si le coup est valide on évalue (Pas de double trois)
                if (ret != Referee::INVALID)
                    return -calcMinMax(map_tmp, depth-1, ret, Referee::OP_COLOR[color], -beta, -alpha);
            }
        }
    }
    return 0;
}
Ejemplo n.º 10
0
void Log::log( const char * format, ...)
{
	va_list args;
	struct tm * ptm;
	time_t now = time(NULL);
	ptm = localtime(&now);
	char LEVEL[10];

	if(m_fp == NULL || checkTime(now))
		reopen(now);
	if(m_fp == NULL)
		return;

	if( mLoglevel > LEVEL_INFO )
		return;

	strcpy(LEVEL, "INFO");
	
	va_start(args, format);

	fprintf(m_fp, "%02d%02d%02d:%02d%02d%02d %8s ", 
			ptm->tm_year - 100, ptm->tm_mon + 1, ptm->tm_mday,
			ptm->tm_hour, ptm->tm_min, ptm->tm_sec, LEVEL );

	vfprintf(m_fp, format, args);
	fprintf(m_fp, "\n");
	fflush(m_fp);

	va_end(args);
}
Ejemplo n.º 11
0
void Tomatime::setLcdNumber()
{
    timeValue->setHMS(0, timeValue->addSecs(-1).minute(), timeValue->addSecs(-1).second());
    ui->lcdNumber->display(timeValue->toString());

    trayIcon->setToolTip(timeValue->toString());

    checkTime();
}
int LogicDetailParser::getHoursTime(string text, int& hours){
	if(parserHoursTime(text, hours)){
		if(!checkTime(hours))
			return ERROR;
		return FOUND;
	}
	else
		return NOTFOUND;
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
	// Initializes the GLFW library
	glfwInit();

	// Creates a window given (width, height, title, monitorPtr, windowPtr).
	// Don't worry about the last two, as they have to do with controlling which monitor to display on and having a reference to other windows. Leaving them as nullptr is fine.
	window = glfwCreateWindow(800, 600, "AABB 2D Collisions", nullptr, nullptr);

	// Makes the OpenGL context current for the created window.
	glfwMakeContextCurrent(window);
	
	// Sets the number of screen updates to wait before swapping the buffers.
	// Setting this to zero will disable VSync, which allows us to actually get a read on our FPS. Otherwise we'd be consistently getting 60FPS or lower, 
	// since it would match our FPS to the screen refresh rate.
	// Set to 1 to enable VSync.
	glfwSwapInterval(0);

	// Initializes most things needed before the main loop
	init();

	// Enter the main loop.
	while (!glfwWindowShouldClose(window))
	{
		// Call to checkTime() which will determine how to go about updating via a set physics timestep as well as calculating FPS.
		checkTime();

		// Call the render function.
		renderScene();

		// Swaps the back buffer to the front buffer
		// Remember, you're rendering to the back buffer, then once rendering is complete, you're moving the back buffer to the front so it can be displayed.
		glfwSwapBuffers(window);

		// Add one to our frame counter, since we've successfully 
		frame++;

		// Checks to see if any events are pending and then processes them.
		glfwPollEvents();
	}

	// After the program is over, cleanup your data!
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	glDeleteProgram(program);
	// Note: If at any point you stop using a "program" or shaders, you should free the data up then and there.

	delete(obj1);
	delete(obj2);
	delete(square);

	// Frees up GLFW memory
	glfwTerminate();

	return 0;
}
Ejemplo n.º 14
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QTimer *timer= new QTimer (this);
    connect( ui->calendarWidget, SIGNAL( activated( const QDate & )),
             this, SLOT( remind( const QDate & )));
    connect (timer, SIGNAL(timeout()), this, SLOT( checkTime()));
    timer->start();     //runs a timeer
}
Ejemplo n.º 15
0
void	Client::getToLvl2()
{
  checkTime();
  defineGoal(60, 1, 0, 0, 0, 0, 0);
  searchGoal();
  cleanSquare();
  incantation();
  if (_lvl == 2)
    getToLvl3();
  getToLvl2();
}
Ejemplo n.º 16
0
void TimedColorCallback::perform(EventType* event) {
	TimeEventData myData = TimeEvent::getData(event);
	if (getPercentageDone() == 0.0) {
		mPainter->setColor(mStartColor);
	}
	mTimePassed += myData.mTimePassed;
	mPainter->setColor(mStartColor + ease(getPercentageDone()) * mEndColor);
	checkTime(myData.mTimePassed);
	if (mFinished) {
		mModel->removeEffect(mPainter);
	}
}
Ejemplo n.º 17
0
int AI::calcMinMax(Map& map, int depth, Referee::E_STATE ret, Stone::E_COLOR color, int alpha, int beta) {

    if (depth == 0 || Referee::gameHasEnded(ret))
        return eval(map, ret, color);

    // int y_first = 0;
    // int x_first = 0;

    // On récupère l'évaluation du premier coup possible
    // int current = getEvalForFirstMovePossible(map, depth, color, alpha, beta, y_first, x_first);
    // if (current >= alpha)
    //     alpha = current;

    // if (current < beta)
    // {
        TILE_IT_T it = _openTiles.begin();
        // On parcours les autres cases du Goban
        while (it != _openTiles.end()) {
            checkTime();
            int y = it->first;//le temps de faire marcher les iterateurs
            int x = it->second;

            // Copy de la map et des nombres de pierres capturées
            Map map_tmp = map;
            // On crée la pierre et on joue le coup
            char fake = 0;
            Referee::E_STATE ret = _referee.check(Stone(y, x, color), map_tmp, fake);
            // Si le coup est valide on évalue (Pas de double trois)
            if (ret != Referee::INVALID)
            {
                // int score = 1;
                int score = -calcMinMax(map_tmp, depth-1, ret, Referee::OP_COLOR[color], -(alpha+1), -alpha);
                if (score > alpha && score < beta)
                    score = -calcMinMax(map_tmp, depth-1, ret, Referee::OP_COLOR[color], -beta, -alpha);
                // if (score >= current)
                // {
                    // current = score;
                    if (score >= alpha)
                    {
                        alpha = score;
                        if (/*alpha*/score >= beta)
                            return score;
                            // return current;
                    }
                // }
            }
            ++it;
        }
    // }
    return alpha;
    // return /*alpha*/current;
}
Ejemplo n.º 18
0
myShowManager::myShowManager(QObject *parent) : QObject(parent)
{
    countShows = myLog::getCountCurDay();
    last_time = myLog::getLastTime();
    start_time = QDateTime::currentDateTime();
    plan_showing = myLog::getPlanTime(countShows);

    readLog();

    QTimer *timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(checkTime()));
    timer->start(15000);
}
Ejemplo n.º 19
0
int Dynacoe::Clock::GetTimeLeft() {
	if (!expired) checkTime();

	if (expired) {
		return 0;
	}

	if (endTime < startTime) {
		return -1;
	}

    return (endTime - startTime) - GetTimeSince();
}
Ejemplo n.º 20
0
int TransRecord::readLine(char *line, TransNode **node)
{
    int res = 0;
    char *ptk = NULL;

    char type;
    time_t time;
    int32_t amount;
    char *desc;

    
    ptk = strtok(line, "\t");
    if (FALSE == checkType(ptk)) {
        return FALSE;
    }
    type = *ptk;

    ptk = strtok(NULL, "\t");
    time = checkTime(ptk);
    if (time == FALSE) {
        return FALSE;
    }

    ptk = strtok(NULL, "\t");
    res = checkAmount(ptk);
    if (FALSE == res) {
        return FALSE;
    }
    amount = res;

    ptk = strtok(NULL, "\t");
    if (FALSE == checkDesc(ptk)) {
        return FALSE;
    }
    desc = ptk;

    ptk = strtok(NULL, "\t");
    if (NULL != ptk) {
        cerr << "malformed line, more than 3 <TAB>.\n"; 
        return FALSE;
    }

    *node = new TransNode(type, time, amount, desc);
    if (*node == NULL) {
        cerr << "new failed for line: " << line << endl;
        exit(-1);
    }

    return TRUE;
}
Ejemplo n.º 21
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Create the storage
    storage = new PTStorage(this);
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(checkTime()));
    timer->start(60000 ); // TODO: Change this for every 5 minutes or something

    connect(storage, SIGNAL(hasLogs(QString)), this, SLOT(displayMessage(QString)));
}
Ejemplo n.º 22
0
Stone AI::calc(int depth) {
    int score;
    int max_y=-1,max_x=-1;
    //int max = -AI_INFINITY;
    int alpha = -AI_INFINITY;
    int beta = AI_INFINITY;

    //On parcourt les cases du Goban
    TILE_IT_T it = _openTiles.begin();
    while (it != _openTiles.end()) {
        checkTime();
        int y = it->first;//le temps de faire marcher les iterateurs
        int x = it->second;

        Map map_tmp = _map;// Copy de la map et des nombres de pierres capturées

        char fake = 0;// On crée la pierre et on joue le coup
        Referee::E_STATE ret = _referee.check(Stone(y,x, _color), map_tmp, fake);

        // _closeTiles.push_back(*it);
        // it = _openTiles.erase(it);
        // Si le coup est valide on évalue (Pas de double trois)
        if (ret != Referee::INVALID)
        {
            //score = calcMin(map_tmp, depth - 1, ret, alpha, beta);
            
            score = -calcMinMax(map_tmp, depth - 1, ret, Referee::OP_COLOR[_color], -beta, -alpha);
            // Si ce score est plus grand
            //if (score > max)/*Moins optimise mais aleatoire: if (score > max || (score == max && rand()%2))*/
            if (score > alpha)
            {
                std::cout << "depth:"<<depth<<"[" << alpha << "("<<max_y<<";"<<max_x<<")->" << score << "("<<y<<";"<<x<< ")]" << std::endl;
                //On le choisit
                //max = score;
                alpha = score;
                // On sauvegarde les coordonnées du coup optimum
                max_y = y;
                max_x = x;
            }
        }
        // On annule le coup (Ici rien pour l'instant car copie de la Map et des éléments)
        // TILE_VALUE_T tmp_tile = _closeTiles.back();
        // _closeTiles.pop_back();
        // it = _openTiles.insert(it, tmp_tile);
        ++it;
    }
    // On retourne la pierre optimale
    return Stone(max_y, max_x, _color);
}
Ejemplo n.º 23
0
void loop()
{
	if(deviceStatus == STOPPED)
	{
		if(LCD.getTouchActivity() == TOUCH_UP)
		{
			LCD.getTouchXY(x, y);
			if(oneMinuteButton.isClicked(x, y))
			{
				pumpEndMillis = millis() + 300;
				digitalWrite(VALVE_CONTROL1, LOW);
				digitalWrite(VALVE_CONTROL2, HIGH);
				initializePolling();
			}
			else if(fiveMinuteButton.isClicked(x, y))
			{
				pumpEndMillis = millis() + 300000;
				digitalWrite(VALVE_CONTROL1, LOW);
				digitalWrite(VALVE_CONTROL2, HIGH)
				initializePolling();
			}
			else if(tenMinuteButton.isClicked(x, y))
			{
				pumpEndMillis = millis() + 600000;
				digitalWrite(VALVE_CONTROL1, LOW);
				digitalWrite(VALVE_CONTROL2, HIGH);
				initializePolling();
			}
		}
	}
	else if(deviceStatus != STOPPED)
	{
		checkInput();
		readGPS();
		checkInput();
		readChip();
		checkInput();
		readTempHumid();
		checkInput();

		if(viewOptions)
		{
			drawOptions();
		}
		
		checkTime();
	}
}
Ejemplo n.º 24
0
void loop()
{

if(Spark.connected()){
    RGB.control(true);
    RGB.color(0, 0, 0);
    digitalWrite(led0, LOW);
    lightpt();
    tempdt();
    tempdht();
    readBMP180();
    temperature = (tdht+temptmp+tbmp180)/3;
    checkTime();
}else{
    digitalWrite(led0, HIGH);
}
}
Ejemplo n.º 25
0
bool ErrorHandling::checkSearchInput(vector<string> input)
{
	bool value = true;

	if(input[1] != "")
	{
		if(!checkDate(input[1]))
		value = false;
	}
 
	if(input[2] != "")
	{
		if(!checkTime(input[2]))
		value = false;
	}

	return value;
}
int LogicDetailParser::getMeridiemTime(string text, int& hours){
	string meridiem;
	if(parserMeridiemTime(text, meridiem, hours)){
		if(meridiem == AM){
			if(hours == TWELVEHOURS)
				hours = POINTZERO;
			if(hours > TWELVEHOURS)
				return ERROR;
		}
		if(meridiem == PM)
			if(hours != TWELVEHOURS)
				hours += TWELVEHOURS;
		hours *= HUNDRED;
		if(!checkTime(hours))
			return ERROR;
		return FOUND;
	}
	return NOTFOUND;
}
Ejemplo n.º 27
0
int checkPerm(char targa[], time_t t, nodo_t * r)
{

    int discr;

    if (r == NULL) {
        return 0;
    }

    discr = strncmp(targa, r->targa, LTARGA);

    if (discr == 0) {
        return checkTime(r->lint, t);
    } else if (discr < 0) {
        return checkPerm(targa, t, r->left);
    } else {
        return checkPerm(targa, t, r->right);
    }
}
Ejemplo n.º 28
0
QString SICard::toString() const
{
	QStringList sl;
	//sl << data().dump();
	//sl << tr("cardType: %1 (raw type: %2)").arg(cardTypeToString(cardType())).arg(rawCardType());
	sl << tr("stationNumber: %1").arg(stationNumber());
	sl << tr("cardNumber: %1").arg(cardNumber());
	//sl << tr("startNumber: %1").arg(startNumber());
	//sl << tr("countryCode: %1").arg(countryCode());
	//sl << tr("clubCode: %1").arg(clubCode());
	sl << tr("check: %1").arg(time_str(checkTime()));
	sl << tr("start: %1").arg(time_str(startTime()));
	sl << tr("finish: %1").arg(time_str(finishTime()));
	for (int n = 0; n < punchCount(); ++n) {
		SIPunch p = punchAt(n);
		sl << ("   " + QString::number(n+1)).right(4) + ".\t" + QString::number(p.code()) + "\t" + time_str(p.time());
	}
	return sl.join("\n");
}
int LogicDetailParser::getSymbolledTime(string text, int& hours){
	string meridiem;
	int minutes;
	if(parserSymbolledTime(text, meridiem, hours, minutes)){
		if(meridiem == AM){
			if(hours == TWELVEHOURS)
				hours = POINTZERO;
			if(hours > TWELVEHOURS)
				return ERROR;
		}
		if(meridiem == PM)
			if(hours != TWELVEHOURS)
				hours += TWELVEHOURS;
		hours = hours * HUNDRED + minutes;
		if(!checkTime(hours))
			return ERROR;
		return FOUND;
	}
	return NOTFOUND;
}
Ejemplo n.º 30
0
void Transmitter::checkTime(unsigned int theTime){
	if (myScenario[nextAction].getTime() == theTime){ //Check to see if the time has past the next action to be sent
		if (firstLoop){					//Check if this is the first recursive call
			breakAt = nextAction;		//Set the breaking point for recursive calls
			firstLoop = false;
		}
		else{
			if (breakAt == nextAction){	//Check if the breaking point has been reached
				firstLoop = true;
				return;					//Break out of the recursive calls, if all the actions in the Scenario have been sent simultaniously
			}
		}
		myTx10Ptr->sendAction(myScenario[nextAction]);
		nextAction++;
		if (nextAction == 20){ //If the last action has been sent, queue the first action
			nextAction = 0;
		}
		checkTime(theTime);		//Recursive call, to check if several actions are on the same time.
	}
	else
	firstLoop = true;
}