diff options
author | chai <chaifix@163.com> | 2021-11-01 12:10:29 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-01 12:10:29 +0800 |
commit | 44d6c41e5e586572de08c72c358aed9100a30353 (patch) | |
tree | a3dee8cbb9f7181c88464b31f231a264c570acd4 /Runtime | |
parent | 78417f6cdedfcf60c8ca437190975644e942e01f (diff) |
*log
Diffstat (limited to 'Runtime')
-rw-r--r-- | Runtime/Debug/Log.cpp | 164 | ||||
-rw-r--r-- | Runtime/Debug/Log.h | 16 | ||||
-rw-r--r-- | Runtime/Graphics/DynamicVertexBuffer.h | 1 | ||||
-rw-r--r-- | Runtime/Graphics/VertexBuffer.h | 7 | ||||
-rw-r--r-- | Runtime/Scripting/Debug/Debug.bind.cpp | 10 | ||||
-rw-r--r-- | Runtime/Scripting/GL/GL.bind.cpp | 2 | ||||
-rw-r--r-- | Runtime/Scripting/IO/IO.bind.cpp | 6 | ||||
-rw-r--r-- | Runtime/Scripting/Rendering/Rendering.bind.cpp | 2 | ||||
-rw-r--r-- | Runtime/Scripting/Resource/Resource.bind.cpp | 2 |
9 files changed, 115 insertions, 95 deletions
diff --git a/Runtime/Debug/Log.cpp b/Runtime/Debug/Log.cpp index c92bdc8..c44d7af 100644 --- a/Runtime/Debug/Log.cpp +++ b/Runtime/Debug/Log.cpp @@ -3,6 +3,7 @@ #include <iostream> #include <ctime> #include <unordered_set> +#include <stdarg.h> using namespace std; @@ -30,105 +31,124 @@ const std::string currentDateTime() { return buf; } -void log_open_tag(std::string tag) -{ - s_OpenTags.insert(tag); +static void SetOutputColor(int i) { + if (s_ConsoleHandle == 0) { + s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + } + if (i == 0) { + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); + } + else if(i == 1) { + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); + } + else { + SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_INTENSITY); + } } -// https://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c -// https://en.wikipedia.org/wiki/ANSI_escape_code#Windows_and_DOS -// https://stackoverflow.com/questions/9262270/color-console-output-with-c-in-windows -// https://blog.csdn.net/odaynot/article/details/7722240 - -void log_info(std::string log) +void log_error_null_param(const char* funcName, const char* param) { - Lock(s_Mutex) { -#ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Info] " << log << endl; -#else - cout << "\x1B[97m" << currentDateTime() << " [Info] " << log << "\x1B[0m" << endl; -#endif - } -} - -void log_warning(std::string log) -{ - Lock(s_Mutex) { -#ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Warning] " << log << endl; -#else - cout << "\x1B[93m" << currentDateTime() << " [Warning] " << log << "\x1B[0m" << endl; -#endif - } + log_error("Null parameter in %s called %s", funcName, param); } -void log_error(std::string log) +void log_open_tag(const char* tag) { - Lock(s_Mutex) { -#ifdef GAMELAB_WIN - if (s_ConsoleHandle == 0) { - s_ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); - } - SetConsoleTextAttribute(s_ConsoleHandle, FOREGROUND_RED | FOREGROUND_INTENSITY); - cout << currentDateTime() << " [Error] " << log << endl; -#else - cout << "\x1B[91m" << currentDateTime() << " [Error] " << log << "\x1B[0m" << endl; -#endif - } + s_OpenTags.insert(tag); } -void log_error_null_param(std::string funcName, std::string param) +void log_info(const char* fmt, ...) { - log_error("Null parameter in " + funcName + " called " + param); + Lock(s_Mutex) { + SetOutputColor(0); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Info] ", currentDateTime().c_str()); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ }
} -void log_info(string tag, std::string log) +void log_warning(const char* fmt, ...) { - if (s_OpenTags.count(tag) <= 0) - return; - log_info("[" + tag + "] " + log); + Lock(s_Mutex) { + SetOutputColor(1); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Warning] ", currentDateTime().c_str()); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ }
} -void log_warning(string tag, std::string log) -{ - if (s_OpenTags.count(tag) <= 0) - return; - log_warning("[" + tag + "] " + log); -} -void log_error(string tag, std::string log) -{ - if (s_OpenTags.count(tag) <= 0) - return; - log_error("[" + tag + "] " + log); -} -#else -void log_open_tag(std::string tag) {} -void log_info(std::string log) +void log_error(const char* fmt, ...) { + Lock(s_Mutex) { + SetOutputColor(2); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Error] ", currentDateTime().c_str()); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ }
} -void log_warning(std::string log) +void log_info_tag(const char* tag, const char* fmt, ...) { + Lock(s_Mutex) { + SetOutputColor(0); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Info] %s ", currentDateTime().c_str(), tag); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ } } -void log_error(std::string log) +void log_warning_tag(const char* tag, const char* fmt, ...) { + Lock(s_Mutex) { + SetOutputColor(1); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Warning] %s ", currentDateTime().c_str(), tag); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ } } -void log_error_null_param(std::string funcName, std::string param) +void log_error_tag(const char* tag, const char* fmt, ...) { + Lock(s_Mutex) { + SetOutputColor(2); + va_list pArgs = NULL;
+ va_start(pArgs, fmt); + printf("%s [Error] %s ", currentDateTime().c_str(), tag); + vprintf(fmt, pArgs); + printf("\n"); + va_end(pArgs);
+ } } +#else +void log_open_tag(std::string tag) {} +void log_info(std::string log) {} +void log_warning(std::string log){} +void log_error(std::string log){} +void log_error_null_param(std::string funcName, std::string param){} void log_info(string tag, std::string log) {} void log_warning(string tag, std::string log) {} void log_error(string tag, std::string log) {} -#endif
\ No newline at end of file +void log_open_tag(const char* tag) {} +void log_info(const char* log, ...) {} +void log_warning(const char* log, ...) {} +void log_error(const char* log, ...) {} +void log_info(const char* tag, const char* log, ...) {} +void log_warning(const char* tag, const char* log, ...) {} +void log_error(const char* tag, const char* log, ...) {} +#endif
\ No newline at end of file diff --git a/Runtime/Debug/Log.h b/Runtime/Debug/Log.h index aaaaa78..8547102 100644 --- a/Runtime/Debug/Log.h +++ b/Runtime/Debug/Log.h @@ -1,14 +1,14 @@ #pragma once #include <string> -void log_open_tag(std::string tag); +void log_open_tag(const char* tag); -void log_info(std::string log); -void log_warning(std::string log); -void log_error(std::string log); +void log_info(const char* fmt, ...); +void log_warning(const char* fmt, ...); +void log_error(const char* fmt, ...); -void log_error_null_param(std::string funcName, std::string param); +void log_error_null_param(const char* funcName, const char* param); -void log_info(std::string tag, std::string log); -void log_warning(std::string tag, std::string log); -void log_error(std::string tag, std::string log); +void log_info_tag(const char* tag, const char* fmt, ...); +void log_warning_tag(const char* tag, const char* fmt, ...); +void log_error_tag(const char* tag, const char* fmt, ...); diff --git a/Runtime/Graphics/DynamicVertexBuffer.h b/Runtime/Graphics/DynamicVertexBuffer.h index a849f4c..b520d1b 100644 --- a/Runtime/Graphics/DynamicVertexBuffer.h +++ b/Runtime/Graphics/DynamicVertexBuffer.h @@ -10,6 +10,7 @@ #include "CustomVertexLayout.h" #include "Primitive.h" +// ¶¯Ì¬Ìî³äµÄVBO class DynamicVertexBuffer { public: diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h index 5e4fdf2..e6fd9ee 100644 --- a/Runtime/Graphics/VertexBuffer.h +++ b/Runtime/Graphics/VertexBuffer.h @@ -1,5 +1,4 @@ -#ifndef VBO_H -#define VBO_H +#pragma once #include <vector> @@ -31,8 +30,8 @@ public: private: VertexBufferType m_Type; + GPU::DataBuffer* m_VB; GPU::DataBuffer* m_IB; -}; -#endif
\ No newline at end of file +}; diff --git a/Runtime/Scripting/Debug/Debug.bind.cpp b/Runtime/Scripting/Debug/Debug.bind.cpp index 9d98211..275f935 100644 --- a/Runtime/Scripting/Debug/Debug.bind.cpp +++ b/Runtime/Scripting/Debug/Debug.bind.cpp @@ -14,7 +14,7 @@ int log(lua_State* L) { const char* tag = state.GetValue<const char*>(-2, ""); const char* msg = state.GetValue<const char*>(-1, ""); - log_info(tag, msg); + log_warning_tag(tag, msg); } else { @@ -36,7 +36,7 @@ int logWwarning(lua_State* L) { const char* tag = state.GetValue<const char*>(-2, ""); const char* msg = state.GetValue<const char*>(-1, ""); - log_warning(tag, msg); + log_warning_tag(tag, msg); } else { @@ -58,7 +58,7 @@ int logError(lua_State* L) { const char* tag = state.GetValue<const char*>(-2, ""); const char* msg = state.GetValue<const char*>(-1, ""); - log_error(tag, msg); + log_error_tag(tag, msg); } else { @@ -81,7 +81,7 @@ int logEditor(lua_State* L) { const char* tag = state.GetValue<const char*>(-2, ""); const char* msg = state.GetValue<const char*>(-1, ""); - log_info(tag, msg); + log_info_tag(tag, msg); } else { @@ -103,7 +103,7 @@ int openTag(lua_State* L) int luaopen_GameLab_Debug(lua_State* L) { - log_info("Scripting", "luaopen_GameLab_Debug()"); + log_info_tag("Scripting", "luaopen_GameLab_Debug()"); LUA_BIND_STATE(L); diff --git a/Runtime/Scripting/GL/GL.bind.cpp b/Runtime/Scripting/GL/GL.bind.cpp index 40093e9..f2a270b 100644 --- a/Runtime/Scripting/GL/GL.bind.cpp +++ b/Runtime/Scripting/GL/GL.bind.cpp @@ -421,7 +421,7 @@ static luaL_Reg glFuncs[] = { // GameLab.Engine.GL int luaopen_GameLab_Engine_GL(lua_State* L) { - log_info("Scripting", "luaopen_GameLab_Engine_GL()"); + log_info_tag("Scripting", "luaopen_GameLab_Engine_GL()"); LUA_BIND_STATE(L); diff --git a/Runtime/Scripting/IO/IO.bind.cpp b/Runtime/Scripting/IO/IO.bind.cpp index a46b110..f9530a2 100644 --- a/Runtime/Scripting/IO/IO.bind.cpp +++ b/Runtime/Scripting/IO/IO.bind.cpp @@ -62,7 +62,7 @@ int ReadFile(lua_State* L) std::ifstream file = ifstream(path, openMode); if (!file.is_open()) { - log_error(string("Can't read file. ") + path); + log_error("Can't read file. %s", path); state.PushNil(); return 1; } @@ -72,7 +72,7 @@ int ReadFile(lua_State* L) size = file.tellg() - size; if (size == 0) { - log_error(string("File is Empty. ") + path); + log_error("File is Empty. %s", path); state.PushNil(); return 1; } @@ -106,7 +106,7 @@ static luaL_Reg ioFuncs[] = { int luaopen_GameLab_IO(lua_State* L) { - log_info("Scripting", "luaopen_GameLab_IO()"); + log_info_tag("Scripting", "luaopen_GameLab_IO()"); LUA_BIND_STATE(L); diff --git a/Runtime/Scripting/Rendering/Rendering.bind.cpp b/Runtime/Scripting/Rendering/Rendering.bind.cpp index 9fb9a48..f4777b7 100644 --- a/Runtime/Scripting/Rendering/Rendering.bind.cpp +++ b/Runtime/Scripting/Rendering/Rendering.bind.cpp @@ -28,7 +28,7 @@ static luaL_Reg funcs[] = { int luaopen_GameLab_Engine_Rendering(lua_State* L) { - log_info("Scripting", "luaopen_GameLab_Engine_Rendering()"); + log_info_tag("Scripting", "luaopen_GameLab_Engine_Rendering()"); LUA_BIND_STATE(L); diff --git a/Runtime/Scripting/Resource/Resource.bind.cpp b/Runtime/Scripting/Resource/Resource.bind.cpp index 379d88d..a09460e 100644 --- a/Runtime/Scripting/Resource/Resource.bind.cpp +++ b/Runtime/Scripting/Resource/Resource.bind.cpp @@ -47,7 +47,7 @@ static luaL_Reg funcs[] = { int luaopen_GameLab_Engine_Resource(lua_State* L) { - log_info("Scripting", "luaopen_GameLab_Engine_Resource()"); + log_info_tag("Scripting", "luaopen_GameLab_Engine_Resource()"); LUA_BIND_STATE(L); |