widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01820
[Merge] lp:~widelands-dev/widelands/remove-record into lp:widelands
Hans Joachim Desserud has proposed merging lp:~widelands-dev/widelands/remove-record into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/remove-record/+merge/210496
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.
--
https://code.launchpad.net/~widelands-dev/widelands/remove-record/+merge/210496
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/remove-record into lp:widelands.
=== modified file 'src/helper.h'
--- src/helper.h 2013-07-26 19:16:51 +0000
+++ src/helper.h 2014-03-11 20:33:30 +0000
@@ -135,22 +135,6 @@
return x;
}
-/* Convert any sstream-compatible type to std::string
- *
- * \note In a just world, this would be implemented with gnu::autosprintf. But
- * many distributions don't carry that lib despite the fact that it is part of
- * glibc.
- *
- * \see http://www.experts-exchange.com/Programming/
- * Programming_Languages/Cplusplus/Q_20670737.html
- * \author AssafLavie on http://www.experts-exchange.com
- */
-template<typename T> std::string toString(const T & x) {
- std::ostringstream oss;
- oss << x;
- return oss.str();
-}
-
std::vector<std::string> split_string
(const std::string &, char const * separators);
void remove_spaces(std::string &);
=== removed file 'src/journal.cc'
--- src/journal.cc 2013-07-26 19:16:51 +0000
+++ src/journal.cc 1970-01-01 00:00:00 +0000
@@ -1,484 +0,0 @@
-/*
- * Copyright (C) 2006-2009 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "journal.h"
-
-#include <cassert>
-
-#include "io/filesystem/filesystem.h"
-#include "log.h"
-#include "machdep.h"
-
-/**
- * Write a signed 8bit value to the recording file.
- * \param v The character to be written
- */
-void Journal::write(int8_t const v) {
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-
-/// \overload
-void Journal::write(uint8_t const v) {
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-
-/// \overload
-void Journal::write(int16_t v) {
- v = Little16(v);
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-/// \overload
-void Journal::write(uint16_t v) {
- v = Little16(v);
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-
-/// \overload
-void Journal::write(int32_t v) {
- v = Little32(v);
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-
-/// \overload
-void Journal::write(uint32_t v) {
- v = Little32(v);
- m_recordstream.write(reinterpret_cast<const char *>(&v), sizeof(v));
-}
-
-/// \overload
-/// SDLKey is an enum, and enums are implemented as int32_t. Consequently,
-/// SDLKey changes size on 64bit machines :-(
-/// So we force it to be 32bit, discarding the higher 32 bits (hopefully no-one
-/// will have so many keys).
-///
-/// On 32bit systems, it does not matter whether this method or
-/// \ref write(Uint32 v) actually gets used.
-///
-/// \sa write(SDLMod v)
-/// \sa read(SDLMod &v)
-void Journal::write(SDLKey v)
-{
- write(static_cast<uint32_t>(v));
-}
-
-/**
- * \overload
- * \sa write(SDLKey v)
- */
-void Journal::write(SDLMod v)
-{
- write(static_cast<uint32_t>(v));
-}
-
-/**
- * Write a signed char value to the recording file.
- * \param v Reference where the read character will be stored.
- */
-void Journal::read (int8_t & v)
-{
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint8_t));
-}
-
-/**
- * \overload
- */
-void Journal::read(uint8_t & v)
-{
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint8_t));
-}
-
-/**
- * \overload
- */
-void Journal::read (int16_t & v) {
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(int16_t));
- v = Little16(v);
-}
-
-/**
- * \overload
- */
-void Journal::read(uint16_t & v) {
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint16_t));
- v = Little16(v);
-}
-
-/**
- * \overload
- */
-void Journal::read (int32_t & v) {
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(int32_t));
- v = Little32(v);
-}
-
-/**
- * \overload
- */
-void Journal::read(uint32_t & v) {
- m_playbackstream.read(reinterpret_cast<char *>(&v), sizeof(uint32_t));
- v = Little32(v);
-}
-
-/**
- * \overload
- * \sa read(SDLKey v)
- */
-void Journal::read(SDLKey & v)
-{
- uint32_t x;
- read(x);
- v = static_cast<SDLKey>(x);
-}
-
-/**
- * \overload
- * \sa read(SDLKey v)
- */
-void Journal::read(SDLMod & v)
-{
- uint32_t x;
- read(x);
- v = static_cast<SDLMod>(x);
-}
-
-/**
- * \todo Document me
- */
-void Journal::ensure_code(uint8_t code)
-{
- uint8_t filecode;
-
- read(filecode);
- if (filecode != code) {
- throw BadRecord_error(m_playbackname, filecode, code);
- }
-}
-
-/**
- * Standard ctor
- */
-Journal::Journal()
-:
-m_recordname(""), m_playbackname(""),
-m_record(false), m_playback(false)
-{
- m_recordstream.exceptions
- (std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit);
-
- m_playbackstream.exceptions
- (std::ifstream::eofbit | std::ifstream::failbit | std::ifstream::badbit);
-}
-
-/**
- * Close any open journal files
- */
-Journal::~Journal()
-{
- stop_recording();
- stop_playback();
-}
-
-/**
- * Start recording events handed to us
- * \param filename File the events should be written to
- * \todo set the filename somewhere else
- */
-void Journal::start_recording(const std::string & filename)
-{
- assert(!m_recordstream.is_open());
-
- //TODO: m_recordname = FileSystem::FS_CanonicalizeName(filename);
- m_recordname = filename;
- if (m_recordname.empty())
- assert(false); //TODO: barf in a controlled way
-
- try {
- m_recordstream.open
- (m_recordname.c_str(), std::ios::binary|std::ios::trunc);
- write(RFC_MAGIC);
- m_recordstream << std::flush;
- m_record = true;
- log("Recording into %s\n", m_recordname.c_str());
- }
- catch (std::ofstream::failure &) {
- //TODO: use exception mask to find out what happened
- //TODO: there should be a messagebox to tell the user.
- log
- ("Problem while opening record file %s for writing.\n",
- m_recordname.c_str());
- stop_recording();
- throw Journalfile_error(m_recordname);
- }
-}
-
-/**
- * Stop recording events.
- * It's safe to call this even if recording has not been
- * started yet.
- */
-void Journal::stop_recording()
-{
- m_record = false;
-
- if (m_recordstream.is_open()) {
- m_recordstream<<std::flush;
- m_recordstream.close();
- }
-}
-
-/**
- * Start playing back events
- * \param filename File to get events from
- * \todo set the filename somewhere else
- */
-void Journal::start_playback(const std::string & filename)
-{
- assert(!m_playbackstream.is_open());
-
- //TODO: m_playbackname = FileSystem::FS_CanonicalizeName(filename);
- m_playbackname = filename;
- if (m_playbackname.empty())
- assert(false); //TODO: barf in a controlled way
-
- try {
- uint32_t magic;
-
- m_playbackstream.open(m_playbackname.c_str(), std::ios::binary);
- read(magic);
- if (magic != RFC_MAGIC)
- throw BadMagic_error(m_playbackname);
- m_playback = true;
- log("Playing back from %s\n", m_playbackname.c_str());
- }
- catch (std::ifstream::failure &) {
- //TODO: use exception mask to find out what happened
- //TODO: there should be a messagebox to tell the user.
- log
- ("ERROR: problem while opening playback file for reading. Playback "
- "deactivated.\n");
- stop_playback();
- throw Journalfile_error(m_recordname);
- }
-}
-
-/**
- * Stop playing back events.
- * It's safe to call this even if playback has not been
- * started yet.
- */
-void Journal::stop_playback()
-{
- m_playback = false;
-
- if (m_playbackstream.is_open()) {
- m_playbackstream.close();
- }
-}
-
-/**
- * Record an event into the playback file. This entails serializing the
- * event and writing it out.
- *
- * \param e The event to be recorded
- */
-void Journal::record_event(const SDL_Event & e)
-{
- if (!m_record)
- return;
-
- try {
- //Note: the following lines are *inside* the switch on purpose:
- // write(RFC_EVENT);
- // m_recordstream<<std::flush;
- //If they were outside, they'd get executed on every mainloop
- //iteration, which would yield a) huge files and b) lots of
- //completely unnecessary overhad.
- switch (e.type) {
- case SDL_KEYDOWN:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_KEYDOWN));
- write(e.key.keysym.mod);
- write(e.key.keysym.sym);
- write(e.key.keysym.unicode);
- m_recordstream << std::flush;
- break;
- case SDL_KEYUP:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_KEYUP));
- write(e.key.keysym.mod);
- write(e.key.keysym.sym);
- write(e.key.keysym.unicode);
- m_recordstream << std::flush;
- break;
- case SDL_MOUSEBUTTONDOWN:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_MOUSEBUTTONDOWN));
- write(e.button.button);
- write(e.button.x);
- write(e.button.y);
- write(e.button.state);
- m_recordstream << std::flush;
- break;
- case SDL_MOUSEBUTTONUP:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_MOUSEBUTTONUP));
- write(e.button.button);
- write(e.button.x);
- write(e.button.y);
- write(e.button.state);
- m_recordstream << std::flush;
- break;
- case SDL_MOUSEMOTION:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_MOUSEMOTION));
- write(e.motion.state);
- write(e.motion.x);
- write(e.motion.y);
- write(e.motion.xrel);
- write(e.motion.yrel);
- m_recordstream << std::flush;
- break;
- case SDL_QUIT:
- write(static_cast<uint8_t>(RFC_EVENT));
- write(static_cast<uint8_t>(RFC_QUIT));
- m_recordstream << std::flush;
- break;
- default:
- // can't really do anything useful with this event
- break;
- }
- }
- catch (const std::ofstream::failure &) {
- //TODO: use exception mask to find out what happened
- //TODO: there should be a messagebox to tell the user.
- log("Failed to write to record file. Recording deactivated.\n");
- stop_recording();
- throw Journalfile_error(m_recordname);
- }
-}
-
-/**
- * Get an event from the playback file. This entails creating an empty
- * event with sensible default values (not all parameters get recorded)
- * and deserializing the event record.
- *
- * \param e The event being returned
- */
-bool Journal::read_event(SDL_Event & e)
-{
- if (!m_playback)
- return false;
-
- bool haveevent = false;
-
- try {
- uint8_t recordtype;
- read(recordtype);
- switch (recordtype) {
- case RFC_EVENT:
- uint8_t eventtype;
- read(eventtype);
- switch (eventtype) {
- case RFC_KEYDOWN:
- e.type = SDL_KEYDOWN;
- read(e.key.keysym.mod);
- read(e.key.keysym.sym);
- read(e.key.keysym.unicode);
- break;
- case RFC_KEYUP:
- e.type = SDL_KEYUP;
- read(e.key.keysym.mod);
- read(e.key.keysym.sym);
- read(e.key.keysym.unicode);
- break;
- case RFC_MOUSEBUTTONDOWN:
- e.type = SDL_MOUSEBUTTONDOWN;
- read(e.button.button);
- read(e.button.x);
- read(e.button.y);
- read(e.button.state);
- break;
- case RFC_MOUSEBUTTONUP:
- e.type = SDL_MOUSEBUTTONUP;
- read(e.button.button);
- read(e.button.x);
- read(e.button.y);
- read(e.button.state);
- break;
- case RFC_MOUSEMOTION:
- e.type = SDL_MOUSEMOTION;
- read(e.motion.state);
- read(e.motion.x);
- read(e.motion.y);
- read(e.motion.xrel);
- read(e.motion.yrel);
- break;
- case RFC_QUIT:
- e.type = SDL_QUIT;
- break;
- default:
- throw BadEvent_error(m_playbackname, eventtype);
- }
-
- haveevent = true;
- break;
- case RFC_ENDEVENTS:
- //Do nothing
- break;
- default:
- throw BadRecord_error(m_playbackname, recordtype, RFC_INVALID);
- break;
- }
- } catch (const std::ifstream::failure &) {
- //TODO: use exception mask to find out what happened
- //TODO: there should be a messagebox to tell the user.
- log("Failed to read from journal file. Playback deactivated.\n");
- stop_playback();
- throw Journalfile_error(m_playbackname);
- }
-
- return haveevent;
-}
-
-/**
- * Do the right thing with timestamps.
- * All timestamps handled with \ref WLApplication::get_time() pass through here.
- * If necessary, they will be recorded. On playback, they will be modified to
- * show the recorded time instead of the current time.
- */
-void Journal::timestamp_handler(uint32_t & stamp)
-{
- if (m_record) {
- write(static_cast<uint8_t>(RFC_GETTIME));
- write(stamp);
- }
-
- if (m_playback) {
- ensure_code(static_cast<uint8_t>(RFC_GETTIME));
- read(stamp);
- }
-}
-
-/**
- * \todo document me
- */
-void Journal::set_idle_mark()
-{
- write(static_cast<uint8_t>(RFC_ENDEVENTS));
-}
=== removed file 'src/journal.h'
--- src/journal.h 2013-07-26 19:16:51 +0000
+++ src/journal.h 1970-01-01 00:00:00 +0000
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2006-2009 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef JOURNAL_H
-#define JOURNAL_H
-
-#include <cstring>
-#include <fstream>
-#include <string>
-
-#include <SDL_events.h>
-
-#include "journal_exceptions.h"
-
-/**
- * Journal encapsulates all operations that are necessary for recording and
- * playing back a session. On it's interface, it deals with SDL_Events that
- * might (or might not) be recorded/played back. Whether a recording / playback
- * is actually being performed is internal to Journal.
- *
- * \note If you are hacking this class, throw a Journalfile_exception only
- * and always if there is a nonrecoverable error and you have already dealt with
- * it.
- *
- * \todo The idea of writing enums into a file is bad: enums are int32_t and
- * int32_t varies in size (typ. 32/64bit). Our own codes only need 8bit, so we
- * force IO down to this value. The same happens with keyboard events at
- * 32 bits. Cutting off bits is not a good solution, but in this case it'll do
- * until a better way comes along.
- */
-struct Journal {
- /// change this and I will ensure your death will be a most unpleasant one
- static uint32_t const RFC_MAGIC = 0x0ACAD100;
-
- /**
- * Record file codes
- * It should be possible to use record files across different platforms.
- * However, 64 bit platforms are currently not supported.
- */
- enum rfccode {
- RFC_GETTIME = 0x01,
- RFC_EVENT = 0x02,
- RFC_ENDEVENTS = 0x03,
-
- RFC_KEYDOWN = 0x10,
- RFC_KEYUP = 0x11,
- RFC_MOUSEBUTTONDOWN = 0x12,
- RFC_MOUSEBUTTONUP = 0x13,
- RFC_MOUSEMOTION = 0x14,
- RFC_QUIT = 0x15,
- RFC_INVALID = 0xff
- };
-
-public:
- Journal();
- ~Journal();
-
- void start_recording(const std::string & filename = "widelands.jnl");
- void stop_recording();
- ///True if events are being recorded
- bool is_recording() const {return m_record;}
-
- void start_playback (const std::string & filename = "widelands.jnl");
- void stop_playback();
- ///True if events are being played back
- bool is_playingback() const {return m_playback;}
-
- void record_event(const SDL_Event &);
- bool read_event(SDL_Event &);
-
- void timestamp_handler(uint32_t & stamp);
- void set_idle_mark();
-
-protected:
- /**
- * Returns the position in the playback file
- * \return byte offset into the playback file, used with file reading
- */
- int32_t get_playback_offset() {return m_playbackstream.tellg();}
-
- void write(int8_t);
- void write(uint8_t);
- void write(int16_t);
- void write(uint16_t);
- void write(int32_t);
- void write(uint32_t);
- void write(SDLKey);
- void write(SDLMod);
-
- void read(int8_t &);
- void read(uint8_t &);
- void read(int16_t &);
- void read(uint16_t &);
- void read(int32_t &);
- void read(uint32_t &);
- void read(SDLKey &);
- void read(SDLMod &);
- void ensure_code(uint8_t code);
-
- ///The recording file's name.
- ///\note This does \e not go through the layered filesystem on purpose!
- std::string m_recordname;
-
- ///The playback file's name.
- ///\note This does \e not go through the layered filesystem on purpose!
- std::string m_playbackname;
-
- ///The file events are being recorded to
- std::ofstream m_recordstream;
-
- ///The file events are being played back from
- std::ifstream m_playbackstream;
-
- ///True if events are being recorded
- bool m_record;
-
- ///True if events are being played back
- bool m_playback;
-};
-
-#endif
=== removed file 'src/journal_exceptions.cc'
--- src/journal_exceptions.cc 2013-09-23 18:47:02 +0000
+++ src/journal_exceptions.cc 1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2006, 2008 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "journal_exceptions.h"
-
-#include "helper.h"
-
-Journalfile_error::Journalfile_error(const std::string & _filename)
-: std::runtime_error("Problem with journal file."), filename(_filename)
-{
- text = "Problem with journal file " + _filename;
-}
-
-///\todo Say _which_ magic number was found and which was expected
-BadMagic_error::BadMagic_error(const std::string & _filename)
-: Journalfile_error(_filename)
-{
- text = "Journal file " + _filename + " starts with bad magic number";
-}
-
-BadRecord_error::BadRecord_error
- (const std::string & _filename,
- uint8_t const _code,
- uint8_t const _expectedcode)
-: Journalfile_error(_filename), offset(0), code(_code), expectedcode(_expectedcode)
-{
- text = "Journal file ";
- text += _filename;
- text += " contains record with type ";
- text += toString(static_cast<int>(_code));
- text += " instead of the expected type ";
- text += toString(static_cast<int>(_expectedcode));
-}
-
-BadEvent_error::BadEvent_error
- (const std::string & _filename, uint8_t const _type)
-: Journalfile_error(_filename), offset(0), type(_type)
-{
- text = "Journal file '";
- text += _filename;
- text += "' contains record with unknown event type ";
- text += toString(_type);
-}
=== removed file 'src/journal_exceptions.h'
--- src/journal_exceptions.h 2014-02-22 18:04:02 +0000
+++ src/journal_exceptions.h 1970-01-01 00:00:00 +0000
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2006, 2008-2009 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef JOURNAL_EXCEPTIONS_H
-#define JOURNAL_EXCEPTIONS_H
-
-#include <stdexcept>
-#include <string>
-
-#include <stdint.h>
-
-///
-/// Thrown for IO-errors occurring with a journal file (unable to open file
-/// for any reason, out of space, etc.) that a) are unrecoverable and b)
-/// have already been dealt with.
-///
-/// This is a purely informational exception. Do not throw it unless it can
-/// safely be ignored.
-///
-/// \todo add offset into journal file if applicable
-/// \todo Rework as proposed by Erik, see filesystem_exceptions.h. Before that:
-/// Replace with File*_error where appropriate, migrate from runtime_error to
-/// logic_error (?)
-struct Journalfile_error : public std::runtime_error {
- explicit Journalfile_error(const std::string & filename);
- virtual ~Journalfile_error() throw () {}
-
- virtual char const * what() const throw () override {return text.c_str();}
-
- std::string text;
- std::string filename;
-};
-
-/**
- * Thrown if the journal file contains a bad magic number
- * \todo add offset into journal file
- */
-struct BadMagic_error : public Journalfile_error {
- explicit BadMagic_error(const std::string & filename);
- virtual ~BadMagic_error() throw () {}
-};
-
-/**
- * Thrown if the journal file contains a record with an unknown type number
- * \todo add offset into journal file
- */
-struct BadRecord_error : public Journalfile_error {
- explicit BadRecord_error
- (const std::string & filename,
- const uint8_t code,
- const uint8_t expectedcode)
- ;
- virtual ~BadRecord_error() throw () {}
-
- std::streamoff offset;
- uint8_t code;
- uint8_t expectedcode;
-};
-
-/**
- * Thrown if the journal file contains an event record with an unknown
- * event type
- * \todo add offset into journal file
- */
-struct BadEvent_error : public Journalfile_error {
- explicit BadEvent_error(const std::string & filename, uint8_t const type)
- ;
- virtual ~BadEvent_error() throw () {}
-
- std::streamoff offset;
- uint8_t type;
-};
-
-#endif
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2014-03-09 10:28:39 +0000
+++ src/wlapplication.cc 2014-03-11 20:33:30 +0000
@@ -48,7 +48,6 @@
#include "io/dedicated_log.h"
#include "io/filesystem/disk_filesystem.h"
#include "io/filesystem/layered_filesystem.h"
-#include "journal.h"
#include "log.h"
#include "logic/game.h"
#include "logic/game_data_error.h"
@@ -248,7 +247,6 @@
WLApplication::WLApplication(int const argc, char const * const * const argv) :
m_commandline (std::map<std::string, std::string>()),
m_game_type (NONE),
-journal (nullptr),
m_mouse_swapped (false),
m_faking_middle_mouse_button(false),
m_mouse_position (0, 0),
@@ -480,89 +478,54 @@
/**
* Get an event from the SDL queue, just like SDL_PollEvent.
- * Perform the meat of playback/record stuff when needed.
- *
- * Throttle is a hack to stop record files from getting extremely huge.
- * If it is set to true, we will idle loop if we can't get an SDL_Event
- * returned immediately if we're recording. If there is no user input,
- * the actual mainloop will be throttled to 100fps.
*
* \param ev the retrieved event will be put here
- * \param throttle Limit recording to 100fps max (not the event loop itself!)
*
* \return true if an event was returned inside ev, false otherwise
- *
- * \todo Catch Journalfile_error
*/
-bool WLApplication::poll_event(SDL_Event & ev, bool const throttle) {
+bool WLApplication::poll_event(SDL_Event & ev) {
bool haveevent = false;
+
+//FIXME (REVIEW): Can this be removed now? There was a line saying goto restart
+//around the part with lastthrottle. (Though I don't see how it would be called
+//when the lastthrottle variable would always be reinitialized there...?)
restart:
- //inject synthesized events into the event queue when playing back
- if (journal->is_playingback()) {
- try {
- haveevent = journal->read_event(ev);
- } catch (const Journalfile_error & e) {
- // An error might occur here when playing back a file that
- // was not finalized due to a crash etc.
- // Since playbacks are intended precisely for debugging such
- // crashes, we must ignore the error and continue.
- log("JOURNAL: read error, continue without playback: %s\n", e.what());
- journal->stop_playback();
+
+ haveevent = SDL_PollEvent(&ev);
+
+ if (haveevent) {
+ // We edit mouse motion events in here, so that
+ // differences caused by GrabInput or mouse speed
+ // settings are invisible to the rest of the code
+ switch (ev.type) {
+ case SDL_MOUSEMOTION:
+ ev.motion.xrel += m_mouse_compensate_warp.x;
+ ev.motion.yrel += m_mouse_compensate_warp.y;
+ m_mouse_compensate_warp = Point(0, 0);
+
+ if (m_mouse_locked) {
+ warp_mouse(m_mouse_position);
+
+ ev.motion.x = m_mouse_position.x;
+ ev.motion.y = m_mouse_position.y;
}
- } else {
- haveevent = SDL_PollEvent(&ev);
-
- if (haveevent) {
- // We edit mouse motion events in here, so that
- // differences caused by GrabInput or mouse speed
- // settings are invisible to the rest of the code
- switch (ev.type) {
- case SDL_MOUSEMOTION:
- ev.motion.xrel += m_mouse_compensate_warp.x;
- ev.motion.yrel += m_mouse_compensate_warp.y;
- m_mouse_compensate_warp = Point(0, 0);
-
- if (m_mouse_locked) {
- warp_mouse(m_mouse_position);
-
- ev.motion.x = m_mouse_position.x;
- ev.motion.y = m_mouse_position.y;
- }
-
- break;
- case SDL_USEREVENT:
- if (ev.user.code == CHANGE_MUSIC)
- g_sound_handler.change_music();
-
- break;
- case SDL_VIDEOEXPOSE:
- //log ("SDL Video Window expose event: %i\n", ev.expose.type);
- g_gr->update_fullscreen();
- break;
- default:;
- }
+
+ break;
+ case SDL_USEREVENT:
+ if (ev.user.code == CHANGE_MUSIC)
+ g_sound_handler.change_music();
+
+ break;
+ case SDL_VIDEOEXPOSE:
+ //log ("SDL Video Window expose event: %i\n", ev.expose.type);
+ g_gr->update_fullscreen();
+ break;
+ default:;
}
}
- // log all events into the journal file
- if (journal->is_recording()) {
- if (haveevent)
- journal->record_event(ev);
- else if (throttle && journal->is_playingback()) {
- // Implement the throttle to avoid very quick inner mainloops when
- // recoding a session
- static int32_t lastthrottle = 0;
- int32_t const time = SDL_GetTicks();
-
- if (time - lastthrottle < 10)
- goto restart;
-
- lastthrottle = time;
- }
-
- journal->set_idle_mark();
- } else if (haveevent) {
+ if (haveevent) {
// Eliminate any unhandled events to make sure that record and playback
// are _really_ the same. Yes I know, it's overly paranoid but hey...
switch (ev.type) {
@@ -587,7 +550,6 @@
*/
void WLApplication::handle_input(InputCallback const * cb)
{
- bool gotevents = false;
SDL_Event ev; // Valgrind says:
// Conditional jump or move depends on uninitialised value(s)
// at 0x407EEDA: (within /usr/lib/libSDL-1.2.so.0.11.0)
@@ -602,36 +564,11 @@
// by 0x81427A6: main (main.cc:39)
// We need to empty the SDL message queue always, even in playback mode
- // In playback mode, only F10 for premature exiting works
- if (journal->is_playingback()) {
- while (SDL_PollEvent(&ev)) {
- switch (ev.type) {
- case SDL_KEYDOWN:
- // get out of here quickly, overriding playback;
- // since this is the only key event that works, we don't guard
- // it by requiring Ctrl to be pressed.
- if (ev.key.keysym.sym == SDLK_F10)
- m_should_die = true;
- break;
- case SDL_QUIT:
- m_should_die = true;
- break;
- default:;
- }
- }
- }
+ // FIXME (REVIEW): Note the even in playback mode part. Is this still needed?
+ // And what about the stacktrace above?
// Usual event queue
- while (poll_event(ev, !gotevents)) {
-
- gotevents = true;
-
- // CAREFUL: Record files do not save the entire SDL_Event structure.
- // Therefore, playbacks are incomplete. When you change the following
- // code so that it uses previously unused fields in SDL_Event,
- // please also take a look at Journal::read_event and
- // Journal::record_event
-
+ while (poll_event(ev)) {
switch (ev.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
@@ -747,9 +684,6 @@
int32_t WLApplication::get_time() {
uint32_t time = SDL_GetTicks();
- // might change the time when playing back!
- journal->timestamp_handler(time);
-
return time;
}
@@ -758,20 +692,18 @@
/// SDL_WarpMouse() *will* create a mousemotion event, which we do not want. As
/// a workaround, we store the delta in m_mouse_compensate_warp and use that to
/// eliminate the motion event in poll_event()
-/// \todo Should this method have to care about playback at all???
+//FIXME (REVIEW): should more of this docstring be updated?
///
/// \param position The new mouse position
void WLApplication::warp_mouse(const Point position)
{
m_mouse_position = position;
- if (not journal->is_playingback()) { // don't warp anything during playback
- Point cur_position;
- SDL_GetMouseState(&cur_position.x, &cur_position.y);
- if (cur_position != position) {
- m_mouse_compensate_warp += cur_position - position;
- SDL_WarpMouse(position.x, position.y);
- }
+ Point cur_position;
+ SDL_GetMouseState(&cur_position.x, &cur_position.y);
+ if (cur_position != position) {
+ m_mouse_compensate_warp += cur_position - position;
+ SDL_WarpMouse(position.x, position.y);
}
}
@@ -786,9 +718,6 @@
*/
void WLApplication::set_input_grab(bool grab)
{
- if (journal->is_playingback())
- return; // ignore in playback mode
-
if (grab) {
SDL_WM_GrabInput(SDL_GRAB_ON);
} else {
@@ -842,10 +771,6 @@
*/
bool WLApplication::init_settings() {
- //create a journal so that handle_commandline_parameters can open the
- //journal files
- journal = new Journal();
-
//read in the configuration file
g_options.read("config", "global");
Section & s = g_options.pull_section("global");
@@ -927,10 +852,6 @@
} catch (...) {
log("WARNING: could not save configuration");
}
-
- assert(journal);
- delete journal;
- journal = nullptr;
}
/**
@@ -1280,34 +1201,6 @@
m_commandline.erase("script");
}
- // TODO(sirver): this framework has not been useful in a long time. Kill it.
- if (m_commandline.count("record")) {
- if (m_commandline["record"].empty())
- throw Parameter_error("ERROR: --record needs a filename!");
-
- try {
- journal->start_recording(m_commandline["record"]);
- } catch (Journalfile_error & e) {
- wout << "Journal file error: " << e.what() << endl;
- }
-
- m_commandline.erase("record");
- }
-
- if (m_commandline.count("playback")) {
- if (m_commandline["playback"].empty())
- throw Parameter_error("ERROR: --playback needs a filename!");
-
- try {
- journal->start_playback(m_commandline["playback"]);
- }
- catch (Journalfile_error & e) {
- wout << "Journal file error: " << e.what() << endl;
- }
-
- m_commandline.erase("playback");
- }
-
//If it hasn't been handled yet it's probably an attempt to
//override a conffile setting
//With typos, this will create invalid config settings. They
@@ -1351,9 +1244,7 @@
#ifdef __linux__
<< _(" Default is ~/.widelands") << "\n"
#endif
- << _(" --record=FILENAME Record all events to the given filename for\n"
- " later playback") << "\n"
- << _(" --playback=FILENAME Playback given filename (see --record)") << "\n\n"
+ << "\n"
<< _(" --coredump=[yes|no] Generates a core dump on segfaults instead\n"
" of using the SDL") << "\n"
<< _(" --language=[de_DE|sv_SE|...]\n"
=== modified file 'src/wlapplication.h'
--- src/wlapplication.h 2014-02-22 18:04:02 +0000
+++ src/wlapplication.h 2014-03-11 20:33:30 +0000
@@ -38,7 +38,6 @@
namespace Widelands {class Game;}
-struct Journal;
///Thrown if a commandline parameter is faulty
struct Parameter_error : public std::runtime_error {
@@ -233,7 +232,7 @@
protected:
WLApplication(int argc, char const * const * argv);
- bool poll_event(SDL_Event &, bool throttle);
+ bool poll_event(SDL_Event &);
bool init_settings();
void init_language();
@@ -271,8 +270,6 @@
std::string m_logfile;
GameType m_game_type;
- ///the event recorder object
- Journal * journal;
///True if left and right mouse button should be swapped
bool m_mouse_swapped;
Follow ups