summaryrefslogtreecommitdiffhomepage
path: root/src/utils.c
diff options
context:
space:
mode:
authorDarkElvenAngel <[email protected]>2019-06-10 16:12:06 -0400
committerGitHub <[email protected]>2019-06-10 16:12:06 -0400
commitd7f4be071579e6f00974c0940f021272f22fbc54 (patch)
tree6ee389e6617c494d272e9bc82415fbc3618e7a28 /src/utils.c
parent8a21830b77eaa76ffe0c31df5f96aecd6bd2eecc (diff)
parentbaf7d7d19ad8d6bfbfc201169e4ed4f49a9576a6 (diff)
downloadraylib-d7f4be071579e6f00974c0940f021272f22fbc54.tar.gz
raylib-d7f4be071579e6f00974c0940f021272f22fbc54.zip
Merge pull request #1 from raysan5/master
Update
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c101
1 files changed, 90 insertions, 11 deletions
diff --git a/src/utils.c b/src/utils.c
index b31ce6ae..ee4be46d 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -11,7 +11,7 @@
*
* LICENSE: zlib/libpng
*
-* Copyright (c) 2014-2018 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
@@ -30,9 +30,13 @@
*
**********************************************************************************************/
-#include "config.h"
-
#include "raylib.h" // WARNING: Required for: LogType enum
+
+// Check if config flags have been externally provided on compilation line
+#if !defined(EXTERNAL_CONFIG_FLAGS)
+ #include "config.h" // Defines module configuration flags
+#endif
+
#include "utils.h"
#if defined(PLATFORM_ANDROID)
@@ -41,10 +45,10 @@
#include <android/asset_manager.h> // Required for: Android assets manager: AAsset, AAssetManager_open(), ...
#endif
-#include <stdlib.h> // Required for: malloc(), free()
-#include <stdio.h> // Required for: fopen(), fclose(), fputc(), fwrite(), printf(), fprintf(), funopen()
+#include <stdlib.h> // Required for: exit()
+#include <stdio.h> // Required for: printf(), sprintf()
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
-#include <string.h> // Required for: strlen(), strrchr(), strcmp()
+#include <string.h> // Required for: strcpy(), strcat()
#define MAX_TRACELOG_BUFFER_SIZE 128 // Max length of one trace-log message
@@ -65,7 +69,7 @@ AAssetManager *assetManager;
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
#if defined(PLATFORM_ANDROID)
-/* This should be in <stdio.h>, but Travis doesn't find it... */
+// This should be in <stdio.h>, but Travis does not find it...
FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
@@ -128,7 +132,7 @@ void TraceLog(int logType, const char *text, ...)
#else
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
- switch(logType)
+ switch (logType)
{
case LOG_TRACE: strcpy(buffer, "TRACE: "); break;
case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
@@ -146,7 +150,7 @@ void TraceLog(int logType, const char *text, ...)
va_end(args);
- if (logType >= logTypeExit) exit(1); // If exit message, exit program
+ if (logType >= logTypeExit) exit(1); // If exit message, exit program
#endif // SUPPORT_TRACELOG
}
@@ -169,7 +173,7 @@ FILE *android_fopen(const char *fileName, const char *mode)
return funopen(asset, android_read, android_write, android_seek, android_close);
}
-#endif
+#endif // PLATFORM_ANDROID
//----------------------------------------------------------------------------------
// Module specific Functions Definition
@@ -197,4 +201,79 @@ static int android_close(void *cookie)
AAsset_close((AAsset *)cookie);
return 0;
}
-#endif
+#endif // PLATFORM_ANDROID
+
+#if defined(PLATFORM_UWP)
+
+#define MAX_MESSAGES 512 // If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512
+
+static int UWPOutMessageId = -1; // Stores the last index for the message
+static UWPMessage* UWPOutMessages[MAX_MESSAGES]; // Messages out to UWP
+
+static int UWPInMessageId = -1; // Stores the last index for the message
+static UWPMessage* UWPInMessages[MAX_MESSAGES]; // Messages in from UWP
+
+UWPMessage* CreateUWPMessage(void)
+{
+ UWPMessage *msg = (UWPMessage *)RL_MALLOC(sizeof(UWPMessage));
+ msg->type = UWP_MSG_NONE;
+ Vector2 v0 = { 0, 0 };
+ msg->paramVector0 = v0;
+ msg->paramInt0 = 0;
+ msg->paramInt1 = 0;
+ msg->paramChar0 = 0;
+ msg->paramFloat0 = 0;
+ msg->paramDouble0 = 0;
+ msg->paramBool0 = false;
+ return msg;
+}
+
+void DeleteUWPMessage(UWPMessage *msg)
+{
+ RL_FREE(msg);
+}
+
+bool UWPHasMessages(void)
+{
+ return (UWPOutMessageId > -1);
+}
+
+UWPMessage *UWPGetMessage(void)
+{
+ if (UWPHasMessages()) return UWPOutMessages[UWPOutMessageId--];
+
+ return NULL;
+}
+
+void UWPSendMessage(UWPMessage *msg)
+{
+ if (UWPInMessageId + 1 < MAX_MESSAGES)
+ {
+ UWPInMessageId++;
+ UWPInMessages[UWPInMessageId] = msg;
+ }
+ else TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP inbound Message.");
+}
+
+void SendMessageToUWP(UWPMessage *msg)
+{
+ if (UWPOutMessageId + 1 < MAX_MESSAGES)
+ {
+ UWPOutMessageId++;
+ UWPOutMessages[UWPOutMessageId] = msg;
+ }
+ else TraceLog(LOG_WARNING, "[UWP Messaging] Not enough array space to register new UWP outward Message.");
+}
+
+bool HasMessageFromUWP(void)
+{
+ return UWPInMessageId > -1;
+}
+
+UWPMessage* GetMessageFromUWP(void)
+{
+ if (HasMessageFromUWP()) return UWPInMessages[UWPInMessageId--];
+
+ return NULL;
+}
+#endif // PLATFORM_UWP