Merge lp:~widelands-dev/widelands/map_revision_data into lp:widelands

Proposed by Teppo Mäenpää
Status: Merged
Merged at revision: 6756
Proposed branch: lp:~widelands-dev/widelands/map_revision_data
Merge into: lp:widelands
Diff against target: 381 lines (+270/-3)
8 files modified
src/logic/map.cc (+1/-1)
src/logic/map.h (+4/-0)
src/logic/map_revision.cc (+35/-0)
src/logic/map_revision.h (+51/-0)
src/map_io/widelands_map_loader.cc (+7/-1)
src/map_io/widelands_map_saver.cc (+8/-1)
src/map_io/widelands_map_version_data_packet.cc (+134/-0)
src/map_io/widelands_map_version_data_packet.h (+30/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/map_revision_data
Reviewer Review Type Date Requested Status
Nasenbaer Needs Fixing
SirVer Approve
Teppo Mäenpää Needs Resubmitting
Review via email: mp+184940@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
SirVer (sirver) wrote :

I only did a quick review for now - I think this can go into b18, but it needs some cleanups.

I suggest to refactor the map versioning stuff into a class of its own instead of having it all in Map. Map than only contains one member of this new class type. Map already has too many responsabilities. Also, the map could contain N of these to keep all revisions information around if this is desired - the original_author feels a little weird otherwise imho.

- m_map_source_url.clear(); and the line below are not necessary. strings start out empty.

- + * Copyright (C) 2002-2004, 2006-2008, 2010 by the Widelands Development Team
this is outdated. it's 2013.

- +#include <SDL_image.h>
in the new file this is not needed - some other includes might not be needed either. Please check this.

- there is already packet_version, why do you need packet_compatibility?

- widelands_map_version_data_packet.h
copyright and comments are wrong.

review: Needs Fixing
Revision history for this message
Teppo Mäenpää (kxq) wrote :

The _compatibility is needed for forward compatibility. If one would, for example, add a compelete history to map revision (suggestion of yours), in a way where the latest is store as before, then the older versions of the program could still read the map.

The alternative would lead to maps that cannot be loaded because of revision history. People downloading maps for their latest release would be less happy. I of course cannot know, but I would guess that people making maps also are more likely to download development snapshots than those just playing downloaded maps.

Revision history for this message
Teppo Mäenpää (kxq) wrote :

I tested yesterday's changes. No obvious errors popped up..

review: Needs Resubmitting
Revision history for this message
SirVer (sirver) wrote :

I think this looks good codewise now. Do you have plans to add the packet to the currently shipped maps or will this be delayed till after b18? Note that we might have this for some maps then (which are changed in the next few days) but not for others - not a big problem as long as all formats still load of course. So what are your plans for this now?

I have a few more nits. Feel free to merge this to trunk when you have addressed those.

map_version -> typenames are camlcased in Widelands. Either Map_Version, but much rather MapVersion (the first style is still all over Widelands, but is rather silly and very uncommon in the rest of the world).
m_map_source_url.clear() -> the clears in the constructor are unnecessary.
class map_version -> should be a struct MapVersion as you have no member functions and it really is a plain struct (minus the constructor, which is acceptable imho). If you have plans to make this more complex in the future though it might make sense to add getters/setters right now. Your call.

Thanks for taking ownership of this problem - I gladly see it go away.

Revision history for this message
SirVer (sirver) :
review: Approve
Revision history for this message
Nasenbaer (nasenbaer) wrote :

Your code looks good so far, however I disagree concerning "The _compatibility" - there is no need for a second variable - the compatibility is already defined through the packet version - to _compatibility is really not needed.

Further it would be great to have a real use case - a message box that tells the user if a map is incompatible. The case, where this will happen the most simply is, if a map was created with a newer widelands version. Therefore this would be great to have in build18 - maybe we can make it work until tomorrow evening :).

My idea would be to add up all packet versions of every packet of the map and use that number as compatibility check -> as soon as said number is higher in the map to be loaded than the same number of the used widelands build, the map is definitely incompatible, as at least one of the map packets has a newer version number. Widelands should now show a pop up telling the user that this map is incompatible and the map should not be selectable.

just my 5¢ ... however I have to come back to my first sentence: You did a good job here! I would just like to further improve it. :)

review: Needs Fixing
Revision history for this message
SirVer (sirver) wrote :

the _compatibility is needed for forward compatibility - i.e. b18 will be able to read maps that are made with 'later' versions too if we are careful. This is a good thing to have for maps I think.

And having this in maps now is useful in the future - so while a use case would be nice, I do not see it happening till tomorrow evening. But having b18 maps contain a version string might be useful for this feature in the future.

So I am still +1 for merging as is right now and go from there.

Revision history for this message
Teppo Mäenpää (kxq) wrote :

I had only this version file and the worries of SirVer, expressed in the bug discusssion, in mind while making the _compatibility flag.

I agree that a global forward compatibility handling would be useful, even for savegames, but that would require one additional processing layer to saving and loading. Since slowing down saving harms playing experience, I won't even start anything like that despite I in a way would like to.

Maybe the discussion should continue in bug #1210892 page?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map.cc'
2--- src/logic/map.cc 2013-09-03 18:46:02 +0000
3+++ src/logic/map.cc 2013-09-15 04:43:13 +0000
4@@ -22,6 +22,7 @@
5 #include <algorithm>
6 #include <cstdio>
7
8+#include "build_info.h"
9 #include "economy/flag.h"
10 #include "economy/road.h"
11 #include "editor/tools/editor_increase_resources_tool.h"
12@@ -44,7 +45,6 @@
13 #include "wui/overlay_manager.h"
14
15
16-
17 namespace Widelands {
18
19
20
21=== modified file 'src/logic/map.h'
22--- src/logic/map.h 2013-07-26 20:19:36 +0000
23+++ src/logic/map.h 2013-09-15 04:43:13 +0000
24@@ -30,6 +30,7 @@
25 #include "logic/field.h"
26 #include "interval.h"
27 #include "manager.h"
28+#include "logic/map_revision.h"
29 #include "logic/notification.h"
30 #include "logic/objective.h"
31 #include "random.h"
32@@ -124,6 +125,7 @@
33 friend struct WL_Map_Loader;
34 friend struct Map_Elemental_Data_Packet;
35 friend struct Map_Extradata_Data_Packet;
36+ friend struct Map_Version_Data_Packet;
37 friend class Editor;
38 friend struct Main_Menu_New_Map;
39 friend struct MapGenerator;
40@@ -433,6 +435,8 @@
41 void find_reachable(Area<FCoords>, const CheckStep &, functorT &);
42
43 template<typename functorT> void find(const Area<FCoords>, functorT &) const;
44+
45+ MapVersion m_map_version;
46 };
47
48
49
50=== added file 'src/logic/map_revision.cc'
51--- src/logic/map_revision.cc 1970-01-01 00:00:00 +0000
52+++ src/logic/map_revision.cc 2013-09-15 04:43:13 +0000
53@@ -0,0 +1,35 @@
54+/*
55+ * Copyright (C) 2013 by the Widelands Development Team
56+ *
57+ * This program is free software; you can redistribute it and/or
58+ * modify it under the terms of the GNU General Public License
59+ * as published by the Free Software Foundation; either version 2
60+ * of the License, or (at your option) any later version.
61+ *
62+ * This program is distributed in the hope that it will be useful,
63+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
64+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65+ * GNU General Public License for more details.
66+ *
67+ * You should have received a copy of the GNU General Public License
68+ * along with this program; if not, write to the Free Software
69+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70+ *
71+ */
72+
73+#include "logic/map_revision.h"
74+
75+#include "build_info.h"
76+
77+namespace Widelands {
78+
79+
80+MapVersion::MapVersion() :
81+m_map_version_major(0),
82+m_map_version_minor(0)
83+{
84+ m_map_creator_version = build_id();
85+ m_map_version_timestamp = static_cast<uint32_t>(time(NULL));
86+}
87+
88+}
89
90=== added file 'src/logic/map_revision.h'
91--- src/logic/map_revision.h 1970-01-01 00:00:00 +0000
92+++ src/logic/map_revision.h 2013-09-15 04:43:13 +0000
93@@ -0,0 +1,51 @@
94+/*
95+ * Copyright (C) 2013 by the Widelands Development Team
96+ *
97+ * This program is free software; you can redistribute it and/or
98+ * modify it under the terms of the GNU General Public License
99+ * as published by the Free Software Foundation; either version 2
100+ * of the License, or (at your option) any later version.
101+ *
102+ * This program is distributed in the hope that it will be useful,
103+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
104+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+ * GNU General Public License for more details.
106+ *
107+ * You should have received a copy of the GNU General Public License
108+ * along with this program; if not, write to the Free Software
109+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
110+ *
111+ */
112+
113+#ifndef MAP_REVISION_H
114+#define MAP_REVISION_H
115+
116+#include <cstring>
117+#include <memory>
118+#include <set>
119+#include <string>
120+#include <vector>
121+
122+namespace Widelands {
123+
124+
125+
126+
127+struct MapVersion {
128+
129+ std::string m_map_source_url;
130+ std::string m_map_source_release;
131+ std::string m_map_creator_version;
132+ int32_t m_map_version_major;
133+ int32_t m_map_version_minor;
134+ uint32_t m_map_version_timestamp;
135+
136+ MapVersion();
137+
138+};
139+
140+}
141+
142+
143+
144+#endif
145
146=== modified file 'src/map_io/widelands_map_loader.cc'
147--- src/map_io/widelands_map_loader.cc 2013-07-26 20:19:36 +0000
148+++ src/map_io/widelands_map_loader.cc 2013-09-15 04:43:13 +0000
149@@ -1,5 +1,5 @@
150 /*
151- * Copyright (C) 2002-2004, 2006-2008, 2010-2011 by the Widelands Development Team
152+ * Copyright (C) 2002-2004, 2006-2008, 2010-2011, 2013 by the Widelands Development Team
153 *
154 * This program is free software; you can redistribute it and/or
155 * modify it under the terms of the GNU General Public License
156@@ -52,6 +52,7 @@
157 #include "map_io/widelands_map_roaddata_data_packet.h"
158 #include "map_io/widelands_map_scripting_data_packet.h"
159 #include "map_io/widelands_map_terrain_data_packet.h"
160+#include "map_io/widelands_map_version_data_packet.h"
161 #include "map_io/widelands_map_ware_data_packet.h"
162 #include "map_io/widelands_map_waredata_data_packet.h"
163 #include "warning.h"
164@@ -198,6 +199,11 @@
165 {Map_Extradata_Data_Packet p; p.Read(m_fs, egbase, !scenario, *m_mol);}
166 log("done!\n ");
167
168+ log("Reading Map Version Data ... ");
169+ {Map_Version_Data_Packet p; p.Read(m_fs, egbase, !scenario, *m_mol);}
170+ log("done!\n ");
171+
172+
173 log("Reading Allowed Worker Types Data ... ");
174 {
175 Map_Allowed_Worker_Types_Data_Packet p;
176
177=== modified file 'src/map_io/widelands_map_saver.cc'
178--- src/map_io/widelands_map_saver.cc 2013-07-26 20:19:36 +0000
179+++ src/map_io/widelands_map_saver.cc 2013-09-15 04:43:13 +0000
180@@ -1,5 +1,5 @@
181 /*
182- * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team
183+ * Copyright (C) 2002-2004, 2006-2011, 2013 by the Widelands Development Team
184 *
185 * This program is free software; you can redistribute it and/or
186 * modify it under the terms of the GNU General Public License
187@@ -49,6 +49,7 @@
188 #include "map_io/widelands_map_roaddata_data_packet.h"
189 #include "map_io/widelands_map_scripting_data_packet.h"
190 #include "map_io/widelands_map_terrain_data_packet.h"
191+#include "map_io/widelands_map_version_data_packet.h"
192 #include "wexception.h"
193
194 namespace Widelands {
195@@ -114,6 +115,12 @@
196 {Map_Extradata_Data_Packet p; p.Write(m_fs, m_egbase, *m_mos);}
197 log("done!\n ");
198
199+ log("Writing Map Version ... ");
200+ {Map_Version_Data_Packet p; p.Write(m_fs, m_egbase, *m_mos);}
201+ log("done!\n ");
202+
203+
204+
205 const Map & map = m_egbase.map();
206
207 Player_Number const nr_players = map.get_nrplayers();
208
209=== added file 'src/map_io/widelands_map_version_data_packet.cc'
210--- src/map_io/widelands_map_version_data_packet.cc 1970-01-01 00:00:00 +0000
211+++ src/map_io/widelands_map_version_data_packet.cc 2013-09-15 04:43:13 +0000
212@@ -0,0 +1,134 @@
213+/*
214+ * Copyright (C) 2013 by the Widelands Development Team
215+ *
216+ * This program is free software; you can redistribute it and/or
217+ * modify it under the terms of the GNU General Public License
218+ * as published by the Free Software Foundation; either version 2
219+ * of the License, or (at your option) any later version.
220+ *
221+ * This program is distributed in the hope that it will be useful,
222+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
223+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
224+ * GNU General Public License for more details.
225+ *
226+ * You should have received a copy of the GNU General Public License
227+ * along with this program; if not, write to the Free Software
228+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
229+ *
230+ */
231+
232+#include "map_io/widelands_map_version_data_packet.h"
233+
234+#include "build_info.h"
235+#include "logic/editor_game_base.h"
236+#include "logic/game_data_error.h"
237+#include "logic/map.h"
238+#include "logic/widelands_fileread.h"
239+#include "logic/widelands_filewrite.h"
240+#include "profile/profile.h"
241+
242+namespace Widelands {
243+
244+#define CURRENT_PACKET_VERSION 1
245+
246+
247+void Map_Version_Data_Packet::Read
248+ (FileSystem & fs,
249+ Editor_Game_Base & egbase,
250+ bool const skip,
251+ Map_Map_Object_Loader &)
252+throw (_wexception)
253+{
254+ if (skip)
255+ return;
256+
257+ Profile prof;
258+ try {prof.read("version", 0, fs);} catch (...)
259+ {
260+ Map & map = egbase.map();
261+ map.m_map_version.m_map_version_timestamp = 0;
262+ map.m_map_version.m_map_creator_version = "unknown";
263+ return;
264+ }
265+
266+ try {
267+ Section & globv = prof.get_safe_section("global");
268+ int32_t const packet_version =
269+ globv.get_safe_int("packet_version");
270+ int32_t const forward_compatibility =
271+ globv.get_safe_int("packet_compatibility");
272+ if
273+ ((packet_version == CURRENT_PACKET_VERSION)
274+ || (packet_version > CURRENT_PACKET_VERSION && forward_compatibility <= CURRENT_PACKET_VERSION))
275+ {
276+ Map & map = egbase.map();
277+ map.m_map_version.m_map_source_url = globv.get_safe_string("map_source_url");
278+ map.m_map_version.m_map_source_release = globv.get_safe_string("map_release");
279+ map.m_map_version.m_map_creator_version = globv.get_safe_string("map_creator_version");
280+ map.m_map_version.m_map_version_major = globv.get_safe_int("map_version_major");
281+ map.m_map_version.m_map_version_minor = globv.get_safe_int("map_version_minor");
282+ uint32_t ts = static_cast<uint32_t>(globv.get_safe_int("map_version_timestamp"));
283+ map.m_map_version.m_map_version_timestamp = ts;
284+ } else
285+ throw game_data_error
286+ (_("unknown/unhandled version %u"), packet_version);
287+ } catch (const _wexception & e) {
288+ throw game_data_error(_("version: %s"), e.what());
289+ }
290+}
291+
292+
293+void Map_Version_Data_Packet::Write
294+ (FileSystem & fs, Editor_Game_Base & egbase, Map_Map_Object_Saver &)
295+throw (_wexception)
296+{
297+ Profile prof;
298+ Section & globs = prof.create_section("global");
299+
300+ // This writes the map revision information to savegame.
301+ // revision information is put into a separate file, assuming that
302+ // revision information for bundled maps would be written to the maps
303+ // on-the-fly by the build script. Therefore, we need a file which
304+ // will not go to Software Configuration Management.
305+
306+ // Maps come from three different sources:
307+ // - User makes those
308+ // - Maps are downloaded from widelands.org webpage
309+ // - Maps are bundled with releases.
310+ //
311+ // For maps that are downloaded from website,
312+ // map_source_url should be non-zero. I assume that
313+ // it is always widelands.org, but chose to put an url there for completeness.
314+ //
315+ // For maps bundled with a release, map_source_release should be non-empty,
316+ // preferably listing the release that the map came with.
317+ // For a map made by user, map_creator_version should list the version
318+ // that the map was done with.
319+ //
320+ // If there are many maps with a same name, the major version should be stepped.
321+ // This is mostly intended for maps downloaded from widelands.org
322+ // I also include minor number which is stepped at each save, and a timestamp.
323+ //
324+ // Note -- None of the version numbers are displayed anywhere. I intend to do something
325+ // about that in the future, and only make these pieces of data now so that most
326+ // running copies of widelands would be compatible and relay these data forward!
327+ //
328+ // For now, these are meaningless. Let's hope it will not stay that way!
329+
330+ // FIXME -- we could store the unix time in uint32, as a partial fix to 2038 problem.
331+ // There seems to be a get_safe_natural method, but not corresponding setter.
332+
333+ Map & map = egbase.map();
334+ globs.set_string("map_source_url", map.m_map_version.m_map_source_url);
335+ globs.set_string("map_release", map.m_map_version.m_map_source_release);
336+ globs.set_string("map_creator_version", map.m_map_version.m_map_creator_version);
337+ globs.set_int("map_version_major", map.m_map_version.m_map_version_major);
338+ globs.set_int("map_version_minor", 1 + map.m_map_version.m_map_version_minor);
339+ globs.set_int("map_version_timestamp", static_cast<uint32_t>(time(NULL)));
340+ globs.set_int("packet_version", CURRENT_PACKET_VERSION);
341+ globs.set_int("packet_compatibility", CURRENT_PACKET_VERSION);
342+
343+ prof.write("version", false, fs);
344+}
345+
346+}
347
348=== added file 'src/map_io/widelands_map_version_data_packet.h'
349--- src/map_io/widelands_map_version_data_packet.h 1970-01-01 00:00:00 +0000
350+++ src/map_io/widelands_map_version_data_packet.h 2013-09-15 04:43:13 +0000
351@@ -0,0 +1,30 @@
352+/*
353+ * Copyright (C) 2013 by the Widelands Development Team
354+ *
355+ * This program is free software; you can redistribute it and/or
356+ * modify it under the terms of the GNU General Public License
357+ * as published by the Free Software Foundation; either version 2
358+ * of the License, or (at your option) any later version.
359+ *
360+ * This program is distributed in the hope that it will be useful,
361+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
362+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
363+ * GNU General Public License for more details.
364+ *
365+ * You should have received a copy of the GNU General Public License
366+ * along with this program; if not, write to the Free Software
367+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
368+ *
369+ */
370+
371+#ifndef WIDELANDS_MAP_VERSION_DATA_PACKET_H
372+#define WIDELANDS_MAP_VERSION_DATA_PACKET_H
373+
374+#include "map_io/widelands_map_data_packet.h"
375+
376+/*
377+ * This packet contains the version information of the map.
378+ */
379+MAP_DATA_PACKET(Map_Version_Data_Packet);
380+
381+#endif

Subscribers

People subscribed via source and target branches

to status/vote changes: