Ejemplo n.º 1
0
int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR commandLine, int showCommand)
{
    WNDCLASS wndClass = {0};
    MSG msg;

    /* Register window class */
    wndClass.hInstance = instance;
    wndClass.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
    wndClass.lpszClassName = ClassName;
    wndClass.lpfnWndProc = WndProc;
    if (!RegisterClass(&wndClass))
        exit(1);

    /* Create window */
    g_hwnd = CreateWindow(ClassName, Title, WS_POPUP, 0, 0, 160 * ViewScale, 100 * ViewScale, 0, 0, instance, 0);
    if (!g_hwnd)
        exit(2);

    ShowWindow(g_hwnd, showCommand);
    UpdateWindow(g_hwnd);

    /* Initialize Graphics */
    InitializeGraphics(g_hwnd);
    InitializeGame();

    for (;;)
    {
        if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            TickGame();
            Present();
        }
    }

    DestroyGraphics();

    return 0;
}
Ejemplo n.º 2
0
/*virtual*/ bool Framework3D::TickSim( float DeltaTime )
{
	XTRACE_FUNCTION;

	const bool WasPaused = m_UIManager->GetUIStack()->PausesGame();
	m_Clock->GameTick( WasPaused, DeltaTime );

#if BUILD_SDL
	if( !TickSDLEvents() )
	{
		return false;
	}
#endif

	TickDevices();

#if !BUILD_STEAM
	// Bit of a hack... And would conflict with Steam's F12 key function.
	if( m_Keyboard->OnRise( Keyboard::EB_F12 ) )
	{
		TakeScreenshot();
	}
#endif

	// Man I'm really ruining the notion of "TickInput" huh.
	if(	( m_Keyboard->IsHigh( Keyboard::EB_LeftAlt ) ||
		  m_Keyboard->IsHigh( Keyboard::EB_RightAlt ) ) &&
		m_Keyboard->OnRise( Keyboard::EB_Enter ) )
	{
		ToggleFullscreen();
	}

#if !BUILD_MAC
	// This causes problems on Mac, but is essential on Linux and maybe Windows.
	if( m_Mouse->IsActive() && m_Window->HasFocus() )
	{
		// Fix invisible cursor from affecting other windows
		m_Mouse->SetPosition( m_Display->m_Width / 2, m_Display->m_Height / 2, m_Window );
	}
#endif

	XTRACE_BEGIN( TickUI );
		m_UIManager->ProcessEvents();
		m_UIManager->GetUIStack()->Tick( DeltaTime, DeltaTime, false );
	XTRACE_END;

	const bool Unpaused = WasPaused && !m_UIManager->GetUIStack()->PausesGame();
	if( Unpaused )
	{
		OnUnpaused();
		m_Clock->GameTick( false, DeltaTime );
	}

	if( m_HasFocus )
	{
		if( WasPaused )
		{
			TickPausedInput();
		}
		else
		{
			if( !TickInput( DeltaTime ) )
			{
				return false;
			}
		}
	}

	if( !WasPaused )
	{
		TickGame( DeltaTime );
	}

	XTRACE_BEGIN( TickAudio );
		m_AudioSystem->Tick( DeltaTime, WasPaused );
	XTRACE_END;

	return true;
}