author | celestar |
Mon, 19 Mar 2007 12:38:16 +0000 | |
branch | gamebalance |
changeset 9895 | 7bd07f43b0e3 |
parent 9881 | fbb3eab0e186 |
child 9912 | 1ac8aac92385 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6192
diff
changeset
|
3 |
/** @file debug.h */ |
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6192
diff
changeset
|
4 |
|
1299 | 5 |
#ifndef DEBUG_H |
6 |
#define DEBUG_H |
|
7 |
||
9881
fbb3eab0e186
(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists.
celestar
parents:
6505
diff
changeset
|
8 |
#include "stdafx.h" // We need this for CDECL |
fbb3eab0e186
(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists.
celestar
parents:
6505
diff
changeset
|
9 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
10 |
/* Debugging messages policy: |
75f13d7bfaed
(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 |
75f13d7bfaed
(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 |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
13 |
* debugging is needed. |
75f13d7bfaed
(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): |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
15 |
* 0 - errors or severe warnings |
75f13d7bfaed
(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 |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
17 |
* 2 - crude progress indicator of functionality |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
18 |
* 3 - important debugging messages (function entry) |
75f13d7bfaed
(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.) |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
20 |
* 5 - detailed debugging information |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
21 |
* 6.. - extremely detailed spamming |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
22 |
*/ |
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
23 |
|
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
24 |
/* Of course MSVC 2003 and lower has no support for variadic macros |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
25 |
* so we need to work around this... *sigh* */ |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
26 |
#if defined(_MSC_VER) && (_MSC_VER < 1400) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
27 |
#define NO_VARARG_MACRO |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
28 |
#endif |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
29 |
|
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
30 |
#if defined(NO_VARARG_MACRO) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
31 |
enum DebugLevelType { |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
32 |
ai, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
33 |
driver, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
34 |
grf, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
35 |
map, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
36 |
misc, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
37 |
ms, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
38 |
net, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
39 |
sprite, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
40 |
oldloader, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
41 |
ntp, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
42 |
npf, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
43 |
yapf, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
44 |
freetype, |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
45 |
sl, |
5915 | 46 |
station, |
9881
fbb3eab0e186
(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists.
celestar
parents:
6505
diff
changeset
|
47 |
eco, |
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
48 |
}; |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
49 |
#endif /* NO_VARARG_MACRO */ |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
50 |
|
1299 | 51 |
#ifdef NO_DEBUG_MESSAGES |
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
52 |
#if defined(NO_VARARG_MACRO) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
53 |
static inline void DEBUG(int name, int level, ...) {} |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
54 |
#elif defined(__GNUC__) && (__GNUC__ < 3) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
55 |
#define DEBUG(name, level, args...) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
56 |
#else |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
57 |
#define DEBUG(name, level, ...) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
58 |
#endif |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
59 |
#else /* NO_DEBUG_MESSAGES */ |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
60 |
#if defined(NO_VARARG_MACRO) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
61 |
void CDECL DEBUG(int name, int level, ...); |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
62 |
#elif defined(__GNUC__) && (__GNUC__ < 3) |
5578
595d940beb8f
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5573
diff
changeset
|
63 |
#define DEBUG(name, level, args...) if ((level == 0) || ( _debug_ ## name ## _level >= level)) debug(#name, args) |
595d940beb8f
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5573
diff
changeset
|
64 |
#else |
595d940beb8f
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5573
diff
changeset
|
65 |
#define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__) |
595d940beb8f
(svn r7579) -Fix: upon merging the bridge branch, I accidently reverted 7571. Re-revert it. Sorry.
celestar
parents:
5573
diff
changeset
|
66 |
#endif |
1299 | 67 |
|
68 |
extern int _debug_ai_level; |
|
2210
58a293892a66
(svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents:
2186
diff
changeset
|
69 |
extern int _debug_driver_level; |
1299 | 70 |
extern int _debug_grf_level; |
71 |
extern int _debug_map_level; |
|
72 |
extern int _debug_misc_level; |
|
73 |
extern int _debug_ms_level; |
|
74 |
extern int _debug_net_level; |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
75 |
extern int _debug_sprite_level; |
1322
8697b73baa64
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1299
diff
changeset
|
76 |
extern int _debug_oldloader_level; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2033
diff
changeset
|
77 |
extern int _debug_ntp_level; |
1678
838dd6f46081
(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
|
78 |
extern int _debug_npf_level; |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3851
diff
changeset
|
79 |
extern int _debug_yapf_level; |
5108
dc67d70b5a45
(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
|
80 |
extern int _debug_freetype_level; |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
81 |
extern int _debug_sl_level; |
5915 | 82 |
extern int _debug_station_level; |
9881
fbb3eab0e186
(svn r9114) [gamebalance] -Add: Added the new economy, with the ability to adjust growth in the difficulty window. The economy doesn't do anything yet, it just exists.
celestar
parents:
6505
diff
changeset
|
83 |
extern int _debug_eco_level; |
1299 | 84 |
|
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
85 |
#if !defined(NO_VARARG_MACRO) |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
86 |
void CDECL debug(const char *dbg, ...); |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
87 |
#endif /* NO_VARARG_MACRO */ |
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
88 |
#endif /* NO_DEBUG_MESSAGES */ |
1299 | 89 |
|
90 |
void SetDebugString(const char *s); |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
9881
diff
changeset
|
91 |
const char *GetDebugString(); |
1299 | 92 |
|
3851
4bbb525957b0
(svn r4875) - Fix: %ll don't work with mingw (msvrct.dll problem)
glx
parents:
3341
diff
changeset
|
93 |
/* MSVCRT of course has to have a different syntax for long long *sigh* */ |
4bbb525957b0
(svn r4875) - Fix: %ll don't work with mingw (msvrct.dll problem)
glx
parents:
3341
diff
changeset
|
94 |
#if defined(_MSC_VER) || defined(__MINGW32__) |
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
95 |
#define OTTD_PRINTF64 "I64" |
3341
b8febc9509d7
(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 |
#else |
5657
54c99d0f6ba4
(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents:
5578
diff
changeset
|
97 |
#define OTTD_PRINTF64 "ll" |
3341
b8febc9509d7
(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 |
#endif |
b8febc9509d7
(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 |
|
6505
abcb0580d976
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6192
diff
changeset
|
100 |
/* Used for profiling */ |
3341
b8febc9509d7
(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 |
#define TIC() {\ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
9881
diff
changeset
|
102 |
extern uint64 _rdtsc();\ |
3341
b8febc9509d7
(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 |
uint64 _xxx_ = _rdtsc();\ |
b8febc9509d7
(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 |
static uint64 __sum__ = 0;\ |
b8febc9509d7
(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 |
static uint32 __i__ = 0; |
b8febc9509d7
(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 |
|
b8febc9509d7
(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 |
#define TOC(str, count)\ |
b8febc9509d7
(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
|
108 |
__sum__ += _rdtsc() - _xxx_;\ |
b8febc9509d7
(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 |
if (++__i__ == count) {\ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5108
diff
changeset
|
110 |
DEBUG(misc, 0, "[%s] %" OTTD_PRINTF64 "u [avg: %.1f]\n", str, __sum__, __sum__/(double)__i__);\ |
3341
b8febc9509d7
(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 |
__i__ = 0;\ |
b8febc9509d7
(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 |
__sum__ = 0;\ |
b8febc9509d7
(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 |
}\ |
b8febc9509d7
(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
|
114 |
} |
b8febc9509d7
(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
|
115 |
|
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2210
diff
changeset
|
116 |
#endif /* DEBUG_H */ |