Update C sources
This commit is contained in:
parent
02424e2e10
commit
bd6bf15356
53 changed files with 62247 additions and 9914 deletions
197
raylib/utils.c
197
raylib/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,43 +30,49 @@
|
|||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#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 "raylib.h" // WARNING: Required for: LogType enum
|
||||
#include "utils.h"
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#include <errno.h>
|
||||
#include <android/log.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <errno.h> // Required for: Android error types
|
||||
#include <android/log.h> // Required for: Android log system: __android_log_vprint()
|
||||
#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 <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||
#include <string.h> // Required for: strlen(), strrchr(), strcmp()
|
||||
#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: strcpy(), strcat()
|
||||
|
||||
/* This should be in <stdio.h>, but Travis doesn't 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 *));
|
||||
#define MAX_TRACELOG_BUFFER_SIZE 128 // Max length of one trace-log message
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Log types messages supported flags (bit based)
|
||||
static unsigned char logTypeFlags = LOG_INFO | LOG_WARNING | LOG_ERROR;
|
||||
// Log types messages
|
||||
static int logTypeLevel = LOG_INFO;
|
||||
static int logTypeExit = LOG_ERROR;
|
||||
static TraceLogCallback logCallback = NULL;
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
AAssetManager *assetManager;
|
||||
AAssetManager *assetManager = NULL;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
// 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 *));
|
||||
|
||||
static int android_read(void *cookie, char *buf, int size);
|
||||
static int android_write(void *cookie, const char *buf, int size);
|
||||
static fpos_t android_seek(void *cookie, fpos_t offset, int whence);
|
||||
|
@ -77,82 +83,78 @@ static int android_close(void *cookie);
|
|||
// Module Functions Definition - Utilities
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Enable trace log message types (bit flags based)
|
||||
void SetTraceLog(unsigned char types)
|
||||
// Set the current threshold (minimum) log level
|
||||
void SetTraceLogLevel(int logType)
|
||||
{
|
||||
logTypeFlags = types;
|
||||
logTypeLevel = logType;
|
||||
}
|
||||
|
||||
// Set a trace log callback to enable custom logging bypassing raylib's one
|
||||
// Set the exit threshold (minimum) log level
|
||||
void SetTraceLogExit(int logType)
|
||||
{
|
||||
logTypeExit = logType;
|
||||
}
|
||||
|
||||
// Set a trace log callback to enable custom logging
|
||||
void SetTraceLogCallback(TraceLogCallback callback)
|
||||
{
|
||||
logCallback = callback;
|
||||
}
|
||||
|
||||
// Show trace log messages (LOG_INFO, LOG_WARNING, LOG_ERROR, LOG_DEBUG)
|
||||
void TraceLog(int msgType, const char *text, ...)
|
||||
void TraceLog(int logType, const char *text, ...)
|
||||
{
|
||||
#if defined(SUPPORT_TRACELOG)
|
||||
static char buffer[128];
|
||||
// Message has level below current threshold, don't emit
|
||||
if (logType < logTypeLevel) return;
|
||||
|
||||
va_list args;
|
||||
va_start(args, text);
|
||||
|
||||
if (logCallback)
|
||||
{
|
||||
logCallback(msgType, text, args);
|
||||
logCallback(logType, text, args);
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(msgType)
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
switch(logType)
|
||||
{
|
||||
case LOG_INFO: strcpy(buffer, "INFO: "); break;
|
||||
case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
|
||||
case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
|
||||
case LOG_TRACE: __android_log_vprint(ANDROID_LOG_VERBOSE, "raylib", text, args); break;
|
||||
case LOG_DEBUG: __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", text, args); break;
|
||||
case LOG_INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", text, args); break;
|
||||
case LOG_WARNING: __android_log_vprint(ANDROID_LOG_WARN, "raylib", text, args); break;
|
||||
case LOG_ERROR: __android_log_vprint(ANDROID_LOG_ERROR, "raylib", text, args); break;
|
||||
case LOG_FATAL: __android_log_vprint(ANDROID_LOG_FATAL, "raylib", text, args); break;
|
||||
default: break;
|
||||
}
|
||||
#else
|
||||
char buffer[MAX_TRACELOG_BUFFER_SIZE] = { 0 };
|
||||
|
||||
switch (logType)
|
||||
{
|
||||
case LOG_TRACE: strcpy(buffer, "TRACE: "); break;
|
||||
case LOG_DEBUG: strcpy(buffer, "DEBUG: "); break;
|
||||
case LOG_INFO: strcpy(buffer, "INFO: "); break;
|
||||
case LOG_WARNING: strcpy(buffer, "WARNING: "); break;
|
||||
case LOG_ERROR: strcpy(buffer, "ERROR: "); break;
|
||||
case LOG_FATAL: strcpy(buffer, "FATAL: "); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
strcat(buffer, text);
|
||||
strcat(buffer, "\n");
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
switch(msgType)
|
||||
{
|
||||
case LOG_INFO: if (logTypeFlags & LOG_INFO) __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
|
||||
case LOG_WARNING: if (logTypeFlags & LOG_WARNING) __android_log_vprint(ANDROID_LOG_WARN, "raylib", buffer, args); break;
|
||||
case LOG_ERROR: if (logTypeFlags & LOG_ERROR) __android_log_vprint(ANDROID_LOG_ERROR, "raylib", buffer, args); break;
|
||||
case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
|
||||
default: break;
|
||||
}
|
||||
#else
|
||||
switch(msgType)
|
||||
{
|
||||
case LOG_INFO: if (logTypeFlags & LOG_INFO) vprintf(buffer, args); break;
|
||||
case LOG_WARNING: if (logTypeFlags & LOG_WARNING) vprintf(buffer, args); break;
|
||||
case LOG_ERROR: if (logTypeFlags & LOG_ERROR) vprintf(buffer, args); break;
|
||||
case LOG_DEBUG: if (logTypeFlags & LOG_DEBUG) vprintf(buffer, args); break;
|
||||
default: break;
|
||||
}
|
||||
vprintf(buffer, args);
|
||||
#endif
|
||||
|
||||
va_end(args);
|
||||
|
||||
if (msgType == LOG_ERROR) exit(1); // If LOG_ERROR message, exit program
|
||||
if (logType >= logTypeExit) exit(1); // If exit message, exit program
|
||||
|
||||
#endif // SUPPORT_TRACELOG
|
||||
}
|
||||
|
||||
// Keep track of memory allocated
|
||||
// NOTE: mallocType defines the type of data allocated
|
||||
/*
|
||||
void RecordMalloc(int mallocType, int mallocSize, const char *msg)
|
||||
{
|
||||
// TODO: Investigate how to record memory allocation data...
|
||||
// Maybe creating my own malloc function...
|
||||
}
|
||||
*/
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
// Initialize asset manager from android app
|
||||
void InitAssetManager(AAssetManager *manager)
|
||||
|
@ -171,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
|
||||
|
@ -199,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue