25var
bool autocvar_g_logTimestamps =
false;
37#define LOGLEVEL_DEFAULT LOGLEVEL_WARNINGS
38var logLevel_t autocvar_g_logLevel = LOGLEVEL_DEFAULT;
40#define printf(...) print(sprintf(__VA_ARGS__))
50imageToConsole(
string imageName,
int imgSize,
string toolTip)
52 return sprintf(
"^[\\img\\%s\\s\\%i\\tip\\%s^]", imageName, imgSize, toolTip);
55#define CG_LOG imageToConsole("gfx/icon16/monitor", ICN_SIZE, "Client Game Log")
56#define CG_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Client Game Warning")
57#define CG_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Client Game Error")
59#define SV_LOG imageToConsole("gfx/icon16/server", ICN_SIZE, "Server Game Log")
60#define SV_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Server Game Warning")
61#define SV_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Server Game Error")
63#define UI_LOG imageToConsole("gfx/icon16/picture", ICN_SIZE, "Menu Game Log")
64#define UI_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Menu Game Warning")
65#define UI_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Menu Game Error")
71 if (autocvar_g_logTimestamps)
72 print(sprintf(
"%s ^9%f ^7%s\n", CG_LOG, time, msg));
74 print(sprintf(
"%s ^7%s\n", CG_LOG, msg));
77 if (autocvar_g_logTimestamps)
78 print(sprintf(
"%s ^9%f ^7%s\n", SV_LOG, time, msg));
80 print(sprintf(
"%s ^7%s\n", SV_LOG, msg));
83 if (autocvar_g_logTimestamps)
84 print(sprintf(
"%s ^9%f ^7%s\n", UI_LOG, time, msg));
86 print(sprintf(
"%s ^7%s\n", UI_LOG, msg));
91_ncError(
string functionName,
string msg)
94 if (autocvar_g_logTimestamps)
95 print(sprintf(
"%s ^9%f ^1%s^7: %s\n", CG_ERROR, time, functionName, msg));
97 print(sprintf(
"%s ^1%s^7: %s\n", CG_ERROR, functionName, msg));
100 if (autocvar_g_logTimestamps)
101 print(sprintf(
"%s ^9%f ^1%s^7: %s\n", SV_ERROR, time, functionName, msg));
103 print(sprintf(
"%s ^1%s^7: %s\n", SV_ERROR, functionName, msg));
106 if (autocvar_g_logTimestamps)
107 print(sprintf(
"%s ^9%f ^1%s^7: %s\n", UI_ERROR, time, functionName, msg));
109 print(sprintf(
"%s ^1%s^7: %s\n", UI_ERROR, functionName, msg));
114_ncWarning(
string functionName,
string msg)
117 if (autocvar_g_logTimestamps)
118 print(sprintf(
"%s ^9%f ^3%s^7: %s\n", CG_WARNING, time, functionName, msg));
120 print(sprintf(
"%s ^3%s^7: %s\n", CG_WARNING, functionName, msg));
123 if (autocvar_g_logTimestamps)
124 print(sprintf(
"%s ^9%f ^3%s^7: %s\n", SV_WARNING, time, functionName, msg));
126 print(sprintf(
"%s ^3%s^7: %s\n", SV_WARNING, functionName, msg));
129 if (autocvar_g_logTimestamps)
130 print(sprintf(
"%s ^9%f ^3%s^7: %s\n", UI_WARNING, time, functionName, msg));
132 print(sprintf(
"%s ^3%s^7: %s\n", UI_WARNING, functionName, msg));
137_NSAssert(
bool condition,
string function,
string descr)
141 print(strcat(CG_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
147 print(strcat(SV_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
153 print(strcat(UI_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
162#define ncLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncLog(sprintf(__VA_ARGS__))
168#define ncError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _ncError(__FUNC__, sprintf(__VA_ARGS__))
174#define ncWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _ncWarning(__FUNC__, sprintf(__VA_ARGS__))
182#define NSAssert(condition, ...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
194const vector g_vec_null = [0.0f, 0.0f, 0.0f];
200InitPrint(
string functionName)
205 string sideLeft =
"";
206 string sideRight =
"";
208 if (functionName == __NULL__) {
209 ncLog(
"---------------------------------------------------");
214 chars = chars - (int)strlen(functionName) - 2i;
215 charsLeft = chars / 2i;
216 charExtra = chars % 2i;
218 for (
int i = 0i; i < charsLeft; i++)
219 sideLeft = strcat(sideLeft,
"-");
221 for (
int i = 0i; i < (charsLeft + charExtra); i++) {
222 sideRight = strcat(sideRight,
"-");
225 ncLog(
"%s %s %s", sideLeft, functionName, sideRight);
228var
string g_lastInitFunc;
230_InitStart(
string functionName)
233 error(sprintf(
"Called InitStart() without InitEnd()ing %s!", g_lastInitFunc));
235 InitPrint(functionName);
236 g_lastInitFunc = functionName;
237 g_initTime = gettime(1);
240#define InitStart() _InitStart(__FUNC__)
245 float endTime = gettime(1);
246 ncLog(
"loaded in %.1f seconds", (endTime - g_initTime));
247 ncLog(
"---------------------------------------------------");
251#define InitEnd() _InitEnd()
254#define entity_def(x, ...) const string x[] = { __VA_ARGS__ }
257#define thread(x) if (fork()) { x; abort(); }
259#define STRING_SET(x) ((x != __NULL__) && (x != ""))
262fileExists(
string filePath)
265 if not(whichpack(filePath))
273 int modelNameLength = strlen(inputString);
274 return substring(inputString, modelNameLength - 3, modelNameLength);
278CallSpawnfuncByName(entity target,
string className)
280 entity oldSelf = self;
281 string spawnClass = strcat(
"spawnfunc_", className);
283 callfunction(spawnClass);
292#include "c_math_vector.h"
294#include "c_platform.h"
296#include "c_materials.h"
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37
string Util_ExtensionFromString(string inputString)
Extract the file extension from a given file name string.
Definition: defs.h:271