Преглед на файлове

Ability to build for UWP on ARM (#329)

Changed unit test to color screen green/red depending on success/failure
Jorrit Rouwe преди 2 години
родител
ревизия
aabe803d40
променени са 2 файла, в които са добавени 95 реда и са изтрити 22 реда
  1. 5 0
      Build/cmake_vs2022_uwp_arm.bat
  2. 90 22
      UnitTests/UnitTestFramework.cpp

+ 5 - 0
Build/cmake_vs2022_uwp_arm.bat

@@ -0,0 +1,5 @@
+@echo off
+cmake -S . -B VS2022_UWP_ARM -G "Visual Studio 17 2022" -A ARM64 -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0
+echo If cmake failed then be sure to check the "Universal Windows Platform development" checkbox in the Visual Studio Installer
+echo Open VS2022_UWP_ARM\JoltPhysics.sln to build the project. 
+echo Note that none of the sample applications are available for the Universal Windows Platform (use cmake_vs2022_cl_arm.bat instead).

+ 90 - 22
UnitTests/UnitTestFramework.cpp

@@ -68,37 +68,105 @@ static bool AssertFailedImpl(const char *inExpression, const char *inMessage, co
 
 #ifdef JPH_PLATFORM_WINDOWS_UWP
 
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
+JPH_SUPPRESS_WARNING_PUSH
+JPH_MSVC_SUPPRESS_WARNING(4265) // warning C4265: 'winrt::impl::implements_delegate<winrt::Windows::UI::Core::DispatchedHandler,H>': class has virtual functions, but its non-trivial destructor is not virtual; instances of this class may not be destructed correctly
+JPH_MSVC_SUPPRESS_WARNING(4668) // warning C4668: '_MANAGED' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif'
+JPH_MSVC_SUPPRESS_WARNING(4946) // warning C4946: reinterpret_cast used between related classes: 'winrt::impl::abi<winrt::Windows::ApplicationModel::Core::IFrameworkViewSource,void>::type' and 'winrt::impl::abi<winrt::Windows::Foundation::IUnknown,void>::type'
+JPH_MSVC_SUPPRESS_WARNING(5039) // winbase.h(13179): warning C5039: 'TpSetCallbackCleanupGroup': pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc. Undefined behavior may occur if this function throws an exception.
+JPH_MSVC_SUPPRESS_WARNING(5204) // warning C5204: 'winrt::impl::produce_base<D,winrt::Windows::ApplicationModel::Core::IFrameworkViewSource,void>': class has virtual functions, but its trivial destructor is not virtual; instances of objects derived from this class may not be destructed correctly
+JPH_MSVC_SUPPRESS_WARNING(5246) // warning C5246: '_Elems': the initialization of a subobject should be wrapped in braces
+#include <winrt/Windows.Foundation.h>
+#include <winrt/Windows.Foundation.Collections.h>
+#include <winrt/Windows.ApplicationModel.Core.h>
+#include <winrt/Windows.UI.Core.h>
+#include <winrt/Windows.UI.Composition.h>
+#include <winrt/Windows.UI.Input.h>
+JPH_SUPPRESS_WARNING_POP
+
+using namespace winrt;
+using namespace Windows;
+using namespace Windows::ApplicationModel::Core;
+using namespace Windows::UI;
+using namespace Windows::UI::Core;
+using namespace Windows::UI::Composition;
+
+struct App : implements<App, IFrameworkViewSource, IFrameworkView>
 {
-	// Register allocation hook
-	RegisterDefaultAllocator();
+	CompositionTarget mTarget { nullptr };
 
-	// Install callbacks
-	Trace = TraceImpl;
-	JPH_IF_ENABLE_ASSERTS(AssertFailed = AssertFailedImpl;)
+	IFrameworkView CreateView()
+	{
+		return *this;
+	}
 
-#ifdef _DEBUG
-	// Enable leak detection
-	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
-#endif
+	void Initialize(CoreApplicationView const&)
+	{
+	}
 
-	// Enable floating point exceptions
-	FPExceptionsEnable enable_exceptions;
-	JPH_UNUSED(enable_exceptions);
+	void Load(hstring const&)
+	{
+	}
 
-	// Create a factory
-	Factory::sInstance = new Factory();
+	void Uninitialize()
+	{
+	}
 
-	// Register physics types
-	RegisterTypes();
+	void Run()
+	{
+		CoreWindow window = CoreWindow::GetForCurrentThread();
+		window.Activate();
 
-	int rv = Context().run();
+		CoreDispatcher dispatcher = window.Dispatcher();
+		dispatcher.ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
+	}
 
-	// Destroy the factory
-	delete Factory::sInstance;
-	Factory::sInstance = nullptr;
+	void SetWindow(CoreWindow const& inWindow)
+	{
+		// Register allocation hook
+		RegisterDefaultAllocator();
 
-	return rv;
+		// Install callbacks
+		Trace = TraceImpl;
+		JPH_IF_ENABLE_ASSERTS(AssertFailed = AssertFailedImpl;)
+
+#ifdef _DEBUG
+		// Enable leak detection
+		_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
+#endif
+
+		// Enable floating point exceptions
+		FPExceptionsEnable enable_exceptions;
+		JPH_UNUSED(enable_exceptions);
+
+		// Create a factory
+		Factory::sInstance = new Factory();
+
+		// Register physics types
+		RegisterTypes();
+
+		// Run the tests
+		int rv = Context().run();
+
+		// Destroy the factory
+		delete Factory::sInstance;
+		Factory::sInstance = nullptr;
+
+		// Color the screen according to the result
+		Compositor compositor;
+		ContainerVisual root = compositor.CreateContainerVisual();
+		mTarget = compositor.CreateTargetForCurrentView();
+		mTarget.Root(root);
+		SpriteVisual visual = compositor.CreateSpriteVisual();
+		visual.Brush(compositor.CreateColorBrush(rv != 0 ? Windows::UI::Color { 0xff, 0xff, 0x00, 0x00 } : Windows::UI::Color { 0xff, 0x00, 0xff, 0x00 }));
+		visual.Size({ inWindow.Bounds().Width, inWindow.Bounds().Height });
+		visual.Offset({ 0, 0, 0, });
+		root.Children().InsertAtTop(visual);
+	}
+};
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
+{
+    CoreApplication::Run(make<App>());
 }
 
 #elif !defined(JPH_PLATFORM_ANDROID)