Nuclide
Software Development Kit for id Tech
global.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17var bool autocvar_g_developer = false;
19
20#define printf(...) print(sprintf(__VA_ARGS__))
21
22#ifdef DOXYGEN
24#define enumflags enum
25#endif
26
27void
28_NSLog(string msg)
29{
31 print(sprintf("^9%f ^7%s\n", time, msg));
32 else
33 print(sprintf("^7%s\n", msg));
34}
35
36void
37_NSError(string functionName, string msg)
38{
40 print(sprintf("^9%f ^1%s^7: %s\n", time, functionName, msg));
41 else
42 print(sprintf("^1%s^7: %s\n", functionName, msg));
43}
44
45void
46_NSWarning(string functionName, string msg)
47{
49 print(sprintf("^9%f ^3%s^7: %s\n", time, functionName, msg));
50 else
51 print(sprintf("^3%s^7: %s\n", functionName, msg));
52}
53
54void
55_NSAssert(bool condition, string function, string descr)
56{
57 if (!condition) {
58 print(strcat("^1Assertion failed in ", function, ", reason: ", descr, "\n"));
59#ifndef MENU
60 breakpoint();
61#endif
62 }
63}
64
69#define NSLog(...) if (autocvar_g_developer) _NSLog(sprintf(__VA_ARGS__))
70
75#define NSError(...) _NSError(__FUNC__, sprintf(__VA_ARGS__))
76
81#define NSWarning(...) _NSWarning(__FUNC__, sprintf(__VA_ARGS__))
82
89#define NSAssert(condition, ...) if (autocvar_g_developer) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
90
91typedef enumflags
92{
100
101const vector g_vec_null = [0.0f, 0.0f, 0.0f];
102
103/* the console needs some attention too. */
104var float g_initTime;
105
106void
107InitPrint(string functionName)
108{
109 int chars = 51i;
110 int charsLeft;
111 int charExtra;
112 string sideLeft = "";
113 string sideRight = "";
114
115 if (functionName == __NULL__) {
116 NSLog("---------------------------------------------------");
117 return;
118 }
119
120 /* word and padding */
121 chars = chars - (int)strlen(functionName) - 2i;
122 charsLeft = chars / 2i;
123 charExtra = chars % 2i;
124
125 for (int i = 0i; i < charsLeft; i++)
126 sideLeft = strcat(sideLeft,"-");
127
128 for (int i = 0i; i < (charsLeft + charExtra); i++) {
129 sideRight = strcat(sideRight,"-");
130 }
131
132 NSLog( "%s %s %s", sideLeft, functionName, sideRight);
133}
134
135void
136_InitStart(string functionName)
137{
138 if (g_initTime != 0)
139 error("Called InitStart() without InitEnd()ing the previous one!");
140
141 InitPrint(functionName);
142 g_initTime = gettime(1);
143}
144
145#define InitStart() _InitStart(__FUNC__)
146
147
148void
150{
151 float endTime = gettime(1);
152 NSLog("loaded in %.1f seconds", (endTime - g_initTime));
153 NSLog("---------------------------------------------------");
154 g_initTime = 0;
155}
156
157#define InitEnd() _InitEnd()
float time
Definition: fteextensions.qc:509
vector(vector) normalize
get __int i
Definition: fteextensions.qc:3826
int(float fhandle, void *ptr, int size) fread
const vector g_vec_null
Definition: global.h:101
var float g_initTime
Definition: global.h:104
void _InitStart(string functionName)
Definition: global.h:136
void _NSWarning(string functionName, string msg)
Definition: global.h:46
void _NSLog(string msg)
Definition: global.h:28
void _NSError(string functionName, string msg)
Definition: global.h:37
searchFlags_t
Definition: global.h:92
@ SEARCH_MULTISEARCH
When set, separating search queries with : will allow for multiple queries in one string.
Definition: global.h:97
@ SEARCH_FORCESEARCH
Search a given game directory even if it's not mounted.
Definition: global.h:96
@ SEARCH_NAMESORT
Sort the results alphabetically (slower)
Definition: global.h:98
@ SEARCH_FULLPACKAGE
Package names include the game directory as a prefix.
Definition: global.h:94
@ SEARCH_INSENSITIVE
Attempt to do a case-insensitive search (slower)
Definition: global.h:93
@ SEARCH_ALLOWDUPES
Do not attempt to remove duplicate results (so you can search through multiple archives)
Definition: global.h:95
var bool autocvar_g_developer
Definition: global.h:17
void _NSAssert(bool condition, string function, string descr)
Definition: global.h:55
var bool autocvar_g_developerTimestamps
Definition: global.h:18
void InitPrint(string functionName)
Definition: global.h:107
#define NSLog(...)
Logs an message, with timestamp.
Definition: global.h:69
void _InitEnd(void)
Definition: global.h:149
#define enumflags
Doxygen doesn't know what enumflags (aka bitfields) are, used as e.g.
Definition: global.h:24