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/*****************************************************************************\
20wdebug Neal Kettler
21
22MT-LEVEL
23 MT-Safe
24
25The debugging module is pretty good for debugging and it has some message
26printing stuff as well. The basic idea is that you write a class that
27inherits from OutputDevice (several are provided) and assign that output
28device to a stream. There are seperate streams for debugging, information,
29warning, and error messages. Each one can have a seperate output device,
30or they can all have the same one. Debugging messages only get compiled
31in if your module defines 'DEBUG'. If you don't define debug, then not even
32the text of the debugging message gets into the binary. All the other
33output streams get printed regardless of whether DEBUG is defined.
34
35Sample usage:
36FileD debug_device("gameres.debug"); // create a file device
37MsgManager::setDebugStream(&debug_device);
38DBGMSG("This debug message #" << 1 << " you use C++ streams");
39
40Note that since these are defines you really don't need to put a semicolon
41at the end, and it can be bad in situations like this:
42
43if (x)
44 DBGMSG("Stuff is broken");
45else
46 DBGMSG("Stuff is NOT broken");
47
48This won't compile, read the code until you figure it out. Only then
49will 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
88#define MYDEBUGLOCK MyDebugLibSemaphore.Wait()
89#define MYDEBUGUNLOCK MyDebugLibSemaphore.Post()
90#else
92#define MYDEBUGLOCK MyDebugLibSemaphore.lock()
93#define MYDEBUGUNLOCK MyDebugLibSemaphore.unlock()
94#endif
95
96// Print an information message
97#define PARANOIDMSG(X)\
98{\
99char timebuf[40]; \
100Xtime now; \
101now -= TimezoneOffset(); \
102now.FormatTime(timebuf, "mm/dd/yy hh:mm:ss"); \
103MYDEBUGLOCK; \
104if (MyMsgManager::paranoidStream()) \
105(*(MyMsgManager::paranoidStream())) << "HACK " << timebuf << " [" << \
106__FILE__ << " " << __LINE__ << "] " << X << endl; \
107MYDEBUGUNLOCK; \
108}
109
110// Just get a stream to the information device, no extra junk
111#define PARANOIDSTREAM(X)\
112{\
113MYDEBUGLOCK; \
114if (MyMsgManager::paranoidStream()) \
115(*(MyMsgManager::paranoidStream())) << X;\
116MYDEBUGUNLOCK; \
117}
118
119
120//#undef MYDEBUGLOCK
121//#undef MYDEBUGUNLOCK
122
124{
125protected:
127
128public:
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
Definition filed.h:25
static void enableParanoid(int flag)
static ostream * paranoidStream(void)
Definition mydebug.cpp:72
static int setAllStreams(OutputDevice *device)
Definition mydebug.cpp:39
static int ReplaceAllStreams(FileD *output_device, char *device_filename, char *copy_filename)
Definition mydebug.cpp:78
static int setParanoidStream(OutputDevice *device)
Definition mydebug.cpp:55
Definition sem4.h:43
OutputDevice * output_device
Definition main.cpp:59
Sem4 MyDebugLibSemaphore
Definition mydebug.cpp:33
unsigned char flag
Definition vchannel.cpp:273