25var
bool autocvar_g_logTimestamps =
false;
28typedef float musictrack_t;
38#define LOGLEVEL_DEFAULT LOGLEVEL_WARNINGS
39var logLevel_t autocvar_g_logLevel = LOGLEVEL_DEFAULT;
41#define printf(...) print(sprintf(__VA_ARGS__))
51imageToConsole(
string imageName,
int imgSize,
string toolTip)
53 return sprintf(
"^[\\img\\%s\\s\\%i\\tip\\%s^]", imageName, imgSize, toolTip);
56#define CG_LOG imageToConsole("gfx/icon16/monitor", ICN_SIZE, "Client Game Log")
57#define CG_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Client Game Warning")
58#define CG_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Client Game Error")
60#define SV_LOG imageToConsole("gfx/icon16/server", ICN_SIZE, "Server Game Log")
61#define SV_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Server Game Warning")
62#define SV_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Server Game Error")
64#define UI_LOG imageToConsole("gfx/icon16/picture", ICN_SIZE, "Menu Game Log")
65#define UI_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Menu Game Warning")
66#define UI_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Menu Game Error")
72 if (autocvar_g_logTimestamps)
73 print(sprintf(
"%s ^9%f ^7%s\n", CG_LOG, time, msg));
75 print(sprintf(
"%s ^7%s\n", CG_LOG, msg));
78 if (autocvar_g_logTimestamps)
79 print(sprintf(
"%s ^9%f ^7%s\n", SV_LOG, time, msg));
81 print(sprintf(
"%s ^7%s\n", SV_LOG, msg));
84 if (autocvar_g_logTimestamps)
85 print(sprintf(
"%s ^9%f ^7%s\n", UI_LOG, time, msg));
87 print(sprintf(
"%s ^7%s\n", UI_LOG, msg));
92_ncError(
string functionName,
string msg)
95 if (autocvar_g_logTimestamps)
96 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", CG_ERROR, time, functionName, msg));
98 print(sprintf(
"%s ^1%s^1: %s\n", CG_ERROR, functionName, msg));
101 if (autocvar_g_logTimestamps)
102 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", SV_ERROR, time, functionName, msg));
104 print(sprintf(
"%s ^1%s^1: %s\n", SV_ERROR, functionName, msg));
107 if (autocvar_g_logTimestamps)
108 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", UI_ERROR, time, functionName, msg));
110 print(sprintf(
"%s ^1%s^1: %s\n", UI_ERROR, functionName, msg));
115_ncWarning(
string functionName,
string msg)
118 if (autocvar_g_logTimestamps)
119 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", CG_WARNING, time, functionName, msg));
121 print(sprintf(
"%s ^3%s^1: %s\n", CG_WARNING, functionName, msg));
124 if (autocvar_g_logTimestamps)
125 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", SV_WARNING, time, functionName, msg));
127 print(sprintf(
"%s ^3%s^1: %s\n", SV_WARNING, functionName, msg));
130 if (autocvar_g_logTimestamps)
131 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", UI_WARNING, time, functionName, msg));
133 print(sprintf(
"%s ^3%s^1: %s\n", UI_WARNING, functionName, msg));
138_NSAssert(
bool condition,
string function,
string descr)
142 print(strcat(CG_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
148 print(strcat(SV_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
154 print(strcat(UI_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
163#define ncLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncLog(sprintf(__VA_ARGS__))
169#define ncLogAlways(...) _ncLog(sprintf(__VA_ARGS__))
175#define ncError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _ncError(__FUNC__, sprintf(__VA_ARGS__))
181#define ncWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _ncWarning(__FUNC__, sprintf(__VA_ARGS__))
189#define NSAssert(condition, ...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
201const vector g_vec_null = [0.0f, 0.0f, 0.0f];
207InitPrint(
string functionName)
212 string sideLeft =
"";
213 string sideRight =
"";
215 if (functionName == __NULL__) {
216 ncLog(
"---------------------------------------------------");
221 chars = chars - (int)strlen(functionName) - 2i;
222 charsLeft = chars / 2i;
223 charExtra = chars % 2i;
225 for (
int i = 0i; i < charsLeft; i++)
226 sideLeft = strcat(sideLeft,
"-");
228 for (
int i = 0i; i < (charsLeft + charExtra); i++) {
229 sideRight = strcat(sideRight,
"-");
232 ncLogAlways(
"%s %s %s", sideLeft, functionName, sideRight);
235var
string g_lastInitFunc;
237_InitStart(
string functionName)
240 error(sprintf(
"Called InitStart() without InitEnd()ing %s!", g_lastInitFunc));
242 InitPrint(functionName);
243 g_lastInitFunc = functionName;
244 g_initTime = gettime(1);
247#define InitStart() _InitStart(__FUNC__)
252 float endTime = gettime(1);
253 ncLogAlways(
"loaded in %.1f seconds", (endTime - g_initTime));
254 ncLogAlways(
"---------------------------------------------------");
258#define InitEnd() _InitEnd()
261#define entity_def(x, ...) const string x[] = { __VA_ARGS__ }
264#define thread(x) if (fork()) { x; abort(); }
266#define STRING_SET(x) ((x != __NULL__) && (x != ""))
269fileExists(
string filePath)
272 if not(whichpack(filePath))
279fileExtensionFromString(
string inputString)
281 int modelNameLength = strlen(inputString);
282 return substring(inputString, modelNameLength - 3, -1);
285#define Util_ExtensionFromString fileExtensionFromString
288wordInString(
string fullString,
string wordToFind)
290 int wordCount = tokenize(fullString);
292 for (
int i = 0; i < wordCount; i++) {
293 if (wordToFind == argv(i)) {
302CallSpawnfuncByName(entity target,
string className)
304 entity oldSelf = self;
305 string spawnClass = strcat(
"spawnfunc_", className);
307 callfunction(spawnClass);