Merge lp:~widelands-dev/widelands/editor-grid into lp:widelands
- editor-grid
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 9083 | ||||
Proposed branch: | lp:~widelands-dev/widelands/editor-grid | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
457 lines (+225/-6) 15 files modified
data/shaders/grid.fp (+5/-0) data/shaders/grid.vp (+10/-0) src/editor/editorinteractive.cc (+14/-1) src/editor/editorinteractive.h (+3/-0) src/graphic/CMakeLists.txt (+2/-0) src/graphic/game_renderer.cc (+8/-0) src/graphic/game_renderer.h (+1/-0) src/graphic/gl/grid_program.cc (+89/-0) src/graphic/gl/grid_program.h (+72/-0) src/graphic/render_queue.cc (+10/-0) src/graphic/render_queue.h (+3/-0) src/wui/interactive_player.cc (+1/-1) src/wui/interactive_spectator.cc (+1/-1) src/wui/mapview.cc (+2/-1) src/wui/mapview.h (+4/-2) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/editor-grid | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+366505@code.launchpad.net |
Commit message
Add a grid overlay to the editor that can be toggled with a button or the hotkey 'G'
Description of the change
Next try :)
I also experimented with draw_line_strip – there was no visible difference but it was a bit slower. So a new, small shader is better IMHO.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 4802. State: errored. Details: https:/
Appveyor build 4583. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.
Travis build 4802. State: errored. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Just the usual stalled inputqueues
@bunnybot merge force
Preview Diff
1 | === added file 'data/images/wui/menus/menu_toggle_grid.png' | |||
2 | 0 | Binary files data/images/wui/menus/menu_toggle_grid.png 1970-01-01 00:00:00 +0000 and data/images/wui/menus/menu_toggle_grid.png 2019-04-25 16:22:57 +0000 differ | 0 | Binary files data/images/wui/menus/menu_toggle_grid.png 1970-01-01 00:00:00 +0000 and data/images/wui/menus/menu_toggle_grid.png 2019-04-25 16:22:57 +0000 differ |
3 | === added file 'data/shaders/grid.fp' | |||
4 | --- data/shaders/grid.fp 1970-01-01 00:00:00 +0000 | |||
5 | +++ data/shaders/grid.fp 2019-04-25 16:22:57 +0000 | |||
6 | @@ -0,0 +1,5 @@ | |||
7 | 1 | #version 120 | ||
8 | 2 | |||
9 | 3 | void main() { | ||
10 | 4 | gl_FragColor = vec4(.0, .0, .0, .8); | ||
11 | 5 | } | ||
12 | 0 | 6 | ||
13 | === added file 'data/shaders/grid.vp' | |||
14 | --- data/shaders/grid.vp 1970-01-01 00:00:00 +0000 | |||
15 | +++ data/shaders/grid.vp 2019-04-25 16:22:57 +0000 | |||
16 | @@ -0,0 +1,10 @@ | |||
17 | 1 | #version 120 | ||
18 | 2 | |||
19 | 3 | // Attributes. | ||
20 | 4 | attribute vec2 attr_position; | ||
21 | 5 | |||
22 | 6 | uniform float u_z_value; | ||
23 | 7 | |||
24 | 8 | void main() { | ||
25 | 9 | gl_Position = vec4(attr_position, u_z_value, 1.); | ||
26 | 10 | } | ||
27 | 0 | 11 | ||
28 | === modified file 'src/editor/editorinteractive.cc' | |||
29 | --- src/editor/editorinteractive.cc 2019-04-24 15:56:31 +0000 | |||
30 | +++ src/editor/editorinteractive.cc 2019-04-25 16:22:57 +0000 | |||
31 | @@ -98,6 +98,10 @@ | |||
32 | 98 | toggle_buildhelp_ = add_toolbar_button( | 98 | toggle_buildhelp_ = add_toolbar_button( |
33 | 99 | "wui/menus/menu_toggle_buildhelp", "buildhelp", _("Show building spaces (on/off)")); | 99 | "wui/menus/menu_toggle_buildhelp", "buildhelp", _("Show building spaces (on/off)")); |
34 | 100 | toggle_buildhelp_->sigclicked.connect(boost::bind(&EditorInteractive::toggle_buildhelp, this)); | 100 | toggle_buildhelp_->sigclicked.connect(boost::bind(&EditorInteractive::toggle_buildhelp, this)); |
35 | 101 | toggle_grid_ = | ||
36 | 102 | add_toolbar_button("wui/menus/menu_toggle_grid", "grid", _("Show grid (on/off)")); | ||
37 | 103 | toggle_grid_->set_perm_pressed(true); | ||
38 | 104 | toggle_grid_->sigclicked.connect([this]() { toggle_grid(); }); | ||
39 | 101 | toggle_immovables_ = add_toolbar_button( | 105 | toggle_immovables_ = add_toolbar_button( |
40 | 102 | "wui/menus/menu_toggle_immovables", "immovables", _("Show immovables (on/off)")); | 106 | "wui/menus/menu_toggle_immovables", "immovables", _("Show immovables (on/off)")); |
41 | 103 | toggle_immovables_->set_perm_pressed(true); | 107 | toggle_immovables_->set_perm_pressed(true); |
42 | @@ -262,7 +266,7 @@ | |||
43 | 262 | 266 | ||
44 | 263 | void EditorInteractive::draw(RenderTarget& dst) { | 267 | void EditorInteractive::draw(RenderTarget& dst) { |
45 | 264 | const auto& ebase = egbase(); | 268 | const auto& ebase = egbase(); |
47 | 265 | auto* fields_to_draw = map_view()->draw_terrain(ebase, Workareas(), &dst); | 269 | auto* fields_to_draw = map_view()->draw_terrain(ebase, Workareas(), draw_grid_, &dst); |
48 | 266 | 270 | ||
49 | 267 | const float scale = 1.f / map_view()->view().zoom; | 271 | const float scale = 1.f / map_view()->view().zoom; |
50 | 268 | const uint32_t gametime = ebase.get_gametime(); | 272 | const uint32_t gametime = ebase.get_gametime(); |
51 | @@ -430,6 +434,11 @@ | |||
52 | 430 | toggle_bobs_->set_perm_pressed(draw_bobs_); | 434 | toggle_bobs_->set_perm_pressed(draw_bobs_); |
53 | 431 | } | 435 | } |
54 | 432 | 436 | ||
55 | 437 | void EditorInteractive::toggle_grid() { | ||
56 | 438 | draw_grid_ = !draw_grid_; | ||
57 | 439 | toggle_grid_->set_perm_pressed(draw_grid_); | ||
58 | 440 | } | ||
59 | 441 | |||
60 | 433 | bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) { | 442 | bool EditorInteractive::handle_key(bool const down, SDL_Keysym const code) { |
61 | 434 | if (down) { | 443 | if (down) { |
62 | 435 | switch (code.sym) { | 444 | switch (code.sym) { |
63 | @@ -504,6 +513,10 @@ | |||
64 | 504 | toggle_buildhelp(); | 513 | toggle_buildhelp(); |
65 | 505 | return true; | 514 | return true; |
66 | 506 | 515 | ||
67 | 516 | case SDLK_g: | ||
68 | 517 | toggle_grid(); | ||
69 | 518 | return true; | ||
70 | 519 | |||
71 | 507 | case SDLK_c: | 520 | case SDLK_c: |
72 | 508 | set_display_flag( | 521 | set_display_flag( |
73 | 509 | InteractiveBase::dfShowCensus, !get_display_flag(InteractiveBase::dfShowCensus)); | 522 | InteractiveBase::dfShowCensus, !get_display_flag(InteractiveBase::dfShowCensus)); |
74 | 510 | 523 | ||
75 | === modified file 'src/editor/editorinteractive.h' | |||
76 | --- src/editor/editorinteractive.h 2019-04-24 07:09:29 +0000 | |||
77 | +++ src/editor/editorinteractive.h 2019-04-25 16:22:57 +0000 | |||
78 | @@ -149,6 +149,7 @@ | |||
79 | 149 | void toggle_resources(); | 149 | void toggle_resources(); |
80 | 150 | void toggle_immovables(); | 150 | void toggle_immovables(); |
81 | 151 | void toggle_bobs(); | 151 | void toggle_bobs(); |
82 | 152 | void toggle_grid(); | ||
83 | 152 | 153 | ||
84 | 153 | // state variables | 154 | // state variables |
85 | 154 | bool need_save_; | 155 | bool need_save_; |
86 | @@ -170,6 +171,7 @@ | |||
87 | 170 | UI::UniqueWindow::Registry helpmenu_; | 171 | UI::UniqueWindow::Registry helpmenu_; |
88 | 171 | 172 | ||
89 | 172 | UI::Button* toggle_buildhelp_; | 173 | UI::Button* toggle_buildhelp_; |
90 | 174 | UI::Button* toggle_grid_; | ||
91 | 173 | UI::Button* toggle_resources_; | 175 | UI::Button* toggle_resources_; |
92 | 174 | UI::Button* toggle_immovables_; | 176 | UI::Button* toggle_immovables_; |
93 | 175 | UI::Button* toggle_bobs_; | 177 | UI::Button* toggle_bobs_; |
94 | @@ -182,6 +184,7 @@ | |||
95 | 182 | bool draw_resources_ = true; | 184 | bool draw_resources_ = true; |
96 | 183 | bool draw_immovables_ = true; | 185 | bool draw_immovables_ = true; |
97 | 184 | bool draw_bobs_ = true; | 186 | bool draw_bobs_ = true; |
98 | 187 | bool draw_grid_ = true; | ||
99 | 185 | }; | 188 | }; |
100 | 186 | 189 | ||
101 | 187 | #endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H | 190 | #endif // end of include guard: WL_EDITOR_EDITORINTERACTIVE_H |
102 | 188 | 191 | ||
103 | === modified file 'src/graphic/CMakeLists.txt' | |||
104 | --- src/graphic/CMakeLists.txt 2019-04-24 15:56:31 +0000 | |||
105 | +++ src/graphic/CMakeLists.txt 2019-04-25 16:22:57 +0000 | |||
106 | @@ -225,6 +225,8 @@ | |||
107 | 225 | 225 | ||
108 | 226 | wl_library(graphic_terrain_programs | 226 | wl_library(graphic_terrain_programs |
109 | 227 | SRCS | 227 | SRCS |
110 | 228 | gl/grid_program.cc | ||
111 | 229 | gl/grid_program.h | ||
112 | 228 | gl/road_program.cc | 230 | gl/road_program.cc |
113 | 229 | gl/road_program.h | 231 | gl/road_program.h |
114 | 230 | gl/terrain_program.cc | 232 | gl/terrain_program.cc |
115 | 231 | 233 | ||
116 | === modified file 'src/graphic/game_renderer.cc' | |||
117 | --- src/graphic/game_renderer.cc 2019-04-24 15:56:31 +0000 | |||
118 | +++ src/graphic/game_renderer.cc 2019-04-25 16:22:57 +0000 | |||
119 | @@ -61,6 +61,7 @@ | |||
120 | 61 | const FieldsToDraw& fields_to_draw, | 61 | const FieldsToDraw& fields_to_draw, |
121 | 62 | const float scale, | 62 | const float scale, |
122 | 63 | Workareas workarea, | 63 | Workareas workarea, |
123 | 64 | bool grid, | ||
124 | 64 | RenderTarget* dst) { | 65 | RenderTarget* dst) { |
125 | 65 | const Recti& bounding_rect = dst->get_rect(); | 66 | const Recti& bounding_rect = dst->get_rect(); |
126 | 66 | const Surface& surface = dst->get_surface(); | 67 | const Surface& surface = dst->get_surface(); |
127 | @@ -94,6 +95,13 @@ | |||
128 | 94 | RenderQueue::instance().enqueue(i); | 95 | RenderQueue::instance().enqueue(i); |
129 | 95 | } | 96 | } |
130 | 96 | 97 | ||
131 | 98 | if (grid) { | ||
132 | 99 | // Enqueue the drawing of the grid layer. | ||
133 | 100 | i.program_id = RenderQueue::Program::kTerrainGrid; | ||
134 | 101 | i.blend_mode = BlendMode::UseAlpha; | ||
135 | 102 | RenderQueue::instance().enqueue(i); | ||
136 | 103 | } | ||
137 | 104 | |||
138 | 97 | // Enqueue the drawing of the road layer. | 105 | // Enqueue the drawing of the road layer. |
139 | 98 | i.program_id = RenderQueue::Program::kTerrainRoad; | 106 | i.program_id = RenderQueue::Program::kTerrainRoad; |
140 | 99 | RenderQueue::instance().enqueue(i); | 107 | RenderQueue::instance().enqueue(i); |
141 | 100 | 108 | ||
142 | === modified file 'src/graphic/game_renderer.h' | |||
143 | --- src/graphic/game_renderer.h 2019-03-11 14:45:04 +0000 | |||
144 | +++ src/graphic/game_renderer.h 2019-04-25 16:22:57 +0000 | |||
145 | @@ -34,6 +34,7 @@ | |||
146 | 34 | const FieldsToDraw& fields_to_draw, | 34 | const FieldsToDraw& fields_to_draw, |
147 | 35 | const float scale, | 35 | const float scale, |
148 | 36 | Workareas workarea, | 36 | Workareas workarea, |
149 | 37 | bool grid, | ||
150 | 37 | RenderTarget* dst); | 38 | RenderTarget* dst); |
151 | 38 | 39 | ||
152 | 39 | // Draw the border stones for 'field' if it is a border and 'visibility' is | 40 | // Draw the border stones for 'field' if it is a border and 'visibility' is |
153 | 40 | 41 | ||
154 | === added file 'src/graphic/gl/grid_program.cc' | |||
155 | --- src/graphic/gl/grid_program.cc 1970-01-01 00:00:00 +0000 | |||
156 | +++ src/graphic/gl/grid_program.cc 2019-04-25 16:22:57 +0000 | |||
157 | @@ -0,0 +1,89 @@ | |||
158 | 1 | /* | ||
159 | 2 | * Copyright (C) 2006-2019 by the Widelands Development Team | ||
160 | 3 | * | ||
161 | 4 | * This program is free software; you can redistribute it and/or | ||
162 | 5 | * modify it under the terms of the GNU General Public License | ||
163 | 6 | * as published by the Free Software Foundation; either version 2 | ||
164 | 7 | * of the License, or (at your option) any later version. | ||
165 | 8 | * | ||
166 | 9 | * This program is distributed in the hope that it will be useful, | ||
167 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
168 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
169 | 12 | * GNU General Public License for more details. | ||
170 | 13 | * | ||
171 | 14 | * You should have received a copy of the GNU General Public License | ||
172 | 15 | * along with this program; if not, write to the Free Software | ||
173 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
174 | 17 | * | ||
175 | 18 | */ | ||
176 | 19 | |||
177 | 20 | #include "graphic/gl/grid_program.h" | ||
178 | 21 | |||
179 | 22 | #include "graphic/gl/coordinate_conversion.h" | ||
180 | 23 | #include "graphic/gl/fields_to_draw.h" | ||
181 | 24 | #include "graphic/gl/utils.h" | ||
182 | 25 | #include "graphic/texture.h" | ||
183 | 26 | |||
184 | 27 | GridProgram::GridProgram() { | ||
185 | 28 | gl_program_.build("grid"); | ||
186 | 29 | |||
187 | 30 | attr_position_ = glGetAttribLocation(gl_program_.object(), "attr_position"); | ||
188 | 31 | |||
189 | 32 | u_z_value_ = glGetUniformLocation(gl_program_.object(), "u_z_value"); | ||
190 | 33 | } | ||
191 | 34 | |||
192 | 35 | void GridProgram::gl_draw(int gl_texture, float z_value) { | ||
193 | 36 | glUseProgram(gl_program_.object()); | ||
194 | 37 | |||
195 | 38 | auto& gl_state = Gl::State::instance(); | ||
196 | 39 | |||
197 | 40 | gl_array_buffer_.bind(); | ||
198 | 41 | gl_array_buffer_.update(vertices_); | ||
199 | 42 | |||
200 | 43 | Gl::vertex_attrib_pointer( | ||
201 | 44 | attr_position_, 2, sizeof(PerVertexData), offsetof(PerVertexData, gl_x)); | ||
202 | 45 | |||
203 | 46 | gl_state.bind(GL_TEXTURE0, gl_texture); | ||
204 | 47 | |||
205 | 48 | glUniform1f(u_z_value_, z_value); | ||
206 | 49 | |||
207 | 50 | glDrawArrays(GL_LINES, 0, vertices_.size()); | ||
208 | 51 | } | ||
209 | 52 | |||
210 | 53 | void GridProgram::add_vertex(const FieldsToDraw::Field& field) { | ||
211 | 54 | vertices_.emplace_back(); | ||
212 | 55 | PerVertexData& back = vertices_.back(); | ||
213 | 56 | back.gl_x = field.gl_position.x; | ||
214 | 57 | back.gl_y = field.gl_position.y; | ||
215 | 58 | } | ||
216 | 59 | |||
217 | 60 | void GridProgram::draw(uint32_t texture_id, | ||
218 | 61 | const FieldsToDraw& fields_to_draw, | ||
219 | 62 | float z_value) { | ||
220 | 63 | vertices_.clear(); | ||
221 | 64 | vertices_.reserve(fields_to_draw.size() * 2); | ||
222 | 65 | |||
223 | 66 | for (size_t current_index = 0; current_index < fields_to_draw.size(); ++current_index) { | ||
224 | 67 | const FieldsToDraw::Field& field = fields_to_draw.at(current_index); | ||
225 | 68 | |||
226 | 69 | // Southwestern edge | ||
227 | 70 | if (field.bln_index != FieldsToDraw::kInvalidIndex) { | ||
228 | 71 | add_vertex(fields_to_draw.at(current_index)); | ||
229 | 72 | add_vertex(fields_to_draw.at(field.bln_index)); | ||
230 | 73 | } | ||
231 | 74 | |||
232 | 75 | // Southeastern edge | ||
233 | 76 | if (field.brn_index != FieldsToDraw::kInvalidIndex) { | ||
234 | 77 | add_vertex(fields_to_draw.at(current_index)); | ||
235 | 78 | add_vertex(fields_to_draw.at(field.brn_index)); | ||
236 | 79 | } | ||
237 | 80 | |||
238 | 81 | // Eastern edge | ||
239 | 82 | if (field.rn_index != FieldsToDraw::kInvalidIndex) { | ||
240 | 83 | add_vertex(fields_to_draw.at(current_index)); | ||
241 | 84 | add_vertex(fields_to_draw.at(field.rn_index)); | ||
242 | 85 | } | ||
243 | 86 | } | ||
244 | 87 | |||
245 | 88 | gl_draw(texture_id, z_value); | ||
246 | 89 | } | ||
247 | 0 | 90 | ||
248 | === added file 'src/graphic/gl/grid_program.h' | |||
249 | --- src/graphic/gl/grid_program.h 1970-01-01 00:00:00 +0000 | |||
250 | +++ src/graphic/gl/grid_program.h 2019-04-25 16:22:57 +0000 | |||
251 | @@ -0,0 +1,72 @@ | |||
252 | 1 | /* | ||
253 | 2 | * Copyright (C) 2006-2019 by the Widelands Development Team | ||
254 | 3 | * | ||
255 | 4 | * This program is free software; you can redistribute it and/or | ||
256 | 5 | * modify it under the terms of the GNU General Public License | ||
257 | 6 | * as published by the Free Software Foundation; either version 2 | ||
258 | 7 | * of the License, or (at your option) any later version. | ||
259 | 8 | * | ||
260 | 9 | * This program is distributed in the hope that it will be useful, | ||
261 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
262 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
263 | 12 | * GNU General Public License for more details. | ||
264 | 13 | * | ||
265 | 14 | * You should have received a copy of the GNU General Public License | ||
266 | 15 | * along with this program; if not, write to the Free Software | ||
267 | 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
268 | 17 | * | ||
269 | 18 | */ | ||
270 | 19 | |||
271 | 20 | #ifndef WL_GRAPHIC_GL_GRID_PROGRAM_H | ||
272 | 21 | #define WL_GRAPHIC_GL_GRID_PROGRAM_H | ||
273 | 22 | |||
274 | 23 | #include <vector> | ||
275 | 24 | |||
276 | 25 | #include "base/vector.h" | ||
277 | 26 | #include "graphic/gl/fields_to_draw.h" | ||
278 | 27 | #include "graphic/gl/utils.h" | ||
279 | 28 | #include "logic/description_maintainer.h" | ||
280 | 29 | #include "logic/map_objects/world/terrain_description.h" | ||
281 | 30 | |||
282 | 31 | class GridProgram { | ||
283 | 32 | public: | ||
284 | 33 | // Compiles the program. Throws on errors. | ||
285 | 34 | GridProgram(); | ||
286 | 35 | |||
287 | 36 | // Draws the grid layer | ||
288 | 37 | void draw(uint32_t texture_id, | ||
289 | 38 | const FieldsToDraw& fields_to_draw, | ||
290 | 39 | float z_value); | ||
291 | 40 | |||
292 | 41 | private: | ||
293 | 42 | struct PerVertexData { | ||
294 | 43 | float gl_x; | ||
295 | 44 | float gl_y; | ||
296 | 45 | }; | ||
297 | 46 | static_assert(sizeof(PerVertexData) == 8, "Wrong padding."); | ||
298 | 47 | |||
299 | 48 | void gl_draw(int gl_texture, float z_value); | ||
300 | 49 | |||
301 | 50 | // Adds a vertex to the end of vertices with data from 'field'. | ||
302 | 51 | void add_vertex(const FieldsToDraw::Field& field); | ||
303 | 52 | |||
304 | 53 | // The program used for drawing the grid layer | ||
305 | 54 | Gl::Program gl_program_; | ||
306 | 55 | |||
307 | 56 | // The buffer that will contain 'vertices_' for rendering. | ||
308 | 57 | Gl::Buffer<PerVertexData> gl_array_buffer_; | ||
309 | 58 | |||
310 | 59 | // Attributes. | ||
311 | 60 | GLint attr_position_; | ||
312 | 61 | |||
313 | 62 | // Uniforms. | ||
314 | 63 | GLint u_z_value_; | ||
315 | 64 | |||
316 | 65 | // Objects below are kept around to avoid memory allocations on each frame. | ||
317 | 66 | // They could theoretically also be recreated. | ||
318 | 67 | std::vector<PerVertexData> vertices_; | ||
319 | 68 | |||
320 | 69 | DISALLOW_COPY_AND_ASSIGN(GridProgram); | ||
321 | 70 | }; | ||
322 | 71 | |||
323 | 72 | #endif // end of include guard: WL_GRAPHIC_GL_GRID_PROGRAM_H | ||
324 | 0 | 73 | ||
325 | === modified file 'src/graphic/render_queue.cc' | |||
326 | --- src/graphic/render_queue.cc 2019-04-25 00:03:42 +0000 | |||
327 | +++ src/graphic/render_queue.cc 2019-04-25 16:22:57 +0000 | |||
328 | @@ -28,6 +28,7 @@ | |||
329 | 28 | #include "graphic/gl/dither_program.h" | 28 | #include "graphic/gl/dither_program.h" |
330 | 29 | #include "graphic/gl/draw_line_program.h" | 29 | #include "graphic/gl/draw_line_program.h" |
331 | 30 | #include "graphic/gl/fill_rect_program.h" | 30 | #include "graphic/gl/fill_rect_program.h" |
332 | 31 | #include "graphic/gl/grid_program.h" | ||
333 | 31 | #include "graphic/gl/road_program.h" | 32 | #include "graphic/gl/road_program.h" |
334 | 32 | #include "graphic/gl/terrain_program.h" | 33 | #include "graphic/gl/terrain_program.h" |
335 | 33 | #include "graphic/gl/workarea_program.h" | 34 | #include "graphic/gl/workarea_program.h" |
336 | @@ -144,6 +145,7 @@ | |||
337 | 144 | terrain_program_(new TerrainProgram()), | 145 | terrain_program_(new TerrainProgram()), |
338 | 145 | dither_program_(new DitherProgram()), | 146 | dither_program_(new DitherProgram()), |
339 | 146 | workarea_program_(new WorkareaProgram()), | 147 | workarea_program_(new WorkareaProgram()), |
340 | 148 | grid_program_(new GridProgram()), | ||
341 | 147 | road_program_(new RoadProgram()) { | 149 | road_program_(new RoadProgram()) { |
342 | 148 | } | 150 | } |
343 | 149 | 151 | ||
344 | @@ -167,6 +169,7 @@ | |||
345 | 167 | case Program::kTerrainBase: | 169 | case Program::kTerrainBase: |
346 | 168 | case Program::kTerrainDither: | 170 | case Program::kTerrainDither: |
347 | 169 | case Program::kTerrainWorkarea: | 171 | case Program::kTerrainWorkarea: |
348 | 172 | case Program::kTerrainGrid: | ||
349 | 170 | case Program::kTerrainRoad: | 173 | case Program::kTerrainRoad: |
350 | 171 | /* all fallthroughs intended */ | 174 | /* all fallthroughs intended */ |
351 | 172 | break; | 175 | break; |
352 | @@ -262,6 +265,13 @@ | |||
353 | 262 | ++i; | 265 | ++i; |
354 | 263 | } break; | 266 | } break; |
355 | 264 | 267 | ||
356 | 268 | case Program::kTerrainGrid: { | ||
357 | 269 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); | ||
358 | 270 | grid_program_->draw(item.terrain_arguments.terrains->get(0).get_texture(0).blit_data().texture_id, | ||
359 | 271 | *item.terrain_arguments.fields_to_draw, item.z_value); | ||
360 | 272 | ++i; | ||
361 | 273 | } break; | ||
362 | 274 | |||
363 | 265 | case Program::kTerrainRoad: { | 275 | case Program::kTerrainRoad: { |
364 | 266 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); | 276 | ScopedScissor scoped_scissor(item.terrain_arguments.destination_rect); |
365 | 267 | road_program_->draw(item.terrain_arguments.renderbuffer_width, | 277 | road_program_->draw(item.terrain_arguments.renderbuffer_width, |
366 | 268 | 278 | ||
367 | === modified file 'src/graphic/render_queue.h' | |||
368 | --- src/graphic/render_queue.h 2019-03-11 14:45:04 +0000 | |||
369 | +++ src/graphic/render_queue.h 2019-04-25 16:22:57 +0000 | |||
370 | @@ -36,6 +36,7 @@ | |||
371 | 36 | #include "logic/map_objects/world/terrain_description.h" | 36 | #include "logic/map_objects/world/terrain_description.h" |
372 | 37 | 37 | ||
373 | 38 | class DitherProgram; | 38 | class DitherProgram; |
374 | 39 | class GridProgram; | ||
375 | 39 | class RoadProgram; | 40 | class RoadProgram; |
376 | 40 | class TerrainProgram; | 41 | class TerrainProgram; |
377 | 41 | class WorkareaProgram; | 42 | class WorkareaProgram; |
378 | @@ -84,6 +85,7 @@ | |||
379 | 84 | kTerrainBase, | 85 | kTerrainBase, |
380 | 85 | kTerrainDither, | 86 | kTerrainDither, |
381 | 86 | kTerrainWorkarea, | 87 | kTerrainWorkarea, |
382 | 88 | kTerrainGrid, | ||
383 | 87 | kTerrainRoad, | 89 | kTerrainRoad, |
384 | 88 | kBlit, | 90 | kBlit, |
385 | 89 | kRect, | 91 | kRect, |
386 | @@ -182,6 +184,7 @@ | |||
387 | 182 | std::unique_ptr<TerrainProgram> terrain_program_; | 184 | std::unique_ptr<TerrainProgram> terrain_program_; |
388 | 183 | std::unique_ptr<DitherProgram> dither_program_; | 185 | std::unique_ptr<DitherProgram> dither_program_; |
389 | 184 | std::unique_ptr<WorkareaProgram> workarea_program_; | 186 | std::unique_ptr<WorkareaProgram> workarea_program_; |
390 | 187 | std::unique_ptr<GridProgram> grid_program_; | ||
391 | 185 | std::unique_ptr<RoadProgram> road_program_; | 188 | std::unique_ptr<RoadProgram> road_program_; |
392 | 186 | 189 | ||
393 | 187 | std::vector<Item> blended_items_; | 190 | std::vector<Item> blended_items_; |
394 | 188 | 191 | ||
395 | === modified file 'src/wui/interactive_player.cc' | |||
396 | --- src/wui/interactive_player.cc 2019-04-25 00:03:42 +0000 | |||
397 | +++ src/wui/interactive_player.cc 2019-04-25 16:22:57 +0000 | |||
398 | @@ -288,7 +288,7 @@ | |||
399 | 288 | const uint32_t gametime = gbase.get_gametime(); | 288 | const uint32_t gametime = gbase.get_gametime(); |
400 | 289 | 289 | ||
401 | 290 | Workareas workareas = get_workarea_overlays(map); | 290 | Workareas workareas = get_workarea_overlays(map); |
403 | 291 | auto* fields_to_draw = given_map_view->draw_terrain(gbase, workareas, dst); | 291 | auto* fields_to_draw = given_map_view->draw_terrain(gbase, workareas, false, dst); |
404 | 292 | const auto& road_building = road_building_overlays(); | 292 | const auto& road_building = road_building_overlays(); |
405 | 293 | 293 | ||
406 | 294 | const float scale = 1.f / given_map_view->view().zoom; | 294 | const float scale = 1.f / given_map_view->view().zoom; |
407 | 295 | 295 | ||
408 | === modified file 'src/wui/interactive_spectator.cc' | |||
409 | --- src/wui/interactive_spectator.cc 2019-04-24 15:56:31 +0000 | |||
410 | +++ src/wui/interactive_spectator.cc 2019-04-25 16:22:57 +0000 | |||
411 | @@ -116,7 +116,7 @@ | |||
412 | 116 | 116 | ||
413 | 117 | const Widelands::Game& the_game = game(); | 117 | const Widelands::Game& the_game = game(); |
414 | 118 | const Widelands::Map& map = the_game.map(); | 118 | const Widelands::Map& map = the_game.map(); |
416 | 119 | auto* fields_to_draw = given_map_view->draw_terrain(the_game, get_workarea_overlays(map), dst); | 119 | auto* fields_to_draw = given_map_view->draw_terrain(the_game, get_workarea_overlays(map), false, dst); |
417 | 120 | const float scale = 1.f / given_map_view->view().zoom; | 120 | const float scale = 1.f / given_map_view->view().zoom; |
418 | 121 | const uint32_t gametime = the_game.get_gametime(); | 121 | const uint32_t gametime = the_game.get_gametime(); |
419 | 122 | 122 | ||
420 | 123 | 123 | ||
421 | === modified file 'src/wui/mapview.cc' | |||
422 | --- src/wui/mapview.cc 2019-04-25 00:03:42 +0000 | |||
423 | +++ src/wui/mapview.cc 2019-04-25 16:22:57 +0000 | |||
424 | @@ -341,6 +341,7 @@ | |||
425 | 341 | 341 | ||
426 | 342 | FieldsToDraw* MapView::draw_terrain(const Widelands::EditorGameBase& egbase, | 342 | FieldsToDraw* MapView::draw_terrain(const Widelands::EditorGameBase& egbase, |
427 | 343 | Workareas workarea, | 343 | Workareas workarea, |
428 | 344 | bool grid, | ||
429 | 344 | RenderTarget* dst) { | 345 | RenderTarget* dst) { |
430 | 345 | uint32_t now = SDL_GetTicks(); | 346 | uint32_t now = SDL_GetTicks(); |
431 | 346 | while (!view_plans_.empty()) { | 347 | while (!view_plans_.empty()) { |
432 | @@ -385,7 +386,7 @@ | |||
433 | 385 | 386 | ||
434 | 386 | fields_to_draw_.reset(egbase, view_.viewpoint, view_.zoom, dst); | 387 | fields_to_draw_.reset(egbase, view_.viewpoint, view_.zoom, dst); |
435 | 387 | const float scale = 1.f / view_.zoom; | 388 | const float scale = 1.f / view_.zoom; |
437 | 388 | ::draw_terrain(egbase, fields_to_draw_, scale, workarea, dst); | 389 | ::draw_terrain(egbase, fields_to_draw_, scale, workarea, grid, dst); |
438 | 389 | return &fields_to_draw_; | 390 | return &fields_to_draw_; |
439 | 390 | } | 391 | } |
440 | 391 | 392 | ||
441 | 392 | 393 | ||
442 | === modified file 'src/wui/mapview.h' | |||
443 | --- src/wui/mapview.h 2019-04-25 00:03:42 +0000 | |||
444 | +++ src/wui/mapview.h 2019-04-25 16:22:57 +0000 | |||
445 | @@ -172,8 +172,10 @@ | |||
446 | 172 | // Schedules drawing of the terrain of this MapView. The returned value can | 172 | // Schedules drawing of the terrain of this MapView. The returned value can |
447 | 173 | // be used to override contents of 'fields_to_draw' for player knowledge and | 173 | // be used to override contents of 'fields_to_draw' for player knowledge and |
448 | 174 | // visibility, and to correctly draw map objects, overlays and text. | 174 | // visibility, and to correctly draw map objects, overlays and text. |
451 | 175 | FieldsToDraw* | 175 | FieldsToDraw* draw_terrain(const Widelands::EditorGameBase& egbase, |
452 | 176 | draw_terrain(const Widelands::EditorGameBase& egbase, Workareas workarea, RenderTarget* dst); | 176 | Workareas workarea, |
453 | 177 | bool grid, | ||
454 | 178 | RenderTarget* dst); | ||
455 | 177 | 179 | ||
456 | 178 | // Not overriden from UI::Panel, instead we expect to be passed the data through. | 180 | // Not overriden from UI::Panel, instead we expect to be passed the data through. |
457 | 179 | bool handle_mousepress(uint8_t btn, int32_t x, int32_t y); | 181 | bool handle_mousepress(uint8_t btn, int32_t x, int32_t y); |
Performance is definitely an important point!
Reviewed, tested and working :)
@bunnybot merge