/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/ZZLog.cpp
ViewVC logotype

Annotation of /trunk/plugins/zzogl-pg/opengl/ZZLog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (hide annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 6 months ago) by william
File size: 6028 byte(s)
re-commit (had local access denied errors when committing)
1 william 62 /* ZZ Open GL graphics plugin
2     * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3     * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
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 2 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, write to the Free Software
17     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18     */
19    
20     #include <stdio.h>
21     #include "ZZLog.h"
22 william 280 #include <list>
23     #include <cstring>
24 william 62
25     extern GSconf conf;
26    
27 william 280 using namespace std;
28    
29     static list<MESSAGE> listMsgs;
30    
31     void ProcessMessages()
32     {
33     FUNCLOG
34    
35     if (listMsgs.size() > 0)
36     {
37     int left = 25, top = 15;
38     list<MESSAGE>::iterator it = listMsgs.begin();
39    
40     while (it != listMsgs.end())
41     {
42     DrawText(it->str, left + 1, top + 1, 0xff000000);
43     DrawText(it->str, left, top, 0xffffff30);
44     top += 15;
45    
46     if ((int)(it->dwTimeStamp - timeGetTime()) < 0)
47     it = listMsgs.erase(it);
48     else ++it;
49     }
50     }
51     }
52    
53     void ZZAddMessage(const char* pstr, u32 ms)
54     {
55     FUNCLOG
56     listMsgs.push_back(MESSAGE(pstr, timeGetTime() + ms));
57     ZZLog::Log("%s\n", pstr);
58     }
59    
60 william 62 namespace ZZLog
61     {
62     std::string s_strLogPath("logs/");
63     FILE *gsLog;
64    
65     bool IsLogging()
66     {
67     // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
68     // (GSinit won't have been called then)
69     return (gsLog != NULL && conf.log);
70     }
71    
72 william 191 void Open()
73 william 62 {
74     const std::string LogFile(s_strLogPath + "GSzzogl.log");
75    
76     gsLog = fopen(LogFile.c_str(), "w");
77     if (gsLog != NULL)
78     setvbuf(gsLog, NULL, _IONBF, 0);
79     else
80     SysMessage("Can't create log file %s\n", LogFile.c_str());
81    
82     }
83    
84     void Close()
85     {
86     if (gsLog != NULL) {
87     fclose(gsLog);
88     gsLog = NULL;
89     }
90     }
91    
92     void SetDir(const char* dir)
93     {
94     // Get the path to the log directory.
95     s_strLogPath = (dir==NULL) ? "logs/" : dir;
96    
97 william 191 // Reload previously open log file
98     if (gsLog) {
99     Close();
100     Open();
101     }
102 william 62 }
103    
104     void WriteToScreen(const char* pstr, u32 ms)
105     {
106 william 280 ZZAddMessage(pstr, ms);
107 william 62 }
108    
109 william 280 void WriteToScreen2(const char* fmt, ...)
110     {
111     va_list list;
112     char tmp[512];
113    
114     va_start(list, fmt);
115     vsprintf(tmp, fmt, list);
116     va_end(list);
117    
118     ZZAddMessage(tmp, 5000);
119     }
120    
121 william 62 void _Message(const char *str)
122     {
123     SysMessage(str);
124     }
125    
126     void _Log(const char *str)
127     {
128     if (IsLogging()) fprintf(gsLog, str);
129     }
130    
131     void _WriteToConsole(const char *str)
132     {
133     fprintf(stderr,"ZZogl-PG: %s", str);
134     }
135    
136     void _Print(const char *str)
137     {
138     fprintf(stderr,"ZZogl-PG: %s", str);
139    
140     if (IsLogging()) fprintf(gsLog, str);
141     }
142    
143     void Message(const char *fmt, ...)
144     {
145     va_list list;
146     char tmp[512];
147    
148     va_start(list, fmt);
149     vsprintf(tmp, fmt, list);
150     va_end(list);
151    
152     SysMessage(tmp);
153     }
154    
155     void Log(const char *fmt, ...)
156     {
157     va_list list;
158    
159     va_start(list, fmt);
160    
161     if (IsLogging()) vfprintf(gsLog, fmt, list);
162    
163     va_end(list);
164     }
165    
166     void WriteToConsole(const char *fmt, ...)
167     {
168     va_list list;
169    
170     va_start(list, fmt);
171    
172     fprintf(stderr, "ZZogl-PG: ");
173     vfprintf(stderr, fmt, list);
174     va_end(list);
175     }
176    
177     void Print(const char *fmt, ...)
178     {
179     va_list list;
180    
181     va_start(list, fmt);
182    
183     if (IsLogging()) vfprintf(gsLog, fmt, list);
184    
185     fprintf(stderr, "ZZogl-PG: ");
186     vfprintf(stderr, fmt, list);
187    
188     va_end(list);
189     }
190    
191    
192     void WriteLn(const char *fmt, ...)
193     {
194     va_list list;
195    
196     va_start(list, fmt);
197    
198     if (IsLogging()) vfprintf(gsLog, fmt, list);
199    
200     fprintf(stderr, "ZZogl-PG: ");
201     vfprintf(stderr, fmt, list);
202     va_end(list);
203     fprintf(stderr,"\n");
204     }
205    
206     void Greg_Log(const char *fmt, ...)
207     {
208     #if defined(WRITE_GREG_LOGS)
209     va_list list;
210     char tmp[512];
211    
212     va_start(list, fmt);
213    
214 william 191 if (IsLogging()) {
215     fprintf(gsLog, "GRegs: ");
216     vfprintf(gsLog, fmt, list);
217     }
218 william 62 //fprintf(stderr,"GRegs: ");
219     //vfprintf(stderr, fmt, list);
220    
221     va_end(list);
222    
223     if (IsLogging()) fprintf(gsLog, "\n");
224     //fprintf(stderr,"\n");
225     #endif
226     }
227    
228     void Prim_Log(const char *fmt, ...)
229     {
230     #if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
231     va_list list;
232     char tmp[512];
233    
234     va_start(list, fmt);
235    
236     if (conf.log /*& 0x00000010*/)
237     {
238     if (IsLogging()) vfprintf(gsLog, fmt, list);
239    
240     fprintf(stderr, "ZZogl-PG(PRIM): ");
241     vfprintf(stderr, fmt, list);
242    
243     vprintf(fmt, list);
244     }
245    
246     va_end(list);
247     fprintf(stderr,"\n");
248    
249     #endif
250     }
251    
252     void GS_Log(const char *fmt, ...)
253     {
254     #ifdef ZEROGS_DEVBUILD
255     va_list list;
256    
257     va_start(list, fmt);
258    
259     if (IsLogging())
260     {
261     vfprintf(gsLog, fmt, list);
262     fprintf(gsLog, "\n");
263     }
264    
265     fprintf(stderr, "ZZogl-PG: ");
266     vfprintf(stderr, fmt, list);
267     fprintf(stderr, "\n");
268    
269     va_end(list);
270     #endif
271     }
272    
273     void Warn_Log(const char *fmt, ...)
274     {
275     #ifdef ZEROGS_DEVBUILD
276     va_list list;
277    
278     va_start(list, fmt);
279    
280     if (IsLogging())
281     {
282     vfprintf(gsLog, fmt, list);
283     fprintf(gsLog, "\n");
284     }
285    
286     fprintf(stderr, "ZZogl-PG: ");
287     vfprintf(stderr, fmt, list);
288     fprintf(stderr, "\n");
289    
290     va_end(list);
291     #endif
292     }
293    
294 william 273 void Dev_Log(const char *fmt, ...)
295     {
296     #ifdef ZEROGS_DEVBUILD
297     va_list list;
298    
299     va_start(list, fmt);
300    
301     if (IsLogging())
302     {
303     vfprintf(gsLog, fmt, list);
304     fprintf(gsLog, "\n");
305     }
306    
307     fprintf(stderr, "ZZogl-PG: ");
308     vfprintf(stderr, fmt, list);
309     fprintf(stderr, "\n");
310    
311     va_end(list);
312     #endif
313     }
314    
315 william 62 void Debug_Log(const char *fmt, ...)
316     {
317 william 280 #ifdef _DEBUG
318 william 62 va_list list;
319    
320     va_start(list, fmt);
321    
322     if (IsLogging())
323     {
324     vfprintf(gsLog, fmt, list);
325     fprintf(gsLog, "\n");
326     }
327    
328     fprintf(stderr, "ZZogl-PG: ");
329     vfprintf(stderr, fmt, list);
330     fprintf(stderr, "\n");
331    
332     va_end(list);
333     #endif
334     }
335    
336     void Error_Log(const char *fmt, ...)
337     {
338     va_list list;
339    
340     va_start(list, fmt);
341    
342     if (IsLogging())
343     {
344     vfprintf(gsLog, fmt, list);
345     fprintf(gsLog, "\n");
346     }
347    
348     fprintf(stderr, "ZZogl-PG: ");
349     vfprintf(stderr, fmt, list);
350     fprintf(stderr, "\n");
351    
352     va_end(list);
353     }
354     };

  ViewVC Help
Powered by ViewVC 1.1.22