Exemple #1
0
bool Rcsgedit::RenderLoop()
{
    double timeDelta = 1.0f/(double)GLManager::FPS_TARGET;
    double lastTime = (double)glfwGetTime();
    while (GLManager::GetManager()->running)
    {
        // Draw and swap buffers
        Render(glfwGetTime());
        glfwSwapBuffers(pWindow);
       
        // Handle events.
        glfwPollEvents();
        if (glfwGetKey(pWindow, GLFW_KEY_ESCAPE) == GLFW_PRESS || glfwWindowShouldClose(pWindow))
        {
            GLManager::GetManager()->running = false;
        }

        if (InputSystem::ResizeEvent(GLManager::GetManager()->width, GLManager::GetManager()->height))
        {
            SetupViewport();
        }

        // Update timer and try to sleep for the FPS Target.
        timeDelta = (double)glfwGetTime() - lastTime;
        lastTime  = (double)glfwGetTime();

        std::chrono::milliseconds sleepTime ((int)(1.0/(double)GLManager::FPS_TARGET - 1000*timeDelta));
        if (sleepTime > std::chrono::milliseconds(0))
        {
            std::this_thread::sleep_for(sleepTime);
        }
    }

    return true;
}
Exemple #2
0
  void ACoreSimulator::simulate(unsigned int sleepMillis) {
	boost::posix_time::milliseconds sleepTime(sleepMillis);
	//WaveformsMessage wm = getNextWaveformMessage();
	while (running_) {
		//waveQ.push(&wm);
		if (!settingsQ_.isEmpty()) {
			
			SettingsMessage settings = settingsQ_.popWait();
			std::cout << "In ACoreSimulator received setting: " << settings.toXML() << std::endl;
			if (settings.theSetting.name == "SetBreathRate") {
				lastSetRR_ = settings.theSetting.data;
			}
			else if (settings.theSetting.name == "SetTidalVolume") {
				lastSetTV_ = settings.theSetting.data;
			}
			else if (settings.theSetting.name == "SetPeep") {
				lastSetPeep_ = settings.theSetting.data;
			}
			/*else if (settings.theSetting.name == "SetPMax") {
				lastRR = settings.theSetting.data;
			}*/
			
		}
		this->receiver->receiveWaveforms(getNextWaveformMessage());

		if (waveCounter % 3 == 0) {
			this->receiver->receiveNumerics(getNextNumericsMessage());
		}
		boost::this_thread::sleep(sleepTime);
	}
  }
int main()
{
    srand(time(NULL));
    Stat stat;
    char name[50];
    Snake snake;
    Pos food;
    ToGiveTread toGiveThread = {RIGHT, false, false};
    showLeaderboard();
    initStat(&stat);
    strcpy(name, stat.nickname);
    HANDLE hReadThread = CreateThread(NULL, 0, ReadThread, &toGiveThread, 0, NULL);
    strcpy(stat.nickname, name);
    initField();
    initSnake(&snake);
    initFood(&snake, &food, &stat);
    updateAds(&stat);
    do{
        Sleep(sleepTime(stat.level));
    }while(!updateSnake(&snake, &food, &toGiveThread, &stat));
    toGiveThread.toStopThread = true;
    clearScr();
    updateScore(&stat);
    CloseHandle(hReadThread);
    showLeaderboard();
    return 0;
}
Exemple #4
0
/**
 * FUNCTION NAME: heartBeatRoutine
 *
 * DESCRIPTION: send and check heartbeat
 */
void heartBeatRoutine(DNode * node) {
    while (isAlive) {
        std::chrono::milliseconds sleepTime(HEARTFREQ); // check every HEARTFREQ seconds
        std::this_thread::sleep_for(sleepTime);
        node->nodeLoopOps();
    }
}
Exemple #5
0
void trafficCheck(DNode * node) {
    while (isAlive) {
        std::chrono::milliseconds sleepTime(TRAFFICFREQ); // check every TRAFFICFREQ seconds
        std::this_thread::sleep_for(sleepTime);
        node -> leaderTrafficLoop();
    }
}
Exemple #6
0
	void start(){
		//std::thread mythread ( std::function<void()>(m_taskCreation) );
		std::thread mythread ([&]()->void{ m_taskCreation.process();});
		mythread.detach();
		std::chrono::duration<int, std::centi>	sleepTime ( 20);
		while ( m_taskCreation.isSupplyActive () ){
			std::this_thread::sleep_for(sleepTime );
		}
		m_done = true;
	}
void ThreadedScheduler::run(unsigned int sleep_interval_ms)
{
    float ms = sleep_interval_ms;
    boost::posix_time::milliseconds sleepTime(ms);
    std::cout << "ThreadedScheduler: started, will work every "
        << ms << "ms"
        << std::endl;
    while (should_be_running_)
    {
        tick();
        boost::this_thread::sleep(sleepTime);
    }
    std::cout << "ThreadedScheduler: completed" << std::endl;
}
void CommandLineInterface::visualQueues() {
  std::chrono::milliseconds sleepTime(250);
  while (keepWatching) {
    clearScreen();
    for (int i = 0; i < queues.size(); i++) {
      int progress = ceil(1. * queues[i]->size() * 50 / queues[i]->capacity());
      int percentage = ceil(1. * queues[i]->size() * 100 / queues[i]->capacity());
      std::cout << "Queue #" << i << ": ["
                << std::string(progress, '#') << std::string(50 - progress, '_') << "]"
                << " " << percentage << "%" << "\n";
    }
    std::cout << "\n" << "Press ENTER to stop watching." << "\n";
    std::this_thread::sleep_for(sleepTime);
  }
}
Exemple #9
0
void IgmpSender::threadFunction()
{
    Milliseconds sleepTime(SLEEP_INTERVAL);
    while (!_stopThread) {
        Milliseconds before;

        _igmpPacket->send();

        Milliseconds after;

        after = after - before;

        int slept = after.getTime();
        while (!_stopThread && slept < _interval * 1000) {
            sleepTime.sleep();
            slept += SLEEP_INTERVAL;
        }
    }
}
Exemple #10
0
// Runs the main application.
int main(int argc, char* argv [])
{
    int runStatus;
    do
    {
        std::unique_ptr<Rcsgedit> rcsgEdit(new Rcsgedit());
        runStatus = rcsgEdit->ApplicationSetup();
        if (!runStatus)
        {
            std::cout << std::endl << "Error initializing Rcsg-edit!" << std::endl;
            break;
        }
        runStatus = rcsgEdit->RenderLoop();
    } while (false);

    // Wait before closing for display purposes.
    std::cout << std::endl << "End of application. " << std::endl;
    std::chrono::milliseconds sleepTime(1000);
    std::this_thread::sleep_for(sleepTime);

    return runStatus;
}
void ThreadedScheduler::sleepThisThread(float ms)
{
    boost::posix_time::milliseconds sleepTime(ms);
    boost::this_thread::sleep(sleepTime);
}
		void Thread::Sleep(TimeSpan* span)
		{
			boost::posix_time::milliseconds sleepTime(span->TotalMilliseconds);
			boost::this_thread::sleep(sleepTime);
		}
		void Thread::Sleep(int milliseconds)
		{
			boost::posix_time::milliseconds sleepTime(milliseconds);
			boost::this_thread::sleep(sleepTime);
		}