From 2d24a9c7a17578f0975ec2207fc7239a2bdaa008 Mon Sep 17 00:00:00 2001 From: Reece Mackie <20544390+Rover656@users.noreply.github.com> Date: Sat, 27 Apr 2019 18:15:28 +0100 Subject: [PATCH] Fixed XBOX ONE Support --- projects/VS2017.UWP/raylib.App.UWP/App.cpp | 5 +++-- projects/VS2017.UWP/raylib.App.UWP/BaseApp.h | 17 +++++++++++++++++ src/core.c | 18 ++++++++++++++++-- src/utils.c | 1 + src/utils.h | 4 ++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/projects/VS2017.UWP/raylib.App.UWP/App.cpp b/projects/VS2017.UWP/raylib.App.UWP/App.cpp index 74f3ec819..ae137ed2a 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/App.cpp +++ b/projects/VS2017.UWP/raylib.App.UWP/App.cpp @@ -25,11 +25,12 @@ App::App() static int posX = 100; static int posY = 100; -static int time = 0; +static int gTime = 0; // This method is called every frame void App::Update() { + //return; // Draw BeginDrawing(); @@ -71,7 +72,7 @@ void App::Update() pos -= GetMouseWheelMove(); DrawRectangle(280, pos + 50, 20, 20, BLACK); - DrawRectangle(250, 280 + (time++ % 60), 10, 10, PURPLE); + DrawRectangle(250, 280 + (gTime++ % 60), 10, 10, PURPLE); EndDrawing(); } \ No newline at end of file diff --git a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h index 3cae6e2ef..aed13b23b 100644 --- a/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h +++ b/projects/VS2017.UWP/raylib.App.UWP/BaseApp.h @@ -37,6 +37,7 @@ #include PCH #endif +#include #include #include @@ -142,10 +143,26 @@ public: msg->Vector0 = screenSize; UWPSendMessage(msg); + //Send the time to the core + using clock = std::chrono::high_resolution_clock; + auto timeStart = clock::now(); + + //Set fps if 0 + if (GetFPS() <= 0) + SetTargetFPS(60); + while (!mWindowClosed) { if (mWindowVisible) { + //Send time + auto delta = clock::now() - timeStart; + + UWPMessage* timeMsg = CreateUWPMessage(); + timeMsg->Type = SetGameTime; + timeMsg->Double0 = std::chrono::duration_cast(delta).count(); + UWPSendMessage(timeMsg); + //Call update function Update(); diff --git a/src/core.c b/src/core.c index 72f700a55..db75979a1 100644 --- a/src/core.c +++ b/src/core.c @@ -402,6 +402,7 @@ static double updateTime = 0.0; // Time measure for frame update static double drawTime = 0.0; // Time measure for frame draw static double frameTime = 0.0; // Time measure for one frame static double targetTime = 0.0; // Desired time for one frame, if 0 not applied + //----------------------------------------------------------------------------------- // Config internal variables @@ -1163,6 +1164,8 @@ void EndDrawing(void) frameTime += extraTime; } + + return; } // Initialize 2D mode with custom camera (2D) @@ -1439,6 +1442,11 @@ double GetTime(void) return (double)(time - baseTime)*1e-9; // Elapsed time since InitTimer() #endif + +#if defined(PLATFORM_UWP) + //Updated through messages + return currentTime; +#endif } // Returns hexadecimal value for a Color @@ -3023,7 +3031,7 @@ static void InitTimer(void) // http://stackoverflow.com/questions/43057578/c-programming-win32-games-sleep-taking-longer-than-expected static void Wait(float ms) { -#if defined(SUPPORT_BUSY_WAIT_LOOP) +#if defined(SUPPORT_BUSY_WAIT_LOOP) && !defined(PLATFORM_UWP) double prevTime = GetTime(); double nextTime = 0.0; @@ -3295,6 +3303,12 @@ static void PollInputEvents(void) break; } + case SetGameTime: + { + currentTime = msg->Double0; + break; + } + } DeleteUWPMessage(msg); //Delete, we are done @@ -4789,7 +4803,7 @@ static void *GamepadThread(void *arg) // Plays raylib logo appearing animation static void LogoAnimation(void) { -#if !defined(PLATFORM_WEB) +#if !defined(PLATFORM_WEB) && !defined(PLATFORM_UWP) int logoPositionX = screenWidth/2 - 128; int logoPositionY = screenHeight/2 - 128; diff --git a/src/utils.c b/src/utils.c index 420ebc698..c886d2a70 100644 --- a/src/utils.c +++ b/src/utils.c @@ -223,6 +223,7 @@ UWPMessage* CreateUWPMessage(void) msg->Int1 = 0; msg->Char0 = 0; msg->Float0 = 0; + msg->Double0 = 0; msg->Bool0 = false; return msg; } diff --git a/src/utils.h b/src/utils.h index 8cf26bc89..14e6bf708 100644 --- a/src/utils.h +++ b/src/utils.h @@ -84,6 +84,7 @@ typedef enum MarkGamepadAxis,//Int0 (gamepad), int1 (axis), Float0 (value) SetDisplayDims, //Vector0 (display dimensions) HandleResize, //Vector0 (new dimensions) - Onresized event + SetGameTime, //Int0 } UWPMessageType; typedef struct UWPMessage @@ -104,6 +105,9 @@ typedef struct UWPMessage //Float parameters float Float0; + //Double parameters + double Double0; + //Bool parameters bool Bool0;