void ApplicationController::processSimulation()
{
  while (simulate)
  {
    stepSimulation();
  std::this_thread::sleep_for(std::chrono::milliseconds(interval));
  }
}
static int stepSimulationThreadSafe(rtSimulationThread_t *p_thread)
{
	//EXEC HOLD_TIME_TAKING(simulationExecutionTime);
	pthread_mutex_lock(&p_thread->simulationMutex);
	//EXEC RESUME_TIME_TAKING(simulationExecutionTime);
	int ret = stepSimulation(&p_thread->simulation);
	pthread_mutex_unlock(&p_thread->simulationMutex);
	return ret;
}
void ParticleEffectEntityItem::update(const quint64& now) {

    float deltaTime = (float)(now - _lastSimulated) / (float)USECS_PER_SECOND;
    _lastSimulated = now;

    if (isEmittingParticles()) {
        stepSimulation(deltaTime);
    }

    EntityItem::update(now); // let our base class handle it's updates...
}
Beispiel #4
0
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	if(!createWindow(SAMPLE_NAME,DISPLAY_WIDTH,DISPLAY_HEIGHT)) {
		MessageBox(NULL,"Can't create gl window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return 0;
	}
	
	init();
	
	physics_create_scene(sceneId);

	PfxPerfCounter counter;
	counter.countBegin("dt");

	SCE_PFX_PRINTF("## %s: INIT SUCCEEDED ##\n", SAMPLE_NAME);
	
	MSG msg;
	while(s_isRunning) {
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
			if(msg.message==WM_QUIT) {
				s_isRunning = false;
			}
			else {
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else {
			counter.countEnd();
			float dt = counter.getCountTime(0)/1000.f;

			update(dt);

			if(simulating) 
				stepSimulation(dt);

			counter.resetCount();
			counter.countBegin("dt");

			render();

			perf_sync();
		}
	}

	shutdown();

	SCE_PFX_PRINTF("## %s: FINISHED ##\n", SAMPLE_NAME);

	releaseWindow();
	return (msg.wParam);
}
void ParticleEffectEntityItem::update(const quint64& now) {

    float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
     _lastAnimated = now;

    // only advance the frame index if we're playing
    if (getAnimationIsPlaying()) {
        _animationLoop.simulate(deltaTime);
    }

    if (isAnimatingSomething()) {
        stepSimulation(deltaTime);
    }

    EntityItem::update(now); // let our base class handle it's updates...
}
Beispiel #6
0
void Simulator::mainLoop (void) {
    // TODO: change duration so it limits to 100 updates a second, but allows
    // for slower times if the client really has to think about things.
    std::cout << "Mainloop running" << std::endl;
    while (running) {
        sendSensors();
        nextControl = getControl();
        entities->rocket->applyControl(nextControl);
        stepSimulation(1./100);

        // Rate limit the simulation
        std::chrono::milliseconds dura(10);
        std::this_thread::sleep_for(dura);
    }
    std::cout << "Mainloop not running" << std::endl;
}
void ParticleEffectEntityItem::update(const quint64& now) {

    // we check for 'now' in the past in case users set their clock backward
    if (now < _lastSimulated) {
        _lastSimulated = now;
        return;
    }

    float deltaTime = (float)(now - _lastSimulated) / (float)USECS_PER_SECOND;
    _lastSimulated = now;

    if (isEmittingParticles()) {
        stepSimulation(deltaTime);
    }

    EntityItem::update(now); // let our base class handle it's updates...
}
Beispiel #8
0
int main(int argc, char** argv)
{
   srand(time(0));
   config(&argc, argv);

   initNetwork();
   initSimulation();
   initDisplay(&argc, argv);

   for(;;)
   {
      stepNetwork();
      stepSimulation();
      stepDisplay();
   };

   return 0;
}
void ParticleEffectEntityItem::update(const quint64& now) {

    float deltaTime = (float)(now - _lastAnimated) / (float)USECS_PER_SECOND;
     _lastAnimated = now;

    // only advance the frame index if we're playing
    if (getAnimationIsPlaying()) {
        _animationLoop.simulate(deltaTime);
    }

    if (isAnimatingSomething()) {
        stepSimulation(deltaTime);

        // update the dimensions
        glm::vec3 dims;
        dims.x = glm::max(glm::abs(_particleMinBound.x), glm::abs(_particleMaxBound.x)) * 2.0f;
        dims.y = glm::max(glm::abs(_particleMinBound.y), glm::abs(_particleMaxBound.y)) * 2.0f;
        dims.z = glm::max(glm::abs(_particleMinBound.z), glm::abs(_particleMaxBound.z)) * 2.0f;
        setDimensions(dims);
    }

    EntityItem::update(now); // let our base class handle it's updates...
}
void DynamicsWorld::update(btScalar dt)
{
	stepSimulation(dt, maxSubSteps, timeStep);
	//CProfileManager::dumpAll();
}
Beispiel #11
0
void ForkLiftDemo::stepSimulation(float deltaTime)
{

	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

	
	{			
		int wheelIndex = 2;
		m_vehicle->applyEngineForce(gEngineForce,wheelIndex);
		m_vehicle->setBrake(gBreakingForce,wheelIndex);
		wheelIndex = 3;
		m_vehicle->applyEngineForce(gEngineForce,wheelIndex);
		m_vehicle->setBrake(gBreakingForce,wheelIndex);


		wheelIndex = 0;
		m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex);
		wheelIndex = 1;
		m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex);

	}


	float dt = deltaTime;
	
	if (m_dynamicsWorld)
	{
		//during idle mode, just run 1 simulation step maximum
		int maxSimSubSteps =  2;
		
		int numSimSteps;
        numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);

		if (m_dynamicsWorld->getConstraintSolver()->getSolverType()==BT_MLCP_SOLVER)
		{
			btMLCPSolver* sol = (btMLCPSolver*) m_dynamicsWorld->getConstraintSolver();
			int numFallbacks = sol->getNumFallbacks();
			if (numFallbacks)
			{
				static int totalFailures = 0;
				totalFailures+=numFallbacks;
				printf("MLCP solver failed %d times, falling back to btSequentialImpulseSolver (SI)\n",totalFailures);
			}
			sol->setNumFallbacks(0);
		}


//#define VERBOSE_FEEDBACK
#ifdef VERBOSE_FEEDBACK
				if (!numSimSteps)
			printf("Interpolated transforms\n");
		else
		{
			if (numSimSteps > maxSimSubSteps)
			{
				//detect dropping frames
				printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps);
			} else
			{
				printf("Simulated (%i) steps\n",numSimSteps);
			}
		}
#endif //VERBOSE_FEEDBACK

	}

	
	

}
Beispiel #12
0
int main(int argc, char **argv)
{
	bool keepGoing = true;

	srand(time(NULL)); //seed random generator

	parseArguments(argc, argv);

	allocWorld();
	fillWorld();
	
	Timer renderTimer = makeTimer(1.0 / config.framerate);

	if (config.render)
		initRender();

	if (config.measureSamples < 0) {
		/* Loop forever, or until the user quits the renderer */
		while (stepSimulation(&renderTimer));
	} else {
		printf("Waiting for system to relax.\n");
		for (double t = 0; keepGoing && t < config.measureWait; t += config.timeStep) {
			keepGoing = stepSimulation(&renderTimer);
			if (fmod(t, config.measureWait / 100) < config.timeStep) {
				printf("\rRelax time %13f of %f",
						(t + config.measureWait/100) / TIME_FACTOR, 
						config.measureWait / TIME_FACTOR);
				fflush(stdout);
			}
		}

		/* Perform the measurements */
		printf("\nStarting measurement.\n");
		FILE *outstream = fopen(DATA_FILE_NAME, "w");
		//plotHeader(outstream);
		double intervalTime = 0;
		for (long sample = 0; keepGoing && sample < config.measureSamples; sample++) {
			while (keepGoing && intervalTime <= config.measureInterval) {
				keepGoing = stepSimulation(&renderTimer);
				intervalTime += config.timeStep;
			}
			if (!keepGoing)
				break;

			/* Check for numerical drift (or bugs) before 
			 * commiting measurement. */
			if (!physicsCheck())
				die("You broke physics!\n");

			dumpEnergies(outstream);
			printf("\rMeasured sample %ld/%ld", sample + 1, config.measureSamples);
			fflush(stdout);
			intervalTime -= config.measureInterval;
		}
		printf("\n");
		fclose(outstream);
	}

	freeWorld();
	return 0;
}
Beispiel #13
0
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WindowDetails* details = DefineWindow(hInstance, nShowCmd);
	MSG msg;

	int rows = details->Height / gCellSize + 2;
	int columns = details->Width / gCellSize + 2;
	int prevCellSize = gCellSize;

	int* sim = createSimulationMatrix(rows, columns, gBoundary);
	populateSimulation(gSimulationMode, sim, rows, columns, 0.35);
	clock_t prevTime = clock();

	while (running)
	{
		while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessageW(&msg);
		}

		if (prevCellSize != gCellSize)
		{
			fitWindow(gCellSize, prevCellSize, details);
			prevCellSize = gCellSize;
		}

		switch (ButtonMessage)
		{
		case 1:
			free(sim);
			sim = createSimulationMatrix(rows, columns, gBoundary);
			populateSimulation(gSimulationMode, sim, rows, columns, 0.35);
			generation = 0;
			break;
		case 2:
			gSimulationMode++;
			if (gSimulationMode > 2)
				gSimulationMode = 0;

			free(sim);
			sim = createSimulationMatrix(rows, columns, gBoundary);
			populateSimulation(gSimulationMode, sim, rows, columns, 0.35);

			generation = 0;
			break;
		case 3:
			gBoundary = !gBoundary;
			break;
		}
		ButtonMessage = 0;

		clock_t curTime = clock();
		if (((double)(curTime - prevTime) / CLOCKS_PER_SEC) >= gStepsPerSecond && !paused)
		{
			prevTime = curTime;
			generation++;
			swprintf_s(title, 256, titleFormat, generation, gSimulationMode, gBoundary, (int)(1 / gStepsPerSecond));
			SetWindowTextW(details->Window, title);

			int* newSim = stepSimulation(gSimulationMode, details->BackBuffer, details->Width, sim, rows, columns, gBoundary, gCellSize);
			sim = newSim;

			StretchDIBits(details->DC,
				0, 0, details->Width, details->Height,
				0, 0, details->BitMapInfo.bmiHeader.biWidth, Abs(details->BitMapInfo.bmiHeader.biHeight),
				details->BackBuffer, &details->BitMapInfo,
				DIB_RGB_COLORS, SRCCOPY);
		}
	}

	ReleaseDC(NULL, details->DC);
	free(details->BackBuffer);
	free(details);

	return EXIT_SUCCESS;
}