Skip to content

Commit

Permalink
Replace resources::screen with game_display singleton
Browse files Browse the repository at this point in the history
This is consistent with the use of display::get_singleton() (in fact, it's the same
pointer). It also makes the code more readable, and means we get to further clean up
the resources set.
  • Loading branch information
Vultraz committed Jan 26, 2018
1 parent d11b625 commit 786233d
Show file tree
Hide file tree
Showing 43 changed files with 170 additions and 181 deletions.
6 changes: 3 additions & 3 deletions src/actions/advancement.cpp
Expand Up @@ -134,19 +134,19 @@ namespace
}

u = resources::gameboard->units().find(loc);
resources::screen->invalidate_unit();
game_display::get_singleton()->invalidate_unit();

if (animate && u != resources::gameboard->units().end() && !CVideo::get_singleton().update_locked()) {
unit_animator animator;
animator.add_animation(&*u, "levelin", u->get_location(), map_location(), 0, true);
animator.start_animations();
animator.wait_for_end();
animator.set_all_standing();
resources::screen->invalidate(loc);
game_display::get_singleton()->invalidate(loc);
events::pump();
}

resources::screen->invalidate_all();
game_display::get_singleton()->invalidate_all();

return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/actions/attack.cpp
Expand Up @@ -963,7 +963,7 @@ void attack::fire_event(const std::string& n)
actions::recalculate_fog(defender_side);

if(update_display_) {
resources::screen->redraw_minimap();
game_display::get_singleton()->redraw_minimap();
}

fire_event("attack_end");
Expand Down Expand Up @@ -1227,7 +1227,7 @@ void attack::unit_killed(unit_info& attacker,
attacker.xp_ = game_config::kill_xp(defender.get_unit().level());
defender.xp_ = 0;

resources::screen->invalidate(attacker.loc_);
game_display::get_singleton()->invalidate(attacker.loc_);

game_events::entity_location death_loc(defender.loc_, defender.id_);
game_events::entity_location attacker_loc(attacker.loc_, attacker.id_);
Expand Down Expand Up @@ -1321,7 +1321,7 @@ void attack::unit_killed(unit_info& attacker,
preferences::encountered_units().insert(newunit->type_id());

if(update_display_) {
resources::screen->invalidate(death_loc);
game_display::get_singleton()->invalidate(death_loc);
}
}
} else {
Expand Down Expand Up @@ -1450,7 +1450,7 @@ void attack::perform()

// TODO: if we knew the viewing team, we could skip this display update
if(update_minimap_ && update_display_) {
resources::screen->redraw_minimap();
game_display::get_singleton()->redraw_minimap();
}

if(a_.valid()) {
Expand All @@ -1469,9 +1469,9 @@ void attack::perform()
d_.loc_, d_.valid() ? &d_.get_unit() : nullptr);

if(update_display_) {
resources::screen->invalidate_unit();
resources::screen->invalidate(a_.loc_);
resources::screen->invalidate(d_.loc_);
game_display::get_singleton()->invalidate_unit();
game_display::get_singleton()->invalidate(a_.loc_);
game_display::get_singleton()->invalidate(d_.loc_);
}

if(OOS_error_) {
Expand Down
14 changes: 7 additions & 7 deletions src/actions/create.cpp
Expand Up @@ -663,9 +663,9 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
}
// Make sure the unit appears (if either !show or the animation is suppressed).
new_unit_itor->set_hidden(false);
if ( resources::screen != nullptr ) {
resources::screen->invalidate(current_loc);
resources::screen->redraw_minimap();
if ( game_display::get_singleton() != nullptr ) {
game_display::get_singleton()->invalidate(current_loc);
game_display::get_singleton()->redraw_minimap();
}

// Village capturing.
Expand Down Expand Up @@ -724,8 +724,8 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
}

// Update the screen.
if ( resources::screen != nullptr )
resources::screen->invalidate_game_status();
if ( game_display::get_singleton() != nullptr )
game_display::get_singleton()->invalidate_game_status();
// Other updates were done by place_recruit().
}

Expand Down Expand Up @@ -771,8 +771,8 @@ bool recall_unit(const std::string & id, team & current_team,
}

// Update the screen.
if ( resources::screen != nullptr )
resources::screen->invalidate_game_status();
if ( game_display::get_singleton() != nullptr )
game_display::get_singleton()->invalidate_game_status();
// Other updates were done by place_recruit().

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/actions/heal.cpp
Expand Up @@ -238,7 +238,7 @@ namespace {
patient.heal(amount);
else if ( amount < 0 )
patient.take_hit(-amount);
resources::screen->invalidate_unit();
game_display::get_singleton()->invalidate_unit();
}


Expand Down Expand Up @@ -347,7 +347,7 @@ void calculate_healing(int side, bool update_display)
}

const team & viewing_team =
resources::gameboard->teams()[resources::screen->viewing_team()];
resources::gameboard->teams()[game_display::get_singleton()->viewing_team()];
if (!resources::controller->is_skipping_replay() && update_display &&
patient.is_visible_to_team(viewing_team, *resources::gameboard, false) )
{
Expand Down
14 changes: 7 additions & 7 deletions src/actions/move.cpp
Expand Up @@ -174,8 +174,8 @@ game_events::pump_result_t get_village(const map_location& loc, int side, bool *
}

if(not_defeated) {
if (resources::screen != nullptr) {
resources::screen->invalidate(loc);
if (game_display::get_singleton() != nullptr) {
game_display::get_singleton()->invalidate(loc);
}
return t->get_village(loc, old_owner_side, fire_event ? resources::gamedata : nullptr);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ namespace { // Private helpers for move_unit()
: spectator_(move_spectator)
, skip_sighting_(skip_sightings)
, skip_ally_sighting_(skip_ally_sightings)
, playing_team_is_viewing_(resources::screen->playing_team() == resources::screen->viewing_team() || resources::screen->show_everything())
, playing_team_is_viewing_(game_display::get_singleton()->playing_team() == game_display::get_singleton()->viewing_team() || game_display::get_singleton()->show_everything())
, route_(route)
, begin_(route.begin())
, full_end_(route.end())
Expand Down Expand Up @@ -510,7 +510,7 @@ namespace { // Private helpers for move_unit()
const route_iterator & step_to,
unit_display::unit_mover & animator)
{
game_display &disp = *resources::screen;
game_display &disp = *game_display::get_singleton();

// Adjust the movement even if we cannot move yet.
// We will eventually be able to move if nothing unexpected
Expand Down Expand Up @@ -875,7 +875,7 @@ namespace { // Private helpers for move_unit()
{
// Convenient alias:
unit_map &units = resources::gameboard->units();
game_display &disp = *resources::screen;
game_display &disp = *game_display::get_singleton();

// Find the unit at the indicated location.
unit_map::iterator ambusher = units.find(hex);
Expand Down Expand Up @@ -1105,7 +1105,7 @@ namespace { // Private helpers for move_unit()
}

// Update the screen.
resources::screen->redraw_minimap();
game_display::get_singleton()->redraw_minimap();
}


Expand All @@ -1115,7 +1115,7 @@ namespace { // Private helpers for move_unit()
void unit_mover::feedback() const
{
// Alias some resources.
game_display &disp = *resources::screen;
game_display &disp = *game_display::get_singleton();

// Multiple messages may be displayed simultaneously
// this variable is used to keep them from overlapping
Expand Down
6 changes: 3 additions & 3 deletions src/actions/undo.cpp
Expand Up @@ -350,7 +350,7 @@ void undo_list::undo()

const events::command_disabler disable_commands;

game_display & gui = *resources::screen;
game_display & gui = *game_display::get_singleton();

// Get the action to undo. (This will be placed on the redo stack, but
// only if the undo is successful.)
Expand Down Expand Up @@ -400,7 +400,7 @@ void undo_list::redo()

const events::command_disabler disable_commands;

game_display & gui = *resources::screen;
game_display & gui = *game_display::get_singleton();

// Get the action to redo. (This will be placed on the undo stack, but
// only if the redo is successful.)
Expand Down Expand Up @@ -437,7 +437,7 @@ void undo_list::redo()
*/
bool undo_list::apply_shroud_changes() const
{
game_display &disp = *resources::screen;
game_display &disp = *game_display::get_singleton();
team &tm = resources::gameboard->get_team(side_);
// No need to do clearing if fog/shroud has been kept up-to-date.
if ( tm.auto_shroud_updates() || !tm.fog_or_shroud() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/undo_move_action.cpp
Expand Up @@ -66,7 +66,7 @@ void move_action::write(config & cfg) const
*/
bool move_action::undo(int)
{
game_display & gui = *resources::screen;
game_display & gui = *game_display::get_singleton();
unit_map & units = resources::gameboard->units();

// Copy some of our stored data.
Expand Down
2 changes: 1 addition & 1 deletion src/actions/undo_recall_action.cpp
Expand Up @@ -67,7 +67,7 @@ void recall_action::write(config & cfg) const
*/
bool recall_action::undo(int side)
{
game_display & gui = *resources::screen;
game_display & gui = *game_display::get_singleton();
unit_map & units = resources::gameboard->units();
team &current_team = resources::gameboard->get_team(side);

Expand Down
2 changes: 1 addition & 1 deletion src/actions/undo_recruit_action.cpp
Expand Up @@ -68,7 +68,7 @@ void recruit_action::write(config & cfg) const
*/
bool recruit_action::undo(int side)
{
game_display & gui = *resources::screen;
game_display & gui = *game_display::get_singleton();
unit_map & units = resources::gameboard->units();
team &current_team = resources::gameboard->get_team(side);

Expand Down
10 changes: 5 additions & 5 deletions src/actions/unit_creator.cpp
Expand Up @@ -31,13 +31,13 @@
#include "log.hpp"
#include "map/map.hpp"
#include "pathfind/pathfind.hpp"
#include "resources.hpp" // for resources::screen, resources::gamedata
#include "resources.hpp" // for game_display::get_singleton(), resources::gamedata
#include "team.hpp" //for team
#include "units/unit.hpp" // for unit
#include "units/udisplay.hpp" // for unit_display
#include "variable.hpp" // for vconfig

#include "game_display.hpp" // for resources::screen
#include "game_display.hpp" // for game_display::get_singleton()

static lg::log_domain log_engine("engine");
#define DBG_NG LOG_STREAM(debug, log_engine)
Expand Down Expand Up @@ -221,7 +221,7 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo
preferences::encountered_units().insert(new_unit.type_id());
}

bool show = show_ && (resources::screen !=nullptr) && !resources::screen->fogged(loc);
bool show = show_ && (game_display::get_singleton() !=nullptr) && !game_display::get_singleton()->fogged(loc);
bool animate = show && anim;

if (get_village_) {
Expand All @@ -236,10 +236,10 @@ void unit_creator::post_create(const map_location &loc, const unit &new_unit, bo
resources::game_events->pump().fire("unit_placed", loc);
}

if (resources::screen!=nullptr) {
if (game_display::get_singleton()!=nullptr) {

if (invalidate_ ) {
resources::screen->invalidate(loc);
game_display::get_singleton()->invalidate(loc);
}

if (animate) {
Expand Down
24 changes: 12 additions & 12 deletions src/actions/vision.cpp
Expand Up @@ -272,13 +272,13 @@ bool shroud_clearer::clear_loc(team &tm, const map_location &loc,

// Possible screen invalidation.
if ( was_fogged ) {
resources::screen->invalidate(loc);
game_display::get_singleton()->invalidate(loc);
// Need to also invalidate adjacent hexes to get rid of the
// "fog edge" graphics.
map_location adjacent[6];
get_adjacent_tiles(loc, adjacent);
for ( int i = 0; i != 6; ++i )
resources::screen->invalidate(adjacent[i]);
game_display::get_singleton()->invalidate(adjacent[i]);
}

// Check for units?
Expand Down Expand Up @@ -336,8 +336,8 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
move_unit_spectator * spectator, bool instant)
{
// Give animations a chance to progress; see bug #20324.
if ( !instant && resources::screen )
resources::screen->draw(true);
if ( !instant && game_display::get_singleton() )
game_display::get_singleton()->draw(true);

bool cleared_something = false;
// Dummy variables to make some logic simpler.
Expand All @@ -351,15 +351,15 @@ bool shroud_clearer::clear_unit(const map_location &view_loc, team &view_team,
if ( view_team_ != &view_team ) {
calculate_jamming(&view_team);
// Give animations a chance to progress; see bug #20324.
if ( !instant && resources::screen )
resources::screen->draw(true);
if ( !instant && game_display::get_singleton() )
game_display::get_singleton()->draw(true);
}

// Determine the hexes to clear.
pathfind::vision_path sight(costs, slowed, sight_range, view_loc, jamming_);
// Give animations a chance to progress; see bug #20324.
if ( !instant && resources::screen )
resources::screen->draw(true);
if ( !instant && game_display::get_singleton() )
game_display::get_singleton()->draw(true);

// Clear the fog.
for (const pathfind::paths::step &dest : sight.destinations) {
Expand Down Expand Up @@ -580,9 +580,9 @@ game_events::pump_result_t shroud_clearer::fire_events()
*/
void shroud_clearer::invalidate_after_clear()
{
resources::screen->invalidate_game_status();
resources::screen->recalculate_minimap();
resources::screen->labels().recalculate_shroud();
game_display::get_singleton()->invalidate_game_status();
game_display::get_singleton()->recalculate_minimap();
game_display::get_singleton()->labels().recalculate_shroud();
// The tiles are invalidated as they are cleared, so no need
// to invalidate them here.
}
Expand Down Expand Up @@ -721,7 +721,7 @@ void recalculate_fog(int side)
tm.refog();
// Invalidate the screen before clearing the shroud.
// This speeds up the invalidations within clear_shroud_unit().
resources::screen->invalidate_all();
game_display::get_singleton()->invalidate_all();

shroud_clearer clearer;
for (const unit &u : resources::gameboard->units())
Expand Down
4 changes: 2 additions & 2 deletions src/ai/contexts.cpp
Expand Up @@ -326,7 +326,7 @@ game_info& readwrite_context_impl::get_info_w(){
void readonly_context_impl::diagnostic(const std::string& msg)
{
if(game_config::debug) {
resources::screen->set_diagnostic(msg);
game_display::get_singleton()->set_diagnostic(msg);
}
}

Expand All @@ -340,7 +340,7 @@ const team& readonly_context_impl::current_team() const
void readonly_context_impl::log_message(const std::string& msg)
{
if(game_config::debug) {
resources::screen->get_chat_manager().add_chat_message(time(nullptr), "ai", get_side(), msg,
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), "ai", get_side(), msg,
events::chat_handler::MESSAGE_PUBLIC, false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ai/default/recruitment.cpp
Expand Up @@ -732,10 +732,10 @@ void recruitment::show_important_hexes() const {
if (!game_config::debug) {
return;
}
resources::screen->labels().clear_all();
game_display::get_singleton()->labels().clear_all();
for (const map_location& loc : important_hexes_) {
// Little hack: use map_location north from loc and make 2 linebreaks to center the "X".
resources::screen->labels().set_label(loc.get_direction(map_location::NORTH), "\n\nX");
game_display::get_singleton()->labels().set_label(loc.get_direction(map_location::NORTH), "\n\nX");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ai/formula/ai.cpp
Expand Up @@ -135,7 +135,7 @@ void formula_ai::handle_exception(formula_error& e, const std::string& failed_op

void formula_ai::display_message(const std::string& msg) const
{
resources::screen->get_chat_manager().add_chat_message(time(nullptr), "wfl", get_side(), msg,
game_display::get_singleton()->get_chat_manager().add_chat_message(time(nullptr), "wfl", get_side(), msg,
events::chat_handler::MESSAGE_PUBLIC, false);

}
Expand Down
3 changes: 1 addition & 2 deletions src/arrow.cpp
Expand Up @@ -21,15 +21,14 @@

#include "game_display.hpp"
#include "log.hpp"
#include "resources.hpp"

static lg::log_domain log_arrows("arrows");
#define ERR_ARR LOG_STREAM(err, log_arrows)
#define WRN_ARR LOG_STREAM(warn, log_arrows)
#define LOG_ARR LOG_STREAM(info, log_arrows)
#define DBG_ARR LOG_STREAM(debug, log_arrows)

#define SCREEN (static_cast<display*>(resources::screen))
#define SCREEN (static_cast<display*>(game_display::get_singleton()))

arrow::arrow(bool hidden)
: layer_(display::LAYER_ARROWS)
Expand Down

1 comment on commit 786233d

@jyrkive
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the resources::screen alias wasn't a bad thing.

Please sign in to comment.