예제 #1
0
/*
 * Called every seconds to update the visuals
 */
void second_timer_callback(struct tick_t *t)
{
	t->delay = TICK_SECOND;
	
	if (state & state_IncrementTime) {
		pwmSet(pwmRunning);
		decimalInc();
	} else {
		if (tick_timer_fired(delay_StopFade)) {
			stopTimerCount++;
			if (stopTimerCount >= STANDBY_DELAY) {
				if (OCR0A < 0xff) {
					if ((stopTimerCount & 0xf) == 0) // very gradualy fade out to zero (notch every 8 secs)
						OCR0A++;
				} else
					sleepTimer(); // this will stop the one second timer
			} else {
				if (OCR0A != pwmStopped) {
					if (OCR0A > pwmStopped)
						OCR0A--;
					else
						OCR0A++;
				}
			}
		}			
	}
	updateTimerDisplay();
}
예제 #2
0
파일: Wasabi.cpp 프로젝트: ngopee/Wasabi
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int cmdShow) {
	WInitializeTimers();

	Wasabi* app = WInitialize();
	app->maxFPS = 60.0f;

	app->SoundComponent = new WSoundComponent();

#ifdef _WIN32
	app->WindowComponent = new WWC_Win32(app);
	app->InputComponent = new WIC_Win32(app);
#elif defined(__linux__)
	app->WindowComponent = new WWC_Linux(app);
	app->InputComponent = new WIC_Linux(app);
#endif

	if (app->Setup()) {
		WTimer tmr(W_TIMER_SECONDS);
		WTimer fpsChangeTmr(W_TIMER_SECONDS);
		fpsChangeTmr.Start();
		UINT numFrames = 0;
		float deltaTime = 0.0f;
		while (!app->__EXIT) {
			tmr.Reset();
			tmr.Start();

			if (!app->WindowComponent->Loop())
				continue;

			if (deltaTime) {
				if (!app->Loop(deltaTime))
					break;
				if (app->curState)
					app->curState->Update(deltaTime);
			}

			// TODO: render
			//while (app->core->Update(deltaTime) == HX_WINDOWMINIMIZED)
			//	hx->core->Loop();

			numFrames++;

			deltaTime = app->FPS < 0.0001 ? 1.0f / 60.0f : 1.0f / app->FPS;

			if (app->maxFPS > 0.001) {
				float maxDeltaTime = 1.0f / app->maxFPS; // delta time at max FPS
				if (deltaTime < maxDeltaTime) {
					WTimer sleepTimer(W_TIMER_SECONDS);
					sleepTimer.Start();
					while (sleepTimer.GetElapsedTime() < (maxDeltaTime - deltaTime));
					deltaTime = maxDeltaTime;
				}
			}

			if (fpsChangeTmr.GetElapsedTime() >= 0.5f) //0.5 second passed -> update FPS
			{
				app->FPS = (float)numFrames * 2.0f;
				numFrames = 0;
				fpsChangeTmr.Reset();
			}
		}

		app->Cleanup();
	}

	W_SAFE_DELETE(app);

	WUnInitializeTimers();

	return 0;
}