Merge branch 'fixup_segfaulting_editor'

This commit is contained in:
Chris Beck 2014-06-11 01:31:25 -04:00
commit 3b70c87f5b
13 changed files with 66 additions and 15 deletions

View file

@ -191,6 +191,7 @@
<Unit filename="../../src/dialogs.hpp" />
<Unit filename="../../src/display.cpp" />
<Unit filename="../../src/display.hpp" />
<Unit filename="../../src/display_context.cpp" />
<Unit filename="../../src/display_context.hpp" />
<Unit filename="../../src/editor/action/action_base.hpp" />
<Unit filename="../../src/editor/action/action.cpp" />

View file

@ -229,6 +229,7 @@
<Unit filename="..\..\src\dialogs.hpp" />
<Unit filename="..\..\src\display.cpp" />
<Unit filename="..\..\src\display.hpp" />
<Unit filename="..\..\src\display_context.cpp" />
<Unit filename="..\..\src\display_context.hpp" />
<Unit filename="..\..\src\editor\action\action.cpp" />
<Unit filename="..\..\src\editor\action\action.hpp" />

View file

@ -20052,6 +20052,10 @@
RelativePath="..\..\src\display.hpp"
>
</File>
<File
RelativePath="..\..\src\display_context.cpp"
>
</File>
<File
RelativePath="..\..\src\display_context.hpp"
>

View file

@ -916,6 +916,7 @@ set(libwesnoth-game_STAT_SRC
construct_dialog.cpp
cursor.cpp
display.cpp
display_context.cpp
events.cpp
font.cpp
format_time_summary.cpp

View file

@ -75,6 +75,7 @@ libwesnoth_sources = Split("""
construct_dialog.cpp
cursor.cpp
display.cpp
display_context.cpp
events.cpp
format_time_summary.cpp
generic_event.cpp

View file

@ -206,6 +206,7 @@ display::display(const display_context * dc, CVideo& video, const config& theme_
#endif
{
singleton_ = this;
resources::disp_context = dc_;
blindfold_ctr_ = 0;
@ -565,6 +566,7 @@ void display::change_display_context(const display_context * dc)
{
dc_ = dc;
builder_->change_map(&dc_->map()); //TODO: Should display_context own and initalize the builder object?
resources::disp_context = dc_;
}
void display::blindfold(bool value)

31
src/display_context.cpp Normal file
View file

@ -0,0 +1,31 @@
/*
Copyright (C) 2014 by Chris Beck <render787@gmail.com>
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 "display_context.hpp"
#include "map.hpp"
#include "map_location.hpp"
#include "team.hpp"
#include "unit.hpp"
#include "unit_map.hpp"
const unit * display_context::get_visible_unit(const map_location & loc, const team &current_team, bool see_all) const
{
if (!map().on_board(loc)) return NULL;
const unit_map::const_iterator u = units().find(loc);
if (!u.valid() || !u->is_visible_to_team(current_team, map(), see_all)) {
return NULL;
}
return &*u;
}

View file

@ -28,12 +28,17 @@ class team;
class gamemap;
class unit_map;
class unit;
struct map_location;
class display_context {
public:
virtual const std::vector<team> & teams() const = 0;
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;
const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;
virtual ~display_context() {}
};

View file

@ -24,8 +24,8 @@
#include "map_location.hpp"
#include "config.hpp"
#include "display_context.hpp"
#include "formula_string_utils.hpp"
#include "game_board.hpp"
#include "map.hpp"
#include "resources.hpp"
#include "gettext.hpp"
@ -318,7 +318,7 @@ std::vector<map_location> parse_location_range(const std::string &x, const std::
std::vector<map_location> res;
const std::vector<std::string> xvals = utils::split(x);
const std::vector<std::string> yvals = utils::split(y);
const gamemap *map = & resources::gameboard->map();
const gamemap *map = & resources::disp_context->map();
assert(map);
int xmin = 1, xmax = map->w(), ymin = 1, ymax = map->h();
if (with_border) {

View file

@ -16,6 +16,7 @@
#include "actions/attack.hpp"
#include "attack_prediction.hpp"
#include "display_context.hpp"
#include "editor/editor_controller.hpp"
#include "editor/palette/terrain_palettes.hpp"
#include "font.hpp"
@ -123,14 +124,14 @@ namespace reports {
static const unit *get_visible_unit()
{
return resources::gameboard->get_visible_unit(resources::screen->displayed_unit_hex(),
return resources::disp_context->get_visible_unit(resources::screen->displayed_unit_hex(),
(*resources::teams)[resources::screen->viewing_team()],
resources::screen->show_everything());
}
static const unit *get_selected_unit()
{
return resources::gameboard->get_visible_unit(resources::screen->selected_hex(),
return resources::disp_context->get_visible_unit(resources::screen->selected_hex(),
(*resources::teams)[resources::screen->viewing_team()],
resources::screen->show_everything());
}
@ -318,7 +319,7 @@ static config unit_status(const unit* u)
if (!u) return report();
config res;
map_location displayed_unit_hex = resources::screen->displayed_unit_hex();
if (resources::gameboard->map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) {
if (resources::disp_context->map().on_board(displayed_unit_hex) && u->invisible(displayed_unit_hex)) {
add_status(res, "misc/invisible.png", N_("invisible: "),
N_("This unit is invisible. It cannot be seen or attacked by enemy units."));
}
@ -528,8 +529,8 @@ static config unit_defense(const unit* u, const map_location& displayed_unit_hex
}
std::ostringstream str, tooltip;
const gamemap &map = resources::gameboard->map();
if(!resources::gameboard->map().on_board(displayed_unit_hex)) {
const gamemap &map = resources::disp_context->map();
if(!resources::disp_context->map().on_board(displayed_unit_hex)) {
return report();
}
@ -617,7 +618,7 @@ static config unit_moves(const unit* u)
if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER)
continue;
const terrain_type& info = resources::gameboard->map().get_terrain_info(terrain);
const terrain_type& info = resources::disp_context->map().get_terrain_info(terrain);
if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
@ -1199,7 +1200,7 @@ static config unit_box_at(const map_location& mouseover_hex)
else if (local_tod.bonus_modified < 0) local_tod_image += "~DARKEN()";
if (preferences::flip_time()) local_tod_image += "~FL(horiz)";
const gamemap &map = resources::gameboard->map();
const gamemap &map = resources::disp_context->map();
t_translation::t_terrain terrain = map.get_terrain(mouseover_hex);
//if (terrain == t_translation::OFF_MAP_USER)
@ -1278,13 +1279,13 @@ REPORT_GENERATOR(villages)
str << td.villages << '/';
if (viewing_team.uses_shroud()) {
int unshrouded_villages = 0;
BOOST_FOREACH(const map_location &loc, resources::gameboard->map().villages()) {
BOOST_FOREACH(const map_location &loc, resources::disp_context->map().villages()) {
if (!viewing_team.shrouded(loc))
++unshrouded_villages;
}
str << unshrouded_villages;
} else {
str << resources::gameboard->map().villages().size();
str << resources::disp_context->map().villages().size();
}
return gray_inactive(str.str());
}
@ -1351,7 +1352,7 @@ void blit_tced_icon(config &cfg, const std::string &terrain_id, const std::strin
REPORT_GENERATOR(terrain_info)
{
const gamemap &map = resources::gameboard->map();
const gamemap &map = resources::disp_context->map();
map_location mouseover_hex = display::get_singleton()->mouseover_hex();
if (!map.on_board(mouseover_hex))
@ -1397,7 +1398,7 @@ REPORT_GENERATOR(terrain_info)
REPORT_GENERATOR(terrain)
{
const gamemap &map = resources::gameboard->map();
const gamemap &map = resources::disp_context->map();
int viewing_side = resources::screen->viewing_side();
const team &viewing_team = (*resources::teams)[viewing_side - 1];
map_location mouseover_hex = resources::screen->mouseover_hex();
@ -1446,7 +1447,7 @@ REPORT_GENERATOR(zoom_level)
REPORT_GENERATOR(position)
{
const gamemap &map = resources::gameboard->map();
const gamemap &map = resources::disp_context->map();
map_location mouseover_hex = resources::screen->mouseover_hex(),
displayed_unit_hex = resources::screen->displayed_unit_hex(),
selected_hex = resources::screen->selected_hex();

View file

@ -24,6 +24,7 @@ namespace resources
LuaKernel *lua_kernel = NULL;
persist_manager *persist = NULL;
game_display *screen = NULL;
const display_context *disp_context = NULL;
soundsource::manager *soundsources = NULL;
std::vector<team> *teams = NULL;
::tod_manager *tod_manager = NULL;

View file

@ -20,6 +20,7 @@
class game_board;
class game_config_manager;
class game_display;
class display_context;
class gamemap;
class game_data;
class LuaKernel;
@ -48,6 +49,7 @@ namespace resources
extern persist_manager *persist;
extern game_classification *classification;
extern game_display *screen;
extern const display_context *disp_context;
extern const mp_game_settings *mp_settings;
extern soundsource::manager *soundsources;
extern std::vector<team> *teams;

View file

@ -15,6 +15,7 @@
#include "tod_manager.hpp"
#include "wml_exception.hpp"
#include "gettext.hpp"
#include "display_context.hpp"
#include "formula_string_utils.hpp"
#include "gamestatus.hpp"
#include "log.hpp"
@ -194,7 +195,7 @@ const time_of_day& tod_manager::get_time_of_day(const map_location& loc, int n_t
const time_of_day tod_manager::get_illuminated_time_of_day(const map_location& loc, int for_turn) const
{
const gamemap& map = resources::gameboard->map();
const gamemap& map = resources::disp_context->map();
const unit_map& units = *resources::units;
// get ToD ignoring illumination