コード例 #1
0
TEST(TimeManagerTest, testTimeoutNoParam) {
	TimeManager time;
	timeManagerTestCallback.callbackNoParamCalled = false;
	time.setTimeout(1, &timeManagerTestCallback,
			&TimeManagerTestCallback::timeoutNoParamCallback);
	time.update(1);
	ASSERT_TRUE(timeManagerTestCallback.callbackNoParamCalled);
}
コード例 #2
0
TEST(TimeManagerTest, testTimeoutWithParam) {
	TimeManager time;
	timeManagerTestCallback.callbackWithParamCalled = false;
	float param = 5.50f;
	time.setTimeout(1, &timeManagerTestCallback,
			&TimeManagerTestCallback::timeoutWithParamCallback, (void*) &param);
	time.update(1);
	ASSERT_TRUE(timeManagerTestCallback.callbackWithParamCalled);
	ASSERT_EQ(timeManagerTestCallback.callbackParamValue, param);
}
コード例 #3
0
void mouseMove(int x, int y)
{
	Vector3r mousePos;
	MiniGL::unproject(x, y, mousePos);
	const Vector3r diff = mousePos - oldMousePos;

	TimeManager *tm = TimeManager::getCurrent();
	const Real h = tm->getTimeStepSize();

	ParticleData &pd = model.getParticles();
	for (unsigned int j = 0; j < selectedParticles.size(); j++)
	{
		pd.getVelocity(selectedParticles[j]) += 5.0*diff/h;
	}
	oldMousePos = mousePos;
}
コード例 #4
0
void mouseMove(int x, int y)
{
	Vector3r mousePos;
	MiniGL::unproject(x, y, mousePos);
	const Vector3r diff = mousePos - oldMousePos;

	TimeManager *tm = TimeManager::getCurrent();
	const float h = tm->getTimeStepSize();

	SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
	for (size_t j = 0; j < selectedBodies.size(); j++)
	{
		rb[selectedBodies[j]]->getVelocity() += 1.0f / h * diff;
	}
	oldMousePos = mousePos;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: naruse/SpaceInvadersSFML
void RenderingLoop() {
    // Clear screen
    gameManager.GetWindow().clear();
    gameManager.Render();
    // Update the window
    gameManager.GetWindow().display();
    timeManager.UpdateDelta();//calculate time to complete the last frame.
}
コード例 #6
0
void TimeStepFluidModel::step(FluidModel &model)
{
	TimeManager *tm = TimeManager::getCurrent ();
	const float h = tm->getTimeStepSize();
	ParticleData &pd = model.getParticles();

	clearAccelerations(model);

	// Compute viscosity forces
	if (TimeManager::getCurrent()->getTime() > 0.0)			// in the first step we do not know the neighbors
	{		
		computeDensities(model);
		computeViscosityAccels(model);
	}

	// Update time step size by CFL condition
	updateTimeStepSizeCFL(model, 0.0001f, 0.005f);

	// Time integration
	for (unsigned int i = 0; i < pd.size(); i++)
	{ 
		model.getDeltaX(i).setZero();
		pd.getLastPosition(i) = pd.getOldPosition(i);
		pd.getOldPosition(i) = pd.getPosition(i);
		TimeIntegration::semiImplicitEuler(h, pd.getMass(i), pd.getPosition(i), pd.getVelocity(i), pd.getAcceleration(i));
	}

	// Perform neighborhood search
	model.getNeighborhoodSearch()->neighborhoodSearch(&model.getParticles().getPosition(0), model.numBoundaryParticles(), &model.getBoundaryX(0));

	// Solve density constraint
	constraintProjection(model);

	// Update velocities	
	for (unsigned int i = 0; i < pd.size(); i++)
	{
		if (m_velocityUpdateMethod == 0)
			TimeIntegration::velocityUpdateFirstOrder(h, pd.getMass(i), pd.getPosition(i), pd.getOldPosition(i), pd.getVelocity(i));
		else
			TimeIntegration::velocityUpdateSecondOrder(h, pd.getMass(i), pd.getPosition(i), pd.getOldPosition(i), pd.getLastPosition(i), pd.getVelocity(i));
	}

	// Compute new time	
	tm->setTime (tm->getTime () + h);
	model.getNeighborhoodSearch()->update();
}
コード例 #7
0
int main(int argc, const char *argv[])
{
    BarotropicModel_Semiimp model;
    RossbyHaurwitzTestCase testCase;

    TimeManager timeManager;
    Time startTime, endTime(68*DAYS);
    //Time startTime, endTime(1*DAYS);

    timeManager.init(startTime, endTime, 4*MINUTES);

    model.init(80, 41);
    testCase.calcInitCond(model);

    model.run(timeManager);

    return 0;
}
コード例 #8
0
ファイル: animation-recorder.cpp プロジェクト: 499940913/moon
gboolean setup (void* data)
{
	if (runtime_get_surface_list () == NULL)
		return TRUE;

	Surface *surface = (Surface *) runtime_get_surface_list ()->data; 

	if (surface == NULL)
		return TRUE;
 
	TimeManager *manager = surface_get_time_manager (surface);
	ManualTimeSource *source = (ManualTimeSource *) manager->GetSource ();
    
	printf ("Setting up...\n");
	surface->SetExposeHandoffFunc (expose_handoff, NULL);
	g_idle_add (increase_timer, NULL);

	return FALSE;    
}
コード例 #9
0
void mouseMove(int x, int y)
{
	Eigen::Vector3f mousePos;
	MiniGL::unproject(x, y, mousePos);
	const Eigen::Vector3f diff = mousePos - oldMousePos;

	TimeManager *tm = TimeManager::getCurrent();
	const float h = tm->getTimeStepSize();

	SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
	for (size_t j = 0; j < selectedBodies.size(); j++)
	{
		rb[selectedBodies[j]]->getVelocity() += 1.0f / h * diff;
	}
	ParticleData &pd = model.getParticles();
	for (unsigned int j = 0; j < selectedParticles.size(); j++)
	{
		pd.getVelocity(selectedParticles[j]) += 5.0*diff / h;
	}
	oldMousePos = mousePos;
}
コード例 #10
0
	void CVariableStore::invalidate(TimeManager& timeManager)
	{
		lock_guard<std::mutex> lock(storeMutex);
		map<string, shared_ptr<ConsensusVariable>>::iterator it;
		for (it = store.begin(); it != store.end(); it++)
		{
			shared_ptr<ConsensusVariable> var = it->second;
			if (var->getValidityTime() < timeManager.getDistributedTime())
			{
				var->hasValue = false;
			}
		}
	}
コード例 #11
0
ファイル: animation-recorder.cpp プロジェクト: 499940913/moon
gboolean increase_timer (void *data)
{
	if (runtime_get_surface_list () == NULL)
		return TRUE;

	Surface *surface = (Surface *) runtime_get_surface_list ()->data; 

	if (surface == NULL)
		return TRUE;
    
	TimeManager *manager = surface_get_time_manager (surface);
	ManualTimeSource *source = (ManualTimeSource *) manager->GetSource ();

	source->SetCurrentTime (TimeSpan_FromSecondsFloat (current_time));
	current_time += 0.04; // 25 frames per second
	image_no++;

	if (current_time > 5.0) {
		printf ("ALL DONE! %d images captured\n", image_no - 1);
		exit (0);
	}

	return FALSE;
}
コード例 #12
0
void testManagers()
{	
	/*
	struct MyObject;
	struct MyStorage: public IDPair<MyStorage,MyObject>::Store
	{
	}storage;
	struct MyObject: public IDPair<MyStorage,MyObject>::Stored
	{
		MyObject(MyStorage *manager,const char *n)
			:Stored(manager),hello(n)
		{}
		std::string hello;
	};
	new MyObject(&storage,"object1");
	new MyObject(&storage,"object2");
	new MyObject(&storage,"object3");
	new MyObject(&storage,"object4");*/
	TimeManager manager;
	struct TestEvent : public TimeManager::Action
	{
	public:
		std::string eventMsg;
		TestEvent(const std::string &str):eventMsg(str){}
		virtual void Execute()
		{
			printf("TestEvent::Execute(%s)\n",eventMsg.c_str());
		}
	};
	manager.add(new TestEvent("Event 1"), 40);
	manager.add(new TestEvent("Event 2"), 60);
	manager.add(new TestEvent("Event 3"), 20);
	manager.add(new TestEvent("Event 4"), 50);
	for(int i = 0; i < 8; i++)
		manager.update(5);

	manager.add(new TestEvent("Event 5"), 20);
	manager.add(new TestEvent("Event 6"), 30);	
	for(int i = 0; i < 30; i++)
		manager.update(5);
	int w = 0;
}
コード例 #13
0
ファイル: LevelManager.cpp プロジェクト: sjuxax/JVGS
        void LevelManager::run()
        {
            /* Behold, as I have been told
             * what follows below
             * is very important, you know! */
            InputManager *inputManager = InputManager::getInstance();
            TimeManager *timeManager = TimeManager::getInstance();
            VideoManager *videoManager = VideoManager::getInstance();
            EffectManager *effectManager = EffectManager::getInstance();
            SketchManager *sketchManager = SketchManager::getInstance();

            FPSLogger fps;
 
            float freq_to_update = 1000.0f / 60.0f;

            long lastUpdate = timeManager->getTicks();
            while(!inputManager->hasQuitEvent()) {

                /* Calculate the ticks that have passed. */
                long ticks = timeManager->getTicks();
                float ms = (float)(ticks - lastUpdate);
                lastUpdate = ticks;

                /* Cap FPS by sleeping a little. */
                if(ms <= freq_to_update) {
                    float wait = freq_to_update - ms;
                    timeManager->sleep(wait);
                }

                /* Update the input state. */
                inputManager->update(ms);

                /* Update the level. */
                if(level && ms > 0.0f) level->update(timeFactor * ms);

                /* Update other things. */
                effectManager->update(timeFactor * ms);
                fps.update(ms);

                /* Setup the videoManager for rendering. */
                videoManager->clear();
                videoManager->identity();

                /* Render the level first, this will also apply our camera
                 * transformation, which is good, since the effect manager
                 * wants the same transformation. */
                if(level) level->render();
                effectManager->render();
                fps.render();

                /* Flip the video buffer. */
                videoManager->flip();

                /* Update level queue. */
                if(queue) {
                    /* Remove old level. */
                    if(level)
                        delete level;

                    effectManager->clear();
                    sketchManager->clear();

                    /* Load new level. */
                    level = new Level(queueFileName);
                    queue = false;
                    timeFactor = 1.0f;

                    /* Loading the level might have taken some time, so we skip
                     * some ticks. */
                    lastUpdate = timeManager->getTicks();
                }
            }
        }
コード例 #14
0
ファイル: main.cpp プロジェクト: fanghuan/IAP-CGFD
int main(int argc, const char *argv[])
{
    ConfigManager configManager;
    Domain domain(1);
    Mesh mesh(domain, 2);
    Field<double, 2> u, f;
    Field<double> fu;
    TimeManager timeManager;
    IOManager io;
    int outputFileIdx;
    TimeLevelIndex<2> oldIdx, newIdx, halfIdx;

    double dt, dx;
    string outputPattern = "beam_warming.%3s.nc";

    if (argc != 2) {
        REPORT_ERROR("Configure file is needed!");
    }

    // Read configuration from file.
    configManager.parse(argv[1]);
    dt = configManager.getValue("beam_warming", "dt", 1);
    dx = configManager.getValue("beam_warming", "dx", 0.01);
    outputPattern = configManager.getValue("beam_warming", "output_pattern", outputPattern);

    // Set the one dimensional space axis.
    domain.setAxis(0, "x", "x axis", "m",
                   0, geomtk::BndType::PERIODIC,
                   1, geomtk::BndType::PERIODIC);

    // Set the discrete mesh on the domain.
    mesh.init(domain.axisSpan(0)/dx);

    // Set the time manager.
    Time startTime(0*geomtk::TimeUnit::SECONDS);
    Time endTime(200*geomtk::TimeUnit::SECONDS);
    timeManager.init(startTime, endTime, dt);

    // Set up velocity and density fields.
    u.create("u", "m s-1", "velocity component along x axis", mesh, X_FACE, 1, true);
    f.create("f", "kg m-1", "tracer density", mesh, CENTER, 1);
    fu.create("fu", "kg s-1", "tracer mass flux", mesh, X_FACE, 1);

    // Set the initial conditions.
    newIdx = oldIdx+1;
    for (int i = mesh.is(HALF); i <= mesh.ie(HALF); ++i) {
        u(oldIdx, i) = 0.005;
        u(newIdx, i) = 0.005;
    }
    u.applyBndCond(oldIdx);
    u.applyBndCond(newIdx, true);
    for (int i = mesh.is(FULL); i <= mesh.ie(FULL); ++i) {
        const SpaceCoord &x = mesh.gridCoord(CENTER, i);
        if (x(0) >= 0.05 && x(0) <= 0.1) {
            f(oldIdx, i) = 1.0;
        } else {
            f(oldIdx, i) = 0.0;
        }
    }
    f.applyBndCond(oldIdx);

    // Set up IO manager.
    io.init(timeManager);
    outputFileIdx = io.registerOutputFile(mesh, outputPattern, geomtk::TimeStepUnit::STEP, 1);
    io.registerField(outputFileIdx, "double", FULL_DIMENSION, {&f});
    io.output<double, 2>(outputFileIdx, oldIdx, {&f});

    // Run the main loop.
    double C = dt/dx;
    while (!timeManager.isFinished()) {
        newIdx = oldIdx+1; halfIdx = oldIdx+0.5;
        for (int i = mesh.is(HALF); i <= mesh.ie(HALF); ++i) {
            fu(i) = 0.5*C*(      u(halfIdx, i)    *(3*f(oldIdx, i)-f(oldIdx, i-1))-
                           C*pow(u(halfIdx, i), 2)*(  f(oldIdx, i)-f(oldIdx, i-1)));
        }
        fu.applyBndCond();
        for (int i = mesh.is(FULL); i <= mesh.ie(FULL); ++i) {
            f(newIdx, i) = f(oldIdx, i)-(fu(i)-fu(i-1));
        }
        f.applyBndCond(newIdx);
        timeManager.advance(); oldIdx.shift();
        io.output<double, 2>(outputFileIdx, oldIdx, {&f});
    }

    return 0;
}
コード例 #15
0
ファイル: main.cpp プロジェクト: Th3NiKo/Projects
int main()
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Space Invaders");
    //STARTING SETTINGS

    AudioManager audioManager;
    BulletManager bulletManager;
    EnemyManager enemyManager;
    Randomizer random;
    TimeManager time;
    Menu mainMenu;
    Interface mainInterface;
    Player player(400, 500);
    Player *playerWsk = &player;

    //CONTROL VARIABLES
    bool menu = true;
    bool init = false;
    bool menuMusic = false;
    bool stageTwo = false;


    mainMenu.loadData();

    while (window.isOpen())
    {
        if(menu == false)
        {

            if(init == false)
            {
                audioManager.stopMenu();
                menuMusic = false;

                player.setHealth(3);


                //CREATING ENEMIES and INITILIAZING
                enemyManager.addEnemies(); //2 ROWS


                random.initialize();
                audioManager.playMusic();
                init = true;
            }
        if((stageTwo == false) && (mainInterface.getScore() >= 280))
        {
            enemyManager.addEnemiesMedium();
            stageTwo = true;

        }
        if((mainInterface.getScore() >= 560))
        {
            audioManager.stopMusic();
            init = false;
            menu = true;
        }

        time.updateShoot();
        time.updateRandomShoot();
        // REFRESHING WINDOW
        // ALL PHYSICS HERE

        while(time.getAccumulator() > time.getUps())
        {
            time.updateAccumulator();
            player.keyboardControl(time.getUps(), bulletManager, time.getShootTimer(), time, audioManager);
            enemyManager.controlEnemies(random, bulletManager, time);
            bulletManager.controlBullets(time.getUps());


            //COLLISIONS
            bulletManager.checkPlayerCollisions(playerWsk);
            enemyManager.updateDead(bulletManager);
            player.gameOver(audioManager, menu, init);

        }


        //SIMPLE EVENTS
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        mainInterface.checkRecords(mainMenu);

        //DRAWING
        window.clear();
        mainInterface.drawText(window, player.getHealth());
        enemyManager.drawEnemies(window);
        window.draw(player.getSprite());
        bulletManager.drawBullets(window);
        window.display();

         if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            {
                window.close();
            }

        time.restartAccumulator();
        }
        else
        {

            if(menuMusic == false)
            {
                audioManager.playMenu();
                menuMusic = true;
            }

            enemyManager.clearAll();
            bulletManager.clearAll();
            time.clearAll();
            mainInterface.clearScore();

            mainMenu.keyboardControl(window, menu);

            sf::Event event;
            while (window.pollEvent(event))
            {
                if (event.type == sf::Event::Closed)
                window.close();
            }
            window.clear();
            mainMenu.drawMenu(window);
            window.display();

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
            {
                window.close();
            }
        }


    }

    return EXIT_SUCCESS;
}
コード例 #16
0
ファイル: VisualizerFMU.cpp プロジェクト: hkiel/OMEdit
void VisualizerFMU::simulate(TimeManager& omvm)
{
  while (omvm.getSimTime() < omvm.getRealTime() + omvm.getHVisual() && omvm.getSimTime() < omvm.getEndTime())
    omvm.setSimTime(simulateStep(omvm.getSimTime()));
}
コード例 #17
0
ファイル: TimeManager.cpp プロジェクト: RedChiken/Calendar
bool TimeManager::operator==(TimeManager input) {
	return ((this->hour == input.hour) && (this->min == input.min) && ((int)this->sec == (int)input.sec) && \
		(this->solarDate.solarDay == input.getSolarDay()) && (this->solarDate.solarMonth == input.getSolarMonth()) && \
		(this->solarDate.solarYear == input.getSolarYear()));
}
コード例 #18
0
ファイル: TimeManager.cpp プロジェクト: RedChiken/Calendar
bool TimeManager::operator> (TimeManager input) {
	//2015.11.30 09.12.02 vs 2015.11.29 09.12.02
	//2015.11.30 09.12.02 vs 2015.11.30 09.12.22c
	//2014 2015 이면 당연히 
	if (this->solarDate.solarYear > input.getSolarYear()) { return true; }
	else if (this->solarDate.solarYear < input.getSolarYear()) { return false; } //연도 비교

	if (this->solarDate.solarMonth > input.getSolarMonth()) { return true; } //월 비교
	else if (this->solarDate.solarMonth < input.getSolarMonth()) { return false; }

	if (this->solarDate.solarDay > input.getSolarDay()) { return true; } //일 비교
	else if (this->solarDate.solarDay < input.getSolarDay()) { return false; }

	if (this->hour > input.getHour()) { return true; } //일 비교
	else if (this->hour < input.getHour()) { return false; }

	if (this->min > input.getMinute()) { return true; } //일 비교
	else if (this->min < input.getMinute()) { return false; }

	if (this->sec > input.getSecond()) { return true; } //일 비교
	else if (this->sec < input.getSecond()) { return false; }

	return false;
}
コード例 #19
0
void TimeStepController::step(SimulationModel &model)
{
 	TimeManager *tm = TimeManager::getCurrent ();
 	const float h = tm->getTimeStepSize();
 
	//////////////////////////////////////////////////////////////////////////
	// rigid body model
	//////////////////////////////////////////////////////////////////////////
 	clearAccelerations(model);
	SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
	ParticleData &pd = model.getParticles();
	ParticleData &pg = model.getGhostParticles();

	#pragma omp parallel default(shared)
	{
		#pragma omp for schedule(static) nowait
		for (int i = 0; i < (int) rb.size(); i++)
 		{ 
			rb[i]->getLastPosition() = rb[i]->getOldPosition();
			rb[i]->getOldPosition() = rb[i]->getPosition();
			TimeIntegration::semiImplicitEuler(h, rb[i]->getMass(), rb[i]->getPosition(), rb[i]->getVelocity(), rb[i]->getAcceleration());
			rb[i]->getLastRotation() = rb[i]->getOldRotation();
			rb[i]->getOldRotation() = rb[i]->getRotation();
			TimeIntegration::semiImplicitEulerRotation(h, rb[i]->getMass(), rb[i]->getInertiaTensorInverseW(), rb[i]->getRotation(), rb[i]->getAngularVelocity(), rb[i]->getTorque());
			rb[i]->rotationUpdated();
 		}

		//////////////////////////////////////////////////////////////////////////
		// particle model
		//////////////////////////////////////////////////////////////////////////
		#pragma omp for schedule(static) 
		for (int i = 0; i < (int) pd.size(); i++)
		{
			pd.getLastPosition(i) = pd.getOldPosition(i);
			pd.getOldPosition(i) = pd.getPosition(i);

			pd.getVelocity(i) *= (1.0f - m_damping);

			TimeIntegration::semiImplicitEuler(h, pd.getMass(i), pd.getPosition(i), pd.getVelocity(i), pd.getAcceleration(i));
		}

		for (int i = 0; i < (int)pg.size(); i++)
		{
			pg.getLastPosition(i) = pg.getOldPosition(i);
			pg.getOldPosition(i) = pg.getPosition(i);

			pg.getVelocity(i) *= (1.0f - m_damping);

			TimeIntegration::semiImplicitEuler(h, pg.getMass(i), pg.getPosition(i), pg.getVelocity(i), pg.getAcceleration(i));
		}
	}
 
	positionConstraintProjection(model);
 
	#pragma omp parallel default(shared)
	{
 		// Update velocities	
		#pragma omp for schedule(static) nowait
		for (int i = 0; i < (int) rb.size(); i++)
 		{
			if (m_velocityUpdateMethod == 0)
			{
				TimeIntegration::velocityUpdateFirstOrder(h, rb[i]->getMass(), rb[i]->getPosition(), rb[i]->getOldPosition(), rb[i]->getVelocity());
				TimeIntegration::angularVelocityUpdateFirstOrder(h, rb[i]->getMass(), rb[i]->getRotation(), rb[i]->getOldRotation(), rb[i]->getAngularVelocity());
			}
			else
			{
				TimeIntegration::velocityUpdateSecondOrder(h, rb[i]->getMass(), rb[i]->getPosition(), rb[i]->getOldPosition(), rb[i]->getLastPosition(), rb[i]->getVelocity());
				TimeIntegration::angularVelocityUpdateSecondOrder(h, rb[i]->getMass(), rb[i]->getRotation(), rb[i]->getOldRotation(), rb[i]->getLastRotation(), rb[i]->getAngularVelocity());
			}
 		}

		// Update velocities	
		#pragma omp for schedule(static) 
		for (int i = 0; i < (int) pd.size(); i++)
		{
			if (m_velocityUpdateMethod == 0)
				TimeIntegration::velocityUpdateFirstOrder(h, pd.getMass(i), pd.getPosition(i), pd.getOldPosition(i), pd.getVelocity(i));
			else
				TimeIntegration::velocityUpdateSecondOrder(h, pd.getMass(i), pd.getPosition(i), pd.getOldPosition(i), pd.getLastPosition(i), pd.getVelocity(i));
		}

		#pragma omp for schedule(static) 
		for (int i = 0; i < (int)pg.size(); i++)
		{
			if (m_velocityUpdateMethod == 0)
				TimeIntegration::velocityUpdateFirstOrder(h, pg.getMass(i), pg.getPosition(i), pg.getOldPosition(i), pg.getVelocity(i));
			else
				TimeIntegration::velocityUpdateSecondOrder(h, pg.getMass(i), pg.getPosition(i), pg.getOldPosition(i), pg.getLastPosition(i), pg.getVelocity(i));
		}
	}

	velocityConstraintProjection(model);

	// compute new time	
	tm->setTime (tm->getTime () + h);
}