Extend object variable 0x60 to also return the view
[openttd/fttd.git] / src / debug.h
blobab818225c00dd3c855751dcec5d57cdee3dfd78b
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file debug.h Functions related to debugging. */
12 #ifndef DEBUG_H
13 #define DEBUG_H
15 #include "cpu.h"
17 /* Debugging messages policy:
18 * These should be the severities used for direct DEBUG() calls
19 * maximum debugging level should be 10 if really deep, deep
20 * debugging is needed.
21 * (there is room for exceptions, but you have to have a good cause):
22 * 0 - errors or severe warnings
23 * 1 - other non-fatal, non-severe warnings
24 * 2 - crude progress indicator of functionality
25 * 3 - important debugging messages (function entry)
26 * 4 - debugging messages (crude loop status, etc.)
27 * 5 - detailed debugging information
28 * 6.. - extremely detailed spamming
31 #ifdef NO_DEBUG_MESSAGES
32 #define DEBUG(name, level, ...) { }
33 #else /* NO_DEBUG_MESSAGES */
34 /**
35 * Output a line of debugging information.
36 * @param name Category
37 * @param level Debugging level, higher levels means more detailed information.
39 #define DEBUG(name, level, ...) if ((level) == 0 || _debug_ ## name ## _level >= (level)) debug(#name, __VA_ARGS__)
41 extern int _debug_driver_level;
42 extern int _debug_grf_level;
43 extern int _debug_map_level;
44 extern int _debug_misc_level;
45 extern int _debug_net_level;
46 extern int _debug_sprite_level;
47 extern int _debug_oldloader_level;
48 extern int _debug_yapf_level;
49 extern int _debug_freetype_level;
50 extern int _debug_script_level;
51 extern int _debug_sl_level;
52 extern int _debug_gamelog_level;
53 extern int _debug_desync_level;
54 extern int _debug_console_level;
55 #ifdef RANDOM_DEBUG
56 extern int _debug_random_level;
57 #endif
59 void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
60 #endif /* NO_DEBUG_MESSAGES */
62 char *DumpDebugFacilityNames(char *buf, char *last);
63 void SetDebugString(const char *s);
64 const char *GetDebugString();
66 /* Shorter form for passing filename and linenumber */
67 #define FILE_LINE __FILE__, __LINE__
69 /* Used for profiling
71 * Usage:
72 * TIC();
73 * --Do your code--
74 * TOC("A name", 1);
76 * When you run the TIC() / TOC() multiple times, you can increase the '1'
77 * to only display average stats every N values. Some things to know:
79 * for (int i = 0; i < 5; i++) {
80 * TIC();
81 * --Do your code--
82 * TOC("A name", 5);
83 * }
85 * Is the correct usage for multiple TIC() / TOC() calls.
87 * TIC() / TOC() creates its own block, so make sure not the mangle
88 * it with another block.
89 **/
90 #define TIC() {\
91 uint64 _xxx_ = ottd_rdtsc();\
92 static uint64 __sum__ = 0;\
93 static uint32 __i__ = 0;
95 #define TOC(str, count)\
96 __sum__ += ottd_rdtsc() - _xxx_;\
97 if (++__i__ == count) {\
98 DEBUG(misc, 0, "[%s] " OTTD_PRINTF64 " [avg: %.1f]", str, __sum__, __sum__/(double)__i__);\
99 __i__ = 0;\
100 __sum__ = 0;\
104 void ShowInfo(const char *str);
105 void CDECL ShowInfoF(const char *str, ...) WARN_FORMAT(1, 2);
107 const char *GetLogPrefix();
109 /** The real time in the game. */
110 extern uint32 _realtime_tick;
112 #endif /* DEBUG_H */