void CoreWin32Platform::Run()
	{
		Core::Instance()->SystemAppStarted();

		MSG msg;
		while(1)
		{
            DAVA::uint64 startTime = DAVA::SystemTimer::Instance()->AbsoluteMS();

			// process messages
			willQuit = false;
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);

				if(msg.message == WM_QUIT)
				{
					ApplicationCore * appCore = Core::Instance()->GetApplicationCore();
					if(appCore && appCore->OnQuit())
					{
						exit(0);
					}
					else
					{
						willQuit = true;
					}
				}
			}

            RenderManager::Instance()->Lock();
			Core::SystemProcessFrame();
			RenderManager::Instance()->Unlock();

            uint32 elapsedTime = (uint32) (SystemTimer::Instance()->AbsoluteMS() - startTime);
            int32 sleepMs = 1;

            int32 fps = RenderManager::Instance()->GetFPS();
            if(fps > 0)
            {
                sleepMs = (1000 / fps) - elapsedTime;
                if(sleepMs < 1)
                {
                    sleepMs = 1;
                }
            }

            Sleep(sleepMs);

			if (willQuit)
			{	
				break;
			}
		}

		Core::Instance()->SystemAppFinished();
		FrameworkWillTerminate();
	}
Beispiel #2
0
	void CorePlatformAndroid::StartForeground()
	{
		Logger::Debug("[CorePlatformAndroid::StartForeground] start");
		//TODO: VK: add code for handling

		if(wasCreated)
		{
			ApplicationCore * core = Core::Instance()->GetApplicationCore();
			if(core)
			{
				core->OnResume();
			}

			foreground = true;
		}
		Logger::Debug("[CorePlatformAndroid::StartForeground] end");
	}
Beispiel #3
0
	void CorePlatformAndroid::StopForeground()
	{
		Logger::Debug("[CorePlatformAndroid::StopForeground]");
		//TODO: VK: add code for handling

		RenderResource::SaveAllResourcesToSystemMem();
		RenderResource::LostAllResources();

		ApplicationCore * core = Core::Instance()->GetApplicationCore();
		if(core)
		{
			core->OnSuspend();
		}

		foreground = false;

		width = 0;
		height = 0;
	}
	void CoreWin32Platform::Run()
	{
		Core::Instance()->SystemAppStarted();

		MSG msg;
		while(1)
		{
			// process messages
			willQuit = false;
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);

				if(msg.message == WM_QUIT)
				{
					ApplicationCore * appCore = Core::Instance()->GetApplicationCore();
					if(appCore && appCore->OnQuit())
					{
						exit(0);
					}
					else
					{
						willQuit = true;
					}
				}
			}
			Sleep(1);
			RenderManager::Instance()->Lock();
			Core::SystemProcessFrame();
			RenderManager::Instance()->Unlock();

			if (willQuit)
			{	
				break;
			}
		}

		Core::Instance()->SystemAppFinished();
		FrameworkWillTerminate();
	}
Beispiel #5
0
	LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
#ifndef WM_MOUSEWHEEL
#define WM_MOUSEWHEEL 0x020A
#endif
#ifndef WHEEL_DELTA                     
#define WHEEL_DELTA 120
#endif

		//Event event;
		//event.MouseEvent.RelativeX = 0;
		//event.MouseEvent.RelativeY = 0;

		switch (message) 
		{
		case WM_ERASEBKGND:
				return 0;

		case WM_KEYUP:
			{
				InputSystem::Instance()->GetKeyboard()->OnSystemKeyUnpressed((int32)wParam);
			};
			break;

		case WM_KEYDOWN:
			{
				BYTE allKeys[256];
				GetKeyboardState(allKeys);
	
				if ((allKeys[VK_MENU] & 0x80)
					&& (allKeys[VK_TAB] & 0x80))
				{
					ShowWindow(hWnd, SW_MINIMIZE);
				}

				Vector<DAVA::UIEvent> touches;
				Vector<DAVA::UIEvent> emptyTouches;

				for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++)
				{
					touches.push_back(*it);
				}

				DAVA::UIEvent ev;
				ev.keyChar = 0;
				ev.phase = DAVA::UIEvent::PHASE_KEYCHAR;
				ev.tapCount = 1;
				ev.tid = InputSystem::Instance()->GetKeyboard()->GetDavaKeyForSystemKey((int32)wParam);

				touches.push_back(ev);

				UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
				touches.pop_back();
				UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);

				InputSystem::Instance()->GetKeyboard()->OnSystemKeyPressed((int32)wParam);
			};
			break;

		case WM_CHAR:
			{
				if(wParam > 27) //TODO: remove this elegant check
				{
					Vector<DAVA::UIEvent> touches;
					Vector<DAVA::UIEvent> emptyTouches;

					for(Vector<DAVA::UIEvent>::iterator it = activeTouches.begin(); it != activeTouches.end(); it++)
					{
						touches.push_back(*it);
					}

					DAVA::UIEvent ev;
					ev.keyChar = (char16)wParam;
					ev.phase = DAVA::UIEvent::PHASE_KEYCHAR;
					ev.tapCount = 1;
					ev.tid = 0;

					touches.push_back(ev);

					UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
					touches.pop_back();
					UIControlSystem::Instance()->OnInput(0, emptyTouches, touches);
				}
			}
			break;


		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:
		case WM_MBUTTONDOWN:
//		case WM_XBUTTONDOWN:

		case WM_LBUTTONUP:
		case WM_RBUTTONUP:
		case WM_MBUTTONUP:
//		case WM_XBUTTONUP:

		case WM_MOUSEMOVE:
			{
			
				//Logger::Debug("ms: %d %d", GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));

				Vector<DAVA::UIEvent> touches;
				Vector<DAVA::UIEvent> emptyTouches;

				int32 touchPhase = MoveTouchsToVector(message, wParam, lParam, &touches);

				UIControlSystem::Instance()->OnInput(touchPhase, emptyTouches, touches);

				touches.clear();
			}
// 			if (mouseShow)
// 			{
// 				ShowCursor(false);
// 				mouseShow = false;
// 			}
			if (RenderManager::Instance()->GetCursor() != 0 && mouseCursorShown)
			{
				ShowCursor(false);
				mouseCursorShown = false;
			}
			if (RenderManager::Instance()->GetCursor() == 0 && !mouseCursorShown)			
			{
				ShowCursor(false);
				mouseCursorShown = false;
			}
			break;

		case WM_NCMOUSEMOVE:
			if (!mouseCursorShown)
			{	
				ShowCursor(true);
				mouseCursorShown = true;
			}
			break;

		case WM_NCMOUSELEAVE:
			//ShowCursor(false);
			break;

		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;

		case WM_ACTIVATE:
			{
				ApplicationCore * core = Core::Instance()->GetApplicationCore();
                WORD loWord = LOWORD(wParam);
                WORD hiWord = HIWORD(wParam);
                if(!loWord || hiWord)
                {
                    Logger::Debug("[PlatformWin32] deactivate application");
                    RenderResource::SaveAllResourcesToSystemMem();
					
                    if(core)
					{
						core->OnSuspend();
					}
					else 
					{
						Core::Instance()->SetIsActive(false);
					}
                }
                else
                {
                    Logger::Debug("[PlatformWin32] activate application");
					if(core)
					{
						core->OnResume();
					}
					else 
					{
						Core::Instance()->SetIsActive(true);
					}
                }
			};
			break;
		case WM_SYSCOMMAND:
			// prevent screensaver or monitor powersave mode from starting
			if (wParam == SC_SCREENSAVE ||
				wParam == SC_MONITORPOWER)
				return 0;
			break;
		}

		return DefWindowProc(hWnd, message, wParam, lParam);
	}