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