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

Proposed by SirVer
Status: Merged
Merged at revision: 7114
Proposed branch: lp:~widelands-dev/widelands/map_information
Merge into: lp:widelands
Diff against target: 1281 lines (+257/-628)
16 files modified
src/game_io/game_preload_data_packet.cc (+2/-3)
src/graphic/colormap.cc (+4/-7)
src/graphic/colormap.h (+13/-8)
src/graphic/graphic.cc (+3/-4)
src/graphic/render/minimaprenderer.cc (+40/-56)
src/graphic/render/minimaprenderer.h (+36/-22)
src/graphic/texture.cc (+20/-56)
src/graphic/texture.h (+2/-2)
src/logic/CMakeLists.txt (+15/-0)
src/logic/map.cc (+1/-2)
src/logic/map_info.cc (+78/-0)
src/third_party/CMakeLists.txt (+0/-1)
src/third_party/README (+7/-0)
src/third_party/eris/luac.c (+0/-432)
src/wui/minimap.cc (+26/-28)
src/wui/minimap.h (+10/-7)
To merge this branch: bzr merge lp:~widelands-dev/widelands/map_information
Reviewer Review Type Date Requested Status
SirVer Needs Resubmitting
Review via email: mp+226572@code.launchpad.net

Description of the change

Suggested submit message:

-----
- Add a stand alone tool logic/map_info that can render minimaps.
The upload of maps on the homepage is broken right now. This was triggered through the one-world refactoring, but it is due to the homepage not using Widelands code, but reimplementing everything (including minimap generation) in python from scratch. This second implementation broke. This tool should help to consolidate code paths. I am investigating using boost python for binding to python, so that this can be turned in a python library directly.
- Fixes a bug in minimap rendering code: software rendering was sometimes using the wrong colors.
- Refactor to minimap rendering to not depend on wui.
- Minor refactorings.
-----

To post a comment you must log in.
Revision history for this message
Hans Joachim Desserud (hjd) wrote :

Sounds interesting, and it definitely sounds like a good idea to have a single(, working) implementation for how maps are drawn. Could you give some more details on how you see this being handled on the website-side, and what will be needed there?

Does this handle old (separate world) maps too? (Will likely be fewer of those added once build19 is out, but you never know)

I see that a file in eris has been removed. While that might be the right action, I wonder why it happened in this branch. I also think changes like this should be documented in a way in third_party when we need to sync/pull in the latest version of eris, we have complete track of any changes and/or patches we have done.

Revision history for this message
SirVer (sirver) wrote :

> Could you give some more details on how you see this being handled on the website-side, and what will be needed there?

The code is needed on upload of a map to wl.widelands.org/maps. It has to verify that a map is valid, if it is post one_world (i.e. only working with >= dev and b19) or pre (all versions) of Widelands and extract the minimap image and a bunch of map informations that must get to the database.

There are two ways to go about this:

1) either modify the map_info tool to be a python module using boost python (that will add a dependency to boost python to Widelands) or
2) run the stand alone tool on uploads. It can dump its information to some directory from were the website can read it.

I think 1 is the way to go - but I am unsure if boost.python is a reasonable dependency, especially since we do not use it for anything but the homepage (so most people will not even benefit from it).

> Does this handle old (separate world) maps too? (Will likely be fewer of those added once build19 is out, but you never know)

Yes. It is using Widelands map loading code which can deal with that.

> [eris main removed].
I removed the file that was the stand alone lua() binary. It defined a main() function which could hide our own main() eris was linked in.

I added a comment to third_party/README about that.

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

Anyone?

Revision history for this message
SirVer (sirver) wrote :

I'll go ahead and merge this now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/game_io/game_preload_data_packet.cc'
2--- src/game_io/game_preload_data_packet.cc 2014-06-18 17:11:08 +0000
3+++ src/game_io/game_preload_data_packet.cc 2014-07-17 13:30:57 +0000
4@@ -114,12 +114,11 @@
5 return;
6 }
7 if (ipl != nullptr) {
8- MiniMapRenderer mmr;
9- const uint32_t flags = MiniMap::Owner | MiniMap::Bldns | MiniMap::Terrn;
10+ const MiniMapLayer flags = MiniMapLayer::Owner | MiniMapLayer::Building | MiniMapLayer::Terrain;
11 const Point& vp = ipl->get_viewpoint();
12 std::unique_ptr< ::StreamWrite> sw(fs.OpenStreamWrite(MINIMAP_FILENAME));
13 if (sw.get() != nullptr) {
14- mmr.write_minimap_image(game, &ipl->player(), vp, flags, sw.get());
15+ write_minimap_image(game, &ipl->player(), vp, flags, sw.get());
16 sw->Flush();
17 }
18 }
19
20=== modified file 'src/graphic/colormap.cc'
21--- src/graphic/colormap.cc 2014-07-14 10:45:44 +0000
22+++ src/graphic/colormap.cc 2014-07-17 13:30:57 +0000
23@@ -19,6 +19,7 @@
24
25 #include "graphic/colormap.h"
26
27+#include <algorithm>
28 #include <cassert>
29 #include <cstdlib>
30 #include <cstring>
31@@ -38,13 +39,9 @@
32 int32_t shade = (j < 128) ? j : (j - 256);
33 shade = 256 + 2 * shade;
34
35- int32_t r = (palette[i].r * shade) >> 8;
36- int32_t g = (palette[i].g * shade) >> 8;
37- int32_t b = (palette[i].b * shade) >> 8;
38-
39- if (r > 255) r = 255;
40- if (g > 255) g = 255;
41- if (b > 255) b = 255;
42+ const uint32_t r = std::min<uint32_t>((palette[i].r * shade) >> 8, 255);
43+ const uint32_t g = std::min<uint32_t>((palette[i].g * shade) >> 8, 255);
44+ const uint32_t b = std::min<uint32_t>((palette[i].b * shade) >> 8, 255);
45
46 const uint32_t value =
47 SDL_MapRGB(&const_cast<SDL_PixelFormat &>(format), r, g, b);
48
49=== modified file 'src/graphic/colormap.h'
50--- src/graphic/colormap.h 2014-07-05 16:41:51 +0000
51+++ src/graphic/colormap.h 2014-07-17 13:30:57 +0000
52@@ -22,10 +22,23 @@
53
54 #include <SDL_video.h>
55
56+#include "graphic/color.h"
57+
58 /**
59 * Colormap contains a palette and lookup table for use with ground textures.
60 */
61 class Colormap {
62+public:
63+ Colormap (const SDL_Color &, const SDL_PixelFormat & fmt);
64+ ~Colormap ();
65+
66+ // Returns the palette of this colormap (256 entries of RGB Colors);
67+ SDL_Color * get_palette() {return palette;}
68+
69+ // Returns the internally calculated colormap used in the renderer.
70+ void * get_colormap () const {return colormap;}
71+
72+private:
73 SDL_Color palette[256];
74
75 /// maps 8 bit color and brightness value to the shaded color.
76@@ -33,14 +46,6 @@
77 /// less shades would greatly reduce the size of this table, and thus
78 /// improve memory cache impact inside the renderer.
79 void * colormap;
80-
81-public:
82- Colormap (const SDL_Color &, const SDL_PixelFormat & fmt);
83- ~Colormap ();
84-
85- SDL_Color * get_palette() {return palette;}
86-
87- void * get_colormap () const {return colormap;}
88 };
89
90 #endif // end of include guard: WL_GRAPHIC_COLORMAP_H
91
92=== modified file 'src/graphic/graphic.cc'
93--- src/graphic/graphic.cc 2014-07-14 10:45:44 +0000
94+++ src/graphic/graphic.cc 2014-07-17 13:30:57 +0000
95@@ -80,13 +80,12 @@
96 {
97 ImageTransformations::initialize();
98
99- FileRead fr;
100 #ifndef _WIN32
101- fr.Open(*g_fs, "pics/wl-ico-128.png");
102+ const std::string icon_name = "pics/wl-ico-128.png";
103 #else
104- fr.Open(*g_fs, "pics/wl-ico-32.png");
105+ const std::string icon_name = "pics/wl-ico-32.png";
106 #endif
107- SDL_Surface * s = IMG_Load_RW(SDL_RWFromMem(fr.Data(0), fr.GetSize()), 1);
108+ SDL_Surface* s = load_image_as_sdl_surface(icon_name, g_fs);
109 SDL_WM_SetIcon(s, nullptr);
110 SDL_FreeSurface(s);
111 }
112
113=== modified file 'src/graphic/render/minimaprenderer.cc'
114--- src/graphic/render/minimaprenderer.cc 2014-07-14 10:45:44 +0000
115+++ src/graphic/render/minimaprenderer.cc 2014-07-17 13:30:57 +0000
116@@ -36,7 +36,6 @@
117 #include "logic/world/world.h"
118 #include "wui/mapviewpixelconstants.h"
119 #include "wui/mapviewpixelfunctions.h"
120-#include "wui/minimap.h"
121
122 using namespace Widelands;
123
124@@ -56,24 +55,20 @@
125 // Returns the color to be used in the minimap for the given field.
126 inline uint32_t calc_minimap_color
127 (const SDL_PixelFormat& format, const Widelands::Editor_Game_Base& egbase,
128- const Widelands::FCoords& f, uint32_t flags, Widelands::Player_Number owner,
129+ const Widelands::FCoords& f, MiniMapLayer layers, Widelands::Player_Number owner,
130 bool see_details)
131 {
132 uint32_t pixelcolor = 0;
133
134- if (flags & MiniMap::Terrn) {
135- // We or with format.Amask here because the terrain map texture data is
136- // only RGB and not RGBA in SDL render mode. Or'ing with Amask guarantees
137- // that alpha is set to 255 for this color and is fast.
138- pixelcolor =
139- g_gr->
140- get_maptexture_data
141- (egbase.world()
142- .terrain_descr(f.field->terrain_d()).get_texture())
143- ->get_minimap_color(f.field->get_brightness()) | format.Amask;
144+ if (layers & MiniMapLayer::Terrain) {
145+ const RGBColor color =
146+ g_gr->get_maptexture_data(egbase.world().terrain_descr(f.field->terrain_d()).get_texture())
147+ ->get_minimap_color(f.field->get_brightness());
148+
149+ pixelcolor = SDL_MapRGBA(&format, color.r, color.g, color.b, 255);
150 }
151
152- if (flags & MiniMap::Owner) {
153+ if (layers & MiniMapLayer::Owner) {
154 if (0 < owner) { // If owned, get the player's color...
155 const RGBColor & player_color = egbase.player(owner).get_playercolor();
156
157@@ -92,14 +87,14 @@
158 // * winterland -> orange
159
160 if (upcast(PlayerImmovable const, immovable, f.field->get_immovable())) {
161- if ((flags & MiniMap::Roads) and dynamic_cast<Road const *>(immovable)) {
162+ if ((layers & MiniMapLayer::Road) and dynamic_cast<Road const *>(immovable)) {
163 pixelcolor = blend_color(format, pixelcolor, 255, 255, 255);
164 }
165
166 if
167- (((flags & MiniMap::Flags) and dynamic_cast<Flag const *>(immovable))
168+ (((layers & MiniMapLayer::Flag) and dynamic_cast<Flag const *>(immovable))
169 or
170- ((flags & MiniMap::Bldns)
171+ ((layers & MiniMapLayer::Building)
172 and
173 dynamic_cast<Widelands::Building const *>(immovable)))
174 {
175@@ -160,7 +155,7 @@
176 // Does the actual work of drawing the minimap.
177 void draw_minimap_int
178 (Surface* surface, const Widelands::Editor_Game_Base& egbase,
179- const Widelands::Player* player, const Point& viewpoint, uint32_t flags)
180+ const Widelands::Player* player, const Point& viewpoint, MiniMapLayer layers)
181 {
182 const Widelands::Map & map = egbase.map();
183
184@@ -197,24 +192,23 @@
185 uint8_t * pix = pixels + y * pitch;
186 Widelands::FCoords f
187 (Widelands::Coords
188- (viewpoint.x, viewpoint.y + (flags & MiniMap::Zoom2 ? y / 2 : y)));
189+ (viewpoint.x, viewpoint.y + (layers & MiniMapLayer::Zoom2 ? y / 2 : y)));
190 map.normalize_coords(f);
191 f.field = &map[f];
192 Widelands::Map_Index i = Widelands::Map::get_index(f, mapwidth);
193 for (uint32_t x = 0; x < surface_w; ++x, pix += sizeof(uint32_t)) {
194- if (x % 2 || !(flags & MiniMap::Zoom2))
195+ if (x % 2 || !(layers & MiniMapLayer::Zoom2))
196 move_r(mapwidth, f, i);
197
198- if
199- (is_minimap_frameborder
200- (f, ptopleft, pbottomright, mapwidth, mapheight, modx, mody))
201- {
202+ if ((layers & MiniMapLayer::ViewWindow) &&
203+ is_minimap_frameborder(
204+ f, ptopleft, pbottomright, mapwidth, mapheight, modx, mody)) {
205 *reinterpret_cast<uint32_t *>(pix) = static_cast<uint32_t>
206 (SDL_MapRGB(&const_cast<SDL_PixelFormat &>(format), 255, 0, 0));
207 } else {
208 *reinterpret_cast<uint32_t *>(pix) = static_cast<uint32_t>
209 (calc_minimap_color
210- (format, egbase, f, flags, f.field->get_owned_by(), true));
211+ (format, egbase, f, layers, f.field->get_owned_by(), true));
212 }
213 }
214 }
215@@ -225,18 +219,17 @@
216 Widelands::FCoords f
217 (Widelands::Coords
218 (viewpoint.x, viewpoint.y +
219- (flags & MiniMap::Zoom2 ? y / 2 : y)));
220+ (layers & MiniMapLayer::Zoom2 ? y / 2 : y)));
221 map.normalize_coords(f);
222 f.field = &map[f];
223 Widelands::Map_Index i = Widelands::Map::get_index(f, mapwidth);
224 for (uint32_t x = 0; x < surface_w; ++x, pix += sizeof(uint32_t)) {
225- if (x % 2 || !(flags & MiniMap::Zoom2))
226+ if (x % 2 || !(layers & MiniMapLayer::Zoom2))
227 move_r(mapwidth, f, i);
228
229- if
230- (is_minimap_frameborder
231- (f, ptopleft, pbottomright, mapwidth, mapheight, modx, mody))
232- {
233+ if ((layers & MiniMapLayer::ViewWindow) &&
234+ is_minimap_frameborder(
235+ f, ptopleft, pbottomright, mapwidth, mapheight, modx, mody)) {
236 *reinterpret_cast<uint32_t *>(pix) = static_cast<uint32_t>
237 (SDL_MapRGB
238 (&const_cast<SDL_PixelFormat &>(format), 255, 0, 0));
239@@ -251,7 +244,7 @@
240 (format,
241 egbase,
242 f,
243- flags,
244+ layers,
245 player_field.owner,
246 1 < vision)
247 :
248@@ -262,19 +255,20 @@
249 }
250 }
251
252-// A helper function to draw the minimap. This is called from
253-// renderminimap().
254-Surface* draw_minimap
255- (const Widelands::Editor_Game_Base& egbase, const Widelands::Player* player,
256- const Point& viewpt, uint32_t flags)
257-{
258+
259+} // namespace
260+
261+std::unique_ptr<Surface> draw_minimap(const Editor_Game_Base& egbase,
262+ const Player* player,
263+ const Point& viewpoint,
264+ MiniMapLayer layers) {
265 // First create a temporary SDL Surface to draw the minimap.
266 // TODO: Currently the minimap is redrawn every frame. That is not really
267 // necesary. The created surface could be cached and only redrawn two
268 // or three times per second
269 const Map& map = egbase.map();
270- const int16_t map_w = (flags & MiniMap::Zoom2) ? map.get_width() * 2 : map.get_width();
271- const int16_t map_h = (flags & MiniMap::Zoom2) ? map.get_height() * 2 : map.get_height();
272+ const int16_t map_w = (layers & MiniMapLayer::Zoom2) ? map.get_width() * 2 : map.get_width();
273+ const int16_t map_h = (layers & MiniMapLayer::Zoom2) ? map.get_height() * 2 : map.get_height();
274
275 Surface* surface = Surface::create(map_w, map_h);
276 assert(surface->format().BytesPerPixel == sizeof(uint32_t));
277@@ -282,24 +276,15 @@
278 surface->fill_rect(Rect(0, 0, surface->width(), surface->height()), RGBAColor(0, 0, 0, 255));
279 surface->lock(Surface::Lock_Normal);
280
281- draw_minimap_int(surface, egbase, player, viewpt, flags);
282+ draw_minimap_int(surface, egbase, player, viewpoint, layers);
283
284 surface->unlock(Surface::Unlock_Update);
285
286- return surface;
287-}
288-
289-} // namespace
290-
291-Surface* MiniMapRenderer::get_minimap_image
292- (const Editor_Game_Base& egbase, const Player* player, const Point& viewpoint, uint32_t flags)
293-{
294- Surface* minimap_surf = draw_minimap(egbase, player, viewpoint, flags);
295- return minimap_surf;
296-}
297-
298-void MiniMapRenderer::write_minimap_image
299- (const Editor_Game_Base& egbase, const Player* player, const Point& gviewpoint, uint32_t flags,
300+ return std::unique_ptr<Surface>(surface);
301+}
302+
303+void write_minimap_image
304+ (const Editor_Game_Base& egbase, const Player* player, const Point& gviewpoint, MiniMapLayer layers,
305 ::StreamWrite* const streamwrite)
306 {
307 assert(streamwrite != nullptr);
308@@ -324,8 +309,7 @@
309 viewpoint.y -= map_h / 2;
310
311 // Render minimap
312- std::unique_ptr<Surface> surface
313- (get_minimap_image(egbase, player, viewpoint, flags));
314+ std::unique_ptr<Surface> surface(draw_minimap(egbase, player, viewpoint, layers));
315 std::unique_ptr<const Image> image(new_in_memory_image("minimap", surface.release()));
316 g_gr->save_png(image.get(), streamwrite);
317 image.reset();
318
319=== modified file 'src/graphic/render/minimaprenderer.h'
320--- src/graphic/render/minimaprenderer.h 2014-07-05 16:41:51 +0000
321+++ src/graphic/render/minimaprenderer.h 2014-07-17 13:30:57 +0000
322@@ -20,36 +20,50 @@
323 #ifndef WL_GRAPHIC_RENDER_MINIMAPRENDERER_H
324 #define WL_GRAPHIC_RENDER_MINIMAPRENDERER_H
325
326+#include <memory>
327+
328 #include "graphic/rendertarget.h"
329-#include <memory>
330
331 class StreamWrite;
332+
333 namespace Widelands {
334 class Player;
335 class Editor_Game_Base;
336 }
337
338-/**
339- * This class renders the minimap.
340- */
341-class MiniMapRenderer
342-{
343-public:
344- MiniMapRenderer() {}
345- virtual ~MiniMapRenderer() {}
346-
347- /// Render the minimap. If player is not 0, it renders from that player's
348- /// point of view. The caller must dispose of the returned surface properly.
349- /// \param viewpoint: top left corner in map coordinates
350- Surface* get_minimap_image
351- (const Widelands::Editor_Game_Base& egbase, const Widelands::Player* player,
352- const Point& viewpoint, uint32_t flags);
353-
354- /// Render the minimap to a file. 1 pixel will be used for each fields.
355- /// \param viewpoint : The game point of view as returned by interactive_base.get_viewpoint();
356- void write_minimap_image
357- (const Widelands::Editor_Game_Base& egbase, Widelands::Player const* player,
358- const Point& viewpoint, uint32_t flags, StreamWrite* const streamwrite);
359+// Layers for selecting what do display on the minimap.
360+enum class MiniMapLayer {
361+ Terrain = 1,
362+ Owner = 2,
363+ Flag = 4,
364+ Road = 8,
365+ Building = 16,
366+ Zoom2 = 32,
367+ ViewWindow = 64,
368 };
369
370+// A bunch of operators that turn MiniMapLayer into a bitwise combinable flag class.
371+inline MiniMapLayer operator|(MiniMapLayer left, MiniMapLayer right) {
372+ return MiniMapLayer(static_cast<int>(left) | static_cast<int>(right));
373+}
374+inline int operator&(MiniMapLayer left, MiniMapLayer right) {
375+ return static_cast<int>(left) & static_cast<int>(right);
376+}
377+inline MiniMapLayer operator ^ (MiniMapLayer left, MiniMapLayer right) {
378+ return MiniMapLayer(static_cast<int>(left) ^ static_cast<int>(right));
379+}
380+
381+/// Render the minimap. If player is not nullptr, it renders from that player's
382+/// point of view.
383+/// \param viewpoint: top left corner in map coordinates
384+std::unique_ptr<Surface> draw_minimap
385+ (const Widelands::Editor_Game_Base& egbase, const Widelands::Player* player,
386+ const Point& viewpoint, MiniMapLayer layers);
387+
388+/// Render the minimap to a file. 1 pixel will be used for each fields.
389+/// \param viewpoint : The game point of view as returned by interactive_base.get_viewpoint();
390+void write_minimap_image
391+ (const Widelands::Editor_Game_Base& egbase, Widelands::Player const* player,
392+ const Point& viewpoint, MiniMapLayer layers, StreamWrite* const streamwrite);
393+
394 #endif // end of include guard: WL_GRAPHIC_RENDER_MINIMAPRENDERER_H
395
396=== modified file 'src/graphic/texture.cc'
397--- src/graphic/texture.cc 2014-07-14 10:45:44 +0000
398+++ src/graphic/texture.cc 2014-07-17 13:30:57 +0000
399@@ -24,6 +24,7 @@
400 #include "base/deprecated.h"
401 #include "base/log.h"
402 #include "base/wexception.h"
403+#include "graphic/image_io.h"
404 #include "io/fileread.h"
405 #include "io/filesystem/layered_filesystem.h"
406
407@@ -54,12 +55,8 @@
408 throw wexception("Could not find %s.", fname.c_str());
409 }
410
411- SDL_Surface * surf;
412 m_texture_image = fname;
413- FileRead fr;
414- fr.Open(*g_fs, fname);
415-
416- surf = IMG_Load_RW(SDL_RWFromMem(fr.Data(0), fr.GetSize()), 1);
417+ SDL_Surface* surf = load_image_as_sdl_surface(fname, g_fs);
418 if (!surf) {
419 throw wexception("WARNING: Failed to load texture frame %s: %s\n", fname.c_str(), IMG_GetError());
420 }
421@@ -71,61 +68,34 @@
422 TEXTURE_HEIGHT);
423 }
424
425+ // calculate shades on the first frame
426+ if (!m_nrframes) {
427+ uint8_t top_left_pixel = static_cast<uint8_t*>(surf->pixels)[0];
428+ SDL_Color top_left_pixel_color = surf->format->palette->colors[top_left_pixel];
429+ for (int i = -128; i < 128; i++) {
430+ const int shade = 128 + i;
431+ int32_t r = std::min<int32_t>((top_left_pixel_color.r * shade) >> 7, 255);
432+ int32_t g = std::min<int32_t>((top_left_pixel_color.g * shade) >> 7, 255);
433+ int32_t b = std::min<int32_t>((top_left_pixel_color.b * shade) >> 7, 255);
434+ m_minimap_colors[shade] = RGBColor(r, g, b);
435+ }
436+ }
437+
438 if (g_opengl) {
439 // Note: we except the constructor to free the SDL surface
440 GLSurfaceTexture* surface = new GLSurfaceTexture(surf);
441 m_glFrames.emplace_back(surface);
442
443- // calculate shades on the first frame
444- if (!m_nrframes) {
445- surface->lock(Surface::Lock_Normal);
446- uint32_t mmap_color_base = surface->get_pixel(0, 0);
447- surface->unlock(Surface::Unlock_NoChange);
448-
449- int32_t i, shade, r, g, b, a;
450- for (i = -128; i < 128; i++) {
451- shade = 128 + i;
452-
453- a = (mmap_color_base & 0xff000000) >> 24;
454- b = (mmap_color_base & 0x00ff0000) >> 16;
455- g = (mmap_color_base & 0x0000ff00) >> 8;
456- r = (mmap_color_base & 0x000000ff);
457-
458- b = (b * shade) >> 7;
459- g = (g * shade) >> 7;
460- r = (r * shade) >> 7;
461-
462- if (b > 255) b = 255;
463- if (g > 255) g = 255;
464- if (r > 255) r = 255;
465-
466- m_mmap_color[shade] = (a << 24) | (b << 16) | (g << 8) | r;
467- }
468- }
469-
470 ++m_nrframes;
471 continue;
472 }
473
474 // Determine color map if it's the first frame
475 if (!m_nrframes) {
476- if (surf->format->BitsPerPixel == 8) {
477- m_colormap.reset(new Colormap(*surf->format->palette->colors, format));
478- } else {
479- SDL_Color pal[256];
480-
481- log("WARNING: %s: using 332 default palette\n", fname.c_str());
482-
483- for (int32_t r = 0; r < 8; ++r)
484- for (int32_t g = 0; g < 8; ++g)
485- for (int32_t b = 0; b < 4; ++b) {
486- pal[(r << 5) | (g << 2) | b].r = r << 5;
487- pal[(r << 5) | (g << 2) | b].g = g << 5;
488- pal[(r << 5) | (g << 2) | b].b = b << 6;
489- }
490-
491- m_colormap.reset(new Colormap(*pal, format));
492+ if (surf->format->BitsPerPixel != 8) {
493+ throw wexception("Terrain %s is not 8 bits per pixel.", fname.c_str());
494 }
495+ m_colormap.reset(new Colormap(*surf->format->palette->colors, format));
496 }
497
498 // Convert to our palette
499@@ -180,14 +150,8 @@
500 /**
501 * Return the basic terrain colour to be used in the minimap.
502 */
503-uint32_t Texture::get_minimap_color(char shade) {
504- if (not m_pixels)
505- return m_mmap_color[128 + shade];
506-
507- uint8_t clr = m_pixels[0]; // just use the top-left pixel
508-
509- uint32_t table = static_cast<uint8_t>(shade);
510- return static_cast<const uint32_t*>(m_colormap->get_colormap())[clr | (table << 8)];
511+RGBColor Texture::get_minimap_color(int8_t shade) {
512+ return m_minimap_colors[128 + shade];
513 }
514
515 /**
516
517=== modified file 'src/graphic/texture.h'
518--- src/graphic/texture.h 2014-07-05 16:41:51 +0000
519+++ src/graphic/texture.h 2014-07-17 13:30:57 +0000
520@@ -56,7 +56,7 @@
521 uint8_t * get_curpixels() const {return m_curframe;}
522 void * get_colormap () const {return m_colormap->get_colormap();}
523
524- uint32_t get_minimap_color(char shade);
525+ RGBColor get_minimap_color(int8_t shade);
526
527 void animate(uint32_t time);
528 uint32_t getTexture() const
529@@ -65,7 +65,7 @@
530 private:
531 std::unique_ptr<Colormap> m_colormap;
532 uint8_t * m_pixels;
533- uint32_t m_mmap_color[256];
534+ RGBColor m_minimap_colors[256];
535 uint8_t * m_curframe;
536 int32_t m_frame_num;
537 std::string m_texture_image;
538
539=== modified file 'src/logic/CMakeLists.txt'
540--- src/logic/CMakeLists.txt 2014-07-16 08:23:42 +0000
541+++ src/logic/CMakeLists.txt 2014-07-17 13:30:57 +0000
542@@ -1,3 +1,18 @@
543+wl_binary(map_info
544+ SRCS
545+ map_info.cc
546+ DEPENDS
547+ base_log
548+ graphic
549+ graphic_image_io
550+ graphic_surface
551+ io_fileread
552+ io_filesystem
553+ logic
554+ map_io_map_loader
555+ scripting
556+)
557+
558 wl_library(logic_widelands_geometry
559 SRCS
560 widelands_geometry.cc
561
562=== modified file 'src/logic/map.cc'
563--- src/logic/map.cc 2014-07-16 07:44:33 +0000
564+++ src/logic/map.cc 2014-07-17 13:30:57 +0000
565@@ -1635,8 +1635,7 @@
566 try {
567 result.reset(new WL_Map_Loader(g_fs->MakeSubFileSystem(filename), this));
568 } catch (...) {
569- // If this fails, it is an illegal file (maybe old plain binary map
570- // format)
571+ // If this fails, it is an illegal file.
572 // TODO: catchall hides real errors! Replace with more specific code
573 }
574 } else if (boost::algorithm::ends_with(lower_filename, S2MF_SUFFIX) ||
575
576=== added file 'src/logic/map_info.cc'
577--- src/logic/map_info.cc 1970-01-01 00:00:00 +0000
578+++ src/logic/map_info.cc 2014-07-17 13:30:57 +0000
579@@ -0,0 +1,78 @@
580+/*
581+ * Copyright (C) 2006-2014 by the Widelands Development Team
582+ *
583+ * This program is free software; you can redistribute it and/or
584+ * modify it under the terms of the GNU General Public License
585+ * as published by the Free Software Foundation; either version 2
586+ * of the License, or (at your option) any later version.
587+ *
588+ * This program is distributed in the hope that it will be useful,
589+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
590+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
591+ * GNU General Public License for more details.
592+ *
593+ * You should have received a copy of the GNU General Public License
594+ * along with this program; if not, write to the Free Software
595+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
596+ *
597+ */
598+
599+#include <memory>
600+
601+#include <SDL.h>
602+
603+#include "base/log.h"
604+#include "config.h"
605+#include "graphic/graphic.h"
606+#include "graphic/image_io.h"
607+#include "graphic/render/minimaprenderer.h"
608+#include "graphic/surface.h"
609+#include "io/filesystem/filesystem.h"
610+#include "io/filesystem/layered_filesystem.h"
611+#include "io/filewrite.h"
612+#include "logic/editor_game_base.h"
613+#include "logic/map.h"
614+#include "map_io/widelands_map_loader.h"
615+#include "scripting/scripting.h"
616+
617+using namespace Widelands;
618+
619+int main(int /* argc */, char ** argv)
620+{
621+ try {
622+ SDL_Init(SDL_INIT_VIDEO);
623+
624+ g_fs = new LayeredFileSystem();
625+ g_fs->AddFileSystem(&FileSystem::Create(INSTALL_PREFIX + std::string("/") + INSTALL_DATADIR));
626+
627+#ifdef HAS_GETENV
628+ char dummy_video_env[] = "SDL_VIDEODRIVER=dummy";
629+ putenv(dummy_video_env);
630+#endif
631+
632+ g_gr = new Graphic();
633+ g_gr->initialize(1, 1, false, false);
634+
635+ Editor_Game_Base egbase(nullptr);
636+ Map* map = new Map();
637+ egbase.set_map(map);
638+
639+ std::unique_ptr<Widelands::Map_Loader> ml(map->get_correct_loader(argv[1]));
640+ assert(ml != nullptr);
641+
642+ ml->preload_map(true);
643+ ml->load_map_complete(egbase, true);
644+
645+ std::unique_ptr<Surface> minimap(draw_minimap(egbase, nullptr, Point(0, 0), MiniMapLayer::Terrain));
646+
647+ FileWrite fw;
648+ save_surface_to_png(minimap.get(), &fw);
649+ std::unique_ptr<FileSystem> fs(&FileSystem::Create("."));
650+ fw.Write(*fs, "minimap.png");
651+ }
652+ catch (std::exception& e) {
653+ log("Exception: %s.\n", e.what());
654+ return 1;
655+ }
656+ return 0;
657+}
658
659=== modified file 'src/third_party/CMakeLists.txt'
660--- src/third_party/CMakeLists.txt 2014-07-14 10:45:44 +0000
661+++ src/third_party/CMakeLists.txt 2014-07-17 13:30:57 +0000
662@@ -63,7 +63,6 @@
663 eris/ltm.h
664 eris/lua.h
665 eris/lua.hpp
666- eris/luac.c
667 eris/luaconf.h
668 eris/lualib.h
669 eris/lundump.c
670
671=== modified file 'src/third_party/README'
672--- src/third_party/README 2014-06-12 07:03:29 +0000
673+++ src/third_party/README 2014-07-17 13:30:57 +0000
674@@ -1,2 +1,9 @@
675 This contains third party libraries that are uncommon and are therefore shipped
676 with the Widelands source code for transparent compilation.
677+
678+Changes
679+-------
680+
681+Eris:
682+- removed luac.c. It defined a main() function which could hide our own main()
683+ eris was linked in.
684
685=== removed file 'src/third_party/eris/luac.c'
686--- src/third_party/eris/luac.c 2014-02-22 14:47:28 +0000
687+++ src/third_party/eris/luac.c 1970-01-01 00:00:00 +0000
688@@ -1,432 +0,0 @@
689-/*
690-** $Id: luac.c,v 1.69 2011/11/29 17:46:33 lhf Exp $
691-** Lua compiler (saves bytecodes to files; also list bytecodes)
692-** See Copyright Notice in lua.h
693-*/
694-
695-#include <errno.h>
696-#include <stdio.h>
697-#include <stdlib.h>
698-#include <string.h>
699-
700-#define luac_c
701-#define LUA_CORE
702-
703-#include "lua.h"
704-#include "lauxlib.h"
705-
706-#include "lobject.h"
707-#include "lstate.h"
708-#include "lundump.h"
709-
710-static void PrintFunction(const Proto* f, int full);
711-#define luaU_print PrintFunction
712-
713-#define PROGNAME "luac" /* default program name */
714-#define OUTPUT PROGNAME ".out" /* default output file */
715-
716-static int listing=0; /* list bytecodes? */
717-static int dumping=1; /* dump bytecodes? */
718-static int stripping=0; /* strip debug information? */
719-static char Output[]={ OUTPUT }; /* default output file name */
720-static const char* output=Output; /* actual output file name */
721-static const char* progname=PROGNAME; /* actual program name */
722-
723-static void fatal(const char* message)
724-{
725- fprintf(stderr,"%s: %s\n",progname,message);
726- exit(EXIT_FAILURE);
727-}
728-
729-static void cannot(const char* what)
730-{
731- fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
732- exit(EXIT_FAILURE);
733-}
734-
735-static void usage(const char* message)
736-{
737- if (*message=='-')
738- fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
739- else
740- fprintf(stderr,"%s: %s\n",progname,message);
741- fprintf(stderr,
742- "usage: %s [options] [filenames]\n"
743- "Available options are:\n"
744- " -l list (use -l -l for full listing)\n"
745- " -o name output to file " LUA_QL("name") " (default is \"%s\")\n"
746- " -p parse only\n"
747- " -s strip debug information\n"
748- " -v show version information\n"
749- " -- stop handling options\n"
750- " - stop handling options and process stdin\n"
751- ,progname,Output);
752- exit(EXIT_FAILURE);
753-}
754-
755-#define IS(s) (strcmp(argv[i],s)==0)
756-
757-static int doargs(int argc, char* argv[])
758-{
759- int i;
760- int version=0;
761- if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
762- for (i=1; i<argc; i++)
763- {
764- if (*argv[i]!='-') /* end of options; keep it */
765- break;
766- else if (IS("--")) /* end of options; skip it */
767- {
768- ++i;
769- if (version) ++version;
770- break;
771- }
772- else if (IS("-")) /* end of options; use stdin */
773- break;
774- else if (IS("-l")) /* list */
775- ++listing;
776- else if (IS("-o")) /* output file */
777- {
778- output=argv[++i];
779- if (output==NULL || *output==0 || (*output=='-' && output[1]!=0))
780- usage(LUA_QL("-o") " needs argument");
781- if (IS("-")) output=NULL;
782- }
783- else if (IS("-p")) /* parse only */
784- dumping=0;
785- else if (IS("-s")) /* strip debug information */
786- stripping=1;
787- else if (IS("-v")) /* show version */
788- ++version;
789- else /* unknown option */
790- usage(argv[i]);
791- }
792- if (i==argc && (listing || !dumping))
793- {
794- dumping=0;
795- argv[--i]=Output;
796- }
797- if (version)
798- {
799- printf("%s\n",LUA_COPYRIGHT);
800- if (version==argc-1) exit(EXIT_SUCCESS);
801- }
802- return i;
803-}
804-
805-#define FUNCTION "(function()end)();"
806-
807-static const char* reader(lua_State *L, void *ud, size_t *size)
808-{
809- UNUSED(L);
810- if ((*(int*)ud)--)
811- {
812- *size=sizeof(FUNCTION)-1;
813- return FUNCTION;
814- }
815- else
816- {
817- *size=0;
818- return NULL;
819- }
820-}
821-
822-#define toproto(L,i) getproto(L->top+(i))
823-
824-static const Proto* combine(lua_State* L, int n)
825-{
826- if (n==1)
827- return toproto(L,-1);
828- else
829- {
830- Proto* f;
831- int i=n;
832- if (lua_load(L,reader,&i,"=(" PROGNAME ")",NULL)!=LUA_OK) fatal(lua_tostring(L,-1));
833- f=toproto(L,-1);
834- for (i=0; i<n; i++)
835- {
836- f->p[i]=toproto(L,i-n-1);
837- if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
838- }
839- f->sizelineinfo=0;
840- return f;
841- }
842-}
843-
844-static int writer(lua_State* L, const void* p, size_t size, void* u)
845-{
846- UNUSED(L);
847- return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
848-}
849-
850-static int pmain(lua_State* L)
851-{
852- int argc=(int)lua_tointeger(L,1);
853- char** argv=(char**)lua_touserdata(L,2);
854- const Proto* f;
855- int i;
856- if (!lua_checkstack(L,argc)) fatal("too many input files");
857- for (i=0; i<argc; i++)
858- {
859- const char* filename=IS("-") ? NULL : argv[i];
860- if (luaL_loadfile(L,filename)!=LUA_OK) fatal(lua_tostring(L,-1));
861- }
862- f=combine(L,argc);
863- if (listing) luaU_print(f,listing>1);
864- if (dumping)
865- {
866- FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
867- if (D==NULL) cannot("open");
868- lua_lock(L);
869- luaU_dump(L,f,writer,D,stripping);
870- lua_unlock(L);
871- if (ferror(D)) cannot("write");
872- if (fclose(D)) cannot("close");
873- }
874- return 0;
875-}
876-
877-int main(int argc, char* argv[])
878-{
879- lua_State* L;
880- int i=doargs(argc,argv);
881- argc-=i; argv+=i;
882- if (argc<=0) usage("no input files given");
883- L=luaL_newstate();
884- if (L==NULL) fatal("cannot create state: not enough memory");
885- lua_pushcfunction(L,&pmain);
886- lua_pushinteger(L,argc);
887- lua_pushlightuserdata(L,argv);
888- if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
889- lua_close(L);
890- return EXIT_SUCCESS;
891-}
892-
893-/*
894-** $Id: print.c,v 1.69 2013/07/04 01:03:46 lhf Exp $
895-** print bytecodes
896-** See Copyright Notice in lua.h
897-*/
898-
899-#include <ctype.h>
900-#include <stdio.h>
901-
902-#define luac_c
903-#define LUA_CORE
904-
905-#include "ldebug.h"
906-#include "lobject.h"
907-#include "lopcodes.h"
908-
909-#define VOID(p) ((const void*)(p))
910-
911-static void PrintString(const TString* ts)
912-{
913- const char* s=getstr(ts);
914- size_t i,n=ts->tsv.len;
915- printf("%c",'"');
916- for (i=0; i<n; i++)
917- {
918- int c=(int)(unsigned char)s[i];
919- switch (c)
920- {
921- case '"': printf("\\\""); break;
922- case '\\': printf("\\\\"); break;
923- case '\a': printf("\\a"); break;
924- case '\b': printf("\\b"); break;
925- case '\f': printf("\\f"); break;
926- case '\n': printf("\\n"); break;
927- case '\r': printf("\\r"); break;
928- case '\t': printf("\\t"); break;
929- case '\v': printf("\\v"); break;
930- default: if (isprint(c))
931- printf("%c",c);
932- else
933- printf("\\%03d",c);
934- }
935- }
936- printf("%c",'"');
937-}
938-
939-static void PrintConstant(const Proto* f, int i)
940-{
941- const TValue* o=&f->k[i];
942- switch (ttypenv(o))
943- {
944- case LUA_TNIL:
945- printf("nil");
946- break;
947- case LUA_TBOOLEAN:
948- printf(bvalue(o) ? "true" : "false");
949- break;
950- case LUA_TNUMBER:
951- printf(LUA_NUMBER_FMT,nvalue(o));
952- break;
953- case LUA_TSTRING:
954- PrintString(rawtsvalue(o));
955- break;
956- default: /* cannot happen */
957- printf("? type=%d",ttype(o));
958- break;
959- }
960-}
961-
962-#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
963-#define MYK(x) (-1-(x))
964-
965-static void PrintCode(const Proto* f)
966-{
967- const Instruction* code=f->code;
968- int pc,n=f->sizecode;
969- for (pc=0; pc<n; pc++)
970- {
971- Instruction i=code[pc];
972- OpCode o=GET_OPCODE(i);
973- int a=GETARG_A(i);
974- int b=GETARG_B(i);
975- int c=GETARG_C(i);
976- int ax=GETARG_Ax(i);
977- int bx=GETARG_Bx(i);
978- int sbx=GETARG_sBx(i);
979- int line=getfuncline(f,pc);
980- printf("\t%d\t",pc+1);
981- if (line>0) printf("[%d]\t",line); else printf("[-]\t");
982- printf("%-9s\t",luaP_opnames[o]);
983- switch (getOpMode(o))
984- {
985- case iABC:
986- printf("%d",a);
987- if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (MYK(INDEXK(b))) : b);
988- if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (MYK(INDEXK(c))) : c);
989- break;
990- case iABx:
991- printf("%d",a);
992- if (getBMode(o)==OpArgK) printf(" %d",MYK(bx));
993- if (getBMode(o)==OpArgU) printf(" %d",bx);
994- break;
995- case iAsBx:
996- printf("%d %d",a,sbx);
997- break;
998- case iAx:
999- printf("%d",MYK(ax));
1000- break;
1001- }
1002- switch (o)
1003- {
1004- case OP_LOADK:
1005- printf("\t; "); PrintConstant(f,bx);
1006- break;
1007- case OP_GETUPVAL:
1008- case OP_SETUPVAL:
1009- printf("\t; %s",UPVALNAME(b));
1010- break;
1011- case OP_GETTABUP:
1012- printf("\t; %s",UPVALNAME(b));
1013- if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
1014- break;
1015- case OP_SETTABUP:
1016- printf("\t; %s",UPVALNAME(a));
1017- if (ISK(b)) { printf(" "); PrintConstant(f,INDEXK(b)); }
1018- if (ISK(c)) { printf(" "); PrintConstant(f,INDEXK(c)); }
1019- break;
1020- case OP_GETTABLE:
1021- case OP_SELF:
1022- if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
1023- break;
1024- case OP_SETTABLE:
1025- case OP_ADD:
1026- case OP_SUB:
1027- case OP_MUL:
1028- case OP_DIV:
1029- case OP_POW:
1030- case OP_EQ:
1031- case OP_LT:
1032- case OP_LE:
1033- if (ISK(b) || ISK(c))
1034- {
1035- printf("\t; ");
1036- if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
1037- printf(" ");
1038- if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
1039- }
1040- break;
1041- case OP_JMP:
1042- case OP_FORLOOP:
1043- case OP_FORPREP:
1044- case OP_TFORLOOP:
1045- printf("\t; to %d",sbx+pc+2);
1046- break;
1047- case OP_CLOSURE:
1048- printf("\t; %p",VOID(f->p[bx]));
1049- break;
1050- case OP_SETLIST:
1051- if (c==0) printf("\t; %d",(int)code[++pc]); else printf("\t; %d",c);
1052- break;
1053- case OP_EXTRAARG:
1054- printf("\t; "); PrintConstant(f,ax);
1055- break;
1056- default:
1057- break;
1058- }
1059- printf("\n");
1060- }
1061-}
1062-
1063-#define SS(x) ((x==1)?"":"s")
1064-#define S(x) (int)(x),SS(x)
1065-
1066-static void PrintHeader(const Proto* f)
1067-{
1068- const char* s=f->source ? getstr(f->source) : "=?";
1069- if (*s=='@' || *s=='=')
1070- s++;
1071- else if (*s==LUA_SIGNATURE[0])
1072- s="(bstring)";
1073- else
1074- s="(string)";
1075- printf("\n%s <%s:%d,%d> (%d instruction%s at %p)\n",
1076- (f->linedefined==0)?"main":"function",s,
1077- f->linedefined,f->lastlinedefined,
1078- S(f->sizecode),VOID(f));
1079- printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
1080- (int)(f->numparams),f->is_vararg?"+":"",SS(f->numparams),
1081- S(f->maxstacksize),S(f->sizeupvalues));
1082- printf("%d local%s, %d constant%s, %d function%s\n",
1083- S(f->sizelocvars),S(f->sizek),S(f->sizep));
1084-}
1085-
1086-static void PrintDebug(const Proto* f)
1087-{
1088- int i,n;
1089- n=f->sizek;
1090- printf("constants (%d) for %p:\n",n,VOID(f));
1091- for (i=0; i<n; i++)
1092- {
1093- printf("\t%d\t",i+1);
1094- PrintConstant(f,i);
1095- printf("\n");
1096- }
1097- n=f->sizelocvars;
1098- printf("locals (%d) for %p:\n",n,VOID(f));
1099- for (i=0; i<n; i++)
1100- {
1101- printf("\t%d\t%s\t%d\t%d\n",
1102- i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
1103- }
1104- n=f->sizeupvalues;
1105- printf("upvalues (%d) for %p:\n",n,VOID(f));
1106- for (i=0; i<n; i++)
1107- {
1108- printf("\t%d\t%s\t%d\t%d\n",
1109- i,UPVALNAME(i),f->upvalues[i].instack,f->upvalues[i].idx);
1110- }
1111-}
1112-
1113-static void PrintFunction(const Proto* f, int full)
1114-{
1115- int i,n=f->sizep;
1116- PrintHeader(f);
1117- PrintCode(f);
1118- if (full) PrintDebug(f);
1119- for (i=0; i<n; i++) PrintFunction(f->p[i],full);
1120-}
1121
1122=== modified file 'src/wui/minimap.cc'
1123--- src/wui/minimap.cc 2014-07-14 10:45:44 +0000
1124+++ src/wui/minimap.cc 2014-07-17 13:30:57 +0000
1125@@ -33,7 +33,7 @@
1126
1127
1128 MiniMap::View::View
1129- (UI::Panel & parent, int8_t * flags,
1130+ (UI::Panel & parent, MiniMapLayer * flags,
1131 int32_t const x, int32_t const y, uint32_t const, uint32_t const,
1132 Interactive_Base & ibase)
1133 :
1134@@ -63,16 +63,13 @@
1135
1136 void MiniMap::View::draw(RenderTarget & dst)
1137 {
1138- MiniMapRenderer mmr;
1139-
1140- std::unique_ptr<Surface> surface
1141- (mmr.get_minimap_image
1142- (m_ibase.egbase(),
1143- m_ibase.get_player(),
1144- (*m_flags) & (MiniMap::Zoom2) ?
1145- Point((m_viewx - get_w() / 4), (m_viewy - get_h() / 4)):
1146- Point((m_viewx - get_w() / 2), (m_viewy - get_h() / 2)),
1147- *m_flags));
1148+ std::unique_ptr<Surface> surface(
1149+ draw_minimap(m_ibase.egbase(),
1150+ m_ibase.get_player(),
1151+ (*m_flags) & (MiniMapLayer::Zoom2) ?
1152+ Point((m_viewx - get_w() / 4), (m_viewy - get_h() / 4)) :
1153+ Point((m_viewx - get_w() / 2), (m_viewy - get_h() / 2)),
1154+ *m_flags | MiniMapLayer::ViewWindow));
1155 // Give ownership of the surface to the new image
1156 std::unique_ptr<const Image> im(new_in_memory_image("minimap", surface.release()));
1157 dst.blit(Point(), im.get());
1158@@ -91,7 +88,7 @@
1159
1160 // calculates the coordinates corresponding to the mouse position
1161 Widelands::Coords c;
1162- if (*m_flags & MiniMap::Zoom2)
1163+ if (*m_flags & MiniMapLayer::Zoom2)
1164 c = Widelands::Coords
1165 (m_viewx + 1 - (get_w() / 2 - x) / 2,
1166 m_viewy + 1 - (get_h() / 2 - y) / 2);
1167@@ -182,12 +179,13 @@
1168 g_gr->images().get("pics/button_zoom.png"),
1169 _("Zoom"))
1170 {
1171- button_terrn.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Terrn));
1172- button_owner.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Owner));
1173- button_flags.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Flags));
1174- button_roads.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Roads));
1175- button_bldns.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Bldns));
1176- button_zoom.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), Zoom2));
1177+ button_terrn.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Terrain));
1178+ button_owner.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Owner));
1179+ button_flags.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Flag));
1180+ button_roads.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Road));
1181+ button_bldns.sigclicked.connect(
1182+ boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Building));
1183+ button_zoom.sigclicked.connect(boost::bind(&MiniMap::toggle, boost::ref(*this), MiniMapLayer::Zoom2));
1184
1185 set_cache(false);
1186
1187@@ -200,15 +198,15 @@
1188 }
1189
1190
1191-void MiniMap::toggle(Layers const button) {
1192- *m_view.m_flags ^= button;
1193- if (button == Zoom2)
1194+void MiniMap::toggle(MiniMapLayer const button) {
1195+ *m_view.m_flags = MiniMapLayer(*m_view.m_flags ^ button);
1196+ if (button == MiniMapLayer::Zoom2)
1197 resize();
1198 update_button_permpressed();
1199 }
1200
1201 void MiniMap::resize() {
1202- m_view.set_zoom(*m_view.m_flags & Zoom2 ? 2 : 1);
1203+ m_view.set_zoom(*m_view.m_flags & MiniMapLayer::Zoom2 ? 2 : 1);
1204 set_inner_size
1205 (m_view.get_w(), m_view.get_h() + number_of_button_rows() * but_h());
1206 button_terrn.set_pos(Point(but_w() * 0, m_view.get_h() + but_h() * 0));
1207@@ -228,10 +226,10 @@
1208
1209 // Makes the buttons reflect the selected layers
1210 void MiniMap::update_button_permpressed() {
1211- button_terrn.set_perm_pressed(*m_view.m_flags & Terrn);
1212- button_owner.set_perm_pressed(*m_view.m_flags & Owner);
1213- button_flags.set_perm_pressed(*m_view.m_flags & Flags);
1214- button_roads.set_perm_pressed(*m_view.m_flags & Roads);
1215- button_bldns.set_perm_pressed(*m_view.m_flags & Bldns);
1216- button_zoom .set_perm_pressed(*m_view.m_flags & Zoom2);
1217+ button_terrn.set_perm_pressed(*m_view.m_flags & MiniMapLayer::Terrain);
1218+ button_owner.set_perm_pressed(*m_view.m_flags & MiniMapLayer::Owner);
1219+ button_flags.set_perm_pressed(*m_view.m_flags & MiniMapLayer::Flag);
1220+ button_roads.set_perm_pressed(*m_view.m_flags & MiniMapLayer::Road);
1221+ button_bldns.set_perm_pressed(*m_view.m_flags & MiniMapLayer::Building);
1222+ button_zoom .set_perm_pressed(*m_view.m_flags & MiniMapLayer::Zoom2);
1223 }
1224
1225=== modified file 'src/wui/minimap.h'
1226--- src/wui/minimap.h 2014-07-14 10:45:44 +0000
1227+++ src/wui/minimap.h 2014-07-17 13:30:57 +0000
1228@@ -22,6 +22,7 @@
1229
1230 #include <boost/signals2.hpp>
1231
1232+#include "graphic/render/minimaprenderer.h"
1233 #include "ui_basic/button.h"
1234 #include "ui_basic/unique_window.h"
1235
1236@@ -29,9 +30,13 @@
1237
1238 struct MiniMap : public UI::UniqueWindow {
1239 struct Registry : public UI::UniqueWindow::Registry {
1240- int8_t flags; /**< Combination of \ref Layers flags */
1241+ MiniMapLayer flags; /**< Combination of \ref MiniMapLayer flags */
1242
1243- Registry() : flags(Terrn | Owner | Flags | Roads | Bldns) {}
1244+ Registry()
1245+ : flags(MiniMapLayer::Terrain | MiniMapLayer::Owner |
1246+ MiniMapLayer::Flag | MiniMapLayer::Road |
1247+ MiniMapLayer::Building) {
1248+ }
1249 };
1250
1251 MiniMap(Interactive_Base & parent, Registry *);
1252@@ -42,10 +47,8 @@
1253 m_view.set_view_pos(x, y);
1254 }
1255
1256- enum Layers {Terrn = 1, Owner = 2, Flags = 4, Roads = 8, Bldns = 16, Zoom2 = 32};
1257-
1258 private:
1259- void toggle(Layers);
1260+ void toggle(MiniMapLayer);
1261 void update_button_permpressed();
1262 void resize();
1263
1264@@ -60,7 +63,7 @@
1265 */
1266 struct View : public UI::Panel {
1267 View
1268- (UI::Panel & parent, int8_t * flags,
1269+ (UI::Panel & parent, MiniMapLayer * flags,
1270 int32_t x, int32_t y, uint32_t w, uint32_t h,
1271 Interactive_Base &);
1272
1273@@ -79,7 +82,7 @@
1274 int32_t m_viewx, m_viewy;
1275 const Image* m_pic_map_spot;
1276 public:
1277- int8_t * m_flags;
1278+ MiniMapLayer * m_flags;
1279 };
1280
1281 uint32_t number_of_buttons_per_row() const;

Subscribers

People subscribed via source and target branches

to status/vote changes: