Skip to content

Commit

Permalink
remove display depencendy from multiplayer.cpp and campaign_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgtdf committed Jan 12, 2016
1 parent 9a00374 commit 6e3aa08
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 120 deletions.
120 changes: 61 additions & 59 deletions src/game_initialization/multiplayer.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/game_initialization/multiplayer.hpp
Expand Up @@ -20,7 +20,7 @@
#include "multiplayer_ui.hpp"

class config;
class game_display;
class CVideo;

namespace mp {

Expand All @@ -35,41 +35,41 @@ void run_lobby_loop(CVideo& v, mp::ui& ui);

/** Starts a multiplayer game in single-user mode.
*
* @param disp The global display
* @param video The global display
* @param game_config The global, top-level WML configuration for the game
*/
void start_local_game(game_display& disp, const config& game_config,
void start_local_game(CVideo& video, const config& game_config,
saved_game& state);

/** Starts a multiplayer game in single-user mode.
*
* Same parameters as start_local_game plus:
* cmdline_opts The commandline options
*/
void start_local_game_commandline(game_display& disp, const config& game_config,
void start_local_game_commandline(CVideo& video, const config& game_config,
saved_game& state, const commandline_options& cmdline_opts);

/** Starts a multiplayer game in client mode.
*
* @param disp The global display
* @param video The global display
* @param game_config The global, top-level WML configuration for the game
* @param host The host to connect to.
*/
void start_client(game_display& disp, const config& game_config,
void start_client(CVideo& video, const config& game_config,
saved_game& state, const std::string& host);

/**
* Opens mp::connect screen and sets game state according to the
* changes made.
*/
mp::ui::result goto_mp_connect(game_display& disp, ng::connect_engine& engine,
mp::ui::result goto_mp_connect(CVideo& video, ng::connect_engine& engine,
const config& game_config, const std::string& game_name);

/**
* Opens mp::wait screen and sets game state according to the
* changes made.
*/
mp::ui::result goto_mp_wait(saved_game& state, game_display& disp,
mp::ui::result goto_mp_wait(saved_game& state, CVideo& video,
const config& game_config, bool observe);

}
Expand Down
34 changes: 17 additions & 17 deletions src/game_initialization/playcampaign.cpp
Expand Up @@ -184,13 +184,13 @@ void campaign_controller::show_carryover_message(playsingle_controller& playcont
}

if (end_level.transient.carryover_report) {
gui2::show_transient_message(disp_.video(), title, report.str(), "", true);
gui2::show_transient_message(video_, title, report.str(), "", true);
}
}

LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data &end_level)
{
playsingle_controller playcontroller(is_replay_ ? state_.get_replay_starting_pos() : state_.get_starting_pos(), state_, game_config_, tdata_, disp_.video(), false);
playsingle_controller playcontroller(is_replay_ ? state_.get_replay_starting_pos() : state_.get_starting_pos(), state_, game_config_, tdata_, video_, false);
LOG_NG << "created objects... " << (SDL_GetTicks() - playcontroller.get_ticks()) << "\n";
if(is_replay_) {
playcontroller.enable_replay(is_unit_test_);
Expand All @@ -212,7 +212,7 @@ LEVEL_RESULT campaign_controller::playsingle_scenario(end_level_data &end_level)
end_level = playcontroller.get_end_level_data_const();

show_carryover_message(playcontroller, end_level, res);
if(!disp_.video().faked())
if(!video_.faked())
{
playcontroller.maybe_linger();
}
Expand All @@ -225,7 +225,7 @@ LEVEL_RESULT campaign_controller::playmp_scenario(end_level_data &end_level)
{

playmp_controller playcontroller(state_.get_starting_pos(), state_,
game_config_, tdata_, disp_.video(), mp_info_);
game_config_, tdata_, video_, mp_info_);
LEVEL_RESULT res = playcontroller.play_scenario(state_.get_starting_pos());

//Check if the player started as mp client and changed to host
Expand All @@ -243,7 +243,7 @@ LEVEL_RESULT campaign_controller::playmp_scenario(end_level_data &end_level)
//(we want to see that message before entering the linger mode)
show_carryover_message(playcontroller, end_level, res);
}
if(!disp_.video().faked())
if(!video_.faked())
{
playcontroller.maybe_linger();
}
Expand Down Expand Up @@ -295,24 +295,24 @@ LEVEL_RESULT campaign_controller::play_game()
res = playmp_scenario(end_level);
}
} catch(game::load_game_failed& e) {
gui2::show_error_message(disp_.video(), _("The game could not be loaded: ") + e.message);
gui2::show_error_message(video_, _("The game could not be loaded: ") + e.message);
return LEVEL_RESULT::QUIT;
} catch(quit_game_exception&) {
LOG_NG << "The game was aborted\n";
return LEVEL_RESULT::QUIT;
} catch(game::game_error& e) {
gui2::show_error_message(disp_.video(), _("Error while playing the game: ") + e.message);
gui2::show_error_message(video_, _("Error while playing the game: ") + e.message);
return LEVEL_RESULT::QUIT;
} catch(incorrect_map_format_error& e) {
gui2::show_error_message(disp_.video(), std::string(_("The game map could not be loaded: ")) + e.message);
gui2::show_error_message(video_, std::string(_("The game map could not be loaded: ")) + e.message);
return LEVEL_RESULT::QUIT;
} catch (mapgen_exception& e) {
gui2::show_error_message(disp_.video(), std::string(_("Map generator error: ") + e.message));
gui2::show_error_message(video_, std::string(_("Map generator error: ") + e.message));
} catch(config::error& e) {
gui2::show_error_message(disp_.video(), _("Error while reading the WML: ") + e.message);
gui2::show_error_message(video_, _("Error while reading the WML: ") + e.message);
return LEVEL_RESULT::QUIT;
} catch(twml_exception& e) {
e.show(disp_.video());
e.show(video_);
return LEVEL_RESULT::QUIT;
}

Expand All @@ -334,7 +334,7 @@ LEVEL_RESULT campaign_controller::play_game()
}
if (preferences::save_replays() && end_level.replay_save) {
savegame::replay_savegame save(state_, preferences::save_compression_format());
save.save_game_automatic(disp_.video(), true);
save.save_game_automatic(video_, true);
}

state_.convert_to_start_save();
Expand All @@ -347,7 +347,7 @@ LEVEL_RESULT campaign_controller::play_game()
else if(res == LEVEL_RESULT::OBSERVER_END)
{
// TODO: does it make sense to ask this question if we are currently the host?
const int dlg_res = gui2::show_message(disp_.video(), _("Game Over"),
const int dlg_res = gui2::show_message(video_, _("Game Over"),
_("This scenario has ended. Do you want to continue the campaign?"),
gui2::tmessage::yes_no_buttons);

Expand All @@ -358,7 +358,7 @@ LEVEL_RESULT campaign_controller::play_game()

if (mp_info_ && !mp_info_->is_host) {
// Opens mp::connect dialog to get a new gamestate.
mp::ui::result wait_res = mp::goto_mp_wait(state_, disp_,
mp::ui::result wait_res = mp::goto_mp_wait(state_, video_,
game_config_, res == LEVEL_RESULT::OBSERVER_END);
if (wait_res == mp::ui::QUIT) {
return LEVEL_RESULT::QUIT;
Expand All @@ -381,7 +381,7 @@ LEVEL_RESULT campaign_controller::play_game()

if (!connect_engine->can_start_game() || (game_config::debug && game_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) {
// Opens mp::connect dialog to allow users to make an adjustments for scenario.
mp::ui::result connect_res = mp::goto_mp_connect(disp_,
mp::ui::result connect_res = mp::goto_mp_connect(video_,
*connect_engine, game_config_, state_.mp_settings().name);
if (connect_res == mp::ui::QUIT) {
return LEVEL_RESULT::QUIT;
Expand Down Expand Up @@ -409,7 +409,7 @@ LEVEL_RESULT campaign_controller::play_game()

savegame::scenariostart_savegame save(state_, preferences::save_compression_format());

save.save_game_automatic(disp_.video());
save.save_game_automatic(video_);
}

}
Expand All @@ -420,7 +420,7 @@ LEVEL_RESULT campaign_controller::play_game()
utils::string_map symbols;
symbols["scenario"] = state_.get_scenario_id();
message = utils::interpolate_variables_into_string(message, &symbols);
gui2::show_error_message(disp_.video(), message);
gui2::show_error_message(video_, message);
return LEVEL_RESULT::QUIT;
}

Expand Down
9 changes: 4 additions & 5 deletions src/game_initialization/playcampaign.hpp
Expand Up @@ -25,8 +25,7 @@
#include <set>
#include <string>

class display;
class game_display;
class CVideo;
class saved_game;
class terrain_type_data;
class team;
Expand Down Expand Up @@ -56,16 +55,16 @@ struct mp_campaign_info

class campaign_controller
{
game_display& disp_;
CVideo& video_;
saved_game& state_;
const config& game_config_;
const tdata_cache & tdata_;
const bool is_unit_test_;
bool is_replay_;
mp_campaign_info* mp_info_;
public:
campaign_controller(game_display& disp, saved_game& state, const config& game_config, const tdata_cache & tdata, bool is_unit_test = false)
: disp_(disp)
campaign_controller(CVideo& video, saved_game& state, const config& game_config, const tdata_cache & tdata, bool is_unit_test = false)
: video_(video)
, state_(state)
, game_config_(game_config)
, tdata_(tdata)
Expand Down
30 changes: 15 additions & 15 deletions src/game_initialization/singleplayer.cpp
Expand Up @@ -22,21 +22,21 @@ config gamelist;

namespace sp {

bool enter_create_mode(game_display& disp, const config& game_config,
bool enter_create_mode(CVideo& video, const config& game_config,
saved_game& state, jump_to_campaign_info jump_to_campaign, bool local_players_only) {

bool configure_canceled = false;

do {

ng::create_engine create_eng(disp.video(), state);
ng::create_engine create_eng(video, state);
create_eng.set_current_level_type(ng::level::TYPE::SP_CAMPAIGN);

std::vector<ng::create_engine::level_ptr> campaigns(
create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN));

if (campaigns.empty()) {
gui2::show_error_message(disp.video(),
gui2::show_error_message(video,
_("No campaigns are available.\n"));
return false;
}
Expand All @@ -48,9 +48,9 @@ bool enter_create_mode(game_display& disp, const config& game_config,
gui2::tcampaign_selection dlg(create_eng);

try {
dlg.show(disp.video());
dlg.show(video);
} catch(twml_exception& e) {
e.show(disp.video());
e.show(video);
return false;
}

Expand Down Expand Up @@ -101,7 +101,7 @@ bool enter_create_mode(game_display& disp, const config& game_config,
jump_to_campaign.campaign_id_ = "";
}
// canceled difficulty dialog, relaunch the campaign selection dialog
return enter_create_mode(disp, game_config, state, jump_to_campaign, local_players_only);
return enter_create_mode(video, game_config, state, jump_to_campaign, local_players_only);
}

create_eng.prepare_for_era_and_mods();
Expand All @@ -121,30 +121,30 @@ bool enter_create_mode(game_display& disp, const config& game_config,
std::cerr << "Cannot load scenario with id=" << state.get_scenario_id() << "\n";
return false;
}
configure_canceled = !enter_configure_mode(disp, game_config_manager::get()->game_config(), state, local_players_only);
configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, local_players_only);

} while (configure_canceled);

return true;
}

bool enter_configure_mode(game_display& disp, const config& game_config, saved_game& state, bool local_players_only) {
bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, bool local_players_only) {
bool connect_canceled;
do {
connect_canceled = false;

mp::ui::result res;

{
mp::configure ui(disp.video(), game_config, gamechat, gamelist, state, local_players_only);
mp::run_lobby_loop(disp.video(), ui);
mp::configure ui(video, game_config, gamechat, gamelist, state, local_players_only);
mp::run_lobby_loop(video, ui);
res = ui.get_result();
ui.get_parameters();
}

switch (res) {
case mp::ui::CREATE:
connect_canceled = !enter_connect_mode(disp, game_config, state, local_players_only);
connect_canceled = !enter_connect_mode(video, game_config, state, local_players_only);
break;
case mp::ui::QUIT:
default:
Expand All @@ -154,7 +154,7 @@ bool enter_configure_mode(game_display& disp, const config& game_config, saved_g
return true;
}

bool enter_connect_mode(game_display& disp, const config& game_config,
bool enter_connect_mode(CVideo& video, const config& game_config,
saved_game& state, bool local_players_only) {

ng::connect_engine connect_eng(state, true, NULL);
Expand All @@ -163,8 +163,8 @@ bool enter_connect_mode(game_display& disp, const config& game_config,
mp::ui::result res;
gamelist.clear();
{
mp::connect ui(disp.video(), state.mp_settings().name, game_config, gamechat, gamelist, connect_eng);
mp::run_lobby_loop(disp.video(), ui);
mp::connect ui(video, state.mp_settings().name, game_config, gamechat, gamelist, connect_eng);
mp::run_lobby_loop(video, ui);
res = ui.get_result();

if (res == mp::ui::PLAY) {
Expand All @@ -175,7 +175,7 @@ bool enter_connect_mode(game_display& disp, const config& game_config,
case mp::ui::PLAY:
return true;
case mp::ui::CREATE:
enter_create_mode(disp, game_config, state, jump_to_campaign_info(false, -1, "", ""), local_players_only);
enter_create_mode(video, game_config, state, jump_to_campaign_info(false, -1, "", ""), local_players_only);
break;
case mp::ui::QUIT:
default:
Expand Down
6 changes: 3 additions & 3 deletions src/game_initialization/singleplayer.hpp
Expand Up @@ -22,13 +22,13 @@

namespace sp {

bool enter_create_mode(game_display& disp, const config& game_config,
bool enter_create_mode(CVideo& video, const config& game_config,
saved_game& state, jump_to_campaign_info jump_to, bool local_players_only = true);

bool enter_configure_mode(game_display& disp, const config& game_config,
bool enter_configure_mode(CVideo& video, const config& game_config,
saved_game& state, bool local_players_only = true);

bool enter_connect_mode(game_display& disp, const config& game_config,
bool enter_connect_mode(CVideo& video, const config& game_config,
saved_game& state, bool local_players_only = true);

} // end namespace sp
Expand Down

0 comments on commit 6e3aa08

Please sign in to comment.