author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5664 | 846a93238ca1 |
child 5941 | adaea39e84ab |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1299 | 3 |
#ifndef DEBUG_H |
4 |
#define DEBUG_H |
|
5 |
||
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
6 |
#ifdef __cplusplus |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
7 |
extern "C" { |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
8 |
#endif //__cplusplus |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
9 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
10 |
/* Debugging messages policy: |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
11 |
* These should be the severities used for direct DEBUG() calls |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
12 |
* maximum debugging level should be 10 if really deep, deep |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
13 |
* debugging is needed. |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
14 |
* (there is room for exceptions, but you have to have a good cause): |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
15 |
* 0 - errors or severe warnings |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
16 |
* 1 - other non-fatal, non-severe warnings |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
17 |
* 2 - crude progress indicator of functionality |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
18 |
* 3 - important debugging messages (function entry) |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
19 |
* 4 - debugging messages (crude loop status, etc.) |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
20 |
* 5 - detailed debugging information |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
21 |
* 6.. - extremely detailed spamming |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
22 |
*/ |
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
23 |
|
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
24 |
/* Of course MSVC 2003 and lower has no support for variadic macros |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
25 |
* so we need to work around this... *sigh* */ |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
26 |
#if defined(_MSC_VER) && (_MSC_VER < 1400) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
27 |
#define NO_VARARG_MACRO |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
28 |
#endif |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
29 |
|
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
30 |
#if defined(NO_VARARG_MACRO) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
31 |
enum DebugLevelType { |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
32 |
ai, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
33 |
driver, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
34 |
grf, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
35 |
map, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
36 |
misc, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
37 |
ms, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
38 |
net, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
39 |
sprite, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
40 |
oldloader, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
41 |
ntp, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
42 |
npf, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
43 |
yapf, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
44 |
freetype, |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
45 |
sl, |
5664 | 46 |
station, |
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
47 |
}; |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
48 |
#endif /* NO_VARARG_MACRO */ |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
49 |
|
1299 | 50 |
#ifdef NO_DEBUG_MESSAGES |
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
51 |
#if defined(NO_VARARG_MACRO) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
52 |
static inline void DEBUG(int name, int level, ...) {} |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
53 |
#elif defined(__GNUC__) && (__GNUC__ < 3) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
54 |
#define DEBUG(name, level, args...) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
55 |
#else |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
56 |
#define DEBUG(name, level, ...) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
57 |
#endif |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
58 |
#else /* NO_DEBUG_MESSAGES */ |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
59 |
#if defined(NO_VARARG_MACRO) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
60 |
void CDECL DEBUG(int name, int level, ...); |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
61 |
#elif defined(__GNUC__) && (__GNUC__ < 3) |
5390
b51df40d72a1
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5385
diff
changeset
|
62 |
#define DEBUG(name, level, args...) if ((level == 0) || ( _debug_ ## name ## _level >= level)) debug(#name, args) |
b51df40d72a1
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5385
diff
changeset
|
63 |
#else |
b51df40d72a1
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5385
diff
changeset
|
64 |
#define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__) |
b51df40d72a1
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5385
diff
changeset
|
65 |
#endif |
1299 | 66 |
|
67 |
extern int _debug_ai_level; |
|
2210
b76184e0929c
(svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents:
2186
diff
changeset
|
68 |
extern int _debug_driver_level; |
1299 | 69 |
extern int _debug_grf_level; |
70 |
extern int _debug_map_level; |
|
71 |
extern int _debug_misc_level; |
|
72 |
extern int _debug_ms_level; |
|
73 |
extern int _debug_net_level; |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
74 |
extern int _debug_sprite_level; |
1322
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1299
diff
changeset
|
75 |
extern int _debug_oldloader_level; |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2033
diff
changeset
|
76 |
extern int _debug_ntp_level; |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1322
diff
changeset
|
77 |
extern int _debug_npf_level; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3851
diff
changeset
|
78 |
extern int _debug_yapf_level; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
3900
diff
changeset
|
79 |
extern int _debug_freetype_level; |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
80 |
extern int _debug_sl_level; |
5664 | 81 |
extern int _debug_station_level; |
1299 | 82 |
|
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
83 |
#if !defined(NO_VARARG_MACRO) |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
84 |
void CDECL debug(const char *dbg, ...); |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
85 |
#endif /* NO_VARARG_MACRO */ |
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
86 |
#endif /* NO_DEBUG_MESSAGES */ |
1299 | 87 |
|
88 |
void SetDebugString(const char *s); |
|
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
89 |
const char *GetDebugString(void); |
1299 | 90 |
|
3851
9ad2f4ec0ac3
(svn r4875) - Fix: %ll don't work with mingw (msvrct.dll problem)
glx
parents:
3341
diff
changeset
|
91 |
/* MSVCRT of course has to have a different syntax for long long *sigh* */ |
9ad2f4ec0ac3
(svn r4875) - Fix: %ll don't work with mingw (msvrct.dll problem)
glx
parents:
3341
diff
changeset
|
92 |
#if defined(_MSC_VER) || defined(__MINGW32__) |
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
93 |
#define OTTD_PRINTF64 "I64" |
3341
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
94 |
#else |
5406
2df85542fee4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5390
diff
changeset
|
95 |
#define OTTD_PRINTF64 "ll" |
3341
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
96 |
#endif |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
97 |
|
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
98 |
// Used for profiling |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
99 |
#define TIC() {\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
100 |
extern uint64 _rdtsc(void);\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
101 |
uint64 _xxx_ = _rdtsc();\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
102 |
static uint64 __sum__ = 0;\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
103 |
static uint32 __i__ = 0; |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
104 |
|
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
105 |
#define TOC(str, count)\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
106 |
__sum__ += _rdtsc() - _xxx_;\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
107 |
if (++__i__ == count) {\ |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
108 |
DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\ |
3341
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
109 |
__i__ = 0;\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
110 |
__sum__ = 0;\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
111 |
}\ |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
112 |
} |
b20541ef8945
(svn r4125) - Feature: Add a general TIC() TOC() mechanism using rdtsc or something similar on non-i386 architectures to performance-tune (critical) code. Some systems are probably missing, but those can be added later.
Darkvater
parents:
2916
diff
changeset
|
113 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
114 |
#ifdef __cplusplus |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
115 |
} |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
116 |
#endif //__cplusplus |
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5475
diff
changeset
|
117 |
|
2436
7d5df545bd5d
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2210
diff
changeset
|
118 |
#endif /* DEBUG_H */ |