Skip to content
Permalink
Browse files

Change error_message from wstring to string

This removes a lot of narrow/wide conversions where a wide string was never used.
  • Loading branch information
ShadowNinja committed Mar 28, 2015
1 parent 3d53c90 commit 30075467b84c79ff21736d6c447746caef07dcd0
Showing with 129 additions and 149 deletions.
  1. +12 −26 src/camera.cpp
  2. +1 −1 src/camera.h
  3. +2 −2 src/client.h
  4. +27 −29 src/client/clientlauncher.cpp
  5. +1 −1 src/client/clientlauncher.h
  6. +54 −62 src/game.cpp
  7. +1 −1 src/game.h
  8. +7 −3 src/network/clientpackethandler.cpp
  9. +24 −24 src/network/networkprotocol.h
@@ -119,34 +119,20 @@ Camera::~Camera()
m_wieldmgr->drop();
}

bool Camera::successfullyCreated(std::wstring& error_message)
bool Camera::successfullyCreated(std::string &error_message)
{
if (m_playernode == NULL)
{
error_message = L"Failed to create the player scene node";
return false;
}
if (m_headnode == NULL)
{
error_message = L"Failed to create the head scene node";
return false;
}
if (m_cameranode == NULL)
{
error_message = L"Failed to create the camera scene node";
return false;
}
if (m_wieldmgr == NULL)
{
error_message = L"Failed to create the wielded item scene manager";
return false;
}
if (m_wieldnode == NULL)
{
error_message = L"Failed to create the wielded item scene node";
return false;
if (!m_playernode) {
error_message = "Failed to create the player scene node";
} else if (!m_headnode) {
error_message = "Failed to create the head scene node";
} else if (!m_cameranode) {
error_message = "Failed to create the camera scene node";
} else if (!m_wieldmgr) {
error_message = "Failed to create the wielded item scene manager";
} else if (!m_wieldnode) {
error_message = "Failed to create the wielded item scene node";
}
return true;
return error_message.empty();
}

// Returns the fractional part of x
@@ -110,7 +110,7 @@ class Camera
}

// Checks if the constructor was able to create the scene nodes
bool successfullyCreated(std::wstring& error_message);
bool successfullyCreated(std::string &error_message);

// Step the camera: updates the viewing range and view bobbing.
void step(f32 dtime);
@@ -480,7 +480,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
bool accessDenied()
{ return m_access_denied; }

std::wstring accessDeniedReason()
std::string accessDeniedReason()
{ return m_access_denied_reason; }

bool itemdefReceived()
@@ -589,7 +589,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
u64 m_map_seed;
std::string m_password;
bool m_access_denied;
std::wstring m_access_denied_reason;
std::string m_access_denied_reason;
std::queue<ClientEvent> m_client_event_queue;
bool m_itemdef_received;
bool m_nodedef_received;
@@ -156,7 +156,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)

// If an error occurs, this is set to something by menu().
// It is then displayed before the menu shows on the next call to menu()
std::wstring error_message = L"";
std::string error_message;

bool first_loop = true;

@@ -184,7 +184,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
*/
guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));

bool game_has_run = launch_game(&error_message, game_params, cmd_args);
bool game_has_run = launch_game(error_message, game_params, cmd_args);

// If skip_main_menu, we only want to startup once
if (skip_main_menu && !first_loop)
@@ -207,7 +207,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
}

if (current_playername.length() > PLAYERNAME_SIZE-1) {
error_message = wgettext("Player name too long.");
error_message = gettext("Player name too long.");
playername = current_playername.substr(0, PLAYERNAME_SIZE-1);
g_settings->set("name", playername);
continue;
@@ -245,25 +245,24 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)

} //try
catch (con::PeerNotFoundException &e) {
error_message = wgettext("Connection error (timed out?)");
errorstream << wide_to_narrow(error_message) << std::endl;
error_message = gettext("Connection error (timed out?)");
errorstream << error_message << std::endl;
}

#ifdef NDEBUG
catch (std::exception &e) {
std::string narrow_message = "Some exception: \"";
narrow_message += e.what();
narrow_message += "\"";
errorstream << narrow_message << std::endl;
error_message = narrow_to_wide(narrow_message);
std::string error_message = "Some exception: \"";
error_message += e.what();
error_message += "\"";
errorstream << error_message << std::endl;
}
#endif

// If no main menu, show error and exit
if (skip_main_menu) {
if (error_message != L"") {
if (!error_message.empty()) {
verbosestream << "error_message = "
<< wide_to_narrow(error_message) << std::endl;
<< error_message << std::endl;
retval = false;
}
break;
@@ -312,17 +311,17 @@ bool ClientLauncher::init_engine(int log_level)
return device != NULL;
}

bool ClientLauncher::launch_game(std::wstring *error_message,
bool ClientLauncher::launch_game(std::string &error_message,
GameParams &game_params, const Settings &cmd_args)
{
// Initialize menu data
MainMenuData menudata;
menudata.address = address;
menudata.name = playername;
menudata.port = itos(game_params.socket_port);
menudata.errormessage = wide_to_narrow(*error_message);
menudata.errormessage = error_message;

*error_message = L"";
error_message.clear();

if (cmd_args.exists("password"))
menudata.password = cmd_args.get("password");
@@ -367,11 +366,11 @@ bool ClientLauncher::launch_game(std::wstring *error_message,
}
}

if (menudata.errormessage != "") {
if (!menudata.errormessage.empty()) {
/* The calling function will pass this back into this function upon the
* next iteration (if any) causing it to be displayed by the GUI
*/
*error_message = narrow_to_wide(menudata.errormessage);
error_message = menudata.errormessage;
return false;
}

@@ -410,25 +409,25 @@ bool ClientLauncher::launch_game(std::wstring *error_message,

if (current_address == "") { // If local game
if (worldspec.path == "") {
*error_message = wgettext("No world selected and no address "
error_message = gettext("No world selected and no address "
"provided. Nothing to do.");
errorstream << wide_to_narrow(*error_message) << std::endl;
errorstream << error_message << std::endl;
return false;
}

if (!fs::PathExists(worldspec.path)) {
*error_message = wgettext("Provided world path doesn't exist: ")
+ narrow_to_wide(worldspec.path);
errorstream << wide_to_narrow(*error_message) << std::endl;
error_message = gettext("Provided world path doesn't exist: ")
+ worldspec.path;
errorstream << error_message << std::endl;
return false;
}

// Load gamespec for required game
gamespec = findWorldSubgame(worldspec.path);
if (!gamespec.isValid() && !game_params.game_spec.isValid()) {
*error_message = wgettext("Could not find or load game \"")
+ narrow_to_wide(worldspec.gameid) + L"\"";
errorstream << wide_to_narrow(*error_message) << std::endl;
error_message = gettext("Could not find or load game \"")
+ worldspec.gameid + "\"";
errorstream << error_message << std::endl;
return false;
}

@@ -444,10 +443,9 @@ bool ClientLauncher::launch_game(std::wstring *error_message,
}

if (!gamespec.isValid()) {
*error_message = wgettext("Invalid gamespec.");
*error_message += L" (world_gameid="
+ narrow_to_wide(worldspec.gameid) + L")";
errorstream << wide_to_narrow(*error_message) << std::endl;
error_message = gettext("Invalid gamespec.");
error_message += " (world.gameid=" + worldspec.gameid + ")";
errorstream << error_message << std::endl;
return false;
}
}
@@ -92,7 +92,7 @@ class ClientLauncher
void init_args(GameParams &game_params, const Settings &cmd_args);
bool init_engine(int log_level);

bool launch_game(std::wstring *error_message, GameParams &game_params,
bool launch_game(std::string &error_message, GameParams &game_params,
const Settings &cmd_args);

void main_menu(MainMenuData *menudata);

0 comments on commit 3007546

Please sign in to comment.