Const-correctness on play_level, and play_turn.

This commit is contained in:
Philippe Plantier 2005-03-19 10:26:43 +00:00
parent 7b3c5e8b4b
commit 183e200ef8
13 changed files with 60 additions and 47 deletions

View file

@ -163,7 +163,7 @@ bool animate_unit_advancement(const game_data& info,unit_map& units, gamemap::lo
return true;
}
void show_objectives(display& disp, config& level_info)
void show_objectives(display& disp, const config& level_info)
{
static const std::string no_objectives(_("No objectives available"));
const std::string& name = level_info["name"];

View file

@ -36,7 +36,7 @@ void advance_unit(const game_data& info, const gamemap& map,unit_map& units, gam
bool animate_unit_advancement(const game_data& info,unit_map& units, gamemap::location loc, display& gui, size_t choice);
void show_objectives(display& disp, config& level_info);
void show_objectives(display& disp, const config& level_info);
// Ask user if I should really save the game and what name I should use
// returns 0 iff user wants to save the game

View file

@ -42,6 +42,15 @@
#define WRN_FT lg::warn(lg::display)
#define ERR_FT lg::err(lg::display)
//Deliberately breaking compilation with the original SDL_ttf library. Remove
//the lines below to be able to do this anyway, however this is buggy and may
//cause random memory corruption errors depending on the OS / Version of
//Freetype / Language you are using!
//
#ifndef SDL_TTF_WESNOTH
#error Please use the SDL_ttf files in the sdl_ttf directory, and not the original SDL_ttf library.
#endif
namespace {
// Signed int. Negative values mean "no subset".
@ -435,11 +444,6 @@ std::vector<surface> const &text_surface::get_surfaces() const
continue;
font_style_setter const style_setter(ttfont, style_);
//DEBUG
if (itor->text[0] == 'æ') {
std::cerr << "Nihongo detected:\n";
}
surface s = surface(TTF_RenderUNICODE_Blended(ttfont, (Uint16 const *)&(itor->ucs2_text.front()), color_));
if(!s.null())
surfs_.push_back(s);

View file

@ -141,7 +141,7 @@ gamemap* game_map = NULL;
std::map<gamemap::location,unit>* units = NULL;
std::vector<team>* teams = NULL;
game_state* state_of_game = NULL;
game_data* game_data_ptr = NULL;
const game_data* game_data_ptr = NULL;
gamestatus* status_ptr = NULL;
std::set<std::string> used_items;
@ -1553,10 +1553,11 @@ void set_variable(const std::string& key, const std::string& value)
state_of_game->variables[key] = value;
}
manager::manager(config& cfg, display& gui_, gamemap& map_,
manager::manager(const config& cfg, display& gui_, gamemap& map_,
std::map<gamemap::location,unit>& units_,
std::vector<team>& teams_,
game_state& state_of_game_, gamestatus& status, game_data& game_data_)
game_state& state_of_game_, gamestatus& status,
const game_data& game_data_)
{
const config::child_list& events_list = cfg.get_children("event");
for(config::child_list::const_iterator i = events_list.begin();

View file

@ -42,9 +42,9 @@ namespace game_events
struct manager {
//note that references will be maintained, and must remain valid
//for the life of the object.
manager(config& scenario_cfg, display& disp, gamemap& map,
std::map<gamemap::location,unit>& units, std::vector<team>& teams,
game_state& state_of_game, gamestatus& status, game_data& data);
manager(const config& scenario_cfg, display& disp, gamemap& map,
std::map<gamemap::location,unit>& units, std::vector<team>& teams,
game_state& state_of_game, gamestatus& status, const game_data& data);
~manager();
};

View file

@ -485,7 +485,7 @@ std::string get_first_word(const std::string &s);
namespace {
const config *game_cfg = NULL;
game_data *game_info = NULL;
const game_data *game_info = NULL;
gamemap *map = NULL;
// The default toplevel.
help::section toplevel;
@ -656,7 +656,7 @@ namespace {
namespace help {
help_manager::help_manager(const config *cfg, game_data *gameinfo, gamemap *_map) {
help_manager::help_manager(const config *cfg, const game_data *gameinfo, gamemap *_map) {
game_cfg = cfg == NULL ? &dummy_cfg : cfg;
game_info = gameinfo;
map = _map;
@ -1030,7 +1030,7 @@ public:
advance_end = next_units.end();
advance_it != advance_end; ++advance_it) {
std::string unit_id = *advance_it;
std::map<std::string,unit_type>::iterator new_type = game_info->unit_types.find(unit_id);
std::map<std::string,unit_type>::const_iterator new_type = game_info->unit_types.find(unit_id);
if(new_type != game_info->unit_types.end()) {
std::string lang_unit = new_type->second.language_name();
std::string ref_id = std::string("unit_") + new_type->second.id();

View file

@ -23,7 +23,7 @@ class gamemap;
namespace help {
struct help_manager {
help_manager(const config *game_config, game_data *game_info, gamemap *map);
help_manager(const config *game_config, const game_data *game_info, gamemap *map);
~help_manager();
};

View file

@ -119,7 +119,7 @@ namespace {
}
}
LEVEL_RESULT play_level(game_data& gameinfo, const config& game_config,
LEVEL_RESULT play_level(const game_data& gameinfo, const config& game_config,
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story)
@ -597,7 +597,7 @@ redo_turn:
try {
play_turn(gameinfo,state_of_game,status,game_config,
level, key, gui, map, teams, player_number,
*level, key, gui, map, teams, player_number,
units, textbox_info, replay_sender);
} catch(end_turn_exception& end_turn) {
if (end_turn.redo == player_number)
@ -616,9 +616,9 @@ redo_turn:
const cursor::setter cursor_setter(cursor::WAIT);
turn_info turn_data(gameinfo,state_of_game,status,
game_config,level,key,gui,
game_config,*level,key,gui,
map,teams,player_number,units,
turn_info::BROWSE_AI,textbox_info,replay_sender);
turn_info::BROWSE_AI,textbox_info,replay_sender);
ai_interface::info ai_info(gui,map,gameinfo,units,teams,player_number,status,turn_data);
util::scoped_ptr<ai_interface> ai_obj(create_ai(team_it->ai_algorithm(),ai_info));
@ -635,8 +635,10 @@ redo_turn:
LOG_NG << "is networked...\n";
turn_info turn_data(gameinfo,state_of_game,status,
game_config,level,key,gui,
map,teams,player_number,units,turn_info::BROWSE_NETWORKED,textbox_info,replay_sender);
game_config,*level,key,gui,
map,teams,player_number,units,
turn_info::BROWSE_NETWORKED,
textbox_info,replay_sender);
for(;;) {
@ -853,8 +855,8 @@ redo_turn:
}
turn_info turn_data(gameinfo,state_of_game,status,
game_config,level,key,gui,
map,teams,player_number,units,turn_info::BROWSE_NETWORKED,textbox_info,replay_sender);
game_config,*level,key,gui,
map,teams,player_number,units,turn_info::BROWSE_NETWORKED,textbox_info,replay_sender);
turn_data.save_game(_("A network disconnection has occured, and the game cannot continue. Do you want to save the game?"),gui::YES_NO);
if(disconnect) {

View file

@ -37,7 +37,7 @@ struct end_turn_exception {
int redo;
};
LEVEL_RESULT play_level(game_data& gameinfo, const config& terrain_config,
LEVEL_RESULT play_level(const game_data& gameinfo, const config& terrain_config,
config* level, CVideo& video,
game_state& state_of_game,
const std::vector<config*>& story);

View file

@ -60,9 +60,9 @@ command_disabler::~command_disabler()
--commands_disabled;
}
void play_turn(game_data& gameinfo, game_state& state_of_game,
gamestatus& status, const config& terrain_config,
config* level, CKey& key, display& gui, gamemap& map,
void play_turn(const game_data& gameinfo, game_state& state_of_game,
const gamestatus& status, const config& terrain_config,
const config& level, CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num,
std::map<gamemap::location,unit>& units,
turn_info::floating_textbox& textbox,
@ -139,11 +139,12 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
turn_data.send_data();
}
turn_info::turn_info(game_data& gameinfo, game_state& state_of_game,
gamestatus& status, const config& terrain_config, config* level,
CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num,
unit_map& units, TURN_MODE mode, floating_textbox& textbox, replay_network_sender& replay_sender)
turn_info::turn_info(const game_data& gameinfo, game_state& state_of_game,
const gamestatus& status, const config& terrain_config,
const config& level, CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num, unit_map& units,
TURN_MODE mode, floating_textbox& textbox,
replay_network_sender& replay_sender)
: paths_wiper(gui),
gameinfo_(gameinfo), state_of_game_(state_of_game), status_(status),
terrain_config_(terrain_config), level_(level),
@ -1611,7 +1612,7 @@ unit_map::iterator turn_info::current_unit()
void turn_info::write_game_snapshot(config& start) const
{
start.values = level_->values;
start.values = level_.values;
start["snapshot"] = "yes";
@ -1923,7 +1924,7 @@ void turn_info::recall()
gui_.draw(); //clear the old menu
if((*level_)["disallow_recall"] == "yes") {
if(level_["disallow_recall"] == "yes") {
gui::show_dialog(gui_,NULL,"",_("You are separated from your soldiers and may not recall them"));
} else if(recall_list.empty()) {
gui::show_dialog(gui_,NULL,"",_("There are no troops available to recall\n\
@ -2095,7 +2096,7 @@ void turn_info::preferences()
void turn_info::objectives()
{
dialogs::show_objectives(gui_,*level_);
dialogs::show_objectives(gui_,level_);
}
void turn_info::unit_list()

View file

@ -79,11 +79,12 @@ public:
enum TURN_MODE { PLAY_TURN, BROWSE_NETWORKED, BROWSE_AI };
turn_info(game_data& gameinfo, game_state& state_of_game,
gamestatus& status, const config& terrain_config, config* level,
CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num,
unit_map& units, TURN_MODE mode, floating_textbox& textbox, replay_network_sender& network_sender);
turn_info(const game_data& gameinfo, game_state& state_of_game,
const gamestatus& status, const config& terrain_config,
const config& level, CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num, unit_map& units,
TURN_MODE mode, floating_textbox& textbox,
replay_network_sender& network_sender);
void turn_slice();
@ -201,11 +202,11 @@ private:
void change_side_controller(const std::string& side, const std::string& player, bool orphan_side=false);
game_data& gameinfo_;
const game_data& gameinfo_;
game_state& state_of_game_;
gamestatus& status_;
const gamestatus& status_;
const config& terrain_config_;
config* level_;
const config& level_;
CKey key_;
display& gui_;
gamemap& map_;
@ -253,8 +254,9 @@ private:
replay_network_sender& replay_sender_;
};
void play_turn(game_data& gameinfo, game_state& state_of_game,
gamestatus& status, const config& terrain_config, config* level,
void play_turn(const game_data& gameinfo, game_state& state_of_game,
const gamestatus& status, const config& terrain_config,
const config& level,
CKey& key, display& gui, gamemap& map,
std::vector<team>& teams, int team_num,
std::map<gamemap::location,unit>& units,

View file

@ -439,7 +439,9 @@ static FT_Error Load_Glyph( TTF_Font* font, Uint16 ch, c_glyph* cached, int want
if ( ! cached->index ) {
cached->index = FT_Get_Char_Index( face, ch );
}
//error = FT_Load_Glyph( face, cached->index, FT_LOAD_DEFAULT | FT_LOAD_NO_BITMAP );
error = FT_Load_Glyph( face, cached->index, FT_LOAD_DEFAULT );
if( error ) {
return error;
}

View file

@ -43,6 +43,7 @@ extern "C" {
#define SDL_TTF_MAJOR_VERSION 2
#define SDL_TTF_MINOR_VERSION 0
#define SDL_TTF_PATCHLEVEL 7
#define SDL_TTF_WESNOTH 1
/* This macro can be used to fill a version structure with the compile-time
* version of the SDL_ttf library.