Merge lp:~widelands-dev/widelands/remove-record into lp:widelands
- remove-record
- Merge into trunk
Proposed by
Hans Joachim Desserud
Status: | Merged |
---|---|
Merged at revision: | 6871 |
Proposed branch: | lp:~widelands-dev/widelands/remove-record |
Merge into: | lp:widelands |
Diff against target: |
1174 lines (+42/-985) 7 files modified
src/helper.h (+0/-16) src/journal.cc (+0/-484) src/journal.h (+0/-137) src/journal_exceptions.cc (+0/-59) src/journal_exceptions.h (+0/-90) src/wlapplication.cc (+41/-195) src/wlapplication.h (+1/-4) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/remove-record |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Hans Joachim Desserud | Approve | ||
SirVer | Approve | ||
Review via email: mp+210496@code.launchpad.net |
Commit message
Description of the change
Like we talked about back when updating/tweaking the readme, I've removed the --record and --playback options since they weren't in use.
I started out following the methods called by the option when running Widelands, but ended up removing all of journal and journal_exception when I discovered it wasn't used for anything else. I was also able to remove a helper function which wasn't used elsewhere.
A couple of places has been marked FIXME to get some feedback on them.
To post a comment you must log in.
Revision history for this message
Hans Joachim Desserud (hjd) wrote : | # |
Nice, let's merge this then. :)
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/helper.h' |
2 | --- src/helper.h 2013-07-26 19:16:51 +0000 |
3 | +++ src/helper.h 2014-03-11 20:49:20 +0000 |
4 | @@ -135,22 +135,6 @@ |
5 | return x; |
6 | } |
7 | |
8 | -/* Convert any sstream-compatible type to std::string |
9 | - * |
10 | - * \note In a just world, this would be implemented with gnu::autosprintf. But |
11 | - * many distributions don't carry that lib despite the fact that it is part of |
12 | - * glibc. |
13 | - * |
14 | - * \see http://www.experts-exchange.com/Programming/ |
15 | - * Programming_Languages/Cplusplus/Q_20670737.html |
16 | - * \author AssafLavie on http://www.experts-exchange.com |
17 | - */ |
18 | -template<typename T> std::string toString(const T & x) { |
19 | - std::ostringstream oss; |
20 | - oss << x; |
21 | - return oss.str(); |
22 | -} |
23 | - |
24 | std::vector<std::string> split_string |
25 | (const std::string &, char const * separators); |
26 | void remove_spaces(std::string &); |
27 | |
28 | === removed file 'src/journal.cc' |
29 | --- src/journal.cc 2013-07-26 19:16:51 +0000 |
30 | +++ src/journal.cc 1970-01-01 00:00:00 +0000 |
31 | @@ -1,484 +0,0 @@ |
32 | -/* |
33 | - * Copyright (C) 2006-2009 by the Widelands Development Team |
34 | - * |
35 | - * This program is free software; you can redistribute it and/or |
36 | - * modify it under the terms of the GNU General Public License |
37 | - * as published by the Free Software Foundation; either version 2 |
38 | - * of the License, or (at your option) any later version. |
39 | - * |
40 | - * This program is distributed in the hope that it will be useful, |
41 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
42 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43 | - * GNU General Public License for more details. |
44 | - * |
45 | - * You should have received a copy of the GNU General Public License |
46 | - * along with this program; if not, write to the Free Software |
47 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
48 | - * |
49 | - */ |
50 | - |
51 | -#include "journal.h" |
52 | - |
53 | -#include <cassert> |
54 | - |
55 | -#include "io/filesystem/filesystem.h" |
56 | -#include "log.h" |
57 | -#include "machdep.h" |
58 | - |
59 | -/** |
60 | - * Write a signed 8bit value to the recording file. |
61 | - * \param v The character to be written |
62 | - */ |
63 | -void Journal::write(int8_t const v) { |
64 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
65 | -} |
66 | - |
67 | -/// \overload |
68 | -void Journal::write(uint8_t const v) { |
69 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
70 | -} |
71 | - |
72 | -/// \overload |
73 | -void Journal::write(int16_t v) { |
74 | - v = Little16(v); |
75 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
76 | -} |
77 | -/// \overload |
78 | -void Journal::write(uint16_t v) { |
79 | - v = Little16(v); |
80 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
81 | -} |
82 | - |
83 | -/// \overload |
84 | -void Journal::write(int32_t v) { |
85 | - v = Little32(v); |
86 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
87 | -} |
88 | - |
89 | -/// \overload |
90 | -void Journal::write(uint32_t v) { |
91 | - v = Little32(v); |
92 | - m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v)); |
93 | -} |
94 | - |
95 | -/// \overload |
96 | -/// SDLKey is an enum, and enums are implemented as int32_t. Consequently, |
97 | -/// SDLKey changes size on 64bit machines :-( |
98 | -/// So we force it to be 32bit, discarding the higher 32 bits (hopefully no-one |
99 | -/// will have so many keys). |
100 | -/// |
101 | -/// On 32bit systems, it does not matter whether this method or |
102 | -/// \ref write(Uint32 v) actually gets used. |
103 | -/// |
104 | -/// \sa write(SDLMod v) |
105 | -/// \sa read(SDLMod &v) |
106 | -void Journal::write(SDLKey v) |
107 | -{ |
108 | - write(static_cast<uint32_t>(v)); |
109 | -} |
110 | - |
111 | -/** |
112 | - * \overload |
113 | - * \sa write(SDLKey v) |
114 | - */ |
115 | -void Journal::write(SDLMod v) |
116 | -{ |
117 | - write(static_cast<uint32_t>(v)); |
118 | -} |
119 | - |
120 | -/** |
121 | - * Write a signed char value to the recording file. |
122 | - * \param v Reference where the read character will be stored. |
123 | - */ |
124 | -void Journal::read (int8_t & v) |
125 | -{ |
126 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint8_t)); |
127 | -} |
128 | - |
129 | -/** |
130 | - * \overload |
131 | - */ |
132 | -void Journal::read(uint8_t & v) |
133 | -{ |
134 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint8_t)); |
135 | -} |
136 | - |
137 | -/** |
138 | - * \overload |
139 | - */ |
140 | -void Journal::read (int16_t & v) { |
141 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(int16_t)); |
142 | - v = Little16(v); |
143 | -} |
144 | - |
145 | -/** |
146 | - * \overload |
147 | - */ |
148 | -void Journal::read(uint16_t & v) { |
149 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint16_t)); |
150 | - v = Little16(v); |
151 | -} |
152 | - |
153 | -/** |
154 | - * \overload |
155 | - */ |
156 | -void Journal::read (int32_t & v) { |
157 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(int32_t)); |
158 | - v = Little32(v); |
159 | -} |
160 | - |
161 | -/** |
162 | - * \overload |
163 | - */ |
164 | -void Journal::read(uint32_t & v) { |
165 | - m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint32_t)); |
166 | - v = Little32(v); |
167 | -} |
168 | - |
169 | -/** |
170 | - * \overload |
171 | - * \sa read(SDLKey v) |
172 | - */ |
173 | -void Journal::read(SDLKey & v) |
174 | -{ |
175 | - uint32_t x; |
176 | - read(x); |
177 | - v = static_cast<SDLKey>(x); |
178 | -} |
179 | - |
180 | -/** |
181 | - * \overload |
182 | - * \sa read(SDLKey v) |
183 | - */ |
184 | -void Journal::read(SDLMod & v) |
185 | -{ |
186 | - uint32_t x; |
187 | - read(x); |
188 | - v = static_cast<SDLMod>(x); |
189 | -} |
190 | - |
191 | -/** |
192 | - * \todo Document me |
193 | - */ |
194 | -void Journal::ensure_code(uint8_t code) |
195 | -{ |
196 | - uint8_t filecode; |
197 | - |
198 | - read(filecode); |
199 | - if (filecode != code) { |
200 | - throw BadRecord_error(m_playbackname, filecode, code); |
201 | - } |
202 | -} |
203 | - |
204 | -/** |
205 | - * Standard ctor |
206 | - */ |
207 | -Journal::Journal() |
208 | -: |
209 | -m_recordname(""), m_playbackname(""), |
210 | -m_record(false), m_playback(false) |
211 | -{ |
212 | - m_recordstream.exceptions |
213 | - (std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit); |
214 | - |
215 | - m_playbackstream.exceptions |
216 | - (std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit); |
217 | -} |
218 | - |
219 | -/** |
220 | - * Close any open journal files |
221 | - */ |
222 | -Journal::~Journal() |
223 | -{ |
224 | - stop_recording(); |
225 | - stop_playback(); |
226 | -} |
227 | - |
228 | -/** |
229 | - * Start recording events handed to us |
230 | - * \param filename File the events should be written to |
231 | - * \todo set the filename somewhere else |
232 | - */ |
233 | -void Journal::start_recording(const std::string & filename) |
234 | -{ |
235 | - assert(!m_recordstream.is_open()); |
236 | - |
237 | - //TODO: m_recordname = FileSystem::FS_CanonicalizeName(filename); |
238 | - m_recordname = filename; |
239 | - if (m_recordname.empty()) |
240 | - assert(false); //TODO: barf in a controlled way |
241 | - |
242 | - try { |
243 | - m_recordstream.open |
244 | - (m_recordname.c_str(), std::ios::binary|std::ios::trunc); |
245 | - write(RFC_MAGIC); |
246 | - m_recordstream << std::flush; |
247 | - m_record = true; |
248 | - log("Recording into %s\n", m_recordname.c_str()); |
249 | - } |
250 | - catch (std::ofstream::failure &) { |
251 | - //TODO: use exception mask to find out what happened |
252 | - //TODO: there should be a messagebox to tell the user. |
253 | - log |
254 | - ("Problem while opening record file %s for writing.\n", |
255 | - m_recordname.c_str()); |
256 | - stop_recording(); |
257 | - throw Journalfile_error(m_recordname); |
258 | - } |
259 | -} |
260 | - |
261 | -/** |
262 | - * Stop recording events. |
263 | - * It's safe to call this even if recording has not been |
264 | - * started yet. |
265 | - */ |
266 | -void Journal::stop_recording() |
267 | -{ |
268 | - m_record = false; |
269 | - |
270 | - if (m_recordstream.is_open()) { |
271 | - m_recordstream<<std::flush; |
272 | - m_recordstream.close(); |
273 | - } |
274 | -} |
275 | - |
276 | -/** |
277 | - * Start playing back events |
278 | - * \param filename File to get events from |
279 | - * \todo set the filename somewhere else |
280 | - */ |
281 | -void Journal::start_playback(const std::string & filename) |
282 | -{ |
283 | - assert(!m_playbackstream.is_open()); |
284 | - |
285 | - //TODO: m_playbackname = FileSystem::FS_CanonicalizeName(filename); |
286 | - m_playbackname = filename; |
287 | - if (m_playbackname.empty()) |
288 | - assert(false); //TODO: barf in a controlled way |
289 | - |
290 | - try { |
291 | - uint32_t magic; |
292 | - |
293 | - m_playbackstream.open(m_playbackname.c_str(), std::ios::binary); |
294 | - read(magic); |
295 | - if (magic != RFC_MAGIC) |
296 | - throw BadMagic_error(m_playbackname); |
297 | - m_playback = true; |
298 | - log("Playing back from %s\n", m_playbackname.c_str()); |
299 | - } |
300 | - catch (std::ifstream::failure &) { |
301 | - //TODO: use exception mask to find out what happened |
302 | - //TODO: there should be a messagebox to tell the user. |
303 | - log |
304 | - ("ERROR: problem while opening playback file for reading. Playback " |
305 | - "deactivated.\n"); |
306 | - stop_playback(); |
307 | - throw Journalfile_error(m_recordname); |
308 | - } |
309 | -} |
310 | - |
311 | -/** |
312 | - * Stop playing back events. |
313 | - * It's safe to call this even if playback has not been |
314 | - * started yet. |
315 | - */ |
316 | -void Journal::stop_playback() |
317 | -{ |
318 | - m_playback = false; |
319 | - |
320 | - if (m_playbackstream.is_open()) { |
321 | - m_playbackstream.close(); |
322 | - } |
323 | -} |
324 | - |
325 | -/** |
326 | - * Record an event into the playback file. This entails serializing the |
327 | - * event and writing it out. |
328 | - * |
329 | - * \param e The event to be recorded |
330 | - */ |
331 | -void Journal::record_event(const SDL_Event & e) |
332 | -{ |
333 | - if (!m_record) |
334 | - return; |
335 | - |
336 | - try { |
337 | - //Note: the following lines are *inside* the switch on purpose: |
338 | - // write(RFC_EVENT); |
339 | - // m_recordstream<<std::flush; |
340 | - //If they were outside, they'd get executed on every mainloop |
341 | - //iteration, which would yield a) huge files and b) lots of |
342 | - //completely unnecessary overhad. |
343 | - switch (e.type) { |
344 | - case SDL_KEYDOWN: |
345 | - write(static_cast<uint8_t>(RFC_EVENT)); |
346 | - write(static_cast<uint8_t>(RFC_KEYDOWN)); |
347 | - write(e.key.keysym.mod); |
348 | - write(e.key.keysym.sym); |
349 | - write(e.key.keysym.unicode); |
350 | - m_recordstream << std::flush; |
351 | - break; |
352 | - case SDL_KEYUP: |
353 | - write(static_cast<uint8_t>(RFC_EVENT)); |
354 | - write(static_cast<uint8_t>(RFC_KEYUP)); |
355 | - write(e.key.keysym.mod); |
356 | - write(e.key.keysym.sym); |
357 | - write(e.key.keysym.unicode); |
358 | - m_recordstream << std::flush; |
359 | - break; |
360 | - case SDL_MOUSEBUTTONDOWN: |
361 | - write(static_cast<uint8_t>(RFC_EVENT)); |
362 | - write(static_cast<uint8_t>(RFC_MOUSEBUTTONDOWN)); |
363 | - write(e.button.button); |
364 | - write(e.button.x); |
365 | - write(e.button.y); |
366 | - write(e.button.state); |
367 | - m_recordstream << std::flush; |
368 | - break; |
369 | - case SDL_MOUSEBUTTONUP: |
370 | - write(static_cast<uint8_t>(RFC_EVENT)); |
371 | - write(static_cast<uint8_t>(RFC_MOUSEBUTTONUP)); |
372 | - write(e.button.button); |
373 | - write(e.button.x); |
374 | - write(e.button.y); |
375 | - write(e.button.state); |
376 | - m_recordstream << std::flush; |
377 | - break; |
378 | - case SDL_MOUSEMOTION: |
379 | - write(static_cast<uint8_t>(RFC_EVENT)); |
380 | - write(static_cast<uint8_t>(RFC_MOUSEMOTION)); |
381 | - write(e.motion.state); |
382 | - write(e.motion.x); |
383 | - write(e.motion.y); |
384 | - write(e.motion.xrel); |
385 | - write(e.motion.yrel); |
386 | - m_recordstream << std::flush; |
387 | - break; |
388 | - case SDL_QUIT: |
389 | - write(static_cast<uint8_t>(RFC_EVENT)); |
390 | - write(static_cast<uint8_t>(RFC_QUIT)); |
391 | - m_recordstream << std::flush; |
392 | - break; |
393 | - default: |
394 | - // can't really do anything useful with this event |
395 | - break; |
396 | - } |
397 | - } |
398 | - catch (const std::ofstream::failure &) { |
399 | - //TODO: use exception mask to find out what happened |
400 | - //TODO: there should be a messagebox to tell the user. |
401 | - log("Failed to write to record file. Recording deactivated.\n"); |
402 | - stop_recording(); |
403 | - throw Journalfile_error(m_recordname); |
404 | - } |
405 | -} |
406 | - |
407 | -/** |
408 | - * Get an event from the playback file. This entails creating an empty |
409 | - * event with sensible default values (not all parameters get recorded) |
410 | - * and deserializing the event record. |
411 | - * |
412 | - * \param e The event being returned |
413 | - */ |
414 | -bool Journal::read_event(SDL_Event & e) |
415 | -{ |
416 | - if (!m_playback) |
417 | - return false; |
418 | - |
419 | - bool haveevent = false; |
420 | - |
421 | - try { |
422 | - uint8_t recordtype; |
423 | - read(recordtype); |
424 | - switch (recordtype) { |
425 | - case RFC_EVENT: |
426 | - uint8_t eventtype; |
427 | - read(eventtype); |
428 | - switch (eventtype) { |
429 | - case RFC_KEYDOWN: |
430 | - e.type = SDL_KEYDOWN; |
431 | - read(e.key.keysym.mod); |
432 | - read(e.key.keysym.sym); |
433 | - read(e.key.keysym.unicode); |
434 | - break; |
435 | - case RFC_KEYUP: |
436 | - e.type = SDL_KEYUP; |
437 | - read(e.key.keysym.mod); |
438 | - read(e.key.keysym.sym); |
439 | - read(e.key.keysym.unicode); |
440 | - break; |
441 | - case RFC_MOUSEBUTTONDOWN: |
442 | - e.type = SDL_MOUSEBUTTONDOWN; |
443 | - read(e.button.button); |
444 | - read(e.button.x); |
445 | - read(e.button.y); |
446 | - read(e.button.state); |
447 | - break; |
448 | - case RFC_MOUSEBUTTONUP: |
449 | - e.type = SDL_MOUSEBUTTONUP; |
450 | - read(e.button.button); |
451 | - read(e.button.x); |
452 | - read(e.button.y); |
453 | - read(e.button.state); |
454 | - break; |
455 | - case RFC_MOUSEMOTION: |
456 | - e.type = SDL_MOUSEMOTION; |
457 | - read(e.motion.state); |
458 | - read(e.motion.x); |
459 | - read(e.motion.y); |
460 | - read(e.motion.xrel); |
461 | - read(e.motion.yrel); |
462 | - break; |
463 | - case RFC_QUIT: |
464 | - e.type = SDL_QUIT; |
465 | - break; |
466 | - default: |
467 | - throw BadEvent_error(m_playbackname, eventtype); |
468 | - } |
469 | - |
470 | - haveevent = true; |
471 | - break; |
472 | - case RFC_ENDEVENTS: |
473 | - //Do nothing |
474 | - break; |
475 | - default: |
476 | - throw BadRecord_error(m_playbackname, recordtype, RFC_INVALID); |
477 | - break; |
478 | - } |
479 | - } catch (const std::ifstream::failure &) { |
480 | - //TODO: use exception mask to find out what happened |
481 | - //TODO: there should be a messagebox to tell the user. |
482 | - log("Failed to read from journal file. Playback deactivated.\n"); |
483 | - stop_playback(); |
484 | - throw Journalfile_error(m_playbackname); |
485 | - } |
486 | - |
487 | - return haveevent; |
488 | -} |
489 | - |
490 | -/** |
491 | - * Do the right thing with timestamps. |
492 | - * All timestamps handled with \ref WLApplication::get_time() pass through here. |
493 | - * If necessary, they will be recorded. On playback, they will be modified to |
494 | - * show the recorded time instead of the current time. |
495 | - */ |
496 | -void Journal::timestamp_handler(uint32_t & stamp) |
497 | -{ |
498 | - if (m_record) { |
499 | - write(static_cast<uint8_t>(RFC_GETTIME)); |
500 | - write(stamp); |
501 | - } |
502 | - |
503 | - if (m_playback) { |
504 | - ensure_code(static_cast<uint8_t>(RFC_GETTIME)); |
505 | - read(stamp); |
506 | - } |
507 | -} |
508 | - |
509 | -/** |
510 | - * \todo document me |
511 | - */ |
512 | -void Journal::set_idle_mark() |
513 | -{ |
514 | - write(static_cast<uint8_t>(RFC_ENDEVENTS)); |
515 | -} |
516 | |
517 | === removed file 'src/journal.h' |
518 | --- src/journal.h 2013-07-26 19:16:51 +0000 |
519 | +++ src/journal.h 1970-01-01 00:00:00 +0000 |
520 | @@ -1,137 +0,0 @@ |
521 | -/* |
522 | - * Copyright (C) 2006-2009 by the Widelands Development Team |
523 | - * |
524 | - * This program is free software; you can redistribute it and/or |
525 | - * modify it under the terms of the GNU General Public License |
526 | - * as published by the Free Software Foundation; either version 2 |
527 | - * of the License, or (at your option) any later version. |
528 | - * |
529 | - * This program is distributed in the hope that it will be useful, |
530 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
531 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
532 | - * GNU General Public License for more details. |
533 | - * |
534 | - * You should have received a copy of the GNU General Public License |
535 | - * along with this program; if not, write to the Free Software |
536 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
537 | - * |
538 | - */ |
539 | - |
540 | -#ifndef JOURNAL_H |
541 | -#define JOURNAL_H |
542 | - |
543 | -#include <cstring> |
544 | -#include <fstream> |
545 | -#include <string> |
546 | - |
547 | -#include <SDL_events.h> |
548 | - |
549 | -#include "journal_exceptions.h" |
550 | - |
551 | -/** |
552 | - * Journal encapsulates all operations that are necessary for recording and |
553 | - * playing back a session. On it's interface, it deals with SDL_Events that |
554 | - * might (or might not) be recorded/played back. Whether a recording / playback |
555 | - * is actually being performed is internal to Journal. |
556 | - * |
557 | - * \note If you are hacking this class, throw a Journalfile_exception only |
558 | - * and always if there is a nonrecoverable error and you have already dealt with |
559 | - * it. |
560 | - * |
561 | - * \todo The idea of writing enums into a file is bad: enums are int32_t and |
562 | - * int32_t varies in size (typ. 32/64bit). Our own codes only need 8bit, so we |
563 | - * force IO down to this value. The same happens with keyboard events at |
564 | - * 32 bits. Cutting off bits is not a good solution, but in this case it'll do |
565 | - * until a better way comes along. |
566 | - */ |
567 | -struct Journal { |
568 | - /// change this and I will ensure your death will be a most unpleasant one |
569 | - static uint32_t const RFC_MAGIC = 0x0ACAD100; |
570 | - |
571 | - /** |
572 | - * Record file codes |
573 | - * It should be possible to use record files across different platforms. |
574 | - * However, 64 bit platforms are currently not supported. |
575 | - */ |
576 | - enum rfccode { |
577 | - RFC_GETTIME = 0x01, |
578 | - RFC_EVENT = 0x02, |
579 | - RFC_ENDEVENTS = 0x03, |
580 | - |
581 | - RFC_KEYDOWN = 0x10, |
582 | - RFC_KEYUP = 0x11, |
583 | - RFC_MOUSEBUTTONDOWN = 0x12, |
584 | - RFC_MOUSEBUTTONUP = 0x13, |
585 | - RFC_MOUSEMOTION = 0x14, |
586 | - RFC_QUIT = 0x15, |
587 | - RFC_INVALID = 0xff |
588 | - }; |
589 | - |
590 | -public: |
591 | - Journal(); |
592 | - ~Journal(); |
593 | - |
594 | - void start_recording(const std::string & filename = "widelands.jnl"); |
595 | - void stop_recording(); |
596 | - ///True if events are being recorded |
597 | - bool is_recording() const {return m_record;} |
598 | - |
599 | - void start_playback (const std::string & filename = "widelands.jnl"); |
600 | - void stop_playback(); |
601 | - ///True if events are being played back |
602 | - bool is_playingback() const {return m_playback;} |
603 | - |
604 | - void record_event(const SDL_Event &); |
605 | - bool read_event(SDL_Event &); |
606 | - |
607 | - void timestamp_handler(uint32_t & stamp); |
608 | - void set_idle_mark(); |
609 | - |
610 | -protected: |
611 | - /** |
612 | - * Returns the position in the playback file |
613 | - * \return byte offset into the playback file, used with file reading |
614 | - */ |
615 | - int32_t get_playback_offset() {return m_playbackstream.tellg();} |
616 | - |
617 | - void write(int8_t); |
618 | - void write(uint8_t); |
619 | - void write(int16_t); |
620 | - void write(uint16_t); |
621 | - void write(int32_t); |
622 | - void write(uint32_t); |
623 | - void write(SDLKey); |
624 | - void write(SDLMod); |
625 | - |
626 | - void read(int8_t &); |
627 | - void read(uint8_t &); |
628 | - void read(int16_t &); |
629 | - void read(uint16_t &); |
630 | - void read(int32_t &); |
631 | - void read(uint32_t &); |
632 | - void read(SDLKey &); |
633 | - void read(SDLMod &); |
634 | - void ensure_code(uint8_t code); |
635 | - |
636 | - ///The recording file's name. |
637 | - ///\note This does \e not go through the layered filesystem on purpose! |
638 | - std::string m_recordname; |
639 | - |
640 | - ///The playback file's name. |
641 | - ///\note This does \e not go through the layered filesystem on purpose! |
642 | - std::string m_playbackname; |
643 | - |
644 | - ///The file events are being recorded to |
645 | - std::ofstream m_recordstream; |
646 | - |
647 | - ///The file events are being played back from |
648 | - std::ifstream m_playbackstream; |
649 | - |
650 | - ///True if events are being recorded |
651 | - bool m_record; |
652 | - |
653 | - ///True if events are being played back |
654 | - bool m_playback; |
655 | -}; |
656 | - |
657 | -#endif |
658 | |
659 | === removed file 'src/journal_exceptions.cc' |
660 | --- src/journal_exceptions.cc 2013-09-23 18:47:02 +0000 |
661 | +++ src/journal_exceptions.cc 1970-01-01 00:00:00 +0000 |
662 | @@ -1,59 +0,0 @@ |
663 | -/* |
664 | - * Copyright (C) 2006, 2008 by the Widelands Development Team |
665 | - * |
666 | - * This program is free software; you can redistribute it and/or |
667 | - * modify it under the terms of the GNU General Public License |
668 | - * as published by the Free Software Foundation; either version 2 |
669 | - * of the License, or (at your option) any later version. |
670 | - * |
671 | - * This program is distributed in the hope that it will be useful, |
672 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
673 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
674 | - * GNU General Public License for more details. |
675 | - * |
676 | - * You should have received a copy of the GNU General Public License |
677 | - * along with this program; if not, write to the Free Software |
678 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
679 | - * |
680 | - */ |
681 | - |
682 | -#include "journal_exceptions.h" |
683 | - |
684 | -#include "helper.h" |
685 | - |
686 | -Journalfile_error::Journalfile_error(const std::string & _filename) |
687 | -: std::runtime_error("Problem with journal file."), filename(_filename) |
688 | -{ |
689 | - text = "Problem with journal file " + _filename; |
690 | -} |
691 | - |
692 | -///\todo Say _which_ magic number was found and which was expected |
693 | -BadMagic_error::BadMagic_error(const std::string & _filename) |
694 | -: Journalfile_error(_filename) |
695 | -{ |
696 | - text = "Journal file " + _filename + " starts with bad magic number"; |
697 | -} |
698 | - |
699 | -BadRecord_error::BadRecord_error |
700 | - (const std::string & _filename, |
701 | - uint8_t const _code, |
702 | - uint8_t const _expectedcode) |
703 | -: Journalfile_error(_filename), offset(0), code(_code), expectedcode(_expectedcode) |
704 | -{ |
705 | - text = "Journal file "; |
706 | - text += _filename; |
707 | - text += " contains record with type "; |
708 | - text += toString(static_cast<int>(_code)); |
709 | - text += " instead of the expected type "; |
710 | - text += toString(static_cast<int>(_expectedcode)); |
711 | -} |
712 | - |
713 | -BadEvent_error::BadEvent_error |
714 | - (const std::string & _filename, uint8_t const _type) |
715 | -: Journalfile_error(_filename), offset(0), type(_type) |
716 | -{ |
717 | - text = "Journal file '"; |
718 | - text += _filename; |
719 | - text += "' contains record with unknown event type "; |
720 | - text += toString(_type); |
721 | -} |
722 | |
723 | === removed file 'src/journal_exceptions.h' |
724 | --- src/journal_exceptions.h 2014-02-22 18:04:02 +0000 |
725 | +++ src/journal_exceptions.h 1970-01-01 00:00:00 +0000 |
726 | @@ -1,90 +0,0 @@ |
727 | -/* |
728 | - * Copyright (C) 2006, 2008-2009 by the Widelands Development Team |
729 | - * |
730 | - * This program is free software; you can redistribute it and/or |
731 | - * modify it under the terms of the GNU General Public License |
732 | - * as published by the Free Software Foundation; either version 2 |
733 | - * of the License, or (at your option) any later version. |
734 | - * |
735 | - * This program is distributed in the hope that it will be useful, |
736 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
737 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
738 | - * GNU General Public License for more details. |
739 | - * |
740 | - * You should have received a copy of the GNU General Public License |
741 | - * along with this program; if not, write to the Free Software |
742 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
743 | - * |
744 | - */ |
745 | - |
746 | -#ifndef JOURNAL_EXCEPTIONS_H |
747 | -#define JOURNAL_EXCEPTIONS_H |
748 | - |
749 | -#include <stdexcept> |
750 | -#include <string> |
751 | - |
752 | -#include <stdint.h> |
753 | - |
754 | -/// |
755 | -/// Thrown for IO-errors occurring with a journal file (unable to open file |
756 | -/// for any reason, out of space, etc.) that a) are unrecoverable and b) |
757 | -/// have already been dealt with. |
758 | -/// |
759 | -/// This is a purely informational exception. Do not throw it unless it can |
760 | -/// safely be ignored. |
761 | -/// |
762 | -/// \todo add offset into journal file if applicable |
763 | -/// \todo Rework as proposed by Erik, see filesystem_exceptions.h. Before that: |
764 | -/// Replace with File*_error where appropriate, migrate from runtime_error to |
765 | -/// logic_error (?) |
766 | -struct Journalfile_error : public std::runtime_error { |
767 | - explicit Journalfile_error(const std::string & filename); |
768 | - virtual ~Journalfile_error() throw () {} |
769 | - |
770 | - virtual char const * what() const throw () override {return text.c_str();} |
771 | - |
772 | - std::string text; |
773 | - std::string filename; |
774 | -}; |
775 | - |
776 | -/** |
777 | - * Thrown if the journal file contains a bad magic number |
778 | - * \todo add offset into journal file |
779 | - */ |
780 | -struct BadMagic_error : public Journalfile_error { |
781 | - explicit BadMagic_error(const std::string & filename); |
782 | - virtual ~BadMagic_error() throw () {} |
783 | -}; |
784 | - |
785 | -/** |
786 | - * Thrown if the journal file contains a record with an unknown type number |
787 | - * \todo add offset into journal file |
788 | - */ |
789 | -struct BadRecord_error : public Journalfile_error { |
790 | - explicit BadRecord_error |
791 | - (const std::string & filename, |
792 | - const uint8_t code, |
793 | - const uint8_t expectedcode) |
794 | - ; |
795 | - virtual ~BadRecord_error() throw () {} |
796 | - |
797 | - std::streamoff offset; |
798 | - uint8_t code; |
799 | - uint8_t expectedcode; |
800 | -}; |
801 | - |
802 | -/** |
803 | - * Thrown if the journal file contains an event record with an unknown |
804 | - * event type |
805 | - * \todo add offset into journal file |
806 | - */ |
807 | -struct BadEvent_error : public Journalfile_error { |
808 | - explicit BadEvent_error(const std::string & filename, uint8_t const type) |
809 | - ; |
810 | - virtual ~BadEvent_error() throw () {} |
811 | - |
812 | - std::streamoff offset; |
813 | - uint8_t type; |
814 | -}; |
815 | - |
816 | -#endif |
817 | |
818 | === modified file 'src/wlapplication.cc' |
819 | --- src/wlapplication.cc 2014-03-09 10:28:39 +0000 |
820 | +++ src/wlapplication.cc 2014-03-11 20:49:20 +0000 |
821 | @@ -48,7 +48,6 @@ |
822 | #include "io/dedicated_log.h" |
823 | #include "io/filesystem/disk_filesystem.h" |
824 | #include "io/filesystem/layered_filesystem.h" |
825 | -#include "journal.h" |
826 | #include "log.h" |
827 | #include "logic/game.h" |
828 | #include "logic/game_data_error.h" |
829 | @@ -248,7 +247,6 @@ |
830 | WLApplication::WLApplication(int const argc, char const * const * const argv) : |
831 | m_commandline (std::map<std::string, std::string>()), |
832 | m_game_type (NONE), |
833 | -journal (nullptr), |
834 | m_mouse_swapped (false), |
835 | m_faking_middle_mouse_button(false), |
836 | m_mouse_position (0, 0), |
837 | @@ -480,158 +478,53 @@ |
838 | |
839 | /** |
840 | * Get an event from the SDL queue, just like SDL_PollEvent. |
841 | - * Perform the meat of playback/record stuff when needed. |
842 | - * |
843 | - * Throttle is a hack to stop record files from getting extremely huge. |
844 | - * If it is set to true, we will idle loop if we can't get an SDL_Event |
845 | - * returned immediately if we're recording. If there is no user input, |
846 | - * the actual mainloop will be throttled to 100fps. |
847 | * |
848 | * \param ev the retrieved event will be put here |
849 | - * \param throttle Limit recording to 100fps max (not the event loop itself!) |
850 | * |
851 | * \return true if an event was returned inside ev, false otherwise |
852 | - * |
853 | - * \todo Catch Journalfile_error |
854 | */ |
855 | -bool WLApplication::poll_event(SDL_Event & ev, bool const throttle) { |
856 | - bool haveevent = false; |
857 | - |
858 | -restart: |
859 | - //inject synthesized events into the event queue when playing back |
860 | - if (journal->is_playingback()) { |
861 | - try { |
862 | - haveevent = journal->read_event(ev); |
863 | - } catch (const Journalfile_error & e) { |
864 | - // An error might occur here when playing back a file that |
865 | - // was not finalized due to a crash etc. |
866 | - // Since playbacks are intended precisely for debugging such |
867 | - // crashes, we must ignore the error and continue. |
868 | - log("JOURNAL: read error, continue without playback: %s\n", e.what()); |
869 | - journal->stop_playback(); |
870 | - } |
871 | - } else { |
872 | - haveevent = SDL_PollEvent(&ev); |
873 | - |
874 | - if (haveevent) { |
875 | - // We edit mouse motion events in here, so that |
876 | - // differences caused by GrabInput or mouse speed |
877 | - // settings are invisible to the rest of the code |
878 | - switch (ev.type) { |
879 | - case SDL_MOUSEMOTION: |
880 | - ev.motion.xrel += m_mouse_compensate_warp.x; |
881 | - ev.motion.yrel += m_mouse_compensate_warp.y; |
882 | - m_mouse_compensate_warp = Point(0, 0); |
883 | - |
884 | - if (m_mouse_locked) { |
885 | - warp_mouse(m_mouse_position); |
886 | - |
887 | - ev.motion.x = m_mouse_position.x; |
888 | - ev.motion.y = m_mouse_position.y; |
889 | - } |
890 | - |
891 | - break; |
892 | - case SDL_USEREVENT: |
893 | - if (ev.user.code == CHANGE_MUSIC) |
894 | - g_sound_handler.change_music(); |
895 | - |
896 | - break; |
897 | - case SDL_VIDEOEXPOSE: |
898 | - //log ("SDL Video Window expose event: %i\n", ev.expose.type); |
899 | - g_gr->update_fullscreen(); |
900 | - break; |
901 | - default:; |
902 | - } |
903 | - } |
904 | - } |
905 | - |
906 | - // log all events into the journal file |
907 | - if (journal->is_recording()) { |
908 | - if (haveevent) |
909 | - journal->record_event(ev); |
910 | - else if (throttle && journal->is_playingback()) { |
911 | - // Implement the throttle to avoid very quick inner mainloops when |
912 | - // recoding a session |
913 | - static int32_t lastthrottle = 0; |
914 | - int32_t const time = SDL_GetTicks(); |
915 | - |
916 | - if (time - lastthrottle < 10) |
917 | - goto restart; |
918 | - |
919 | - lastthrottle = time; |
920 | - } |
921 | - |
922 | - journal->set_idle_mark(); |
923 | - } else if (haveevent) { |
924 | - // Eliminate any unhandled events to make sure that record and playback |
925 | - // are _really_ the same. Yes I know, it's overly paranoid but hey... |
926 | - switch (ev.type) { |
927 | - case SDL_KEYDOWN: |
928 | - case SDL_KEYUP: |
929 | - case SDL_MOUSEBUTTONDOWN: |
930 | - case SDL_MOUSEBUTTONUP: |
931 | - case SDL_MOUSEMOTION: |
932 | - case SDL_QUIT: |
933 | - break; |
934 | - default: |
935 | - goto restart; |
936 | - } |
937 | - } |
938 | - |
939 | - return haveevent; |
940 | +bool WLApplication::poll_event(SDL_Event& ev) { |
941 | + if (!SDL_PollEvent(&ev)) { |
942 | + return false; |
943 | + } |
944 | + |
945 | + // We edit mouse motion events in here, so that |
946 | + // differences caused by GrabInput or mouse speed |
947 | + // settings are invisible to the rest of the code |
948 | + switch (ev.type) { |
949 | + case SDL_MOUSEMOTION: |
950 | + ev.motion.xrel += m_mouse_compensate_warp.x; |
951 | + ev.motion.yrel += m_mouse_compensate_warp.y; |
952 | + m_mouse_compensate_warp = Point(0, 0); |
953 | + |
954 | + if (m_mouse_locked) { |
955 | + warp_mouse(m_mouse_position); |
956 | + |
957 | + ev.motion.x = m_mouse_position.x; |
958 | + ev.motion.y = m_mouse_position.y; |
959 | + } |
960 | + break; |
961 | + |
962 | + case SDL_USEREVENT: |
963 | + if (ev.user.code == CHANGE_MUSIC) |
964 | + g_sound_handler.change_music(); |
965 | + break; |
966 | + |
967 | + case SDL_VIDEOEXPOSE: |
968 | + // log ("SDL Video Window expose event: %i\n", ev.expose.type); |
969 | + g_gr->update_fullscreen(); |
970 | + break; |
971 | + } |
972 | + return true; |
973 | } |
974 | |
975 | - |
976 | /** |
977 | * Pump the event queue, get packets from the network, etc... |
978 | */ |
979 | void WLApplication::handle_input(InputCallback const * cb) |
980 | { |
981 | - bool gotevents = false; |
982 | - SDL_Event ev; // Valgrind says: |
983 | - // Conditional jump or move depends on uninitialised value(s) |
984 | - // at 0x407EEDA: (within /usr/lib/libSDL-1.2.so.0.11.0) |
985 | - // by 0x407F78F: (within /usr/lib/libSDL-1.2.so.0.11.0) |
986 | - // by 0x404FB12: SDL_PumpEvents (in /usr/lib/libSDL-1.2.so.0.11.0) |
987 | - // by 0x404FFC3: SDL_PollEvent (in /usr/lib/libSDL-1.2.so.0.11.0) |
988 | - // by 0x8252545: WLApplication::poll_event(SDL_Event*, bool) |
989 | - // (wlapplication.cc:309) |
990 | - // by 0x8252EB6: WLApplication::handle_input(InputCallback const*) |
991 | - // (wlapplication.cc:459) by 0x828B56E: UI::Panel::run() (ui_panel.cc:148) |
992 | - // by 0x8252FAB: WLApplication::run() (wlapplication.cc:212) |
993 | - // by 0x81427A6: main (main.cc:39) |
994 | - |
995 | - // We need to empty the SDL message queue always, even in playback mode |
996 | - // In playback mode, only F10 for premature exiting works |
997 | - if (journal->is_playingback()) { |
998 | - while (SDL_PollEvent(&ev)) { |
999 | - switch (ev.type) { |
1000 | - case SDL_KEYDOWN: |
1001 | - // get out of here quickly, overriding playback; |
1002 | - // since this is the only key event that works, we don't guard |
1003 | - // it by requiring Ctrl to be pressed. |
1004 | - if (ev.key.keysym.sym == SDLK_F10) |
1005 | - m_should_die = true; |
1006 | - break; |
1007 | - case SDL_QUIT: |
1008 | - m_should_die = true; |
1009 | - break; |
1010 | - default:; |
1011 | - } |
1012 | - } |
1013 | - } |
1014 | - |
1015 | - // Usual event queue |
1016 | - while (poll_event(ev, !gotevents)) { |
1017 | - |
1018 | - gotevents = true; |
1019 | - |
1020 | - // CAREFUL: Record files do not save the entire SDL_Event structure. |
1021 | - // Therefore, playbacks are incomplete. When you change the following |
1022 | - // code so that it uses previously unused fields in SDL_Event, |
1023 | - // please also take a look at Journal::read_event and |
1024 | - // Journal::record_event |
1025 | - |
1026 | + SDL_Event ev; |
1027 | + while (poll_event(ev)) { |
1028 | switch (ev.type) { |
1029 | case SDL_KEYDOWN: |
1030 | case SDL_KEYUP: |
1031 | @@ -747,9 +640,6 @@ |
1032 | int32_t WLApplication::get_time() { |
1033 | uint32_t time = SDL_GetTicks(); |
1034 | |
1035 | - // might change the time when playing back! |
1036 | - journal->timestamp_handler(time); |
1037 | - |
1038 | return time; |
1039 | } |
1040 | |
1041 | @@ -758,20 +648,17 @@ |
1042 | /// SDL_WarpMouse() *will* create a mousemotion event, which we do not want. As |
1043 | /// a workaround, we store the delta in m_mouse_compensate_warp and use that to |
1044 | /// eliminate the motion event in poll_event() |
1045 | -/// \todo Should this method have to care about playback at all??? |
1046 | /// |
1047 | /// \param position The new mouse position |
1048 | void WLApplication::warp_mouse(const Point position) |
1049 | { |
1050 | m_mouse_position = position; |
1051 | |
1052 | - if (not journal->is_playingback()) { // don't warp anything during playback |
1053 | - Point cur_position; |
1054 | - SDL_GetMouseState(&cur_position.x, &cur_position.y); |
1055 | - if (cur_position != position) { |
1056 | - m_mouse_compensate_warp += cur_position - position; |
1057 | - SDL_WarpMouse(position.x, position.y); |
1058 | - } |
1059 | + Point cur_position; |
1060 | + SDL_GetMouseState(&cur_position.x, &cur_position.y); |
1061 | + if (cur_position != position) { |
1062 | + m_mouse_compensate_warp += cur_position - position; |
1063 | + SDL_WarpMouse(position.x, position.y); |
1064 | } |
1065 | } |
1066 | |
1067 | @@ -786,9 +673,6 @@ |
1068 | */ |
1069 | void WLApplication::set_input_grab(bool grab) |
1070 | { |
1071 | - if (journal->is_playingback()) |
1072 | - return; // ignore in playback mode |
1073 | - |
1074 | if (grab) { |
1075 | SDL_WM_GrabInput(SDL_GRAB_ON); |
1076 | } else { |
1077 | @@ -842,10 +726,6 @@ |
1078 | */ |
1079 | bool WLApplication::init_settings() { |
1080 | |
1081 | - //create a journal so that handle_commandline_parameters can open the |
1082 | - //journal files |
1083 | - journal = new Journal(); |
1084 | - |
1085 | //read in the configuration file |
1086 | g_options.read("config", "global"); |
1087 | Section & s = g_options.pull_section("global"); |
1088 | @@ -927,10 +807,6 @@ |
1089 | } catch (...) { |
1090 | log("WARNING: could not save configuration"); |
1091 | } |
1092 | - |
1093 | - assert(journal); |
1094 | - delete journal; |
1095 | - journal = nullptr; |
1096 | } |
1097 | |
1098 | /** |
1099 | @@ -1280,34 +1156,6 @@ |
1100 | m_commandline.erase("script"); |
1101 | } |
1102 | |
1103 | - // TODO(sirver): this framework has not been useful in a long time. Kill it. |
1104 | - if (m_commandline.count("record")) { |
1105 | - if (m_commandline["record"].empty()) |
1106 | - throw Parameter_error("ERROR: --record needs a filename!"); |
1107 | - |
1108 | - try { |
1109 | - journal->start_recording(m_commandline["record"]); |
1110 | - } catch (Journalfile_error & e) { |
1111 | - wout << "Journal file error: " << e.what() << endl; |
1112 | - } |
1113 | - |
1114 | - m_commandline.erase("record"); |
1115 | - } |
1116 | - |
1117 | - if (m_commandline.count("playback")) { |
1118 | - if (m_commandline["playback"].empty()) |
1119 | - throw Parameter_error("ERROR: --playback needs a filename!"); |
1120 | - |
1121 | - try { |
1122 | - journal->start_playback(m_commandline["playback"]); |
1123 | - } |
1124 | - catch (Journalfile_error & e) { |
1125 | - wout << "Journal file error: " << e.what() << endl; |
1126 | - } |
1127 | - |
1128 | - m_commandline.erase("playback"); |
1129 | - } |
1130 | - |
1131 | //If it hasn't been handled yet it's probably an attempt to |
1132 | //override a conffile setting |
1133 | //With typos, this will create invalid config settings. They |
1134 | @@ -1351,9 +1199,7 @@ |
1135 | #ifdef __linux__ |
1136 | << _(" Default is ~/.widelands") << "\n" |
1137 | #endif |
1138 | - << _(" --record=FILENAME Record all events to the given filename for\n" |
1139 | - " later playback") << "\n" |
1140 | - << _(" --playback=FILENAME Playback given filename (see --record)") << "\n\n" |
1141 | + << "\n" |
1142 | << _(" --coredump=[yes|no] Generates a core dump on segfaults instead\n" |
1143 | " of using the SDL") << "\n" |
1144 | << _(" --language=[de_DE|sv_SE|...]\n" |
1145 | |
1146 | === modified file 'src/wlapplication.h' |
1147 | --- src/wlapplication.h 2014-02-22 18:04:02 +0000 |
1148 | +++ src/wlapplication.h 2014-03-11 20:49:20 +0000 |
1149 | @@ -38,7 +38,6 @@ |
1150 | |
1151 | |
1152 | namespace Widelands {class Game;} |
1153 | -struct Journal; |
1154 | |
1155 | ///Thrown if a commandline parameter is faulty |
1156 | struct Parameter_error : public std::runtime_error { |
1157 | @@ -233,7 +232,7 @@ |
1158 | protected: |
1159 | WLApplication(int argc, char const * const * argv); |
1160 | |
1161 | - bool poll_event(SDL_Event &, bool throttle); |
1162 | + bool poll_event(SDL_Event &); |
1163 | |
1164 | bool init_settings(); |
1165 | void init_language(); |
1166 | @@ -271,8 +270,6 @@ |
1167 | std::string m_logfile; |
1168 | |
1169 | GameType m_game_type; |
1170 | - ///the event recorder object |
1171 | - Journal * journal; |
1172 | |
1173 | ///True if left and right mouse button should be swapped |
1174 | bool m_mouse_swapped; |
looks good to me. I added one revision adressing all the FIXMEs. hjd, if you are happy with my changes we can merge this imho.