Removed the old surface drawing queue implementation, except for the layer enum

Kept that since it's still used in some places and is good for reference.
Also removed display::get_screen_surface which was used in said impl.
This commit is contained in:
Charles Dang 2018-03-20 22:07:34 +11:00
parent 0b8e86df85
commit 239fde451a
9 changed files with 4 additions and 283 deletions

View file

@ -790,7 +790,6 @@
<ClCompile Include="..\..\src\display.cpp" />
<ClCompile Include="..\..\src\display_chat_manager.cpp" />
<ClCompile Include="..\..\src\display_context.cpp" />
<ClCompile Include="..\..\src\drawing_queue.cpp" />
<ClCompile Include="..\..\src\editor\action\action.cpp">
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)Editor\Action\</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='ReleaseDEBUG|Win32'">$(IntDir)Editor\Action\</ObjectFileName>

View file

@ -1421,7 +1421,6 @@
<ClCompile Include="..\..\src\display.cpp" />
<ClCompile Include="..\..\src\display_chat_manager.cpp" />
<ClCompile Include="..\..\src\display_context.cpp" />
<ClCompile Include="..\..\src\drawing_queue.cpp" />
<ClCompile Include="..\..\src\events.cpp" />
<ClCompile Include="..\..\src\fake_unit_manager.cpp" />
<ClCompile Include="..\..\src\fake_unit_ptr.cpp" />

View file

@ -4,7 +4,6 @@ desktop/clipboard.cpp
deprecation.cpp
display.cpp
display_context.cpp
drawing_queue.cpp
events.cpp
floating_label.cpp
font/font_config.cpp

View file

@ -21,6 +21,7 @@
#include "game_display.hpp"
#include "log.hpp"
#include "sdl/texture.hpp"
static lg::log_domain log_arrows("arrows");
#define ERR_ARR LOG_STREAM(err, log_arrows)

View file

@ -248,16 +248,11 @@ public:
return video_;
}
/** return the screen surface or the surface used for map_screenshot. */
surface& get_screen_surface()
{
return video_.getSurface();
}
virtual bool in_game() const
{
return false;
}
virtual bool in_editor() const
{
return false;

View file

@ -1,127 +0,0 @@
/*
Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "drawing_queue.hpp"
#include "display.hpp"
#include "sdl/surface.hpp"
#include "video.hpp"
namespace
{
enum {
// You may adjust the following when needed:
// maximum border. 3 should be safe even if a larger border is in use somewhere
MAX_BORDER = 3,
// store x, y, and layer in one 32 bit integer
// 4 most significant bits == layer group => 16
BITS_FOR_LAYER_GROUP = 4,
// 10 second most significant bits == y => 1024
BITS_FOR_Y = 10,
// 1 third most significant bit == x parity => 2
BITS_FOR_X_PARITY = 1,
// 8 fourth most significant bits == layer => 256
BITS_FOR_LAYER = 8,
// 9 least significant bits == x / 2 => 512 (really 1024 for x)
BITS_FOR_X_OVER_2 = 9
};
} // end anon namespace
drawing_queue::buffer_key::layer_group_array drawing_queue::buffer_key::layer_groups {{
LAYER_TERRAIN_BG,
LAYER_UNIT_FIRST,
LAYER_UNIT_MOVE_DEFAULT,
// Make sure the movement doesn't show above fog and reachmap.
LAYER_REACHMAP
}};
drawing_queue::buffer_key::buffer_key(const map_location &loc, layer layer)
: key_(0)
{
// Start with the index of last group entry...
unsigned int group_i = layer_groups.size() - 1;
// ...and works backwards until the group containing the specified layer is found.
while(layer < layer_groups[group_i]) {
--group_i;
}
enum {
SHIFT_LAYER = BITS_FOR_X_OVER_2,
SHIFT_X_PARITY = BITS_FOR_LAYER + SHIFT_LAYER,
SHIFT_Y = BITS_FOR_X_PARITY + SHIFT_X_PARITY,
SHIFT_LAYER_GROUP = BITS_FOR_Y + SHIFT_Y
};
static_assert(SHIFT_LAYER_GROUP + BITS_FOR_LAYER_GROUP == sizeof(key_) * 8, "Bit field too small");
/* The parity of x must be more significant than the layer but less significant than y.
* Thus basically every row is split in two: First the row containing all the odd x
* then the row containing all the even x. Since thus the least significant bit of x is
* not required for x ordering anymore it can be shifted out to the right.
*/
const unsigned int x_parity = static_cast<unsigned int>(loc.x) & 1;
key_ = (group_i << SHIFT_LAYER_GROUP) | (static_cast<unsigned int>(loc.y + MAX_BORDER) << SHIFT_Y);
key_ |= (x_parity << SHIFT_X_PARITY);
key_ |= (static_cast<unsigned int>(layer) << SHIFT_LAYER) | static_cast<unsigned int>(loc.x + MAX_BORDER) / 2;
}
void drawing_queue::render_buffer()
{
// std::list::sort() is a stable sort
buffer_.sort();
display* disp = display::get_singleton();
SDL_Rect clip_rect = disp->map_area();
surface& screen = disp->get_screen_surface();
clip_rect_setter set_clip_rect(screen, &clip_rect);
/* Info regarding the rendering algorithm.
*
* In order to render a hex properly it needs to be rendered per row. On
* this row several layers need to be drawn at the same time. Mainly the
* unit and the background terrain. This is needed since both can spill
* in the next hex. The foreground terrain needs to be drawn before to
* avoid decapitation a unit.
*
* This ended in the following priority order:
* layergroup > location > layer > 'blit_helper' > surface
*/
for(const blit_helper& blit : buffer_) {
for(const surface& surf : blit.surfaces()) {
// Note that dstrect can be changed by sdl_blit
// and so a new instance should be initialized
// to pass to each call to sdl_blit.
SDL_Rect dstrect {blit.x(), blit.y(), 0, 0};
SDL_Rect srcrect = blit.clip();
SDL_Rect* srcrectArg = (srcrect.x | srcrect.y | srcrect.w | srcrect.h) ? &srcrect : nullptr;
sdl_blit(surf, srcrectArg, screen, &dstrect);
// NOTE: the screen part should already be marked as 'to update'
}
}
// Clear the buffer.
buffer_.clear();
}

View file

@ -14,33 +14,9 @@
#pragma once
#include "map/location.hpp"
#include "sdl/texture.hpp"
#include <SDL_rect.h>
#include <array>
#include <list>
#include <vector>
class drawing_queue
{
public:
drawing_queue()
: buffer_()
{
}
/** Draws the contents of the buffer to screen and clears it. */
void render_buffer();
/** Adds a new item to the buffer. */
template<typename... T>
void add_item(T&&... args)
{
buffer_.emplace_back(std::forward<T>(args)...);
}
/**
* The various map rendering layers. This controls the internal rendering order.
*/
@ -119,127 +95,4 @@ public:
/** The map border. */
LAYER_BORDER,
};
private:
/**
* In order to render a hex properly it needs to be rendered per row. On
* this row several layers need to be drawn at the same time. Mainly the
* unit and the background terrain. This is needed since both can spill
* in the next hex. The foreground terrain needs to be drawn before to
* avoid decapitation a unit.
*
* In other words:
* for every layer
* for every row (starting from the top)
* for every hex in the row
* ...
*
* this is modified to:
* for every layer group
* for every row (starting from the top)
* for every layer in the group
* for every hex in the row
* ...
*
* * Surfaces are rendered per level in a map.
* * Per level the items are rendered per location these locations are
* stored in the drawing order required for units.
* * every location has a vector with surfaces, each with its own screen
* coordinate to render at.
* * every vector element has a vector with surfaces to render.
*/
class buffer_key
{
public:
buffer_key(const map_location& loc, layer layer);
bool operator<(const buffer_key& rhs) const
{
return key_ < rhs.key_;
}
private:
unsigned int key_;
using layer_group_array = const std::array<layer, 4>;
// The drawing is done per layer_group, with the range per group being [low, high].
// FIXME: better documentation.
static layer_group_array layer_groups;
};
/** Helper structure for rendering the buffer contents. */
class blit_helper
{
public:
blit_helper(const layer layer,
const map_location& loc,
const int x,
const int y,
const surface& surf,
const SDL_Rect& clip)
: x_(x)
, y_(y)
, surf_(1, surf)
, clip_(clip)
, key_(loc, layer)
{
}
blit_helper(const layer layer,
const map_location& loc,
const int x,
const int y,
const std::vector<surface>& surf,
const SDL_Rect& clip)
: x_(x)
, y_(y)
, surf_(surf)
, clip_(clip)
, key_(loc, layer)
{
}
int x() const
{
return x_;
}
int y() const
{
return y_;
}
const std::vector<surface>& surfaces() const
{
return surf_;
}
const SDL_Rect& clip() const
{
return clip_;
}
bool operator<(const blit_helper& rhs) const
{
return key_ < rhs.key_;
}
private:
/** x screen coordinate to render at. */
int x_;
/** y screen coordinate to render at. */
int y_;
/** surface(s) to render. */
std::vector<surface> surf_;
/** The clipping area of the source. If omitted the entire source is used. */
SDL_Rect clip_;
buffer_key key_;
};
std::list<blit_helper> buffer_;
};

View file

@ -18,6 +18,7 @@
#include "lexical_cast.hpp"
#include "ogl/utils.hpp"
#include "reports.hpp"
#include "sdl/texture.hpp"
#include "team.hpp"
#include "terrain/builder.hpp"
#include "units/map.hpp"

View file

@ -23,6 +23,7 @@
#include "display.hpp"
#include "log.hpp"
#include "preferences/game.hpp"
#include "sdl/texture.hpp"
#include "serialization/string_utils.hpp"
#include <iostream>