Ejemplo n.º 1
0
void pEngine::Processing(){//float dt){

	dLastTime=dCurTime;
	dCurTime=::GetTickCount();
	fpDeltaTime=(dCurTime-dLastTime)/1000.0f;// 0.020
//	10 < fpDeltaTime < 30
	if (bGameOver) return;

	if (this->fpDeltaTime>0.03f) return; // 33.3 FPS
	if (this->fpDeltaTime<0.015f) return;// 66.6 FPS

	AssemblyRubbish();
	Collisions();

	//ProcessClients();//Вызывать не чаще 20 раз в сек. Как?!?

//	DWORD cur_time=GetTickCount();
//	Calculate();
//if ((cur_time-timers<1000)||(steps))
//if (steps)
//{
	Rotatings();
	Movings();
//}
}
Ejemplo n.º 2
0
void Game::Run(HWND hwnd)
{
	if(graphics == NULL) // if graphics not initialized
		return;

	// Calculate elapsed time of last frame, save in frameTime
	QueryPerformanceCounter(&timeEnd);
	frameTime = (float)(timeEnd.QuadPart - timeStart.QuadPart ) / (float)timerFreq.QuadPart;

	// Power saving code, requires winmm.lib
	// if not enough time has elapsed for desired frame rate
	if (frameTime < MIN_FRAME_TIME)
	{
		sleepTime = (DWORD)((MIN_FRAME_TIME - frameTime)*1000);
		timeBeginPeriod(1);			// request 1mS resolution for windows timer
		Sleep(sleepTime);			// release cpu for sleepTime
		timeEndPeriod(1);			// end 1mS timer resolution
		return;
	}

	if (frameTime > 0.0)
		fps = (fps*0.99f) + (0.01f/frameTime); // average fps
	if (frameTime > MAX_FRAME_TIME) // if frame rate is very slow
		frameTime = MAX_FRAME_TIME; // limit maximum frameTime
	timeStart = timeEnd;

	// Update(), AI(), and Collisions() are pure virtual functions.
	// These functions must be provided in the class that inherits from Game.
	if (!paused)
	{
		Collisions(); // handle collisions
		Update(); // update all game items
		AI(); // artificial intelligence
		//input->VibrateControllers(frameTime); // handle controller vibration
	}
	RenderGame();

	//check for console key
	if (input->WasKeyPressed(Key::TILDE))
	{
		console->showHide();
		paused = console->getVisible(); // pause game when console is visible
	}
	ConsoleCommand();               // process user entered console command

	input->ReadControllers(); // read state of controllers

	// if Alt+Enter toggle fullscreen/window
	if (input->IsKeyDown(Key::ALT) && input->WasKeyPressed(Key::ENTER))
		SetDisplayMode(GraphicsNS::TOGGLE); // toggle fullscreen/window

	// if Esc key, set window mode
	//if (input->IsKeyDown(Key::ESC))
		//SetDisplayMode(GraphicsNS::WINDOW); // set window mode

	// Clear input
	// Call this after all key checks are done
	input->Clear(InputNS::KEYS_PRESSED);
}