Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Merged at revision: | 8148 | ||||||||||||
Proposed branch: | lp:~widelands-dev/widelands/zoom | ||||||||||||
Merge into: | lp:widelands | ||||||||||||
Diff against target: |
10816 lines (+2707/-2303) 183 files modified
src/base/CMakeLists.txt (+10/-3) src/base/math.cc (+20/-0) src/base/math.h (+43/-0) src/base/point.h (+0/-79) src/base/rect.h (+25/-15) src/base/vector.cc (+10/-4) src/base/vector.h (+81/-16) src/economy/flag.h (+6/-1) src/economy/portdock.cc (+1/-1) src/economy/portdock.h (+5/-1) src/economy/road.h (+5/-1) src/editor/editorinteractive.cc (+4/-2) src/editor/tools/set_origin_tool.cc (+2/-5) src/editor/tools/set_starting_pos_tool.cc (+1/-1) src/editor/ui_menus/main_menu_load_or_save_map.cc (+1/-1) src/editor/ui_menus/main_menu_map_options.cc (+1/-1) src/editor/ui_menus/main_menu_random_map.cc (+1/-1) src/editor/ui_menus/main_menu_save_map.h (+1/-1) src/editor/ui_menus/player_menu.cc (+3/-3) src/editor/ui_menus/tool_change_resources_options_menu.cc (+1/-1) src/editor/ui_menus/tool_menu.cc (+2/-2) src/editor/ui_menus/tool_place_bob_options_menu.cc (+2/-2) src/editor/ui_menus/tool_place_immovable_options_menu.cc (+1/-1) src/editor/ui_menus/tool_set_terrain_options_menu.cc (+6/-6) src/game_io/CMakeLists.txt (+2/-0) src/game_io/game_interactive_player_packet.cc (+42/-12) src/game_io/game_preload_packet.cc (+8/-3) src/graphic/CMakeLists.txt (+1/-1) src/graphic/align.cc (+6/-1) src/graphic/align.h (+2/-2) src/graphic/animation.cc (+20/-16) src/graphic/animation.h (+7/-4) src/graphic/font_handler.cc (+10/-9) src/graphic/font_handler.h (+3/-3) src/graphic/font_handler1.h (+1/-1) src/graphic/game_renderer.cc (+303/-269) src/graphic/game_renderer.h (+23/-34) src/graphic/gl/blit_data.h (+1/-1) src/graphic/gl/blit_program.cc (+5/-5) src/graphic/gl/blit_program.h (+3/-3) src/graphic/gl/coordinate_conversion.h (+6/-6) src/graphic/gl/dither_program.cc (+35/-36) src/graphic/gl/dither_program.h (+2/-2) src/graphic/gl/draw_line_program.h (+1/-1) src/graphic/gl/fields_to_draw.h (+48/-12) src/graphic/gl/fill_rect_program.cc (+1/-1) src/graphic/gl/fill_rect_program.h (+2/-2) src/graphic/gl/road_program.cc (+29/-29) src/graphic/gl/road_program.h (+2/-0) src/graphic/gl/terrain_program.cc (+21/-21) src/graphic/gl/terrain_program.h (+2/-2) src/graphic/minimap_renderer.cc (+132/-131) src/graphic/minimap_renderer.h (+29/-21) src/graphic/render_queue.cc (+6/-5) src/graphic/render_queue.h (+4/-3) src/graphic/rendertarget.cc (+80/-87) src/graphic/rendertarget.h (+37/-34) src/graphic/richtext.cc (+15/-15) src/graphic/richtext.h (+2/-2) src/graphic/screen.cc (+4/-4) src/graphic/screen.h (+4/-4) src/graphic/surface.cc (+43/-43) src/graphic/surface.h (+12/-12) src/graphic/text/rt_render.cc (+20/-21) src/graphic/texture.cc (+8/-10) src/graphic/texture.h (+5/-5) src/graphic/texture_atlas.cc (+13/-13) src/graphic/texture_atlas.h (+2/-2) src/graphic/wordwrap.cc (+4/-4) src/graphic/wordwrap.h (+2/-2) src/io/streamread.cc (+10/-0) src/io/streamread.h (+1/-0) src/io/streamwrite.cc (+1/-0) src/io/streamwrite.h (+6/-0) src/logic/CMakeLists.txt (+8/-6) src/logic/game.cc (+1/-1) src/logic/game_controller.h (+0/-3) src/logic/map_objects/bob.cc (+47/-39) src/logic/map_objects/bob.h (+13/-7) src/logic/map_objects/draw_text.h (+34/-0) src/logic/map_objects/immovable.cc (+24/-21) src/logic/map_objects/immovable.h (+24/-11) src/logic/map_objects/map_object.cc (+33/-20) src/logic/map_objects/map_object.h (+10/-4) src/logic/map_objects/tribes/building.cc (+20/-35) src/logic/map_objects/tribes/building.h (+7/-3) src/logic/map_objects/tribes/constructionsite.cc (+19/-22) src/logic/map_objects/tribes/constructionsite.h (+5/-1) src/logic/map_objects/tribes/dismantlesite.cc (+9/-12) src/logic/map_objects/tribes/dismantlesite.h (+5/-1) src/logic/map_objects/tribes/road_textures.cc (+4/-4) src/logic/map_objects/tribes/road_textures.h (+5/-4) src/logic/map_objects/tribes/ship.cc (+9/-7) src/logic/map_objects/tribes/ship.h (+5/-1) src/logic/map_objects/tribes/soldier.cc (+91/-71) src/logic/map_objects/tribes/soldier.h (+16/-3) src/logic/map_objects/tribes/worker.cc (+20/-8) src/logic/map_objects/tribes/worker.h (+9/-2) src/logic/map_objects/tribes/worker_descr.cc (+3/-3) src/logic/map_objects/tribes/worker_descr.h (+2/-2) src/logic/widelands_geometry.h (+1/-0) src/map_io/map_saver.cc (+4/-3) src/profile/profile.cc (+4/-4) src/profile/profile.h (+3/-3) src/scripting/lua_game.cc (+1/-1) src/scripting/lua_map.cc (+6/-6) src/scripting/lua_ui.cc (+14/-14) src/sound/CMakeLists.txt (+1/-0) src/sound/sound_handler.cc (+5/-6) src/ui_basic/box.cc (+3/-3) src/ui_basic/button.cc (+39/-41) src/ui_basic/checkbox.cc (+9/-9) src/ui_basic/checkbox.h (+4/-4) src/ui_basic/editbox.cc (+16/-16) src/ui_basic/icon.cc (+9/-10) src/ui_basic/listselect.cc (+8/-8) src/ui_basic/multilineeditbox.cc (+9/-9) src/ui_basic/multilinetextarea.cc (+7/-7) src/ui_basic/panel.cc (+22/-22) src/ui_basic/panel.h (+8/-8) src/ui_basic/progressbar.cc (+11/-12) src/ui_basic/progresswindow.cc (+9/-9) src/ui_basic/progresswindow.h (+6/-3) src/ui_basic/radiobutton.cc (+2/-2) src/ui_basic/radiobutton.h (+3/-3) src/ui_basic/scrollbar.cc (+40/-40) src/ui_basic/scrollbar.h (+2/-2) src/ui_basic/slider.cc (+28/-29) src/ui_basic/table.cc (+15/-15) src/ui_basic/tabpanel.cc (+27/-28) src/ui_basic/textarea.cc (+9/-9) src/ui_basic/unique_window.cc (+1/-1) src/ui_basic/window.cc (+34/-31) src/ui_basic/window.h (+2/-2) src/ui_fsmenu/about.cc (+1/-1) src/ui_fsmenu/base.cc (+1/-1) src/ui_fsmenu/helpwindow.cc (+1/-1) src/ui_fsmenu/launch_mpg.cc (+1/-1) src/ui_fsmenu/loadgame.cc (+1/-1) src/ui_fsmenu/mapselect.cc (+2/-2) src/ui_fsmenu/options.cc (+14/-14) src/website/map_info.cc (+2/-2) src/wlapplication.cc (+4/-4) src/wlapplication.h (+6/-6) src/wui/CMakeLists.txt (+32/-6) src/wui/building_statistics_menu.cc (+2/-2) src/wui/building_ui.cc (+2/-2) src/wui/buildingwindow.cc (+5/-4) src/wui/chatoverlay.cc (+3/-5) src/wui/field_overlay_manager.cc (+5/-5) src/wui/field_overlay_manager.h (+7/-7) src/wui/fieldaction.cc (+1/-1) src/wui/game_message_menu.cc (+1/-1) src/wui/game_options_sound_menu.cc (+4/-3) src/wui/game_tips.cc (+4/-5) src/wui/general_statistics_menu.cc (+13/-12) src/wui/interactive_base.cc (+22/-93) src/wui/interactive_base.h (+6/-8) src/wui/interactive_gamebase.cc (+1/-1) src/wui/interactive_player.cc (+1/-1) src/wui/itemwaresdisplay.cc (+4/-3) src/wui/login_box.cc (+3/-3) src/wui/mapdetails.cc (+1/-1) src/wui/mapview.cc (+159/-53) src/wui/mapview.h (+29/-25) src/wui/mapviewpixelconstants.h (+5/-1) src/wui/mapviewpixelfunctions.cc (+30/-31) src/wui/mapviewpixelfunctions.h (+26/-16) src/wui/minimap.cc (+27/-45) src/wui/minimap.h (+17/-16) src/wui/playerdescrgroup.cc (+1/-1) src/wui/plot_area.cc (+28/-25) src/wui/quicknavigation.cc (+23/-24) src/wui/quicknavigation.h (+19/-25) src/wui/shipwindow.cc (+2/-2) src/wui/soldierlist.cc (+22/-18) src/wui/story_message_box.cc (+2/-2) src/wui/transport_draw.cc (+19/-12) src/wui/warehousewindow.cc (+1/-1) src/wui/waresdisplay.cc (+10/-11) src/wui/waresdisplay.h (+1/-1) src/wui/waresqueuedisplay.cc (+6/-6) src/wui/watchwindow.cc (+87/-99) |
||||||||||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/zoom | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+309086@code.launchpad.net |
Commit message
- Adds mouse wheel zoom to the MapView and adapt code for these changes.
- Overlays (text & soldier icons) are drawn at integer scale only and not at all once scale is < 0.5.
- This required to change all blitting to be sub-pixel - i.e. float - for the 'destination'.
- Adapted and simplified minimap rendering. It gained a feature too: Minimaps can be drawn using two modes :
- the map scrolls and the view window stands still (the old one, stil used for in-game)
- the view window scrolls and the map always looks like the minimap preview. This is now used in the editor.
- Renames Vector -> Vector3f, Point -> Vector2i, Pointf -> Vector2f, Rect -> Recti, FloatRect -> Rectf.
- Refactored object drawing to be simpler and slightly faster:
- Never pass the field to be drawn to the draw routine.
- Do not calculate if statics or census should be shown inside the draw routines of the objects, but outside.
- Move 'owner' field to MapObject - it was duplicated on Bob, Immovable and PlayerImmovable.
Known issues that I will not fix in this branch:
Lua is not aware of zoom and uses zoomless calculations for its moving functions of the view. That means that if the player has zoomed in a scenario and the code wants to move to a certain field, the movement will be wrong. My plan is to remove the Lua functions and add a Animator class to the MapView that will do smooth animations over time in the next branch.
Description of the change
Jaaai - a journey of some 3 years starting with OpenGL finally enabling zoom!
Apologies for the huge diff. If it is unreviewable, I can pull out some of the
changes, like the renames and changing to floating point in rendering and
changing the minimap to two modes - but it would be a hassle and I'd prefer to
get it in as is after b19.
GunChleoc (gunchleoc) wrote : | # |
SirVer (sirver) wrote : | # |
should be fixed now. ptal.
GunChleoc (gunchleoc) wrote : | # |
I have given it a quick spin, zooming works fine. I still think it would be good to have some keyboard navigation for it, something like:
bool MapView:
if (down)
switch (code.sym) {
case SDLK_PLUS:
if (code.mod & KMOD_CTRL) {
<decrease zoom>;
return true;
}
break;
case SDLK_MINUS:
if (code.mod & KMOD_CTRL) {
<increase zoom>;
return true;
}
break;
case SDLK_0:
if (code.mod & KMOD_CTRL) {
<reset zoom>;
return true;
}
break;
default:
break;
}
return false;
}
SirVer (sirver) wrote : | # |
I agree, let's do that in the next branch though. this one is so big.
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
Running 'bzr pull --overwrite' failed. Output:
Warning: Permanently added 'bazaar.
Permission denied (publickey).
ConnectionReset reading response for 'BzrDir.open_2.1', retrying
Permission denied (publickey).
bzr: ERROR: Connection closed: Unexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.
Using saved parent location: bzr+ssh:
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
Running 'bzr pull --overwrite' failed. Output:
Permission denied (publickey).
ConnectionReset reading response for 'BzrDir.open_2.1', retrying
Permission denied (publickey).
bzr: ERROR: Connection closed: Unexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.
Using saved parent location: bzr+ssh:
GunChleoc (gunchleoc) wrote : | # |
Code review done in last commit. Just some few minor nits + refactoring ideas for the future. And I found some more float coordinates for text that I fixed.
I still have a list of things that I want to test, but looking very good overall :)
GunChleoc (gunchleoc) wrote : | # |
Testing done - this can go in whenever you're happy.
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
Running 'git fetch bzr_origin' failed. Output:
Traceback (most recent call last):
File "/usr/local/
sys.
File "/usr/local/
repo = get_repo(url, alias)
File "/usr/local/
origin = bzrlib.
File "/usr/lib/
_unsupporte
File "/usr/lib/
find_format, transport, redirected)
File "/usr/lib/
return action(transport)
File "/usr/lib/
probers=
File "/usr/lib/
raise errors.
bzrlib.
SirVer (sirver) wrote : | # |
Excellent code review - thanks for that! I applied everything except for one thing:
> move set_owner to superclass as well, where get_owner() is now.
I considered this - but set_owner has different implementations in different classes and makes no sense for some MapObjects (that can never be owned). So I left it in the classes where it was defined.
Bunnybot should be all ready for action again too - and it should now deal fine with many branches.
SirVer (sirver) wrote : | # |
@bunnybot merge
Lets see if that works again.
GunChleoc (gunchleoc) wrote : | # |
Thanks for a great feature :)
Preview Diff
1 | === modified file 'src/base/CMakeLists.txt' | |||
2 | --- src/base/CMakeLists.txt 2016-08-15 10:43:23 +0000 | |||
3 | +++ src/base/CMakeLists.txt 2016-10-24 20:07:47 +0000 | |||
4 | @@ -37,9 +37,9 @@ | |||
5 | 37 | 37 | ||
6 | 38 | wl_library(base_geometry | 38 | wl_library(base_geometry |
7 | 39 | SRCS | 39 | SRCS |
8 | 40 | point.h | ||
9 | 41 | point.cc | ||
10 | 42 | rect.h | 40 | rect.h |
11 | 41 | vector.h | ||
12 | 42 | vector.cc | ||
13 | 43 | ) | 43 | ) |
14 | 44 | 44 | ||
15 | 45 | wl_library(base_md5 | 45 | wl_library(base_md5 |
16 | @@ -50,7 +50,6 @@ | |||
17 | 50 | base_macros | 50 | base_macros |
18 | 51 | ) | 51 | ) |
19 | 52 | 52 | ||
20 | 53 | |||
21 | 54 | wl_library(base_scoped_timer | 53 | wl_library(base_scoped_timer |
22 | 55 | SRCS | 54 | SRCS |
23 | 56 | scoped_timer.h | 55 | scoped_timer.h |
24 | @@ -68,3 +67,11 @@ | |||
25 | 68 | DEPENDS | 67 | DEPENDS |
26 | 69 | base_i18n | 68 | base_i18n |
27 | 70 | ) | 69 | ) |
28 | 70 | |||
29 | 71 | wl_library(base_math | ||
30 | 72 | SRCS | ||
31 | 73 | math.h | ||
32 | 74 | math.cc | ||
33 | 75 | DEPENDS | ||
34 | 76 | base_macros | ||
35 | 77 | ) | ||
36 | 71 | 78 | ||
37 | === added file 'src/base/math.cc' | |||
38 | --- src/base/math.cc 1970-01-01 00:00:00 +0000 | |||
39 | +++ src/base/math.cc 2016-10-24 20:07:47 +0000 | |||
40 | @@ -0,0 +1,20 @@ | |||
41 | 1 | /* | ||
42 | 2 | * Copyright (C) 2006-2016 by the Widelands Development Team | ||
43 | 3 | * | ||
44 | 4 | * This program is free software; you can redistribute it and/or | ||
45 | 5 | * modify it under the terms of the GNU General Public License | ||
46 | 6 | * as published by the Free Software Foundation; either version 2 | ||
47 | 7 | * of the License, or (at your option) any later version. | ||
48 | 8 | * | ||
49 | 9 | * This program is distributed in the hope that it will be useful, | ||
50 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
51 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
52 | 12 | * GNU General Public License for more details. | ||
53 | 13 | * | ||
54 | 14 | * You should have received a copy of the GNU General Public License | ||
55 | 15 | * along with this program; if not, write to the Free Software | ||
56 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
57 | 17 | * | ||
58 | 18 | */ | ||
59 | 19 | |||
60 | 20 | // Dummy file as cmake cannot handle header only libraries :(. | ||
61 | 0 | 21 | ||
62 | === added file 'src/base/math.h' | |||
63 | --- src/base/math.h 1970-01-01 00:00:00 +0000 | |||
64 | +++ src/base/math.h 2016-10-24 20:07:47 +0000 | |||
65 | @@ -0,0 +1,43 @@ | |||
66 | 1 | /* | ||
67 | 2 | * Copyright (C) 2006-2016 by the Widelands Development Team | ||
68 | 3 | * | ||
69 | 4 | * This program is free software; you can redistribute it and/or | ||
70 | 5 | * modify it under the terms of the GNU General Public License | ||
71 | 6 | * as published by the Free Software Foundation; either version 2 | ||
72 | 7 | * of the License, or (at your option) any later version. | ||
73 | 8 | * | ||
74 | 9 | * This program is distributed in the hope that it will be useful, | ||
75 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
76 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
77 | 12 | * GNU General Public License for more details. | ||
78 | 13 | * | ||
79 | 14 | * You should have received a copy of the GNU General Public License | ||
80 | 15 | * along with this program; if not, write to the Free Software | ||
81 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
82 | 17 | * | ||
83 | 18 | */ | ||
84 | 19 | |||
85 | 20 | #ifndef WL_BASE_MATH_H | ||
86 | 21 | #define WL_BASE_MATH_H | ||
87 | 22 | |||
88 | 23 | #include "base/macros.h" | ||
89 | 24 | |||
90 | 25 | namespace math { | ||
91 | 26 | |||
92 | 27 | // Returns 1 for positive and -1 for negative numbers. | ||
93 | 28 | template <typename T> | ||
94 | 29 | T sign(const T& val) { | ||
95 | 30 | return val < T(0.) ? T(-1.) : T(1.); | ||
96 | 31 | } | ||
97 | 32 | |||
98 | 33 | // Clamps 'val' to 'min' and 'max'. | ||
99 | 34 | template <typename T> | ||
100 | 35 | T clamp(const T& val, const T& low, const T& high) { | ||
101 | 36 | if (val < low) { return low; } | ||
102 | 37 | if (val > high) { return high; } | ||
103 | 38 | return val; | ||
104 | 39 | } | ||
105 | 40 | |||
106 | 41 | } // namespace math | ||
107 | 42 | |||
108 | 43 | #endif // end of include guard: WL_BASE_MATH_H | ||
109 | 0 | 44 | ||
110 | === removed file 'src/base/point.h' | |||
111 | --- src/base/point.h 2016-08-04 15:49:05 +0000 | |||
112 | +++ src/base/point.h 1970-01-01 00:00:00 +0000 | |||
113 | @@ -1,79 +0,0 @@ | |||
114 | 1 | /* | ||
115 | 2 | * Copyright (C) 2002-2004, 2006-2013 by the Widelands Development Team | ||
116 | 3 | * | ||
117 | 4 | * This program is free software; you can redistribute it and/or | ||
118 | 5 | * modify it under the terms of the GNU General Public License | ||
119 | 6 | * as published by the Free Software Foundation; either version 2 | ||
120 | 7 | * of the License, or (at your option) any later version. | ||
121 | 8 | * | ||
122 | 9 | * This program is distributed in the hope that it will be useful, | ||
123 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
124 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
125 | 12 | * GNU General Public License for more details. | ||
126 | 13 | * | ||
127 | 14 | * You should have received a copy of the GNU General Public License | ||
128 | 15 | * along with this program; if not, write to the Free Software | ||
129 | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
130 | 17 | * | ||
131 | 18 | */ | ||
132 | 19 | |||
133 | 20 | #ifndef WL_BASE_POINT_H | ||
134 | 21 | #define WL_BASE_POINT_H | ||
135 | 22 | |||
136 | 23 | #include <limits> | ||
137 | 24 | |||
138 | 25 | #include <stdint.h> | ||
139 | 26 | |||
140 | 27 | template <typename T> struct GenericPoint { | ||
141 | 28 | GenericPoint(const T& px, const T& py) : x(px), y(py) { | ||
142 | 29 | } | ||
143 | 30 | GenericPoint() : GenericPoint(T(0), T(0)) { | ||
144 | 31 | } | ||
145 | 32 | |||
146 | 33 | // Returns an invalid point. | ||
147 | 34 | static GenericPoint invalid() { | ||
148 | 35 | return GenericPoint(std::numeric_limits<T>::max(), std::numeric_limits<T>::max()); | ||
149 | 36 | } | ||
150 | 37 | |||
151 | 38 | bool operator==(const GenericPoint& other) const { | ||
152 | 39 | return x == other.x && y == other.y; | ||
153 | 40 | } | ||
154 | 41 | bool operator!=(const GenericPoint& other) const { | ||
155 | 42 | return !(*this == other); | ||
156 | 43 | } | ||
157 | 44 | |||
158 | 45 | GenericPoint operator+(const GenericPoint& other) const { | ||
159 | 46 | return GenericPoint(x + other.x, y + other.y); | ||
160 | 47 | } | ||
161 | 48 | |||
162 | 49 | GenericPoint operator-() const { | ||
163 | 50 | return GenericPoint(-x, -y); | ||
164 | 51 | } | ||
165 | 52 | |||
166 | 53 | GenericPoint operator-(const GenericPoint& other) const { | ||
167 | 54 | return GenericPoint(x - other.x, y - other.y); | ||
168 | 55 | } | ||
169 | 56 | |||
170 | 57 | GenericPoint& operator+=(const GenericPoint& other) { | ||
171 | 58 | x += other.x; | ||
172 | 59 | y += other.y; | ||
173 | 60 | return *this; | ||
174 | 61 | } | ||
175 | 62 | |||
176 | 63 | GenericPoint& operator-=(const GenericPoint& other) { | ||
177 | 64 | x -= other.x; | ||
178 | 65 | y -= other.y; | ||
179 | 66 | return *this; | ||
180 | 67 | } | ||
181 | 68 | |||
182 | 69 | T x, y; | ||
183 | 70 | }; | ||
184 | 71 | |||
185 | 72 | using Point = GenericPoint<int>; | ||
186 | 73 | using FloatPoint = GenericPoint<float>; | ||
187 | 74 | |||
188 | 75 | /// Returns the point in the middle between a and b (rounded to integer | ||
189 | 76 | /// values). | ||
190 | 77 | Point middle(const Point& a, const Point& b); | ||
191 | 78 | |||
192 | 79 | #endif // end of include guard: WL_BASE_POINT_H | ||
193 | 80 | 0 | ||
194 | === modified file 'src/base/rect.h' | |||
195 | --- src/base/rect.h 2016-08-04 15:49:05 +0000 | |||
196 | +++ src/base/rect.h 2016-10-24 20:07:47 +0000 | |||
197 | @@ -20,41 +20,51 @@ | |||
198 | 20 | #ifndef WL_BASE_RECT_H | 20 | #ifndef WL_BASE_RECT_H |
199 | 21 | #define WL_BASE_RECT_H | 21 | #define WL_BASE_RECT_H |
200 | 22 | 22 | ||
202 | 23 | #include "base/point.h" | 23 | #include "base/vector.h" |
203 | 24 | 24 | ||
207 | 25 | template <typename T> struct GenericRect { | 25 | template <typename T> struct Rect { |
208 | 26 | /// Generates a degenerate Rect at (0, 0) with no height or width. | 26 | /// Generates a degenerate Recti at (0, 0) with no height or width. |
209 | 27 | GenericRect() : GenericRect(T(0), T(0), T(0), T(0)) { | 27 | Rect() : Rect(T(0), T(0), T(0), T(0)) { |
210 | 28 | } | 28 | } |
211 | 29 | 29 | ||
213 | 30 | GenericRect(const T& gx, const T& gy, const T& W, const T& H) : x(gx), y(gy), w(W), h(H) { | 30 | Rect(const T& gx, const T& gy, const T& W, const T& H) : x(gx), y(gy), w(W), h(H) { |
214 | 31 | } | 31 | } |
215 | 32 | 32 | ||
216 | 33 | template <typename PointType> | 33 | template <typename PointType> |
219 | 34 | GenericRect(const GenericPoint<PointType>& p, const T& width, const T& height) | 34 | Rect(const Vector2<PointType>& p, const T& width, const T& height) |
220 | 35 | : GenericRect(T(p.x), T(p.y), width, height) { | 35 | : Rect(T(p.x), T(p.y), width, height) { |
221 | 36 | } | 36 | } |
222 | 37 | 37 | ||
226 | 38 | /// The Point (x, y). | 38 | /// The Vector2i (x, y). |
227 | 39 | GenericPoint<T> origin() const { | 39 | Vector2<T> origin() const { |
228 | 40 | return GenericPoint<T>(x, y); | 40 | return Vector2<T>(x, y); |
229 | 41 | } | 41 | } |
230 | 42 | 42 | ||
231 | 43 | /// The point (x + w, y + h). | 43 | /// The point (x + w, y + h). |
234 | 44 | GenericPoint<T> opposite_of_origin() const { | 44 | Vector2<T> opposite_of_origin() const { |
235 | 45 | return GenericPoint<T>(x + w, y + h); | 45 | return Vector2<T>(x + w, y + h); |
236 | 46 | } | 46 | } |
237 | 47 | 47 | ||
238 | 48 | /// Returns true if this rectangle contains the given point. | 48 | /// Returns true if this rectangle contains the given point. |
239 | 49 | /// The bottom and right borders of the rectangle are considered to be excluded. | 49 | /// The bottom and right borders of the rectangle are considered to be excluded. |
241 | 50 | template <typename PointType> bool contains(const GenericPoint<PointType>& pt) const { | 50 | template <typename PointType> bool contains(const Vector2<PointType>& pt) const { |
242 | 51 | return T(pt.x) >= x && T(pt.x) < x + w && T(pt.y) >= y && T(pt.y) < y + h; | 51 | return T(pt.x) >= x && T(pt.x) < x + w && T(pt.y) >= y && T(pt.y) < y + h; |
243 | 52 | } | 52 | } |
244 | 53 | 53 | ||
245 | 54 | // The center point of 'r'. | ||
246 | 55 | Vector2f center() const { | ||
247 | 56 | return Vector2f(x + w / 2.f, y + h / 2.f); | ||
248 | 57 | } | ||
249 | 58 | |||
250 | 59 | template<typename Type> | ||
251 | 60 | Rect<Type> cast() const { | ||
252 | 61 | return Rect<Type>(Type(x), Type(y), Type(w), Type(h)); | ||
253 | 62 | } | ||
254 | 63 | |||
255 | 54 | T x, y, w, h; | 64 | T x, y, w, h; |
256 | 55 | }; | 65 | }; |
257 | 56 | 66 | ||
260 | 57 | using Rect = GenericRect<int>; | 67 | using Recti = Rect<int>; |
261 | 58 | using FloatRect = GenericRect<float>; | 68 | using Rectf = Rect<float>; |
262 | 59 | 69 | ||
263 | 60 | #endif // end of include guard: WL_BASE_RECT_H | 70 | #endif // end of include guard: WL_BASE_RECT_H |
264 | 61 | 71 | ||
265 | === renamed file 'src/base/point.cc' => 'src/base/vector.cc' | |||
266 | --- src/base/point.cc 2015-03-01 09:21:20 +0000 | |||
267 | +++ src/base/vector.cc 2016-10-24 20:07:47 +0000 | |||
268 | @@ -17,8 +17,14 @@ | |||
269 | 17 | * | 17 | * |
270 | 18 | */ | 18 | */ |
271 | 19 | 19 | ||
276 | 20 | #include "base/point.h" | 20 | #include "base/vector.h" |
277 | 21 | 21 | ||
278 | 22 | Point middle(const Point& a, const Point& b) { | 22 | #include <cmath> |
279 | 23 | return Point((a.x + b.x) / 2, (a.y + b.y) / 2); | 23 | |
280 | 24 | Vector2f middle(const Vector2f& a, const Vector2f& b) { | ||
281 | 25 | return Vector2f((a.x + b.x) / 2.f, (a.y + b.y) / 2.f); | ||
282 | 26 | } | ||
283 | 27 | |||
284 | 28 | Vector2i round(const Vector2f& a) { | ||
285 | 29 | return Vector2i(std::lround(a.x), std::lround(a.y)); | ||
286 | 24 | } | 30 | } |
287 | 25 | 31 | ||
288 | === renamed file 'src/wui/vector.h' => 'src/base/vector.h' | |||
289 | --- src/wui/vector.h 2016-08-04 15:49:05 +0000 | |||
290 | +++ src/base/vector.h 2016-10-24 20:07:47 +0000 | |||
291 | @@ -17,23 +17,88 @@ | |||
292 | 17 | * | 17 | * |
293 | 18 | */ | 18 | */ |
294 | 19 | 19 | ||
297 | 20 | #ifndef WL_WUI_VECTOR_H | 20 | #ifndef WL_BASE_VECTOR_H |
298 | 21 | #define WL_WUI_VECTOR_H | 21 | #define WL_BASE_VECTOR_H |
299 | 22 | 22 | ||
300 | 23 | #include <cmath> | 23 | #include <cmath> |
309 | 24 | 24 | #include <limits> | |
310 | 25 | // hm, floats... | 25 | |
311 | 26 | // tried to be faster with fixed point arithmetics | 26 | #include <stdint.h> |
312 | 27 | // it was, but i'll try to find other opts first | 27 | |
313 | 28 | struct Vector { | 28 | template <typename T> struct Vector2 { |
314 | 29 | Vector() : x(0), y(0), z(0) { | 29 | Vector2(const T& px, const T& py) : x(px), y(py) { |
315 | 30 | } | 30 | } |
316 | 31 | Vector(const float X, const float Y, const float Z) : x(X), y(Y), z(Z) { | 31 | Vector2() : Vector2(T(0), T(0)) { |
317 | 32 | } | ||
318 | 33 | |||
319 | 34 | // Returns an invalid point. | ||
320 | 35 | static Vector2 invalid() { | ||
321 | 36 | return Vector2(std::numeric_limits<T>::max(), std::numeric_limits<T>::max()); | ||
322 | 37 | } | ||
323 | 38 | |||
324 | 39 | bool operator==(const Vector2& other) const { | ||
325 | 40 | return x == other.x && y == other.y; | ||
326 | 41 | } | ||
327 | 42 | bool operator!=(const Vector2& other) const { | ||
328 | 43 | return !(*this == other); | ||
329 | 44 | } | ||
330 | 45 | |||
331 | 46 | Vector2 operator+(const Vector2& other) const { | ||
332 | 47 | return Vector2(x + other.x, y + other.y); | ||
333 | 48 | } | ||
334 | 49 | |||
335 | 50 | Vector2 operator*(const float a) const { | ||
336 | 51 | return Vector2(a * x, a * y); | ||
337 | 52 | } | ||
338 | 53 | |||
339 | 54 | Vector2 operator/(const float a) const { | ||
340 | 55 | return Vector2(x / a, y / a); | ||
341 | 56 | } | ||
342 | 57 | |||
343 | 58 | Vector2 operator-() const { | ||
344 | 59 | return Vector2(-x, -y); | ||
345 | 60 | } | ||
346 | 61 | |||
347 | 62 | Vector2 operator-(const Vector2& other) const { | ||
348 | 63 | return Vector2(x - other.x, y - other.y); | ||
349 | 64 | } | ||
350 | 65 | |||
351 | 66 | Vector2& operator+=(const Vector2& other) { | ||
352 | 67 | x += other.x; | ||
353 | 68 | y += other.y; | ||
354 | 69 | return *this; | ||
355 | 70 | } | ||
356 | 71 | |||
357 | 72 | Vector2& operator-=(const Vector2& other) { | ||
358 | 73 | x -= other.x; | ||
359 | 74 | y -= other.y; | ||
360 | 75 | return *this; | ||
361 | 76 | } | ||
362 | 77 | |||
363 | 78 | template<typename Type> | ||
364 | 79 | Vector2<Type> cast() const { | ||
365 | 80 | return Vector2<Type>(Type(x), Type(y)); | ||
366 | 81 | } | ||
367 | 82 | |||
368 | 83 | T x, y; | ||
369 | 84 | }; | ||
370 | 85 | |||
371 | 86 | using Vector2i = Vector2<int>; | ||
372 | 87 | using Vector2f = Vector2<float>; | ||
373 | 88 | |||
374 | 89 | /// Returns the point in the middle between a and b. | ||
375 | 90 | Vector2f middle(const Vector2f& a, const Vector2f& b); | ||
376 | 91 | |||
377 | 92 | // Returns an point rounded to the closest integer. | ||
378 | 93 | Vector2i round(const Vector2f& a); | ||
379 | 94 | |||
380 | 95 | struct Vector3f { | ||
381 | 96 | Vector3f(const float X, const float Y, const float Z) : x(X), y(Y), z(Z) { | ||
382 | 32 | } | 97 | } |
383 | 33 | 98 | ||
384 | 34 | void normalize() { | 99 | void normalize() { |
387 | 35 | const float f = static_cast<float>(sqrt(x * x + y * y + z * z)); | 100 | const float f = static_cast<float>(std::sqrt(x * x + y * y + z * z)); |
388 | 36 | if (fabs(f) < 0.00001) // check for ==0 | 101 | if (std::fabs(f) < 0.00001f) // check for ==0 |
389 | 37 | return; | 102 | return; |
390 | 38 | x /= f; | 103 | x /= f; |
391 | 39 | y /= f; | 104 | y /= f; |
392 | @@ -41,16 +106,16 @@ | |||
393 | 41 | } | 106 | } |
394 | 42 | 107 | ||
395 | 43 | // vector addition | 108 | // vector addition |
398 | 44 | Vector operator+(const Vector& other) const { | 109 | Vector3f operator+(const Vector3f& other) const { |
399 | 45 | return Vector(x + other.x, y + other.y, z + other.z); | 110 | return Vector3f(x + other.x, y + other.y, z + other.z); |
400 | 46 | } | 111 | } |
401 | 47 | 112 | ||
402 | 48 | // inner product | 113 | // inner product |
404 | 49 | float operator*(const Vector& other) const { | 114 | float dot(const Vector3f& other) const { |
405 | 50 | return x * other.x + y * other.y + z * other.z; | 115 | return x * other.x + y * other.y + z * other.z; |
406 | 51 | } | 116 | } |
407 | 52 | 117 | ||
408 | 53 | float x, y, z; | 118 | float x, y, z; |
409 | 54 | }; | 119 | }; |
410 | 55 | 120 | ||
412 | 56 | #endif // end of include guard: WL_WUI_VECTOR_H | 121 | #endif // end of include guard: WL_BASE_VECTOR_H |
413 | 57 | 122 | ||
414 | === modified file 'src/economy/flag.h' | |||
415 | --- src/economy/flag.h 2016-08-04 15:49:05 +0000 | |||
416 | +++ src/economy/flag.h 2016-10-24 20:07:47 +0000 | |||
417 | @@ -25,6 +25,7 @@ | |||
418 | 25 | 25 | ||
419 | 26 | #include "base/macros.h" | 26 | #include "base/macros.h" |
420 | 27 | #include "economy/routing_node.h" | 27 | #include "economy/routing_node.h" |
421 | 28 | #include "logic/map_objects/draw_text.h" | ||
422 | 28 | #include "logic/map_objects/immovable.h" | 29 | #include "logic/map_objects/immovable.h" |
423 | 29 | 30 | ||
424 | 30 | namespace Widelands { | 31 | namespace Widelands { |
425 | @@ -144,7 +145,11 @@ | |||
426 | 144 | void init(EditorGameBase&) override; | 145 | void init(EditorGameBase&) override; |
427 | 145 | void cleanup(EditorGameBase&) override; | 146 | void cleanup(EditorGameBase&) override; |
428 | 146 | 147 | ||
430 | 147 | void draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) override; | 148 | void draw(uint32_t gametime, |
431 | 149 | DrawText draw_text, | ||
432 | 150 | const Vector2f& point_on_dst, | ||
433 | 151 | float scale, | ||
434 | 152 | RenderTarget* dst) override; | ||
435 | 148 | 153 | ||
436 | 149 | void wake_up_capacity_queue(Game&); | 154 | void wake_up_capacity_queue(Game&); |
437 | 150 | 155 | ||
438 | 151 | 156 | ||
439 | === modified file 'src/economy/portdock.cc' | |||
440 | --- src/economy/portdock.cc 2016-09-30 07:34:06 +0000 | |||
441 | +++ src/economy/portdock.cc 2016-10-24 20:07:47 +0000 | |||
442 | @@ -141,7 +141,7 @@ | |||
443 | 141 | expedition_bootstrap_->set_economy(e); | 141 | expedition_bootstrap_->set_economy(e); |
444 | 142 | } | 142 | } |
445 | 143 | 143 | ||
447 | 144 | void PortDock::draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) { | 144 | void PortDock::draw(uint32_t, const DrawText, const Vector2f&, float, RenderTarget*) { |
448 | 145 | // do nothing | 145 | // do nothing |
449 | 146 | } | 146 | } |
450 | 147 | 147 | ||
451 | 148 | 148 | ||
452 | === modified file 'src/economy/portdock.h' | |||
453 | --- src/economy/portdock.h 2016-08-04 15:49:05 +0000 | |||
454 | +++ src/economy/portdock.h 2016-10-24 20:07:47 +0000 | |||
455 | @@ -96,7 +96,11 @@ | |||
456 | 96 | 96 | ||
457 | 97 | Flag& base_flag() override; | 97 | Flag& base_flag() override; |
458 | 98 | PositionList get_positions(const EditorGameBase&) const override; | 98 | PositionList get_positions(const EditorGameBase&) const override; |
460 | 99 | void draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) override; | 99 | void draw(uint32_t gametime, |
461 | 100 | DrawText draw_text, | ||
462 | 101 | const Vector2f& point_on_dst, | ||
463 | 102 | float scale, | ||
464 | 103 | RenderTarget* dst) override; | ||
465 | 100 | 104 | ||
466 | 101 | void init(EditorGameBase&) override; | 105 | void init(EditorGameBase&) override; |
467 | 102 | void cleanup(EditorGameBase&) override; | 106 | void cleanup(EditorGameBase&) override; |
468 | 103 | 107 | ||
469 | === modified file 'src/economy/road.h' | |||
470 | --- src/economy/road.h 2016-08-04 15:49:05 +0000 | |||
471 | +++ src/economy/road.h 2016-10-24 20:07:47 +0000 | |||
472 | @@ -118,7 +118,11 @@ | |||
473 | 118 | void init(EditorGameBase&) override; | 118 | void init(EditorGameBase&) override; |
474 | 119 | void cleanup(EditorGameBase&) override; | 119 | void cleanup(EditorGameBase&) override; |
475 | 120 | 120 | ||
477 | 121 | void draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) override; | 121 | void draw(uint32_t gametime, |
478 | 122 | DrawText draw_text, | ||
479 | 123 | const Vector2f& point_on_dst, | ||
480 | 124 | float scale, | ||
481 | 125 | RenderTarget* dst) override; | ||
482 | 122 | 126 | ||
483 | 123 | private: | 127 | private: |
484 | 124 | void set_path(EditorGameBase&, const Path&); | 128 | void set_path(EditorGameBase&, const Path&); |
485 | 125 | 129 | ||
486 | === modified file 'src/editor/editorinteractive.cc' | |||
487 | --- src/editor/editorinteractive.cc 2016-09-25 18:46:29 +0000 | |||
488 | +++ src/editor/editorinteractive.cc 2016-10-24 20:07:47 +0000 | |||
489 | @@ -160,6 +160,8 @@ | |||
490 | 160 | [this](const Widelands::NoteFieldResourceChanged& note) { | 160 | [this](const Widelands::NoteFieldResourceChanged& note) { |
491 | 161 | update_resource_overlay(note, egbase().world(), mutable_field_overlay_manager()); | 161 | update_resource_overlay(note, egbase().world(), mutable_field_overlay_manager()); |
492 | 162 | }); | 162 | }); |
493 | 163 | |||
494 | 164 | minimap_registry().minimap_type = MiniMapType::kStaticMap; | ||
495 | 163 | } | 165 | } |
496 | 164 | 166 | ||
497 | 165 | void EditorInteractive::register_overlays() { | 167 | void EditorInteractive::register_overlays() { |
498 | @@ -173,7 +175,7 @@ | |||
499 | 173 | const Image* player_image = g_gr->images().get(player_pictures[p - 1]); | 175 | const Image* player_image = g_gr->images().get(player_pictures[p - 1]); |
500 | 174 | assert(player_image); | 176 | assert(player_image); |
501 | 175 | mutable_field_overlay_manager()->register_overlay( | 177 | mutable_field_overlay_manager()->register_overlay( |
503 | 176 | sp, player_image, 8, Point(player_image->width() / 2, STARTING_POS_HOTSPOT_Y)); | 178 | sp, player_image, 8, Vector2i(player_image->width() / 2, STARTING_POS_HOTSPOT_Y)); |
504 | 177 | } | 179 | } |
505 | 178 | } | 180 | } |
506 | 179 | 181 | ||
507 | @@ -669,7 +671,7 @@ | |||
508 | 669 | } | 671 | } |
509 | 670 | 672 | ||
510 | 671 | // Make sure that we will start at coordinates (0,0). | 673 | // Make sure that we will start at coordinates (0,0). |
512 | 672 | set_viewpoint(Point(0, 0), true); | 674 | set_viewpoint(Vector2f(0, 0), true); |
513 | 673 | set_sel_pos(Widelands::NodeAndTriangle<>( | 675 | set_sel_pos(Widelands::NodeAndTriangle<>( |
514 | 674 | Widelands::Coords(0, 0), | 676 | Widelands::Coords(0, 0), |
515 | 675 | Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TCoords<>::D))); | 677 | Widelands::TCoords<>(Widelands::Coords(0, 0), Widelands::TCoords<>::D))); |
516 | 676 | 678 | ||
517 | === modified file 'src/editor/tools/set_origin_tool.cc' | |||
518 | --- src/editor/tools/set_origin_tool.cc 2016-08-04 15:49:05 +0000 | |||
519 | +++ src/editor/tools/set_origin_tool.cc 2016-10-24 20:07:47 +0000 | |||
520 | @@ -30,9 +30,7 @@ | |||
521 | 30 | Widelands::Map* map) { | 30 | Widelands::Map* map) { |
522 | 31 | map->set_origin(center.node); | 31 | map->set_origin(center.node); |
523 | 32 | eia.map_changed(EditorInteractive::MapWas::kGloballyMutated); | 32 | eia.map_changed(EditorInteractive::MapWas::kGloballyMutated); |
527 | 33 | eia.set_rel_viewpoint(Point(-(center.node.x * 2 + (center.node.y & 1)) * (kTriangleWidth / 2), | 33 | eia.center_view_on_coords(Widelands::Coords(0, 0)); |
525 | 34 | -center.node.y * kTriangleHeight), | ||
526 | 35 | true); | ||
528 | 36 | return 0; | 34 | return 0; |
529 | 37 | } | 35 | } |
530 | 38 | 36 | ||
531 | @@ -46,8 +44,7 @@ | |||
532 | 46 | map->get_width() - 1 - center.node.x, map->get_height() - 1 - center.node.y); | 44 | map->get_width() - 1 - center.node.x, map->get_height() - 1 - center.node.y); |
533 | 47 | map->set_origin(nc); | 45 | map->set_origin(nc); |
534 | 48 | eia.map_changed(EditorInteractive::MapWas::kGloballyMutated); | 46 | eia.map_changed(EditorInteractive::MapWas::kGloballyMutated); |
537 | 49 | eia.set_rel_viewpoint( | 47 | eia.center_view_on_coords(Widelands::Coords(0, 0)); |
536 | 50 | Point(-(nc.x * 2 + (nc.y & 1)) * (kTriangleWidth / 2), -nc.y * kTriangleHeight), true); | ||
538 | 51 | return 0; | 48 | return 0; |
539 | 52 | } | 49 | } |
540 | 53 | 50 | ||
541 | 54 | 51 | ||
542 | === modified file 'src/editor/tools/set_starting_pos_tool.cc' | |||
543 | --- src/editor/tools/set_starting_pos_tool.cc 2016-08-04 15:49:05 +0000 | |||
544 | +++ src/editor/tools/set_starting_pos_tool.cc 2016-10-24 20:07:47 +0000 | |||
545 | @@ -113,7 +113,7 @@ | |||
546 | 113 | 113 | ||
547 | 114 | // add new overlay | 114 | // add new overlay |
548 | 115 | overlay_manager->register_overlay( | 115 | overlay_manager->register_overlay( |
550 | 116 | center.node, player_image, 4, Point(player_image->width() / 2, STARTING_POS_HOTSPOT_Y)); | 116 | center.node, player_image, 4, Vector2i(player_image->width() / 2, STARTING_POS_HOTSPOT_Y)); |
551 | 117 | 117 | ||
552 | 118 | // set new player pos | 118 | // set new player pos |
553 | 119 | map->set_starting_pos(current_player_, center.node); | 119 | map->set_starting_pos(current_player_, center.node); |
554 | 120 | 120 | ||
555 | === modified file 'src/editor/ui_menus/main_menu_load_or_save_map.cc' | |||
556 | --- src/editor/ui_menus/main_menu_load_or_save_map.cc 2016-08-04 18:09:55 +0000 | |||
557 | +++ src/editor/ui_menus/main_menu_load_or_save_map.cc 2016-10-24 20:07:47 +0000 | |||
558 | @@ -89,7 +89,7 @@ | |||
559 | 89 | vbox->add(show_mapnames_, UI::Align::kLeft, true); | 89 | vbox->add(show_mapnames_, UI::Align::kLeft, true); |
560 | 90 | 90 | ||
561 | 91 | /** TRANSLATORS: Checkbox title. If this checkbox is enabled, map names aren't translated. */ | 91 | /** TRANSLATORS: Checkbox title. If this checkbox is enabled, map names aren't translated. */ |
563 | 92 | cb_dont_localize_mapnames_ = new UI::Checkbox(vbox, Point(0, 0), _("Show original map names")); | 92 | cb_dont_localize_mapnames_ = new UI::Checkbox(vbox, Vector2i(0, 0), _("Show original map names")); |
564 | 93 | cb_dont_localize_mapnames_->set_state(false); | 93 | cb_dont_localize_mapnames_->set_state(false); |
565 | 94 | vbox->add_space(2 * padding_); | 94 | vbox->add_space(2 * padding_); |
566 | 95 | vbox->add(cb_dont_localize_mapnames_, UI::Align::kLeft, true); | 95 | vbox->add(cb_dont_localize_mapnames_, UI::Align::kLeft, true); |
567 | 96 | 96 | ||
568 | === modified file 'src/editor/ui_menus/main_menu_map_options.cc' | |||
569 | --- src/editor/ui_menus/main_menu_map_options.cc 2016-08-07 10:10:18 +0000 | |||
570 | +++ src/editor/ui_menus/main_menu_map_options.cc 2016-10-24 20:07:47 +0000 | |||
571 | @@ -227,7 +227,7 @@ | |||
572 | 227 | std::string tag, | 227 | std::string tag, |
573 | 228 | std::string displ_name) { | 228 | std::string displ_name) { |
574 | 229 | UI::Box* box = new UI::Box(parent, 0, 0, UI::Box::Horizontal, max_w_, checkbox_space_, 0); | 229 | UI::Box* box = new UI::Box(parent, 0, 0, UI::Box::Horizontal, max_w_, checkbox_space_, 0); |
576 | 230 | UI::Checkbox* cb = new UI::Checkbox(box, Point(0, 0), displ_name); | 230 | UI::Checkbox* cb = new UI::Checkbox(box, Vector2i(0, 0), displ_name); |
577 | 231 | box->add(cb, UI::Align::kLeft, true); | 231 | box->add(cb, UI::Align::kLeft, true); |
578 | 232 | box->add_space(checkbox_space_); | 232 | box->add_space(checkbox_space_); |
579 | 233 | parent->add(box, UI::Align::kLeft); | 233 | parent->add(box, UI::Align::kLeft); |
580 | 234 | 234 | ||
581 | === modified file 'src/editor/ui_menus/main_menu_random_map.cc' | |||
582 | --- src/editor/ui_menus/main_menu_random_map.cc 2016-08-04 15:49:05 +0000 | |||
583 | +++ src/editor/ui_menus/main_menu_random_map.cc 2016-10-24 20:07:47 +0000 | |||
584 | @@ -184,7 +184,7 @@ | |||
585 | 184 | resources_label_.get_h(), | 184 | resources_label_.get_h(), |
586 | 185 | (boost::format(_("%i %%")) % mountainsval_).str(), | 185 | (boost::format(_("%i %%")) % mountainsval_).str(), |
587 | 186 | UI::Align::kHCenter), | 186 | UI::Align::kHCenter), |
589 | 187 | island_mode_(&box_, Point(0, 0), _("Island mode")), | 187 | island_mode_(&box_, Vector2i(0, 0), _("Island mode")), |
590 | 188 | // Geeky stuff | 188 | // Geeky stuff |
591 | 189 | map_number_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_), | 189 | map_number_box_(&box_, 0, 0, UI::Box::Horizontal, 0, 0, margin_), |
592 | 190 | map_number_label_(&map_number_box_, 0, 0, _("Random Number:")), | 190 | map_number_label_(&map_number_box_, 0, 0, _("Random Number:")), |
593 | 191 | 191 | ||
594 | === modified file 'src/editor/ui_menus/main_menu_save_map.h' | |||
595 | --- src/editor/ui_menus/main_menu_save_map.h 2016-08-04 15:49:05 +0000 | |||
596 | +++ src/editor/ui_menus/main_menu_save_map.h 2016-10-24 20:07:47 +0000 | |||
597 | @@ -40,7 +40,7 @@ | |||
598 | 40 | 40 | ||
599 | 41 | private: | 41 | private: |
600 | 42 | EditorInteractive& eia(); | 42 | EditorInteractive& eia(); |
602 | 43 | void clicked_ok(); | 43 | void clicked_ok() override; |
603 | 44 | void clicked_make_directory(); | 44 | void clicked_make_directory(); |
604 | 45 | void clicked_edit_options(); | 45 | void clicked_edit_options(); |
605 | 46 | void clicked_item(); | 46 | void clicked_item(); |
606 | 47 | 47 | ||
607 | === modified file 'src/editor/ui_menus/player_menu.cc' | |||
608 | --- src/editor/ui_menus/player_menu.cc 2016-09-25 11:24:10 +0000 | |||
609 | +++ src/editor/ui_menus/player_menu.cc 2016-10-24 20:07:47 +0000 | |||
610 | @@ -95,11 +95,11 @@ | |||
611 | 95 | set_inner_size(375, 135); | 95 | set_inner_size(375, 135); |
612 | 96 | 96 | ||
613 | 97 | UI::Textarea* ta = new UI::Textarea(this, 0, 0, _("Number of Players")); | 97 | UI::Textarea* ta = new UI::Textarea(this, 0, 0, _("Number of Players")); |
615 | 98 | ta->set_pos(Point((get_inner_w() - ta->get_w()) / 2, posy + 5)); | 98 | ta->set_pos(Vector2i((get_inner_w() - ta->get_w()) / 2, posy + 5)); |
616 | 99 | posy += spacing + width; | 99 | posy += spacing + width; |
617 | 100 | 100 | ||
618 | 101 | nr_of_players_ta_ = new UI::Textarea(this, 0, 0, "5"); | 101 | nr_of_players_ta_ = new UI::Textarea(this, 0, 0, "5"); |
620 | 102 | nr_of_players_ta_->set_pos(Point((get_inner_w() - nr_of_players_ta_->get_w()) / 2, posy + 5)); | 102 | nr_of_players_ta_->set_pos(Vector2i((get_inner_w() - nr_of_players_ta_->get_w()) / 2, posy + 5)); |
621 | 103 | 103 | ||
622 | 104 | posy += width + spacing + spacing; | 104 | posy += width + spacing + spacing; |
623 | 105 | 105 | ||
624 | @@ -292,7 +292,7 @@ | |||
625 | 292 | // jump to the current node | 292 | // jump to the current node |
626 | 293 | Widelands::Map& map = menu.egbase().map(); | 293 | Widelands::Map& map = menu.egbase().map(); |
627 | 294 | if (Widelands::Coords const sp = map.get_starting_pos(n)) | 294 | if (Widelands::Coords const sp = map.get_starting_pos(n)) |
629 | 295 | menu.move_view_to(sp); | 295 | menu.center_view_on_coords(sp); |
630 | 296 | 296 | ||
631 | 297 | // select tool set mplayer | 297 | // select tool set mplayer |
632 | 298 | menu.select_tool(menu.tools()->set_starting_pos, EditorTool::First); | 298 | menu.select_tool(menu.tools()->set_starting_pos, EditorTool::First); |
633 | 299 | 299 | ||
634 | === modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc' | |||
635 | --- src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-08-04 15:49:05 +0000 | |||
636 | +++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2016-10-24 20:07:47 +0000 | |||
637 | @@ -100,7 +100,7 @@ | |||
638 | 100 | 100 | ||
639 | 101 | for (Widelands::DescriptionIndex i = 0; i < nr_resources; ++i) { | 101 | for (Widelands::DescriptionIndex i = 0; i < nr_resources; ++i) { |
640 | 102 | const Widelands::ResourceDescription& resource = *world.get_resource(i); | 102 | const Widelands::ResourceDescription& resource = *world.get_resource(i); |
642 | 103 | radiogroup_.add_button(&resources_box_, Point(0, 0), | 103 | radiogroup_.add_button(&resources_box_, Vector2i(0, 0), |
643 | 104 | g_gr->images().get(resource.representative_image()), | 104 | g_gr->images().get(resource.representative_image()), |
644 | 105 | resource.descname()); | 105 | resource.descname()); |
645 | 106 | resources_box_.add(radiogroup_.get_first_button(), UI::Align::kLeft, false, true); | 106 | resources_box_.add(radiogroup_.get_first_button(), UI::Align::kLeft, false, true); |
646 | 107 | 107 | ||
647 | === modified file 'src/editor/ui_menus/tool_menu.cc' | |||
648 | --- src/editor/ui_menus/tool_menu.cc 2016-08-04 15:49:05 +0000 | |||
649 | +++ src/editor/ui_menus/tool_menu.cc 2016-10-24 20:07:47 +0000 | |||
650 | @@ -45,8 +45,8 @@ | |||
651 | 45 | : UI::UniqueWindow(&parent, "tool_menu", ®istry, 350, 400, _("Tools")) { | 45 | : UI::UniqueWindow(&parent, "tool_menu", ®istry, 350, 400, _("Tools")) { |
652 | 46 | 46 | ||
653 | 47 | #define spacing 5 | 47 | #define spacing 5 |
656 | 48 | Point const offs(spacing, spacing); | 48 | Vector2i const offs(spacing, spacing); |
657 | 49 | Point pos = offs; | 49 | Vector2i pos = offs; |
658 | 50 | int32_t const width = 34; | 50 | int32_t const width = 34; |
659 | 51 | int32_t const height = 34; | 51 | int32_t const height = 34; |
660 | 52 | 52 | ||
661 | 53 | 53 | ||
662 | === modified file 'src/editor/ui_menus/tool_place_bob_options_menu.cc' | |||
663 | --- src/editor/ui_menus/tool_place_bob_options_menu.cc 2016-08-04 15:49:05 +0000 | |||
664 | +++ src/editor/ui_menus/tool_place_bob_options_menu.cc 2016-10-24 20:07:47 +0000 | |||
665 | @@ -64,14 +64,14 @@ | |||
666 | 64 | } | 64 | } |
667 | 65 | 65 | ||
668 | 66 | const Image* tab_icon = g_gr->images().get("images/ui_basic/list_first_entry.png"); | 66 | const Image* tab_icon = g_gr->images().get("images/ui_basic/list_first_entry.png"); |
670 | 67 | Point pos; | 67 | Vector2i pos; |
671 | 68 | uint32_t cur_x = bobs_in_row; | 68 | uint32_t cur_x = bobs_in_row; |
672 | 69 | int32_t i = 0; | 69 | int32_t i = 0; |
673 | 70 | UI::Box* box = nullptr; | 70 | UI::Box* box = nullptr; |
674 | 71 | while (i < nr_bobs) { | 71 | while (i < nr_bobs) { |
675 | 72 | if (cur_x == bobs_in_row) { | 72 | if (cur_x == bobs_in_row) { |
676 | 73 | cur_x = 0; | 73 | cur_x = 0; |
678 | 74 | pos = Point(5, 15); | 74 | pos = Vector2i(5, 15); |
679 | 75 | box = new UI::Box(&tabpanel_, 0, 0, UI::Box::Horizontal); | 75 | box = new UI::Box(&tabpanel_, 0, 0, UI::Box::Horizontal); |
680 | 76 | tabpanel_.add("icons", tab_icon, box); | 76 | tabpanel_.add("icons", tab_icon, box); |
681 | 77 | } | 77 | } |
682 | 78 | 78 | ||
683 | === modified file 'src/editor/ui_menus/tool_place_immovable_options_menu.cc' | |||
684 | --- src/editor/ui_menus/tool_place_immovable_options_menu.cc 2016-08-04 15:49:05 +0000 | |||
685 | +++ src/editor/ui_menus/tool_place_immovable_options_menu.cc 2016-10-24 20:07:47 +0000 | |||
686 | @@ -39,7 +39,7 @@ | |||
687 | 39 | 39 | ||
688 | 40 | UI::Checkbox* create_immovable_checkbox(UI::Panel* parent, const ImmovableDescr& immovable_descr) { | 40 | UI::Checkbox* create_immovable_checkbox(UI::Panel* parent, const ImmovableDescr& immovable_descr) { |
689 | 41 | const Image* pic = immovable_descr.representative_image(); | 41 | const Image* pic = immovable_descr.representative_image(); |
691 | 42 | UI::Checkbox* cb = new UI::Checkbox(parent, Point(0, 0), pic, immovable_descr.descname()); | 42 | UI::Checkbox* cb = new UI::Checkbox(parent, Vector2i(0, 0), pic, immovable_descr.descname()); |
692 | 43 | const int kMinClickableArea = 24; | 43 | const int kMinClickableArea = 24; |
693 | 44 | cb->set_desired_size(std::max<int>(pic->width(), kMinClickableArea), | 44 | cb->set_desired_size(std::max<int>(pic->width(), kMinClickableArea), |
694 | 45 | std::max<int>(pic->height(), kMinClickableArea)); | 45 | std::max<int>(pic->height(), kMinClickableArea)); |
695 | 46 | 46 | ||
696 | === modified file 'src/editor/ui_menus/tool_set_terrain_options_menu.cc' | |||
697 | --- src/editor/ui_menus/tool_set_terrain_options_menu.cc 2016-08-04 15:49:05 +0000 | |||
698 | +++ src/editor/ui_menus/tool_set_terrain_options_menu.cc 2016-10-24 20:07:47 +0000 | |||
699 | @@ -53,10 +53,10 @@ | |||
700 | 53 | // Blit the main terrain image | 53 | // Blit the main terrain image |
701 | 54 | const Image& terrain_texture = terrain_descr.get_texture(0); | 54 | const Image& terrain_texture = terrain_descr.get_texture(0); |
702 | 55 | Texture* texture = new Texture(terrain_texture.width(), terrain_texture.height()); | 55 | Texture* texture = new Texture(terrain_texture.width(), terrain_texture.height()); |
705 | 56 | texture->blit(Rect(0, 0, terrain_texture.width(), terrain_texture.height()), terrain_texture, | 56 | texture->blit(Rectf(0, 0, terrain_texture.width(), terrain_texture.height()), terrain_texture, |
706 | 57 | Rect(0, 0, terrain_texture.width(), terrain_texture.height()), 1., | 57 | Rectf(0, 0, terrain_texture.width(), terrain_texture.height()), 1., |
707 | 58 | BlendMode::UseAlpha); | 58 | BlendMode::UseAlpha); |
709 | 59 | Point pt(1, terrain_texture.height() - kSmallPicSize - 1); | 59 | Vector2i pt(1, terrain_texture.height() - kSmallPicSize - 1); |
710 | 60 | 60 | ||
711 | 61 | // Collect tooltips and blit small icons representing "is" values | 61 | // Collect tooltips and blit small icons representing "is" values |
712 | 62 | for (const TerrainDescription::Type& terrain_type : terrain_descr.get_types()) { | 62 | for (const TerrainDescription::Type& terrain_type : terrain_descr.get_types()) { |
713 | @@ -64,9 +64,9 @@ | |||
714 | 64 | terrain_descr.custom_tooltips().end()); | 64 | terrain_descr.custom_tooltips().end()); |
715 | 65 | tooltips.push_back(terrain_type.descname); | 65 | tooltips.push_back(terrain_type.descname); |
716 | 66 | 66 | ||
718 | 67 | texture->blit(Rect(pt.x, pt.y, terrain_type.icon->width(), terrain_type.icon->height()), | 67 | texture->blit(Rectf(pt.x, pt.y, terrain_type.icon->width(), terrain_type.icon->height()), |
719 | 68 | *terrain_type.icon, | 68 | *terrain_type.icon, |
721 | 69 | Rect(0, 0, terrain_type.icon->width(), terrain_type.icon->height()), 1., | 69 | Rectf(0, 0, terrain_type.icon->width(), terrain_type.icon->height()), 1., |
722 | 70 | BlendMode::UseAlpha); | 70 | BlendMode::UseAlpha); |
723 | 71 | pt.x += kSmallPicSize + 1; | 71 | pt.x += kSmallPicSize + 1; |
724 | 72 | } | 72 | } |
725 | @@ -79,7 +79,7 @@ | |||
726 | 79 | .str(); | 79 | .str(); |
727 | 80 | 80 | ||
728 | 81 | std::unique_ptr<const Image>& image = offscreen_images->back(); | 81 | std::unique_ptr<const Image>& image = offscreen_images->back(); |
730 | 82 | UI::Checkbox* cb = new UI::Checkbox(parent, Point(0, 0), image.get(), tooltip); | 82 | UI::Checkbox* cb = new UI::Checkbox(parent, Vector2i(0, 0), image.get(), tooltip); |
731 | 83 | cb->set_desired_size(image->width() + 1, image->height() + 1); | 83 | cb->set_desired_size(image->width() + 1, image->height() + 1); |
732 | 84 | return cb; | 84 | return cb; |
733 | 85 | } | 85 | } |
734 | 86 | 86 | ||
735 | === modified file 'src/game_io/CMakeLists.txt' | |||
736 | --- src/game_io/CMakeLists.txt 2016-01-20 20:12:00 +0000 | |||
737 | +++ src/game_io/CMakeLists.txt 2016-10-24 20:07:47 +0000 | |||
738 | @@ -30,6 +30,7 @@ | |||
739 | 30 | build_info | 30 | build_info |
740 | 31 | economy | 31 | economy |
741 | 32 | graphic | 32 | graphic |
742 | 33 | graphic_image_io | ||
743 | 33 | graphic_minimap_renderer | 34 | graphic_minimap_renderer |
744 | 34 | io_fileread | 35 | io_fileread |
745 | 35 | io_filesystem | 36 | io_filesystem |
746 | @@ -42,4 +43,5 @@ | |||
747 | 42 | scripting_lua_table | 43 | scripting_lua_table |
748 | 43 | wui | 44 | wui |
749 | 44 | wui_mapview_pixelfunctions | 45 | wui_mapview_pixelfunctions |
750 | 46 | wui_mapview | ||
751 | 45 | ) | 47 | ) |
752 | 46 | 48 | ||
753 | === modified file 'src/game_io/game_interactive_player_packet.cc' | |||
754 | --- src/game_io/game_interactive_player_packet.cc 2016-08-04 15:49:05 +0000 | |||
755 | +++ src/game_io/game_interactive_player_packet.cc 2016-10-24 20:07:47 +0000 | |||
756 | @@ -30,7 +30,22 @@ | |||
757 | 30 | 30 | ||
758 | 31 | namespace Widelands { | 31 | namespace Widelands { |
759 | 32 | 32 | ||
761 | 33 | constexpr uint16_t kCurrentPacketVersion = 3; | 33 | namespace { |
762 | 34 | |||
763 | 35 | constexpr uint16_t kCurrentPacketVersion = 4; | ||
764 | 36 | |||
765 | 37 | void load_landmarks_pre_zoom(FileRead* fr, InteractiveBase* ibase) { | ||
766 | 38 | size_t no_of_landmarks = fr->unsigned_8(); | ||
767 | 39 | for (size_t i = 0; i < no_of_landmarks; ++i) { | ||
768 | 40 | uint8_t set = fr->unsigned_8(); | ||
769 | 41 | QuickNavigation::View view = {Vector2f(fr->signed_32(), fr->signed_32()), 1.f}; | ||
770 | 42 | if (set > 0) { | ||
771 | 43 | ibase->set_landmark(i, view); | ||
772 | 44 | } | ||
773 | 45 | } | ||
774 | 46 | } | ||
775 | 47 | |||
776 | 48 | } // namespace | ||
777 | 34 | 49 | ||
778 | 35 | void GameInteractivePlayerPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) { | 50 | void GameInteractivePlayerPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) { |
779 | 36 | try { | 51 | try { |
780 | @@ -55,12 +70,19 @@ | |||
781 | 55 | if (player_number > max) | 70 | if (player_number > max) |
782 | 56 | throw GameDataError("The game has no players!"); | 71 | throw GameDataError("The game has no players!"); |
783 | 57 | } | 72 | } |
786 | 58 | int32_t const x = fr.unsigned_16(); | 73 | float viewpoint_x, viewpoint_y; |
787 | 59 | int32_t const y = fr.unsigned_16(); | 74 | if (packet_version <= 3) { |
788 | 75 | viewpoint_x = fr.unsigned_16(); | ||
789 | 76 | viewpoint_y = fr.unsigned_16(); | ||
790 | 77 | } else { | ||
791 | 78 | viewpoint_x = fr.float_32(); | ||
792 | 79 | viewpoint_y = fr.float_32(); | ||
793 | 80 | } | ||
794 | 81 | |||
795 | 60 | uint32_t const display_flags = fr.unsigned_32(); | 82 | uint32_t const display_flags = fr.unsigned_32(); |
796 | 61 | 83 | ||
797 | 62 | if (InteractiveBase* const ibase = game.get_ibase()) { | 84 | if (InteractiveBase* const ibase = game.get_ibase()) { |
799 | 63 | ibase->set_viewpoint(Point(x, y), true); | 85 | ibase->set_viewpoint(Vector2f(viewpoint_x, viewpoint_y), true); |
800 | 64 | 86 | ||
801 | 65 | uint32_t const loaded_df = | 87 | uint32_t const loaded_df = |
802 | 66 | InteractiveBase::dfShowCensus | InteractiveBase::dfShowStatistics; | 88 | InteractiveBase::dfShowCensus | InteractiveBase::dfShowStatistics; |
803 | @@ -73,14 +95,19 @@ | |||
804 | 73 | } | 95 | } |
805 | 74 | 96 | ||
806 | 75 | // Map landmarks | 97 | // Map landmarks |
809 | 76 | if (packet_version >= 3) { | 98 | if (InteractiveBase* const ibase = game.get_ibase()) { |
810 | 77 | if (InteractiveBase* const ibase = game.get_ibase()) { | 99 | if (packet_version == 3) { |
811 | 100 | load_landmarks_pre_zoom(&fr, ibase); | ||
812 | 101 | } else if (packet_version >= 4) { | ||
813 | 78 | size_t no_of_landmarks = fr.unsigned_8(); | 102 | size_t no_of_landmarks = fr.unsigned_8(); |
814 | 79 | for (size_t i = 0; i < no_of_landmarks; ++i) { | 103 | for (size_t i = 0; i < no_of_landmarks; ++i) { |
815 | 80 | uint8_t set = fr.unsigned_8(); | 104 | uint8_t set = fr.unsigned_8(); |
817 | 81 | Point landmark(fr.signed_32(), fr.signed_32()); | 105 | const float x = fr.float_32(); |
818 | 106 | const float y = fr.float_32(); | ||
819 | 107 | const float zoom = fr.float_32(); | ||
820 | 108 | QuickNavigation::View view = {Vector2f(x, y), zoom}; | ||
821 | 82 | if (set > 0) { | 109 | if (set > 0) { |
823 | 83 | ibase->set_landmark(i, landmark); | 110 | ibase->set_landmark(i, view); |
824 | 84 | } | 111 | } |
825 | 85 | } | 112 | } |
826 | 86 | } | 113 | } |
827 | @@ -109,12 +136,14 @@ | |||
828 | 109 | fw.unsigned_8(iplayer ? iplayer->player_number() : 1); | 136 | fw.unsigned_8(iplayer ? iplayer->player_number() : 1); |
829 | 110 | 137 | ||
830 | 111 | // Map Position | 138 | // Map Position |
831 | 139 | #ifndef NDEBUG | ||
832 | 112 | if (ibase) { | 140 | if (ibase) { |
833 | 113 | assert(0 <= ibase->get_viewpoint().x); | 141 | assert(0 <= ibase->get_viewpoint().x); |
834 | 114 | assert(0 <= ibase->get_viewpoint().y); | 142 | assert(0 <= ibase->get_viewpoint().y); |
835 | 115 | } | 143 | } |
838 | 116 | fw.unsigned_16(ibase ? ibase->get_viewpoint().x : 0); | 144 | #endif |
839 | 117 | fw.unsigned_16(ibase ? ibase->get_viewpoint().y : 0); | 145 | fw.float_32(ibase ? ibase->get_viewpoint().x : 0.f); |
840 | 146 | fw.float_32(ibase ? ibase->get_viewpoint().y : 0.f); | ||
841 | 118 | 147 | ||
842 | 119 | // Display flags | 148 | // Display flags |
843 | 120 | fw.unsigned_32(ibase ? ibase->get_display_flags() : 0); | 149 | fw.unsigned_32(ibase ? ibase->get_display_flags() : 0); |
844 | @@ -124,8 +153,9 @@ | |||
845 | 124 | fw.unsigned_8(landmarks.size()); | 153 | fw.unsigned_8(landmarks.size()); |
846 | 125 | for (const QuickNavigation::Landmark& landmark : landmarks) { | 154 | for (const QuickNavigation::Landmark& landmark : landmarks) { |
847 | 126 | fw.unsigned_8(landmark.set ? 1 : 0); | 155 | fw.unsigned_8(landmark.set ? 1 : 0); |
850 | 127 | fw.signed_32(landmark.point.x); | 156 | fw.float_32(landmark.view.viewpoint.x); |
851 | 128 | fw.signed_32(landmark.point.y); | 157 | fw.float_32(landmark.view.viewpoint.y); |
852 | 158 | fw.float_32(landmark.view.zoom); | ||
853 | 129 | } | 159 | } |
854 | 130 | 160 | ||
855 | 131 | fw.write(fs, "binary/interactive_player"); | 161 | fw.write(fs, "binary/interactive_player"); |
856 | 132 | 162 | ||
857 | === modified file 'src/game_io/game_preload_packet.cc' | |||
858 | --- src/game_io/game_preload_packet.cc 2016-08-05 12:32:08 +0000 | |||
859 | +++ src/game_io/game_preload_packet.cc 2016-10-24 20:07:47 +0000 | |||
860 | @@ -27,6 +27,7 @@ | |||
861 | 27 | #include "base/time_string.h" | 27 | #include "base/time_string.h" |
862 | 28 | #include "build_info.h" | 28 | #include "build_info.h" |
863 | 29 | #include "graphic/graphic.h" | 29 | #include "graphic/graphic.h" |
864 | 30 | #include "graphic/image_io.h" | ||
865 | 30 | #include "graphic/minimap_renderer.h" | 31 | #include "graphic/minimap_renderer.h" |
866 | 31 | #include "logic/game.h" | 32 | #include "logic/game.h" |
867 | 32 | #include "logic/game_data_error.h" | 33 | #include "logic/game_data_error.h" |
868 | @@ -120,13 +121,17 @@ | |||
869 | 120 | 121 | ||
870 | 121 | std::unique_ptr<::StreamWrite> sw(fs.open_stream_write(kMinimapFilename)); | 122 | std::unique_ptr<::StreamWrite> sw(fs.open_stream_write(kMinimapFilename)); |
871 | 122 | if (sw.get() != nullptr) { | 123 | if (sw.get() != nullptr) { |
873 | 123 | const MiniMapLayer flags = | 124 | const MiniMapLayer layers = |
874 | 124 | MiniMapLayer::Owner | MiniMapLayer::Building | MiniMapLayer::Terrain; | 125 | MiniMapLayer::Owner | MiniMapLayer::Building | MiniMapLayer::Terrain; |
875 | 126 | std::unique_ptr<Texture> texture; | ||
876 | 125 | if (ipl != nullptr) { // Player | 127 | if (ipl != nullptr) { // Player |
878 | 126 | write_minimap_image(game, &ipl->player(), ipl->get_viewpoint(), flags, sw.get()); | 128 | texture = draw_minimap( |
879 | 129 | game, &ipl->player(), ipl->get_view_area(), MiniMapType::kStaticViewWindow, layers); | ||
880 | 127 | } else { // Observer | 130 | } else { // Observer |
882 | 128 | write_minimap_image(game, nullptr, Point(0, 0), flags, sw.get()); | 131 | texture = draw_minimap(game, nullptr, Rectf(), MiniMapType::kStaticMap, layers); |
883 | 129 | } | 132 | } |
884 | 133 | assert(texture != nullptr); | ||
885 | 134 | save_to_png(texture.get(), sw.get(), ColorType::RGBA); | ||
886 | 130 | sw->flush(); | 135 | sw->flush(); |
887 | 131 | } | 136 | } |
888 | 132 | } | 137 | } |
889 | 133 | 138 | ||
890 | === modified file 'src/graphic/CMakeLists.txt' | |||
891 | --- src/graphic/CMakeLists.txt 2016-02-19 19:10:44 +0000 | |||
892 | +++ src/graphic/CMakeLists.txt 2016-10-24 20:07:47 +0000 | |||
893 | @@ -124,6 +124,7 @@ | |||
894 | 124 | graphic_surface | 124 | graphic_surface |
895 | 125 | io_filesystem | 125 | io_filesystem |
896 | 126 | logic | 126 | logic |
897 | 127 | logic_widelands_geometry | ||
898 | 127 | ) | 128 | ) |
899 | 128 | 129 | ||
900 | 129 | wl_library(graphic_draw_programs | 130 | wl_library(graphic_draw_programs |
901 | @@ -209,7 +210,6 @@ | |||
902 | 209 | base_macros | 210 | base_macros |
903 | 210 | economy | 211 | economy |
904 | 211 | graphic | 212 | graphic |
905 | 212 | graphic_image_io | ||
906 | 213 | graphic_surface | 213 | graphic_surface |
907 | 214 | logic | 214 | logic |
908 | 215 | wui_mapview_pixelfunctions | 215 | wui_mapview_pixelfunctions |
909 | 216 | 216 | ||
910 | === modified file 'src/graphic/align.cc' | |||
911 | --- src/graphic/align.cc 2016-08-04 15:49:05 +0000 | |||
912 | +++ src/graphic/align.cc 2016-10-24 20:07:47 +0000 | |||
913 | @@ -53,7 +53,12 @@ | |||
914 | 53 | return alignment; | 53 | return alignment; |
915 | 54 | } | 54 | } |
916 | 55 | 55 | ||
918 | 56 | void correct_for_align(Align align, uint32_t w, uint32_t h, Point* pt) { | 56 | void correct_for_align(Align align, uint32_t w, uint32_t h, Vector2f* pt) { |
919 | 57 | // When correcting for align, we never move from pixel boundaries to | ||
920 | 58 | // sub-pixels, because this might lead from pixel-perfect rendering to | ||
921 | 59 | // subsampled rendering - this can lead to blurry texts. That is why we | ||
922 | 60 | // never do float divisions in this function. | ||
923 | 61 | |||
924 | 57 | // Vertical Align | 62 | // Vertical Align |
925 | 58 | if (static_cast<int>(align & (Align::kVCenter | Align::kBottom))) { | 63 | if (static_cast<int>(align & (Align::kVCenter | Align::kBottom))) { |
926 | 59 | if (static_cast<int>(align & Align::kVCenter)) | 64 | if (static_cast<int>(align & Align::kVCenter)) |
927 | 60 | 65 | ||
928 | === modified file 'src/graphic/align.h' | |||
929 | --- src/graphic/align.h 2016-08-04 15:49:05 +0000 | |||
930 | +++ src/graphic/align.h 2016-10-24 20:07:47 +0000 | |||
931 | @@ -20,7 +20,7 @@ | |||
932 | 20 | #ifndef WL_GRAPHIC_ALIGN_H | 20 | #ifndef WL_GRAPHIC_ALIGN_H |
933 | 21 | #define WL_GRAPHIC_ALIGN_H | 21 | #define WL_GRAPHIC_ALIGN_H |
934 | 22 | 22 | ||
936 | 23 | #include "base/point.h" | 23 | #include "base/vector.h" |
937 | 24 | 24 | ||
938 | 25 | namespace UI { | 25 | namespace UI { |
939 | 26 | 26 | ||
940 | @@ -58,6 +58,6 @@ | |||
941 | 58 | } | 58 | } |
942 | 59 | 59 | ||
943 | 60 | Align mirror_alignment(Align alignment); | 60 | Align mirror_alignment(Align alignment); |
945 | 61 | void correct_for_align(Align, uint32_t w, uint32_t h, Point* pt); | 61 | void correct_for_align(Align, uint32_t w, uint32_t h, Vector2f* pt); |
946 | 62 | } | 62 | } |
947 | 63 | #endif // end of include guard: WL_GRAPHIC_ALIGN_H | 63 | #endif // end of include guard: WL_GRAPHIC_ALIGN_H |
948 | 64 | 64 | ||
949 | === modified file 'src/graphic/animation.cc' | |||
950 | --- src/graphic/animation.cc 2016-08-04 15:49:05 +0000 | |||
951 | +++ src/graphic/animation.cc 2016-10-24 20:07:47 +0000 | |||
952 | @@ -44,7 +44,7 @@ | |||
953 | 44 | 44 | ||
954 | 45 | namespace { | 45 | namespace { |
955 | 46 | // Parses an array { 12, 23 } into a point. | 46 | // Parses an array { 12, 23 } into a point. |
957 | 47 | void get_point(const LuaTable& table, Point* p) { | 47 | void get_point(const LuaTable& table, Vector2i* p) { |
958 | 48 | std::vector<int> pts = table.array_entries<int>(); | 48 | std::vector<int> pts = table.array_entries<int>(); |
959 | 49 | if (pts.size() != 2) { | 49 | if (pts.size() != 2) { |
960 | 50 | throw wexception("Expected 2 entries, but got %" PRIuS ".", pts.size()); | 50 | throw wexception("Expected 2 entries, but got %" PRIuS ".", pts.size()); |
961 | @@ -68,11 +68,14 @@ | |||
962 | 68 | uint16_t height() const override; | 68 | uint16_t height() const override; |
963 | 69 | uint16_t nr_frames() const override; | 69 | uint16_t nr_frames() const override; |
964 | 70 | uint32_t frametime() const override; | 70 | uint32_t frametime() const override; |
966 | 71 | const Point& hotspot() const override; | 71 | const Vector2i& hotspot() const override; |
967 | 72 | Image* representative_image(const RGBColor* clr) const override; | 72 | Image* representative_image(const RGBColor* clr) const override; |
968 | 73 | const std::string& representative_image_filename() const override; | 73 | const std::string& representative_image_filename() const override; |
971 | 74 | virtual void blit( | 74 | virtual void blit(uint32_t time, |
972 | 75 | uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const override; | 75 | const Rectf& dstrc, |
973 | 76 | const Rectf& srcrc, | ||
974 | 77 | const RGBColor* clr, | ||
975 | 78 | Surface*) const override; | ||
976 | 76 | void trigger_sound(uint32_t framenumber, uint32_t stereo_position) const override; | 79 | void trigger_sound(uint32_t framenumber, uint32_t stereo_position) const override; |
977 | 77 | 80 | ||
978 | 78 | private: | 81 | private: |
979 | @@ -85,7 +88,7 @@ | |||
980 | 85 | uint32_t current_frame(uint32_t time) const; | 88 | uint32_t current_frame(uint32_t time) const; |
981 | 86 | 89 | ||
982 | 87 | uint32_t frametime_; | 90 | uint32_t frametime_; |
984 | 88 | Point hotspot_; | 91 | Vector2i hotspot_; |
985 | 89 | bool hasplrclrs_; | 92 | bool hasplrclrs_; |
986 | 90 | std::vector<std::string> image_files_; | 93 | std::vector<std::string> image_files_; |
987 | 91 | std::vector<std::string> pc_mask_image_files_; | 94 | std::vector<std::string> pc_mask_image_files_; |
988 | @@ -207,7 +210,7 @@ | |||
989 | 207 | return frametime_; | 210 | return frametime_; |
990 | 208 | } | 211 | } |
991 | 209 | 212 | ||
993 | 210 | const Point& NonPackedAnimation::hotspot() const { | 213 | const Vector2i& NonPackedAnimation::hotspot() const { |
994 | 211 | return hotspot_; | 214 | return hotspot_; |
995 | 212 | } | 215 | } |
996 | 213 | 216 | ||
997 | @@ -221,11 +224,11 @@ | |||
998 | 221 | Texture* rv = new Texture(w, h); | 224 | Texture* rv = new Texture(w, h); |
999 | 222 | if (!hasplrclrs_ || clr == nullptr) { | 225 | if (!hasplrclrs_ || clr == nullptr) { |
1000 | 223 | // No player color means we simply want an exact copy of the original image. | 226 | // No player color means we simply want an exact copy of the original image. |
1002 | 224 | rv->blit(Rect(Point(0, 0), w, h), *image, Rect(Point(0, 0), w, h), 1., BlendMode::Copy); | 227 | rv->blit(Rectf(0, 0, w, h), *image, Rectf(0, 0, w, h), 1., BlendMode::Copy); |
1003 | 225 | } else { | 228 | } else { |
1007 | 226 | rv->fill_rect(Rect(Point(0, 0), w, h), RGBAColor(0, 0, 0, 0)); | 229 | rv->fill_rect(Rectf(0, 0, w, h), RGBAColor(0, 0, 0, 0)); |
1008 | 227 | rv->blit_blended(Rect(Point(0, 0), w, h), *image, | 230 | rv->blit_blended(Rectf(0, 0, w, h), *image, *g_gr->images().get(pc_mask_image_files_[0]), |
1009 | 228 | *g_gr->images().get(pc_mask_image_files_[0]), Rect(Point(0, 0), w, h), *clr); | 231 | Rectf(0, 0, w, h), *clr); |
1010 | 229 | } | 232 | } |
1011 | 230 | return rv; | 233 | return rv; |
1012 | 231 | } | 234 | } |
1013 | @@ -255,19 +258,20 @@ | |||
1014 | 255 | } | 258 | } |
1015 | 256 | } | 259 | } |
1016 | 257 | 260 | ||
1019 | 258 | void NonPackedAnimation::blit( | 261 | void NonPackedAnimation::blit(uint32_t time, |
1020 | 259 | uint32_t time, const Point& dst, const Rect& srcrc, const RGBColor* clr, Surface* target) const { | 262 | const Rectf& dstrc, |
1021 | 263 | const Rectf& srcrc, | ||
1022 | 264 | const RGBColor* clr, | ||
1023 | 265 | Surface* target) const { | ||
1024 | 260 | assert(target); | 266 | assert(target); |
1025 | 261 | 267 | ||
1026 | 262 | const uint32_t idx = current_frame(time); | 268 | const uint32_t idx = current_frame(time); |
1027 | 263 | assert(idx < nr_frames()); | 269 | assert(idx < nr_frames()); |
1028 | 264 | 270 | ||
1029 | 265 | if (!hasplrclrs_ || clr == nullptr) { | 271 | if (!hasplrclrs_ || clr == nullptr) { |
1032 | 266 | target->blit( | 272 | target->blit(dstrc, *frames_.at(idx), srcrc, 1., BlendMode::UseAlpha); |
1031 | 267 | Rect(dst.x, dst.y, srcrc.w, srcrc.h), *frames_.at(idx), srcrc, 1., BlendMode::UseAlpha); | ||
1033 | 268 | } else { | 273 | } else { |
1036 | 269 | target->blit_blended( | 274 | target->blit_blended(dstrc, *frames_.at(idx), *pcmasks_.at(idx), srcrc, *clr); |
1035 | 270 | Rect(dst.x, dst.y, srcrc.w, srcrc.h), *frames_.at(idx), *pcmasks_.at(idx), srcrc, *clr); | ||
1037 | 271 | } | 275 | } |
1038 | 272 | } | 276 | } |
1039 | 273 | 277 | ||
1040 | 274 | 278 | ||
1041 | === modified file 'src/graphic/animation.h' | |||
1042 | --- src/graphic/animation.h 2016-08-04 15:49:05 +0000 | |||
1043 | +++ src/graphic/animation.h 2016-10-24 20:07:47 +0000 | |||
1044 | @@ -29,8 +29,8 @@ | |||
1045 | 29 | #include <boost/utility.hpp> | 29 | #include <boost/utility.hpp> |
1046 | 30 | 30 | ||
1047 | 31 | #include "base/macros.h" | 31 | #include "base/macros.h" |
1048 | 32 | #include "base/point.h" | ||
1049 | 33 | #include "base/rect.h" | 32 | #include "base/rect.h" |
1050 | 33 | #include "base/vector.h" | ||
1051 | 34 | 34 | ||
1052 | 35 | class Image; | 35 | class Image; |
1053 | 36 | class LuaTable; | 36 | class LuaTable; |
1054 | @@ -68,7 +68,7 @@ | |||
1055 | 68 | 68 | ||
1056 | 69 | /// The hotspot of this animation. Note that this is ignored when blitting, | 69 | /// The hotspot of this animation. Note that this is ignored when blitting, |
1057 | 70 | /// so the caller has to adjust for the hotspot himself. | 70 | /// so the caller has to adjust for the hotspot himself. |
1059 | 71 | virtual const Point& hotspot() const = 0; | 71 | virtual const Vector2i& hotspot() const = 0; |
1060 | 72 | 72 | ||
1061 | 73 | /// An image of the first frame, blended with the given player color. | 73 | /// An image of the first frame, blended with the given player color. |
1062 | 74 | /// The 'clr' is the player color used for blending - the parameter can be | 74 | /// The 'clr' is the player color used for blending - the parameter can be |
1063 | @@ -83,8 +83,11 @@ | |||
1064 | 83 | /// color used for blitting - the parameter can be 'nullptr', in which case the | 83 | /// color used for blitting - the parameter can be 'nullptr', in which case the |
1065 | 84 | /// neutral image will be blitted. The Surface is the target for the blit | 84 | /// neutral image will be blitted. The Surface is the target for the blit |
1066 | 85 | /// operation and must be non-null. | 85 | /// operation and must be non-null. |
1069 | 86 | virtual void | 86 | virtual void blit(uint32_t time, |
1070 | 87 | blit(uint32_t time, const Point&, const Rect& srcrc, const RGBColor* clr, Surface*) const = 0; | 87 | const Rectf& dstrc, |
1071 | 88 | const Rectf& srcrc, | ||
1072 | 89 | const RGBColor* clr, | ||
1073 | 90 | Surface*) const = 0; | ||
1074 | 88 | 91 | ||
1075 | 89 | /// Play the sound effect associated with this animation at the given time. | 92 | /// Play the sound effect associated with this animation at the given time. |
1076 | 90 | virtual void trigger_sound(uint32_t time, uint32_t stereo_position) const = 0; | 93 | virtual void trigger_sound(uint32_t time, uint32_t stereo_position) const = 0; |
1077 | 91 | 94 | ||
1078 | === modified file 'src/graphic/font_handler.cc' | |||
1079 | --- src/graphic/font_handler.cc 2016-08-04 15:49:05 +0000 | |||
1080 | +++ src/graphic/font_handler.cc 2016-10-24 20:07:47 +0000 | |||
1081 | @@ -46,16 +46,15 @@ | |||
1082 | 46 | */ | 46 | */ |
1083 | 47 | void draw_caret(RenderTarget& dst, | 47 | void draw_caret(RenderTarget& dst, |
1084 | 48 | const TextStyle& style, | 48 | const TextStyle& style, |
1086 | 49 | const Point& dstpoint, | 49 | const Vector2f& dstpoint, |
1087 | 50 | const std::string& text, | 50 | const std::string& text, |
1088 | 51 | uint32_t caret_offset) { | 51 | uint32_t caret_offset) { |
1089 | 52 | int caret_x = style.calc_bare_width(text.substr(0, caret_offset)); | 52 | int caret_x = style.calc_bare_width(text.substr(0, caret_offset)); |
1090 | 53 | 53 | ||
1091 | 54 | const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png"); | 54 | const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png"); |
1093 | 55 | Point caretpt; | 55 | Vector2f caretpt; |
1094 | 56 | caretpt.x = dstpoint.x + caret_x + LINE_MARGIN - caret_image->width(); | 56 | caretpt.x = dstpoint.x + caret_x + LINE_MARGIN - caret_image->width(); |
1097 | 57 | caretpt.y = dstpoint.y + (style.font->height() - caret_image->height()) / 2; | 57 | caretpt.y = dstpoint.y + (style.font->height() - caret_image->height()) / 2.f; |
1096 | 58 | |||
1098 | 59 | dst.blit(caretpt, caret_image); | 58 | dst.blit(caretpt, caret_image); |
1099 | 60 | } | 59 | } |
1100 | 61 | 60 | ||
1101 | @@ -202,7 +201,7 @@ | |||
1102 | 202 | */ | 201 | */ |
1103 | 203 | void FontHandler::draw_text(RenderTarget& dst, | 202 | void FontHandler::draw_text(RenderTarget& dst, |
1104 | 204 | const TextStyle& style, | 203 | const TextStyle& style, |
1106 | 205 | Point dstpoint, | 204 | Vector2i dstpoint_i, |
1107 | 206 | const std::string& text, | 205 | const std::string& text, |
1108 | 207 | Align align, | 206 | Align align, |
1109 | 208 | uint32_t caret) { | 207 | uint32_t caret) { |
1110 | @@ -212,10 +211,11 @@ | |||
1111 | 212 | copytext = i18n::make_ligatures(copytext.c_str()); | 211 | copytext = i18n::make_ligatures(copytext.c_str()); |
1112 | 213 | const LineCacheEntry& lce = d->get_line(style, copytext); | 212 | const LineCacheEntry& lce = d->get_line(style, copytext); |
1113 | 214 | 213 | ||
1114 | 214 | Vector2f dstpoint = dstpoint_i.cast<float>(); | ||
1115 | 215 | UI::correct_for_align(align, lce.width + 2 * LINE_MARGIN, lce.height, &dstpoint); | 215 | UI::correct_for_align(align, lce.width + 2 * LINE_MARGIN, lce.height, &dstpoint); |
1116 | 216 | 216 | ||
1117 | 217 | if (lce.image) | 217 | if (lce.image) |
1119 | 218 | dst.blit(Point(dstpoint.x + LINE_MARGIN, dstpoint.y), lce.image.get()); | 218 | dst.blit(Vector2f(dstpoint.x + LINE_MARGIN, dstpoint.y), lce.image.get()); |
1120 | 219 | 219 | ||
1121 | 220 | if (caret <= copytext.size()) | 220 | if (caret <= copytext.size()) |
1122 | 221 | draw_caret(dst, style, dstpoint, copytext, caret); | 221 | draw_caret(dst, style, dstpoint, copytext, caret); |
1123 | @@ -226,12 +226,13 @@ | |||
1124 | 226 | */ | 226 | */ |
1125 | 227 | uint32_t FontHandler::draw_text_raw(RenderTarget& dst, | 227 | uint32_t FontHandler::draw_text_raw(RenderTarget& dst, |
1126 | 228 | const UI::TextStyle& style, | 228 | const UI::TextStyle& style, |
1128 | 229 | Point dstpoint, | 229 | Vector2i dstpoint, |
1129 | 230 | const std::string& text) { | 230 | const std::string& text) { |
1130 | 231 | const LineCacheEntry& lce = d->get_line(style, text); | 231 | const LineCacheEntry& lce = d->get_line(style, text); |
1131 | 232 | 232 | ||
1134 | 233 | if (lce.image) | 233 | if (lce.image) { |
1135 | 234 | dst.blit(dstpoint, lce.image.get()); | 234 | dst.blit(dstpoint.cast<float>(), lce.image.get()); |
1136 | 235 | } | ||
1137 | 235 | 236 | ||
1138 | 236 | return lce.width; | 237 | return lce.width; |
1139 | 237 | } | 238 | } |
1140 | 238 | 239 | ||
1141 | === modified file 'src/graphic/font_handler.h' | |||
1142 | --- src/graphic/font_handler.h 2016-08-04 15:49:05 +0000 | |||
1143 | +++ src/graphic/font_handler.h 2016-10-24 20:07:47 +0000 | |||
1144 | @@ -24,7 +24,7 @@ | |||
1145 | 24 | #include <memory> | 24 | #include <memory> |
1146 | 25 | #include <string> | 25 | #include <string> |
1147 | 26 | 26 | ||
1149 | 27 | #include "base/point.h" | 27 | #include "base/vector.h" |
1150 | 28 | #include "graphic/align.h" | 28 | #include "graphic/align.h" |
1151 | 29 | 29 | ||
1152 | 30 | class RenderTarget; | 30 | class RenderTarget; |
1153 | @@ -42,11 +42,11 @@ | |||
1154 | 42 | 42 | ||
1155 | 43 | void draw_text(RenderTarget&, | 43 | void draw_text(RenderTarget&, |
1156 | 44 | const TextStyle&, | 44 | const TextStyle&, |
1158 | 45 | Point dstpoint, | 45 | Vector2i dstpoint, |
1159 | 46 | const std::string& text, | 46 | const std::string& text, |
1160 | 47 | Align align = UI::Align::kCenterLeft, | 47 | Align align = UI::Align::kCenterLeft, |
1161 | 48 | uint32_t caret = std::numeric_limits<uint32_t>::max()); | 48 | uint32_t caret = std::numeric_limits<uint32_t>::max()); |
1163 | 49 | uint32_t draw_text_raw(RenderTarget&, const TextStyle&, Point dstpoint, const std::string& text); | 49 | uint32_t draw_text_raw(RenderTarget&, const TextStyle&, Vector2i dstpoint, const std::string& text); |
1164 | 50 | 50 | ||
1165 | 51 | void get_size(const TextStyle&, | 51 | void get_size(const TextStyle&, |
1166 | 52 | const std::string& text, | 52 | const std::string& text, |
1167 | 53 | 53 | ||
1168 | === modified file 'src/graphic/font_handler1.h' | |||
1169 | --- src/graphic/font_handler1.h 2016-08-04 15:49:05 +0000 | |||
1170 | +++ src/graphic/font_handler1.h 2016-10-24 20:07:47 +0000 | |||
1171 | @@ -25,7 +25,7 @@ | |||
1172 | 25 | #include <string> | 25 | #include <string> |
1173 | 26 | 26 | ||
1174 | 27 | #include "base/macros.h" | 27 | #include "base/macros.h" |
1176 | 28 | #include "base/point.h" | 28 | #include "base/vector.h" |
1177 | 29 | #include "graphic/align.h" | 29 | #include "graphic/align.h" |
1178 | 30 | #include "graphic/text/font_set.h" | 30 | #include "graphic/text/font_set.h" |
1179 | 31 | 31 | ||
1180 | 32 | 32 | ||
1181 | === modified file 'src/graphic/game_renderer.cc' | |||
1182 | --- src/graphic/game_renderer.cc 2016-08-04 15:49:05 +0000 | |||
1183 | +++ src/graphic/game_renderer.cc 2016-10-24 20:07:47 +0000 | |||
1184 | @@ -97,23 +97,214 @@ | |||
1185 | 97 | return brightness / 255.; | 97 | return brightness / 255.; |
1186 | 98 | } | 98 | } |
1187 | 99 | 99 | ||
1205 | 100 | // Returns the road that should be rendered here. The format is like in field, | 100 | void draw_objects_for_visible_field(const EditorGameBase& egbase, |
1206 | 101 | // but this is not the physically present road, but the one that should be | 101 | const FieldsToDraw::Field& field, |
1207 | 102 | // drawn (i.e. taking into account if there is fog of war involved or road | 102 | const float zoom, |
1208 | 103 | // building overlays enabled). | 103 | const DrawText draw_text, |
1209 | 104 | uint8_t field_roads(const FCoords& coords, | 104 | const Player* player, |
1210 | 105 | const Map& map, | 105 | RenderTarget* dst) { |
1211 | 106 | const EdgeOverlayManager& edge_overlay_manager, | 106 | BaseImmovable* const imm = field.fcoords.field->get_immovable(); |
1212 | 107 | const Player* const player) { | 107 | if (imm != nullptr && imm->get_positions(egbase).front() == field.fcoords) { |
1213 | 108 | uint8_t roads; | 108 | DrawText draw_text_for_this_immovable = draw_text; |
1214 | 109 | if (player && !player->see_all()) { | 109 | const Player* owner = imm->get_owner(); |
1215 | 110 | const Player::Field& pf = player->fields()[Map::get_index(coords, map.get_width())]; | 110 | if (player != nullptr && owner != nullptr && !player->see_all() && |
1216 | 111 | roads = pf.roads | edge_overlay_manager.get_overlay(coords); | 111 | player->is_hostile(*owner)) { |
1217 | 112 | } else { | 112 | draw_text_for_this_immovable = |
1218 | 113 | roads = coords.field->get_roads(); | 113 | static_cast<DrawText>(draw_text_for_this_immovable & ~DrawText::kStatistics); |
1219 | 114 | } | 114 | } |
1220 | 115 | roads |= edge_overlay_manager.get_overlay(coords); | 115 | |
1221 | 116 | return roads; | 116 | imm->draw( |
1222 | 117 | egbase.get_gametime(), draw_text_for_this_immovable, field.rendertarget_pixel, zoom, dst); | ||
1223 | 118 | } | ||
1224 | 119 | for (Bob* bob = field.fcoords.field->get_first_bob(); bob; bob = bob->get_next_bob()) { | ||
1225 | 120 | DrawText draw_text_for_this_bob = draw_text; | ||
1226 | 121 | const Player* owner = bob->get_owner(); | ||
1227 | 122 | if (player != nullptr && owner != nullptr && !player->see_all() && | ||
1228 | 123 | player->is_hostile(*owner)) { | ||
1229 | 124 | draw_text_for_this_bob = | ||
1230 | 125 | static_cast<DrawText>(draw_text_for_this_bob & ~DrawText::kStatistics); | ||
1231 | 126 | } | ||
1232 | 127 | bob->draw(egbase, draw_text_for_this_bob, field.rendertarget_pixel, zoom, dst); | ||
1233 | 128 | } | ||
1234 | 129 | } | ||
1235 | 130 | |||
1236 | 131 | void draw_objets_for_formerly_visible_field(const FieldsToDraw::Field& field, | ||
1237 | 132 | const Player::Field& player_field, | ||
1238 | 133 | const float zoom, | ||
1239 | 134 | RenderTarget* dst) { | ||
1240 | 135 | if (const MapObjectDescr* const map_object_descr = | ||
1241 | 136 | player_field.map_object_descr[TCoords<>::None]) { | ||
1242 | 137 | if (player_field.constructionsite.becomes) { | ||
1243 | 138 | assert(field.owner != nullptr); | ||
1244 | 139 | const ConstructionsiteInformation& csinf = player_field.constructionsite; | ||
1245 | 140 | // draw the partly finished constructionsite | ||
1246 | 141 | uint32_t anim_idx; | ||
1247 | 142 | try { | ||
1248 | 143 | anim_idx = csinf.becomes->get_animation("build"); | ||
1249 | 144 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1250 | 145 | try { | ||
1251 | 146 | anim_idx = csinf.becomes->get_animation("unoccupied"); | ||
1252 | 147 | } catch (MapObjectDescr::AnimationNonexistent) { | ||
1253 | 148 | anim_idx = csinf.becomes->get_animation("idle"); | ||
1254 | 149 | } | ||
1255 | 150 | } | ||
1256 | 151 | const Animation& anim = g_gr->animations().get_animation(anim_idx); | ||
1257 | 152 | const size_t nr_frames = anim.nr_frames(); | ||
1258 | 153 | uint32_t cur_frame = | ||
1259 | 154 | csinf.totaltime ? csinf.completedtime * nr_frames / csinf.totaltime : 0; | ||
1260 | 155 | uint32_t tanim = cur_frame * FRAME_LENGTH; | ||
1261 | 156 | |||
1262 | 157 | const uint16_t w = anim.width(); | ||
1263 | 158 | const uint16_t h = anim.height(); | ||
1264 | 159 | uint32_t lines = h * csinf.completedtime * nr_frames; | ||
1265 | 160 | if (csinf.totaltime) | ||
1266 | 161 | lines /= csinf.totaltime; | ||
1267 | 162 | assert(h * cur_frame <= lines); | ||
1268 | 163 | lines -= h * cur_frame; | ||
1269 | 164 | |||
1270 | 165 | if (cur_frame) { // not the first frame | ||
1271 | 166 | // draw the prev frame from top to where next image will be drawing | ||
1272 | 167 | dst->blit_animation(field.rendertarget_pixel, zoom, anim_idx, tanim - FRAME_LENGTH, | ||
1273 | 168 | field.owner->get_playercolor(), | ||
1274 | 169 | Recti(Vector2i(0, 0), w, h - lines)); | ||
1275 | 170 | } else if (csinf.was) { | ||
1276 | 171 | // Is the first frame, but there was another building here before, | ||
1277 | 172 | // get its last build picture and draw it instead. | ||
1278 | 173 | uint32_t a; | ||
1279 | 174 | try { | ||
1280 | 175 | a = csinf.was->get_animation("unoccupied"); | ||
1281 | 176 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1282 | 177 | a = csinf.was->get_animation("idle"); | ||
1283 | 178 | } | ||
1284 | 179 | dst->blit_animation(field.rendertarget_pixel, zoom, a, tanim - FRAME_LENGTH, | ||
1285 | 180 | field.owner->get_playercolor(), | ||
1286 | 181 | Recti(Vector2i(0, 0), w, h - lines)); | ||
1287 | 182 | } | ||
1288 | 183 | assert(lines <= h); | ||
1289 | 184 | dst->blit_animation(field.rendertarget_pixel, zoom, anim_idx, tanim, | ||
1290 | 185 | field.owner->get_playercolor(), | ||
1291 | 186 | Recti(Vector2i(0, h - lines), w, lines)); | ||
1292 | 187 | } else if (upcast(const BuildingDescr, building, map_object_descr)) { | ||
1293 | 188 | assert(field.owner != nullptr); | ||
1294 | 189 | // this is a building therefore we either draw unoccupied or idle animation | ||
1295 | 190 | uint32_t pic; | ||
1296 | 191 | try { | ||
1297 | 192 | pic = building->get_animation("unoccupied"); | ||
1298 | 193 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1299 | 194 | pic = building->get_animation("idle"); | ||
1300 | 195 | } | ||
1301 | 196 | dst->blit_animation( | ||
1302 | 197 | field.rendertarget_pixel, zoom, pic, 0, field.owner->get_playercolor()); | ||
1303 | 198 | } else if (map_object_descr->type() == MapObjectType::FLAG) { | ||
1304 | 199 | assert(field.owner != nullptr); | ||
1305 | 200 | dst->blit_animation(field.rendertarget_pixel, zoom, field.owner->tribe().flag_animation(), | ||
1306 | 201 | 0, field.owner->get_playercolor()); | ||
1307 | 202 | } else if (const uint32_t pic = map_object_descr->main_animation()) { | ||
1308 | 203 | if (field.owner != nullptr) { | ||
1309 | 204 | dst->blit_animation( | ||
1310 | 205 | field.rendertarget_pixel, zoom, pic, 0, field.owner->get_playercolor()); | ||
1311 | 206 | } else { | ||
1312 | 207 | dst->blit_animation(field.rendertarget_pixel, zoom, pic, 0); | ||
1313 | 208 | } | ||
1314 | 209 | } | ||
1315 | 210 | } | ||
1316 | 211 | } | ||
1317 | 212 | |||
1318 | 213 | // Draws the objects (animations & overlays). | ||
1319 | 214 | void draw_objects(const EditorGameBase& egbase, | ||
1320 | 215 | const float zoom, | ||
1321 | 216 | const FieldsToDraw& fields_to_draw, | ||
1322 | 217 | const Player* player, | ||
1323 | 218 | const DrawText draw_text, | ||
1324 | 219 | RenderTarget* dst) { | ||
1325 | 220 | std::vector<FieldOverlayManager::OverlayInfo> overlay_info; | ||
1326 | 221 | for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) { | ||
1327 | 222 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); | ||
1328 | 223 | if (!field.all_neighbors_valid()) { | ||
1329 | 224 | continue; | ||
1330 | 225 | } | ||
1331 | 226 | |||
1332 | 227 | const FieldsToDraw::Field& rn = fields_to_draw.at(field.rn_index); | ||
1333 | 228 | const FieldsToDraw::Field& bln = fields_to_draw.at(field.bln_index); | ||
1334 | 229 | const FieldsToDraw::Field& brn = fields_to_draw.at(field.brn_index); | ||
1335 | 230 | |||
1336 | 231 | if (field.is_border) { | ||
1337 | 232 | assert(field.owner != nullptr); | ||
1338 | 233 | uint32_t const anim_idx = field.owner->tribe().frontier_animation(); | ||
1339 | 234 | if (field.vision) { | ||
1340 | 235 | dst->blit_animation( | ||
1341 | 236 | field.rendertarget_pixel, zoom, anim_idx, 0, field.owner->get_playercolor()); | ||
1342 | 237 | } | ||
1343 | 238 | for (const auto& nf : {rn, bln, brn}) { | ||
1344 | 239 | if ((field.vision || nf.vision) && nf.is_border && | ||
1345 | 240 | (field.owner == nf.owner || nf.owner == nullptr)) { | ||
1346 | 241 | dst->blit_animation(middle(field.rendertarget_pixel, nf.rendertarget_pixel), zoom, | ||
1347 | 242 | anim_idx, 0, field.owner->get_playercolor()); | ||
1348 | 243 | } | ||
1349 | 244 | } | ||
1350 | 245 | } | ||
1351 | 246 | |||
1352 | 247 | if (1 < field.vision) { // Render stuff that belongs to the node. | ||
1353 | 248 | draw_objects_for_visible_field(egbase, field, zoom, draw_text, player, dst); | ||
1354 | 249 | } else if (field.vision == 1) { | ||
1355 | 250 | // We never show census or statistics for objects in the fog. | ||
1356 | 251 | assert(player != nullptr); | ||
1357 | 252 | const Map& map = egbase.map(); | ||
1358 | 253 | const Player::Field& player_field = | ||
1359 | 254 | player->fields()[map.get_index(field.fcoords, map.get_width())]; | ||
1360 | 255 | draw_objets_for_formerly_visible_field(field, player_field, zoom, dst); | ||
1361 | 256 | } | ||
1362 | 257 | |||
1363 | 258 | const FieldOverlayManager& overlay_manager = egbase.get_ibase()->field_overlay_manager(); | ||
1364 | 259 | { | ||
1365 | 260 | overlay_info.clear(); | ||
1366 | 261 | overlay_manager.get_overlays(field.fcoords, &overlay_info); | ||
1367 | 262 | for (const auto& overlay : overlay_info) { | ||
1368 | 263 | dst->blitrect_scale( | ||
1369 | 264 | Rectf(field.rendertarget_pixel - overlay.hotspot.cast<float>() * zoom, | ||
1370 | 265 | overlay.pic->width() * zoom, overlay.pic->height() * zoom), | ||
1371 | 266 | overlay.pic, Recti(0, 0, overlay.pic->width(), overlay.pic->height()), 1.f, | ||
1372 | 267 | BlendMode::UseAlpha); | ||
1373 | 268 | } | ||
1374 | 269 | } | ||
1375 | 270 | |||
1376 | 271 | { | ||
1377 | 272 | // Render overlays on the right triangle | ||
1378 | 273 | overlay_info.clear(); | ||
1379 | 274 | overlay_manager.get_overlays(TCoords<>(field.fcoords, TCoords<>::R), &overlay_info); | ||
1380 | 275 | |||
1381 | 276 | Vector2f tripos( | ||
1382 | 277 | (field.rendertarget_pixel.x + rn.rendertarget_pixel.x + brn.rendertarget_pixel.x) / 3.f, | ||
1383 | 278 | (field.rendertarget_pixel.y + rn.rendertarget_pixel.y + brn.rendertarget_pixel.y) / | ||
1384 | 279 | 3.f); | ||
1385 | 280 | for (const auto& overlay : overlay_info) { | ||
1386 | 281 | dst->blitrect_scale(Rectf(tripos - overlay.hotspot.cast<float>() * zoom, | ||
1387 | 282 | overlay.pic->width() * zoom, overlay.pic->height() * zoom), | ||
1388 | 283 | overlay.pic, | ||
1389 | 284 | Recti(0, 0, overlay.pic->width(), overlay.pic->height()), 1.f, | ||
1390 | 285 | BlendMode::UseAlpha); | ||
1391 | 286 | } | ||
1392 | 287 | } | ||
1393 | 288 | |||
1394 | 289 | { | ||
1395 | 290 | // Render overlays on the D triangle | ||
1396 | 291 | overlay_info.clear(); | ||
1397 | 292 | overlay_manager.get_overlays(TCoords<>(field.fcoords, TCoords<>::D), &overlay_info); | ||
1398 | 293 | |||
1399 | 294 | Vector2f tripos( | ||
1400 | 295 | (field.rendertarget_pixel.x + bln.rendertarget_pixel.x + brn.rendertarget_pixel.x) / | ||
1401 | 296 | 3.f, | ||
1402 | 297 | (field.rendertarget_pixel.y + bln.rendertarget_pixel.y + brn.rendertarget_pixel.y) / | ||
1403 | 298 | 3.f); | ||
1404 | 299 | for (const auto& overlay : overlay_info) { | ||
1405 | 300 | dst->blitrect_scale(Rectf(tripos - overlay.hotspot.cast<float>() * zoom, | ||
1406 | 301 | overlay.pic->width() * zoom, overlay.pic->height() * zoom), | ||
1407 | 302 | overlay.pic, | ||
1408 | 303 | Recti(0, 0, overlay.pic->width(), overlay.pic->height()), 1.f, | ||
1409 | 304 | BlendMode::UseAlpha); | ||
1410 | 305 | } | ||
1411 | 306 | } | ||
1412 | 307 | } | ||
1413 | 117 | } | 308 | } |
1414 | 118 | 309 | ||
1415 | 119 | } // namespace | 310 | } // namespace |
1416 | @@ -124,46 +315,60 @@ | |||
1417 | 124 | GameRenderer::~GameRenderer() { | 315 | GameRenderer::~GameRenderer() { |
1418 | 125 | } | 316 | } |
1419 | 126 | 317 | ||
1452 | 127 | void GameRenderer::rendermap(RenderTarget& dst, | 318 | void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase, |
1453 | 128 | const Widelands::EditorGameBase& egbase, | 319 | const Vector2f& viewpoint, |
1454 | 129 | const Point& view_offset, | 320 | const float zoom, |
1455 | 130 | 321 | const Widelands::Player& player, | |
1456 | 131 | const Widelands::Player& player) { | 322 | const DrawText draw_text, |
1457 | 132 | draw(dst, egbase, view_offset, &player); | 323 | RenderTarget* dst) { |
1458 | 133 | } | 324 | draw(egbase, viewpoint, zoom, draw_text, &player, dst); |
1459 | 134 | 325 | } | |
1460 | 135 | void GameRenderer::rendermap(RenderTarget& dst, | 326 | |
1461 | 136 | const Widelands::EditorGameBase& egbase, | 327 | void GameRenderer::rendermap(const Widelands::EditorGameBase& egbase, |
1462 | 137 | const Point& view_offset) { | 328 | const Vector2f& viewpoint, |
1463 | 138 | draw(dst, egbase, view_offset, nullptr); | 329 | const float zoom, |
1464 | 139 | } | 330 | const DrawText draw_text, |
1465 | 140 | 331 | RenderTarget* dst) { | |
1466 | 141 | void GameRenderer::draw(RenderTarget& dst, | 332 | draw(egbase, viewpoint, zoom, draw_text, nullptr, dst); |
1467 | 142 | const EditorGameBase& egbase, | 333 | } |
1468 | 143 | const Point& view_offset, | 334 | |
1469 | 144 | const Player* player) { | 335 | void GameRenderer::draw(const EditorGameBase& egbase, |
1470 | 145 | Point tl_map = dst.get_offset() + view_offset; | 336 | const Vector2f& viewpoint, |
1471 | 146 | 337 | const float zoom, | |
1472 | 147 | assert(tl_map.x >= 0); // divisions involving negative numbers are bad | 338 | const DrawText draw_text, |
1473 | 148 | assert(tl_map.y >= 0); | 339 | const Player* player, |
1474 | 149 | 340 | RenderTarget* dst) { | |
1475 | 150 | int minfx = tl_map.x / kTriangleWidth - 1; | 341 | assert(viewpoint.x >= 0); // divisions involving negative numbers are bad |
1476 | 151 | int minfy = tl_map.y / kTriangleHeight - 1; | 342 | assert(viewpoint.y >= 0); |
1477 | 152 | int maxfx = (tl_map.x + dst.get_rect().w + (kTriangleWidth / 2)) / kTriangleWidth; | 343 | assert(dst->get_offset().x <= 0); |
1478 | 153 | int maxfy = (tl_map.y + dst.get_rect().h) / kTriangleHeight; | 344 | assert(dst->get_offset().y <= 0); |
1479 | 154 | 345 | ||
1480 | 155 | // fudge for triangle boundary effects and for height differences | 346 | int minfx = std::floor(viewpoint.x / kTriangleWidth); |
1481 | 156 | minfx -= 1; | 347 | int minfy = std::floor(viewpoint.y / kTriangleHeight); |
1482 | 157 | minfy -= 1; | 348 | |
1483 | 158 | maxfx += 1; | 349 | // If a view window is partially moved outside of the display, its 'rect' is |
1484 | 350 | // adjusted to be fully contained on the screen - i.e. x = 0 and width is | ||
1485 | 351 | // made smaller. Its offset is made negative to account for this change. | ||
1486 | 352 | // To figure out which fields we need to draw, we have to add the absolute | ||
1487 | 353 | // value of 'offset' to the actual dimension of the 'rect' to get to desired | ||
1488 | 354 | // dimension of the 'rect' | ||
1489 | 355 | const Vector2f br_map = MapviewPixelFunctions::panel_to_map( | ||
1490 | 356 | viewpoint, zoom, Vector2f(dst->get_rect().w + std::abs(dst->get_offset().x), | ||
1491 | 357 | dst->get_rect().h + std::abs(dst->get_offset().y))); | ||
1492 | 358 | int maxfx = std::ceil(br_map.x / kTriangleWidth); | ||
1493 | 359 | int maxfy = std::ceil(br_map.y / kTriangleHeight); | ||
1494 | 360 | |||
1495 | 361 | // Adjust for triangle boundary effects and for height differences. | ||
1496 | 362 | minfx -= 2; | ||
1497 | 363 | maxfx += 2; | ||
1498 | 364 | minfy -= 2; | ||
1499 | 159 | maxfy += 10; | 365 | maxfy += 10; |
1500 | 160 | 366 | ||
1502 | 161 | Surface* surface = dst.get_surface(); | 367 | Surface* surface = dst->get_surface(); |
1503 | 162 | if (!surface) | 368 | if (!surface) |
1504 | 163 | return; | 369 | return; |
1505 | 164 | 370 | ||
1508 | 165 | const Rect& bounding_rect = dst.get_rect(); | 371 | const Recti& bounding_rect = dst->get_rect(); |
1507 | 166 | const Point surface_offset = bounding_rect.origin() + dst.get_offset() - view_offset; | ||
1509 | 167 | const int surface_width = surface->width(); | 372 | const int surface_width = surface->width(); |
1510 | 168 | const int surface_height = surface->height(); | 373 | const int surface_height = surface->height(); |
1511 | 169 | 374 | ||
1512 | @@ -171,46 +376,60 @@ | |||
1513 | 171 | const EdgeOverlayManager& edge_overlay_manager = egbase.get_ibase()->edge_overlay_manager(); | 376 | const EdgeOverlayManager& edge_overlay_manager = egbase.get_ibase()->edge_overlay_manager(); |
1514 | 172 | const uint32_t gametime = egbase.get_gametime(); | 377 | const uint32_t gametime = egbase.get_gametime(); |
1515 | 173 | 378 | ||
1516 | 379 | const float scale = 1.f / zoom; | ||
1517 | 174 | fields_to_draw_.reset(minfx, maxfx, minfy, maxfy); | 380 | fields_to_draw_.reset(minfx, maxfx, minfy, maxfy); |
1518 | 175 | for (int32_t fy = minfy; fy <= maxfy; ++fy) { | 381 | for (int32_t fy = minfy; fy <= maxfy; ++fy) { |
1519 | 176 | for (int32_t fx = minfx; fx <= maxfx; ++fx) { | 382 | for (int32_t fx = minfx; fx <= maxfx; ++fx) { |
1520 | 177 | FieldsToDraw::Field& f = | 383 | FieldsToDraw::Field& f = |
1521 | 178 | *fields_to_draw_.mutable_field(fields_to_draw_.calculate_index(fx, fy)); | 384 | *fields_to_draw_.mutable_field(fields_to_draw_.calculate_index(fx, fy)); |
1522 | 179 | 385 | ||
1532 | 180 | f.fx = fx; | 386 | f.geometric_coords = Coords(fx, fy); |
1533 | 181 | f.fy = fy; | 387 | |
1534 | 182 | 388 | f.ln_index = fields_to_draw_.calculate_index(fx - 1, fy); | |
1535 | 183 | Coords coords(fx, fy); | 389 | f.rn_index = fields_to_draw_.calculate_index(fx + 1, fy); |
1536 | 184 | int x, y; | 390 | f.trn_index = fields_to_draw_.calculate_index(fx + (fy & 1), fy - 1); |
1537 | 185 | MapviewPixelFunctions::get_basepix(coords, x, y); | 391 | f.bln_index = fields_to_draw_.calculate_index(fx + (fy & 1) - 1, fy + 1); |
1538 | 186 | 392 | f.brn_index = fields_to_draw_.calculate_index(fx + (fy & 1), fy + 1); | |
1530 | 187 | map.normalize_coords(coords); | ||
1531 | 188 | const FCoords& fcoords = map.get_fcoords(coords); | ||
1539 | 189 | 393 | ||
1540 | 190 | // Texture coordinates for pseudo random tiling of terrain and road | 394 | // Texture coordinates for pseudo random tiling of terrain and road |
1541 | 191 | // graphics. Since screen space X increases top-to-bottom and OpenGL | 395 | // graphics. Since screen space X increases top-to-bottom and OpenGL |
1542 | 192 | // increases bottom-to-top we flip the y coordinate to not have | 396 | // increases bottom-to-top we flip the y coordinate to not have |
1543 | 193 | // terrains and road graphics vertically mirrorerd. | 397 | // terrains and road graphics vertically mirrorerd. |
1561 | 194 | f.texture_x = float(x) / kTextureSideLength; | 398 | Vector2f map_pixel = |
1562 | 195 | f.texture_y = -float(y) / kTextureSideLength; | 399 | MapviewPixelFunctions::to_map_pixel_ignoring_height(f.geometric_coords); |
1563 | 196 | 400 | f.texture_coords.x = map_pixel.x / kTextureSideLength; | |
1564 | 197 | f.gl_x = f.pixel_x = x + surface_offset.x; | 401 | f.texture_coords.y = -map_pixel.y / kTextureSideLength; |
1565 | 198 | f.gl_y = f.pixel_y = y + surface_offset.y - fcoords.field->get_height() * kHeightFactor; | 402 | |
1566 | 199 | pixel_to_gl_renderbuffer(surface_width, surface_height, &f.gl_x, &f.gl_y); | 403 | Coords normalized = f.geometric_coords; |
1567 | 200 | 404 | map.normalize_coords(normalized); | |
1568 | 201 | f.ter_d = fcoords.field->terrain_d(); | 405 | f.fcoords = map.get_fcoords(normalized); |
1569 | 202 | f.ter_r = fcoords.field->terrain_r(); | 406 | |
1570 | 203 | 407 | map_pixel.y -= f.fcoords.field->get_height() * kHeightFactor; | |
1571 | 204 | f.brightness = field_brightness(fcoords, gametime, map, player); | 408 | |
1572 | 205 | 409 | f.rendertarget_pixel = MapviewPixelFunctions::map_to_panel(viewpoint, zoom, map_pixel); | |
1573 | 206 | PlayerNumber owner_number = fcoords.field->get_owned_by(); | 410 | f.gl_position = f.surface_pixel = f.rendertarget_pixel + |
1574 | 207 | if (owner_number > 0) { | 411 | dst->get_rect().origin().cast<float>() + |
1575 | 208 | f.road_textures = &egbase.player(owner_number).tribe().road_textures(); | 412 | dst->get_offset().cast<float>(); |
1576 | 209 | } else { | 413 | pixel_to_gl_renderbuffer( |
1577 | 210 | f.road_textures = nullptr; | 414 | surface_width, surface_height, &f.gl_position.x, &f.gl_position.y); |
1578 | 415 | |||
1579 | 416 | f.brightness = field_brightness(f.fcoords, gametime, map, player); | ||
1580 | 417 | |||
1581 | 418 | PlayerNumber owned_by = f.fcoords.field->get_owned_by(); | ||
1582 | 419 | f.owner = owned_by != 0 ? &egbase.player(owned_by) : nullptr; | ||
1583 | 420 | f.is_border = f.fcoords.field->is_border(); | ||
1584 | 421 | f.vision = 2; | ||
1585 | 422 | f.roads = f.fcoords.field->get_roads(); | ||
1586 | 423 | if (player && !player->see_all()) { | ||
1587 | 424 | const Player::Field& pf = player->fields()[map.get_index(f.fcoords, map.get_width())]; | ||
1588 | 425 | f.roads = pf.roads; | ||
1589 | 426 | f.vision = pf.vision; | ||
1590 | 427 | if (pf.vision == 1) { | ||
1591 | 428 | f.owner = pf.owner != 0 ? &egbase.player(owned_by) : nullptr; | ||
1592 | 429 | f.is_border = pf.border; | ||
1593 | 430 | } | ||
1594 | 211 | } | 431 | } |
1597 | 212 | 432 | f.roads |= edge_overlay_manager.get_overlay(f.fcoords); | |
1596 | 213 | f.roads = field_roads(fcoords, map, edge_overlay_manager, player); | ||
1598 | 214 | } | 433 | } |
1599 | 215 | } | 434 | } |
1600 | 216 | 435 | ||
1601 | @@ -219,13 +438,14 @@ | |||
1602 | 219 | i.program_id = RenderQueue::Program::kTerrainBase; | 438 | i.program_id = RenderQueue::Program::kTerrainBase; |
1603 | 220 | i.blend_mode = BlendMode::Copy; | 439 | i.blend_mode = BlendMode::Copy; |
1604 | 221 | i.terrain_arguments.destination_rect = | 440 | i.terrain_arguments.destination_rect = |
1607 | 222 | FloatRect(bounding_rect.x, surface_height - bounding_rect.y - bounding_rect.h, | 441 | Rectf(bounding_rect.x, surface_height - bounding_rect.y - bounding_rect.h, bounding_rect.w, |
1608 | 223 | bounding_rect.w, bounding_rect.h); | 442 | bounding_rect.h); |
1609 | 224 | i.terrain_arguments.gametime = gametime; | 443 | i.terrain_arguments.gametime = gametime; |
1610 | 225 | i.terrain_arguments.renderbuffer_width = surface_width; | 444 | i.terrain_arguments.renderbuffer_width = surface_width; |
1611 | 226 | i.terrain_arguments.renderbuffer_height = surface_height; | 445 | i.terrain_arguments.renderbuffer_height = surface_height; |
1612 | 227 | i.terrain_arguments.terrains = &egbase.world().terrains(); | 446 | i.terrain_arguments.terrains = &egbase.world().terrains(); |
1613 | 228 | i.terrain_arguments.fields_to_draw = &fields_to_draw_; | 447 | i.terrain_arguments.fields_to_draw = &fields_to_draw_; |
1614 | 448 | i.terrain_arguments.scale = scale; | ||
1615 | 229 | RenderQueue::instance().enqueue(i); | 449 | RenderQueue::instance().enqueue(i); |
1616 | 230 | 450 | ||
1617 | 231 | // Enqueue the drawing of the dither layer. | 451 | // Enqueue the drawing of the dither layer. |
1618 | @@ -237,191 +457,5 @@ | |||
1619 | 237 | i.program_id = RenderQueue::Program::kTerrainRoad; | 457 | i.program_id = RenderQueue::Program::kTerrainRoad; |
1620 | 238 | RenderQueue::instance().enqueue(i); | 458 | RenderQueue::instance().enqueue(i); |
1621 | 239 | 459 | ||
1809 | 240 | draw_objects(dst, egbase, view_offset, player, minfx, maxfx, minfy, maxfy); | 460 | draw_objects(egbase, scale, fields_to_draw_, player, draw_text, dst); |
1623 | 241 | } | ||
1624 | 242 | |||
1625 | 243 | void GameRenderer::draw_objects(RenderTarget& dst, | ||
1626 | 244 | const EditorGameBase& egbase, | ||
1627 | 245 | const Point& view_offset, | ||
1628 | 246 | const Player* player, | ||
1629 | 247 | int minfx, | ||
1630 | 248 | int maxfx, | ||
1631 | 249 | int minfy, | ||
1632 | 250 | int maxfy) { | ||
1633 | 251 | // TODO(sirver): this should use FieldsToDraw. Would simplify this function a lot. | ||
1634 | 252 | static const uint32_t F = 0; | ||
1635 | 253 | static const uint32_t R = 1; | ||
1636 | 254 | static const uint32_t BL = 2; | ||
1637 | 255 | static const uint32_t BR = 3; | ||
1638 | 256 | const Map& map = egbase.map(); | ||
1639 | 257 | |||
1640 | 258 | std::vector<FieldOverlayManager::OverlayInfo> overlay_info; | ||
1641 | 259 | for (int32_t fy = minfy; fy <= maxfy; ++fy) { | ||
1642 | 260 | for (int32_t fx = minfx; fx <= maxfx; ++fx) { | ||
1643 | 261 | Coords ncoords(fx, fy); | ||
1644 | 262 | map.normalize_coords(ncoords); | ||
1645 | 263 | FCoords coords[4]; | ||
1646 | 264 | coords[F] = map.get_fcoords(ncoords); | ||
1647 | 265 | coords[R] = map.r_n(coords[F]); | ||
1648 | 266 | coords[BL] = map.bl_n(coords[F]); | ||
1649 | 267 | coords[BR] = map.br_n(coords[F]); | ||
1650 | 268 | Point pos[4]; | ||
1651 | 269 | MapviewPixelFunctions::get_basepix(Coords(fx, fy), pos[F].x, pos[F].y); | ||
1652 | 270 | MapviewPixelFunctions::get_basepix(Coords(fx + 1, fy), pos[R].x, pos[R].y); | ||
1653 | 271 | MapviewPixelFunctions::get_basepix( | ||
1654 | 272 | Coords(fx + (fy & 1) - 1, fy + 1), pos[BL].x, pos[BL].y); | ||
1655 | 273 | MapviewPixelFunctions::get_basepix(Coords(fx + (fy & 1), fy + 1), pos[BR].x, pos[BR].y); | ||
1656 | 274 | for (uint32_t d = 0; d < 4; ++d) { | ||
1657 | 275 | pos[d].y -= coords[d].field->get_height() * kHeightFactor; | ||
1658 | 276 | pos[d] -= view_offset; | ||
1659 | 277 | } | ||
1660 | 278 | |||
1661 | 279 | PlayerNumber owner_number[4]; | ||
1662 | 280 | bool isborder[4]; | ||
1663 | 281 | Vision vision[4] = {2, 2, 2, 2}; | ||
1664 | 282 | for (uint32_t d = 0; d < 4; ++d) | ||
1665 | 283 | owner_number[d] = coords[d].field->get_owned_by(); | ||
1666 | 284 | for (uint32_t d = 0; d < 4; ++d) | ||
1667 | 285 | isborder[d] = coords[d].field->is_border(); | ||
1668 | 286 | |||
1669 | 287 | if (player && !player->see_all()) { | ||
1670 | 288 | for (uint32_t d = 0; d < 4; ++d) { | ||
1671 | 289 | const Player::Field& pf = | ||
1672 | 290 | player->fields()[map.get_index(coords[d], map.get_width())]; | ||
1673 | 291 | vision[d] = pf.vision; | ||
1674 | 292 | if (pf.vision == 1) { | ||
1675 | 293 | owner_number[d] = pf.owner; | ||
1676 | 294 | isborder[d] = pf.border; | ||
1677 | 295 | } | ||
1678 | 296 | } | ||
1679 | 297 | } | ||
1680 | 298 | |||
1681 | 299 | if (isborder[F]) { | ||
1682 | 300 | const Player& owner = egbase.player(owner_number[F]); | ||
1683 | 301 | uint32_t const anim_idx = owner.tribe().frontier_animation(); | ||
1684 | 302 | if (vision[F]) | ||
1685 | 303 | dst.blit_animation(pos[F], anim_idx, 0, owner.get_playercolor()); | ||
1686 | 304 | for (uint32_t d = 1; d < 4; ++d) { | ||
1687 | 305 | if ((vision[F] || vision[d]) && isborder[d] && | ||
1688 | 306 | (owner_number[d] == owner_number[F] || !owner_number[d])) { | ||
1689 | 307 | dst.blit_animation(middle(pos[F], pos[d]), anim_idx, 0, owner.get_playercolor()); | ||
1690 | 308 | } | ||
1691 | 309 | } | ||
1692 | 310 | } | ||
1693 | 311 | |||
1694 | 312 | if (1 < vision[F]) { // Render stuff that belongs to the node. | ||
1695 | 313 | if (BaseImmovable* const imm = coords[F].field->get_immovable()) | ||
1696 | 314 | imm->draw(egbase, dst, coords[F], pos[F]); | ||
1697 | 315 | for (Bob* bob = coords[F].field->get_first_bob(); bob; bob = bob->get_next_bob()) | ||
1698 | 316 | bob->draw(egbase, dst, pos[F]); | ||
1699 | 317 | } else if (vision[F] == 1) { | ||
1700 | 318 | const Player::Field& f_pl = player->fields()[map.get_index(coords[F], map.get_width())]; | ||
1701 | 319 | const Player* owner = owner_number[F] ? egbase.get_player(owner_number[F]) : nullptr; | ||
1702 | 320 | if (const MapObjectDescr* const map_object_descr = | ||
1703 | 321 | f_pl.map_object_descr[TCoords<>::None]) { | ||
1704 | 322 | if (f_pl.constructionsite.becomes) { | ||
1705 | 323 | assert(owner != nullptr); | ||
1706 | 324 | const ConstructionsiteInformation& csinf = f_pl.constructionsite; | ||
1707 | 325 | // draw the partly finished constructionsite | ||
1708 | 326 | uint32_t anim_idx; | ||
1709 | 327 | try { | ||
1710 | 328 | anim_idx = csinf.becomes->get_animation("build"); | ||
1711 | 329 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1712 | 330 | try { | ||
1713 | 331 | anim_idx = csinf.becomes->get_animation("unoccupied"); | ||
1714 | 332 | } catch (MapObjectDescr::AnimationNonexistent) { | ||
1715 | 333 | anim_idx = csinf.becomes->get_animation("idle"); | ||
1716 | 334 | } | ||
1717 | 335 | } | ||
1718 | 336 | const Animation& anim = g_gr->animations().get_animation(anim_idx); | ||
1719 | 337 | const size_t nr_frames = anim.nr_frames(); | ||
1720 | 338 | uint32_t cur_frame = | ||
1721 | 339 | csinf.totaltime ? csinf.completedtime * nr_frames / csinf.totaltime : 0; | ||
1722 | 340 | uint32_t tanim = cur_frame * FRAME_LENGTH; | ||
1723 | 341 | |||
1724 | 342 | const uint16_t w = anim.width(); | ||
1725 | 343 | const uint16_t h = anim.height(); | ||
1726 | 344 | uint32_t lines = h * csinf.completedtime * nr_frames; | ||
1727 | 345 | if (csinf.totaltime) | ||
1728 | 346 | lines /= csinf.totaltime; | ||
1729 | 347 | assert(h * cur_frame <= lines); | ||
1730 | 348 | lines -= h * cur_frame; | ||
1731 | 349 | |||
1732 | 350 | if (cur_frame) { // not the first frame | ||
1733 | 351 | // draw the prev frame from top to where next image will be drawing | ||
1734 | 352 | dst.blit_animation(pos[F], anim_idx, tanim - FRAME_LENGTH, | ||
1735 | 353 | owner->get_playercolor(), Rect(Point(0, 0), w, h - lines)); | ||
1736 | 354 | } else if (csinf.was) { | ||
1737 | 355 | // Is the first frame, but there was another building here before, | ||
1738 | 356 | // get its last build picture and draw it instead. | ||
1739 | 357 | uint32_t a; | ||
1740 | 358 | try { | ||
1741 | 359 | a = csinf.was->get_animation("unoccupied"); | ||
1742 | 360 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1743 | 361 | a = csinf.was->get_animation("idle"); | ||
1744 | 362 | } | ||
1745 | 363 | dst.blit_animation(pos[F], a, tanim - FRAME_LENGTH, owner->get_playercolor(), | ||
1746 | 364 | Rect(Point(0, 0), w, h - lines)); | ||
1747 | 365 | } | ||
1748 | 366 | assert(lines <= h); | ||
1749 | 367 | dst.blit_animation(pos[F], anim_idx, tanim, owner->get_playercolor(), | ||
1750 | 368 | Rect(Point(0, h - lines), w, lines)); | ||
1751 | 369 | } else if (upcast(const BuildingDescr, building, map_object_descr)) { | ||
1752 | 370 | assert(owner != nullptr); | ||
1753 | 371 | // this is a building therefore we either draw unoccupied or idle animation | ||
1754 | 372 | uint32_t pic; | ||
1755 | 373 | try { | ||
1756 | 374 | pic = building->get_animation("unoccupied"); | ||
1757 | 375 | } catch (MapObjectDescr::AnimationNonexistent&) { | ||
1758 | 376 | pic = building->get_animation("idle"); | ||
1759 | 377 | } | ||
1760 | 378 | dst.blit_animation(pos[F], pic, 0, owner->get_playercolor()); | ||
1761 | 379 | } else if (map_object_descr->type() == MapObjectType::FLAG) { | ||
1762 | 380 | assert(owner != nullptr); | ||
1763 | 381 | dst.blit_animation( | ||
1764 | 382 | pos[F], owner->tribe().flag_animation(), 0, owner->get_playercolor()); | ||
1765 | 383 | } else if (const uint32_t pic = map_object_descr->main_animation()) { | ||
1766 | 384 | if (owner != nullptr) { | ||
1767 | 385 | dst.blit_animation(pos[F], pic, 0, owner->get_playercolor()); | ||
1768 | 386 | } else { | ||
1769 | 387 | dst.blit_animation(pos[F], pic, 0); | ||
1770 | 388 | } | ||
1771 | 389 | } | ||
1772 | 390 | } | ||
1773 | 391 | } | ||
1774 | 392 | |||
1775 | 393 | const FieldOverlayManager& overlay_manager = egbase.get_ibase()->field_overlay_manager(); | ||
1776 | 394 | { | ||
1777 | 395 | overlay_info.clear(); | ||
1778 | 396 | overlay_manager.get_overlays(coords[F], &overlay_info); | ||
1779 | 397 | for (const auto& overlay : overlay_info) { | ||
1780 | 398 | dst.blit(pos[F] - overlay.hotspot, overlay.pic); | ||
1781 | 399 | } | ||
1782 | 400 | } | ||
1783 | 401 | |||
1784 | 402 | { | ||
1785 | 403 | // Render overlays on the R triangle | ||
1786 | 404 | overlay_info.clear(); | ||
1787 | 405 | overlay_manager.get_overlays(TCoords<>(coords[F], TCoords<>::R), &overlay_info); | ||
1788 | 406 | |||
1789 | 407 | Point tripos( | ||
1790 | 408 | (pos[F].x + pos[R].x + pos[BR].x) / 3, (pos[F].y + pos[R].y + pos[BR].y) / 3); | ||
1791 | 409 | for (const auto& overlay : overlay_info) { | ||
1792 | 410 | dst.blit(tripos - overlay.hotspot, overlay.pic); | ||
1793 | 411 | } | ||
1794 | 412 | } | ||
1795 | 413 | |||
1796 | 414 | { | ||
1797 | 415 | // Render overlays on the D triangle | ||
1798 | 416 | overlay_info.clear(); | ||
1799 | 417 | overlay_manager.get_overlays(TCoords<>(coords[F], TCoords<>::D), &overlay_info); | ||
1800 | 418 | |||
1801 | 419 | Point tripos( | ||
1802 | 420 | (pos[F].x + pos[BL].x + pos[BR].x) / 3, (pos[F].y + pos[BL].y + pos[BR].y) / 3); | ||
1803 | 421 | for (const auto& overlay : overlay_info) { | ||
1804 | 422 | dst.blit(tripos - overlay.hotspot, overlay.pic); | ||
1805 | 423 | } | ||
1806 | 424 | } | ||
1807 | 425 | } | ||
1808 | 426 | } | ||
1810 | 427 | } | 461 | } |
1811 | 428 | 462 | ||
1812 | === modified file 'src/graphic/game_renderer.h' | |||
1813 | --- src/graphic/game_renderer.h 2016-08-04 15:49:05 +0000 | |||
1814 | +++ src/graphic/game_renderer.h 2016-10-24 20:07:47 +0000 | |||
1815 | @@ -23,8 +23,9 @@ | |||
1816 | 23 | #include <memory> | 23 | #include <memory> |
1817 | 24 | 24 | ||
1818 | 25 | #include "base/macros.h" | 25 | #include "base/macros.h" |
1820 | 26 | #include "base/point.h" | 26 | #include "base/vector.h" |
1821 | 27 | #include "graphic/gl/fields_to_draw.h" | 27 | #include "graphic/gl/fields_to_draw.h" |
1822 | 28 | #include "logic/map_objects/draw_text.h" | ||
1823 | 28 | 29 | ||
1824 | 29 | namespace Widelands { | 30 | namespace Widelands { |
1825 | 30 | class Player; | 31 | class Player; |
1826 | @@ -33,51 +34,39 @@ | |||
1827 | 33 | 34 | ||
1828 | 34 | class RenderTarget; | 35 | class RenderTarget; |
1829 | 35 | 36 | ||
1840 | 36 | /** | 37 | // Renders the MapView on screen. |
1831 | 37 | * This abstract base class renders the main game view into an | ||
1832 | 38 | * arbitrary @ref RenderTarget. | ||
1833 | 39 | * | ||
1834 | 40 | * Specializations exist for SDL software rendering and for OpenGL rendering. | ||
1835 | 41 | * | ||
1836 | 42 | * Users of this class should keep instances alive for as long as possible, | ||
1837 | 43 | * so that target-specific optimizations (such as caching data) can | ||
1838 | 44 | * be effective. | ||
1839 | 45 | */ | ||
1841 | 46 | class GameRenderer { | 38 | class GameRenderer { |
1842 | 47 | public: | 39 | public: |
1843 | 48 | GameRenderer(); | 40 | GameRenderer(); |
1844 | 49 | ~GameRenderer(); | 41 | ~GameRenderer(); |
1845 | 50 | 42 | ||
1853 | 51 | // Renders the map from a player's point of view into the given | 43 | // Renders the map from a player's point of view into the given drawing |
1854 | 52 | // drawing window. 'view_offset' is the offset of the upper left | 44 | // window. The 'viewpoint' is the top left screens pixel map pixel and |
1855 | 53 | // corner of the window into the map, in pixels. | 45 | // 'scale' is the magnification of the view. |
1856 | 54 | void rendermap(RenderTarget& dst, | 46 | void rendermap(const Widelands::EditorGameBase& egbase, |
1857 | 55 | const Widelands::EditorGameBase& egbase, | 47 | const Vector2f& viewpoint, |
1858 | 56 | const Point& view_offset, | 48 | float scale, |
1859 | 57 | const Widelands::Player& player); | 49 | const Widelands::Player& player, |
1860 | 50 | DrawText draw_text, | ||
1861 | 51 | RenderTarget* dst); | ||
1862 | 58 | 52 | ||
1863 | 59 | // Renders the map from an omniscient perspective. This is used | 53 | // Renders the map from an omniscient perspective. This is used |
1864 | 60 | // for spectators, players that see all, and in the editor. | 54 | // for spectators, players that see all, and in the editor. |
1867 | 61 | void | 55 | void rendermap(const Widelands::EditorGameBase& egbase, |
1868 | 62 | rendermap(RenderTarget& dst, const Widelands::EditorGameBase& egbase, const Point& view_offset); | 56 | const Vector2f& viewpoint, |
1869 | 57 | float scale, | ||
1870 | 58 | DrawText draw_text, | ||
1871 | 59 | RenderTarget* dst); | ||
1872 | 63 | 60 | ||
1873 | 64 | private: | 61 | private: |
1874 | 65 | // Draw the map for the given parameters (see rendermap). 'player' | 62 | // Draw the map for the given parameters (see rendermap). 'player' |
1875 | 66 | // can be nullptr in which case the whole map is drawn. | 63 | // can be nullptr in which case the whole map is drawn. |
1890 | 67 | void draw(RenderTarget& dst, | 64 | void draw(const Widelands::EditorGameBase& egbase, |
1891 | 68 | const Widelands::EditorGameBase& egbase, | 65 | const Vector2f& viewpoint, |
1892 | 69 | const Point& view_offset, | 66 | float scale, |
1893 | 70 | const Widelands::Player* player); | 67 | DrawText draw_text, |
1894 | 71 | 68 | const Widelands::Player* player, | |
1895 | 72 | // Draws the objects (animations & overlays). | 69 | RenderTarget* dst); |
1882 | 73 | void draw_objects(RenderTarget& dst, | ||
1883 | 74 | const Widelands::EditorGameBase& egbase, | ||
1884 | 75 | const Point& view_offset, | ||
1885 | 76 | const Widelands::Player* player, | ||
1886 | 77 | int minfx, | ||
1887 | 78 | int maxfx, | ||
1888 | 79 | int minfy, | ||
1889 | 80 | int maxfy); | ||
1896 | 81 | 70 | ||
1897 | 82 | // This is owned and handled by us, but handed to the RenderQueue, so we | 71 | // This is owned and handled by us, but handed to the RenderQueue, so we |
1898 | 83 | // basically promise that this stays valid for one frame. | 72 | // basically promise that this stays valid for one frame. |
1899 | 84 | 73 | ||
1900 | === modified file 'src/graphic/gl/blit_data.h' | |||
1901 | --- src/graphic/gl/blit_data.h 2016-01-04 20:54:08 +0000 | |||
1902 | +++ src/graphic/gl/blit_data.h 2016-10-24 20:07:47 +0000 | |||
1903 | @@ -38,7 +38,7 @@ | |||
1904 | 38 | int parent_height; | 38 | int parent_height; |
1905 | 39 | 39 | ||
1906 | 40 | // The subrect in the parent texture. | 40 | // The subrect in the parent texture. |
1908 | 41 | Rect rect; | 41 | Rectf rect; |
1909 | 42 | }; | 42 | }; |
1910 | 43 | 43 | ||
1911 | 44 | #endif // end of include guard: WL_GRAPHIC_GL_BLIT_DATA_H | 44 | #endif // end of include guard: WL_GRAPHIC_GL_BLIT_DATA_H |
1912 | 45 | 45 | ||
1913 | === modified file 'src/graphic/gl/blit_program.cc' | |||
1914 | --- src/graphic/gl/blit_program.cc 2016-08-04 15:49:05 +0000 | |||
1915 | +++ src/graphic/gl/blit_program.cc 2016-10-24 20:07:47 +0000 | |||
1916 | @@ -108,8 +108,8 @@ | |||
1917 | 108 | const float blend_b = current_args.blend.b / 255.; | 108 | const float blend_b = current_args.blend.b / 255.; |
1918 | 109 | const float blend_a = current_args.blend.a / 255.; | 109 | const float blend_a = current_args.blend.a / 255.; |
1919 | 110 | 110 | ||
1922 | 111 | const FloatRect texture_rect = to_gl_texture(current_args.texture); | 111 | const Rectf texture_rect = to_gl_texture(current_args.texture); |
1923 | 112 | const FloatRect mask_rect = to_gl_texture(current_args.mask); | 112 | const Rectf mask_rect = to_gl_texture(current_args.mask); |
1924 | 113 | float program_flavor = 0; | 113 | float program_flavor = 0; |
1925 | 114 | switch (current_args.blit_mode) { | 114 | switch (current_args.blit_mode) { |
1926 | 115 | case BlitMode::kDirect: | 115 | case BlitMode::kDirect: |
1927 | @@ -176,7 +176,7 @@ | |||
1928 | 176 | } | 176 | } |
1929 | 177 | } | 177 | } |
1930 | 178 | 178 | ||
1932 | 179 | void BlitProgram::draw(const FloatRect& gl_dest_rect, | 179 | void BlitProgram::draw(const Rectf& gl_dest_rect, |
1933 | 180 | const float z_value, | 180 | const float z_value, |
1934 | 181 | const BlitData& texture, | 181 | const BlitData& texture, |
1935 | 182 | const BlitData& mask, | 182 | const BlitData& mask, |
1936 | @@ -186,11 +186,11 @@ | |||
1937 | 186 | mask.texture_id != 0 ? BlitMode::kBlendedWithMask : BlitMode::kDirect}}); | 186 | mask.texture_id != 0 ? BlitMode::kBlendedWithMask : BlitMode::kDirect}}); |
1938 | 187 | } | 187 | } |
1939 | 188 | 188 | ||
1941 | 189 | void BlitProgram::draw_monochrome(const FloatRect& dest_rect, | 189 | void BlitProgram::draw_monochrome(const Rectf& dest_rect, |
1942 | 190 | const float z_value, | 190 | const float z_value, |
1943 | 191 | const BlitData& texture, | 191 | const BlitData& texture, |
1944 | 192 | const RGBAColor& blend) { | 192 | const RGBAColor& blend) { |
1946 | 193 | draw({Arguments{dest_rect, z_value, texture, BlitData{0, 0, 0, Rect()}, blend, | 193 | draw({Arguments{dest_rect, z_value, texture, BlitData{0, 0, 0, Rectf()}, blend, |
1947 | 194 | BlendMode::UseAlpha, BlitMode::kMonochrome}}); | 194 | BlendMode::UseAlpha, BlitMode::kMonochrome}}); |
1948 | 195 | } | 195 | } |
1949 | 196 | 196 | ||
1950 | 197 | 197 | ||
1951 | === modified file 'src/graphic/gl/blit_program.h' | |||
1952 | --- src/graphic/gl/blit_program.h 2016-08-04 15:49:05 +0000 | |||
1953 | +++ src/graphic/gl/blit_program.h 2016-10-24 20:07:47 +0000 | |||
1954 | @@ -36,7 +36,7 @@ | |||
1955 | 36 | class BlitProgram { | 36 | class BlitProgram { |
1956 | 37 | public: | 37 | public: |
1957 | 38 | struct Arguments { | 38 | struct Arguments { |
1959 | 39 | FloatRect destination_rect; | 39 | Rectf destination_rect; |
1960 | 40 | float z_value; | 40 | float z_value; |
1961 | 41 | BlitData texture; | 41 | BlitData texture; |
1962 | 42 | BlitData mask; | 42 | BlitData mask; |
1963 | @@ -53,7 +53,7 @@ | |||
1964 | 53 | // 'gl_texture_image' to 'gl_dest_rect' in the currently bound framebuffer. All | 53 | // 'gl_texture_image' to 'gl_dest_rect' in the currently bound framebuffer. All |
1965 | 54 | // coordinates are in the OpenGL frame. The 'texture_mask' is used to selectively apply | 54 | // coordinates are in the OpenGL frame. The 'texture_mask' is used to selectively apply |
1966 | 55 | // the 'blend'. This is used for blitting player colored images. | 55 | // the 'blend'. This is used for blitting player colored images. |
1968 | 56 | void draw(const FloatRect& gl_dest_rect, | 56 | void draw(const Rectf& gl_dest_rect, |
1969 | 57 | const float z_value, | 57 | const float z_value, |
1970 | 58 | const BlitData& texture, | 58 | const BlitData& texture, |
1971 | 59 | const BlitData& mask, | 59 | const BlitData& mask, |
1972 | @@ -64,7 +64,7 @@ | |||
1973 | 64 | // 'texture' to 'gl_dest_rect' in the currently bound framebuffer. All | 64 | // 'texture' to 'gl_dest_rect' in the currently bound framebuffer. All |
1974 | 65 | // coordinates are in the OpenGL frame. The image is first converted to | 65 | // coordinates are in the OpenGL frame. The image is first converted to |
1975 | 66 | // luminance, then all values are multiplied with blend. | 66 | // luminance, then all values are multiplied with blend. |
1977 | 67 | void draw_monochrome(const FloatRect& gl_dest_rect, | 67 | void draw_monochrome(const Rectf& gl_dest_rect, |
1978 | 68 | const float z_value, | 68 | const float z_value, |
1979 | 69 | const BlitData& blit_source, | 69 | const BlitData& blit_source, |
1980 | 70 | const RGBAColor& blend); | 70 | const RGBAColor& blend); |
1981 | 71 | 71 | ||
1982 | === modified file 'src/graphic/gl/coordinate_conversion.h' | |||
1983 | --- src/graphic/gl/coordinate_conversion.h 2016-08-04 15:49:05 +0000 | |||
1984 | +++ src/graphic/gl/coordinate_conversion.h 2016-10-24 20:07:47 +0000 | |||
1985 | @@ -38,34 +38,34 @@ | |||
1986 | 38 | // Converts 'rect' given on a screen of 'width' x 'height' pixels into a rect | 38 | // Converts 'rect' given on a screen of 'width' x 'height' pixels into a rect |
1987 | 39 | // in opengl coordinates in a renderbuffer, i.e. in [-1, 1]. The returned | 39 | // in opengl coordinates in a renderbuffer, i.e. in [-1, 1]. The returned |
1988 | 40 | // rectangle has positive width and height. | 40 | // rectangle has positive width and height. |
1990 | 41 | inline FloatRect rect_to_gl_renderbuffer(const int width, const int height, const Rect& rect) { | 41 | inline Rectf rect_to_gl_renderbuffer(const int width, const int height, const Rectf& rect) { |
1991 | 42 | float left = rect.x; | 42 | float left = rect.x; |
1992 | 43 | float top = rect.y; | 43 | float top = rect.y; |
1993 | 44 | float right = rect.x + rect.w; | 44 | float right = rect.x + rect.w; |
1994 | 45 | float bottom = rect.y + rect.h; | 45 | float bottom = rect.y + rect.h; |
1995 | 46 | pixel_to_gl_renderbuffer(width, height, &left, &top); | 46 | pixel_to_gl_renderbuffer(width, height, &left, &top); |
1996 | 47 | pixel_to_gl_renderbuffer(width, height, &right, &bottom); | 47 | pixel_to_gl_renderbuffer(width, height, &right, &bottom); |
1998 | 48 | return FloatRect(left, bottom, right - left, top - bottom); | 48 | return Rectf(left, bottom, right - left, top - bottom); |
1999 | 49 | } | 49 | } |
2000 | 50 | 50 | ||
2001 | 51 | // Converts 'rect' given on a texture of 'width' x 'height' pixels into a rect | 51 | // Converts 'rect' given on a texture of 'width' x 'height' pixels into a rect |
2002 | 52 | // in opengl coordinates in a texture, i.e. in [0, 1]. Texture pixels are sampled in their center. | 52 | // in opengl coordinates in a texture, i.e. in [0, 1]. Texture pixels are sampled in their center. |
2003 | 53 | // The returned rectangle has positive width and height. | 53 | // The returned rectangle has positive width and height. |
2005 | 54 | inline FloatRect rect_to_gl_texture(const int width, const int height, const FloatRect& rect) { | 54 | inline Rectf rect_to_gl_texture(const int width, const int height, const Rectf& rect) { |
2006 | 55 | float left = rect.x; | 55 | float left = rect.x; |
2007 | 56 | float top = rect.y; | 56 | float top = rect.y; |
2008 | 57 | float right = rect.x + rect.w; | 57 | float right = rect.x + rect.w; |
2009 | 58 | float bottom = rect.y + rect.h; | 58 | float bottom = rect.y + rect.h; |
2010 | 59 | pixel_to_gl_texture(width, height, &left, &top); | 59 | pixel_to_gl_texture(width, height, &left, &top); |
2011 | 60 | pixel_to_gl_texture(width, height, &right, &bottom); | 60 | pixel_to_gl_texture(width, height, &right, &bottom); |
2013 | 61 | return FloatRect(left, bottom, right - left, top - bottom); | 61 | return Rectf(left, bottom, right - left, top - bottom); |
2014 | 62 | } | 62 | } |
2015 | 63 | 63 | ||
2016 | 64 | // Convert 'blit_data' from pixel space into opengl space. | 64 | // Convert 'blit_data' from pixel space into opengl space. |
2018 | 65 | inline FloatRect to_gl_texture(const BlitData& blit_data) { | 65 | inline Rectf to_gl_texture(const BlitData& blit_data) { |
2019 | 66 | return rect_to_gl_texture( | 66 | return rect_to_gl_texture( |
2020 | 67 | blit_data.parent_width, blit_data.parent_height, | 67 | blit_data.parent_width, blit_data.parent_height, |
2022 | 68 | FloatRect(blit_data.rect.x, blit_data.rect.y, blit_data.rect.w, blit_data.rect.h)); | 68 | Rectf(blit_data.rect.x, blit_data.rect.y, blit_data.rect.w, blit_data.rect.h)); |
2023 | 69 | } | 69 | } |
2024 | 70 | 70 | ||
2025 | 71 | #endif // end of include guard: WL_GRAPHIC_GL_COORDINATE_CONVERSION_H | 71 | #endif // end of include guard: WL_GRAPHIC_GL_COORDINATE_CONVERSION_H |
2026 | 72 | 72 | ||
2027 | === modified file 'src/graphic/gl/dither_program.cc' | |||
2028 | --- src/graphic/gl/dither_program.cc 2016-08-04 15:49:05 +0000 | |||
2029 | +++ src/graphic/gl/dither_program.cc 2016-10-24 20:07:47 +0000 | |||
2030 | @@ -56,14 +56,14 @@ | |||
2031 | 56 | 56 | ||
2032 | 57 | void DitherProgram::add_vertex(const FieldsToDraw::Field& field, | 57 | void DitherProgram::add_vertex(const FieldsToDraw::Field& field, |
2033 | 58 | const TrianglePoint triangle_point, | 58 | const TrianglePoint triangle_point, |
2035 | 59 | const FloatPoint& texture_offset) { | 59 | const Vector2f& texture_offset) { |
2036 | 60 | vertices_.emplace_back(); | 60 | vertices_.emplace_back(); |
2037 | 61 | PerVertexData& back = vertices_.back(); | 61 | PerVertexData& back = vertices_.back(); |
2038 | 62 | 62 | ||
2043 | 63 | back.gl_x = field.gl_x; | 63 | back.gl_x = field.gl_position.x; |
2044 | 64 | back.gl_y = field.gl_y; | 64 | back.gl_y = field.gl_position.y; |
2045 | 65 | back.texture_x = field.texture_x; | 65 | back.texture_x = field.texture_coords.x; |
2046 | 66 | back.texture_y = field.texture_y; | 66 | back.texture_y = field.texture_coords.y; |
2047 | 67 | back.brightness = field.brightness; | 67 | back.brightness = field.brightness; |
2048 | 68 | back.texture_offset_x = texture_offset.x; | 68 | back.texture_offset_x = texture_offset.x; |
2049 | 69 | back.texture_offset_y = texture_offset.y; | 69 | back.texture_offset_y = texture_offset.y; |
2050 | @@ -98,7 +98,7 @@ | |||
2051 | 98 | } | 98 | } |
2052 | 99 | const Widelands::TerrainDescription& other_terrain_description = terrains.get(other_terrain); | 99 | const Widelands::TerrainDescription& other_terrain_description = terrains.get(other_terrain); |
2053 | 100 | if (terrains.get(my_terrain).dither_layer() < other_terrain_description.dither_layer()) { | 100 | if (terrains.get(my_terrain).dither_layer() < other_terrain_description.dither_layer()) { |
2055 | 101 | const FloatPoint texture_offset = | 101 | const Vector2f texture_offset = |
2056 | 102 | to_gl_texture(other_terrain_description.get_texture(gametime).blit_data()).origin(); | 102 | to_gl_texture(other_terrain_description.get_texture(gametime).blit_data()).origin(); |
2057 | 103 | add_vertex(fields_to_draw.at(idx1), TrianglePoint::kTopRight, texture_offset); | 103 | add_vertex(fields_to_draw.at(idx1), TrianglePoint::kTopRight, texture_offset); |
2058 | 104 | add_vertex(fields_to_draw.at(idx2), TrianglePoint::kTopLeft, texture_offset); | 104 | add_vertex(fields_to_draw.at(idx2), TrianglePoint::kTopLeft, texture_offset); |
2059 | @@ -156,50 +156,49 @@ | |||
2060 | 156 | // The bottom right neighbor fields_to_draw is needed for both triangles | 156 | // The bottom right neighbor fields_to_draw is needed for both triangles |
2061 | 157 | // associated with this field. If it is not in fields_to_draw, there is no need to | 157 | // associated with this field. If it is not in fields_to_draw, there is no need to |
2062 | 158 | // draw any triangles. | 158 | // draw any triangles. |
2065 | 159 | const int brn_index = fields_to_draw.calculate_index(field.fx + (field.fy & 1), field.fy + 1); | 159 | if (field.brn_index == FieldsToDraw::kInvalidIndex) { |
2064 | 160 | if (brn_index == -1) { | ||
2066 | 161 | continue; | 160 | continue; |
2067 | 162 | } | 161 | } |
2068 | 163 | 162 | ||
2069 | 164 | // Dithering triangles for Down triangle. | 163 | // Dithering triangles for Down triangle. |
2083 | 165 | const int bln_index = | 164 | if (field.bln_index != FieldsToDraw::kInvalidIndex) { |
2084 | 166 | fields_to_draw.calculate_index(field.fx + (field.fy & 1) - 1, field.fy + 1); | 165 | maybe_add_dithering_triangle( |
2085 | 167 | if (bln_index != -1) { | 166 | gametime, terrains, fields_to_draw, field.brn_index, current_index, field.bln_index, |
2086 | 168 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, brn_index, current_index, | 167 | field.fcoords.field->terrain_d(), field.fcoords.field->terrain_r()); |
2087 | 169 | bln_index, field.ter_d, field.ter_r); | 168 | |
2088 | 170 | 169 | const int terrain_dd = fields_to_draw.at(field.bln_index).fcoords.field->terrain_r(); | |
2089 | 171 | const int terrain_dd = fields_to_draw.at(bln_index).ter_r; | 170 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, field.bln_index, |
2090 | 172 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, bln_index, brn_index, | 171 | field.brn_index, current_index, |
2091 | 173 | current_index, field.ter_d, terrain_dd); | 172 | field.fcoords.field->terrain_d(), terrain_dd); |
2092 | 174 | 173 | ||
2093 | 175 | const int ln_index = fields_to_draw.calculate_index(field.fx - 1, field.fy); | 174 | if (field.ln_index != FieldsToDraw::kInvalidIndex) { |
2094 | 176 | if (ln_index != -1) { | 175 | const int terrain_l = fields_to_draw.at(field.ln_index).fcoords.field->terrain_r(); |
2082 | 177 | const int terrain_l = fields_to_draw.at(ln_index).ter_r; | ||
2095 | 178 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, current_index, | 176 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, current_index, |
2097 | 179 | bln_index, brn_index, field.ter_d, terrain_l); | 177 | field.bln_index, field.brn_index, |
2098 | 178 | field.fcoords.field->terrain_d(), terrain_l); | ||
2099 | 180 | } | 179 | } |
2100 | 181 | } | 180 | } |
2101 | 182 | 181 | ||
2102 | 183 | // Dithering for right triangle. | 182 | // Dithering for right triangle. |
2110 | 184 | const int rn_index = fields_to_draw.calculate_index(field.fx + 1, field.fy); | 183 | if (field.rn_index != FieldsToDraw::kInvalidIndex) { |
2111 | 185 | if (rn_index != -1) { | 184 | maybe_add_dithering_triangle( |
2112 | 186 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, current_index, brn_index, | 185 | gametime, terrains, fields_to_draw, current_index, field.brn_index, field.rn_index, |
2113 | 187 | rn_index, field.ter_r, field.ter_d); | 186 | field.fcoords.field->terrain_r(), field.fcoords.field->terrain_d()); |
2114 | 188 | int terrain_rr = fields_to_draw.at(rn_index).ter_d; | 187 | int terrain_rr = fields_to_draw.at(field.rn_index).fcoords.field->terrain_d(); |
2115 | 189 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, brn_index, rn_index, | 188 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, field.brn_index, |
2116 | 190 | current_index, field.ter_r, terrain_rr); | 189 | field.rn_index, current_index, |
2117 | 190 | field.fcoords.field->terrain_r(), terrain_rr); | ||
2118 | 191 | 191 | ||
2125 | 192 | const int trn_index = | 192 | if (field.trn_index != FieldsToDraw::kInvalidIndex) { |
2126 | 193 | fields_to_draw.calculate_index(field.fx + (field.fy & 1), field.fy - 1); | 193 | const int terrain_u = fields_to_draw.at(field.trn_index).fcoords.field->terrain_d(); |
2127 | 194 | if (trn_index != -1) { | 194 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, field.rn_index, |
2128 | 195 | const int terrain_u = fields_to_draw.at(trn_index).ter_d; | 195 | current_index, field.brn_index, |
2129 | 196 | maybe_add_dithering_triangle(gametime, terrains, fields_to_draw, rn_index, | 196 | field.fcoords.field->terrain_r(), terrain_u); |
2124 | 197 | current_index, brn_index, field.ter_r, terrain_u); | ||
2130 | 198 | } | 197 | } |
2131 | 199 | } | 198 | } |
2132 | 200 | } | 199 | } |
2133 | 201 | 200 | ||
2134 | 202 | const BlitData& blit_data = terrains.get(0).get_texture(0).blit_data(); | 201 | const BlitData& blit_data = terrains.get(0).get_texture(0).blit_data(); |
2136 | 203 | const FloatRect texture_coordinates = to_gl_texture(blit_data); | 202 | const Rectf texture_coordinates = to_gl_texture(blit_data); |
2137 | 204 | gl_draw(blit_data.texture_id, texture_coordinates.w, texture_coordinates.h, z_value); | 203 | gl_draw(blit_data.texture_id, texture_coordinates.w, texture_coordinates.h, z_value); |
2138 | 205 | } | 204 | } |
2139 | 206 | 205 | ||
2140 | === modified file 'src/graphic/gl/dither_program.h' | |||
2141 | --- src/graphic/gl/dither_program.h 2016-01-08 21:00:39 +0000 | |||
2142 | +++ src/graphic/gl/dither_program.h 2016-10-24 20:07:47 +0000 | |||
2143 | @@ -22,7 +22,7 @@ | |||
2144 | 22 | 22 | ||
2145 | 23 | #include <memory> | 23 | #include <memory> |
2146 | 24 | 24 | ||
2148 | 25 | #include "base/point.h" | 25 | #include "base/vector.h" |
2149 | 26 | #include "graphic/gl/fields_to_draw.h" | 26 | #include "graphic/gl/fields_to_draw.h" |
2150 | 27 | #include "graphic/gl/utils.h" | 27 | #include "graphic/gl/utils.h" |
2151 | 28 | #include "logic/description_maintainer.h" | 28 | #include "logic/description_maintainer.h" |
2152 | @@ -66,7 +66,7 @@ | |||
2153 | 66 | // this vertex. | 66 | // this vertex. |
2154 | 67 | void add_vertex(const FieldsToDraw::Field& field, | 67 | void add_vertex(const FieldsToDraw::Field& field, |
2155 | 68 | TrianglePoint triangle_point, | 68 | TrianglePoint triangle_point, |
2157 | 69 | const FloatPoint& texture_offset); | 69 | const Vector2f& texture_offset); |
2158 | 70 | 70 | ||
2159 | 71 | struct PerVertexData { | 71 | struct PerVertexData { |
2160 | 72 | float gl_x; | 72 | float gl_x; |
2161 | 73 | 73 | ||
2162 | === modified file 'src/graphic/gl/draw_line_program.h' | |||
2163 | --- src/graphic/gl/draw_line_program.h 2016-02-02 09:02:53 +0000 | |||
2164 | +++ src/graphic/gl/draw_line_program.h 2016-10-24 20:07:47 +0000 | |||
2165 | @@ -22,8 +22,8 @@ | |||
2166 | 22 | 22 | ||
2167 | 23 | #include <vector> | 23 | #include <vector> |
2168 | 24 | 24 | ||
2169 | 25 | #include "base/point.h" | ||
2170 | 26 | #include "base/rect.h" | 25 | #include "base/rect.h" |
2171 | 26 | #include "base/vector.h" | ||
2172 | 27 | #include "graphic/blend_mode.h" | 27 | #include "graphic/blend_mode.h" |
2173 | 28 | #include "graphic/color.h" | 28 | #include "graphic/color.h" |
2174 | 29 | #include "graphic/gl/utils.h" | 29 | #include "graphic/gl/utils.h" |
2175 | 30 | 30 | ||
2176 | === modified file 'src/graphic/gl/fields_to_draw.h' | |||
2177 | --- src/graphic/gl/fields_to_draw.h 2016-08-04 15:49:05 +0000 | |||
2178 | +++ src/graphic/gl/fields_to_draw.h 2016-10-24 20:07:47 +0000 | |||
2179 | @@ -21,29 +21,64 @@ | |||
2180 | 21 | #define WL_GRAPHIC_GL_FIELDS_TO_DRAW_H | 21 | #define WL_GRAPHIC_GL_FIELDS_TO_DRAW_H |
2181 | 22 | 22 | ||
2182 | 23 | #include <cstddef> | 23 | #include <cstddef> |
2183 | 24 | #include <limits> | ||
2184 | 24 | #include <string> | 25 | #include <string> |
2185 | 25 | #include <vector> | 26 | #include <vector> |
2186 | 26 | 27 | ||
2187 | 27 | #include <stdint.h> | 28 | #include <stdint.h> |
2188 | 28 | 29 | ||
2189 | 30 | #include "base/vector.h" | ||
2190 | 29 | #include "logic/map_objects/tribes/road_textures.h" | 31 | #include "logic/map_objects/tribes/road_textures.h" |
2191 | 32 | #include "logic/player.h" | ||
2192 | 33 | #include "logic/widelands.h" | ||
2193 | 34 | #include "logic/widelands_geometry.h" | ||
2194 | 30 | 35 | ||
2195 | 31 | // Helper struct that contains the data needed for drawing all fields. All | 36 | // Helper struct that contains the data needed for drawing all fields. All |
2196 | 32 | // methods are inlined for performance reasons. | 37 | // methods are inlined for performance reasons. |
2197 | 33 | class FieldsToDraw { | 38 | class FieldsToDraw { |
2198 | 34 | public: | 39 | public: |
2199 | 40 | static constexpr int kInvalidIndex = std::numeric_limits<int>::min(); | ||
2200 | 41 | |||
2201 | 35 | struct Field { | 42 | struct Field { |
2210 | 36 | int fx, fy; // geometric coordinates (i.e. map coordinates that can be out of bounds). | 43 | Widelands::Coords geometric_coords; // geometric coordinates (i.e. map coordinates that can |
2211 | 37 | float gl_x, gl_y; // GL Position of this field. | 44 | // be out of bounds). |
2212 | 38 | float pixel_x, pixel_y; // Pixel position relative to top left. | 45 | Widelands::FCoords fcoords; // The normalized coords and the field this is refering to. |
2213 | 39 | float texture_x, texture_y; // Texture coordinates. | 46 | Vector2f gl_position; // GL Position of this field. |
2214 | 40 | float brightness; // brightness of the pixel | 47 | |
2215 | 41 | uint8_t ter_r, ter_d; // Texture index of the right and down triangle. | 48 | // Surface pixel this will be plotted on. |
2216 | 42 | uint8_t roads; // Bitmask of roads to render, see logic/roadtype.h. | 49 | Vector2f surface_pixel; |
2217 | 43 | const RoadTextures* road_textures; // Road Textures to use for drawing. | 50 | |
2218 | 51 | // Rendertarget pixel this will be plotted on. This is only different by | ||
2219 | 52 | // the Rendertarget::get_rect().origin() of the view window. | ||
2220 | 53 | Vector2f rendertarget_pixel; | ||
2221 | 54 | Vector2f texture_coords; // Texture coordinates. | ||
2222 | 55 | float brightness; // brightness of the pixel | ||
2223 | 56 | |||
2224 | 57 | // The next values are not necessarily the true data of this field, but | ||
2225 | 58 | // what the player should see. For example in fog of war we always draw | ||
2226 | 59 | // what we saw last. | ||
2227 | 60 | uint8_t roads; // Bitmask of roads to render, see logic/roadtype.h. | ||
2228 | 61 | bool is_border; | ||
2229 | 62 | Widelands::Vision vision; | ||
2230 | 63 | Widelands::Player* owner; // can be nullptr. | ||
2231 | 64 | |||
2232 | 65 | // Index of neighbors in this 'FieldsToDraw'. kInvalidIndex if this | ||
2233 | 66 | // neighbor is not contained. | ||
2234 | 67 | int ln_index; | ||
2235 | 68 | int rn_index; | ||
2236 | 69 | int trn_index; | ||
2237 | 70 | int bln_index; | ||
2238 | 71 | int brn_index; | ||
2239 | 72 | |||
2240 | 73 | inline bool all_neighbors_valid() const { | ||
2241 | 74 | return ln_index != kInvalidIndex && rn_index != kInvalidIndex && | ||
2242 | 75 | trn_index != kInvalidIndex && bln_index != kInvalidIndex && | ||
2243 | 76 | brn_index != kInvalidIndex; | ||
2244 | 77 | } | ||
2245 | 44 | }; | 78 | }; |
2246 | 45 | 79 | ||
2248 | 46 | FieldsToDraw() = default; | 80 | FieldsToDraw() { |
2249 | 81 | } | ||
2250 | 47 | 82 | ||
2251 | 48 | // Resize this fields to draw for reuse. | 83 | // Resize this fields to draw for reuse. |
2252 | 49 | void reset(int minfx, int maxfx, int minfy, int maxfy) { | 84 | void reset(int minfx, int maxfx, int minfy, int maxfy) { |
2253 | @@ -60,15 +95,16 @@ | |||
2254 | 60 | } | 95 | } |
2255 | 61 | 96 | ||
2256 | 62 | // Calculates the index of the given field with ('fx', 'fy') being geometric | 97 | // Calculates the index of the given field with ('fx', 'fy') being geometric |
2258 | 63 | // coordinates in the map. Returns -1 if this field is not in the fields_to_draw. | 98 | // coordinates in the map. Returns kInvalidIndex if this field is not in the |
2259 | 99 | // fields_to_draw. | ||
2260 | 64 | inline int calculate_index(int fx, int fy) const { | 100 | inline int calculate_index(int fx, int fy) const { |
2261 | 65 | uint16_t xidx = fx - min_fx_; | 101 | uint16_t xidx = fx - min_fx_; |
2262 | 66 | if (xidx >= w_) { | 102 | if (xidx >= w_) { |
2264 | 67 | return -1; | 103 | return kInvalidIndex; |
2265 | 68 | } | 104 | } |
2266 | 69 | uint16_t yidx = fy - min_fy_; | 105 | uint16_t yidx = fy - min_fy_; |
2267 | 70 | if (yidx >= h_) { | 106 | if (yidx >= h_) { |
2269 | 71 | return -1; | 107 | return kInvalidIndex; |
2270 | 72 | } | 108 | } |
2271 | 73 | return yidx * w_ + xidx; | 109 | return yidx * w_ + xidx; |
2272 | 74 | } | 110 | } |
2273 | 75 | 111 | ||
2274 | === modified file 'src/graphic/gl/fill_rect_program.cc' | |||
2275 | --- src/graphic/gl/fill_rect_program.cc 2016-08-04 15:49:05 +0000 | |||
2276 | +++ src/graphic/gl/fill_rect_program.cc 2016-10-24 20:07:47 +0000 | |||
2277 | @@ -37,7 +37,7 @@ | |||
2278 | 37 | attr_color_ = glGetAttribLocation(gl_program_.object(), "attr_color"); | 37 | attr_color_ = glGetAttribLocation(gl_program_.object(), "attr_color"); |
2279 | 38 | } | 38 | } |
2280 | 39 | 39 | ||
2282 | 40 | void FillRectProgram::draw(const FloatRect& destination_rect, | 40 | void FillRectProgram::draw(const Rectf& destination_rect, |
2283 | 41 | const float z_value, | 41 | const float z_value, |
2284 | 42 | const RGBAColor& color, | 42 | const RGBAColor& color, |
2285 | 43 | const BlendMode blend_mode) { | 43 | const BlendMode blend_mode) { |
2286 | 44 | 44 | ||
2287 | === modified file 'src/graphic/gl/fill_rect_program.h' | |||
2288 | --- src/graphic/gl/fill_rect_program.h 2016-08-04 15:49:05 +0000 | |||
2289 | +++ src/graphic/gl/fill_rect_program.h 2016-10-24 20:07:47 +0000 | |||
2290 | @@ -30,7 +30,7 @@ | |||
2291 | 30 | class FillRectProgram { | 30 | class FillRectProgram { |
2292 | 31 | public: | 31 | public: |
2293 | 32 | struct Arguments { | 32 | struct Arguments { |
2295 | 33 | FloatRect destination_rect; | 33 | Rectf destination_rect; |
2296 | 34 | float z_value; | 34 | float z_value; |
2297 | 35 | RGBAColor color; | 35 | RGBAColor color; |
2298 | 36 | BlendMode blend_mode; | 36 | BlendMode blend_mode; |
2299 | @@ -41,7 +41,7 @@ | |||
2300 | 41 | 41 | ||
2301 | 42 | // Fills a solid rect in 'color'. If blend_mode is BlendMode::UseAlpha, this | 42 | // Fills a solid rect in 'color'. If blend_mode is BlendMode::UseAlpha, this |
2302 | 43 | // will brighten the rect, if it is BlendMode::Subtract it darkens it. | 43 | // will brighten the rect, if it is BlendMode::Subtract it darkens it. |
2304 | 44 | void draw(const FloatRect& destination_rect, | 44 | void draw(const Rectf& destination_rect, |
2305 | 45 | float z_value, | 45 | float z_value, |
2306 | 46 | const RGBAColor& color, | 46 | const RGBAColor& color, |
2307 | 47 | BlendMode blend_mode); | 47 | BlendMode blend_mode); |
2308 | 48 | 48 | ||
2309 | === modified file 'src/graphic/gl/road_program.cc' | |||
2310 | --- src/graphic/gl/road_program.cc 2016-08-04 15:49:05 +0000 | |||
2311 | +++ src/graphic/gl/road_program.cc 2016-10-24 20:07:47 +0000 | |||
2312 | @@ -50,6 +50,7 @@ | |||
2313 | 50 | const int renderbuffer_height, | 50 | const int renderbuffer_height, |
2314 | 51 | const FieldsToDraw::Field& start, | 51 | const FieldsToDraw::Field& start, |
2315 | 52 | const FieldsToDraw::Field& end, | 52 | const FieldsToDraw::Field& end, |
2316 | 53 | const float scale, | ||
2317 | 53 | const Widelands::RoadType road_type, | 54 | const Widelands::RoadType road_type, |
2318 | 54 | const Direction direction, | 55 | const Direction direction, |
2319 | 55 | uint32_t* gl_texture) { | 56 | uint32_t* gl_texture) { |
2320 | @@ -59,8 +60,8 @@ | |||
2321 | 59 | // The overshot of the road in either direction in percent. | 60 | // The overshot of the road in either direction in percent. |
2322 | 60 | static constexpr float kRoadElongationInPercent = .1; | 61 | static constexpr float kRoadElongationInPercent = .1; |
2323 | 61 | 62 | ||
2326 | 62 | const float delta_x = end.pixel_x - start.pixel_x; | 63 | const float delta_x = end.surface_pixel.x - start.surface_pixel.x; |
2327 | 63 | const float delta_y = end.pixel_y - start.pixel_y; | 64 | const float delta_y = end.surface_pixel.y - start.surface_pixel.y; |
2328 | 64 | const float vector_length = std::hypot(delta_x, delta_y); | 65 | const float vector_length = std::hypot(delta_x, delta_y); |
2329 | 65 | 66 | ||
2330 | 66 | const float road_overshoot_x = delta_x * kRoadElongationInPercent; | 67 | const float road_overshoot_x = delta_x * kRoadElongationInPercent; |
2331 | @@ -68,13 +69,15 @@ | |||
2332 | 68 | 69 | ||
2333 | 69 | // Find the reciprocal unit vector, so that we can calculate start and end | 70 | // Find the reciprocal unit vector, so that we can calculate start and end |
2334 | 70 | // points for the quad that will make the road. | 71 | // points for the quad that will make the road. |
2337 | 71 | const float road_thickness_x = (-delta_y / vector_length) * kRoadThicknessInPixels; | 72 | const float road_thickness_x = (-delta_y / vector_length) * kRoadThicknessInPixels * scale; |
2338 | 72 | const float road_thickness_y = (delta_x / vector_length) * kRoadThicknessInPixels; | 73 | const float road_thickness_y = (delta_x / vector_length) * kRoadThicknessInPixels * scale; |
2339 | 73 | 74 | ||
2340 | 75 | assert(start.owner != nullptr); | ||
2341 | 74 | const Image& texture = | 76 | const Image& texture = |
2342 | 75 | road_type == Widelands::RoadType::kNormal ? | 77 | road_type == Widelands::RoadType::kNormal ? |
2345 | 76 | start.road_textures->get_normal_texture(start.fx, start.fy, direction) : | 78 | start.owner->tribe().road_textures().get_normal_texture( |
2346 | 77 | start.road_textures->get_busy_texture(start.fx, start.fy, direction); | 79 | start.geometric_coords, direction) : |
2347 | 80 | start.owner->tribe().road_textures().get_busy_texture(start.geometric_coords, direction); | ||
2348 | 78 | if (*gl_texture == 0) { | 81 | if (*gl_texture == 0) { |
2349 | 79 | *gl_texture = texture.blit_data().texture_id; | 82 | *gl_texture = texture.blit_data().texture_id; |
2350 | 80 | } | 83 | } |
2351 | @@ -82,27 +85,27 @@ | |||
2352 | 82 | // one texture atlas. | 85 | // one texture atlas. |
2353 | 83 | assert(*gl_texture == texture.blit_data().texture_id); | 86 | assert(*gl_texture == texture.blit_data().texture_id); |
2354 | 84 | 87 | ||
2356 | 85 | const FloatRect texture_rect = to_gl_texture(texture.blit_data()); | 88 | const Rectf texture_rect = to_gl_texture(texture.blit_data()); |
2357 | 86 | 89 | ||
2358 | 87 | vertices_.emplace_back(PerVertexData{ | 90 | vertices_.emplace_back(PerVertexData{ |
2361 | 88 | start.pixel_x - road_overshoot_x + road_thickness_x, | 91 | start.surface_pixel.x - road_overshoot_x + road_thickness_x, |
2362 | 89 | start.pixel_y - road_overshoot_y + road_thickness_y, texture_rect.x, texture_rect.y, | 92 | start.surface_pixel.y - road_overshoot_y + road_thickness_y, texture_rect.x, texture_rect.y, |
2363 | 90 | start.brightness, | 93 | start.brightness, |
2364 | 91 | }); | 94 | }); |
2365 | 92 | pixel_to_gl_renderbuffer( | 95 | pixel_to_gl_renderbuffer( |
2366 | 93 | renderbuffer_width, renderbuffer_height, &vertices_.back().gl_x, &vertices_.back().gl_y); | 96 | renderbuffer_width, renderbuffer_height, &vertices_.back().gl_x, &vertices_.back().gl_y); |
2367 | 94 | 97 | ||
2368 | 95 | vertices_.emplace_back(PerVertexData{ | 98 | vertices_.emplace_back(PerVertexData{ |
2371 | 96 | start.pixel_x - road_overshoot_x - road_thickness_x, | 99 | start.surface_pixel.x - road_overshoot_x - road_thickness_x, |
2372 | 97 | start.pixel_y - road_overshoot_y - road_thickness_y, texture_rect.x, | 100 | start.surface_pixel.y - road_overshoot_y - road_thickness_y, texture_rect.x, |
2373 | 98 | texture_rect.y + texture_rect.h, start.brightness, | 101 | texture_rect.y + texture_rect.h, start.brightness, |
2374 | 99 | }); | 102 | }); |
2375 | 100 | pixel_to_gl_renderbuffer( | 103 | pixel_to_gl_renderbuffer( |
2376 | 101 | renderbuffer_width, renderbuffer_height, &vertices_.back().gl_x, &vertices_.back().gl_y); | 104 | renderbuffer_width, renderbuffer_height, &vertices_.back().gl_x, &vertices_.back().gl_y); |
2377 | 102 | 105 | ||
2378 | 103 | vertices_.emplace_back(PerVertexData{ | 106 | vertices_.emplace_back(PerVertexData{ |
2381 | 104 | end.pixel_x + road_overshoot_x + road_thickness_x, | 107 | end.surface_pixel.x + road_overshoot_x + road_thickness_x, |
2382 | 105 | end.pixel_y + road_overshoot_y + road_thickness_y, texture_rect.x + texture_rect.w, | 108 | end.surface_pixel.y + road_overshoot_y + road_thickness_y, texture_rect.x + texture_rect.w, |
2383 | 106 | texture_rect.y, end.brightness, | 109 | texture_rect.y, end.brightness, |
2384 | 107 | }); | 110 | }); |
2385 | 108 | pixel_to_gl_renderbuffer( | 111 | pixel_to_gl_renderbuffer( |
2386 | @@ -116,8 +119,8 @@ | |||
2387 | 116 | vertices_.emplace_back(vertices_.at(vertices_.size() - 2)); | 119 | vertices_.emplace_back(vertices_.at(vertices_.size() - 2)); |
2388 | 117 | 120 | ||
2389 | 118 | vertices_.emplace_back(PerVertexData{ | 121 | vertices_.emplace_back(PerVertexData{ |
2392 | 119 | end.pixel_x + road_overshoot_x - road_thickness_x, | 122 | end.surface_pixel.x + road_overshoot_x - road_thickness_x, |
2393 | 120 | end.pixel_y + road_overshoot_y - road_thickness_y, texture_rect.x + texture_rect.w, | 123 | end.surface_pixel.y + road_overshoot_y - road_thickness_y, texture_rect.x + texture_rect.w, |
2394 | 121 | texture_rect.y + texture_rect.h, end.brightness, | 124 | texture_rect.y + texture_rect.h, end.brightness, |
2395 | 122 | }); | 125 | }); |
2396 | 123 | pixel_to_gl_renderbuffer( | 126 | pixel_to_gl_renderbuffer( |
2397 | @@ -127,7 +130,8 @@ | |||
2398 | 127 | void RoadProgram::draw(const int renderbuffer_width, | 130 | void RoadProgram::draw(const int renderbuffer_width, |
2399 | 128 | const int renderbuffer_height, | 131 | const int renderbuffer_height, |
2400 | 129 | const FieldsToDraw& fields_to_draw, | 132 | const FieldsToDraw& fields_to_draw, |
2402 | 130 | float z_value) { | 133 | const float scale, |
2403 | 134 | const float z_value) { | ||
2404 | 131 | vertices_.clear(); | 135 | vertices_.clear(); |
2405 | 132 | 136 | ||
2406 | 133 | uint32_t gl_texture = 0; | 137 | uint32_t gl_texture = 0; |
2407 | @@ -135,36 +139,32 @@ | |||
2408 | 135 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); | 139 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); |
2409 | 136 | 140 | ||
2410 | 137 | // Road to right neighbor. | 141 | // Road to right neighbor. |
2413 | 138 | const int rn_index = fields_to_draw.calculate_index(field.fx + 1, field.fy); | 142 | if (field.rn_index != FieldsToDraw::kInvalidIndex) { |
2412 | 139 | if (rn_index != -1) { | ||
2414 | 140 | const Widelands::RoadType road = | 143 | const Widelands::RoadType road = |
2415 | 141 | static_cast<Widelands::RoadType>(field.roads & Widelands::RoadType::kMask); | 144 | static_cast<Widelands::RoadType>(field.roads & Widelands::RoadType::kMask); |
2416 | 142 | if (road != Widelands::RoadType::kNone) { | 145 | if (road != Widelands::RoadType::kNone) { |
2419 | 143 | add_road(renderbuffer_width, renderbuffer_height, field, fields_to_draw.at(rn_index), | 146 | add_road(renderbuffer_width, renderbuffer_height, field, |
2420 | 144 | road, kEast, &gl_texture); | 147 | fields_to_draw.at(field.rn_index), scale, road, kEast, &gl_texture); |
2421 | 145 | } | 148 | } |
2422 | 146 | } | 149 | } |
2423 | 147 | 150 | ||
2424 | 148 | // Road to bottom right neighbor. | 151 | // Road to bottom right neighbor. |
2427 | 149 | const int brn_index = fields_to_draw.calculate_index(field.fx + (field.fy & 1), field.fy + 1); | 152 | if (field.brn_index != FieldsToDraw::kInvalidIndex) { |
2426 | 150 | if (brn_index != -1) { | ||
2428 | 151 | const Widelands::RoadType road = | 153 | const Widelands::RoadType road = |
2429 | 152 | static_cast<Widelands::RoadType>((field.roads >> 2) & Widelands::RoadType::kMask); | 154 | static_cast<Widelands::RoadType>((field.roads >> 2) & Widelands::RoadType::kMask); |
2430 | 153 | if (road != Widelands::RoadType::kNone) { | 155 | if (road != Widelands::RoadType::kNone) { |
2433 | 154 | add_road(renderbuffer_width, renderbuffer_height, field, fields_to_draw.at(brn_index), | 156 | add_road(renderbuffer_width, renderbuffer_height, field, |
2434 | 155 | road, kSouthEast, &gl_texture); | 157 | fields_to_draw.at(field.brn_index), scale, road, kSouthEast, &gl_texture); |
2435 | 156 | } | 158 | } |
2436 | 157 | } | 159 | } |
2437 | 158 | 160 | ||
2438 | 159 | // Road to bottom right neighbor. | 161 | // Road to bottom right neighbor. |
2442 | 160 | const int bln_index = | 162 | if (field.bln_index != FieldsToDraw::kInvalidIndex) { |
2440 | 161 | fields_to_draw.calculate_index(field.fx + (field.fy & 1) - 1, field.fy + 1); | ||
2441 | 162 | if (bln_index != -1) { | ||
2443 | 163 | const Widelands::RoadType road = | 163 | const Widelands::RoadType road = |
2444 | 164 | static_cast<Widelands::RoadType>((field.roads >> 4) & Widelands::RoadType::kMask); | 164 | static_cast<Widelands::RoadType>((field.roads >> 4) & Widelands::RoadType::kMask); |
2445 | 165 | if (road != Widelands::RoadType::kNone) { | 165 | if (road != Widelands::RoadType::kNone) { |
2448 | 166 | add_road(renderbuffer_width, renderbuffer_height, field, fields_to_draw.at(bln_index), | 166 | add_road(renderbuffer_width, renderbuffer_height, field, |
2449 | 167 | road, kSouthWest, &gl_texture); | 167 | fields_to_draw.at(field.bln_index), scale, road, kSouthWest, &gl_texture); |
2450 | 168 | } | 168 | } |
2451 | 169 | } | 169 | } |
2452 | 170 | } | 170 | } |
2453 | 171 | 171 | ||
2454 | === modified file 'src/graphic/gl/road_program.h' | |||
2455 | --- src/graphic/gl/road_program.h 2016-08-04 15:49:05 +0000 | |||
2456 | +++ src/graphic/gl/road_program.h 2016-10-24 20:07:47 +0000 | |||
2457 | @@ -42,6 +42,7 @@ | |||
2458 | 42 | void draw(int renderbuffer_width, | 42 | void draw(int renderbuffer_width, |
2459 | 43 | int renderbuffer_height, | 43 | int renderbuffer_height, |
2460 | 44 | const FieldsToDraw& fields_to_draw, | 44 | const FieldsToDraw& fields_to_draw, |
2461 | 45 | float scale, | ||
2462 | 45 | float z_value); | 46 | float z_value); |
2463 | 46 | 47 | ||
2464 | 47 | private: | 48 | private: |
2465 | @@ -61,6 +62,7 @@ | |||
2466 | 61 | int renderbuffer_height, | 62 | int renderbuffer_height, |
2467 | 62 | const FieldsToDraw::Field& start, | 63 | const FieldsToDraw::Field& start, |
2468 | 63 | const FieldsToDraw::Field& end, | 64 | const FieldsToDraw::Field& end, |
2469 | 65 | float scale, | ||
2470 | 64 | const Widelands::RoadType road_type, | 66 | const Widelands::RoadType road_type, |
2471 | 65 | const Direction direction, | 67 | const Direction direction, |
2472 | 66 | uint32_t* gl_texture); | 68 | uint32_t* gl_texture); |
2473 | 67 | 69 | ||
2474 | === modified file 'src/graphic/gl/terrain_program.cc' | |||
2475 | --- src/graphic/gl/terrain_program.cc 2016-08-04 15:49:05 +0000 | |||
2476 | +++ src/graphic/gl/terrain_program.cc 2016-10-24 20:07:47 +0000 | |||
2477 | @@ -71,15 +71,15 @@ | |||
2478 | 71 | } | 71 | } |
2479 | 72 | 72 | ||
2480 | 73 | void TerrainProgram::add_vertex(const FieldsToDraw::Field& field, | 73 | void TerrainProgram::add_vertex(const FieldsToDraw::Field& field, |
2482 | 74 | const FloatPoint& texture_offset) { | 74 | const Vector2f& texture_offset) { |
2483 | 75 | vertices_.emplace_back(); | 75 | vertices_.emplace_back(); |
2484 | 76 | PerVertexData& back = vertices_.back(); | 76 | PerVertexData& back = vertices_.back(); |
2485 | 77 | 77 | ||
2488 | 78 | back.gl_x = field.gl_x; | 78 | back.gl_x = field.gl_position.x; |
2489 | 79 | back.gl_y = field.gl_y; | 79 | back.gl_y = field.gl_position.y; |
2490 | 80 | back.brightness = field.brightness; | 80 | back.brightness = field.brightness; |
2493 | 81 | back.texture_x = field.texture_x; | 81 | back.texture_x = field.texture_coords.x; |
2494 | 82 | back.texture_y = field.texture_y; | 82 | back.texture_y = field.texture_coords.y; |
2495 | 83 | back.texture_offset_x = texture_offset.x; | 83 | back.texture_offset_x = texture_offset.x; |
2496 | 84 | back.texture_offset_y = texture_offset.y; | 84 | back.texture_offset_y = texture_offset.y; |
2497 | 85 | } | 85 | } |
2498 | @@ -101,34 +101,34 @@ | |||
2499 | 101 | // The bottom right neighbor fields_to_draw is needed for both triangles | 101 | // The bottom right neighbor fields_to_draw is needed for both triangles |
2500 | 102 | // associated with this field. If it is not in fields_to_draw, there is no need to | 102 | // associated with this field. If it is not in fields_to_draw, there is no need to |
2501 | 103 | // draw any triangles. | 103 | // draw any triangles. |
2504 | 104 | const int brn_index = fields_to_draw.calculate_index(field.fx + (field.fy & 1), field.fy + 1); | 104 | if (field.brn_index == FieldsToDraw::kInvalidIndex) { |
2503 | 105 | if (brn_index == -1) { | ||
2505 | 106 | continue; | 105 | continue; |
2506 | 107 | } | 106 | } |
2507 | 108 | 107 | ||
2508 | 109 | // Down triangle. | 108 | // Down triangle. |
2514 | 110 | const int bln_index = | 109 | if (field.bln_index != FieldsToDraw::kInvalidIndex) { |
2515 | 111 | fields_to_draw.calculate_index(field.fx + (field.fy & 1) - 1, field.fy + 1); | 110 | const Vector2f texture_offset = |
2516 | 112 | if (bln_index != -1) { | 111 | to_gl_texture( |
2517 | 113 | const FloatPoint texture_offset = | 112 | terrains.get(field.fcoords.field->terrain_d()).get_texture(gametime).blit_data()) |
2518 | 114 | to_gl_texture(terrains.get(field.ter_d).get_texture(gametime).blit_data()).origin(); | 113 | .origin(); |
2519 | 115 | add_vertex(fields_to_draw.at(current_index), texture_offset); | 114 | add_vertex(fields_to_draw.at(current_index), texture_offset); |
2522 | 116 | add_vertex(fields_to_draw.at(bln_index), texture_offset); | 115 | add_vertex(fields_to_draw.at(field.bln_index), texture_offset); |
2523 | 117 | add_vertex(fields_to_draw.at(brn_index), texture_offset); | 116 | add_vertex(fields_to_draw.at(field.brn_index), texture_offset); |
2524 | 118 | } | 117 | } |
2525 | 119 | 118 | ||
2526 | 120 | // Right triangle. | 119 | // Right triangle. |
2531 | 121 | const int rn_index = fields_to_draw.calculate_index(field.fx + 1, field.fy); | 120 | if (field.rn_index != FieldsToDraw::kInvalidIndex) { |
2532 | 122 | if (rn_index != -1) { | 121 | const Vector2f texture_offset = |
2533 | 123 | const FloatPoint texture_offset = | 122 | to_gl_texture( |
2534 | 124 | to_gl_texture(terrains.get(field.ter_r).get_texture(gametime).blit_data()).origin(); | 123 | terrains.get(field.fcoords.field->terrain_r()).get_texture(gametime).blit_data()) |
2535 | 124 | .origin(); | ||
2536 | 125 | add_vertex(fields_to_draw.at(current_index), texture_offset); | 125 | add_vertex(fields_to_draw.at(current_index), texture_offset); |
2539 | 126 | add_vertex(fields_to_draw.at(brn_index), texture_offset); | 126 | add_vertex(fields_to_draw.at(field.brn_index), texture_offset); |
2540 | 127 | add_vertex(fields_to_draw.at(rn_index), texture_offset); | 127 | add_vertex(fields_to_draw.at(field.rn_index), texture_offset); |
2541 | 128 | } | 128 | } |
2542 | 129 | } | 129 | } |
2543 | 130 | 130 | ||
2544 | 131 | const BlitData& blit_data = terrains.get(0).get_texture(0).blit_data(); | 131 | const BlitData& blit_data = terrains.get(0).get_texture(0).blit_data(); |
2546 | 132 | const FloatRect texture_coordinates = to_gl_texture(blit_data); | 132 | const Rectf texture_coordinates = to_gl_texture(blit_data); |
2547 | 133 | gl_draw(blit_data.texture_id, texture_coordinates.w, texture_coordinates.h, z_value); | 133 | gl_draw(blit_data.texture_id, texture_coordinates.w, texture_coordinates.h, z_value); |
2548 | 134 | } | 134 | } |
2549 | 135 | 135 | ||
2550 | === modified file 'src/graphic/gl/terrain_program.h' | |||
2551 | --- src/graphic/gl/terrain_program.h 2016-08-04 15:49:05 +0000 | |||
2552 | +++ src/graphic/gl/terrain_program.h 2016-10-24 20:07:47 +0000 | |||
2553 | @@ -22,7 +22,7 @@ | |||
2554 | 22 | 22 | ||
2555 | 23 | #include <vector> | 23 | #include <vector> |
2556 | 24 | 24 | ||
2558 | 25 | #include "base/point.h" | 25 | #include "base/vector.h" |
2559 | 26 | #include "graphic/gl/fields_to_draw.h" | 26 | #include "graphic/gl/fields_to_draw.h" |
2560 | 27 | #include "graphic/gl/utils.h" | 27 | #include "graphic/gl/utils.h" |
2561 | 28 | #include "logic/description_maintainer.h" | 28 | #include "logic/description_maintainer.h" |
2562 | @@ -54,7 +54,7 @@ | |||
2563 | 54 | void gl_draw(int gl_texture, float texture_w, float texture_h, float z_value); | 54 | void gl_draw(int gl_texture, float texture_w, float texture_h, float z_value); |
2564 | 55 | 55 | ||
2565 | 56 | // Adds a vertex to the end of vertices with data from 'field' and 'texture_coordinates'. | 56 | // Adds a vertex to the end of vertices with data from 'field' and 'texture_coordinates'. |
2567 | 57 | void add_vertex(const FieldsToDraw::Field& field, const FloatPoint& texture_coordinates); | 57 | void add_vertex(const FieldsToDraw::Field& field, const Vector2f& texture_coordinates); |
2568 | 58 | 58 | ||
2569 | 59 | // The program used for drawing the terrain. | 59 | // The program used for drawing the terrain. |
2570 | 60 | Gl::Program gl_program_; | 60 | Gl::Program gl_program_; |
2571 | 61 | 61 | ||
2572 | === modified file 'src/graphic/minimap_renderer.cc' | |||
2573 | --- src/graphic/minimap_renderer.cc 2016-08-04 15:49:05 +0000 | |||
2574 | +++ src/graphic/minimap_renderer.cc 2016-10-24 20:07:47 +0000 | |||
2575 | @@ -25,13 +25,9 @@ | |||
2576 | 25 | #include "economy/flag.h" | 25 | #include "economy/flag.h" |
2577 | 26 | #include "economy/road.h" | 26 | #include "economy/road.h" |
2578 | 27 | #include "graphic/graphic.h" | 27 | #include "graphic/graphic.h" |
2579 | 28 | #include "graphic/image_io.h" | ||
2580 | 29 | #include "graphic/texture.h" | ||
2581 | 30 | #include "logic/field.h" | 28 | #include "logic/field.h" |
2582 | 31 | #include "logic/map.h" | ||
2583 | 32 | #include "logic/map_objects/world/terrain_description.h" | 29 | #include "logic/map_objects/world/terrain_description.h" |
2584 | 33 | #include "logic/map_objects/world/world.h" | 30 | #include "logic/map_objects/world/world.h" |
2585 | 34 | #include "logic/player.h" | ||
2586 | 35 | #include "wui/mapviewpixelconstants.h" | 31 | #include "wui/mapviewpixelconstants.h" |
2587 | 36 | #include "wui/mapviewpixelfunctions.h" | 32 | #include "wui/mapviewpixelfunctions.h" |
2588 | 37 | 33 | ||
2589 | @@ -40,12 +36,17 @@ | |||
2590 | 40 | namespace { | 36 | namespace { |
2591 | 41 | 37 | ||
2592 | 42 | const RGBColor kWhite(255, 255, 255); | 38 | const RGBColor kWhite(255, 255, 255); |
2593 | 39 | const RGBColor kRed(255, 0, 0); | ||
2594 | 43 | 40 | ||
2595 | 44 | // Blend two colors. | 41 | // Blend two colors. |
2596 | 45 | inline RGBColor blend_color(const RGBColor& c1, const RGBColor& c2) { | 42 | inline RGBColor blend_color(const RGBColor& c1, const RGBColor& c2) { |
2597 | 46 | return RGBColor((c1.r + c2.r) / 2, (c1.g + c2.g) / 2, (c1.b + c2.b) / 2); | 43 | return RGBColor((c1.r + c2.r) / 2, (c1.g + c2.g) / 2, (c1.b + c2.b) / 2); |
2598 | 47 | } | 44 | } |
2599 | 48 | 45 | ||
2600 | 46 | int round_up_to_nearest_even(int number) { | ||
2601 | 47 | return number % 2 == 0 ? number : number + 1; | ||
2602 | 48 | } | ||
2603 | 49 | |||
2604 | 49 | // Returns the color to be used in the minimap for the given field. | 50 | // Returns the color to be used in the minimap for the given field. |
2605 | 50 | inline RGBColor calc_minimap_color(const Widelands::EditorGameBase& egbase, | 51 | inline RGBColor calc_minimap_color(const Widelands::EditorGameBase& egbase, |
2606 | 51 | const Widelands::FCoords& f, | 52 | const Widelands::FCoords& f, |
2607 | @@ -85,83 +86,83 @@ | |||
2608 | 85 | return color; | 86 | return color; |
2609 | 86 | } | 87 | } |
2610 | 87 | 88 | ||
2642 | 88 | // Draws the dotted frame border onto the minimap. | 89 | void draw_view_window(const Map& map, |
2643 | 89 | bool is_minimap_frameborder(const Widelands::FCoords& f, | 90 | const Rectf& view_area, |
2644 | 90 | const Point& ptopleft, | 91 | const MiniMapType minimap_type, |
2645 | 91 | const Point& pbottomright, | 92 | const bool zoom, |
2646 | 92 | int32_t mapwidth, | 93 | Texture* texture) { |
2647 | 93 | int32_t mapheight, | 94 | const float divider = zoom ? 1.f : 2.f; |
2648 | 94 | int32_t modx, | 95 | const int half_width = |
2649 | 95 | int32_t mody) { | 96 | round_up_to_nearest_even(std::ceil(view_area.w / kTriangleWidth / divider)); |
2650 | 96 | bool isframepixel = false; | 97 | const int half_height = |
2651 | 97 | 98 | round_up_to_nearest_even(std::ceil(view_area.h / kTriangleHeight / divider)); | |
2652 | 98 | if (ptopleft.x <= pbottomright.x) { | 99 | |
2653 | 99 | if (f.x >= ptopleft.x && f.x <= pbottomright.x && | 100 | Vector2i center_pixel; |
2654 | 100 | (f.y == ptopleft.y || f.y == pbottomright.y) && f.x % 2 == modx) | 101 | switch (minimap_type) { |
2655 | 101 | isframepixel = true; | 102 | case MiniMapType::kStaticViewWindow: |
2656 | 102 | } else { | 103 | center_pixel = Vector2i(texture->width() / 2, texture->height() / 2); |
2657 | 103 | if (((f.x >= ptopleft.x && f.x <= mapwidth) || (f.x >= 0 && f.x <= pbottomright.x)) && | 104 | break; |
2658 | 104 | (f.y == ptopleft.y || f.y == pbottomright.y) && (f.x % 2) == modx) | 105 | |
2659 | 105 | isframepixel = true; | 106 | case MiniMapType::kStaticMap: { |
2660 | 106 | } | 107 | Vector2f origin = view_area.center(); |
2661 | 107 | 108 | MapviewPixelFunctions::normalize_pix(map, &origin); | |
2662 | 108 | if (ptopleft.y <= pbottomright.y) { | 109 | center_pixel = |
2663 | 109 | if (f.y >= ptopleft.y && f.y <= pbottomright.y && | 110 | Vector2i(origin.x / kTriangleWidth, origin.y / kTriangleHeight) * (zoom ? 2 : 1); |
2664 | 110 | (f.x == ptopleft.x || f.x == pbottomright.x) && f.y % 2 == mody) | 111 | break; |
2665 | 111 | isframepixel = true; | 112 | } |
2666 | 112 | } else { | 113 | } |
2667 | 113 | if (((f.y >= ptopleft.y && f.y <= mapheight) || (f.y >= 0 && f.y <= pbottomright.y)) && | 114 | |
2668 | 114 | (f.x == ptopleft.x || f.x == pbottomright.x) && f.y % 2 == mody) | 115 | const int width = zoom ? map.get_width() * 2 : map.get_width(); |
2669 | 115 | isframepixel = true; | 116 | const int height = zoom ? map.get_height() * 2 : map.get_height(); |
2670 | 116 | } | 117 | const auto make_red = [width, height, &texture](int x, int y) { |
2671 | 117 | 118 | if (x < 0) { | |
2672 | 118 | return isframepixel; | 119 | x += width; |
2673 | 120 | } | ||
2674 | 121 | if (x >= width) { | ||
2675 | 122 | x -= width; | ||
2676 | 123 | } | ||
2677 | 124 | if (y < 0) { | ||
2678 | 125 | y += height; | ||
2679 | 126 | } | ||
2680 | 127 | if (y >= height) { | ||
2681 | 128 | y -= height; | ||
2682 | 129 | } | ||
2683 | 130 | texture->set_pixel(x, y, kRed); | ||
2684 | 131 | }; | ||
2685 | 132 | |||
2686 | 133 | bool draw = true; | ||
2687 | 134 | for (int y = -half_height; y <= half_height; ++y) { | ||
2688 | 135 | if (draw) { | ||
2689 | 136 | make_red(-half_width + center_pixel.x, y + center_pixel.y); | ||
2690 | 137 | make_red(half_width + center_pixel.x, y + center_pixel.y); | ||
2691 | 138 | } | ||
2692 | 139 | draw = !draw; | ||
2693 | 140 | } | ||
2694 | 141 | |||
2695 | 142 | draw = true; | ||
2696 | 143 | for (int x = -half_width; x <= half_width; ++x) { | ||
2697 | 144 | if (draw) { | ||
2698 | 145 | make_red(x + center_pixel.x, -half_height + center_pixel.y); | ||
2699 | 146 | make_red(x + center_pixel.x, half_height + center_pixel.y); | ||
2700 | 147 | } | ||
2701 | 148 | draw = !draw; | ||
2702 | 149 | } | ||
2703 | 119 | } | 150 | } |
2704 | 120 | 151 | ||
2705 | 121 | // Does the actual work of drawing the minimap. | 152 | // Does the actual work of drawing the minimap. |
2711 | 122 | void draw_minimap_int(Texture* texture, | 153 | void do_draw_minimap(Texture* texture, |
2712 | 123 | const Widelands::EditorGameBase& egbase, | 154 | const Widelands::EditorGameBase& egbase, |
2713 | 124 | const Widelands::Player* player, | 155 | const Widelands::Player* player, |
2714 | 125 | const Point& viewpoint, | 156 | const Vector2i& top_left, |
2715 | 126 | MiniMapLayer layers) { | 157 | MiniMapLayer layers) { |
2716 | 127 | const Widelands::Map& map = egbase.map(); | 158 | const Widelands::Map& map = egbase.map(); |
2717 | 128 | |||
2718 | 129 | const uint16_t surface_h = texture->height(); | 159 | const uint16_t surface_h = texture->height(); |
2719 | 130 | const uint16_t surface_w = texture->width(); | 160 | const uint16_t surface_w = texture->width(); |
2720 | 131 | |||
2721 | 132 | // size of the display frame | ||
2722 | 133 | int32_t xsize = g_gr->get_xres() / kTriangleWidth / 2; | ||
2723 | 134 | int32_t ysize = g_gr->get_yres() / kTriangleHeight / 2; | ||
2724 | 135 | |||
2725 | 136 | const int32_t mapwidth = egbase.get_map().get_width(); | 161 | const int32_t mapwidth = egbase.get_map().get_width(); |
2726 | 137 | const int32_t mapheight = map.get_height(); | ||
2727 | 138 | |||
2728 | 139 | Point ptopleft; // top left point of the current display frame | ||
2729 | 140 | ptopleft.x = viewpoint.x + mapwidth / 2 - xsize; | ||
2730 | 141 | if (ptopleft.x < 0) { | ||
2731 | 142 | ptopleft.x += mapwidth; | ||
2732 | 143 | } | ||
2733 | 144 | ptopleft.y = viewpoint.y + mapheight / 2 - ysize; | ||
2734 | 145 | if (ptopleft.y < 0) { | ||
2735 | 146 | ptopleft.y += mapheight; | ||
2736 | 147 | } | ||
2737 | 148 | |||
2738 | 149 | Point pbottomright; // bottom right point of the current display frame | ||
2739 | 150 | pbottomright.x = viewpoint.x + mapwidth / 2 + xsize; | ||
2740 | 151 | if (pbottomright.x >= mapwidth) { | ||
2741 | 152 | pbottomright.x -= mapwidth; | ||
2742 | 153 | } | ||
2743 | 154 | pbottomright.y = viewpoint.y + mapheight / 2 + ysize; | ||
2744 | 155 | if (pbottomright.y >= mapheight) { | ||
2745 | 156 | pbottomright.y -= mapheight; | ||
2746 | 157 | } | ||
2747 | 158 | |||
2748 | 159 | uint32_t modx = pbottomright.x % 2; | ||
2749 | 160 | uint32_t mody = pbottomright.y % 2; | ||
2750 | 161 | 162 | ||
2751 | 162 | for (uint32_t y = 0; y < surface_h; ++y) { | 163 | for (uint32_t y = 0; y < surface_h; ++y) { |
2752 | 163 | Widelands::FCoords f( | 164 | Widelands::FCoords f( |
2754 | 164 | Widelands::Coords(viewpoint.x, viewpoint.y + (layers & MiniMapLayer::Zoom2 ? y / 2 : y))); | 165 | Widelands::Coords(top_left.x, top_left.y + (layers & MiniMapLayer::Zoom2 ? y / 2 : y))); |
2755 | 165 | map.normalize_coords(f); | 166 | map.normalize_coords(f); |
2756 | 166 | f.field = &map[f]; | 167 | f.field = &map[f]; |
2757 | 167 | Widelands::MapIndex i = Widelands::Map::get_index(f, mapwidth); | 168 | Widelands::MapIndex i = Widelands::Map::get_index(f, mapwidth); |
2758 | @@ -170,30 +171,26 @@ | |||
2759 | 170 | move_r(mapwidth, f, i); | 171 | move_r(mapwidth, f, i); |
2760 | 171 | } | 172 | } |
2761 | 172 | 173 | ||
2782 | 173 | RGBColor pixel_color; | 174 | uint16_t vision = 0; // See Player::Field::Vision: 1 if seen once, > 1 if seen right now. |
2783 | 174 | if ((layers & MiniMapLayer::ViewWindow) && | 175 | Widelands::PlayerNumber owner = 0; |
2784 | 175 | is_minimap_frameborder(f, ptopleft, pbottomright, mapwidth, mapheight, modx, mody)) { | 176 | if (player == nullptr || player->see_all()) { |
2785 | 176 | pixel_color = RGBColor(255, 0, 0); | 177 | // This player has omnivision - show the field like it is in reality. |
2786 | 177 | } else { | 178 | vision = 2; // Seen right now. |
2787 | 178 | uint16_t vision = | 179 | owner = f.field->get_owned_by(); |
2788 | 179 | 0; // See Player::Field::Vision: 1 if seen once, > 1 if seen right now. | 180 | } else if (player != nullptr) { |
2789 | 180 | Widelands::PlayerNumber owner = 0; | 181 | // This player might be affected by fog of war - instead of the |
2790 | 181 | if (player == nullptr || player->see_all()) { | 182 | // reality, we show her what she last saw on this field. If she has |
2791 | 182 | vision = 2; // Seen right now. | 183 | // vision of this field, this will be the same as reality - |
2792 | 183 | owner = f.field->get_owned_by(); | 184 | // otherwise this shows reality as it was the last time she had |
2793 | 184 | } else if (player != nullptr) { | 185 | // vision on the field. |
2794 | 185 | const auto& field = player->fields()[i]; | 186 | // If she never had vision, field.vision will be 0. |
2795 | 186 | vision = field.vision; | 187 | const auto& field = player->fields()[i]; |
2796 | 187 | owner = field.owner; | 188 | vision = field.vision; |
2797 | 188 | } | 189 | owner = field.owner; |
2778 | 189 | |||
2779 | 190 | if (vision > 0) { | ||
2780 | 191 | pixel_color = calc_minimap_color(egbase, f, layers, owner, vision > 1); | ||
2781 | 192 | } | ||
2798 | 193 | } | 190 | } |
2799 | 194 | 191 | ||
2802 | 195 | if (pixel_color.r != 0 || pixel_color.g != 0 || pixel_color.b != 0) { | 192 | if (vision > 0) { |
2803 | 196 | texture->set_pixel(x, y, pixel_color); | 193 | texture->set_pixel(x, y, calc_minimap_color(egbase, f, layers, owner, vision > 1)); |
2804 | 197 | } | 194 | } |
2805 | 198 | } | 195 | } |
2806 | 199 | } | 196 | } |
2807 | @@ -201,12 +198,38 @@ | |||
2808 | 201 | 198 | ||
2809 | 202 | } // namespace | 199 | } // namespace |
2810 | 203 | 200 | ||
2811 | 201 | Vector2f minimap_pixel_to_mappixel(const Widelands::Map& map, | ||
2812 | 202 | const Vector2i& minimap_pixel, | ||
2813 | 203 | const Rectf& view_area, | ||
2814 | 204 | MiniMapType minimap_type, | ||
2815 | 205 | const bool zoom) { | ||
2816 | 206 | Vector2f top_left; | ||
2817 | 207 | switch (minimap_type) { | ||
2818 | 208 | case MiniMapType::kStaticViewWindow: | ||
2819 | 209 | top_left = | ||
2820 | 210 | view_area.center() - | ||
2821 | 211 | Vector2f(map.get_width() * kTriangleWidth, map.get_height() * kTriangleHeight) / 2.f; | ||
2822 | 212 | break; | ||
2823 | 213 | |||
2824 | 214 | case MiniMapType::kStaticMap: | ||
2825 | 215 | top_left = Vector2f(0., 0.); | ||
2826 | 216 | break; | ||
2827 | 217 | } | ||
2828 | 218 | |||
2829 | 219 | const float multiplier = zoom ? 2.f : 1.f; | ||
2830 | 220 | Vector2f map_pixel = top_left + Vector2f(minimap_pixel.x / multiplier * kTriangleWidth, | ||
2831 | 221 | minimap_pixel.y / multiplier * kTriangleHeight); | ||
2832 | 222 | MapviewPixelFunctions::normalize_pix(map, &map_pixel); | ||
2833 | 223 | return map_pixel; | ||
2834 | 224 | } | ||
2835 | 225 | |||
2836 | 204 | std::unique_ptr<Texture> draw_minimap(const EditorGameBase& egbase, | 226 | std::unique_ptr<Texture> draw_minimap(const EditorGameBase& egbase, |
2837 | 205 | const Player* player, | 227 | const Player* player, |
2839 | 206 | const Point& viewpoint, | 228 | const Rectf& view_area, |
2840 | 229 | const MiniMapType& minimap_type, | ||
2841 | 207 | MiniMapLayer layers) { | 230 | MiniMapLayer layers) { |
2844 | 208 | // TODO(unknown): Currently the minimap is redrawn every frame. That is not really | 231 | // TODO(sirver): Currently the minimap is redrawn every frame. That is not really |
2845 | 209 | // necesary. The created texture could be cached and only redrawn two | 232 | // necessary. The created texture could be cached and only redrawn two |
2846 | 210 | // or three times per second | 233 | // or three times per second |
2847 | 211 | const Map& map = egbase.map(); | 234 | const Map& map = egbase.map(); |
2848 | 212 | const int16_t map_w = (layers & MiniMapLayer::Zoom2) ? map.get_width() * 2 : map.get_width(); | 235 | const int16_t map_w = (layers & MiniMapLayer::Zoom2) ? map.get_width() * 2 : map.get_width(); |
2849 | @@ -214,44 +237,22 @@ | |||
2850 | 214 | 237 | ||
2851 | 215 | std::unique_ptr<Texture> texture(new Texture(map_w, map_h)); | 238 | std::unique_ptr<Texture> texture(new Texture(map_w, map_h)); |
2852 | 216 | 239 | ||
2854 | 217 | texture->fill_rect(Rect(0, 0, texture->width(), texture->height()), RGBAColor(0, 0, 0, 255)); | 240 | texture->fill_rect(Rectf(0, 0, texture->width(), texture->height()), RGBAColor(0, 0, 0, 255)); |
2855 | 241 | |||
2856 | 242 | // Center the view on the middle of the 'view_area'. | ||
2857 | 243 | const bool zoom = layers & MiniMapLayer::Zoom2; | ||
2858 | 244 | Vector2f top_left = | ||
2859 | 245 | minimap_pixel_to_mappixel(map, Vector2i(0, 0), view_area, minimap_type, zoom); | ||
2860 | 246 | const Coords node = | ||
2861 | 247 | MapviewPixelFunctions::calc_node_and_triangle(map, top_left.x, top_left.y).node; | ||
2862 | 218 | 248 | ||
2863 | 219 | texture->lock(); | 249 | texture->lock(); |
2865 | 220 | draw_minimap_int(texture.get(), egbase, player, viewpoint, layers); | 250 | do_draw_minimap(texture.get(), egbase, player, Vector2i(node.x, node.y), layers); |
2866 | 251 | |||
2867 | 252 | if (layers & MiniMapLayer::ViewWindow) { | ||
2868 | 253 | draw_view_window(map, view_area, minimap_type, zoom, texture.get()); | ||
2869 | 254 | } | ||
2870 | 221 | texture->unlock(Texture::Unlock_Update); | 255 | texture->unlock(Texture::Unlock_Update); |
2871 | 222 | 256 | ||
2872 | 223 | return texture; | 257 | return texture; |
2873 | 224 | } | 258 | } |
2874 | 225 | |||
2875 | 226 | void write_minimap_image(const EditorGameBase& egbase, | ||
2876 | 227 | const Player* player, | ||
2877 | 228 | const Point& gviewpoint, | ||
2878 | 229 | MiniMapLayer layers, | ||
2879 | 230 | ::StreamWrite* const streamwrite) { | ||
2880 | 231 | assert(streamwrite != nullptr); | ||
2881 | 232 | |||
2882 | 233 | Point viewpoint(gviewpoint); | ||
2883 | 234 | |||
2884 | 235 | // map dimension | ||
2885 | 236 | const int16_t map_w = egbase.get_map().get_width(); | ||
2886 | 237 | const int16_t map_h = egbase.get_map().get_height(); | ||
2887 | 238 | const int32_t maxx = MapviewPixelFunctions::get_map_end_screen_x(egbase.get_map()); | ||
2888 | 239 | const int32_t maxy = MapviewPixelFunctions::get_map_end_screen_y(egbase.get_map()); | ||
2889 | 240 | // adjust the viewpoint top topleft in map coords | ||
2890 | 241 | viewpoint.x += g_gr->get_xres() / 2; | ||
2891 | 242 | if (viewpoint.x >= maxx) { | ||
2892 | 243 | viewpoint.x -= maxx; | ||
2893 | 244 | } | ||
2894 | 245 | viewpoint.y += g_gr->get_yres() / 2; | ||
2895 | 246 | if (viewpoint.y >= maxy) { | ||
2896 | 247 | viewpoint.y -= maxy; | ||
2897 | 248 | } | ||
2898 | 249 | viewpoint.x /= kTriangleWidth; | ||
2899 | 250 | viewpoint.y /= kTriangleHeight; | ||
2900 | 251 | viewpoint.x -= map_w / 2; | ||
2901 | 252 | viewpoint.y -= map_h / 2; | ||
2902 | 253 | |||
2903 | 254 | // Render minimap | ||
2904 | 255 | std::unique_ptr<Texture> texture(draw_minimap(egbase, player, viewpoint, layers)); | ||
2905 | 256 | save_to_png(texture.get(), streamwrite, ColorType::RGBA); | ||
2906 | 257 | } | ||
2907 | 258 | 259 | ||
2908 | === modified file 'src/graphic/minimap_renderer.h' | |||
2909 | --- src/graphic/minimap_renderer.h 2016-08-04 15:49:05 +0000 | |||
2910 | +++ src/graphic/minimap_renderer.h 2016-10-24 20:07:47 +0000 | |||
2911 | @@ -22,15 +22,12 @@ | |||
2912 | 22 | 22 | ||
2913 | 23 | #include <memory> | 23 | #include <memory> |
2914 | 24 | 24 | ||
2924 | 25 | #include "base/point.h" | 25 | #include "base/rect.h" |
2925 | 26 | 26 | #include "base/vector.h" | |
2926 | 27 | class StreamWrite; | 27 | #include "graphic/texture.h" |
2927 | 28 | class Texture; | 28 | #include "logic/editor_game_base.h" |
2928 | 29 | 29 | #include "logic/map.h" | |
2929 | 30 | namespace Widelands { | 30 | #include "logic/player.h" |
2921 | 31 | class Player; | ||
2922 | 32 | class EditorGameBase; | ||
2923 | 33 | } | ||
2930 | 34 | 31 | ||
2931 | 35 | // Layers for selecting what do display on the minimap. | 32 | // Layers for selecting what do display on the minimap. |
2932 | 36 | enum class MiniMapLayer { | 33 | enum class MiniMapLayer { |
2933 | @@ -54,20 +51,31 @@ | |||
2934 | 54 | return MiniMapLayer(static_cast<int>(left) ^ static_cast<int>(right)); | 51 | return MiniMapLayer(static_cast<int>(left) ^ static_cast<int>(right)); |
2935 | 55 | } | 52 | } |
2936 | 56 | 53 | ||
2940 | 57 | /// Render the minimap. If player is not nullptr, it renders from that player's | 54 | enum class MiniMapType { |
2941 | 58 | /// point of view. | 55 | // Keep the view window always in the center of the minimap and pan the underlying map. |
2942 | 59 | /// \param viewpoint top left corner in map coordinates | 56 | kStaticViewWindow, |
2943 | 57 | |||
2944 | 58 | // Always align the map at (0, 0) and move the view window instead. | ||
2945 | 59 | kStaticMap, | ||
2946 | 60 | }; | ||
2947 | 61 | |||
2948 | 62 | // Converts between minimap pixel and map pixel. | ||
2949 | 63 | // Remember to call 'normalize_pix' after applying the transformation. | ||
2950 | 64 | Vector2f minimap_pixel_to_mappixel(const Widelands::Map& map, | ||
2951 | 65 | const Vector2i& minimap_pixel, | ||
2952 | 66 | const Rectf& view_area, | ||
2953 | 67 | MiniMapType minimap_type, | ||
2954 | 68 | const bool zoom); | ||
2955 | 69 | |||
2956 | 70 | // Render the minimap. If player is not nullptr, it renders from that player's | ||
2957 | 71 | // point of view. The 'view_area' designates the currently visible area in the | ||
2958 | 72 | // main view in map pixel coordinates and is used to draw the wire frame view | ||
2959 | 73 | // window. The 'view_point' is map pixel that will be drawn as the top-left | ||
2960 | 74 | // point in the resulting minimap. | ||
2961 | 60 | std::unique_ptr<Texture> draw_minimap(const Widelands::EditorGameBase& egbase, | 75 | std::unique_ptr<Texture> draw_minimap(const Widelands::EditorGameBase& egbase, |
2962 | 61 | const Widelands::Player* player, | 76 | const Widelands::Player* player, |
2964 | 62 | const Point& viewpoint, | 77 | const Rectf& view_area, |
2965 | 78 | const MiniMapType& map_draw_type, | ||
2966 | 63 | MiniMapLayer layers); | 79 | MiniMapLayer layers); |
2967 | 64 | 80 | ||
2968 | 65 | /// Render the minimap to a file. 1 pixel will be used for each fields. | ||
2969 | 66 | /// \param viewpoint : The game point of view as returned by interactive_base.get_viewpoint(); | ||
2970 | 67 | void write_minimap_image(const Widelands::EditorGameBase& egbase, | ||
2971 | 68 | Widelands::Player const* player, | ||
2972 | 69 | const Point& viewpoint, | ||
2973 | 70 | MiniMapLayer layers, | ||
2974 | 71 | StreamWrite* const streamwrite); | ||
2975 | 72 | |||
2976 | 73 | #endif // end of include guard: WL_GRAPHIC_MINIMAP_RENDERER_H | 81 | #endif // end of include guard: WL_GRAPHIC_MINIMAP_RENDERER_H |
2977 | 74 | 82 | ||
2978 | === modified file 'src/graphic/render_queue.cc' | |||
2979 | --- src/graphic/render_queue.cc 2016-08-04 15:49:05 +0000 | |||
2980 | +++ src/graphic/render_queue.cc 2016-10-24 20:07:47 +0000 | |||
2981 | @@ -120,14 +120,14 @@ | |||
2982 | 120 | // creation. Disables GL_SCISSOR_TEST at desctruction again. | 120 | // creation. Disables GL_SCISSOR_TEST at desctruction again. |
2983 | 121 | class ScopedScissor { | 121 | class ScopedScissor { |
2984 | 122 | public: | 122 | public: |
2986 | 123 | ScopedScissor(const FloatRect& rect); | 123 | ScopedScissor(const Rectf& rect); |
2987 | 124 | ~ScopedScissor(); | 124 | ~ScopedScissor(); |
2988 | 125 | 125 | ||
2989 | 126 | private: | 126 | private: |
2990 | 127 | DISALLOW_COPY_AND_ASSIGN(ScopedScissor); | 127 | DISALLOW_COPY_AND_ASSIGN(ScopedScissor); |
2991 | 128 | }; | 128 | }; |
2992 | 129 | 129 | ||
2994 | 130 | ScopedScissor::ScopedScissor(const FloatRect& rect) { | 130 | ScopedScissor::ScopedScissor(const Rectf& rect) { |
2995 | 131 | glScissor(rect.x, rect.y, rect.w, rect.h); | 131 | glScissor(rect.x, rect.y, rect.w, rect.h); |
2996 | 132 | glEnable(GL_SCISSOR_TEST); | 132 | glEnable(GL_SCISSOR_TEST); |
2997 | 133 | } | 133 | } |
2998 | @@ -249,9 +249,10 @@ | |||
2999 | 249 | 249 | ||
3000 | 250 | case Program::kTerrainRoad: { | 250 | case Program::kTerrainRoad: { |
3001 | 251 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); | 251 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); |
3005 | 252 | road_program_->draw( | 252 | road_program_->draw(item.terrain_arguments.renderbuffer_width, |
3006 | 253 | item.terrain_arguments.renderbuffer_width, item.terrain_arguments.renderbuffer_height, | 253 | item.terrain_arguments.renderbuffer_height, |
3007 | 254 | *item.terrain_arguments.fields_to_draw, item.z_value + 2 * kOpenGlZDelta); | 254 | *item.terrain_arguments.fields_to_draw, item.terrain_arguments.scale, |
3008 | 255 | item.z_value + 2 * kOpenGlZDelta); | ||
3009 | 255 | ++i; | 256 | ++i; |
3010 | 256 | } break; | 257 | } break; |
3011 | 257 | 258 | ||
3012 | 258 | 259 | ||
3013 | === modified file 'src/graphic/render_queue.h' | |||
3014 | --- src/graphic/render_queue.h 2016-08-04 15:49:05 +0000 | |||
3015 | +++ src/graphic/render_queue.h 2016-10-24 20:07:47 +0000 | |||
3016 | @@ -99,12 +99,12 @@ | |||
3017 | 99 | BlitData texture; | 99 | BlitData texture; |
3018 | 100 | BlitData mask; | 100 | BlitData mask; |
3019 | 101 | RGBAColor blend; | 101 | RGBAColor blend; |
3021 | 102 | FloatRect destination_rect; | 102 | Rectf destination_rect; |
3022 | 103 | }; | 103 | }; |
3023 | 104 | 104 | ||
3024 | 105 | struct RectArguments { | 105 | struct RectArguments { |
3025 | 106 | RGBAColor color; | 106 | RGBAColor color; |
3027 | 107 | FloatRect destination_rect; | 107 | Rectf destination_rect; |
3028 | 108 | }; | 108 | }; |
3029 | 109 | 109 | ||
3030 | 110 | // TODO(sirver): these are really triangle arguments. | 110 | // TODO(sirver): these are really triangle arguments. |
3031 | @@ -121,7 +121,8 @@ | |||
3032 | 121 | int renderbuffer_height; | 121 | int renderbuffer_height; |
3033 | 122 | const DescriptionMaintainer<Widelands::TerrainDescription>* terrains; | 122 | const DescriptionMaintainer<Widelands::TerrainDescription>* terrains; |
3034 | 123 | FieldsToDraw* fields_to_draw; | 123 | FieldsToDraw* fields_to_draw; |
3036 | 124 | FloatRect destination_rect; | 124 | float scale; |
3037 | 125 | Rectf destination_rect; | ||
3038 | 125 | }; | 126 | }; |
3039 | 126 | 127 | ||
3040 | 127 | // The union of all possible program arguments represents an Item that is | 128 | // The union of all possible program arguments represents an Item that is |
3041 | 128 | 129 | ||
3042 | === modified file 'src/graphic/rendertarget.cc' | |||
3043 | --- src/graphic/rendertarget.cc 2016-08-04 15:49:05 +0000 | |||
3044 | +++ src/graphic/rendertarget.cc 2016-10-24 20:07:47 +0000 | |||
3045 | @@ -35,7 +35,7 @@ | |||
3046 | 35 | /** | 35 | /** |
3047 | 36 | * Sets an arbitrary drawing window. | 36 | * Sets an arbitrary drawing window. |
3048 | 37 | */ | 37 | */ |
3050 | 38 | void RenderTarget::set_window(const Rect& rc, const Point& ofs) { | 38 | void RenderTarget::set_window(const Recti& rc, const Vector2i& ofs) { |
3051 | 39 | rect_ = rc; | 39 | rect_ = rc; |
3052 | 40 | offset_ = ofs; | 40 | offset_ = ofs; |
3053 | 41 | 41 | ||
3054 | @@ -69,15 +69,15 @@ | |||
3055 | 69 | * Returns false if the subwindow is invisible. In that case, the window state | 69 | * Returns false if the subwindow is invisible. In that case, the window state |
3056 | 70 | * is not changed at all. Otherwise, the function returns true. | 70 | * is not changed at all. Otherwise, the function returns true. |
3057 | 71 | */ | 71 | */ |
3062 | 72 | bool RenderTarget::enter_window(const Rect& rc, Rect* previous, Point* prevofs) { | 72 | bool RenderTarget::enter_window(const Recti& rc, Recti* previous, Vector2i* prevofs) { |
3063 | 73 | Rect newrect = rc; | 73 | Rectf newrect_f = rc.cast<float>(); |
3064 | 74 | 74 | if (clip(newrect_f)) { | |
3061 | 75 | if (clip(newrect)) { | ||
3065 | 76 | if (previous) | 75 | if (previous) |
3066 | 77 | *previous = rect_; | 76 | *previous = rect_; |
3067 | 78 | if (prevofs) | 77 | if (prevofs) |
3068 | 79 | *prevofs = offset_; | 78 | *prevofs = offset_; |
3069 | 80 | 79 | ||
3070 | 80 | const Recti newrect = newrect_f.cast<int>(); | ||
3071 | 81 | // Apply the changes | 81 | // Apply the changes |
3072 | 82 | offset_ = rc.origin() - (newrect.origin() - rect_.origin() - offset_); | 82 | offset_ = rc.origin() - (newrect.origin() - rect_.origin() - offset_); |
3073 | 83 | rect_ = newrect; | 83 | rect_ = newrect; |
3074 | @@ -104,10 +104,10 @@ | |||
3075 | 104 | /** | 104 | /** |
3076 | 105 | * This functions draws a line in the target | 105 | * This functions draws a line in the target |
3077 | 106 | */ | 106 | */ |
3079 | 107 | void RenderTarget::draw_line_strip(const std::vector<FloatPoint>& points, | 107 | void RenderTarget::draw_line_strip(const std::vector<Vector2f>& points, |
3080 | 108 | const RGBColor& color, | 108 | const RGBColor& color, |
3081 | 109 | float line_width) { | 109 | float line_width) { |
3083 | 110 | std::vector<FloatPoint> adjusted_points; | 110 | std::vector<Vector2f> adjusted_points; |
3084 | 111 | adjusted_points.reserve(points.size()); | 111 | adjusted_points.reserve(points.size()); |
3085 | 112 | for (const auto& p : points) { | 112 | for (const auto& p : points) { |
3086 | 113 | adjusted_points.emplace_back(p.x + offset_.x + rect_.x, p.y + offset_.y + rect_.y); | 113 | adjusted_points.emplace_back(p.x + offset_.x + rect_.x, p.y + offset_.y + rect_.y); |
3087 | @@ -118,21 +118,21 @@ | |||
3088 | 118 | /** | 118 | /** |
3089 | 119 | * Clip against window and pass those primitives along to the bitmap. | 119 | * Clip against window and pass those primitives along to the bitmap. |
3090 | 120 | */ | 120 | */ |
3093 | 121 | void RenderTarget::draw_rect(const Rect& rect, const RGBColor& clr) { | 121 | void RenderTarget::draw_rect(const Rectf& rect, const RGBColor& clr) { |
3094 | 122 | Rect r(rect); | 122 | Rectf r(rect); |
3095 | 123 | if (clip(r)) { | 123 | if (clip(r)) { |
3096 | 124 | ::draw_rect(r, clr, surface_); | 124 | ::draw_rect(r, clr, surface_); |
3097 | 125 | } | 125 | } |
3098 | 126 | } | 126 | } |
3099 | 127 | 127 | ||
3102 | 128 | void RenderTarget::fill_rect(const Rect& rect, const RGBAColor& clr, BlendMode blend_mode) { | 128 | void RenderTarget::fill_rect(const Rectf& rect, const RGBAColor& clr, BlendMode blend_mode) { |
3103 | 129 | Rect r(rect); | 129 | Rectf r(rect); |
3104 | 130 | if (clip(r)) | 130 | if (clip(r)) |
3105 | 131 | surface_->fill_rect(r, clr, blend_mode); | 131 | surface_->fill_rect(r, clr, blend_mode); |
3106 | 132 | } | 132 | } |
3107 | 133 | 133 | ||
3110 | 134 | void RenderTarget::brighten_rect(const Rect& rect, int32_t factor) { | 134 | void RenderTarget::brighten_rect(const Rectf& rect, int32_t factor) { |
3111 | 135 | Rect r(rect); | 135 | Rectf r(rect); |
3112 | 136 | if (clip(r)) | 136 | if (clip(r)) |
3113 | 137 | surface_->brighten_rect(r, factor); | 137 | surface_->brighten_rect(r, factor); |
3114 | 138 | } | 138 | } |
3115 | @@ -142,30 +142,32 @@ | |||
3116 | 142 | * | 142 | * |
3117 | 143 | * This blit function copies the pixels to the destination surface. | 143 | * This blit function copies the pixels to the destination surface. |
3118 | 144 | */ | 144 | */ |
3120 | 145 | void RenderTarget::blit(const Point& dst, | 145 | void RenderTarget::blit(const Vector2f& dst, |
3121 | 146 | const Image* image, | 146 | const Image* image, |
3122 | 147 | BlendMode blend_mode, | 147 | BlendMode blend_mode, |
3123 | 148 | UI::Align align) { | 148 | UI::Align align) { |
3125 | 149 | Point destination_point(dst); | 149 | Vector2f destination_point(dst); |
3126 | 150 | UI::correct_for_align(align, image->width(), image->height(), &destination_point); | 150 | UI::correct_for_align(align, image->width(), image->height(), &destination_point); |
3127 | 151 | 151 | ||
3130 | 152 | Rect source_rect(Point(0, 0), image->width(), image->height()); | 152 | Rectf source_rect(Vector2i(0, 0), image->width(), image->height()); |
3131 | 153 | Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); | 153 | Rectf destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); |
3132 | 154 | 154 | ||
3133 | 155 | if (to_surface_geometry(&destination_rect, &source_rect)) { | 155 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3135 | 156 | surface_->blit(destination_rect, *image, source_rect, 1., blend_mode); | 156 | // I seem to remember seeing 1. a lot in blitting calls. |
3136 | 157 | constexpr float kFullyOpaque = 1.f; | ||
3137 | 158 | surface_->blit(destination_rect, *image, source_rect, kFullyOpaque, blend_mode); | ||
3138 | 157 | } | 159 | } |
3139 | 158 | } | 160 | } |
3140 | 159 | 161 | ||
3142 | 160 | void RenderTarget::blit_monochrome(const Point& dst, | 162 | void RenderTarget::blit_monochrome(const Vector2f& dst, |
3143 | 161 | const Image* image, | 163 | const Image* image, |
3144 | 162 | const RGBAColor& blend_mode, | 164 | const RGBAColor& blend_mode, |
3145 | 163 | UI::Align align) { | 165 | UI::Align align) { |
3147 | 164 | Point destination_point(dst); | 166 | Vector2f destination_point(dst); |
3148 | 165 | UI::correct_for_align(align, image->width(), image->height(), &destination_point); | 167 | UI::correct_for_align(align, image->width(), image->height(), &destination_point); |
3149 | 166 | 168 | ||
3152 | 167 | Rect source_rect(Point(0, 0), image->width(), image->height()); | 169 | Rectf source_rect(Vector2i(0, 0), image->width(), image->height()); |
3153 | 168 | Rect destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); | 170 | Rectf destination_rect(destination_point.x, destination_point.y, source_rect.w, source_rect.h); |
3154 | 169 | 171 | ||
3155 | 170 | if (to_surface_geometry(&destination_rect, &source_rect)) { | 172 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3156 | 171 | surface_->blit_monochrome(destination_rect, *image, source_rect, blend_mode); | 173 | surface_->blit_monochrome(destination_rect, *image, source_rect, blend_mode); |
3157 | @@ -175,38 +177,40 @@ | |||
3158 | 175 | /** | 177 | /** |
3159 | 176 | * Like \ref blit, but use only a sub-rectangle of the source image. | 178 | * Like \ref blit, but use only a sub-rectangle of the source image. |
3160 | 177 | */ | 179 | */ |
3162 | 178 | void RenderTarget::blitrect(const Point& dst, | 180 | void RenderTarget::blitrect(const Vector2f& dst, |
3163 | 179 | const Image* image, | 181 | const Image* image, |
3165 | 180 | const Rect& gsrcrc, | 182 | const Recti& gsrcrc, |
3166 | 181 | BlendMode blend_mode) { | 183 | BlendMode blend_mode) { |
3167 | 182 | assert(0 <= gsrcrc.x); | 184 | assert(0 <= gsrcrc.x); |
3168 | 183 | assert(0 <= gsrcrc.y); | 185 | assert(0 <= gsrcrc.y); |
3169 | 184 | 186 | ||
3170 | 185 | // We want to use the given srcrc, but we must make sure that we are not | 187 | // We want to use the given srcrc, but we must make sure that we are not |
3171 | 186 | // blitting outside of the boundaries of 'image'. | 188 | // blitting outside of the boundaries of 'image'. |
3175 | 187 | Rect source_rect(gsrcrc.x, gsrcrc.y, std::min<int32_t>(image->width() - gsrcrc.x, gsrcrc.w), | 189 | Rectf source_rect(gsrcrc.x, gsrcrc.y, std::min<int32_t>(image->width() - gsrcrc.x, gsrcrc.w), |
3176 | 188 | std::min<int32_t>(image->height() - gsrcrc.y, gsrcrc.h)); | 190 | std::min<int32_t>(image->height() - gsrcrc.y, gsrcrc.h)); |
3177 | 189 | Rect destination_rect(dst.x, dst.y, source_rect.w, source_rect.h); | 191 | Rectf destination_rect(dst.x, dst.y, source_rect.w, source_rect.h); |
3178 | 190 | 192 | ||
3179 | 191 | if (to_surface_geometry(&destination_rect, &source_rect)) { | 193 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3180 | 192 | surface_->blit(destination_rect, *image, source_rect, 1., blend_mode); | 194 | surface_->blit(destination_rect, *image, source_rect, 1., blend_mode); |
3181 | 193 | } | 195 | } |
3182 | 194 | } | 196 | } |
3183 | 195 | 197 | ||
3185 | 196 | void RenderTarget::blitrect_scale(Rect destination_rect, | 198 | void RenderTarget::blitrect_scale(Rectf destination_rect, |
3186 | 197 | const Image* image, | 199 | const Image* image, |
3188 | 198 | Rect source_rect, | 200 | Recti source_rect_i, |
3189 | 199 | const float opacity, | 201 | const float opacity, |
3190 | 200 | const BlendMode blend_mode) { | 202 | const BlendMode blend_mode) { |
3191 | 203 | Rectf source_rect = source_rect_i.cast<float>(); | ||
3192 | 201 | if (to_surface_geometry(&destination_rect, &source_rect)) { | 204 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3193 | 202 | surface_->blit(destination_rect, *image, source_rect, opacity, blend_mode); | 205 | surface_->blit(destination_rect, *image, source_rect, opacity, blend_mode); |
3194 | 203 | } | 206 | } |
3195 | 204 | } | 207 | } |
3196 | 205 | 208 | ||
3198 | 206 | void RenderTarget::blitrect_scale_monochrome(Rect destination_rect, | 209 | void RenderTarget::blitrect_scale_monochrome(Rectf destination_rect, |
3199 | 207 | const Image* image, | 210 | const Image* image, |
3201 | 208 | Rect source_rect, | 211 | Recti source_rect_i, |
3202 | 209 | const RGBAColor& blend) { | 212 | const RGBAColor& blend) { |
3203 | 213 | Rectf source_rect = source_rect_i.cast<float>(); | ||
3204 | 210 | if (to_surface_geometry(&destination_rect, &source_rect)) { | 214 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3205 | 211 | surface_->blit_monochrome(destination_rect, *image, source_rect, blend); | 215 | surface_->blit_monochrome(destination_rect, *image, source_rect, blend); |
3206 | 212 | } | 216 | } |
3207 | @@ -218,15 +222,15 @@ | |||
3208 | 218 | * The pixel from ofs inside image is placed at the top-left corner of | 222 | * The pixel from ofs inside image is placed at the top-left corner of |
3209 | 219 | * the filled rectangle. | 223 | * the filled rectangle. |
3210 | 220 | */ | 224 | */ |
3212 | 221 | void RenderTarget::tile(const Rect& rect, | 225 | void RenderTarget::tile(const Recti& rect, |
3213 | 222 | const Image* image, | 226 | const Image* image, |
3215 | 223 | const Point& gofs, | 227 | const Vector2i& gofs, |
3216 | 224 | BlendMode blend_mode) { | 228 | BlendMode blend_mode) { |
3217 | 225 | int32_t srcw = image->width(); | 229 | int32_t srcw = image->width(); |
3218 | 226 | int32_t srch = image->height(); | 230 | int32_t srch = image->height(); |
3219 | 227 | 231 | ||
3222 | 228 | Rect r(rect); | 232 | Rectf r = rect.cast<float>(); |
3223 | 229 | Point ofs(gofs); | 233 | Vector2i ofs(gofs); |
3224 | 230 | if (clip(r)) { | 234 | if (clip(r)) { |
3225 | 231 | if (offset_.x < 0) | 235 | if (offset_.x < 0) |
3226 | 232 | ofs.x -= offset_.x; | 236 | ofs.x -= offset_.x; |
3227 | @@ -251,7 +255,7 @@ | |||
3228 | 251 | while (ty < r.h) { | 255 | while (ty < r.h) { |
3229 | 252 | int tx = 0; | 256 | int tx = 0; |
3230 | 253 | int32_t tofsx = ofs.x; | 257 | int32_t tofsx = ofs.x; |
3232 | 254 | Rect srcrc; | 258 | Rectf srcrc; |
3233 | 255 | 259 | ||
3234 | 256 | srcrc.y = ofs.y; | 260 | srcrc.y = ofs.y; |
3235 | 257 | srcrc.h = srch - ofs.y; | 261 | srcrc.h = srch - ofs.y; |
3236 | @@ -266,7 +270,7 @@ | |||
3237 | 266 | if (tx + srcrc.w > r.w) | 270 | if (tx + srcrc.w > r.w) |
3238 | 267 | srcrc.w = r.w - tx; | 271 | srcrc.w = r.w - tx; |
3239 | 268 | 272 | ||
3241 | 269 | const Rect dst_rect(r.x + tx, r.y + ty, srcrc.w, srcrc.h); | 273 | const Rectf dst_rect(r.x + tx, r.y + ty, srcrc.w, srcrc.h); |
3242 | 270 | surface_->blit(dst_rect, *image, srcrc, 1., blend_mode); | 274 | surface_->blit(dst_rect, *image, srcrc, 1., blend_mode); |
3243 | 271 | 275 | ||
3244 | 272 | tx += srcrc.w; | 276 | tx += srcrc.w; |
3245 | @@ -280,54 +284,50 @@ | |||
3246 | 280 | } | 284 | } |
3247 | 281 | } | 285 | } |
3248 | 282 | 286 | ||
3264 | 283 | /** | 287 | void RenderTarget::blit_animation(const Vector2f& dst, |
3265 | 284 | * Draws a frame of an animation at the given location | 288 | const float scale, |
3266 | 285 | * Plays sound effect that is registered with this frame (the SoundHandler | 289 | uint32_t animation, |
3267 | 286 | * decides if the sound really does get played) | 290 | uint32_t time) { |
3268 | 287 | * | 291 | // TODO(unknown): Correctly calculate the stereo position for sound effects |
3269 | 288 | * \param dstx, dsty the on-screen location of the animation hot spot | 292 | // TODO(unknown): The chosen semantics of animation sound effects is problematic: |
3270 | 289 | * \param animation the animation ID | 293 | // What if the game runs very slowly or very quickly? |
3256 | 290 | * \param time the time, in milliseconds, in the animation | ||
3257 | 291 | * \param player the player this object belongs to, for player colour | ||
3258 | 292 | * purposes. May be 0 (for example, for world objects). | ||
3259 | 293 | */ | ||
3260 | 294 | // TODO(unknown): Correctly calculate the stereo position for sound effects | ||
3261 | 295 | // TODO(unknown): The chosen semantics of animation sound effects is problematic: | ||
3262 | 296 | // What if the game runs very slowly or very quickly? | ||
3263 | 297 | void RenderTarget::blit_animation(const Point& dst, uint32_t animation, uint32_t time) { | ||
3271 | 298 | const Animation& anim = g_gr->animations().get_animation(animation); | 294 | const Animation& anim = g_gr->animations().get_animation(animation); |
3273 | 299 | do_blit_animation(dst, anim, time, nullptr, Rect(Point(0, 0), anim.width(), anim.height())); | 295 | do_blit_animation( |
3274 | 296 | dst, scale, anim, time, nullptr, Recti(Vector2i(0, 0), anim.width(), anim.height())); | ||
3275 | 300 | } | 297 | } |
3276 | 301 | 298 | ||
3278 | 302 | void RenderTarget::blit_animation(const Point& dst, | 299 | void RenderTarget::blit_animation(const Vector2f& dst, |
3279 | 300 | const float scale, | ||
3280 | 303 | uint32_t animation, | 301 | uint32_t animation, |
3281 | 304 | uint32_t time, | 302 | uint32_t time, |
3282 | 305 | const RGBColor& player_color) { | 303 | const RGBColor& player_color) { |
3283 | 306 | const Animation& anim = g_gr->animations().get_animation(animation); | 304 | const Animation& anim = g_gr->animations().get_animation(animation); |
3284 | 307 | do_blit_animation( | 305 | do_blit_animation( |
3286 | 308 | dst, anim, time, &player_color, Rect(Point(0, 0), anim.width(), anim.height())); | 306 | dst, scale, anim, time, &player_color, Recti(Vector2i(0, 0), anim.width(), anim.height())); |
3287 | 309 | } | 307 | } |
3288 | 310 | 308 | ||
3290 | 311 | void RenderTarget::blit_animation(const Point& dst, | 309 | void RenderTarget::blit_animation(const Vector2f& dst, |
3291 | 310 | const float scale, | ||
3292 | 312 | uint32_t animation, | 311 | uint32_t animation, |
3293 | 313 | uint32_t time, | 312 | uint32_t time, |
3294 | 314 | const RGBColor& player_color, | 313 | const RGBColor& player_color, |
3296 | 315 | const Rect& source_rect) { | 314 | const Recti& source_rect) { |
3297 | 316 | do_blit_animation( | 315 | do_blit_animation( |
3299 | 317 | dst, g_gr->animations().get_animation(animation), time, &player_color, source_rect); | 316 | dst, scale, g_gr->animations().get_animation(animation), time, &player_color, source_rect); |
3300 | 318 | } | 317 | } |
3301 | 319 | 318 | ||
3303 | 320 | void RenderTarget::do_blit_animation(const Point& dst, | 319 | void RenderTarget::do_blit_animation(const Vector2f& dst, |
3304 | 320 | const float scale, | ||
3305 | 321 | const Animation& animation, | 321 | const Animation& animation, |
3306 | 322 | uint32_t time, | 322 | uint32_t time, |
3307 | 323 | const RGBColor* player_color, | 323 | const RGBColor* player_color, |
3315 | 324 | const Rect& source_rect) { | 324 | const Recti& source_rect_i) { |
3316 | 325 | Rect destination_rect(dst.x - animation.hotspot().x + source_rect.x, | 325 | Rectf source_rect = source_rect_i.cast<float>(); |
3317 | 326 | dst.y - animation.hotspot().y + source_rect.y, source_rect.w, | 326 | Rectf destination_rect(dst.x - (animation.hotspot().x - source_rect.x) * scale, |
3318 | 327 | source_rect.h); | 327 | dst.y - (animation.hotspot().y - source_rect.y) * scale, |
3319 | 328 | Rect srcrc(source_rect); | 328 | source_rect.w * scale, source_rect.h * scale); |
3320 | 329 | if (to_surface_geometry(&destination_rect, &srcrc)) { | 329 | if (to_surface_geometry(&destination_rect, &source_rect)) { |
3321 | 330 | animation.blit(time, destination_rect.origin(), srcrc, player_color, surface_); | 330 | animation.blit(time, destination_rect, source_rect, player_color, surface_); |
3322 | 331 | } | 331 | } |
3323 | 332 | 332 | ||
3324 | 333 | // Look if there is a sound effect registered for this frame and trigger the | 333 | // Look if there is a sound effect registered for this frame and trigger the |
3325 | @@ -355,7 +355,7 @@ | |||
3326 | 355 | * If true is returned, r a valid rectangle that can be used. | 355 | * If true is returned, r a valid rectangle that can be used. |
3327 | 356 | * If false is returned, r may not be used and may be partially modified. | 356 | * If false is returned, r may not be used and may be partially modified. |
3328 | 357 | */ | 357 | */ |
3330 | 358 | bool RenderTarget::clip(Rect& r) const { | 358 | bool RenderTarget::clip(Rectf& r) const { |
3331 | 359 | r.x += offset_.x; | 359 | r.x += offset_.x; |
3332 | 360 | r.y += offset_.y; | 360 | r.y += offset_.y; |
3333 | 361 | 361 | ||
3334 | @@ -397,7 +397,7 @@ | |||
3335 | 397 | * Clip against window and source bitmap, returns false if blitting is | 397 | * Clip against window and source bitmap, returns false if blitting is |
3336 | 398 | * unnecessary because image is not inside the target surface. | 398 | * unnecessary because image is not inside the target surface. |
3337 | 399 | */ | 399 | */ |
3339 | 400 | bool RenderTarget::to_surface_geometry(Rect* destination_rect, Rect* source_rect) const { | 400 | bool RenderTarget::to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const { |
3340 | 401 | assert(0 <= source_rect->x); | 401 | assert(0 <= source_rect->x); |
3341 | 402 | assert(0 <= source_rect->y); | 402 | assert(0 <= source_rect->y); |
3342 | 403 | destination_rect->x += offset_.x; | 403 | destination_rect->x += offset_.x; |
3343 | @@ -409,17 +409,16 @@ | |||
3344 | 409 | // destination_rect, we do this by making the proportional change. | 409 | // destination_rect, we do this by making the proportional change. |
3345 | 410 | 410 | ||
3346 | 411 | // Clipping, from the left. | 411 | // Clipping, from the left. |
3348 | 412 | if (destination_rect->x < 0) { | 412 | if (destination_rect->x < 0.f) { |
3349 | 413 | if (destination_rect->w <= -destination_rect->x) { | 413 | if (destination_rect->w <= -destination_rect->x) { |
3350 | 414 | return false; | 414 | return false; |
3351 | 415 | } | 415 | } |
3355 | 416 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. | 416 | const float source_rect_pixel_change = |
3356 | 417 | const int source_rect_pixel_change = | 417 | -destination_rect->x / destination_rect->w * source_rect->w; |
3354 | 418 | 0.5 + -static_cast<double>(destination_rect->x) / destination_rect->w * source_rect->w; | ||
3357 | 419 | source_rect->x += source_rect_pixel_change; | 418 | source_rect->x += source_rect_pixel_change; |
3358 | 420 | source_rect->w -= source_rect_pixel_change; | 419 | source_rect->w -= source_rect_pixel_change; |
3359 | 421 | destination_rect->w += destination_rect->x; | 420 | destination_rect->w += destination_rect->x; |
3361 | 422 | destination_rect->x = 0; | 421 | destination_rect->x = 0.f; |
3362 | 423 | } | 422 | } |
3363 | 424 | 423 | ||
3364 | 425 | // Clipping, from the right. | 424 | // Clipping, from the right. |
3365 | @@ -427,25 +426,22 @@ | |||
3366 | 427 | if (rect_.w <= destination_rect->x) { | 426 | if (rect_.w <= destination_rect->x) { |
3367 | 428 | return false; | 427 | return false; |
3368 | 429 | } | 428 | } |
3373 | 430 | const int new_destination_w = rect_.w - destination_rect->x; | 429 | const float new_destination_w = rect_.w - destination_rect->x; |
3374 | 431 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. | 430 | source_rect->w = new_destination_w / destination_rect->w * source_rect->w; |
3371 | 432 | source_rect->w = | ||
3372 | 433 | 0.5 + static_cast<double>(new_destination_w) / destination_rect->w * source_rect->w; | ||
3375 | 434 | destination_rect->w = new_destination_w; | 431 | destination_rect->w = new_destination_w; |
3376 | 435 | } | 432 | } |
3377 | 436 | 433 | ||
3378 | 437 | // Clipping, from the top. | 434 | // Clipping, from the top. |
3380 | 438 | if (destination_rect->y < 0) { | 435 | if (destination_rect->y < 0.f) { |
3381 | 439 | if (destination_rect->h <= -destination_rect->y) { | 436 | if (destination_rect->h <= -destination_rect->y) { |
3382 | 440 | return false; | 437 | return false; |
3383 | 441 | } | 438 | } |
3387 | 442 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. | 439 | const float source_rect_pixel_change = |
3388 | 443 | const int source_rect_pixel_change = | 440 | -destination_rect->y / destination_rect->h * source_rect->h; |
3386 | 444 | 0.5 + -static_cast<double>(destination_rect->y) / destination_rect->h * source_rect->h; | ||
3389 | 445 | source_rect->y += source_rect_pixel_change; | 441 | source_rect->y += source_rect_pixel_change; |
3390 | 446 | source_rect->h -= source_rect_pixel_change; | 442 | source_rect->h -= source_rect_pixel_change; |
3391 | 447 | destination_rect->h += destination_rect->y; | 443 | destination_rect->h += destination_rect->y; |
3393 | 448 | destination_rect->y = 0; | 444 | destination_rect->y = 0.f; |
3394 | 449 | } | 445 | } |
3395 | 450 | 446 | ||
3396 | 451 | // Clipping, from the bottom. | 447 | // Clipping, from the bottom. |
3397 | @@ -453,13 +449,10 @@ | |||
3398 | 453 | if (rect_.h <= destination_rect->y) { | 449 | if (rect_.h <= destination_rect->y) { |
3399 | 454 | return false; | 450 | return false; |
3400 | 455 | } | 451 | } |
3405 | 456 | const int new_destination_h = rect_.h - destination_rect->y; | 452 | const float new_destination_h = rect_.h - destination_rect->y; |
3406 | 457 | // Adding 0.5 is a cheap way of turning integer truncation into a rounded value. | 453 | source_rect->h = new_destination_h / destination_rect->h * source_rect->h; |
3403 | 458 | source_rect->h = | ||
3404 | 459 | 0.5 + static_cast<double>(new_destination_h) / destination_rect->h * source_rect->h; | ||
3407 | 460 | destination_rect->h = new_destination_h; | 454 | destination_rect->h = new_destination_h; |
3408 | 461 | } | 455 | } |
3409 | 462 | |||
3410 | 463 | destination_rect->x += rect_.x; | 456 | destination_rect->x += rect_.x; |
3411 | 464 | destination_rect->y += rect_.y; | 457 | destination_rect->y += rect_.y; |
3412 | 465 | return true; | 458 | return true; |
3413 | 466 | 459 | ||
3414 | === modified file 'src/graphic/rendertarget.h' | |||
3415 | --- src/graphic/rendertarget.h 2016-08-04 15:49:05 +0000 | |||
3416 | +++ src/graphic/rendertarget.h 2016-10-24 20:07:47 +0000 | |||
3417 | @@ -51,31 +51,31 @@ | |||
3418 | 51 | class RenderTarget { | 51 | class RenderTarget { |
3419 | 52 | public: | 52 | public: |
3420 | 53 | RenderTarget(Surface*); | 53 | RenderTarget(Surface*); |
3423 | 54 | void set_window(const Rect& rc, const Point& ofs); | 54 | void set_window(const Recti& rc, const Vector2i& ofs); |
3424 | 55 | bool enter_window(const Rect& rc, Rect* previous, Point* prevofs); | 55 | bool enter_window(const Recti& rc, Recti* previous, Vector2i* prevofs); |
3425 | 56 | 56 | ||
3426 | 57 | int32_t width() const; | 57 | int32_t width() const; |
3427 | 58 | int32_t height() const; | 58 | int32_t height() const; |
3428 | 59 | 59 | ||
3433 | 60 | void draw_line_strip(const std::vector<FloatPoint>& points, const RGBColor& color, float width); | 60 | void draw_line_strip(const std::vector<Vector2f>& points, const RGBColor& color, float width); |
3434 | 61 | void draw_rect(const Rect&, const RGBColor&); | 61 | void draw_rect(const Rectf&, const RGBColor&); |
3435 | 62 | void fill_rect(const Rect&, const RGBAColor&, BlendMode blend_mode = BlendMode::Copy); | 62 | void fill_rect(const Rectf&, const RGBAColor&, BlendMode blend_mode = BlendMode::Copy); |
3436 | 63 | void brighten_rect(const Rect&, int32_t factor); | 63 | void brighten_rect(const Rectf&, int32_t factor); |
3437 | 64 | 64 | ||
3439 | 65 | void blit(const Point& dst, | 65 | void blit(const Vector2f& dst, |
3440 | 66 | const Image* image, | 66 | const Image* image, |
3441 | 67 | BlendMode blend_mode = BlendMode::UseAlpha, | 67 | BlendMode blend_mode = BlendMode::UseAlpha, |
3442 | 68 | UI::Align = UI::Align::kTopLeft); | 68 | UI::Align = UI::Align::kTopLeft); |
3443 | 69 | 69 | ||
3444 | 70 | // Like blit. See MonochromeBlitProgram for details. | 70 | // Like blit. See MonochromeBlitProgram for details. |
3446 | 71 | void blit_monochrome(const Point& dst, | 71 | void blit_monochrome(const Vector2f& dst, |
3447 | 72 | const Image* image, | 72 | const Image* image, |
3448 | 73 | const RGBAColor& blend_mode, | 73 | const RGBAColor& blend_mode, |
3449 | 74 | UI::Align = UI::Align::kTopLeft); | 74 | UI::Align = UI::Align::kTopLeft); |
3450 | 75 | 75 | ||
3452 | 76 | void blitrect(const Point& dst, | 76 | void blitrect(const Vector2f& dst, |
3453 | 77 | const Image* image, | 77 | const Image* image, |
3455 | 78 | const Rect& src, | 78 | const Recti& src, |
3456 | 79 | BlendMode blend_mode = BlendMode::UseAlpha); | 79 | BlendMode blend_mode = BlendMode::UseAlpha); |
3457 | 80 | 80 | ||
3458 | 81 | // Blits the 'source_rect' from 'image' into the | 81 | // Blits the 'source_rect' from 'image' into the |
3459 | @@ -83,68 +83,71 @@ | |||
3460 | 83 | // multiplied with 'opacity' before blitting. The 'blend_mode' | 83 | // multiplied with 'opacity' before blitting. The 'blend_mode' |
3461 | 84 | // defines if values are blended with whats already there or just | 84 | // defines if values are blended with whats already there or just |
3462 | 85 | // copied over. | 85 | // copied over. |
3465 | 86 | // Rect's are taken by value on purpose. | 86 | // Takes by value on purpose. |
3466 | 87 | void blitrect_scale(Rect destination_rect, | 87 | void blitrect_scale(Rectf destination_rect, |
3467 | 88 | const Image* image, | 88 | const Image* image, |
3469 | 89 | Rect source_rect, | 89 | Recti source_rect, |
3470 | 90 | float opacity, | 90 | float opacity, |
3471 | 91 | BlendMode blend_mode); | 91 | BlendMode blend_mode); |
3472 | 92 | 92 | ||
3476 | 93 | // Like blitrect_scale. See MonochromeBlitProgram for details. Rect's are | 93 | // Like blitrect_scale. See MonochromeBlitProgram for details. Takes by |
3477 | 94 | // taken by value on purpose. | 94 | // value on purpose. |
3478 | 95 | void blitrect_scale_monochrome(Rect destination_rect, | 95 | void blitrect_scale_monochrome(Rectf destination_rect, |
3479 | 96 | const Image* image, | 96 | const Image* image, |
3481 | 97 | Rect source_rect, | 97 | Recti source_rect, |
3482 | 98 | const RGBAColor& blend); | 98 | const RGBAColor& blend); |
3483 | 99 | 99 | ||
3485 | 100 | void tile(const Rect&, | 100 | void tile(const Recti&, |
3486 | 101 | const Image* image, | 101 | const Image* image, |
3488 | 102 | const Point& ofs, | 102 | const Vector2i& ofs, |
3489 | 103 | BlendMode blend_mode = BlendMode::UseAlpha); | 103 | BlendMode blend_mode = BlendMode::UseAlpha); |
3490 | 104 | 104 | ||
3496 | 105 | // Draw the 'animation' as it should appear at 'time' in this target at 'dst'. Optionally, the | 105 | // Draw the 'animation' as it should appear at 'time' in this target at |
3497 | 106 | // animation is | 106 | // 'dst'. Optionally, the animation is tinted with 'player_color' and |
3498 | 107 | // tinted with 'player_color' and cropped to 'source_rect'. | 107 | // cropped to 'source_rect'. |
3499 | 108 | void blit_animation(const Point& dst, uint32_t animation, uint32_t time); | 108 | void blit_animation(const Vector2f& dst, float scale, uint32_t animation, uint32_t time); |
3500 | 109 | void blit_animation(const Point& dst, | 109 | void blit_animation(const Vector2f& dst, |
3501 | 110 | float scale, | ||
3502 | 110 | uint32_t animation, | 111 | uint32_t animation, |
3503 | 111 | uint32_t time, | 112 | uint32_t time, |
3504 | 112 | const RGBColor& player_color); | 113 | const RGBColor& player_color); |
3506 | 113 | void blit_animation(const Point& dst, | 114 | void blit_animation(const Vector2f& dst, |
3507 | 115 | float scale, | ||
3508 | 114 | uint32_t animation, | 116 | uint32_t animation, |
3509 | 115 | uint32_t time, | 117 | uint32_t time, |
3510 | 116 | const RGBColor& player_color, | 118 | const RGBColor& player_color, |
3512 | 117 | const Rect& source_rect); | 119 | const Recti& source_rect); |
3513 | 118 | 120 | ||
3514 | 119 | void reset(); | 121 | void reset(); |
3515 | 120 | 122 | ||
3516 | 121 | Surface* get_surface() const { | 123 | Surface* get_surface() const { |
3517 | 122 | return surface_; | 124 | return surface_; |
3518 | 123 | } | 125 | } |
3520 | 124 | const Rect& get_rect() const { | 126 | const Recti& get_rect() const { |
3521 | 125 | return rect_; | 127 | return rect_; |
3522 | 126 | } | 128 | } |
3524 | 127 | const Point& get_offset() const { | 129 | const Vector2i& get_offset() const { |
3525 | 128 | return offset_; | 130 | return offset_; |
3526 | 129 | } | 131 | } |
3527 | 130 | 132 | ||
3528 | 131 | protected: | 133 | protected: |
3531 | 132 | bool clip(Rect& r) const; | 134 | bool clip(Rectf& r) const; |
3532 | 133 | bool to_surface_geometry(Rect* destination_rect, Rect* source_rect) const; | 135 | bool to_surface_geometry(Rectf* destination_rect, Rectf* source_rect) const; |
3533 | 134 | 136 | ||
3534 | 135 | // Does the actual blitting. | 137 | // Does the actual blitting. |
3536 | 136 | void do_blit_animation(const Point& dst, | 138 | void do_blit_animation(const Vector2f& dst, |
3537 | 139 | const float scale, | ||
3538 | 137 | const Animation& animation, | 140 | const Animation& animation, |
3539 | 138 | uint32_t time, | 141 | uint32_t time, |
3540 | 139 | const RGBColor* player_color, | 142 | const RGBColor* player_color, |
3542 | 140 | const Rect& source_rect); | 143 | const Recti& source_rect); |
3543 | 141 | 144 | ||
3544 | 142 | /// The target surface | 145 | /// The target surface |
3545 | 143 | Surface* surface_; | 146 | Surface* surface_; |
3546 | 144 | /// The current clip rectangle | 147 | /// The current clip rectangle |
3548 | 145 | Rect rect_; | 148 | Recti rect_; |
3549 | 146 | /// Drawing offset | 149 | /// Drawing offset |
3551 | 147 | Point offset_; | 150 | Vector2i offset_; |
3552 | 148 | }; | 151 | }; |
3553 | 149 | 152 | ||
3554 | 150 | #endif // end of include guard: WL_GRAPHIC_RENDERTARGET_H | 153 | #endif // end of include guard: WL_GRAPHIC_RENDERTARGET_H |
3555 | 151 | 154 | ||
3556 | === modified file 'src/graphic/richtext.cc' | |||
3557 | --- src/graphic/richtext.cc 2016-08-04 16:24:09 +0000 | |||
3558 | +++ src/graphic/richtext.cc 2016-10-24 20:07:47 +0000 | |||
3559 | @@ -41,7 +41,7 @@ | |||
3560 | 41 | * rectangular bounding box. | 41 | * rectangular bounding box. |
3561 | 42 | */ | 42 | */ |
3562 | 43 | struct Element { | 43 | struct Element { |
3564 | 44 | explicit Element(const Rect& bounding_box) : bbox(bounding_box) { | 44 | explicit Element(const Recti& bounding_box) : bbox(bounding_box) { |
3565 | 45 | } | 45 | } |
3566 | 46 | virtual ~Element() { | 46 | virtual ~Element() { |
3567 | 47 | } | 47 | } |
3568 | @@ -52,23 +52,23 @@ | |||
3569 | 52 | */ | 52 | */ |
3570 | 53 | virtual void draw(RenderTarget& dst) = 0; | 53 | virtual void draw(RenderTarget& dst) = 0; |
3571 | 54 | 54 | ||
3573 | 55 | Rect bbox; | 55 | Recti bbox; |
3574 | 56 | }; | 56 | }; |
3575 | 57 | 57 | ||
3576 | 58 | struct ImageElement : Element { | 58 | struct ImageElement : Element { |
3578 | 59 | ImageElement(const Rect& bounding_box, const Image* init_image) | 59 | ImageElement(const Recti& bounding_box, const Image* init_image) |
3579 | 60 | : Element(bounding_box), image(init_image) { | 60 | : Element(bounding_box), image(init_image) { |
3580 | 61 | } | 61 | } |
3581 | 62 | 62 | ||
3582 | 63 | void draw(RenderTarget& dst) override { | 63 | void draw(RenderTarget& dst) override { |
3584 | 64 | dst.blit(Point(0, 0), image); | 64 | dst.blit(Vector2f(0, 0), image); |
3585 | 65 | } | 65 | } |
3586 | 66 | 66 | ||
3587 | 67 | const Image* image; | 67 | const Image* image; |
3588 | 68 | }; | 68 | }; |
3589 | 69 | 69 | ||
3590 | 70 | struct TextlineElement : Element { | 70 | struct TextlineElement : Element { |
3592 | 71 | TextlineElement(const Rect& bounding_box, | 71 | TextlineElement(const Recti& bounding_box, |
3593 | 72 | const TextStyle& init_style, | 72 | const TextStyle& init_style, |
3594 | 73 | std::vector<std::string>::const_iterator words_begin, | 73 | std::vector<std::string>::const_iterator words_begin, |
3595 | 74 | std::vector<std::string>::const_iterator words_end) | 74 | std::vector<std::string>::const_iterator words_end) |
3596 | @@ -107,16 +107,16 @@ | |||
3597 | 107 | } | 107 | } |
3598 | 108 | } | 108 | } |
3599 | 109 | // Now render | 109 | // Now render |
3601 | 110 | uint32_t x = g_fh->draw_text_raw(dst, style, Point(0, 0), result_words[0]); | 110 | uint32_t x = g_fh->draw_text_raw(dst, style, Vector2i(0, 0), result_words[0]); |
3602 | 111 | 111 | ||
3603 | 112 | it = result_words.begin() + 1; | 112 | it = result_words.begin() + 1; |
3604 | 113 | if (it != result_words.end()) { | 113 | if (it != result_words.end()) { |
3605 | 114 | do { | 114 | do { |
3606 | 115 | if (style.underline) | 115 | if (style.underline) |
3608 | 116 | x += g_fh->draw_text_raw(dst, style, Point(x, 0), " "); | 116 | x += g_fh->draw_text_raw(dst, style, Vector2i(x, 0), " "); |
3609 | 117 | else | 117 | else |
3610 | 118 | x += spacewidth; | 118 | x += spacewidth; |
3612 | 119 | x += g_fh->draw_text_raw(dst, style, Point(x, 0), *it++); | 119 | x += g_fh->draw_text_raw(dst, style, Vector2i(x, 0), *it++); |
3613 | 120 | } while (it != result_words.end()); | 120 | } while (it != result_words.end()); |
3614 | 121 | } | 121 | } |
3615 | 122 | } | 122 | } |
3616 | @@ -357,7 +357,7 @@ | |||
3617 | 357 | if (!image) | 357 | if (!image) |
3618 | 358 | continue; | 358 | continue; |
3619 | 359 | 359 | ||
3621 | 360 | Rect bbox; | 360 | Recti bbox; |
3622 | 361 | bbox.x = text.images_width; | 361 | bbox.x = text.images_width; |
3623 | 362 | bbox.y = m->height; | 362 | bbox.y = m->height; |
3624 | 363 | bbox.w = image->width(); | 363 | bbox.w = image->width(); |
3625 | @@ -423,7 +423,7 @@ | |||
3626 | 423 | TextBuilder::Elt elt; | 423 | TextBuilder::Elt elt; |
3627 | 424 | elt.miny = elt.maxy = 0; | 424 | elt.miny = elt.maxy = 0; |
3628 | 425 | 425 | ||
3630 | 426 | Rect bbox; | 426 | Recti bbox; |
3631 | 427 | bbox.x = text.linewidth ? text.linewidth + text.spacewidth : 0; | 427 | bbox.x = text.linewidth ? text.linewidth + text.spacewidth : 0; |
3632 | 428 | bbox.y = 0; // filled in later | 428 | bbox.y = 0; // filled in later |
3633 | 429 | bbox.w = 0; | 429 | bbox.w = 0; |
3634 | @@ -486,16 +486,16 @@ | |||
3635 | 486 | * @note this function may draw content outside the box given offset | 486 | * @note this function may draw content outside the box given offset |
3636 | 487 | * and @ref width and @ref height, if there were wrapping problems. | 487 | * and @ref width and @ref height, if there were wrapping problems. |
3637 | 488 | */ | 488 | */ |
3639 | 489 | void RichText::draw(RenderTarget& dst, const Point& offset, bool background) { | 489 | void RichText::draw(RenderTarget& dst, const Vector2i& offset, bool background) { |
3640 | 490 | for (std::vector<Element*>::const_iterator elt = m->elements.begin(); elt != m->elements.end(); | 490 | for (std::vector<Element*>::const_iterator elt = m->elements.begin(); elt != m->elements.end(); |
3641 | 491 | ++elt) { | 491 | ++elt) { |
3645 | 492 | Rect oldbox; | 492 | Recti oldbox; |
3646 | 493 | Point oldofs; | 493 | Vector2i oldofs; |
3647 | 494 | Rect bbox((*elt)->bbox.origin() + offset, (*elt)->bbox.w, (*elt)->bbox.h); | 494 | Recti bbox((*elt)->bbox.origin() + offset, (*elt)->bbox.w, (*elt)->bbox.h); |
3648 | 495 | 495 | ||
3649 | 496 | if (dst.enter_window(bbox, &oldbox, &oldofs)) { | 496 | if (dst.enter_window(bbox, &oldbox, &oldofs)) { |
3650 | 497 | if (background) | 497 | if (background) |
3652 | 498 | dst.fill_rect(Rect(Point(0, 0), bbox.w, bbox.h), m->background_color); | 498 | dst.fill_rect(Rectf(0.f, 0.f, bbox.w, bbox.h), m->background_color); |
3653 | 499 | (*elt)->draw(dst); | 499 | (*elt)->draw(dst); |
3654 | 500 | dst.set_window(oldbox, oldofs); | 500 | dst.set_window(oldbox, oldofs); |
3655 | 501 | } | 501 | } |
3656 | 502 | 502 | ||
3657 | === modified file 'src/graphic/richtext.h' | |||
3658 | --- src/graphic/richtext.h 2016-08-04 15:49:05 +0000 | |||
3659 | +++ src/graphic/richtext.h 2016-10-24 20:07:47 +0000 | |||
3660 | @@ -24,7 +24,7 @@ | |||
3661 | 24 | #include <memory> | 24 | #include <memory> |
3662 | 25 | #include <string> | 25 | #include <string> |
3663 | 26 | 26 | ||
3665 | 27 | #include "base/point.h" | 27 | #include "base/vector.h" |
3666 | 28 | #include "graphic/color.h" | 28 | #include "graphic/color.h" |
3667 | 29 | 29 | ||
3668 | 30 | class RenderTarget; | 30 | class RenderTarget; |
3669 | @@ -50,7 +50,7 @@ | |||
3670 | 50 | uint32_t height(); | 50 | uint32_t height(); |
3671 | 51 | 51 | ||
3672 | 52 | void parse(const std::string& text); | 52 | void parse(const std::string& text); |
3674 | 53 | void draw(RenderTarget& dst, const Point& offset, bool background = false); | 53 | void draw(RenderTarget& dst, const Vector2i& offset, bool background = false); |
3675 | 54 | 54 | ||
3676 | 55 | private: | 55 | private: |
3677 | 56 | std::unique_ptr<RichTextImpl> m; | 56 | std::unique_ptr<RichTextImpl> m; |
3678 | 57 | 57 | ||
3679 | === modified file 'src/graphic/screen.cc' | |||
3680 | --- src/graphic/screen.cc 2016-08-04 15:49:05 +0000 | |||
3681 | +++ src/graphic/screen.cc 2016-10-24 20:07:47 +0000 | |||
3682 | @@ -53,7 +53,7 @@ | |||
3683 | 53 | return std::unique_ptr<Texture>(new Texture(surface)); | 53 | return std::unique_ptr<Texture>(new Texture(surface)); |
3684 | 54 | } | 54 | } |
3685 | 55 | 55 | ||
3687 | 56 | void Screen::do_blit(const FloatRect& dst_rect, | 56 | void Screen::do_blit(const Rectf& dst_rect, |
3688 | 57 | const BlitData& texture, | 57 | const BlitData& texture, |
3689 | 58 | float opacity, | 58 | float opacity, |
3690 | 59 | BlendMode blend_mode) { | 59 | BlendMode blend_mode) { |
3691 | @@ -68,7 +68,7 @@ | |||
3692 | 68 | RenderQueue::instance().enqueue(i); | 68 | RenderQueue::instance().enqueue(i); |
3693 | 69 | } | 69 | } |
3694 | 70 | 70 | ||
3696 | 71 | void Screen::do_blit_blended(const FloatRect& dst_rect, | 71 | void Screen::do_blit_blended(const Rectf& dst_rect, |
3697 | 72 | const BlitData& texture, | 72 | const BlitData& texture, |
3698 | 73 | const BlitData& mask, | 73 | const BlitData& mask, |
3699 | 74 | const RGBColor& blend) { | 74 | const RGBColor& blend) { |
3700 | @@ -83,7 +83,7 @@ | |||
3701 | 83 | RenderQueue::instance().enqueue(i); | 83 | RenderQueue::instance().enqueue(i); |
3702 | 84 | } | 84 | } |
3703 | 85 | 85 | ||
3705 | 86 | void Screen::do_blit_monochrome(const FloatRect& dst_rect, | 86 | void Screen::do_blit_monochrome(const Rectf& dst_rect, |
3706 | 87 | const BlitData& texture, | 87 | const BlitData& texture, |
3707 | 88 | const RGBAColor& blend) { | 88 | const RGBAColor& blend) { |
3708 | 89 | RenderQueue::Item i; | 89 | RenderQueue::Item i; |
3709 | @@ -105,7 +105,7 @@ | |||
3710 | 105 | RenderQueue::instance().enqueue(i); | 105 | RenderQueue::instance().enqueue(i); |
3711 | 106 | } | 106 | } |
3712 | 107 | 107 | ||
3714 | 108 | void Screen::do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) { | 108 | void Screen::do_fill_rect(const Rectf& dst_rect, const RGBAColor& color, BlendMode blend_mode) { |
3715 | 109 | RenderQueue::Item i; | 109 | RenderQueue::Item i; |
3716 | 110 | i.blend_mode = blend_mode; | 110 | i.blend_mode = blend_mode; |
3717 | 111 | i.program_id = RenderQueue::Program::kRect; | 111 | i.program_id = RenderQueue::Program::kRect; |
3718 | 112 | 112 | ||
3719 | === modified file 'src/graphic/screen.h' | |||
3720 | --- src/graphic/screen.h 2016-08-04 15:49:05 +0000 | |||
3721 | +++ src/graphic/screen.h 2016-10-24 20:07:47 +0000 | |||
3722 | @@ -43,20 +43,20 @@ | |||
3723 | 43 | std::unique_ptr<Texture> to_texture() const; | 43 | std::unique_ptr<Texture> to_texture() const; |
3724 | 44 | 44 | ||
3725 | 45 | private: | 45 | private: |
3727 | 46 | void do_blit(const FloatRect& dst_rect, | 46 | void do_blit(const Rectf& dst_rect, |
3728 | 47 | const BlitData& texture, | 47 | const BlitData& texture, |
3729 | 48 | float opacity, | 48 | float opacity, |
3730 | 49 | BlendMode blend_mode) override; | 49 | BlendMode blend_mode) override; |
3732 | 50 | void do_blit_blended(const FloatRect& dst_rect, | 50 | void do_blit_blended(const Rectf& dst_rect, |
3733 | 51 | const BlitData& texture, | 51 | const BlitData& texture, |
3734 | 52 | const BlitData& mask, | 52 | const BlitData& mask, |
3735 | 53 | const RGBColor& blend) override; | 53 | const RGBColor& blend) override; |
3737 | 54 | void do_blit_monochrome(const FloatRect& dst_rect, | 54 | void do_blit_monochrome(const Rectf& dst_rect, |
3738 | 55 | const BlitData& texture, | 55 | const BlitData& texture, |
3739 | 56 | const RGBAColor& blend) override; | 56 | const RGBAColor& blend) override; |
3740 | 57 | void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) override; | 57 | void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) override; |
3741 | 58 | void | 58 | void |
3743 | 59 | do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; | 59 | do_fill_rect(const Rectf& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; |
3744 | 60 | 60 | ||
3745 | 61 | const int w_, h_; | 61 | const int w_, h_; |
3746 | 62 | 62 | ||
3747 | 63 | 63 | ||
3748 | === modified file 'src/graphic/surface.cc' | |||
3749 | --- src/graphic/surface.cc 2016-08-04 15:49:05 +0000 | |||
3750 | +++ src/graphic/surface.cc 2016-10-24 20:07:47 +0000 | |||
3751 | @@ -26,15 +26,15 @@ | |||
3752 | 26 | #include <SDL.h> | 26 | #include <SDL.h> |
3753 | 27 | 27 | ||
3754 | 28 | #include "base/macros.h" | 28 | #include "base/macros.h" |
3755 | 29 | #include "base/point.h" | ||
3756 | 30 | #include "base/rect.h" | 29 | #include "base/rect.h" |
3757 | 30 | #include "base/vector.h" | ||
3758 | 31 | #include "graphic/gl/coordinate_conversion.h" | 31 | #include "graphic/gl/coordinate_conversion.h" |
3759 | 32 | #include "graphic/gl/utils.h" | 32 | #include "graphic/gl/utils.h" |
3760 | 33 | 33 | ||
3761 | 34 | namespace { | 34 | namespace { |
3762 | 35 | 35 | ||
3763 | 36 | // Adjust 'original' so that only 'src_rect' is actually blitted. | 36 | // Adjust 'original' so that only 'src_rect' is actually blitted. |
3765 | 37 | BlitData adjust_for_src(BlitData blit_data, const Rect& src_rect) { | 37 | BlitData adjust_for_src(BlitData blit_data, const Rectf& src_rect) { |
3766 | 38 | blit_data.rect.x += src_rect.x; | 38 | blit_data.rect.x += src_rect.x; |
3767 | 39 | blit_data.rect.y += src_rect.y; | 39 | blit_data.rect.y += src_rect.y; |
3768 | 40 | blit_data.rect.w = src_rect.w; | 40 | blit_data.rect.w = src_rect.w; |
3769 | @@ -44,11 +44,11 @@ | |||
3770 | 44 | 44 | ||
3771 | 45 | // Get the normal of the line between 'start' and 'end'. | 45 | // Get the normal of the line between 'start' and 'end'. |
3772 | 46 | template <typename PointType> | 46 | template <typename PointType> |
3774 | 47 | FloatPoint calculate_line_normal(const PointType& start, const PointType& end) { | 47 | Vector2f calculate_line_normal(const PointType& start, const PointType& end) { |
3775 | 48 | const float dx = end.x - start.x; | 48 | const float dx = end.x - start.x; |
3776 | 49 | const float dy = end.y - start.y; | 49 | const float dy = end.y - start.y; |
3777 | 50 | const float len = std::hypot(dx, dy); | 50 | const float len = std::hypot(dx, dy); |
3779 | 51 | return FloatPoint(-dy / len, dx / len); | 51 | return Vector2f(-dy / len, dx / len); |
3780 | 52 | } | 52 | } |
3781 | 53 | 53 | ||
3782 | 54 | // Tesselates the line made up of 'points' ino triangles and converts them into | 54 | // Tesselates the line made up of 'points' ino triangles and converts them into |
3783 | @@ -60,7 +60,7 @@ | |||
3784 | 60 | int h, | 60 | int h, |
3785 | 61 | const RGBColor& color, | 61 | const RGBColor& color, |
3786 | 62 | float line_width, | 62 | float line_width, |
3788 | 63 | const std::vector<FloatPoint>& points, | 63 | const std::vector<Vector2f>& points, |
3789 | 64 | std::vector<DrawLineProgram::PerVertexData>* vertices) { | 64 | std::vector<DrawLineProgram::PerVertexData>* vertices) { |
3790 | 65 | const float r = color.r / 255.; | 65 | const float r = color.r / 255.; |
3791 | 66 | const float g = color.g / 255.; | 66 | const float g = color.g / 255.; |
3792 | @@ -69,27 +69,27 @@ | |||
3793 | 69 | // Iterate over each line segment, i.e. all points but the last, convert | 69 | // Iterate over each line segment, i.e. all points but the last, convert |
3794 | 70 | // them from pixel space to gl space and draw them. | 70 | // them from pixel space to gl space and draw them. |
3795 | 71 | for (size_t i = 0; i < points.size() - 1; ++i) { | 71 | for (size_t i = 0; i < points.size() - 1; ++i) { |
3798 | 72 | const FloatPoint p1 = FloatPoint(points[i].x, points[i].y); | 72 | const Vector2f p1 = Vector2f(points[i].x, points[i].y); |
3799 | 73 | const FloatPoint p2 = FloatPoint(points[i + 1].x, points[i + 1].y); | 73 | const Vector2f p2 = Vector2f(points[i + 1].x, points[i + 1].y); |
3800 | 74 | 74 | ||
3803 | 75 | const FloatPoint normal = calculate_line_normal(p1, p2); | 75 | const Vector2f normal = calculate_line_normal(p1, p2); |
3804 | 76 | const FloatPoint scaled_normal(0.5f * line_width * normal.x, 0.5f * line_width * normal.y); | 76 | const Vector2f scaled_normal(0.5f * line_width * normal.x, 0.5f * line_width * normal.y); |
3805 | 77 | 77 | ||
3806 | 78 | // Quad points are created in rendering order for OpenGL. | 78 | // Quad points are created in rendering order for OpenGL. |
3807 | 79 | { | 79 | { |
3821 | 80 | FloatPoint p = p1 - scaled_normal; | 80 | Vector2f p = p1 - scaled_normal; |
3822 | 81 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); | 81 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); |
3823 | 82 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, 1.}); | 82 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, 1.}); |
3824 | 83 | } | 83 | } |
3825 | 84 | 84 | ||
3826 | 85 | { | 85 | { |
3827 | 86 | FloatPoint p = p2 - scaled_normal; | 86 | Vector2f p = p2 - scaled_normal; |
3828 | 87 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); | 87 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); |
3829 | 88 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, 1.}); | 88 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, 1.}); |
3830 | 89 | } | 89 | } |
3831 | 90 | 90 | ||
3832 | 91 | { | 91 | { |
3833 | 92 | FloatPoint p = p1 + scaled_normal; | 92 | Vector2f p = p1 + scaled_normal; |
3834 | 93 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); | 93 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); |
3835 | 94 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, -1.}); | 94 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, -1.}); |
3836 | 95 | } | 95 | } |
3837 | @@ -98,7 +98,7 @@ | |||
3838 | 98 | vertices->push_back(vertices->at(vertices->size() - 2)); | 98 | vertices->push_back(vertices->at(vertices->size() - 2)); |
3839 | 99 | 99 | ||
3840 | 100 | { | 100 | { |
3842 | 101 | FloatPoint p = p2 + scaled_normal; | 101 | Vector2f p = p2 + scaled_normal; |
3843 | 102 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); | 102 | pixel_to_gl_renderbuffer(w, h, &p.x, &p.y); |
3844 | 103 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, -1.}); | 103 | vertices->emplace_back(DrawLineProgram::PerVertexData{p.x, p.y, 0.f, r, g, b, -1.}); |
3845 | 104 | } | 104 | } |
3846 | @@ -107,12 +107,12 @@ | |||
3847 | 107 | 107 | ||
3848 | 108 | } // namespace | 108 | } // namespace |
3849 | 109 | 109 | ||
3852 | 110 | void Surface::fill_rect(const Rect& rc, const RGBAColor& clr, BlendMode blend_mode) { | 110 | void Surface::fill_rect(const Rectf& rc, const RGBAColor& clr, BlendMode blend_mode) { |
3853 | 111 | const FloatRect rect = rect_to_gl_renderbuffer(width(), height(), rc); | 111 | const Rectf rect = rect_to_gl_renderbuffer(width(), height(), rc); |
3854 | 112 | do_fill_rect(rect, clr, blend_mode); | 112 | do_fill_rect(rect, clr, blend_mode); |
3855 | 113 | } | 113 | } |
3856 | 114 | 114 | ||
3858 | 115 | void Surface::brighten_rect(const Rect& rc, const int32_t factor) { | 115 | void Surface::brighten_rect(const Rectf& rc, const int32_t factor) { |
3859 | 116 | if (!factor) { | 116 | if (!factor) { |
3860 | 117 | return; | 117 | return; |
3861 | 118 | } | 118 | } |
3862 | @@ -120,11 +120,11 @@ | |||
3863 | 120 | const BlendMode blend_mode = factor < 0 ? BlendMode::Subtract : BlendMode::UseAlpha; | 120 | const BlendMode blend_mode = factor < 0 ? BlendMode::Subtract : BlendMode::UseAlpha; |
3864 | 121 | const int abs_factor = std::abs(factor); | 121 | const int abs_factor = std::abs(factor); |
3865 | 122 | const RGBAColor color(abs_factor, abs_factor, abs_factor, 0); | 122 | const RGBAColor color(abs_factor, abs_factor, abs_factor, 0); |
3867 | 123 | const FloatRect rect = rect_to_gl_renderbuffer(width(), height(), rc); | 123 | const Rectf rect = rect_to_gl_renderbuffer(width(), height(), rc); |
3868 | 124 | do_fill_rect(rect, color, blend_mode); | 124 | do_fill_rect(rect, color, blend_mode); |
3869 | 125 | } | 125 | } |
3870 | 126 | 126 | ||
3872 | 127 | void Surface::draw_line_strip(std::vector<FloatPoint> points, | 127 | void Surface::draw_line_strip(std::vector<Vector2f> points, |
3873 | 128 | const RGBColor& color, | 128 | const RGBColor& color, |
3874 | 129 | float line_width) { | 129 | float line_width) { |
3875 | 130 | if (points.size() < 2) { | 130 | if (points.size() < 2) { |
3876 | @@ -138,41 +138,41 @@ | |||
3877 | 138 | do_draw_line_strip(std::move(vertices)); | 138 | do_draw_line_strip(std::move(vertices)); |
3878 | 139 | } | 139 | } |
3879 | 140 | 140 | ||
3881 | 141 | void Surface::blit_monochrome(const Rect& dst_rect, | 141 | void Surface::blit_monochrome(const Rectf& dst_rect, |
3882 | 142 | const Image& image, | 142 | const Image& image, |
3884 | 143 | const Rect& src_rect, | 143 | const Rectf& src_rect, |
3885 | 144 | const RGBAColor& blend) { | 144 | const RGBAColor& blend) { |
3887 | 145 | const FloatRect rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); | 145 | const Rectf rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); |
3888 | 146 | do_blit_monochrome(rect, adjust_for_src(image.blit_data(), src_rect), blend); | 146 | do_blit_monochrome(rect, adjust_for_src(image.blit_data(), src_rect), blend); |
3889 | 147 | } | 147 | } |
3890 | 148 | 148 | ||
3892 | 149 | void Surface::blit_blended(const Rect& dst_rect, | 149 | void Surface::blit_blended(const Rectf& dst_rect, |
3893 | 150 | const Image& image, | 150 | const Image& image, |
3894 | 151 | const Image& texture_mask, | 151 | const Image& texture_mask, |
3896 | 152 | const Rect& src_rect, | 152 | const Rectf& src_rect, |
3897 | 153 | const RGBColor& blend) { | 153 | const RGBColor& blend) { |
3899 | 154 | const FloatRect rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); | 154 | const Rectf rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); |
3900 | 155 | do_blit_blended(rect, adjust_for_src(image.blit_data(), src_rect), | 155 | do_blit_blended(rect, adjust_for_src(image.blit_data(), src_rect), |
3901 | 156 | adjust_for_src(texture_mask.blit_data(), src_rect), blend); | 156 | adjust_for_src(texture_mask.blit_data(), src_rect), blend); |
3902 | 157 | } | 157 | } |
3903 | 158 | 158 | ||
3905 | 159 | void Surface::blit(const Rect& dst_rect, | 159 | void Surface::blit(const Rectf& dst_rect, |
3906 | 160 | const Image& image, | 160 | const Image& image, |
3908 | 161 | const Rect& src_rect, | 161 | const Rectf& src_rect, |
3909 | 162 | float opacity, | 162 | float opacity, |
3910 | 163 | BlendMode blend_mode) { | 163 | BlendMode blend_mode) { |
3912 | 164 | const FloatRect rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); | 164 | const Rectf rect = rect_to_gl_renderbuffer(width(), height(), dst_rect); |
3913 | 165 | do_blit(rect, adjust_for_src(image.blit_data(), src_rect), opacity, blend_mode); | 165 | do_blit(rect, adjust_for_src(image.blit_data(), src_rect), opacity, blend_mode); |
3914 | 166 | } | 166 | } |
3915 | 167 | 167 | ||
3921 | 168 | void draw_rect(const Rect& rc, const RGBColor& clr, Surface* surface) { | 168 | void draw_rect(const Rectf& rc, const RGBColor& clr, Surface* surface) { |
3922 | 169 | const FloatPoint top_left = FloatPoint(rc.x + 0.5f, rc.y + 0.5f); | 169 | const Vector2f top_left = Vector2f(rc.x + 0.5f, rc.y + 0.5f); |
3923 | 170 | const FloatPoint top_right = FloatPoint(rc.x + rc.w - 0.5f, rc.y + 0.5f); | 170 | const Vector2f top_right = Vector2f(rc.x + rc.w - 0.5f, rc.y + 0.5f); |
3924 | 171 | const FloatPoint bottom_right = FloatPoint(rc.x + rc.w - 0.5f, rc.y + rc.h - 0.5f); | 171 | const Vector2f bottom_right = Vector2f(rc.x + rc.w - 0.5f, rc.y + rc.h - 0.5f); |
3925 | 172 | const FloatPoint bottom_left = FloatPoint(rc.x + 0.5f, rc.y + rc.h - 0.5f); | 172 | const Vector2f bottom_left = Vector2f(rc.x + 0.5f, rc.y + rc.h - 0.5f); |
3926 | 173 | 173 | ||
3927 | 174 | surface->draw_line_strip({top_left, top_right, bottom_right}, clr, 1); | 174 | surface->draw_line_strip({top_left, top_right, bottom_right}, clr, 1); |
3928 | 175 | // We need to split this up in order not to miss a pixel on the bottom right corner. | 175 | // We need to split this up in order not to miss a pixel on the bottom right corner. |
3929 | 176 | surface->draw_line_strip( | 176 | surface->draw_line_strip( |
3931 | 177 | {FloatPoint(bottom_right.x + 1, bottom_right.y), bottom_left, top_left}, clr, 1); | 177 | {Vector2f(bottom_right.x + 1, bottom_right.y), bottom_left, top_left}, clr, 1); |
3932 | 178 | } | 178 | } |
3933 | 179 | 179 | ||
3934 | === modified file 'src/graphic/surface.h' | |||
3935 | --- src/graphic/surface.h 2016-08-04 15:49:05 +0000 | |||
3936 | +++ src/graphic/surface.h 2016-10-24 20:07:47 +0000 | |||
3937 | @@ -46,42 +46,42 @@ | |||
3938 | 46 | 46 | ||
3939 | 47 | /// This draws a part of 'texture'. | 47 | /// This draws a part of 'texture'. |
3940 | 48 | void blit( | 48 | void blit( |
3942 | 49 | const Rect& dst, const Image&, const Rect& srcrc, const float opacity, BlendMode blend_mode); | 49 | const Rectf& dst, const Image&, const Rectf& srcrc, const float opacity, BlendMode blend_mode); |
3943 | 50 | 50 | ||
3944 | 51 | /// This draws a playercolor blended image. | 51 | /// This draws a playercolor blended image. |
3946 | 52 | void blit_blended(const Rect& dst, | 52 | void blit_blended(const Rectf& dst, |
3947 | 53 | const Image& image, | 53 | const Image& image, |
3948 | 54 | const Image& texture_mask, | 54 | const Image& texture_mask, |
3950 | 55 | const Rect& srcrc, | 55 | const Rectf& srcrc, |
3951 | 56 | const RGBColor& blend); | 56 | const RGBColor& blend); |
3952 | 57 | 57 | ||
3953 | 58 | /// This draws a grayed out version. | 58 | /// This draws a grayed out version. |
3954 | 59 | void | 59 | void |
3956 | 60 | blit_monochrome(const Rect& dst, const Image&, const Rect& srcrc, const RGBAColor& multiplier); | 60 | blit_monochrome(const Rectf& dst, const Image&, const Rectf& srcrc, const RGBAColor& multiplier); |
3957 | 61 | 61 | ||
3958 | 62 | /// Draws a filled rect to the destination. | 62 | /// Draws a filled rect to the destination. |
3960 | 63 | void fill_rect(const Rect&, const RGBAColor&, BlendMode blend_mode = BlendMode::Copy); | 63 | void fill_rect(const Rectf& dst, const RGBAColor&, BlendMode blend_mode = BlendMode::Copy); |
3961 | 64 | 64 | ||
3962 | 65 | // Draw a 'width' pixel wide line to the destination. 'points' are taken by | 65 | // Draw a 'width' pixel wide line to the destination. 'points' are taken by |
3963 | 66 | // value on purpose. | 66 | // value on purpose. |
3965 | 67 | void draw_line_strip(std::vector<FloatPoint> points, const RGBColor& color, float width); | 67 | void draw_line_strip(std::vector<Vector2f> points, const RGBColor& color, float width); |
3966 | 68 | 68 | ||
3967 | 69 | /// makes a rectangle on the destination brighter (or darker). | 69 | /// makes a rectangle on the destination brighter (or darker). |
3969 | 70 | void brighten_rect(const Rect&, int factor); | 70 | void brighten_rect(const Rectf&, int factor); |
3970 | 71 | 71 | ||
3971 | 72 | private: | 72 | private: |
3972 | 73 | /// The actual implementation of the methods below. | 73 | /// The actual implementation of the methods below. |
3974 | 74 | virtual void do_blit(const FloatRect& dst_rect, | 74 | virtual void do_blit(const Rectf& dst_rect, |
3975 | 75 | const BlitData& texture, | 75 | const BlitData& texture, |
3976 | 76 | float opacity, | 76 | float opacity, |
3977 | 77 | BlendMode blend_mode) = 0; | 77 | BlendMode blend_mode) = 0; |
3978 | 78 | 78 | ||
3980 | 79 | virtual void do_blit_blended(const FloatRect& dst_rect, | 79 | virtual void do_blit_blended(const Rectf& dst_rect, |
3981 | 80 | const BlitData& texture, | 80 | const BlitData& texture, |
3982 | 81 | const BlitData& mask, | 81 | const BlitData& mask, |
3983 | 82 | const RGBColor& blend) = 0; | 82 | const RGBColor& blend) = 0; |
3984 | 83 | 83 | ||
3986 | 84 | virtual void do_blit_monochrome(const FloatRect& dst_rect, | 84 | virtual void do_blit_monochrome(const Rectf& dst_rect, |
3987 | 85 | const BlitData& texture, | 85 | const BlitData& texture, |
3988 | 86 | const RGBAColor& blend) = 0; | 86 | const RGBAColor& blend) = 0; |
3989 | 87 | 87 | ||
3990 | @@ -90,7 +90,7 @@ | |||
3991 | 90 | virtual void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) = 0; | 90 | virtual void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) = 0; |
3992 | 91 | 91 | ||
3993 | 92 | virtual void | 92 | virtual void |
3995 | 93 | do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) = 0; | 93 | do_fill_rect(const Rectf& dst_rect, const RGBAColor& color, BlendMode blend_mode) = 0; |
3996 | 94 | 94 | ||
3997 | 95 | DISALLOW_COPY_AND_ASSIGN(Surface); | 95 | DISALLOW_COPY_AND_ASSIGN(Surface); |
3998 | 96 | }; | 96 | }; |
3999 | @@ -98,6 +98,6 @@ | |||
4000 | 98 | /// Draws a rect (frame only) to the surface. The width of the surrounding line | 98 | /// Draws a rect (frame only) to the surface. The width of the surrounding line |
4001 | 99 | /// is 1 pixel, i.e. the transparent inner box of the drawn rectangle starts at | 99 | /// is 1 pixel, i.e. the transparent inner box of the drawn rectangle starts at |
4002 | 100 | /// (x+1, y+1) and has dimension (w - 2, h - 2). | 100 | /// (x+1, y+1) and has dimension (w - 2, h - 2). |
4004 | 101 | void draw_rect(const Rect& rect, const RGBColor&, Surface* destination); | 101 | void draw_rect(const Rectf& rect, const RGBColor&, Surface* destination); |
4005 | 102 | 102 | ||
4006 | 103 | #endif // end of include guard: WL_GRAPHIC_SURFACE_H | 103 | #endif // end of include guard: WL_GRAPHIC_SURFACE_H |
4007 | 104 | 104 | ||
4008 | === modified file 'src/graphic/text/rt_render.cc' | |||
4009 | --- src/graphic/text/rt_render.cc 2016-08-04 15:49:05 +0000 | |||
4010 | +++ src/graphic/text/rt_render.cc 2016-10-24 20:07:47 +0000 | |||
4011 | @@ -32,8 +32,8 @@ | |||
4012 | 32 | #include "base/i18n.h" | 32 | #include "base/i18n.h" |
4013 | 33 | #include "base/log.h" | 33 | #include "base/log.h" |
4014 | 34 | #include "base/macros.h" | 34 | #include "base/macros.h" |
4015 | 35 | #include "base/point.h" | ||
4016 | 36 | #include "base/rect.h" | 35 | #include "base/rect.h" |
4017 | 36 | #include "base/vector.h" | ||
4018 | 37 | #include "base/wexception.h" | 37 | #include "base/wexception.h" |
4019 | 38 | #include "graphic/align.h" | 38 | #include "graphic/align.h" |
4020 | 39 | #include "graphic/graphic.h" | 39 | #include "graphic/graphic.h" |
4021 | @@ -173,7 +173,7 @@ | |||
4022 | 173 | } | 173 | } |
4023 | 174 | 174 | ||
4024 | 175 | struct Reference { | 175 | struct Reference { |
4026 | 176 | Rect dim; | 176 | Recti dim; |
4027 | 177 | string ref; | 177 | string ref; |
4028 | 178 | }; | 178 | }; |
4029 | 179 | 179 | ||
4030 | @@ -185,7 +185,7 @@ | |||
4031 | 185 | // Should this linear algorithm proof to be too slow (doubtful), the | 185 | // Should this linear algorithm proof to be too slow (doubtful), the |
4032 | 186 | // RefMap could also be efficiently implemented using an R-Tree | 186 | // RefMap could also be efficiently implemented using an R-Tree |
4033 | 187 | for (const Reference& c : refs_) | 187 | for (const Reference& c : refs_) |
4035 | 188 | if (c.dim.contains(Point(x, y))) | 188 | if (c.dim.contains(Vector2i(x, y))) |
4036 | 189 | return c.ref; | 189 | return c.ref; |
4037 | 190 | return ""; | 190 | return ""; |
4038 | 191 | } | 191 | } |
4039 | @@ -469,7 +469,7 @@ | |||
4040 | 469 | const vector<Reference> get_references() override { | 469 | const vector<Reference> get_references() override { |
4041 | 470 | vector<Reference> rv; | 470 | vector<Reference> rv; |
4042 | 471 | if (!nodestyle_.reference.empty()) { | 471 | if (!nodestyle_.reference.empty()) { |
4044 | 472 | Reference r = {Rect(0, 0, w_, h_), nodestyle_.reference}; | 472 | Reference r = {Recti(0, 0, w_, h_), nodestyle_.reference}; |
4045 | 473 | rv.push_back(r); | 473 | rv.push_back(r); |
4046 | 474 | } | 474 | } |
4047 | 475 | return rv; | 475 | return rv; |
4048 | @@ -501,7 +501,7 @@ | |||
4049 | 501 | const Texture& img = | 501 | const Texture& img = |
4050 | 502 | font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); | 502 | font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); |
4051 | 503 | Texture* rv = new Texture(img.width(), img.height()); | 503 | Texture* rv = new Texture(img.width(), img.height()); |
4053 | 504 | rv->blit(Rect(0, 0, img.width(), img.height()), img, Rect(0, 0, img.width(), img.height()), 1., | 504 | rv->blit(Rectf(0, 0, img.width(), img.height()), img, Rectf(0, 0, img.width(), img.height()), 1., |
4054 | 505 | BlendMode::Copy); | 505 | BlendMode::Copy); |
4055 | 506 | return rv; | 506 | return rv; |
4056 | 507 | } | 507 | } |
4057 | @@ -536,8 +536,8 @@ | |||
4058 | 536 | font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); | 536 | font_.render(txt_, nodestyle_.font_color, nodestyle_.font_style, texture_cache); |
4059 | 537 | Texture* rv = new Texture(w_, h_); | 537 | Texture* rv = new Texture(w_, h_); |
4060 | 538 | for (uint16_t curx = 0; curx < w_; curx += t.width()) { | 538 | for (uint16_t curx = 0; curx < w_; curx += t.width()) { |
4063 | 539 | Rect srcrect(Point(0, 0), min<int>(t.width(), w_ - curx), h_); | 539 | Rectf srcrect(0.f, 0.f, min<int>(t.width(), w_ - curx), h_); |
4064 | 540 | rv->blit(Rect(curx, 0, srcrect.w, srcrect.h), t, srcrect, 1., BlendMode::Copy); | 540 | rv->blit(Rectf(curx, 0, srcrect.w, srcrect.h), t, srcrect, 1., BlendMode::Copy); |
4065 | 541 | } | 541 | } |
4066 | 542 | return rv; | 542 | return rv; |
4067 | 543 | } | 543 | } |
4068 | @@ -557,7 +557,7 @@ | |||
4069 | 557 | Texture* render(TextureCache* texture_cache) override { | 557 | Texture* render(TextureCache* texture_cache) override { |
4070 | 558 | if (show_spaces_) { | 558 | if (show_spaces_) { |
4071 | 559 | Texture* rv = new Texture(w_, h_); | 559 | Texture* rv = new Texture(w_, h_); |
4073 | 560 | rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(0xcc, 0, 0, 0xcc)); | 560 | rv->fill_rect(Rectf(0, 0, w_, h_), RGBAColor(0xcc, 0, 0, 0xcc)); |
4074 | 561 | return rv; | 561 | return rv; |
4075 | 562 | } | 562 | } |
4076 | 563 | return TextNode::render(texture_cache); | 563 | return TextNode::render(texture_cache); |
4077 | @@ -619,8 +619,8 @@ | |||
4078 | 619 | 619 | ||
4079 | 620 | // Draw background image (tiling) | 620 | // Draw background image (tiling) |
4080 | 621 | if (background_image_) { | 621 | if (background_image_) { |
4083 | 622 | Rect dst; | 622 | Rectf dst; |
4084 | 623 | Rect srcrect(Point(0, 0), 1, 1); | 623 | Rectf srcrect(0, 0, 1, 1); |
4085 | 624 | for (uint16_t curx = 0; curx < w_; curx += background_image_->width()) { | 624 | for (uint16_t curx = 0; curx < w_; curx += background_image_->width()) { |
4086 | 625 | dst.x = curx; | 625 | dst.x = curx; |
4087 | 626 | dst.y = 0; | 626 | dst.y = 0; |
4088 | @@ -629,7 +629,7 @@ | |||
4089 | 629 | rv->blit(dst, *background_image_, srcrect, 1., BlendMode::Copy); | 629 | rv->blit(dst, *background_image_, srcrect, 1., BlendMode::Copy); |
4090 | 630 | } | 630 | } |
4091 | 631 | } else { | 631 | } else { |
4093 | 632 | rv->fill_rect(Rect(0, 0, w_, h_), RGBAColor(255, 255, 255, 0)); | 632 | rv->fill_rect(Rectf(0, 0, w_, h_), RGBAColor(255, 255, 255, 0)); |
4094 | 633 | } | 633 | } |
4095 | 634 | return rv; | 634 | return rv; |
4096 | 635 | } | 635 | } |
4097 | @@ -689,19 +689,19 @@ | |||
4098 | 689 | throw TextureTooBig(error_message); | 689 | throw TextureTooBig(error_message); |
4099 | 690 | } | 690 | } |
4100 | 691 | Texture* rv = new Texture(width(), height()); | 691 | Texture* rv = new Texture(width(), height()); |
4102 | 692 | rv->fill_rect(Rect(0, 0, rv->width(), rv->height()), RGBAColor(255, 255, 255, 0)); | 692 | rv->fill_rect(Rectf(0, 0, rv->width(), rv->height()), RGBAColor(255, 255, 255, 0)); |
4103 | 693 | 693 | ||
4104 | 694 | // Draw Solid background Color | 694 | // Draw Solid background Color |
4105 | 695 | bool set_alpha = true; | 695 | bool set_alpha = true; |
4106 | 696 | if (is_background_color_set_) { | 696 | if (is_background_color_set_) { |
4108 | 697 | rv->fill_rect(Rect(Point(margin_.left, margin_.top), w_, h_), background_color_); | 697 | rv->fill_rect(Rectf(margin_.left, margin_.top, w_, h_), background_color_); |
4109 | 698 | set_alpha = false; | 698 | set_alpha = false; |
4110 | 699 | } | 699 | } |
4111 | 700 | 700 | ||
4112 | 701 | // Draw background image (tiling) | 701 | // Draw background image (tiling) |
4113 | 702 | if (background_image_) { | 702 | if (background_image_) { |
4116 | 703 | Rect dst; | 703 | Rectf dst; |
4117 | 704 | Rect src(0, 0, 0, 0); | 704 | Rectf src(0, 0, 0, 0); |
4118 | 705 | 705 | ||
4119 | 706 | for (uint16_t cury = margin_.top; cury < h_ + margin_.top; | 706 | for (uint16_t cury = margin_.top; cury < h_ + margin_.top; |
4120 | 707 | cury += background_image_->height()) { | 707 | cury += background_image_->height()) { |
4121 | @@ -720,10 +720,9 @@ | |||
4122 | 720 | for (RenderNode* n : nodes_to_render_) { | 720 | for (RenderNode* n : nodes_to_render_) { |
4123 | 721 | Texture* node_texture = n->render(texture_cache); | 721 | Texture* node_texture = n->render(texture_cache); |
4124 | 722 | if (node_texture) { | 722 | if (node_texture) { |
4126 | 723 | Rect dst = Rect(n->x() + margin_.left, n->y() + margin_.top, node_texture->width(), | 723 | Rectf dst(n->x() + margin_.left, n->y() + margin_.top, node_texture->width(), |
4127 | 724 | node_texture->height()); | 724 | node_texture->height()); |
4130 | 725 | Rect src = Rect(0, 0, node_texture->width(), node_texture->height()); | 725 | Rectf src(0, 0, node_texture->width(), node_texture->height()); |
4129 | 726 | |||
4131 | 727 | rv->blit( | 726 | rv->blit( |
4132 | 728 | dst, *node_texture, src, 1., set_alpha ? BlendMode::Copy : BlendMode::UseAlpha); | 727 | dst, *node_texture, src, 1., set_alpha ? BlendMode::Copy : BlendMode::UseAlpha); |
4133 | 729 | delete node_texture; | 728 | delete node_texture; |
4134 | @@ -754,7 +753,7 @@ | |||
4135 | 754 | nodes_to_render_ = n; | 753 | nodes_to_render_ = n; |
4136 | 755 | } | 754 | } |
4137 | 756 | void add_reference(int16_t gx, int16_t gy, uint16_t w, uint16_t h, const string& s) { | 755 | void add_reference(int16_t gx, int16_t gy, uint16_t w, uint16_t h, const string& s) { |
4139 | 757 | Reference r = {Rect(gx, gy, w, h), s}; | 756 | Reference r = {Recti(gx, gy, w, h), s}; |
4140 | 758 | refs_.push_back(r); | 757 | refs_.push_back(r); |
4141 | 759 | } | 758 | } |
4142 | 760 | 759 | ||
4143 | @@ -790,8 +789,8 @@ | |||
4144 | 790 | 789 | ||
4145 | 791 | Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) { | 790 | Texture* ImgRenderNode::render(TextureCache* /* texture_cache */) { |
4146 | 792 | Texture* rv = new Texture(image_.width(), image_.height()); | 791 | Texture* rv = new Texture(image_.width(), image_.height()); |
4149 | 793 | rv->blit(Rect(0, 0, image_.width(), image_.height()), image_, | 792 | rv->blit(Rectf(0, 0, image_.width(), image_.height()), image_, |
4150 | 794 | Rect(0, 0, image_.width(), image_.height()), 1., BlendMode::Copy); | 793 | Rectf(0, 0, image_.width(), image_.height()), 1., BlendMode::Copy); |
4151 | 795 | return rv; | 794 | return rv; |
4152 | 796 | } | 795 | } |
4153 | 797 | // End: Helper Stuff | 796 | // End: Helper Stuff |
4154 | 798 | 797 | ||
4155 | === modified file 'src/graphic/texture.cc' | |||
4156 | --- src/graphic/texture.cc 2016-08-04 15:49:05 +0000 | |||
4157 | +++ src/graphic/texture.cc 2016-10-24 20:07:47 +0000 | |||
4158 | @@ -144,14 +144,14 @@ | |||
4159 | 144 | SDL_FreeSurface(surface); | 144 | SDL_FreeSurface(surface); |
4160 | 145 | } | 145 | } |
4161 | 146 | 146 | ||
4163 | 147 | Texture::Texture(const GLuint texture, const Rect& subrect, int parent_w, int parent_h) | 147 | Texture::Texture(const GLuint texture, const Recti& subrect, int parent_w, int parent_h) |
4164 | 148 | : owns_texture_(false) { | 148 | : owns_texture_(false) { |
4165 | 149 | if (parent_w == 0 || parent_h == 0) { | 149 | if (parent_w == 0 || parent_h == 0) { |
4166 | 150 | throw wexception("Created a sub Texture with zero height and width parent."); | 150 | throw wexception("Created a sub Texture with zero height and width parent."); |
4167 | 151 | } | 151 | } |
4168 | 152 | 152 | ||
4169 | 153 | blit_data_ = BlitData{ | 153 | blit_data_ = BlitData{ |
4171 | 154 | texture, parent_w, parent_h, subrect, | 154 | texture, parent_w, parent_h, subrect.cast<float>(), |
4172 | 155 | }; | 155 | }; |
4173 | 156 | } | 156 | } |
4174 | 157 | 157 | ||
4175 | @@ -172,7 +172,7 @@ | |||
4176 | 172 | void Texture::init(uint16_t w, uint16_t h) { | 172 | void Texture::init(uint16_t w, uint16_t h) { |
4177 | 173 | blit_data_ = { | 173 | blit_data_ = { |
4178 | 174 | 0, // initialized below | 174 | 0, // initialized below |
4180 | 175 | w, h, Rect(0, 0, w, h), | 175 | w, h, Rectf(0, 0, w, h), |
4181 | 176 | }; | 176 | }; |
4182 | 177 | if (w * h == 0) { | 177 | if (w * h == 0) { |
4183 | 178 | return; | 178 | return; |
4184 | @@ -250,7 +250,7 @@ | |||
4185 | 250 | glViewport(0, 0, width(), height()); | 250 | glViewport(0, 0, width(), height()); |
4186 | 251 | } | 251 | } |
4187 | 252 | 252 | ||
4189 | 253 | void Texture::do_blit(const FloatRect& dst_rect, | 253 | void Texture::do_blit(const Rectf& dst_rect, |
4190 | 254 | const BlitData& texture, | 254 | const BlitData& texture, |
4191 | 255 | float opacity, | 255 | float opacity, |
4192 | 256 | BlendMode blend_mode) { | 256 | BlendMode blend_mode) { |
4193 | @@ -258,11 +258,11 @@ | |||
4194 | 258 | return; | 258 | return; |
4195 | 259 | } | 259 | } |
4196 | 260 | setup_gl(); | 260 | setup_gl(); |
4198 | 261 | BlitProgram::instance().draw(dst_rect, 0.f, texture, BlitData{0, 0, 0, Rect()}, | 261 | BlitProgram::instance().draw(dst_rect, 0.f, texture, BlitData{0, 0, 0, Rectf()}, |
4199 | 262 | RGBAColor(0, 0, 0, 255 * opacity), blend_mode); | 262 | RGBAColor(0, 0, 0, 255 * opacity), blend_mode); |
4200 | 263 | } | 263 | } |
4201 | 264 | 264 | ||
4203 | 265 | void Texture::do_blit_blended(const FloatRect& dst_rect, | 265 | void Texture::do_blit_blended(const Rectf& dst_rect, |
4204 | 266 | const BlitData& texture, | 266 | const BlitData& texture, |
4205 | 267 | const BlitData& mask, | 267 | const BlitData& mask, |
4206 | 268 | const RGBColor& blend) { | 268 | const RGBColor& blend) { |
4207 | @@ -274,7 +274,7 @@ | |||
4208 | 274 | BlitProgram::instance().draw(dst_rect, 0.f, texture, mask, blend, BlendMode::UseAlpha); | 274 | BlitProgram::instance().draw(dst_rect, 0.f, texture, mask, blend, BlendMode::UseAlpha); |
4209 | 275 | } | 275 | } |
4210 | 276 | 276 | ||
4212 | 277 | void Texture::do_blit_monochrome(const FloatRect& dst_rect, | 277 | void Texture::do_blit_monochrome(const Rectf& dst_rect, |
4213 | 278 | const BlitData& texture, | 278 | const BlitData& texture, |
4214 | 279 | const RGBAColor& blend) { | 279 | const RGBAColor& blend) { |
4215 | 280 | if (blit_data_.texture_id == 0) { | 280 | if (blit_data_.texture_id == 0) { |
4216 | @@ -293,9 +293,7 @@ | |||
4217 | 293 | {DrawLineProgram::Arguments{vertices, 0.f, BlendMode::UseAlpha}}); | 293 | {DrawLineProgram::Arguments{vertices, 0.f, BlendMode::UseAlpha}}); |
4218 | 294 | } | 294 | } |
4219 | 295 | 295 | ||
4223 | 296 | void Texture::do_fill_rect(const FloatRect& dst_rect, | 296 | void Texture::do_fill_rect(const Rectf& dst_rect, const RGBAColor& color, BlendMode blend_mode) { |
4221 | 297 | const RGBAColor& color, | ||
4222 | 298 | BlendMode blend_mode) { | ||
4224 | 299 | if (blit_data_.texture_id == 0) { | 297 | if (blit_data_.texture_id == 0) { |
4225 | 300 | return; | 298 | return; |
4226 | 301 | } | 299 | } |
4227 | 302 | 300 | ||
4228 | === modified file 'src/graphic/texture.h' | |||
4229 | --- src/graphic/texture.h 2016-08-04 15:49:05 +0000 | |||
4230 | +++ src/graphic/texture.h 2016-10-24 20:07:47 +0000 | |||
4231 | @@ -39,7 +39,7 @@ | |||
4232 | 39 | 39 | ||
4233 | 40 | // Create a logical texture that is a 'subrect' (in Pixel) in | 40 | // Create a logical texture that is a 'subrect' (in Pixel) in |
4234 | 41 | // another texture. Ownership of 'texture' is not taken. | 41 | // another texture. Ownership of 'texture' is not taken. |
4236 | 42 | Texture(const GLuint texture, const Rect& subrect, int parent_w, int parent_h); | 42 | Texture(const GLuint texture, const Recti& subrect, int parent_w, int parent_h); |
4237 | 43 | 43 | ||
4238 | 44 | virtual ~Texture(); | 44 | virtual ~Texture(); |
4239 | 45 | 45 | ||
4240 | @@ -83,20 +83,20 @@ | |||
4241 | 83 | void init(uint16_t w, uint16_t h); | 83 | void init(uint16_t w, uint16_t h); |
4242 | 84 | 84 | ||
4243 | 85 | // Implements surface. | 85 | // Implements surface. |
4245 | 86 | void do_blit(const FloatRect& dst_rect, | 86 | void do_blit(const Rectf& dst_rect, |
4246 | 87 | const BlitData& texture, | 87 | const BlitData& texture, |
4247 | 88 | float opacity, | 88 | float opacity, |
4248 | 89 | BlendMode blend_mode) override; | 89 | BlendMode blend_mode) override; |
4250 | 90 | void do_blit_blended(const FloatRect& dst_rect, | 90 | void do_blit_blended(const Rectf& dst_rect, |
4251 | 91 | const BlitData& texture, | 91 | const BlitData& texture, |
4252 | 92 | const BlitData& mask, | 92 | const BlitData& mask, |
4253 | 93 | const RGBColor& blend) override; | 93 | const RGBColor& blend) override; |
4255 | 94 | void do_blit_monochrome(const FloatRect& dst_rect, | 94 | void do_blit_monochrome(const Rectf& dst_rect, |
4256 | 95 | const BlitData& texture, | 95 | const BlitData& texture, |
4257 | 96 | const RGBAColor& blend) override; | 96 | const RGBAColor& blend) override; |
4258 | 97 | void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) override; | 97 | void do_draw_line_strip(std::vector<DrawLineProgram::PerVertexData> vertices) override; |
4259 | 98 | void | 98 | void |
4261 | 99 | do_fill_rect(const FloatRect& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; | 99 | do_fill_rect(const Rectf& dst_rect, const RGBAColor& color, BlendMode blend_mode) override; |
4262 | 100 | 100 | ||
4263 | 101 | // True if we own the texture, i.e. if we need to delete it. | 101 | // True if we own the texture, i.e. if we need to delete it. |
4264 | 102 | bool owns_texture_; | 102 | bool owns_texture_; |
4265 | 103 | 103 | ||
4266 | === modified file 'src/graphic/texture_atlas.cc' | |||
4267 | --- src/graphic/texture_atlas.cc 2016-08-04 15:49:05 +0000 | |||
4268 | +++ src/graphic/texture_atlas.cc 2016-10-24 20:07:47 +0000 | |||
4269 | @@ -34,14 +34,14 @@ | |||
4270 | 34 | 34 | ||
4271 | 35 | } // namespace | 35 | } // namespace |
4272 | 36 | 36 | ||
4274 | 37 | TextureAtlas::Node::Node(const Rect& init_r) : used(false), r(init_r) { | 37 | TextureAtlas::Node::Node(const Recti& init_r) : used(false), r(init_r) { |
4275 | 38 | } | 38 | } |
4276 | 39 | 39 | ||
4277 | 40 | void TextureAtlas::Node::split(int item_w, int item_h) { | 40 | void TextureAtlas::Node::split(int item_w, int item_h) { |
4278 | 41 | assert(!used); | 41 | assert(!used); |
4279 | 42 | 42 | ||
4282 | 43 | down.reset(new Node(Rect(r.x, r.y + item_h, r.w, r.h - item_h))); | 43 | down.reset(new Node(Recti(r.x, r.y + item_h, r.w, r.h - item_h))); |
4283 | 44 | right.reset(new Node(Rect(r.x + item_w, r.y, r.w - item_w, item_h))); | 44 | right.reset(new Node(Recti(r.x + item_w, r.y, r.w - item_w, item_h))); |
4284 | 45 | used = true; | 45 | used = true; |
4285 | 46 | 46 | ||
4286 | 47 | // Note: we do not change the size of the root. It is not needed | 47 | // Note: we do not change the size of the root. It is not needed |
4287 | @@ -77,21 +77,21 @@ | |||
4288 | 77 | std::unique_ptr<Texture> TextureAtlas::pack_as_many_as_possible( | 77 | std::unique_ptr<Texture> TextureAtlas::pack_as_many_as_possible( |
4289 | 78 | const int max_dimension, const int texture_atlas_index, std::vector<PackedTexture>* pack_info) { | 78 | const int max_dimension, const int texture_atlas_index, std::vector<PackedTexture>* pack_info) { |
4290 | 79 | 79 | ||
4293 | 80 | std::unique_ptr<Node> root(new Node(Rect(0, 0, blocks_.begin()->texture->width() + kPadding, | 80 | std::unique_ptr<Node> root(new Node(Recti(0, 0, blocks_.begin()->texture->width() + kPadding, |
4294 | 81 | blocks_.begin()->texture->height() + kPadding))); | 81 | blocks_.begin()->texture->height() + kPadding))); |
4295 | 82 | 82 | ||
4296 | 83 | const auto grow_right = [&root](int delta_w) { | 83 | const auto grow_right = [&root](int delta_w) { |
4298 | 84 | std::unique_ptr<Node> new_root(new Node(Rect(0, 0, root->r.w + delta_w, root->r.h))); | 84 | std::unique_ptr<Node> new_root(new Node(Recti(0, 0, root->r.w + delta_w, root->r.h))); |
4299 | 85 | new_root->used = true; | 85 | new_root->used = true; |
4301 | 86 | new_root->right.reset(new Node(Rect(root->r.w, 0, delta_w, root->r.h))); | 86 | new_root->right.reset(new Node(Recti(root->r.w, 0, delta_w, root->r.h))); |
4302 | 87 | new_root->down.reset(root.release()); | 87 | new_root->down.reset(root.release()); |
4303 | 88 | root.reset(new_root.release()); | 88 | root.reset(new_root.release()); |
4304 | 89 | }; | 89 | }; |
4305 | 90 | 90 | ||
4306 | 91 | const auto grow_down = [&root](int delta_h) { | 91 | const auto grow_down = [&root](int delta_h) { |
4308 | 92 | std::unique_ptr<Node> new_root(new Node(Rect(0, 0, root->r.w, root->r.h + delta_h))); | 92 | std::unique_ptr<Node> new_root(new Node(Recti(0, 0, root->r.w, root->r.h + delta_h))); |
4309 | 93 | new_root->used = true; | 93 | new_root->used = true; |
4311 | 94 | new_root->down.reset(new Node(Rect(0, root->r.h, root->r.w, delta_h))); | 94 | new_root->down.reset(new Node(Recti(0, root->r.h, root->r.w, delta_h))); |
4312 | 95 | new_root->right.reset(root.release()); | 95 | new_root->right.reset(root.release()); |
4313 | 96 | root.reset(new_root.release()); | 96 | root.reset(new_root.release()); |
4314 | 97 | }; | 97 | }; |
4315 | @@ -134,20 +134,20 @@ | |||
4316 | 134 | } | 134 | } |
4317 | 135 | 135 | ||
4318 | 136 | std::unique_ptr<Texture> texture_atlas(new Texture(root->r.w, root->r.h)); | 136 | std::unique_ptr<Texture> texture_atlas(new Texture(root->r.w, root->r.h)); |
4320 | 137 | texture_atlas->fill_rect(Rect(0, 0, root->r.w, root->r.h), RGBAColor(0, 0, 0, 0)); | 137 | texture_atlas->fill_rect(Rectf(0, 0, root->r.w, root->r.h), RGBAColor(0, 0, 0, 0)); |
4321 | 138 | 138 | ||
4322 | 139 | const auto packed_texture_id = texture_atlas->blit_data().texture_id; | 139 | const auto packed_texture_id = texture_atlas->blit_data().texture_id; |
4323 | 140 | for (Block& block : packed) { | 140 | for (Block& block : packed) { |
4324 | 141 | texture_atlas->blit( | 141 | texture_atlas->blit( |
4327 | 142 | Rect(block.node->r.x, block.node->r.y, block.texture->width(), block.texture->height()), | 142 | Rectf(block.node->r.x, block.node->r.y, block.texture->width(), block.texture->height()), |
4328 | 143 | *block.texture, Rect(0, 0, block.texture->width(), block.texture->height()), 1., | 143 | *block.texture, Rectf(0, 0, block.texture->width(), block.texture->height()), 1., |
4329 | 144 | BlendMode::Copy); | 144 | BlendMode::Copy); |
4330 | 145 | 145 | ||
4331 | 146 | pack_info->emplace_back(PackedTexture( | 146 | pack_info->emplace_back(PackedTexture( |
4332 | 147 | texture_atlas_index, block.index, | 147 | texture_atlas_index, block.index, |
4333 | 148 | std::unique_ptr<Texture>(new Texture( | 148 | std::unique_ptr<Texture>(new Texture( |
4334 | 149 | packed_texture_id, | 149 | packed_texture_id, |
4336 | 150 | Rect(block.node->r.origin(), block.texture->width(), block.texture->height()), | 150 | Recti(block.node->r.origin(), block.texture->width(), block.texture->height()), |
4337 | 151 | root->r.w, root->r.h)))); | 151 | root->r.w, root->r.h)))); |
4338 | 152 | } | 152 | } |
4339 | 153 | blocks_ = not_packed; | 153 | blocks_ = not_packed; |
4340 | 154 | 154 | ||
4341 | === modified file 'src/graphic/texture_atlas.h' | |||
4342 | --- src/graphic/texture_atlas.h 2016-08-04 15:49:05 +0000 | |||
4343 | +++ src/graphic/texture_atlas.h 2016-10-24 20:07:47 +0000 | |||
4344 | @@ -68,11 +68,11 @@ | |||
4345 | 68 | 68 | ||
4346 | 69 | private: | 69 | private: |
4347 | 70 | struct Node { | 70 | struct Node { |
4349 | 71 | Node(const Rect& init_r); | 71 | Node(const Recti& init_r); |
4350 | 72 | void split(int w, int h); | 72 | void split(int w, int h); |
4351 | 73 | 73 | ||
4352 | 74 | bool used; | 74 | bool used; |
4354 | 75 | Rect r; | 75 | Recti r; |
4355 | 76 | std::unique_ptr<Node> right; | 76 | std::unique_ptr<Node> right; |
4356 | 77 | std::unique_ptr<Node> down; | 77 | std::unique_ptr<Node> down; |
4357 | 78 | 78 | ||
4358 | 79 | 79 | ||
4359 | === modified file 'src/graphic/wordwrap.cc' | |||
4360 | --- src/graphic/wordwrap.cc 2016-08-04 15:49:05 +0000 | |||
4361 | +++ src/graphic/wordwrap.cc 2016-10-24 20:07:47 +0000 | |||
4362 | @@ -303,7 +303,7 @@ | |||
4363 | 303 | * | 303 | * |
4364 | 304 | * \note This also draws the caret, if any. | 304 | * \note This also draws the caret, if any. |
4365 | 305 | */ | 305 | */ |
4367 | 306 | void WordWrap::draw(RenderTarget& dst, Point where, Align align, uint32_t caret) { | 306 | void WordWrap::draw(RenderTarget& dst, Vector2i where, Align align, uint32_t caret) { |
4368 | 307 | if (lines_.empty()) | 307 | if (lines_.empty()) |
4369 | 308 | return; | 308 | return; |
4370 | 309 | 309 | ||
4371 | @@ -329,7 +329,7 @@ | |||
4372 | 329 | if (where.y >= dst.height() || int32_t(where.y + fontheight) <= 0) | 329 | if (where.y >= dst.height() || int32_t(where.y + fontheight) <= 0) |
4373 | 330 | continue; | 330 | continue; |
4374 | 331 | 331 | ||
4376 | 332 | Point point(where.x, where.y); | 332 | Vector2f point(where.x, where.y); |
4377 | 333 | 333 | ||
4378 | 334 | if (static_cast<int>(alignment & UI::Align::kRight)) { | 334 | if (static_cast<int>(alignment & UI::Align::kRight)) { |
4379 | 335 | point.x += wrapwidth_ - LINE_MARGIN; | 335 | point.x += wrapwidth_ - LINE_MARGIN; |
4380 | @@ -346,9 +346,9 @@ | |||
4381 | 346 | int caret_x = text_width(line_to_caret, style_.font->size()); | 346 | int caret_x = text_width(line_to_caret, style_.font->size()); |
4382 | 347 | 347 | ||
4383 | 348 | const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png"); | 348 | const Image* caret_image = g_gr->images().get("images/ui_basic/caret.png"); |
4385 | 349 | Point caretpt; | 349 | Vector2f caretpt; |
4386 | 350 | caretpt.x = point.x + caret_x - caret_image->width() + LINE_MARGIN; | 350 | caretpt.x = point.x + caret_x - caret_image->width() + LINE_MARGIN; |
4388 | 351 | caretpt.y = point.y + (fontheight - caret_image->height()) / 2; | 351 | caretpt.y = point.y + (fontheight - caret_image->height()) / 2.f; |
4389 | 352 | dst.blit(caretpt, caret_image); | 352 | dst.blit(caretpt, caret_image); |
4390 | 353 | } | 353 | } |
4391 | 354 | } | 354 | } |
4392 | 355 | 355 | ||
4393 | === modified file 'src/graphic/wordwrap.h' | |||
4394 | --- src/graphic/wordwrap.h 2016-08-04 15:49:05 +0000 | |||
4395 | +++ src/graphic/wordwrap.h 2016-10-24 20:07:47 +0000 | |||
4396 | @@ -21,7 +21,7 @@ | |||
4397 | 21 | 21 | ||
4398 | 22 | #include <string> | 22 | #include <string> |
4399 | 23 | 23 | ||
4401 | 24 | #include "base/point.h" | 24 | #include "base/vector.h" |
4402 | 25 | #include "graphic/align.h" | 25 | #include "graphic/align.h" |
4403 | 26 | #include "graphic/text_layout.h" | 26 | #include "graphic/text_layout.h" |
4404 | 27 | 27 | ||
4405 | @@ -50,7 +50,7 @@ | |||
4406 | 50 | } | 50 | } |
4407 | 51 | 51 | ||
4408 | 52 | void draw(RenderTarget& dst, | 52 | void draw(RenderTarget& dst, |
4410 | 53 | Point where, | 53 | Vector2i where, |
4411 | 54 | Align align = UI::Align::kLeft, | 54 | Align align = UI::Align::kLeft, |
4412 | 55 | uint32_t caret = std::numeric_limits<uint32_t>::max()); | 55 | uint32_t caret = std::numeric_limits<uint32_t>::max()); |
4413 | 56 | 56 | ||
4414 | 57 | 57 | ||
4415 | === modified file 'src/io/streamread.cc' | |||
4416 | --- src/io/streamread.cc 2016-08-04 15:49:05 +0000 | |||
4417 | +++ src/io/streamread.cc 2016-10-24 20:07:47 +0000 | |||
4418 | @@ -22,6 +22,7 @@ | |||
4419 | 22 | #include <cassert> | 22 | #include <cassert> |
4420 | 23 | #include <cstdarg> | 23 | #include <cstdarg> |
4421 | 24 | #include <cstdio> | 24 | #include <cstdio> |
4422 | 25 | #include <cstring> | ||
4423 | 25 | 26 | ||
4424 | 26 | #include "base/wexception.h" | 27 | #include "base/wexception.h" |
4425 | 27 | 28 | ||
4426 | @@ -89,6 +90,15 @@ | |||
4427 | 89 | return little_32(x); | 90 | return little_32(x); |
4428 | 90 | } | 91 | } |
4429 | 91 | 92 | ||
4430 | 93 | float StreamRead::float_32() { | ||
4431 | 94 | uint32_t x; | ||
4432 | 95 | data_complete(&x, 4); | ||
4433 | 96 | x = little_32(x); | ||
4434 | 97 | float rv; | ||
4435 | 98 | memcpy(&rv, &x, 4); | ||
4436 | 99 | return rv; | ||
4437 | 100 | } | ||
4438 | 101 | |||
4439 | 92 | std::string StreamRead::string() { | 102 | std::string StreamRead::string() { |
4440 | 93 | std::string x; | 103 | std::string x; |
4441 | 94 | char ch; | 104 | char ch; |
4442 | 95 | 105 | ||
4443 | === modified file 'src/io/streamread.h' | |||
4444 | --- src/io/streamread.h 2016-08-04 15:49:05 +0000 | |||
4445 | +++ src/io/streamread.h 2016-10-24 20:07:47 +0000 | |||
4446 | @@ -67,6 +67,7 @@ | |||
4447 | 67 | uint16_t unsigned_16(); | 67 | uint16_t unsigned_16(); |
4448 | 68 | int32_t signed_32(); | 68 | int32_t signed_32(); |
4449 | 69 | uint32_t unsigned_32(); | 69 | uint32_t unsigned_32(); |
4450 | 70 | float float_32(); | ||
4451 | 70 | std::string string(); | 71 | std::string string(); |
4452 | 71 | virtual char const* c_string() { | 72 | virtual char const* c_string() { |
4453 | 72 | throw; | 73 | throw; |
4454 | 73 | 74 | ||
4455 | === modified file 'src/io/streamwrite.cc' | |||
4456 | --- src/io/streamwrite.cc 2016-08-04 15:49:05 +0000 | |||
4457 | +++ src/io/streamwrite.cc 2016-10-24 20:07:47 +0000 | |||
4458 | @@ -20,6 +20,7 @@ | |||
4459 | 20 | #include "io/streamwrite.h" | 20 | #include "io/streamwrite.h" |
4460 | 21 | 21 | ||
4461 | 22 | #include <cstdarg> | 22 | #include <cstdarg> |
4462 | 23 | #include <cstring> | ||
4463 | 23 | 24 | ||
4464 | 24 | #include "base/wexception.h" | 25 | #include "base/wexception.h" |
4465 | 25 | 26 | ||
4466 | 26 | 27 | ||
4467 | === modified file 'src/io/streamwrite.h' | |||
4468 | --- src/io/streamwrite.h 2016-08-04 15:49:05 +0000 | |||
4469 | +++ src/io/streamwrite.h 2016-10-24 20:07:47 +0000 | |||
4470 | @@ -82,6 +82,12 @@ | |||
4471 | 82 | uint32_t const y = little_32(x); | 82 | uint32_t const y = little_32(x); |
4472 | 83 | data(&y, 4); | 83 | data(&y, 4); |
4473 | 84 | } | 84 | } |
4474 | 85 | void float_32(const float x) { | ||
4475 | 86 | uint32_t y; | ||
4476 | 87 | memcpy(&y, &x, 4); | ||
4477 | 88 | y = little_32(y); | ||
4478 | 89 | data(&y, 4); | ||
4479 | 90 | } | ||
4480 | 85 | void string(const std::string& str) { | 91 | void string(const std::string& str) { |
4481 | 86 | data(str.c_str(), str.size() + 1); | 92 | data(str.c_str(), str.size() + 1); |
4482 | 87 | } | 93 | } |
4483 | 88 | 94 | ||
4484 | === modified file 'src/logic/CMakeLists.txt' | |||
4485 | --- src/logic/CMakeLists.txt 2016-05-14 07:35:39 +0000 | |||
4486 | +++ src/logic/CMakeLists.txt 2016-10-24 20:07:47 +0000 | |||
4487 | @@ -119,6 +119,7 @@ | |||
4488 | 119 | widelands_geometry_io.cc | 119 | widelands_geometry_io.cc |
4489 | 120 | widelands_geometry_io.h | 120 | widelands_geometry_io.h |
4490 | 121 | widelands.h | 121 | widelands.h |
4491 | 122 | map_objects/draw_text.h | ||
4492 | 122 | map_objects/attackable.h | 123 | map_objects/attackable.h |
4493 | 123 | map_objects/bob.cc | 124 | map_objects/bob.cc |
4494 | 124 | map_objects/bob.h | 125 | map_objects/bob.h |
4495 | @@ -126,15 +127,13 @@ | |||
4496 | 126 | map_objects/buildcost.h | 127 | map_objects/buildcost.h |
4497 | 127 | map_objects/checkstep.cc | 128 | map_objects/checkstep.cc |
4498 | 128 | map_objects/checkstep.h | 129 | map_objects/checkstep.h |
4499 | 129 | map_objects/immovable_program.h | ||
4500 | 130 | map_objects/immovable.cc | 130 | map_objects/immovable.cc |
4501 | 131 | map_objects/immovable.h | 131 | map_objects/immovable.h |
4502 | 132 | map_objects/immovable_program.h | ||
4503 | 132 | map_objects/map_object.cc | 133 | map_objects/map_object.cc |
4504 | 133 | map_objects/map_object.h | 134 | map_objects/map_object.h |
4505 | 134 | map_objects/terrain_affinity.cc | 135 | map_objects/terrain_affinity.cc |
4506 | 135 | map_objects/terrain_affinity.h | 136 | map_objects/terrain_affinity.h |
4507 | 136 | map_objects/walkingdir.cc | ||
4508 | 137 | map_objects/walkingdir.h | ||
4509 | 138 | map_objects/tribes/battle.cc | 137 | map_objects/tribes/battle.cc |
4510 | 139 | map_objects/tribes/battle.h | 138 | map_objects/tribes/battle.h |
4511 | 140 | map_objects/tribes/bill_of_materials.h | 139 | map_objects/tribes/bill_of_materials.h |
4512 | @@ -181,15 +180,17 @@ | |||
4513 | 181 | map_objects/tribes/warelist.h | 180 | map_objects/tribes/warelist.h |
4514 | 182 | map_objects/tribes/wareworker.h | 181 | map_objects/tribes/wareworker.h |
4515 | 183 | map_objects/tribes/workarea_info.h | 182 | map_objects/tribes/workarea_info.h |
4516 | 183 | map_objects/tribes/worker.cc | ||
4517 | 184 | map_objects/tribes/worker.h | ||
4518 | 184 | map_objects/tribes/worker_descr.cc | 185 | map_objects/tribes/worker_descr.cc |
4519 | 185 | map_objects/tribes/worker_descr.h | 186 | map_objects/tribes/worker_descr.h |
4520 | 186 | map_objects/tribes/worker_program.cc | 187 | map_objects/tribes/worker_program.cc |
4521 | 187 | map_objects/tribes/worker_program.h | 188 | map_objects/tribes/worker_program.h |
4525 | 188 | map_objects/tribes/worker.cc | 189 | map_objects/walkingdir.cc |
4526 | 189 | map_objects/tribes/worker.h | 190 | map_objects/walkingdir.h |
4524 | 190 | map_objects/world/critter_program.h | ||
4527 | 191 | map_objects/world/critter.cc | 191 | map_objects/world/critter.cc |
4528 | 192 | map_objects/world/critter.h | 192 | map_objects/world/critter.h |
4529 | 193 | map_objects/world/critter_program.h | ||
4530 | 193 | map_objects/world/editor_category.cc | 194 | map_objects/world/editor_category.cc |
4531 | 194 | map_objects/world/editor_category.h | 195 | map_objects/world/editor_category.h |
4532 | 195 | map_objects/world/map_gen.cc | 196 | map_objects/world/map_gen.cc |
4533 | @@ -209,6 +210,7 @@ | |||
4534 | 209 | base_i18n | 210 | base_i18n |
4535 | 210 | base_log | 211 | base_log |
4536 | 211 | base_macros | 212 | base_macros |
4537 | 213 | base_math | ||
4538 | 212 | base_md5 | 214 | base_md5 |
4539 | 213 | base_scoped_timer | 215 | base_scoped_timer |
4540 | 214 | base_time_string | 216 | base_time_string |
4541 | 215 | 217 | ||
4542 | === modified file 'src/logic/game.cc' | |||
4543 | --- src/logic/game.cc 2016-08-04 15:49:05 +0000 | |||
4544 | +++ src/logic/game.cc 2016-10-24 20:07:47 +0000 | |||
4545 | @@ -455,7 +455,7 @@ | |||
4546 | 455 | } | 455 | } |
4547 | 456 | 456 | ||
4548 | 457 | if (get_ipl()) | 457 | if (get_ipl()) |
4550 | 458 | get_ipl()->move_view_to(map().get_starting_pos(get_ipl()->player_number())); | 458 | get_ipl()->center_view_on_coords(map().get_starting_pos(get_ipl()->player_number())); |
4551 | 459 | 459 | ||
4552 | 460 | // Prepare the map, set default textures | 460 | // Prepare the map, set default textures |
4553 | 461 | map().recalc_default_resources(world()); | 461 | map().recalc_default_resources(world()); |
4554 | 462 | 462 | ||
4555 | === modified file 'src/logic/game_controller.h' | |||
4556 | --- src/logic/game_controller.h 2016-08-04 15:49:05 +0000 | |||
4557 | +++ src/logic/game_controller.h 2016-10-24 20:07:47 +0000 | |||
4558 | @@ -100,9 +100,6 @@ | |||
4559 | 100 | /** | 100 | /** |
4560 | 101 | * Report a player result once he has left the game. This may be done through lua | 101 | * Report a player result once he has left the game. This may be done through lua |
4561 | 102 | * by the win_condition scripts. | 102 | * by the win_condition scripts. |
4562 | 103 | * \param player : the player idx; | ||
4563 | 104 | * \param result : the player result | ||
4564 | 105 | * \param info : The info string (\see \struct PlayerEndStatus) | ||
4565 | 106 | */ | 103 | */ |
4566 | 107 | virtual void report_result(uint8_t /* player */, | 104 | virtual void report_result(uint8_t /* player */, |
4567 | 108 | Widelands::PlayerEndResult /*result*/, | 105 | Widelands::PlayerEndResult /*result*/, |
4568 | 109 | 106 | ||
4569 | === modified file 'src/logic/map_objects/bob.cc' | |||
4570 | --- src/logic/map_objects/bob.cc 2016-08-04 15:49:05 +0000 | |||
4571 | +++ src/logic/map_objects/bob.cc 2016-10-24 20:07:47 +0000 | |||
4572 | @@ -25,6 +25,7 @@ | |||
4573 | 25 | #include <stdint.h> | 25 | #include <stdint.h> |
4574 | 26 | 26 | ||
4575 | 27 | #include "base/macros.h" | 27 | #include "base/macros.h" |
4576 | 28 | #include "base/math.h" | ||
4577 | 28 | #include "base/wexception.h" | 29 | #include "base/wexception.h" |
4578 | 29 | #include "economy/route.h" | 30 | #include "economy/route.h" |
4579 | 30 | #include "economy/transfer.h" | 31 | #include "economy/transfer.h" |
4580 | @@ -88,7 +89,6 @@ | |||
4581 | 88 | 89 | ||
4582 | 89 | Bob::Bob(const BobDescr& init_descr) | 90 | Bob::Bob(const BobDescr& init_descr) |
4583 | 90 | : MapObject(&init_descr), | 91 | : MapObject(&init_descr), |
4584 | 91 | owner_(nullptr), | ||
4585 | 92 | position_(FCoords(Coords(0, 0), nullptr)), // not linked anywhere | 92 | position_(FCoords(Coords(0, 0), nullptr)), // not linked anywhere |
4586 | 93 | linknext_(nullptr), | 93 | linknext_(nullptr), |
4587 | 94 | linkpprev_(nullptr), | 94 | linkpprev_(nullptr), |
4588 | @@ -685,45 +685,51 @@ | |||
4589 | 685 | return schedule_act(game, walkend_ - game.get_gametime()); | 685 | return schedule_act(game, walkend_ - game.get_gametime()); |
4590 | 686 | } | 686 | } |
4591 | 687 | 687 | ||
4598 | 688 | /// Calculates the actual position to draw on from the base node position. | 688 | // Calculates the actual position to draw on from the base node position. This |
4599 | 689 | /// This function takes walking etc. into account. | 689 | // function takes walking etc. into account. |
4600 | 690 | /// | 690 | // |
4601 | 691 | /// pos is the location, in pixels, of the node position_ (height is already | 691 | // pos is the location, in pixels, of the node position_ on screen with scale |
4602 | 692 | /// taken into account). | 692 | // and height taken into account. |
4603 | 693 | Point Bob::calc_drawpos(const EditorGameBase& game, const Point pos) const { | 693 | Vector2f Bob::calc_drawpos(const EditorGameBase& game, |
4604 | 694 | const Vector2f& field_on_dst, | ||
4605 | 695 | const float scale) const { | ||
4606 | 694 | const Map& map = game.get_map(); | 696 | const Map& map = game.get_map(); |
4607 | 695 | const FCoords end = position_; | 697 | const FCoords end = position_; |
4608 | 696 | FCoords start; | 698 | FCoords start; |
4610 | 697 | Point spos = pos, epos = pos; | 699 | Vector2f spos = field_on_dst; |
4611 | 700 | Vector2f epos = field_on_dst; | ||
4612 | 701 | |||
4613 | 702 | const float triangle_w = kTriangleWidth * scale; | ||
4614 | 703 | const float triangle_h = kTriangleHeight * scale; | ||
4615 | 698 | 704 | ||
4616 | 699 | switch (walking_) { | 705 | switch (walking_) { |
4617 | 700 | case WALK_NW: | 706 | case WALK_NW: |
4618 | 701 | map.get_brn(end, &start); | 707 | map.get_brn(end, &start); |
4621 | 702 | spos.x += kTriangleWidth / 2; | 708 | spos.x += triangle_w / 2.f; |
4622 | 703 | spos.y += kTriangleHeight; | 709 | spos.y += triangle_h; |
4623 | 704 | break; | 710 | break; |
4624 | 705 | case WALK_NE: | 711 | case WALK_NE: |
4625 | 706 | map.get_bln(end, &start); | 712 | map.get_bln(end, &start); |
4628 | 707 | spos.x -= kTriangleWidth / 2; | 713 | spos.x -= triangle_w / 2.f; |
4629 | 708 | spos.y += kTriangleHeight; | 714 | spos.y += triangle_h; |
4630 | 709 | break; | 715 | break; |
4631 | 710 | case WALK_W: | 716 | case WALK_W: |
4632 | 711 | map.get_rn(end, &start); | 717 | map.get_rn(end, &start); |
4634 | 712 | spos.x += kTriangleWidth; | 718 | spos.x += triangle_w; |
4635 | 713 | break; | 719 | break; |
4636 | 714 | case WALK_E: | 720 | case WALK_E: |
4637 | 715 | map.get_ln(end, &start); | 721 | map.get_ln(end, &start); |
4639 | 716 | spos.x -= kTriangleWidth; | 722 | spos.x -= triangle_w; |
4640 | 717 | break; | 723 | break; |
4641 | 718 | case WALK_SW: | 724 | case WALK_SW: |
4642 | 719 | map.get_trn(end, &start); | 725 | map.get_trn(end, &start); |
4645 | 720 | spos.x += kTriangleWidth / 2; | 726 | spos.x += triangle_w / 2.f; |
4646 | 721 | spos.y -= kTriangleHeight; | 727 | spos.y -= triangle_h; |
4647 | 722 | break; | 728 | break; |
4648 | 723 | case WALK_SE: | 729 | case WALK_SE: |
4649 | 724 | map.get_tln(end, &start); | 730 | map.get_tln(end, &start); |
4652 | 725 | spos.x -= kTriangleWidth / 2; | 731 | spos.x -= triangle_w / 2.f; |
4653 | 726 | spos.y -= kTriangleHeight; | 732 | spos.y -= triangle_h; |
4654 | 727 | break; | 733 | break; |
4655 | 728 | 734 | ||
4656 | 729 | case IDLE: | 735 | case IDLE: |
4657 | @@ -732,37 +738,39 @@ | |||
4658 | 732 | } | 738 | } |
4659 | 733 | 739 | ||
4660 | 734 | if (start.field) { | 740 | if (start.field) { |
4663 | 735 | spos.y += end.field->get_height() * kHeightFactor; | 741 | spos.y += end.field->get_height() * kHeightFactor * scale; |
4664 | 736 | spos.y -= start.field->get_height() * kHeightFactor; | 742 | spos.y -= start.field->get_height() * kHeightFactor * scale; |
4665 | 737 | 743 | ||
4666 | 738 | assert(static_cast<uint32_t>(walkstart_) <= game.get_gametime()); | 744 | assert(static_cast<uint32_t>(walkstart_) <= game.get_gametime()); |
4667 | 739 | assert(walkstart_ < walkend_); | 745 | assert(walkstart_ < walkend_); |
4677 | 740 | float f = static_cast<float>(game.get_gametime() - walkstart_) / (walkend_ - walkstart_); | 746 | const float f = math::clamp( |
4678 | 741 | 747 | static_cast<float>(game.get_gametime() - walkstart_) / (walkend_ - walkstart_), | |
4679 | 742 | if (f < 0) | 748 | 0.f, 1.f); |
4680 | 743 | f = 0; | 749 | epos.x = f * epos.x + (1.f - f) * spos.x; |
4681 | 744 | else if (f > 1) | 750 | epos.y = f * epos.y + (1.f - f) * spos.y; |
4673 | 745 | f = 1; | ||
4674 | 746 | |||
4675 | 747 | epos.x = static_cast<int32_t>(f * epos.x + (1 - f) * spos.x); | ||
4676 | 748 | epos.y = static_cast<int32_t>(f * epos.y + (1 - f) * spos.y); | ||
4682 | 749 | } | 751 | } |
4683 | 750 | |||
4684 | 751 | return epos; | 752 | return epos; |
4685 | 752 | } | 753 | } |
4686 | 753 | 754 | ||
4687 | 754 | /// It LERPs between start and end position when we are walking. | 755 | /// It LERPs between start and end position when we are walking. |
4688 | 755 | /// Note that the current node is actually the node that we are walking to, not | 756 | /// Note that the current node is actually the node that we are walking to, not |
4689 | 756 | /// the the one that we start from. | 757 | /// the the one that we start from. |
4699 | 757 | void Bob::draw(const EditorGameBase& egbase, RenderTarget& dst, const Point& pos) const { | 758 | void Bob::draw(const EditorGameBase& egbase, |
4700 | 758 | if (anim_) { | 759 | const DrawText&, |
4701 | 759 | auto* const owner = get_owner(); | 760 | const Vector2f& field_on_dst, |
4702 | 760 | if (owner != nullptr) { | 761 | const float scale, |
4703 | 761 | dst.blit_animation(calc_drawpos(egbase, pos), anim_, egbase.get_gametime() - animstart_, | 762 | RenderTarget* dst) const { |
4704 | 762 | owner->get_playercolor()); | 763 | if (!anim_) { |
4705 | 763 | } else { | 764 | return; |
4706 | 764 | dst.blit_animation(calc_drawpos(egbase, pos), anim_, egbase.get_gametime() - animstart_); | 765 | } |
4707 | 765 | } | 766 | |
4708 | 767 | auto* const owner = get_owner(); | ||
4709 | 768 | const Vector2f point_on_dst = calc_drawpos(egbase, field_on_dst, scale); | ||
4710 | 769 | if (owner != nullptr) { | ||
4711 | 770 | dst->blit_animation( | ||
4712 | 771 | point_on_dst, scale, anim_, egbase.get_gametime() - animstart_, owner->get_playercolor()); | ||
4713 | 772 | } else { | ||
4714 | 773 | dst->blit_animation(point_on_dst, scale, anim_, egbase.get_gametime() - animstart_); | ||
4715 | 766 | } | 774 | } |
4716 | 767 | } | 775 | } |
4717 | 768 | 776 | ||
4718 | 769 | 777 | ||
4719 | === modified file 'src/logic/map_objects/bob.h' | |||
4720 | --- src/logic/map_objects/bob.h 2016-08-04 15:49:05 +0000 | |||
4721 | +++ src/logic/map_objects/bob.h 2016-10-24 20:07:47 +0000 | |||
4722 | @@ -21,10 +21,11 @@ | |||
4723 | 21 | #define WL_LOGIC_MAP_OBJECTS_BOB_H | 21 | #define WL_LOGIC_MAP_OBJECTS_BOB_H |
4724 | 22 | 22 | ||
4725 | 23 | #include "base/macros.h" | 23 | #include "base/macros.h" |
4727 | 24 | #include "base/point.h" | 24 | #include "base/vector.h" |
4728 | 25 | #include "economy/route.h" | 25 | #include "economy/route.h" |
4729 | 26 | #include "graphic/animation.h" | 26 | #include "graphic/animation.h" |
4730 | 27 | #include "graphic/diranimations.h" | 27 | #include "graphic/diranimations.h" |
4731 | 28 | #include "logic/map_objects/draw_text.h" | ||
4732 | 28 | #include "logic/map_objects/map_object.h" | 29 | #include "logic/map_objects/map_object.h" |
4733 | 29 | #include "logic/map_objects/walkingdir.h" | 30 | #include "logic/map_objects/walkingdir.h" |
4734 | 30 | #include "logic/widelands_geometry.h" | 31 | #include "logic/widelands_geometry.h" |
4735 | @@ -240,11 +241,9 @@ | |||
4736 | 240 | void schedule_destroy(Game&); | 241 | void schedule_destroy(Game&); |
4737 | 241 | void schedule_act(Game&, uint32_t tdelta); | 242 | void schedule_act(Game&, uint32_t tdelta); |
4738 | 242 | void skip_act(); | 243 | void skip_act(); |
4740 | 243 | Point calc_drawpos(const EditorGameBase&, Point) const; | 244 | Vector2f calc_drawpos(const EditorGameBase&, const Vector2f& field_on_dst, float scale) const; |
4741 | 244 | void set_owner(Player*); | 245 | void set_owner(Player*); |
4745 | 245 | Player* get_owner() const { | 246 | |
4743 | 246 | return owner_; | ||
4744 | 247 | } | ||
4746 | 248 | void set_position(EditorGameBase&, const Coords&); | 247 | void set_position(EditorGameBase&, const Coords&); |
4747 | 249 | const FCoords& get_position() const { | 248 | const FCoords& get_position() const { |
4748 | 250 | return position_; | 249 | return position_; |
4749 | @@ -260,7 +259,15 @@ | |||
4750 | 260 | /// onto the \p to node if this function allows it to. | 259 | /// onto the \p to node if this function allows it to. |
4751 | 261 | virtual bool check_node_blocked(Game&, const FCoords&, bool commit); | 260 | virtual bool check_node_blocked(Game&, const FCoords&, bool commit); |
4752 | 262 | 261 | ||
4754 | 263 | virtual void draw(const EditorGameBase&, RenderTarget&, const Point&) const; | 262 | // Draws the bob onto the screen with 'field_on_dst' being the position of |
4755 | 263 | // the field associated with this bob (if it is walking, that is its | ||
4756 | 264 | // starting field) in pixel space of 'dst' (including scale). The 'scale' is | ||
4757 | 265 | // required to draw the bob in the right size. | ||
4758 | 266 | virtual void draw(const EditorGameBase&, | ||
4759 | 267 | const DrawText& draw_text, | ||
4760 | 268 | const Vector2f& field_on_dst, | ||
4761 | 269 | float scale, | ||
4762 | 270 | RenderTarget* dst) const; | ||
4763 | 264 | 271 | ||
4764 | 265 | // For debug | 272 | // For debug |
4765 | 266 | void log_general_info(const EditorGameBase&) override; | 273 | void log_general_info(const EditorGameBase&) override; |
4766 | @@ -366,7 +373,6 @@ | |||
4767 | 366 | static Task const taskMovepath; | 373 | static Task const taskMovepath; |
4768 | 367 | static Task const taskMove; | 374 | static Task const taskMove; |
4769 | 368 | 375 | ||
4770 | 369 | Player* owner_; ///< can be 0 | ||
4771 | 370 | FCoords position_; ///< where are we right now? | 376 | FCoords position_; ///< where are we right now? |
4772 | 371 | Bob* linknext_; ///< next object on this node | 377 | Bob* linknext_; ///< next object on this node |
4773 | 372 | Bob** linkpprev_; | 378 | Bob** linkpprev_; |
4774 | 373 | 379 | ||
4775 | === added file 'src/logic/map_objects/draw_text.h' | |||
4776 | --- src/logic/map_objects/draw_text.h 1970-01-01 00:00:00 +0000 | |||
4777 | +++ src/logic/map_objects/draw_text.h 2016-10-24 20:07:47 +0000 | |||
4778 | @@ -0,0 +1,34 @@ | |||
4779 | 1 | /* | ||
4780 | 2 | * Copyright (C) 2006-2016 by the Widelands Development Team | ||
4781 | 3 | * | ||
4782 | 4 | * This program is free software; you can redistribute it and/or | ||
4783 | 5 | * modify it under the terms of the GNU General Public License | ||
4784 | 6 | * as published by the Free Software Foundation; either version 2 | ||
4785 | 7 | * of the License, or (at your option) any later version. | ||
4786 | 8 | * | ||
4787 | 9 | * This program is distributed in the hope that it will be useful, | ||
4788 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4789 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4790 | 12 | * GNU General Public License for more details. | ||
4791 | 13 | * | ||
4792 | 14 | * You should have received a copy of the GNU General Public License | ||
4793 | 15 | * along with this program; if not, write to the Free Software | ||
4794 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
4795 | 17 | * | ||
4796 | 18 | */ | ||
4797 | 19 | |||
4798 | 20 | #ifndef WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H | ||
4799 | 21 | #define WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H | ||
4800 | 22 | |||
4801 | 23 | enum DrawText { | ||
4802 | 24 | kNone = 0, | ||
4803 | 25 | kCensus = 1, | ||
4804 | 26 | kStatistics = 2, | ||
4805 | 27 | }; | ||
4806 | 28 | |||
4807 | 29 | inline DrawText operator|(DrawText a, DrawText b) { | ||
4808 | 30 | return static_cast<DrawText>(static_cast<int>(a) | static_cast<int>(b)); | ||
4809 | 31 | } | ||
4810 | 32 | |||
4811 | 33 | #endif // end of include guard: WL_LOGIC_MAP_OBJECTS_DRAW_TEXT_H | ||
4812 | 34 | |||
4813 | 0 | 35 | ||
4814 | === modified file 'src/logic/map_objects/immovable.cc' | |||
4815 | --- src/logic/map_objects/immovable.cc 2016-08-04 15:49:05 +0000 | |||
4816 | +++ src/logic/map_objects/immovable.cc 2016-10-24 20:07:47 +0000 | |||
4817 | @@ -324,7 +324,6 @@ | |||
4818 | 324 | * Create an immovable of this type | 324 | * Create an immovable of this type |
4819 | 325 | */ | 325 | */ |
4820 | 326 | Immovable& ImmovableDescr::create(EditorGameBase& egbase, const Coords& coords) const { | 326 | Immovable& ImmovableDescr::create(EditorGameBase& egbase, const Coords& coords) const { |
4821 | 327 | assert(this != nullptr); | ||
4822 | 328 | Immovable& result = *new Immovable(*this); | 327 | Immovable& result = *new Immovable(*this); |
4823 | 329 | result.position_ = coords; | 328 | result.position_ = coords; |
4824 | 330 | result.init(egbase); | 329 | result.init(egbase); |
4825 | @@ -341,7 +340,6 @@ | |||
4826 | 341 | 340 | ||
4827 | 342 | Immovable::Immovable(const ImmovableDescr& imm_descr) | 341 | Immovable::Immovable(const ImmovableDescr& imm_descr) |
4828 | 343 | : BaseImmovable(imm_descr), | 342 | : BaseImmovable(imm_descr), |
4829 | 344 | owner_(nullptr), | ||
4830 | 345 | anim_(0), | 343 | anim_(0), |
4831 | 346 | animstart_(0), | 344 | animstart_(0), |
4832 | 347 | program_(nullptr), | 345 | program_(nullptr), |
4833 | @@ -439,19 +437,26 @@ | |||
4834 | 439 | } | 437 | } |
4835 | 440 | } | 438 | } |
4836 | 441 | 439 | ||
4846 | 442 | void Immovable::draw(const EditorGameBase& game, | 440 | void Immovable::draw(uint32_t gametime, |
4847 | 443 | RenderTarget& dst, | 441 | const DrawText draw_text, |
4848 | 444 | const FCoords&, | 442 | const Vector2f& point_on_dst, |
4849 | 445 | const Point& pos) { | 443 | float scale, |
4850 | 446 | if (anim_) { | 444 | RenderTarget* dst) { |
4851 | 447 | if (!anim_construction_total_) | 445 | if (!anim_) { |
4852 | 448 | dst.blit_animation(pos, anim_, game.get_gametime() - animstart_); | 446 | return; |
4853 | 449 | else | 447 | } |
4854 | 450 | draw_construction(game, dst, pos); | 448 | if (!anim_construction_total_) { |
4855 | 449 | dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_); | ||
4856 | 450 | } else { | ||
4857 | 451 | draw_construction(gametime, draw_text, point_on_dst, scale, dst); | ||
4858 | 451 | } | 452 | } |
4859 | 452 | } | 453 | } |
4860 | 453 | 454 | ||
4862 | 454 | void Immovable::draw_construction(const EditorGameBase& game, RenderTarget& dst, const Point pos) { | 455 | void Immovable::draw_construction(const uint32_t gametime, |
4863 | 456 | const DrawText draw_text, | ||
4864 | 457 | const Vector2f& point_on_dst, | ||
4865 | 458 | const float scale, | ||
4866 | 459 | RenderTarget* dst) { | ||
4867 | 455 | const ImmovableProgram::ActConstruction* constructionact = nullptr; | 460 | const ImmovableProgram::ActConstruction* constructionact = nullptr; |
4868 | 456 | if (program_ptr_ < program_->size()) | 461 | if (program_ptr_ < program_->size()) |
4869 | 457 | constructionact = | 462 | constructionact = |
4870 | @@ -462,7 +467,7 @@ | |||
4871 | 462 | uint32_t done = 0; | 467 | uint32_t done = 0; |
4872 | 463 | if (anim_construction_done_ > 0) { | 468 | if (anim_construction_done_ > 0) { |
4873 | 464 | done = steptime * (anim_construction_done_ - 1); | 469 | done = steptime * (anim_construction_done_ - 1); |
4875 | 465 | done += std::min(steptime, game.get_gametime() - animstart_); | 470 | done += std::min(steptime, gametime - animstart_); |
4876 | 466 | } | 471 | } |
4877 | 467 | 472 | ||
4878 | 468 | uint32_t total = anim_construction_total_ * steptime; | 473 | uint32_t total = anim_construction_total_ * steptime; |
4879 | @@ -483,21 +488,19 @@ | |||
4880 | 483 | const RGBColor& player_color = get_owner()->get_playercolor(); | 488 | const RGBColor& player_color = get_owner()->get_playercolor(); |
4881 | 484 | if (current_frame > 0) { | 489 | if (current_frame > 0) { |
4882 | 485 | // Not the first pic, so draw the previous one in the back | 490 | // Not the first pic, so draw the previous one in the back |
4884 | 486 | dst.blit_animation(pos, anim_, (current_frame - 1) * frametime, player_color); | 491 | dst->blit_animation(point_on_dst, scale, anim_, (current_frame - 1) * frametime, player_color); |
4885 | 487 | } | 492 | } |
4886 | 488 | 493 | ||
4887 | 489 | assert(lines <= curh); | 494 | assert(lines <= curh); |
4890 | 490 | dst.blit_animation(pos, anim_, current_frame * frametime, player_color, | 495 | dst->blit_animation(point_on_dst, scale, anim_, current_frame * frametime, player_color, |
4891 | 491 | Rect(Point(0, curh - lines), curw, lines)); | 496 | Recti(Vector2i(0, curh - lines), curw, lines)); |
4892 | 492 | 497 | ||
4893 | 493 | // Additionally, if statistics are enabled, draw a progression string | 498 | // Additionally, if statistics are enabled, draw a progression string |
4897 | 494 | uint32_t const display_flags = game.get_ibase()->get_display_flags(); | 499 | do_draw_info(draw_text, descr().descname(), |
4895 | 495 | do_draw_info(display_flags & InteractiveBase::dfShowCensus, descr().descname(), | ||
4896 | 496 | display_flags & InteractiveBase::dfShowStatistics, | ||
4898 | 497 | (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() % | 500 | (boost::format("<font color=%s>%s</font>") % UI_FONT_CLR_DARK.hex_value() % |
4899 | 498 | (boost::format(_("%i%% built")) % (100 * done / total)).str()) | 501 | (boost::format(_("%i%% built")) % (100 * done / total)).str()) |
4900 | 499 | .str(), | 502 | .str(), |
4902 | 500 | dst, pos); | 503 | point_on_dst, scale, dst); |
4903 | 501 | } | 504 | } |
4904 | 502 | 505 | ||
4905 | 503 | /** | 506 | /** |
4906 | @@ -1179,7 +1182,7 @@ | |||
4907 | 1179 | * Zero-initialize | 1182 | * Zero-initialize |
4908 | 1180 | */ | 1183 | */ |
4909 | 1181 | PlayerImmovable::PlayerImmovable(const MapObjectDescr& mo_descr) | 1184 | PlayerImmovable::PlayerImmovable(const MapObjectDescr& mo_descr) |
4911 | 1182 | : BaseImmovable(mo_descr), owner_(nullptr), economy_(nullptr) { | 1185 | : BaseImmovable(mo_descr), economy_(nullptr) { |
4912 | 1183 | } | 1186 | } |
4913 | 1184 | 1187 | ||
4914 | 1185 | /** | 1188 | /** |
4915 | 1186 | 1189 | ||
4916 | === modified file 'src/logic/map_objects/immovable.h' | |||
4917 | --- src/logic/map_objects/immovable.h 2016-08-04 15:49:05 +0000 | |||
4918 | +++ src/logic/map_objects/immovable.h 2016-10-24 20:07:47 +0000 | |||
4919 | @@ -26,6 +26,7 @@ | |||
4920 | 26 | #include "base/macros.h" | 26 | #include "base/macros.h" |
4921 | 27 | #include "graphic/animation.h" | 27 | #include "graphic/animation.h" |
4922 | 28 | #include "logic/map_objects/buildcost.h" | 28 | #include "logic/map_objects/buildcost.h" |
4923 | 29 | #include "logic/map_objects/draw_text.h" | ||
4924 | 29 | #include "logic/map_objects/map_object.h" | 30 | #include "logic/map_objects/map_object.h" |
4925 | 30 | #include "logic/widelands_geometry.h" | 31 | #include "logic/widelands_geometry.h" |
4926 | 31 | #include "notifications/note_ids.h" | 32 | #include "notifications/note_ids.h" |
4927 | @@ -91,7 +92,18 @@ | |||
4928 | 91 | * if one can be chosen as main. | 92 | * if one can be chosen as main. |
4929 | 92 | */ | 93 | */ |
4930 | 93 | virtual PositionList get_positions(const EditorGameBase&) const = 0; | 94 | virtual PositionList get_positions(const EditorGameBase&) const = 0; |
4932 | 94 | virtual void draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) = 0; | 95 | |
4933 | 96 | // Draw this immovable onto 'dst' choosing the frame appropriate for | ||
4934 | 97 | // 'gametime'. 'draw_text' decides if census and statistics are written too. | ||
4935 | 98 | // The 'coords_to_draw' are passed one to give objects that occupy multiple | ||
4936 | 99 | // fields a way to only draw themselves once. The 'point_on_dst' determines | ||
4937 | 100 | // the point for the hotspot of the animation and 'scale' determines how big | ||
4938 | 101 | // the immovable will be plotted. | ||
4939 | 102 | virtual void draw(uint32_t gametime, | ||
4940 | 103 | DrawText draw_text, | ||
4941 | 104 | const Vector2f& point_on_dst, | ||
4942 | 105 | float scale, | ||
4943 | 106 | RenderTarget* dst) = 0; | ||
4944 | 95 | 107 | ||
4945 | 96 | static int32_t string_to_size(const std::string& size); | 108 | static int32_t string_to_size(const std::string& size); |
4946 | 97 | static std::string size_to_string(int32_t size); | 109 | static std::string size_to_string(int32_t size); |
4947 | @@ -189,10 +201,7 @@ | |||
4948 | 189 | Immovable(const ImmovableDescr&); | 201 | Immovable(const ImmovableDescr&); |
4949 | 190 | ~Immovable(); | 202 | ~Immovable(); |
4950 | 191 | 203 | ||
4955 | 192 | Player* get_owner() const { | 204 | void set_owner(Player*); |
4952 | 193 | return owner_; | ||
4953 | 194 | } | ||
4954 | 195 | void set_owner(Player* player); | ||
4956 | 196 | 205 | ||
4957 | 197 | Coords get_position() const { | 206 | Coords get_position() const { |
4958 | 198 | return position_; | 207 | return position_; |
4959 | @@ -212,8 +221,11 @@ | |||
4960 | 212 | void init(EditorGameBase&) override; | 221 | void init(EditorGameBase&) override; |
4961 | 213 | void cleanup(EditorGameBase&) override; | 222 | void cleanup(EditorGameBase&) override; |
4962 | 214 | void act(Game&, uint32_t data) override; | 223 | void act(Game&, uint32_t data) override; |
4965 | 215 | 224 | void draw(uint32_t gametime, | |
4966 | 216 | void draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) override; | 225 | DrawText draw_text, |
4967 | 226 | const Vector2f& point_on_dst, | ||
4968 | 227 | float scale, | ||
4969 | 228 | RenderTarget* dst) override; | ||
4970 | 217 | 229 | ||
4971 | 218 | void switch_program(Game& game, const std::string& programname); | 230 | void switch_program(Game& game, const std::string& programname); |
4972 | 219 | bool construct_ware(Game& game, DescriptionIndex index); | 231 | bool construct_ware(Game& game, DescriptionIndex index); |
4973 | @@ -230,7 +242,6 @@ | |||
4974 | 230 | } | 242 | } |
4975 | 231 | 243 | ||
4976 | 232 | protected: | 244 | protected: |
4977 | 233 | Player* owner_; | ||
4978 | 234 | Coords position_; | 245 | Coords position_; |
4979 | 235 | 246 | ||
4980 | 236 | uint32_t anim_; | 247 | uint32_t anim_; |
4981 | @@ -289,8 +300,11 @@ | |||
4982 | 289 | 300 | ||
4983 | 290 | private: | 301 | private: |
4984 | 291 | void increment_program_pointer(); | 302 | void increment_program_pointer(); |
4987 | 292 | 303 | void draw_construction(uint32_t gametime, | |
4988 | 293 | void draw_construction(const EditorGameBase&, RenderTarget&, Point); | 304 | DrawText draw_text, |
4989 | 305 | const Vector2f& point_on_dst, | ||
4990 | 306 | float scale, | ||
4991 | 307 | RenderTarget* dst); | ||
4992 | 294 | }; | 308 | }; |
4993 | 295 | 309 | ||
4994 | 296 | /** | 310 | /** |
4995 | @@ -360,7 +374,6 @@ | |||
4996 | 360 | void cleanup(EditorGameBase&) override; | 374 | void cleanup(EditorGameBase&) override; |
4997 | 361 | 375 | ||
4998 | 362 | private: | 376 | private: |
4999 | 363 | Player* owner_; | ||
5000 | 364 | Economy* economy_; | 377 | Economy* economy_; |
This branch creates a problem with the new font renderer - see
https:/ /bugs.launchpad .net/widelands/ +bug/536461/ comments/ 14