Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Core/Console.cpp

Diff revisions: vs.
  @@ -6,6 +6,8 @@
6 6 #include <iomanip>
7 7 #include <stdarg.h>
8 8
9 + #define CONSOLE_OUTPUT_BUFFER_SIZE 2048
10 +
9 11 //! Do not remove the following license without express permission granted bu DIVIDE-Studio
10 12 void Console::printCopyrightNotice() const {
11 13 std::cout << "------------------------------------------------------------------------------" << std::endl;
  @@ -37,152 +39,109 @@
37 39 #ifdef _DEBUG
38 40 void Console::d_printfn(const char* format, ...) const {
39 41 va_list args;
40 - std::string fmt_text;
42 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
41 43 va_start(args, format);
42 - I32 len = _vscprintf(format, args) + 1;
43 - char *text = new char[len];
44 - vsprintf_s(text, len, format, args);
45 - fmt_text.append(text);
46 - fmt_text.append("\n");
47 - delete[] text;
48 - text = NULL;
44 + assert(_vscprintf(format, args) - 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
45 + vsprintf_s(text, sizeof(text), format, args);
46 + strcat(text, "\n");
49 47 va_end(args);
50 - output(fmt_text);
51 - fmt_text.empty();
48 + output(text);
52 49 }
53 50
54 51 void Console::d_printf(const char* format, ...) const {
55 52 va_list args;
56 - std::string fmt_text;
53 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
57 54 va_start(args, format);
58 - I32 len = _vscprintf(format, args) + 1;
59 - char *text = new char[len];
60 - vsprintf_s(text, len, format, args);
61 - fmt_text.append(text);
62 - delete[] text;
63 - text = NULL;
55 + assert(_vscprintf(format, args) + 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
56 + vsprintf_s(text, sizeof(text), format, args);
64 57 va_end(args);
65 - output(fmt_text);
66 - fmt_text.empty();
58 + output(text);
67 59 }
68 - #endif
69 60
70 - void Console::printfn(const char* format, ...) const {
61 + void Console::d_errorfn(const char* format, ...) const {
71 62 va_list args;
72 - std::string fmt_text;
63 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
73 64 va_start(args, format);
74 - I32 len = _vscprintf(format, args) + 1;
75 - char *text = new char[len];
76 - vsprintf_s(text, len, format, args);
77 - fmt_text.append(text);
78 - fmt_text.append("\n");
79 - delete[] text;
80 - text = NULL;
65 + assert(_vscprintf(format, args) + 3 < CONSOLE_OUTPUT_BUFFER_SIZE);
66 + vsprintf_s(text, sizeof(text), format, args);
67 + strcat(text, "\n");
81 68 va_end(args);
82 - output(fmt_text);
83 - fmt_text.empty();
69 + output(text,true);
84 70 }
85 71
86 - void Console::printf(const char* format, ...) const {
72 + void Console::d_errorf(const char* format, ...) const {
87 73 va_list args;
88 - std::string fmt_text;
74 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
89 75 va_start(args, format);
90 - I32 len = _vscprintf(format, args) + 1;
91 - char *text = new char[len];
92 - vsprintf_s(text, len, format, args);
93 - fmt_text.append(text);
94 - delete[] text;
95 - text = NULL;
76 + assert(_vscprintf(format, args) + 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
77 + vsprintf_s(text, sizeof(text), format, args);
96 78 va_end(args);
97 - output(fmt_text);
98 - fmt_text.empty();
79 + output(text,true);
99 80 }
100 81
101 - #ifdef _DEBUG
102 -
103 - void Console::d_errorfn(const char* format, ...) const {
82 + #endif
83 + void Console::printfn(const char* format, ...) const {
104 84 va_list args;
105 - std::string fmt_text;
85 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
106 86 va_start(args, format);
107 - I32 len = _vscprintf(format, args) + 1;
108 - char *text = new char[len];
109 - vsprintf_s(text, len, format, args);
110 - fmt_text.append("Error: ");
111 - fmt_text.append(text);
112 - fmt_text.append("\n");
113 - delete[] text;
114 - text = NULL;
87 + assert(_vscprintf(format, args) + 3 < CONSOLE_OUTPUT_BUFFER_SIZE);
88 + vsprintf_s(text, sizeof(text), format, args);
89 + strcat(text, "\n");
115 90 va_end(args);
116 - output(fmt_text,true);
117 - fmt_text.empty();
91 + output(text);
118 92 }
119 93
120 - void Console::d_errorf(const char* format, ...) const {
94 + void Console::printf(const char* format, ...) const {
121 95 va_list args;
122 - std::string fmt_text;
96 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
123 97 va_start(args, format);
124 - I32 len = _vscprintf(format, args) + 1;
125 - char *text = new char[len];
126 - vsprintf_s(text, len, format, args);
127 - fmt_text.append("Error: ");
128 - fmt_text.append(text);
129 - delete[] text;
130 - text = NULL;
98 + assert(_vscprintf(format, args) + 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
99 + vsprintf_s(text, sizeof(text), format, args);
131 100 va_end(args);
132 - output(fmt_text,true);
133 - fmt_text.empty();
101 + output(text);
134 102 }
135 - #endif
136 103
137 104 void Console::errorfn(const char* format, ...) const {
138 105 va_list args;
139 - std::string fmt_text;
106 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
140 107 va_start(args, format);
141 - I32 len = _vscprintf(format, args) + 1;
142 - char *text = new char[len];
143 - vsprintf_s(text, len, format, args);
144 - fmt_text.append("Error: ");
145 - fmt_text.append(text);
146 - fmt_text.append("\n");
147 - delete[] text;
148 - text = NULL;
108 + assert(_vscprintf(format, args) + 3 < CONSOLE_OUTPUT_BUFFER_SIZE);
109 + vsprintf_s(text, sizeof(text), format, args);
110 + strcat(text, "\n");
149 111 va_end(args);
150 - output(fmt_text,true);
151 - fmt_text.empty();
112 + output(text,true);
152 113 }
153 114
154 115 void Console::errorf(const char* format, ...) const {
155 116 va_list args;
156 - std::string fmt_text;
117 + char text[CONSOLE_OUTPUT_BUFFER_SIZE] = {};
157 118 va_start(args, format);
158 - I32 len = _vscprintf(format, args) + 1;
159 - char *text = new char[len];
160 - vsprintf_s(text, len, format, args);
161 - fmt_text.append("Error: ");
162 - fmt_text.append(text);
163 - delete[] text;
164 - text = NULL;
165 - va_end(args);
166 - output(fmt_text,true);
167 - fmt_text.empty();
168 - }
169 -
170 - void Console::output(const std::string& output,const bool error) const {
171 - boost::mutex::scoped_lock lock(io_mutex);
172 - if(_timestamps){
173 - if(error){
174 - std::cerr << "[ " << std::setprecision(4) << GETTIME() << " ] " << output << std::flush;
175 - }else{
176 - std::cout << "[ " << std::setprecision(4) << GETTIME() << " ] " << output << std::flush;
177 - }
178 - }else{
119 + assert(_vscprintf(format, args) + 1 < CONSOLE_OUTPUT_BUFFER_SIZE);
120 + vsprintf_s(text, sizeof(text), format, args);
121 + va_end(args);
122 + output(text,true);
123 + }
124 +
125 + void Console::output(const char* output, const bool error) const {
126 + if(!_guiConsoleCallback.empty()){
179 127 if(error){
180 - std::cerr << output << std::flush;
128 + std::string outputString("Error: ");
129 + outputString.append(output);
130 + _guiConsoleCallback(outputString.c_str(),error);
181 131 }else{
182 - std::cout << output << std::flush;
132 + _guiConsoleCallback(output,error);
183 133 }
184 134 }
185 - if(!_guiConsoleCallback.empty()){
186 - _guiConsoleCallback(output,error);
187 - }
135 +
136 + boost::mutex::scoped_lock lock(io_mutex);
137 +
138 + std::ostream& outputStream = error ? std::cerr : std::cout;
139 +
140 + if(_timestamps)
141 + outputStream << "[ " << std::setprecision(4) << GETTIME() << " ] ";
142 +
143 + if(error)
144 + outputStream << " Error: ";
145 +
146 + outputStream << output << std::flush;
188 147 }