예제 #1
0
// D3D ½ÇÇà (¸Þ¼¼Áö ·çÇÁ)
int cInitD3D::Run()
{
	MSG msg = { 0 };
	mTimer.Reset();

	// ¸Þ¼¼Áö ·çÇÁ
	while (msg.message != WM_QUIT)
	{
		// À©µµ¿ì ¸Þ¼¼Áö°¡ µé¾î¿Ô´Â°¡?
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		// ¾Æ´Ï¶ó¸é, ·»´õ¸µ
		else
		{
			// ŸÀ̸Ó
			mTimer.Tick();

			if (!mAppPaused)
			{
				CalculateFrameStats();
				UpdateScene(mTimer.DeltaTime());
				DrawScene();
			}
			else
			{
				// ÇÁ·¹ÀÓ Àç°è»êÇÏ´Â ½Ã°£
				Sleep(100);
			}
		}
	}
	return (int)msg.wParam;
}
예제 #2
0
int D3DApp::Run()
{
	MSG msg = {0};
 
	mTimer.Reset();

	while(msg.message != WM_QUIT)
	{
		// If there are Window messages then process them.
		if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
		{
            TranslateMessage( &msg );
            DispatchMessage( &msg );
		}
		// Otherwise, do animation/game stuff.
		else
        {	
			mTimer.Tick();

			if( !mAppPaused )
			{
				CalculateFrameStats();
				UpdateScene(mTimer.DeltaTime());	
				DrawScene();
			}
			else
			{
				Sleep(100);
			}
        }
    }

	return (int)msg.wParam;
}
예제 #3
0
int DemoBase::RunDemo()
{
	MSG msg = { 0 };

	mTimer.Reset();

	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			mTimer.Tick();

			if (!mAppPaused)
			{
				CalculateFrameStats();
				UpdateScene(mTimer.DeltaTime());
				DrawScene();
			}
			else
			{
				Sleep(100);
			}
		}
	}

	return (int)msg.wParam;
}
예제 #4
0
int Game::start(void(*buildFunc)(), void(*destructFunc)())
{
	if (game == nullptr)
		return EXIT_FAILURE;

	this->destructFunc = destructFunc;

	if (!InitMainWindow())
	{
		delete game;
		return EXIT_FAILURE;
	}

	if (!InitDirect3D())
	{
		delete game;
		return EXIT_FAILURE;
	}

	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	initEngine();

	buildFunc();

	NetworkManager::networkManager->Initialize(2);
	NetworkManager::networkManager->AssignTask([]() { NetworkManager::networkManager->startClient(); });

	MSG msg = { 0 };

	while (msg.message != WM_QUIT)
	{
		// Peek at the next message (and remove it from the queue)
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			// Handle this message
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else if (!minimized) // No message to handle
		{
			if (Input::wasControlPressed("quit"))
				PostQuitMessage(0);

			// Update the timer for this frame
			UpdateTimer();

			// Standard game loop type stuff
			CalculateFrameStats();
			update(deltaTime, totalTime);

			draw();// (deltaTime, totalTime);
			Input::updateControlStates();
		}
	}

	delete game;
	
	return (int)msg.wParam;
}
예제 #5
0
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_MY121614SIMPLE2DGAME, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	g_pMainGame = new cMainGame;
	g_pMainGame->Setup();
	srand(GetCurrentTime());

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY121614SIMPLE2DGAME));

	g_Timer.Reset();

	// 기본 메시지 루프입니다.
	while (true)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				break;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			g_Timer.Tick();
			CalculateFrameStats();
			g_pMainGame->Update(g_Timer.DeltaTime());
			g_pMainGame->Render();
		}
	}

	delete g_pMainGame;
	return (int) msg.wParam;
}
예제 #6
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);
			}
		}
	}

}
예제 #7
0
// The actual game loop, which processes the windows message queue
// and calls our Update & Draw methods
int DirectXGame::Run()
{
	MSG msg = { 0 };
	timer.Reset();

	// Loop until we get a quit message from windows
	while (msg.message != WM_QUIT)
	{
		// Peek at the next message (and remove it from the queue)
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			// Handle this message
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// No message, so continue the game loop
			timer.Tick();

			if (gamePaused)
			{
				Sleep(100);
			}
			else
			{
				//Wait for vertical sync
				//float dt = 0.0f;
				//do
				//{
				//	dt += timer.DeltaTime();
				//	timer.Reset();
				//	Sleep(1);
				//} while (dt < 0.016f);
				// Standard game loop type stuff
				float dt = timer.DeltaTime();
				CalculateFrameStats();
				UpdateScene(dt);
				DrawScene();
			}
		}
	}

	return (int)msg.wParam;
}
예제 #8
0
// --------------------------------------------------------
// The actual game loop, which processes the windows message queue
// and calls our Update & Draw methods
// --------------------------------------------------------
int DirectXGameCore::Run()
{
	// Grab the start time
	__int64 now;
	QueryPerformanceCounter((LARGE_INTEGER*)&now);
	startTime    = now;
	currentTime  = now;
	previousTime = now;

	// Create a variable to hold the current message
	MSG msg = {0};

	// Loop until we get a quit message from windows
	while(msg.message != WM_QUIT)
	{
		// Peek at the next message (and remove it from the queue)
		if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			// Handle this message
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		else // No message to handle
		{
			// Update the timer for this frame
			UpdateTimer();

			// Standard game loop type stuff
			Input::Update();
			CalculateFrameStats();
			UpdateScene(deltaTime, totalTime);
			DrawScene(deltaTime, totalTime);			
		}
	}

	// If we make it outside the game loop, return the most
	// recent message's exit code
	return (int)msg.wParam;
}
예제 #9
0
파일: CApp.cpp 프로젝트: hoisin/SSRenderer
//------------------------------------------------------------------
//
//	AppRun(..)
//
//	Main Loop 
//
//------------------------------------------------------------------
void CApp::AppRun()
{
	MSG msg;
	long startTime = timeGetTime();

	m_timer.Reset();
	m_timer.Start();

	while(m_bRun)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg); // Otherwise send message to appropriate window
			DispatchMessage(&msg);	
		}
		else 
		{
			// If app is currently active
			if(m_bAppActive)
			{
				// Only want to process the timer when our app is the active window (may change)
				m_timer.Tick();

				OnUpdate( 0.001f * ( timeGetTime() - startTime )  );

				OnDraw();

				CalculateFrameStats();
			}
			else 
			{
				Sleep(200); // Do not consume processor power if application isn't active
			}
		}
	}
}
예제 #10
0
//================================================================
// Application loop
//================================================================
int D3D11App::Run()
{
	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

	mTimer.reset();

	while(msg.message != WM_QUIT)
	{
		// If there are Window messages, process them
		if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
		}
		// Else run the game loop
		else
		{
			mTimer.tick();

			if (!mAppPaused)
			{
				Update(mTimer.getDeltaTime());
				mDirectInput->Update();
				CalculateFrameStats();
				Draw();
			}
			else
			{
				Sleep(100);
			}
		}
	}

	return (int)msg.wParam;
}
예제 #11
0
int D3D11App::Run()
{
	MSG msg = { 0 };
	while (msg.message != WM_QUIT)
	{
		// If there are Window messages then process them.
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		// Otherwise, do animation/game stuff.
		else
		{
			mTimer.Tick();
			if (!mAppPaused)
			{
				static DWORD timeLoop = 0;
				const DWORD FRAME_INTERVAL = 30; //15 毫秒
				DWORD timerNow = mTimer.GetTime();
				if (timerNow < timeLoop + FRAME_INTERVAL)
				{

				}
				else
				{
					timeLoop = mTimer.GetTime();
					CalculateFrameStats();
					UpdateScene(mTimer.DeltaTime());
					DrawScene();
				}
			}
		}
	}
	return (int)msg.wParam;
}
예제 #12
0
파일: window.cpp 프로젝트: Gr390ry/Shade
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
	, LPSTR lpszCmdParam, int nCmdShow)
{
#if defined (DEBUG) | defined (_DEBUG)
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	//아이콘 로드
	HICON hIcon = reinterpret_cast<HICON>(::LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON2),
											IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR));
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L,
					GetModuleHandle(NULL),
					hIcon,
					NULL, 
					NULL, 
					NULL,
					GENERIC::gAppName.c_str(),
					hIcon };
	RegisterClassEx(&wc);

	DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
	HWND hWnd = CreateWindow(GENERIC::gAppName.c_str(), GENERIC::gAppName.c_str(),
		style, CW_USEDEFAULT, 0, GENERIC::windowWidth, GENERIC::windowHeight,
		GetDesktopWindow(), NULL, wc.hInstance, NULL);


	Console::Get()->Initialize("Debug Console", hInstance, hPrevInstance, lpszCmdParam, nCmdShow);
	DEBUG_CONSOLE("Hello!\n");	

	gAppPuased = false;
	InitializeObjects(hWnd);
	SetWindowRect(hWnd);
	ShowWindow(hWnd, SW_SHOWDEFAULT);
	UpdateWindow(hWnd);	

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	

	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		GameTimer::Get()->UpdateTickCount();


		if (!gAppPuased)
		{
			float tick = GameTimer::Get()->DeltaTime();

			General::Get()->Update(tick);
			//RenderDevice::Get()->UpdateScene(tick);
			RenderDevice::Get()->Render11();
			CalculateFrameStats(hWnd);
		}
		else
		{
			Sleep(1);
		}		
	}

	RenderDevice::Get()->Release();
	UnregisterClass(GENERIC::gAppName.c_str(), wc.hInstance);
	return 0;
}
예제 #13
0
void Window::Update(float total_time)
{
	CalculateFrameStats(total_time);
}