Пример #1
0
bool CALL HGE_Impl::System_Start()
{
	//Tu.NguyenHoang Gameloop here	
	if(!procFrameFunc) {
		_PostError("System_Start: No frame function defined");
		return false;
	}
	bActive=true;
	// MAIN LOOP
	bool done = false;
	while (!done) {
		SDL_Event event;
		while (SDL_PollEvent(&event)) {	
			//ProcessInput : Will implement later
			done = ProcessInput(&event);
			if (done)
				break;
		}
		//Process FrameRate
		dt = SDL_GetTicks() - t0;				
		if (dt >= nFixedDelta)
		{
			fDeltaTime = dt / 1000.0f;
			if (fDeltaTime > 0.2f){
				if (nFixedDelta)
					fDeltaTime = nFixedDelta / 1000.0f;
				else
					fDeltaTime = 0.01f;
			}
			fTime += fDeltaTime;
			t0 = SDL_GetTicks();
			if (t0 - t0fps < 1000)
				cfps++;
			else {
				nFPS = cfps;
				cfps = 0;
				t0fps = t0;
			}
			//UpdateFrame
			if (procFrameFunc()){
				break;
			}
			_ClearQueue();
			//Render
			if (procRenderFunc)
				procRenderFunc();
			//_ClearQueue();
		}
		else{
			if (nFixedDelta && dt + 3 < nFixedDelta)
				SDL_Delay(1);
		}
	}

	_ClearQueue();

	bActive=false;

	return true;
}
Пример #2
0
void CALL HGE_Impl::System_Shutdown()
{
	System_Log("\nFinishing..");

	_ClearQueue();
	_SoundDone();
	_GfxDone();
	_DonePowerStatus();
	SDL_Quit();
	System_Log("The End.");
}
Пример #3
0
void CALL HGE_Impl::System_Shutdown()
{
	System_Log("\nFinishing..");

	timeEndPeriod(1);
	_ClearQueue();
	_SoundDone();
	_GfxDone();
	if(hwnd)
	{
		//ShowWindow(hwnd, SW_HIDE);
		//SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_TOOLWINDOW);
		//ShowWindow(hwnd, SW_SHOW);
		DestroyWindow(hwnd);
		hwnd=0;
	}
	if(hInstance) UnregisterClass(WINDOW_CLASS_NAME, hInstance);

	System_Log("The End.");
}
Пример #4
0
bool CALL HGE_Impl::System_Start()
{
	MSG		msg;

	if(!hwnd)
	{
		_PostError("System_Start: System_Initiate wasn't called");
		return false;
	}

	if(!procFrameFunc) {
		_PostError("System_Start: No frame function defined");
		return false;
	}

	bActive=true;

	// MAIN LOOP

	for(;;)
	{
		
		// Process window messages if not in "child mode"
		// (if in "child mode" the parent application will do this for us)

		if(!hwndParent)
		{
			if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
			{ 
				if (msg.message == WM_QUIT)	break;
				// TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
		}

		// Check if mouse is over HGE window for Input_IsMouseOver

		_UpdateMouse();

		// If HGE window is focused or we have the "don't suspend" state - process the main loop

		if(bActive || bDontSuspend)
		{
			// Ensure we have at least 1ms time step
			// to not confuse user's code with 0

			do { dt=timeGetTime() - t0; } while(dt < 1);

			// If we reached the time for the next frame
			// or we just run in unlimited FPS mode, then
			// do the stuff

			if(dt >= nFixedDelta)
			{
				// fDeltaTime = time step in seconds returned by Timer_GetDelta

				fDeltaTime=dt/1000.0f;

				// Cap too large time steps usually caused by lost focus to avoid jerks

				if(fDeltaTime > 0.2f)
				{
					fDeltaTime = nFixedDelta ? nFixedDelta/1000.0f : 0.01f;
				}

				// Update time counter returned Timer_GetTime

				fTime += fDeltaTime;

				// Store current time for the next frame
				// and count FPS

				t0=timeGetTime();
				if(t0-t0fps <= 1000) cfps++;
				else
				{
					nFPS=cfps; cfps=0; t0fps=t0;
					_UpdatePowerStatus();
				}

				// Do user's stuff

				if(procFrameFunc()) break;
				if(procRenderFunc) procRenderFunc();
				
				// If if "child mode" - return after processing single frame

				if(hwndParent) break;

				// Clean up input events that were generated by
				// WindowProc and weren't handled by user's code

				_ClearQueue();

				// If we use VSYNC - we could afford a little
				// sleep to lower CPU usage

				// if(!bWindowed && nHGEFPS==HGEFPS_VSYNC) Sleep(1);
			}

			// If we have a fixed frame rate and the time
			// for the next frame isn't too close, sleep a bit

			else
			{
				if(nFixedDelta && dt+3 < nFixedDelta) Sleep(1);
			}
		}

		// If main loop is suspended - just sleep a bit
		// (though not too much to allow instant window
		// redraw if requested by OS)

		else Sleep(1);
	}

	_ClearQueue();

	bActive=false;

	return true;
}
Пример #5
0
bool CALL HGE_Impl::System_Start()
{
	MSG		msg;
	POINT	pt;
	RECT	rc;

	if(!hwnd)
	{
		_PostError("System_Start: System_Initiate wasn't called");
		return false;
	}

	if(!procFrameFunc) {
		_PostError("System_Start: No frame function defined");
		return false;
	}

	bActive=true;

	for(;;)
	{
		
		if(!hwndParent)
		{
			if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
			{ 
				if (msg.message == WM_QUIT)	break;
				// TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
		}

		GetCursorPos(&pt);
		GetClientRect(hwnd, &rc);
		MapWindowPoints(hwnd, NULL, (LPPOINT)&rc, 2);
		if(bCaptured || (PtInRect(&rc, pt) && WindowFromPoint(pt)==hwnd)) bMouseOver=true;
		else bMouseOver=false;

		if(bActive || bDontSuspend) {
			do { dt=timeGetTime() - t0; } while(dt < 1);
			if(dt >= nFixedDelta)
			{
				fDeltaTime=dt/1000.0f;
				if(fDeltaTime > 0.2f)
				{
					if(nFixedDelta) fDeltaTime=nFixedDelta/1000.0f;
					else fDeltaTime=0.01f;
				}
				fTime+=fDeltaTime;

				t0=timeGetTime();
				if(t0-t0fps < 1000) cfps++;
				else {nFPS=cfps; cfps=0; t0fps=t0;}
				if(procFrameFunc()) break;
				if(procRenderFunc) procRenderFunc();
				if(hwndParent) break;
				_ClearQueue();
				if(!bWindowed && nHGEFPS==HGEFPS_VSYNC) Sleep(1);
			}
			else { if(nFixedDelta && dt+3 < nFixedDelta) Sleep(1); }
		}
		else Sleep(1);
	}
	_ClearQueue();
	bActive=false;
	return true;
}