widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #01611
[Merge] lp:~widelands-dev/widelands/map_revision_data into lp:widelands
Teppo Mäenpää has proposed merging lp:~widelands-dev/widelands/map_revision_data into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1210892 in widelands: "Map files should have a version number"
https://bugs.launchpad.net/widelands/+bug/1210892
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/map_revision_data/+merge/184940
Adds version data to map files.
not done yet:
- Bundled maps would not have version information, yet.
- Associated code with Widelands web page not even started yet.
- Version data is not displayed to the player anywhere.
See the bug discussion thread for more info.
--
https://code.launchpad.net/~widelands-dev/widelands/map_revision_data/+merge/184940
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/map_revision_data into lp:widelands.
=== modified file 'src/logic/map.cc'
--- src/logic/map.cc 2013-09-03 18:46:02 +0000
+++ src/logic/map.cc 2013-09-11 07:04:55 +0000
@@ -22,6 +22,7 @@
#include <algorithm>
#include <cstdio>
+#include "build_info.h"
#include "economy/flag.h"
#include "economy/road.h"
#include "editor/tools/editor_increase_resources_tool.h"
@@ -44,7 +45,6 @@
#include "wui/overlay_manager.h"
-
namespace Widelands {
@@ -71,9 +71,16 @@
m_starting_pos (0),
m_fields (0),
m_overlay_manager(0),
-m_pathfieldmgr (new PathfieldManager)
+m_pathfieldmgr (new PathfieldManager),
+m_map_version_major(0),
+m_map_version_minor(0)
{
m_worldname[0] = '\0';
+ m_map_source_url.clear();
+ m_map_source_release.clear();
+ m_map_creator_version_original = build_id();
+ m_map_creator_version_latest = build_id();
+ m_map_version_timestamp = static_cast<uint32_t>(time(NULL));
}
=== modified file 'src/logic/map.h'
--- src/logic/map.h 2013-07-26 20:19:36 +0000
+++ src/logic/map.h 2013-09-11 07:04:55 +0000
@@ -124,6 +124,7 @@
friend struct WL_Map_Loader;
friend struct Map_Elemental_Data_Packet;
friend struct Map_Extradata_Data_Packet;
+ friend struct Map_Version_Data_Packet;
friend class Editor;
friend struct Main_Menu_New_Map;
friend struct MapGenerator;
@@ -433,6 +434,16 @@
void find_reachable(Area<FCoords>, const CheckStep &, functorT &);
template<typename functorT> void find(const Area<FCoords>, functorT &) const;
+
+ // Map version information. Details in widelands_map_version_data_packet.cc
+ std::string m_map_source_url;
+ std::string m_map_source_release;
+ std::string m_map_creator_version_original;
+ std::string m_map_creator_version_latest;
+ int32_t m_map_version_major;
+ int32_t m_map_version_minor;
+ uint32_t m_map_version_timestamp;
+
};
=== modified file 'src/map_io/widelands_map_loader.cc'
--- src/map_io/widelands_map_loader.cc 2013-07-26 20:19:36 +0000
+++ src/map_io/widelands_map_loader.cc 2013-09-11 07:04:55 +0000
@@ -52,6 +52,7 @@
#include "map_io/widelands_map_roaddata_data_packet.h"
#include "map_io/widelands_map_scripting_data_packet.h"
#include "map_io/widelands_map_terrain_data_packet.h"
+#include "map_io/widelands_map_version_data_packet.h"
#include "map_io/widelands_map_ware_data_packet.h"
#include "map_io/widelands_map_waredata_data_packet.h"
#include "warning.h"
@@ -198,6 +199,11 @@
{Map_Extradata_Data_Packet p; p.Read(m_fs, egbase, !scenario, *m_mol);}
log("done!\n ");
+ log("Reading Map Version Data ... ");
+ {Map_Version_Data_Packet p; p.Read(m_fs, egbase, !scenario, *m_mol);}
+ log("done!\n ");
+
+
log("Reading Allowed Worker Types Data ... ");
{
Map_Allowed_Worker_Types_Data_Packet p;
=== modified file 'src/map_io/widelands_map_saver.cc'
--- src/map_io/widelands_map_saver.cc 2013-07-26 20:19:36 +0000
+++ src/map_io/widelands_map_saver.cc 2013-09-11 07:04:55 +0000
@@ -49,6 +49,7 @@
#include "map_io/widelands_map_roaddata_data_packet.h"
#include "map_io/widelands_map_scripting_data_packet.h"
#include "map_io/widelands_map_terrain_data_packet.h"
+#include "map_io/widelands_map_version_data_packet.h"
#include "wexception.h"
namespace Widelands {
@@ -114,6 +115,12 @@
{Map_Extradata_Data_Packet p; p.Write(m_fs, m_egbase, *m_mos);}
log("done!\n ");
+ log("Writing Map Version ... ");
+ {Map_Version_Data_Packet p; p.Write(m_fs, m_egbase, *m_mos);}
+ log("done!\n ");
+
+
+
const Map & map = m_egbase.map();
Player_Number const nr_players = map.get_nrplayers();
=== added file 'src/map_io/widelands_map_version_data_packet.cc'
--- src/map_io/widelands_map_version_data_packet.cc 1970-01-01 00:00:00 +0000
+++ src/map_io/widelands_map_version_data_packet.cc 2013-09-11 07:04:55 +0000
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2002-2004, 2006-2008, 2010 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 "map_io/widelands_map_version_data_packet.h"
+
+#include <SDL_image.h>
+
+#include "build_info.h"
+#include "graphic/graphic.h"
+#include "graphic/in_memory_image.h"
+#include "graphic/surface.h"
+#include "io/filewrite.h"
+#include "logic/editor_game_base.h"
+#include "logic/game_data_error.h"
+#include "logic/map.h"
+#include "logic/widelands_fileread.h"
+#include "logic/widelands_filewrite.h"
+#include "profile/profile.h"
+
+
+namespace Widelands {
+
+#define CURRENT_PACKET_VERSION 1
+
+
+void Map_Version_Data_Packet::Read
+ (FileSystem & fs,
+ Editor_Game_Base & egbase,
+ bool const skip,
+ Map_Map_Object_Loader &)
+throw (_wexception)
+{
+ if (skip)
+ return;
+
+ Profile prof;
+ try {prof.read("version", 0, fs);} catch (...)
+ {
+ Map & map = egbase.map();
+ map.m_map_version_timestamp = 0;
+ map.m_map_creator_version_original = "unknown";
+ map.m_map_creator_version_latest = "old";
+ return;
+ }
+
+ try {
+ Section & globv = prof.get_safe_section("global");
+ int32_t const packet_version =
+ globv.get_safe_int("packet_version");
+ int32_t const forward_compatibility =
+ globv.get_safe_int("packet_compatibility");
+ if
+ ((packet_version == CURRENT_PACKET_VERSION)
+ || (packet_version > CURRENT_PACKET_VERSION && forward_compatibility <= CURRENT_PACKET_VERSION))
+ {
+ Map & map = egbase.map();
+ map.m_map_source_url = globv.get_safe_string("map_source_url");
+ map.m_map_source_release = globv.get_safe_string("map_release");
+ map.m_map_creator_version_original = globv.get_safe_string("map_creator_version_original");
+ map.m_map_creator_version_latest = globv.get_safe_string("map_creator_version_latest");
+ map.m_map_version_major = globv.get_safe_int("map_version_major");
+ map.m_map_version_minor = globv.get_safe_int("map_version_minor");
+ map.m_map_version_timestamp = static_cast<uint32_t>(globv.get_safe_int("map_version_timestamp"));
+ } else
+ throw game_data_error
+ (_("unknown/unhandled version %u"), packet_version);
+ } catch (const _wexception & e) {
+ throw game_data_error(_("version: %s"), e.what());
+ }
+}
+
+
+void Map_Version_Data_Packet::Write
+ (FileSystem & fs, Editor_Game_Base & egbase, Map_Map_Object_Saver &)
+throw (_wexception)
+{
+ Profile prof;
+ Section & globs = prof.create_section("global");
+
+ // This writes the map revision information to savegame.
+ // revision information is put into a separate file, assuming that
+ // revision information for bundled maps would be written to the maps
+ // on-the-fly by the build script. Therefore, we need a file which
+ // will not go to Software Configuration Management.
+
+ // Maps come from three different sources:
+ // - User makes those
+ // - Maps are downloaded from widelands.org webpage
+ // - Maps are bundled with releases.
+ //
+ // For maps that are downloaded from website,
+ // map_source_url should be non-zero. I assume that
+ // it is always widelands.org, but chose to put an url there for completeness.
+ //
+ // FOr maps bundled with a release, map_source_release should be non-empty,
+ // preferably listing the release that the map came with.
+ // For a map made by user, map_creator_version should list the version
+ // that the map was done with.
+ //
+ // If there are many maps with a same name, the major version should be stepped.
+ // This is mostly intended for maps downloaded from widelands.org
+ // I also include minor number which is stepped at each save, and a timestamp.
+ //
+ // Note -- None of the version numbers are displayed anywhere. I intend to do something
+ // about that in the future, and only make these pieces of data now so that most
+ // running copies of widelands would be compatible and relay these data forward!
+ //
+ // For now, these are meaningless. Let's hope it will not stay that way!
+
+ Map & map = egbase.map();
+ globs.set_string("map_source_url", map.m_map_source_url);
+ globs.set_string("map_release", map.m_map_source_release);
+ globs.set_string("map_creator_version_original", map.m_map_creator_version_original);
+ globs.set_string("map_creator_version_latest", build_id() + "(" + build_type() + ")");
+ globs.set_int("map_version_major", map.m_map_version_major);
+ globs.set_int("map_version_minor", 1 + map.m_map_version_minor);
+ globs.set_int("map_version_timestamp", static_cast<uint32_t>(time(NULL)));
+ globs.set_int("packet_version", CURRENT_PACKET_VERSION);
+ globs.set_int("packet_compatibility", CURRENT_PACKET_VERSION);
+
+ prof.write("version", false, fs);
+}
+
+}
=== added file 'src/map_io/widelands_map_version_data_packet.h'
--- src/map_io/widelands_map_version_data_packet.h 1970-01-01 00:00:00 +0000
+++ src/map_io/widelands_map_version_data_packet.h 2013-09-11 07:04:55 +0000
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 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 WIDELANDS_MAP_VERSION_DATA_PACKET_H
+#define WIDELANDS_MAP_VERSION_DATA_PACKET_H
+
+#include "map_io/widelands_map_data_packet.h"
+
+/*
+ * This packet contains all extra data in the map. This can currently be one of
+ * the followings
+ * - Images
+ */
+MAP_DATA_PACKET(Map_Version_Data_Packet);
+
+#endif
Follow ups