Remove game controllers: new and abstract.

This commit is contained in:
Andrius Silinskas 2013-06-13 11:36:47 +01:00
parent 2759b1b141
commit 4175e62956
10 changed files with 150 additions and 470 deletions

View File

@ -17790,22 +17790,6 @@
RelativePath="..\..\src\game_controller.hpp"
>
</File>
<File
RelativePath="..\..\src\game_controller_abstract.cpp"
>
</File>
<File
RelativePath="..\..\src\game_controller_abstract.hpp"
>
</File>
<File
RelativePath="..\..\src\game_controller_new.cpp"
>
</File>
<File
RelativePath="..\..\src\game_controller_new.hpp"
>
</File>
<File
RelativePath="..\..\src\game_display.cpp"
>

View File

@ -686,8 +686,6 @@ set(wesnoth-main_SRC
formula_tokenizer.cpp
game_config_manager.cpp
game_controller.cpp
game_controller_abstract.cpp
game_controller_new.cpp
game_display.cpp
game_errors.cpp
game_events.cpp

View File

@ -258,8 +258,6 @@ wesnoth_sources = Split("""
formula_tokenizer.cpp
game_config_manager.cpp
game_controller.cpp
game_controller_abstract.cpp
game_controller_new.cpp
game_display.cpp
game_errors.cpp
game_events.cpp

View File

@ -20,7 +20,6 @@
#include "commandline_options.hpp"
#include "game_config_manager.hpp"
#include "game_controller.hpp"
#include "game_controller_new.hpp"
#include "gui/dialogs/title_screen.hpp"
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
#include "gui/widgets/debug.hpp"
@ -426,11 +425,8 @@ static int do_gameloop(int argc, char** argv)
//ensure recorder has an actually random seed instead of what it got during
//static initialization (before any srand() call)
recorder.set_seed(rand());
boost::shared_ptr<game_controller_abstract> game;
if (game_config::new_syntax)
game = boost::shared_ptr<game_controller_abstract>(new game_controller_new(cmdline_opts));
else
game = boost::shared_ptr<game_controller_abstract>(new game_controller(cmdline_opts,argv[0]));
boost::scoped_ptr<game_controller> game(
new game_controller(cmdline_opts,argv[0]));
const int start_ticks = SDL_GetTicks();
init_locale();
@ -579,7 +575,8 @@ static int do_gameloop(int argc, char** argv)
res = static_cast<gui2::ttitle_screen::tresult>(dlg.get_retval());
}
game_controller_abstract::RELOAD_GAME_DATA should_reload = game_controller_abstract::RELOAD_DATA;
game_controller::RELOAD_GAME_DATA should_reload =
game_controller::RELOAD_DATA;
if(res == gui2::ttitle_screen::QUIT_GAME) {
LOG_GENERAL << "quitting game...\n";
@ -590,7 +587,7 @@ static int do_gameloop(int argc, char** argv)
res = gui2::ttitle_screen::NOTHING;
continue;
}
should_reload = game_controller_abstract::NO_RELOAD_DATA;
should_reload = game_controller::NO_RELOAD_DATA;
} else if(res == gui2::ttitle_screen::TUTORIAL) {
game->set_tutorial();
} else if(res == gui2::ttitle_screen::NEW_CAMPAIGN) {

View File

@ -72,7 +72,9 @@ static bool less_campaigns_rank(const config &a, const config &b) {
}
game_controller::game_controller(const commandline_options& cmdline_opts, const char *appname) :
game_controller_abstract(cmdline_opts),
cmdline_opts_(cmdline_opts),
disp_(NULL),
video_(),
thread_manager(),
font_manager_(),
prefs_manager_(),
@ -274,6 +276,135 @@ game_controller::game_controller(const commandline_options& cmdline_opts, const
}
}
game_display& game_controller::disp()
{
if(disp_.get() == NULL) {
if(get_video_surface() == NULL) {
throw CVideo::error();
}
disp_.assign(game_display::create_dummy_display(video_));
}
return *disp_.get();
}
bool game_controller::init_joystick()
{
if (!preferences::joystick_support_enabled())
return false;
if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
return false;
int joysticks = SDL_NumJoysticks();
if (joysticks == 0) return false;
SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick* joystick;
bool joystick_found = false;
for (int i = 0; i<joysticks; i++) {
joystick = SDL_JoystickOpen(i);
if (joystick)
joystick_found = true;
}
return joystick_found;
}
bool game_controller::init_language()
{
if(!::load_language_list())
return false;
language_def locale;
if(cmdline_opts_.language) {
std::vector<language_def> langs = get_languages();
BOOST_FOREACH(const language_def & def, langs) {
if(def.localename == *cmdline_opts_.language) {
locale = def;
break;
}
}
if(locale.localename.empty()) {
std::cerr << "Language symbol '" << *cmdline_opts_.language << "' not found.\n";
return false;
}
} else {
locale = get_locale();
}
::set_language(locale);
if(!cmdline_opts_.nogui) {
std::string wm_title_string = _("The Battle for Wesnoth");
wm_title_string += " - " + game_config::revision;
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
}
return true;
}
bool game_controller::init_video()
{
if(cmdline_opts_.nogui) {
if( !(cmdline_opts_.multiplayer || cmdline_opts_.screenshot) ) {
std::cerr << "--nogui flag is only valid with --multiplayer flag or --screenshot flag\n";
return false;
}
video_.make_fake();
game_config::no_delay = true;
return true;
}
#if !(defined(__APPLE__))
surface icon(image::get_image("game-icon.png", image::UNSCALED));
if(icon != NULL) {
///must be called after SDL_Init() and before setting video mode
SDL_WM_SetIcon(icon,NULL);
}
#endif
std::pair<int,int> resolution;
int bpp = 0;
int video_flags = 0;
bool found_matching = preferences::detect_video_settings(video_, resolution, bpp, video_flags);
if (cmdline_opts_.bpp) {
bpp = *cmdline_opts_.bpp;
} else if (cmdline_opts_.screenshot) {
bpp = 32;
}
if(!found_matching) {
std::cerr << "Video mode " << resolution.first << 'x'
<< resolution.second << 'x' << bpp
<< " is not supported.\n";
if ((video_flags & FULL_SCREEN)) {
std::cerr << "Try running the program with the --windowed option "
<< "using a " << bpp << "bpp setting for your display adapter.\n";
} else {
std::cerr << "Try running the program with the --fullscreen option.\n";
}
return false;
}
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "x" << bpp << "\n";
const int res = video_.setMode(resolution.first,resolution.second,bpp,video_flags);
video_.setBpp(bpp);
if(res == 0) {
std::cerr << "required video mode, " << resolution.first << "x"
<< resolution.second << "x" << bpp << " is not supported\n";
return false;
}
return true;
}
bool game_controller::play_test()
{
static bool first_time = true;

View File

@ -14,9 +14,8 @@
#ifndef GAME_CONTROLLER_H_INCLUDED
#define GAME_CONTROLLER_H_INCLUDED
#include "game_controller_abstract.hpp"
#include "commandline_options.hpp"
#include "editor/editor_main.hpp"
#include "gamestatus.hpp"
#include "game_config_manager.hpp"
#include "game_display.hpp"
@ -41,12 +40,18 @@ public:
std::string campaign_id_,scenario_id_;
};
class game_controller : public game_controller_abstract
class game_controller
{
public:
game_controller(const commandline_options& cmdline_opts, const char* appname);
~game_controller();
game_display& disp();
bool init_video();
bool init_language();
bool init_joystick();
bool play_test();
bool play_screenshot_mode();
@ -69,6 +74,7 @@ public:
void show_preferences();
enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
void play_replay();
@ -83,6 +89,10 @@ private:
editor::EXIT_STATUS start_editor(const std::string& filename);
const commandline_options& cmdline_opts_;
util::scoped_ptr<game_display> disp_;
CVideo video_;
//this should get destroyed *after* the video, since we want
//to clean up threads after the display disappears.
const threading::manager thread_manager;
@ -99,7 +109,6 @@ private:
std::string screenshot_map_, screenshot_filename_;
/// Stateful class taking over scenario-switching capabilities from the current game_controller and playsingle_controller. Currently only available when --new-syntax command line option is enabled.
game_state state_;
std::string multiplayer_server_;

View File

@ -1,164 +0,0 @@
/*
Copyright (C) 2011 - 2013 by Lukasz Dobrogowski <lukasz.dobrogowski@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 "game_controller_abstract.hpp"
#include "game_display.hpp"
#include "gettext.hpp"
#include "hotkeys.hpp"
#include "language.hpp"
#include "preferences_display.hpp"
#include "preferences.hpp"
#include <boost/foreach.hpp>
#include <iostream>
game_controller_abstract::game_controller_abstract(const commandline_options &cmdline_opts) :
cmdline_opts_(cmdline_opts),
disp_(NULL),
video_()
{
}
game_display& game_controller_abstract::disp()
{
if(disp_.get() == NULL) {
if(get_video_surface() == NULL) {
throw CVideo::error();
}
disp_.assign(game_display::create_dummy_display(video_));
}
return *disp_.get();
}
bool game_controller_abstract::init_joystick()
{
if (!preferences::joystick_support_enabled())
return false;
if(SDL_WasInit(SDL_INIT_JOYSTICK) == 0)
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
return false;
int joysticks = SDL_NumJoysticks();
if (joysticks == 0) return false;
SDL_JoystickEventState(SDL_ENABLE);
SDL_Joystick* joystick;
bool joystick_found = false;
for (int i = 0; i<joysticks; i++) {
joystick = SDL_JoystickOpen(i);
if (joystick)
joystick_found = true;
}
return joystick_found;
}
bool game_controller_abstract::init_language()
{
if(!::load_language_list())
return false;
language_def locale;
if(cmdline_opts_.language) {
std::vector<language_def> langs = get_languages();
BOOST_FOREACH(const language_def & def, langs) {
if(def.localename == *cmdline_opts_.language) {
locale = def;
break;
}
}
if(locale.localename.empty()) {
std::cerr << "Language symbol '" << *cmdline_opts_.language << "' not found.\n";
return false;
}
} else {
locale = get_locale();
}
::set_language(locale);
if(!cmdline_opts_.nogui) {
std::string wm_title_string = _("The Battle for Wesnoth");
wm_title_string += " - " + game_config::revision;
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
}
return true;
}
bool game_controller_abstract::init_video()
{
if(cmdline_opts_.nogui) {
if( !(cmdline_opts_.multiplayer || cmdline_opts_.screenshot) ) {
std::cerr << "--nogui flag is only valid with --multiplayer flag or --screenshot flag\n";
return false;
}
video_.make_fake();
game_config::no_delay = true;
return true;
}
#if !(defined(__APPLE__))
surface icon(image::get_image("game-icon.png", image::UNSCALED));
if(icon != NULL) {
///must be called after SDL_Init() and before setting video mode
SDL_WM_SetIcon(icon,NULL);
}
#endif
std::pair<int,int> resolution;
int bpp = 0;
int video_flags = 0;
bool found_matching = preferences::detect_video_settings(video_, resolution, bpp, video_flags);
if (cmdline_opts_.bpp) {
bpp = *cmdline_opts_.bpp;
} else if (cmdline_opts_.screenshot) {
bpp = 32;
}
if(!found_matching) {
std::cerr << "Video mode " << resolution.first << 'x'
<< resolution.second << 'x' << bpp
<< " is not supported.\n";
if ((video_flags & FULL_SCREEN)) {
std::cerr << "Try running the program with the --windowed option "
<< "using a " << bpp << "bpp setting for your display adapter.\n";
} else {
std::cerr << "Try running the program with the --fullscreen option.\n";
}
return false;
}
std::cerr << "setting mode to " << resolution.first << "x" << resolution.second << "x" << bpp << "\n";
const int res = video_.setMode(resolution.first,resolution.second,bpp,video_flags);
video_.setBpp(bpp);
if(res == 0) {
std::cerr << "required video mode, " << resolution.first << "x"
<< resolution.second << "x" << bpp << " is not supported\n";
return false;
}
return true;
}

View File

@ -1,70 +0,0 @@
/*
Copyright (C) 2011 - 2013 by Lukasz Dobrogowski <lukasz.dobrogowski@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.
*/
#ifndef GAME_CONTROLLER_ABSTRACT_H_INCLUDED
#define GAME_CONTROLLER_ABSTRACT_H_INCLUDED
#include "commandline_options.hpp"
#include "editor/editor_main.hpp"
#include "scoped_resource.hpp"
#include "video.hpp"
#include <string>
class config;
class game_display;
class game_controller_abstract
{
public:
game_controller_abstract(const commandline_options &cmdline_opts);
virtual ~game_controller_abstract() {}
game_display& disp();
bool init_video();
bool init_language();
bool init_joystick();
virtual bool play_test() = 0;
virtual bool play_screenshot_mode() = 0;
virtual bool is_loading() const = 0;
virtual void clear_loaded_game() = 0;
virtual bool load_game() = 0;
virtual void set_tutorial() = 0;
virtual std::string jump_to_campaign_id() const = 0;
virtual bool new_campaign() = 0;
virtual bool goto_campaign() = 0;
virtual bool goto_multiplayer() = 0;
virtual bool goto_editor() = 0;
virtual bool jump_to_editor() const = 0;
virtual bool play_multiplayer() = 0;
virtual bool play_multiplayer_commandline() = 0;
virtual bool change_language() = 0;
virtual void show_preferences() = 0;
enum RELOAD_GAME_DATA { RELOAD_DATA, NO_RELOAD_DATA };
virtual void launch_game(RELOAD_GAME_DATA) = 0;
virtual void play_replay() = 0;
virtual editor::EXIT_STATUS start_editor() = 0;
protected:
const commandline_options& cmdline_opts_;
util::scoped_ptr<game_display> disp_;
CVideo video_;
};
#endif

View File

@ -1,139 +0,0 @@
/*
Copyright (C) 2011 - 2013 by Lukasz Dobrogowski <lukasz.dobrogowski@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 "game_controller_new.hpp"
#include "game_display.hpp"
#include <iostream>
game_controller_new::game_controller_new(const commandline_options& cmdline_opts) :
game_controller_abstract(cmdline_opts),
main_config_()
{
}
game_controller_new::~game_controller_new()
{
}
bool game_controller_new::init_config()
{
return true;
}
bool game_controller_new::play_test()
{
return true;
}
bool game_controller_new::play_screenshot_mode()
{
return true;
}
void game_controller_new::reload_changed_game_config()
{
}
bool game_controller_new::is_loading() const
{
return true;
}
void game_controller_new::clear_loaded_game()
{
}
bool game_controller_new::load_game()
{
return true;
}
void game_controller_new::set_tutorial()
{
}
std::string game_controller_new::jump_to_campaign_id() const
{
return std::string();
}
bool game_controller_new::new_campaign()
{
return true;
}
bool game_controller_new::goto_campaign()
{
return true;
}
bool game_controller_new::goto_multiplayer()
{
return true;
}
bool game_controller_new::goto_editor()
{
return true;
}
bool game_controller_new::jump_to_editor() const
{
return true;
}
bool game_controller_new::play_multiplayer()
{
return true;
}
bool game_controller_new::play_multiplayer_commandline()
{
return true;
}
bool game_controller_new::change_language()
{
return true;
}
void game_controller_new::show_preferences()
{
}
void game_controller_new::launch_game ( game_controller_abstract::RELOAD_GAME_DATA /*reload*/ )
{
}
void game_controller_new::play_replay()
{
}
editor::EXIT_STATUS game_controller_new::start_editor()
{
return editor::EXIT_NORMAL;
}
const config& game_controller_new::game_config() const
{
return main_config_;
}

View File

@ -1,64 +0,0 @@
/*
Copyright (C) 2011 - 2013 by Lukasz Dobrogowski <lukasz.dobrogowski@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.
*/
#ifndef GAME_CONTROLLER_NEW_HPP_INCLUDED
#define GAME_CONTROLLER_NEW_HPP_INCLUDED
#include "game_controller_abstract.hpp"
#include "config.hpp"
class game_controller_new : public game_controller_abstract
{
public:
game_controller_new(const commandline_options& cmdline_opts);
~game_controller_new();
bool init_config();
bool play_test();
bool play_screenshot_mode();
void reload_changed_game_config();
bool is_loading() const;
void clear_loaded_game();
bool load_game();
void set_tutorial();
std::string jump_to_campaign_id() const;
bool new_campaign();
bool goto_campaign();
bool goto_multiplayer();
bool goto_editor();
bool jump_to_editor() const;
bool play_multiplayer();
bool play_multiplayer_commandline();
bool change_language();
void show_preferences();
void launch_game(RELOAD_GAME_DATA reload=RELOAD_DATA);
void play_replay();
editor::EXIT_STATUS start_editor();
const config& game_config() const;
private:
config main_config_;
};
#endif