diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-08-07 01:59:38 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-08-07 01:59:38 +0000 |
commit | 16793c9b9b3fb5fd64fdf434ef6b5501803cb670 (patch) | |
tree | 626ec25bb4a0b3e387621c0e998f76997a33b881 /src | |
parent | d25e1c9b0dac7fcfe803083af1189489d5a9ad88 (diff) | |
download | Mana-16793c9b9b3fb5fd64fdf434ef6b5501803cb670.tar.gz Mana-16793c9b9b3fb5fd64fdf434ef6b5501803cb670.tar.bz2 Mana-16793c9b9b3fb5fd64fdf434ef6b5501803cb670.tar.xz Mana-16793c9b9b3fb5fd64fdf434ef6b5501803cb670.zip |
A bunch of cleanups.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 3 | ||||
-rw-r--r-- | src/gui/chat.cpp | 81 | ||||
-rw-r--r-- | src/gui/chat.h | 9 | ||||
-rw-r--r-- | src/main.cpp | 27 |
4 files changed, 45 insertions, 75 deletions
diff --git a/src/game.cpp b/src/game.cpp index 0d834468..fec186e6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -167,8 +167,7 @@ int get_elapsed_time(int start_time) void createGuiWindows(Network *network) { // Create dialogs - chatWindow = new ChatWindow( - config.getValue("homeDir", "") + std::string("/chatlog.txt"), network); + chatWindow = new ChatWindow(network); menuWindow = new MenuWindow(); statusWindow = new StatusWindow(player_node); miniStatusWindow = new MiniStatusWindow(); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 64b56caf..92412dde 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -35,18 +35,16 @@ #include "../game.h" #include "../localplayer.h" -#include "../log.h" #include "../net/messageout.h" #include "../net/protocol.h" -ChatWindow::ChatWindow(const std::string &logfile, Network *network): +ChatWindow::ChatWindow(Network *network): Window(""), mNetwork(network), mTmpVisible(false) { setWindowName("Chat"); - mChatlogFile.open(logfile.c_str(), std::ios::out | std::ios::app); mItems = 0; mItemsKeep = 20; @@ -76,12 +74,6 @@ ChatWindow::ChatWindow(const std::string &logfile, Network *network): mCurHist = mHistory.end(); } -ChatWindow::~ChatWindow() -{ - mChatlogFile.flush(); - mChatlogFile.close(); -} - void ChatWindow::logic() { @@ -252,44 +244,12 @@ ChatWindow::isFocused() void ChatWindow::chatSend(const std::string &nick, std::string msg) { - // Prepare command - if (msg.substr(0, 1) == "/") - { - /* Some messages are managed client side, while others - * require server handling by proper packet. Probably - * those if elses should be replaced by protocol calls */ - if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) - { - msg.erase(0, IS_ANNOUNCE_LENGTH); - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x0099); - outMsg.writeInt16(msg.length() + 4); - outMsg.writeString(msg, msg.length()); - } - else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) - { - chatLog("-- Help --", BY_SERVER); - chatLog("/help : Display this help.", BY_SERVER); - chatLog("/announce : Global announcement (GM only)", BY_SERVER); - chatLog("/where : Display map name", BY_SERVER); - chatLog("/who : Display number of online users", BY_SERVER); - } - else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) - { - chatLog(map_path, BY_SERVER); - } - else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) - { - MessageOut outMsg(mNetwork); - outMsg.writeInt16(0x00c1); - } - else - { - chatLog("Unknown command", BY_SERVER); - } - } + /* Some messages are managed client side, while others + * require server handling by proper packet. Probably + * those if elses should be replaced by protocol calls */ + // Prepare ordinary message - else { + if (msg.substr(0, 1) != "/") { msg = nick + " : " + msg; MessageOut outMsg(mNetwork); @@ -297,6 +257,35 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) outMsg.writeInt16(msg.length() + 4); outMsg.writeString(msg, msg.length()); } + else if (msg.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE) + { + msg.erase(0, IS_ANNOUNCE_LENGTH); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0099); + outMsg.writeInt16(msg.length() + 4); + outMsg.writeString(msg, msg.length()); + } + else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP) + { + chatLog("-- Help --", BY_SERVER); + chatLog("/help : Display this help.", BY_SERVER); + chatLog("/announce : Global announcement (GM only)", BY_SERVER); + chatLog("/where : Display map name", BY_SERVER); + chatLog("/who : Display number of online users", BY_SERVER); + } + else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE) + { + chatLog(map_path, BY_SERVER); + } + else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO) + { + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x00c1); + } + else + { + chatLog("Unknown command", BY_SERVER); + } } std::string diff --git a/src/gui/chat.h b/src/gui/chat.h index 80e57a84..cd52ac46 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -24,7 +24,6 @@ #ifndef _TMW_CHAT_H #define _TMW_CHAT_H -#include <fstream> #include <list> #include <string> @@ -117,12 +116,7 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Constructor. */ - ChatWindow(const std::string &logfile, Network *network); - - /** - * Destructor. - */ - ~ChatWindow(); + ChatWindow(Network *network); /** * Logic (updates components' size) @@ -195,7 +189,6 @@ class ChatWindow : public Window, public gcn::ActionListener, private: Network *mNetwork; - std::ofstream mChatlogFile; bool mTmpVisible; /** One item in the chat log */ diff --git a/src/main.cpp b/src/main.cpp index 3476ffdd..eb20c169 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -210,15 +210,6 @@ void init_engine() SDL_WM_SetCaption("The Mana World", NULL); SDL_WM_SetIcon(IMG_Load(TMW_DATADIR "data/icons/tmw-icon.png"), NULL); - int width, height, bpp; - bool fullscreen, hwaccel; - - width = (int)config.getValue("screenwidth", 800); - height = (int)config.getValue("screenheight", 600); - bpp = 0; - fullscreen = ((int)config.getValue("screen", 0) == 1); - hwaccel = ((int)config.getValue("hwaccel", 0) == 1); - #ifdef USE_OPENGL bool useOpenGL = (config.getValue("opengl", 0) == 1); @@ -226,16 +217,17 @@ void init_engine() Image::setLoadAsOpenGL(useOpenGL); // Create the graphics context - if (useOpenGL) { - graphics = new OpenGLGraphics(); - } else { - graphics = new Graphics(); - } + graphics = useOpenGL ? new OpenGLGraphics() : new Graphics(); #else // Create the graphics context graphics = new Graphics(); #endif + int width = (int)config.getValue("screenwidth", 800); + int height = (int)config.getValue("screenheight", 600); + int bpp = 0; + bool fullscreen = ((int)config.getValue("screen", 0) == 1); + bool hwaccel = ((int)config.getValue("hwaccel", 0) == 1); // Try to set the desired video mode if (!graphics->setVideoMode(width, height, bpp, fullscreen, hwaccel)) @@ -293,11 +285,8 @@ void exit_engine() delete gui; delete graphics; - std::vector<Spriteset *>::iterator iter; - for (iter = hairset.begin(); iter != hairset.end(); ++iter) - { - (*iter)->decRef(); - } + std::for_each(hairset.begin(), hairset.end(), + std::mem_fun(&Spriteset::decRef)); hairset.clear(); playerset[0]->decRef(); |