From 91e8bc7a5a9cd691930969ec066561e79dfb8d0f Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:24:15 +0200 Subject: [PATCH 01/13] Delete utils_android.go --- raylib/utils_android.go | 66 ----------------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 raylib/utils_android.go diff --git a/raylib/utils_android.go b/raylib/utils_android.go deleted file mode 100644 index aa965f4..0000000 --- a/raylib/utils_android.go +++ /dev/null @@ -1,66 +0,0 @@ -//go:build android -// +build android - -package rl - -/* -#include "raylib.h" -#include - -void log_info(const char *msg); -void log_warn(const char *msg); -void log_error(const char *msg); -void log_debug(const char *msg); - -extern char* get_internal_storage_path(); -*/ -import "C" - -import ( - "fmt" - "unsafe" -) - -// SetTraceLog - Enable trace log message types (bit flags based) -func SetTraceLog(typeFlags byte) { - logTypeFlags = typeFlags - - ctypeFlags := (C.int)(typeFlags) - C.SetTraceLogLevel(ctypeFlags) -} - -// TraceLog - Trace log messages showing (INFO, WARNING, ERROR, DEBUG) -func TraceLog(msgType int, text string, v ...interface{}) { - switch msgType { - case LogInfo: - if logTypeFlags&LogInfo != 0 { - msg := C.CString(fmt.Sprintf("INFO: "+text, v...)) - defer C.free(unsafe.Pointer(msg)) - C.log_info(msg) - } - case LogWarning: - if logTypeFlags&LogWarning != 0 { - msg := C.CString(fmt.Sprintf("WARNING: "+text, v...)) - defer C.free(unsafe.Pointer(msg)) - C.log_warn(msg) - } - case LogError: - if logTypeFlags&LogError != 0 { - msg := C.CString(fmt.Sprintf("ERROR: "+text, v...)) - defer C.free(unsafe.Pointer(msg)) - C.log_error(msg) - } - case LogDebug: - if logTypeFlags&LogDebug != 0 { - msg := C.CString(fmt.Sprintf("DEBUG: "+text, v...)) - defer C.free(unsafe.Pointer(msg)) - C.log_debug(msg) - } - } -} - -// HomeDir - Returns user home directory -// NOTE: On Android this returns internal data path and must be called after InitWindow -func HomeDir() string { - return C.GoString(C.get_internal_storage_path()) -} From b3ec30afeb7e2717d9b95c614e300d694bf25dae Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:24:33 +0200 Subject: [PATCH 02/13] Delete utils_android.c --- raylib/utils_android.c | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 raylib/utils_android.c diff --git a/raylib/utils_android.c b/raylib/utils_android.c deleted file mode 100644 index 2b80116..0000000 --- a/raylib/utils_android.c +++ /dev/null @@ -1,24 +0,0 @@ -// +build android - -#include "_cgo_export.h" -#include - -void log_info(const char *msg) { - __android_log_print(ANDROID_LOG_INFO, "raylib", "%s\n", msg); -} - -void log_warn(const char *msg) { - __android_log_print(ANDROID_LOG_WARN, "raylib", "%s\n", msg); -} - -void log_error(const char *msg) { - __android_log_print(ANDROID_LOG_ERROR, "raylib", "%s\n", msg); -} - -void log_debug(const char *msg) { - __android_log_print(ANDROID_LOG_DEBUG, "raylib", "%s\n", msg); -} - -const char* get_internal_storage_path() { - return internal_storage_path; -} From 9e579dc762abbd612bdf98ddf509ffe068d665a5 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:24:54 +0200 Subject: [PATCH 03/13] Delete utils_windows.go --- raylib/utils_windows.go | 53 ----------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 raylib/utils_windows.go diff --git a/raylib/utils_windows.go b/raylib/utils_windows.go deleted file mode 100644 index 60ee359..0000000 --- a/raylib/utils_windows.go +++ /dev/null @@ -1,53 +0,0 @@ -//go:build windows -// +build windows - -package rl - -/* -#include "raylib.h" -*/ -import "C" - -import ( - "fmt" - "os" -) - -// SetTraceLog - Enable trace log message types (bit flags based) -func SetTraceLog(typeFlags byte) { - logTypeFlags = typeFlags - - ctypeFlags := (C.int)(typeFlags) - C.SetTraceLogLevel(ctypeFlags) -} - -// TraceLog - Show trace log messages (INFO, WARNING, ERROR, DEBUG) -func TraceLog(msgType int, text string, v ...interface{}) { - switch msgType { - case LogInfo: - if logTypeFlags&LogInfo != 0 { - fmt.Printf("INFO: "+text+"\n", v...) - } - case LogWarning: - if logTypeFlags&LogWarning != 0 { - fmt.Printf("WARNING: "+text+"\n", v...) - } - case LogError: - if logTypeFlags&LogError != 0 { - fmt.Printf("ERROR: "+text+"\n", v...) - } - case LogDebug: - if logTypeFlags&LogDebug != 0 { - fmt.Printf("DEBUG: "+text+"\n", v...) - } - } -} - -// HomeDir - Returns user home directory -func HomeDir() string { - home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH") - if home == "" { - home = os.Getenv("USERPROFILE") - } - return home -} From 3f3fdc5c6f09a7130f4f3b1a4bf35d478693d573 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:25:29 +0200 Subject: [PATCH 04/13] Update utils.go --- raylib/utils.go | 56 +++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/raylib/utils.go b/raylib/utils.go index 39b1373..1c3fbe0 100644 --- a/raylib/utils.go +++ b/raylib/utils.go @@ -1,49 +1,41 @@ -//go:build !android && !windows -// +build !android,!windows - package rl /* +#include "stdlib.h" #include "raylib.h" +void TraceLogWrapper(int logLevel, const char *text) +{ + TraceLog(logLevel, text); +} */ import "C" import ( - "fmt" - "os" + "fmt" + "os" + "unsafe" ) -// SetTraceLog - Enable trace log message types -func SetTraceLog(typeFlags byte) { - logTypeFlags = typeFlags - - ctypeFlags := (C.int)(typeFlags) - C.SetTraceLogLevel(ctypeFlags) +// Set the current threshold (minimum) log level +func SetTraceLog(logLevel TraceLogLevel) { + clogLevel := (C.int)(logLevel) + C.SetTraceLogLevel(clogLevel) } -// TraceLog - Show trace log messages (INFO, WARNING, ERROR, DEBUG) -func TraceLog(msgType int, text string, v ...interface{}) { - switch msgType { - case LogInfo: - if logTypeFlags&LogInfo != 0 { - fmt.Printf("INFO: "+text+"\n", v...) - } - case LogWarning: - if logTypeFlags&LogWarning != 0 { - fmt.Printf("WARNING: "+text+"\n", v...) - } - case LogError: - if logTypeFlags&LogError != 0 { - fmt.Printf("ERROR: "+text+"\n", v...) - } - case LogDebug: - if logTypeFlags&LogDebug != 0 { - fmt.Printf("DEBUG: "+text+"\n", v...) - } - } +// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) +func TraceLog(logLevel TraceLogLevel, text string, v ...interface{}) { + ctext := C.CString(fmt.Sprintf(text, v...)) + defer C.free(unsafe.Pointer(ctext)) + clogLevel := (C.int)(logLevel) + C.TraceLogWrapper(clogLevel, ctext) } // HomeDir - Returns user home directory func HomeDir() string { - return os.Getenv("HOME") + if homeDir, err := os.UserHomeDir(); err != nil { + return homeDir + } + return "" } + + From 3c6fcf8bce2e416834b60bd5e859cbf9183a499a Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:26:32 +0200 Subject: [PATCH 05/13] Update utils.go --- raylib/utils.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/raylib/utils.go b/raylib/utils.go index 1c3fbe0..bc8ee21 100644 --- a/raylib/utils.go +++ b/raylib/utils.go @@ -37,5 +37,3 @@ func HomeDir() string { } return "" } - - From ef4e71cff713071706474bc95c538e4bd9ae97fb Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:29:53 +0200 Subject: [PATCH 06/13] Update raylib.go --- raylib/raylib.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/raylib/raylib.go b/raylib/raylib.go index e897128..a87909e 100644 --- a/raylib/raylib.go +++ b/raylib/raylib.go @@ -1195,16 +1195,25 @@ func newRenderTexture2DFromPointer(ptr unsafe.Pointer) RenderTexture2D { return *(*RenderTexture2D)(ptr) } -// Log message types +type TraceLogLevel int + +// Trace log level +// NOTE: Organized by priority level const ( - LogAll = iota + // Display all logs + LogAll TraceLogLevel = iota + // Trace logging, intended for internal use only LogTrace + // Debug logging, used for internal debugging, it should be disabled on release builds LogDebug + // Info logging, used for program execution info LogInfo + // Warning logging, used on recoverable failures LogWarning + // Error logging, used on unrecoverable failures LogError + // Fatal logging, used to abort program: exit(EXIT_FAILURE) LogFatal + // Disable logging LogNone ) - -var logTypeFlags byte = LogInfo | LogWarning | LogError From 010d4eb10f346201eaed0800d9a50194e67a0d6a Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:34:23 +0200 Subject: [PATCH 07/13] Update utils.go --- raylib/utils.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/raylib/utils.go b/raylib/utils.go index bc8ee21..cf83feb 100644 --- a/raylib/utils.go +++ b/raylib/utils.go @@ -5,35 +5,35 @@ package rl #include "raylib.h" void TraceLogWrapper(int logLevel, const char *text) { - TraceLog(logLevel, text); + TraceLog(logLevel, text); } */ import "C" import ( - "fmt" - "os" - "unsafe" + "fmt" + "os" + "unsafe" ) // Set the current threshold (minimum) log level func SetTraceLog(logLevel TraceLogLevel) { - clogLevel := (C.int)(logLevel) - C.SetTraceLogLevel(clogLevel) + clogLevel := (C.int)(logLevel) + C.SetTraceLogLevel(clogLevel) } // Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) func TraceLog(logLevel TraceLogLevel, text string, v ...interface{}) { - ctext := C.CString(fmt.Sprintf(text, v...)) - defer C.free(unsafe.Pointer(ctext)) - clogLevel := (C.int)(logLevel) - C.TraceLogWrapper(clogLevel, ctext) + ctext := C.CString(fmt.Sprintf(text, v...)) + defer C.free(unsafe.Pointer(ctext)) + clogLevel := (C.int)(logLevel) + C.TraceLogWrapper(clogLevel, ctext) } // HomeDir - Returns user home directory func HomeDir() string { - if homeDir, err := os.UserHomeDir(); err != nil { - return homeDir - } - return "" + if homeDir, err := os.UserHomeDir(); err != nil { + return homeDir + } + return "" } From 37fe6619d4b67227cca07a0d02b21d4a2be680a9 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:31:12 +0200 Subject: [PATCH 08/13] Update platform_android.go --- raylib/platform_android.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/raylib/platform_android.go b/raylib/platform_android.go index d50dcaf..3e79e99 100644 --- a/raylib/platform_android.go +++ b/raylib/platform_android.go @@ -131,3 +131,7 @@ func (a *asset) Close() error { C.AAsset_close(a.ptr) return nil } + +func getInternalStoragePath() string { + return C.GoString(C.internal_storage_path) +} From c1f48ea0ac1b3d8eeb148f48daac85f7918a1af9 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:33:08 +0200 Subject: [PATCH 09/13] Update utils.go --- raylib/utils.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/raylib/utils.go b/raylib/utils.go index cf83feb..f5a1979 100644 --- a/raylib/utils.go +++ b/raylib/utils.go @@ -13,6 +13,7 @@ import "C" import ( "fmt" "os" + "runtime" "unsafe" ) @@ -31,7 +32,12 @@ func TraceLog(logLevel TraceLogLevel, text string, v ...interface{}) { } // HomeDir - Returns user home directory +// NOTE: On Android this returns internal data path and must be called after InitWindow func HomeDir() string { + if runtime.GOOS == "android" { + return getInternalStoragePath() + } + if homeDir, err := os.UserHomeDir(); err != nil { return homeDir } From 76f1c56135ad4c7b17c198eb8615075813fa4b85 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:58:31 +0200 Subject: [PATCH 10/13] Update utils.go --- raylib/utils.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/raylib/utils.go b/raylib/utils.go index f5a1979..ea98082 100644 --- a/raylib/utils.go +++ b/raylib/utils.go @@ -1,3 +1,6 @@ +//go:build !android +// +build !android + package rl /* @@ -13,7 +16,6 @@ import "C" import ( "fmt" "os" - "runtime" "unsafe" ) @@ -33,11 +35,7 @@ func TraceLog(logLevel TraceLogLevel, text string, v ...interface{}) { // HomeDir - Returns user home directory // NOTE: On Android this returns internal data path and must be called after InitWindow -func HomeDir() string { - if runtime.GOOS == "android" { - return getInternalStoragePath() - } - +func HomeDir() string { if homeDir, err := os.UserHomeDir(); err != nil { return homeDir } From bd025d2b1e113c1623fafc96d49bc7ce1be56d20 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 22:02:00 +0200 Subject: [PATCH 11/13] Create utils_android.go --- raylib/utils_android.go | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 raylib/utils_android.go diff --git a/raylib/utils_android.go b/raylib/utils_android.go new file mode 100644 index 0000000..e820e53 --- /dev/null +++ b/raylib/utils_android.go @@ -0,0 +1,10 @@ +//go:build android +// +build android + +package rl + +// HomeDir - Returns user home directory +// NOTE: On Android this returns internal data path and must be called after InitWindow +func HomeDir() string { + return getInternalStoragePath() +} From 460dab9501584b34b58510fabc2f634c28c733a0 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 22:02:35 +0200 Subject: [PATCH 12/13] Update utils_android.go --- raylib/utils_android.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raylib/utils_android.go b/raylib/utils_android.go index e820e53..ce99e24 100644 --- a/raylib/utils_android.go +++ b/raylib/utils_android.go @@ -6,5 +6,5 @@ package rl // HomeDir - Returns user home directory // NOTE: On Android this returns internal data path and must be called after InitWindow func HomeDir() string { - return getInternalStoragePath() + return getInternalStoragePath() } From e33a1830c9d530a3662b78d20325fb021947a2c6 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Tue, 25 Oct 2022 22:09:18 +0200 Subject: [PATCH 13/13] Update utils_android.go --- raylib/utils_android.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/raylib/utils_android.go b/raylib/utils_android.go index ce99e24..69c41c3 100644 --- a/raylib/utils_android.go +++ b/raylib/utils_android.go @@ -3,6 +3,35 @@ package rl +/* +#include "stdlib.h" +#include "raylib.h" +void TraceLogWrapper(int logLevel, const char *text) +{ + TraceLog(logLevel, text); +} +*/ +import "C" + +import ( + "fmt" + "unsafe" +) + +// Set the current threshold (minimum) log level +func SetTraceLog(logLevel TraceLogLevel) { + clogLevel := (C.int)(logLevel) + C.SetTraceLogLevel(clogLevel) +} + +// Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) +func TraceLog(logLevel TraceLogLevel, text string, v ...interface{}) { + ctext := C.CString(fmt.Sprintf(text, v...)) + defer C.free(unsafe.Pointer(ctext)) + clogLevel := (C.int)(logLevel) + C.TraceLogWrapper(clogLevel, ctext) +} + // HomeDir - Returns user home directory // NOTE: On Android this returns internal data path and must be called after InitWindow func HomeDir() string {