From 1a3598a88a30608f5f918397ae6ac37ef8c7ad2a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 8 Feb 2018 22:08:14 -0800 Subject: Reworked UWP app implementation --- Common/NativeApp/include/AppBase.h | 38 ++++++++++++++ Common/NativeApp/include/NativeAppBase.h | 37 ++++++-------- Common/NativeApp/include/NativeAppData.h | 38 -------------- Common/NativeApp/include/UWP/UWPAppBase.h | 71 +++++++++++++++++++++++++++ Common/NativeApp/include/Win32/Win32AppBase.h | 36 ++++++++++++++ 5 files changed, 159 insertions(+), 61 deletions(-) create mode 100644 Common/NativeApp/include/AppBase.h delete mode 100644 Common/NativeApp/include/NativeAppData.h create mode 100644 Common/NativeApp/include/UWP/UWPAppBase.h create mode 100644 Common/NativeApp/include/Win32/Win32AppBase.h (limited to 'Common/NativeApp/include') diff --git a/Common/NativeApp/include/AppBase.h b/Common/NativeApp/include/AppBase.h new file mode 100644 index 0000000..e6641b1 --- /dev/null +++ b/Common/NativeApp/include/AppBase.h @@ -0,0 +1,38 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +class AppBase +{ +public: + virtual ~AppBase() {} + + virtual void ProcessCommandLine(const char *CmdLine) = 0; + virtual const char* GetAppTitle()const = 0; + virtual void Update(double CurrTime, double ElapsedTime) {}; + virtual void Render() = 0; + virtual void Present() = 0; + virtual void Resize(int width, int height) = 0; +}; + diff --git a/Common/NativeApp/include/NativeAppBase.h b/Common/NativeApp/include/NativeAppBase.h index 590b6c9..6ffbb74 100644 --- a/Common/NativeApp/include/NativeAppBase.h +++ b/Common/NativeApp/include/NativeAppBase.h @@ -20,31 +20,22 @@ * all other commercial damages or losses), even if such Contributor has been advised * of the possibility of such damages. */ - #pragma once -struct NativeAppAttributes -{ -#ifdef PLATFORM_WIN32 - // * HWND on Win32 - void* NativeWindowHandle = nullptr; +#if defined(PLATFORM_WIN32) + + #include "Win32AppBase.h" + using NativeAppBase = Win32AppBase; + +#elif defined(PLATFORM_UNIVERSAL_WINDOWS) + + #include "UWPAppBase.h" + using NativeAppBase = UWPAppBase; + +#else + +# error Usnupported paltform + #endif - int WindowWidth = 0; - int WindowHeight = 0; -}; - -class NativeAppBase -{ -public: - virtual ~NativeAppBase() {} - - virtual void ProcessCommandLine(const char *CmdLine) = 0; - virtual const char* GetAppTitle()const = 0; - virtual void Initialize(const struct NativeAppAttributes &NativeAppAttribs) = 0; - virtual void Update(double CurrTime, double ElapsedTime) {}; - virtual void PlatformRender() = 0; - virtual bool HandleNativeMessage(struct NativeMessage &msg) = 0; - virtual void Resize(int width, int height) = 0; -}; extern NativeAppBase* CreateApplication(); diff --git a/Common/NativeApp/include/NativeAppData.h b/Common/NativeApp/include/NativeAppData.h deleted file mode 100644 index ac8c55f..0000000 --- a/Common/NativeApp/include/NativeAppData.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2015-2018 Egor Yusov - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#ifdef PLATFORM_WIN32 -#include -#endif - -struct NativeMessage -{ -#ifdef PLATFORM_WIN32 - HWND hWnd; - UINT message; - WPARAM wParam; - LPARAM lParam; -#endif -}; diff --git a/Common/NativeApp/include/UWP/UWPAppBase.h b/Common/NativeApp/include/UWP/UWPAppBase.h new file mode 100644 index 0000000..dc56b80 --- /dev/null +++ b/Common/NativeApp/include/UWP/UWPAppBase.h @@ -0,0 +1,71 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + + +#pragma once + +#include + +#define NOMINIMAX +#include +#include + +#include "AppBase.h" +#include "Common/StepTimer.h" +#include "Common/DeviceResources.h" + +class UWPAppBase : public AppBase +{ +public: + UWPAppBase(); + + virtual void OnSetWindow(Windows::UI::Core::CoreWindow^ window) {} + virtual void OnWindowSizeChanged() = 0; + + using AppBase::Update; + virtual void Update(); + + // Notifies the app that it is being suspended. + virtual void OnSuspending() {} + + // Notifes the app that it is no longer suspended. + virtual void OnResuming() {} + + // Notifies renderers that device resources need to be released. + virtual void OnDeviceRemoved() {} + + bool IsFrameReady()const { return m_bFrameReady; } + + virtual std::shared_ptr InitDeviceResources() = 0; + + virtual void InitWindowSizeDependentResources() = 0; + + virtual void CreateRenderers() = 0; + +protected: + std::shared_ptr m_DeviceResources; + + // Rendering loop timer. + DX::StepTimer m_timer; + bool m_bFrameReady = false; +}; diff --git a/Common/NativeApp/include/Win32/Win32AppBase.h b/Common/NativeApp/include/Win32/Win32AppBase.h new file mode 100644 index 0000000..abfdcff --- /dev/null +++ b/Common/NativeApp/include/Win32/Win32AppBase.h @@ -0,0 +1,36 @@ +/* Copyright 2015-2018 Egor Yusov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#define NOMINMAX +#include + +#include "AppBase.h" + +class Win32AppBase : public AppBase +{ +public: + virtual void OnWindowCreated(HWND hWnd, LONG WindowWidth, LONG WindowHeight) = 0; + virtual LRESULT HandleWin32Message(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { return 0; } +}; -- cgit v1.2.3