]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/debug.qh
##__VA_ARGS__: replace with standards compliant alternative
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / debug.qh
1 #ifndef DEBUG_H
2 #define DEBUG_H
3
4 #ifndef MENUQC
5 .bool debug;
6 .int sv_entnum;
7 REGISTER_NET_TEMP(net_debug)
8 #endif
9
10 #ifdef CSQC
11         NET_HANDLE(net_debug, bool isNew)
12         {
13                 Net_Accept(net_debug);
14                 this.sv_entnum = ReadShort();
15                 if (ReadByte()) make_pure(this);
16                 this.origin_x = ReadCoord();
17                 this.origin_y = ReadCoord();
18                 this.origin_z = ReadCoord();
19                 setorigin(this, this.origin);
20                 this.debug = true;  // identify server entities by this
21                 this.classname = strzone(ReadString());
22                 this.sourceLoc = strzone(ReadString());
23                 return true;
24         }
25 #endif
26
27 #ifdef SVQC
28         bool debug_send(entity this, entity to, int sf)
29         {
30                 int channel = MSG_ONE;
31                 msg_entity = to;
32                 WriteHeader(channel, net_debug);
33                 WriteShort(channel, etof(this));
34                 WriteByte(channel, is_pure(this));
35                 WriteCoord(channel, this.origin.x);
36                 WriteCoord(channel, this.origin.y);
37                 WriteCoord(channel, this.origin.z);
38                 WriteString(channel, this.classname);
39                 WriteString(channel, this.sourceLoc);
40                 return true;
41         }
42 #endif
43
44 #ifndef MENUQC
45 bool autocvar_debugdraw;
46 #endif
47
48 #ifdef CSQC
49         string autocvar_debugdraw_filter, autocvar_debugdraw_filterout;
50         .int debugdraw_last;
51         vector project_3d_to_2d(vector vec);
52         void Debug_Draw()
53         {
54                 if (!autocvar_debugdraw) return;
55                 static int debugdraw_frame;
56                 ++debugdraw_frame;
57                 const int sz = 8;
58                 FOREACH_ENTITY(true, LAMBDA(
59                         if (it.debugdraw_last == debugdraw_frame) continue;
60                         int ofs = 0;
61                         for (entity e = findradius(it.origin, 100); e; e = e.chain)
62                         {
63                                 if (e.debugdraw_last == debugdraw_frame) continue;
64                                 e.debugdraw_last = debugdraw_frame;
65                                 vector rgb = (e.debug) ? '0 0 1' : '1 0 0';
66                                 if (autocvar_debugdraw_filterout != "" && strhasword(autocvar_debugdraw_filterout, e.classname)) continue;
67                                 if (autocvar_debugdraw_filter != "" && !strhasword(autocvar_debugdraw_filter, e.classname)) continue;
68                                 if (autocvar_debugdraw == 3)
69                                 {
70                                         if (!e.entnum) continue;
71                                 }
72                                 if (autocvar_debugdraw == 4)
73                                 {
74                                         if (e.origin) continue;
75                                 }
76                                 else if (autocvar_debugdraw > 4)
77                                 {
78                                         bool flag = true;
79                                         do {
80 //                                              if (e.modelindex) break;
81 //                                              if (e.absmin) break;
82 //                                              if (e.absmax) break;
83 //                                              if (e.entnum) break;
84 //                                              if (e.drawmask) break;
85 //                                              if (e.predraw) break;
86 //                                              if (e.movetype) break;
87                                                 if (e.solid) break;
88 //                                              if (e.origin) break;
89 //                                              if (e.oldorigin) break;
90 //                                              if (e.velocity) break;
91 //                                              if (e.angles) break;
92 //                                              if (e.avelocity) break;
93 //                                              if (e.classname) break;
94 //                                              if (e.model) break;
95 //                                              if (e.frame) break;
96 //                                              if (e.skin) break;
97 //                                              if (e.effects) break;
98 //                                              if (e.mins) break;
99 //                                              if (e.maxs) break;
100 //                                              if (e.size) break;
101 //                                              if (e.touch) break;
102 //                                              if (e.use) break;
103 //                                              if (e.think) break;
104 //                                              if (e.blocked) break;
105 //                                              if (e.nextthink) break;
106 //                                              if (e.chain) break;
107 //                                              if (e.netname) break;
108 //                                              if (e.enemy) break;
109 //                                              if (e.flags) break;
110 //                                              if (e.colormap) break;
111 //                                              if (e.owner) break;
112                                                 flag = false;
113                                         } while (0);
114                                         if (!flag) continue;
115                                 }
116                                 else if (is_pure(e))
117                                 {
118                                         if (autocvar_debugdraw < 2) continue;
119                                         rgb.y = 1;
120                                 }
121                                 vector pos = project_3d_to_2d(e.origin);
122                                 if (pos.z < 0) continue;
123                                 pos.z = 0;
124                                 pos.y += ofs * sz;
125                                 drawcolorcodedstring2(pos,
126                                         sprintf("%d: '%s'@%s", (e.debug ? e.sv_entnum : etof(e)),
127                                         e.classname, e.sourceLoc),
128                                         sz * '1 1 0', rgb, 0.5, DRAWFLAG_NORMAL);
129                                 ++ofs;
130                         }
131                 ));
132         }
133 #endif
134
135 #ifdef SVQC
136         COMMON_COMMAND(debugdraw_sv, "Dump all server entities")
137         {
138                 switch (request)
139                 {
140                         case CMD_REQUEST_COMMAND:
141                         {
142                                 if (!autocvar_debugdraw) return;
143                                 int n = 1000;
144                                 int rem = n;
145                                 for (entity e = NULL; (e = findfloat(e, debug, 0)) && rem > 0; )
146                                 {
147                                         if (autocvar_debugdraw < 2 && is_pure(e)) continue;
148                                         debug_send(e, nextent(NULL), 0);
149                                         e.debug = true;
150                                         --rem;
151                                 }
152                                 LOG_INFOF("%d server entities sent\n", n - rem);
153                                 return;
154                         }
155
156                         default:
157                         case CMD_REQUEST_USAGE:
158                         {
159                                 LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " debugdraw_sv"));
160                                 return;
161                         }
162                 }
163         }
164 #endif
165
166 GENERIC_COMMAND(bufstr_get, "Examine a string buffer object")
167 {
168         switch (request)
169         {
170                 case CMD_REQUEST_COMMAND:
171                 {
172                     int bufhandle = stof(argv(1));
173                     int string_index = stof(argv(2));
174                         string s = bufstr_get(bufhandle, string_index);
175                         LOG_INFOF("%s\n", s);
176                         return;
177                 }
178
179                 default:
180                 case CMD_REQUEST_USAGE:
181                 {
182                         LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " bufstr_get bufhandle string_index"));
183                         return;
184                 }
185         }
186 }
187
188 #endif