Richard Boegli's CnC_Generals_Zero_Hour Fork
WIP
This is documentation of Richard Boegil's Zero Hour Fork
Loading...
Searching...
No Matches
mydebug.h
Go to the documentation of this file.
1
/*
2
** Command & Conquer Generals Zero Hour(tm)
3
** Copyright 2025 Electronic Arts Inc.
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/*****************************************************************************\
20
wdebug Neal Kettler
21
22
MT-LEVEL
23
MT-Safe
24
25
The debugging module is pretty good for debugging and it has some message
26
printing stuff as well. The basic idea is that you write a class that
27
inherits from OutputDevice (several are provided) and assign that output
28
device to a stream. There are seperate streams for debugging, information,
29
warning, and error messages. Each one can have a seperate output device,
30
or they can all have the same one. Debugging messages only get compiled
31
in if your module defines 'DEBUG'. If you don't define debug, then not even
32
the text of the debugging message gets into the binary. All the other
33
output streams get printed regardless of whether DEBUG is defined.
34
35
Sample usage:
36
FileD debug_device("gameres.debug"); // create a file device
37
MsgManager::setDebugStream(&debug_device);
38
DBGMSG("This debug message #" << 1 << " you use C++ streams");
39
40
Note that since these are defines you really don't need to put a semicolon
41
at the end, and it can be bad in situations like this:
42
43
if (x)
44
DBGMSG("Stuff is broken");
45
else
46
DBGMSG("Stuff is NOT broken");
47
48
This won't compile, read the code until you figure it out. Only then
49
will you be ready to leave grasshopper.
50
51
\*****************************************************************************/
52
53
#ifndef MYDEBUG_HEADER
54
#define MYDEBUG_HEADER
55
56
#define USE_SEM
57
58
#include "wstypes.h"
59
60
#ifdef _WINDOWS
61
#include <iostream.h>
62
#include <strstrea.h>
63
#else
64
#include <iostream>
65
#endif
66
67
#ifdef USE_SEM
68
#include "sem4.h"
69
#else
70
#include "critsec.h"
71
#endif
72
#include "odevice.h"
73
#include "streamer.h"
74
#include "xtime.h"
75
#include "timezone.h"
// MDC
76
#include "filed.h"
77
78
// This is needed because the streams return a pointer. Every time you
79
// change the output device the old stream is deleted, and a new one
80
// is created.
81
// MDC: Changed from semaphores to critical sections because Windows doesn't provide
82
// a good way of doing semaphores (I think)
83
// MDC: Never mind, they seem to be working now! I'm leaving it in, though, so anyone can
84
// flip a switch between the two.
85
86
#ifdef USE_SEM
87
extern
Sem4
MyDebugLibSemaphore
;
88
#define MYDEBUGLOCK MyDebugLibSemaphore.Wait()
89
#define MYDEBUGUNLOCK MyDebugLibSemaphore.Post()
90
#else
91
extern
CritSec
MyDebugLibSemaphore
;
92
#define MYDEBUGLOCK MyDebugLibSemaphore.lock()
93
#define MYDEBUGUNLOCK MyDebugLibSemaphore.unlock()
94
#endif
95
96
// Print an information message
97
#define PARANOIDMSG(X)\
98
{\
99
char timebuf[40]; \
100
Xtime now; \
101
now -= TimezoneOffset(); \
102
now.FormatTime(timebuf, "mm/dd/yy hh:mm:ss"); \
103
MYDEBUGLOCK; \
104
if (MyMsgManager::paranoidStream()) \
105
(*(MyMsgManager::paranoidStream())) << "HACK " << timebuf << " [" << \
106
__FILE__ << " " << __LINE__ << "] " << X << endl; \
107
MYDEBUGUNLOCK; \
108
}
109
110
// Just get a stream to the information device, no extra junk
111
#define PARANOIDSTREAM(X)\
112
{\
113
MYDEBUGLOCK; \
114
if (MyMsgManager::paranoidStream()) \
115
(*(MyMsgManager::paranoidStream())) << X;\
116
MYDEBUGUNLOCK; \
117
}
118
119
120
//#undef MYDEBUGLOCK
121
//#undef MYDEBUGUNLOCK
122
123
class
MyMsgManager
124
{
125
protected
:
126
MyMsgManager
();
127
128
public
:
129
static
int
setAllStreams
(
OutputDevice
*device);
130
static
int
setParanoidStream
(
OutputDevice
*device);
131
static
int
ReplaceAllStreams
(
FileD
*
output_device
,
char
*device_filename,
char
*copy_filename);
132
133
static
void
enableParanoid
(
int
flag
);
134
135
static
ostream *
paranoidStream
(
void
);
136
};
137
138
#endif
CritSec
Definition
critsec.h:44
FileD
Definition
filed.h:25
MyMsgManager::enableParanoid
static void enableParanoid(int flag)
MyMsgManager::paranoidStream
static ostream * paranoidStream(void)
Definition
mydebug.cpp:72
MyMsgManager::MyMsgManager
MyMsgManager()
MyMsgManager::setAllStreams
static int setAllStreams(OutputDevice *device)
Definition
mydebug.cpp:39
MyMsgManager::ReplaceAllStreams
static int ReplaceAllStreams(FileD *output_device, char *device_filename, char *copy_filename)
Definition
mydebug.cpp:78
MyMsgManager::setParanoidStream
static int setParanoidStream(OutputDevice *device)
Definition
mydebug.cpp:55
OutputDevice
Definition
odevice.h:25
Sem4
Definition
sem4.h:43
output_device
OutputDevice * output_device
Definition
main.cpp:59
MyDebugLibSemaphore
Sem4 MyDebugLibSemaphore
Definition
mydebug.cpp:33
flag
unsigned char flag
Definition
vchannel.cpp:273
Code
Tools
matchbot
mydebug.h
Generated by
1.13.2