Beispiel #1
0
void WindowManager::Render()
{
    list<WindowApplication*>::reverse_iterator windowIt = _windows.rbegin();
    list<WindowApplication*>::reverse_iterator finalWindow = _windows.rend();
    WindowApplication* ontop = 0;
    while (windowIt != finalWindow)
    {
        WindowApplication* window = (WindowApplication*)*windowIt;
        if (window->Settings->Enabled == 1)
        {
            window->Render();
            if (window->Settings->Fullscreen)
            {
                window->RenderFullscreen();
                FullScreenEnabled = 1;
                break;
            }

            if (window->Settings->OnTop == 1)
                ontop = window;
            else
                RenderWindow(window);
        }
        windowIt++;
    }
    if (ontop)
        RenderWindow(ontop);
    ontop = 0;
}
Beispiel #2
0
void RenderWindows( Window* window )
{
    memset( &map[0], ' ', sizeof(map) );

    RenderWindow( &map[0], &window[0] );
    RenderWindow( &map[0], &window[1] );
    RenderWindow( &map[0], &window[2] );

    for(uint32_t i=0; i<sizeof(map); i+=8)
    {
        printf("%c", map[i] );
    }
    printf("\n");
}
Beispiel #3
0
void TreeGeneratorCanvas::OnIdle(wxIdleEvent& event)
{
	if(gEngine->GetDriver()->GetD3DDevice())
		RenderWindow();

	event.RequestMore(true);
}
Beispiel #4
0
void ModelPreviewCanvas::OnIdle( wxIdleEvent& event )
{
	if(gEngine->GetDriver()->GetD3DDevice())
		RenderWindow();

	event.RequestMore(true);
}
Beispiel #5
0
void DXApp::Run()
{
	MSG msg = { 0 };

	BOOL bRet = 1;

	float dt = 0;
	PreInit();
	InitGame();
	LateInit();
	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			m_gameTimer->Tick();
			if (!m_appPaused)
			{
				CalculateFrameStats();
				dt += m_gameTimer->DeltaTime();
				if (dt >= 1.f / TICKS_PER_SECOND)
				{
					OnTickUpdate(m_gameTimer->DeltaTime());
					LateTickUpdate(m_gameTimer->DeltaTime());
					dt = 0;
					tick++;
				}
				if (tick == TICKS_PER_SECOND)
				{
					std::wstringstream ss;
					ss << "DirectX title - FPS: ";
					ss << fps;
					BOOL b = SetWindowText(m_mainHandle, LPCWSTR(ss.str().c_str()));
					DWORD d = GetLastError();
					fps = 0;
					tick = 0;
				}
				PrepareWindow();
				RenderUpdate();
				RenderWindow();
				fps++;
			}
			else
			{
				Sleep(100);
			}
		}
	}

}
Beispiel #6
0
//Our main loop which should continue running as long as we don't quite the game
static void MainLoop()
{
	char DLLFilePath[MAX_PATH];
	char *onePastLastSlash;

	DWORD pathSize = GetModuleFileNameA(NULL, DLLFilePath, sizeof(DLLFilePath));
	onePastLastSlash = DLLFilePath;

	for (char *scan = DLLFilePath; *scan; scan++)
	{
		if (*scan == '\\')
		{
			onePastLastSlash = scan + 1;
		}
	}
	char DLLFullPath[MAX_PATH];
	BuildFileFullPath(&state, "playground game.dll", DLLFullPath, sizeof(DLLFullPath));

	char tempDLLFullPath[MAX_PATH];
	BuildFileFullPath(&state, "playground game_temp.dll", tempDLLFullPath, sizeof(tempDLLFullPath));

	char PDBFullPath[MAX_PATH];
	BuildFileFullPath(&state, "playground game.pdb", PDBFullPath, sizeof(PDBFullPath));

	char tempPDBFullPath[MAX_PATH];
	BuildFileFullPath(&state, "playground game_temp.pdb", tempPDBFullPath, sizeof(tempPDBFullPath));

	Input = {};
	Input.UP.Button = VK_UP;
	Input.DOWN.Button = VK_DOWN;
	Input.RIGHT.Button = VK_RIGHT;
	Input.LEFT.Button = VK_LEFT;

	LARGE_INTEGER performanceFrequency;
	QueryPerformanceFrequency(&performanceFrequency);
	TicksPerSecond = performanceFrequency.QuadPart;

	int monitorRefreshHZ = 60;
	HDC deviceContext = GetDC(Window.Window);
	int refreshHz = GetDeviceCaps(deviceContext, VREFRESH);
	ReleaseDC(Window.Window, deviceContext);

	if (refreshHz > 1)
	{
		monitorRefreshHZ = refreshHz;
	}

	float gameUpdateHZ = (float)(monitorRefreshHZ);
	float targetSecondsPerFrame = 1.0f / gameUpdateHZ;

	UINT desiredSchedulerTime = 1;
	bool sleepIsSmaller = true;//timeBeginPeriod(desiredSchedulerTime) == TIMERR_NOERROR;

	LARGE_INTEGER lastTick = GetTicks();
	float updateTime = 0;
	int updates = 0;
	double frames = 0;
	double frameTime = 0;

	while (IsRunning)
	{
		/*
		start_loop = clock();
		*/

		FILETIME newWriteTimeDLL = GetLastWriteTime(DLLFullPath);
		FILETIME newWriteTimePDB = GetLastWriteTime(PDBFullPath);
		
		if (CompareFileTime(&newWriteTimeDLL, &Game.LastWriteTimeDLL) != 0 && CompareFileTime(&newWriteTimeDLL, &Game.LastWriteTimePDB) != 0)
		{
			UnloadGameCode(&Game);
			CopyFile(PDBFullPath, tempPDBFullPath, FALSE);
			Game = LoadGameCode(DLLFullPath, tempDLLFullPath);
			Game.Game_Init(Dimensions);
		}

		LARGE_INTEGER gameTimerStart = GetTicks();
		ProcessPendingMessages(&Keys);

		ProcessInput(&Input);

		//Update everything
		//Update the game
		Game.Game_Update(&Input);

		/*NOTE(kai): TEST ONLY*/
		//Testing if A button is pressed
		if (IsKeyDown(&Keys, 'A'))
		{
			OutputDebugString("Key: a is pressed\n");
		}
		//Testing if A button is released
		if (IsKeyUp(&Keys, 'A'))
		{
			OutputDebugString("Key: a is released\n");
		}		

		//Render everything
		//Clear the window
		ClearWindow();
		//Render the game
		Game.Game_Render();
		LARGE_INTEGER gameTimerEnd = GetTicks();
		frameTime += (double)(1000.0f * GetSecondsElapsed(gameTimerStart, gameTimerEnd));
		frames++;
		//frames += 1000.0f / (double)(1000.0f * GetSecondsElapsed(gameTimerStart, gameTimerEnd));
		//PrintTimeElapsed(lastTick, gameTimerEnd);

		float secondsElapsedForFrame = GetSecondsElapsed(lastTick, GetTicks());

		if (secondsElapsedForFrame < targetSecondsPerFrame)
		{
			if (sleepIsSmaller)
			{
				DWORD sleepTime = (DWORD)(1000.0f * (targetSecondsPerFrame - secondsElapsedForFrame));

				if (sleepTime > 0)
				{
					Sleep(sleepTime);
				}
			}

			while (secondsElapsedForFrame < targetSecondsPerFrame)
			{
				secondsElapsedForFrame = GetSecondsElapsed(lastTick, GetTicks());
			}
			updates++;
		}

		updateTime += GetSecondsElapsed(lastTick, GetTicks());

		if (updateTime >= 1.0f)
		{
			double avgFPS = 1000.0f / ((frameTime) / frames);
			std::cout << "UPS: " << updates << ", average FPS: " << avgFPS << ", average work/frame: " << (frameTime) / frames << "\n";
			
			frames = 0;
			frameTime = 0;
			updates = 0;
			updateTime = 0;
		}
		
		LARGE_INTEGER endTick = GetTicks();
		//PrintTimeElapsed(lastTick, endTick);
		lastTick = endTick;
		
		//Render the window
		RenderWindow(Window.Window);

		/*
		//calc fps 
		calcfps();
		static int framecount = 0;
		framecount++;
		if (framecount == 10) {
			framecount = 0;
			std::cout << "frame per second is : " << (fps) << std::endl;

		}
		//QueryPerformanceCounter(&t_current_loop);
		end_loop = clock();

		//float frameticks = (t_current_loop.QuadPart - t_previous_loop.QuadPart) / ((frequency_loop.QuadPart) / 1000.0);

		float frameticks = ((float)(end_loop - start_loop) / CLOCKS_PER_SEC) * 1000.0f;

		//print the current fps 

		// std::cout << 1000/frameticks << std::endl;

		if (1000.0f / max_fps > frameticks){

			Sleep(1000.0f / max_fps - frameticks);
		}
		*/

	}

	//Release resources (if there is any) and destory  the window
	Release();

}
void RenderWindowFrame(FRAMETYPE frame, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height)
{
	RenderWindow(frame, x, y, Width, Height, false);
}