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