diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2008-12-17 20:23:33 +0100 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2009-01-04 21:41:25 +0100 |
commit | ad276ae0d4679aee9d7e6082fa602b49c6fd940a (patch) | |
tree | df3ff4eb6a315faaf722815c4af1e6398a40e81f | |
parent | 33130dd288f5842f0edde0fff8618cdfe3afc856 (diff) | |
download | mana-ad276ae0d4679aee9d7e6082fa602b49c6fd940a.tar.gz mana-ad276ae0d4679aee9d7e6082fa602b49c6fd940a.tar.bz2 mana-ad276ae0d4679aee9d7e6082fa602b49c6fd940a.tar.xz mana-ad276ae0d4679aee9d7e6082fa602b49c6fd940a.zip |
Code reformatting
Mainly making sure 'const std::string &' is used everywhere instead of
'std::string const &'. The former has always been the preferred order in
this project.
(cherry picked from mainline)
-rw-r--r-- | src/animatedsprite.h | 27 | ||||
-rw-r--r-- | src/gui/chat.cpp | 37 | ||||
-rw-r--r-- | src/gui/chat.h | 21 | ||||
-rw-r--r-- | src/gui/window.h | 9 | ||||
-rw-r--r-- | src/localplayer.cpp | 5 | ||||
-rw-r--r-- | src/properties.h | 15 | ||||
-rw-r--r-- | src/resources/dye.cpp | 6 | ||||
-rw-r--r-- | src/resources/dye.h | 6 | ||||
-rw-r--r-- | src/resources/imageloader.cpp | 2 | ||||
-rw-r--r-- | src/resources/imageloader.h | 3 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 12 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 9 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 28 | ||||
-rw-r--r-- | src/resources/spritedef.h | 23 |
14 files changed, 80 insertions, 123 deletions
diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 405bf42e..41857d8f 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -50,7 +50,8 @@ class AnimatedSprite * @param filename the file of the sprite to animate * @param variant the sprite variant */ - static AnimatedSprite *load(std::string const &filename, int variant = 0); + static AnimatedSprite *load(const std::string &filename, + int variant = 0); /** * Destructor. @@ -60,50 +61,42 @@ class AnimatedSprite /** * Resets the animated sprite. */ - void - reset(); + void reset(); /** * Plays an action using the current direction */ - void - play(SpriteAction action); + void play(SpriteAction action); /** * Inform the animation of the passed time so that it can output the * correct animation frame. */ - void - update(int time); + void update(int time); /** * Draw the current animation frame at the coordinates given in screen * pixels. */ - bool - draw(Graphics* graphics, int posX, int posY) const; + bool draw(Graphics* graphics, int posX, int posY) const; /** * gets the width in pixels of the image of the current frame */ - int - getWidth() const; + int getWidth() const; /** * gets the height in pixels of the image of the current frame */ - int - getHeight() const; + int getHeight() const; /** * Sets the direction. */ - void - setDirection(SpriteDirection direction); + void setDirection(SpriteDirection direction); private: - bool - updateCurrentAnimation(unsigned int dt); + bool updateCurrentAnimation(unsigned int dt); SpriteDirection mDirection; /**< The sprite direction. */ int mLastTime; /**< The last time update was called. */ diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index edde42d0..aa24ba7f 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -91,8 +91,7 @@ void ChatWindow::widgetResized(const gcn::Event &event) mChatInput->getHeight() - 5); } -void -ChatWindow::chatLog(std::string line, int own) +void ChatWindow::chatLog(std::string line, int own) { // Trim whitespace trim(line); @@ -182,14 +181,12 @@ ChatWindow::chatLog(std::string line, int own) } } -void -ChatWindow::chatLog(CHATSKILL act) +void ChatWindow::chatLog(CHATSKILL act) { chatLog(const_msg(act), BY_SERVER); } -void -ChatWindow::action(const gcn::ActionEvent &event) +void ChatWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "chatinput") { @@ -222,8 +219,7 @@ ChatWindow::action(const gcn::ActionEvent &event) } } -void -ChatWindow::requestChatFocus() +void ChatWindow::requestChatFocus() { // Make sure chatWindow is visible if (!isVisible()) @@ -243,14 +239,13 @@ ChatWindow::requestChatFocus() mChatInput->requestFocus(); } -bool -ChatWindow::isInputFocused() +bool ChatWindow::isInputFocused() { return mChatInput->isFocused(); } -void -ChatWindow::whisper(const std::string &nick, std::string msg, int prefixlen) +void ChatWindow::whisper(const std::string &nick, std::string msg, + int prefixlen) { std::string recvnick = ""; msg.erase(0, prefixlen + 1); @@ -281,8 +276,7 @@ ChatWindow::whisper(const std::string &nick, std::string msg, int prefixlen) chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER); } -void -ChatWindow::chatSend(const std::string &nick, std::string msg) +void ChatWindow::chatSend(const std::string &nick, std::string msg) { /* Some messages are managed client side, while others * require server handling by proper packet. Probably @@ -354,8 +348,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } } -std::string -ChatWindow::const_msg(CHATSKILL act) +std::string ChatWindow::const_msg(CHATSKILL act) { std::string msg; if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) { @@ -432,8 +425,7 @@ ChatWindow::const_msg(CHATSKILL act) return msg; } -void -ChatWindow::scroll(int amount) +void ChatWindow::scroll(int amount) { if (!isVisible()) return; @@ -445,8 +437,7 @@ ChatWindow::scroll(int amount) mTextOutput->showPart(scr); } -void -ChatWindow::keyPressed(gcn::KeyEvent &event) +void ChatWindow::keyPressed(gcn::KeyEvent &event) { if (event.getKey().getValue() == gcn::Key::DOWN && mCurHist != mHistory.end()) @@ -471,15 +462,13 @@ ChatWindow::keyPressed(gcn::KeyEvent &event) } } -void -ChatWindow::setInputText(std::string input_str) +void ChatWindow::setInputText(std::string input_str) { mChatInput->setText(input_str + " "); requestChatFocus(); } -void -ChatWindow::setVisible(bool isVisible) +void ChatWindow::setVisible(bool isVisible) { Window::setVisible(isVisible); diff --git a/src/gui/chat.h b/src/gui/chat.h index 09c3712b..dc0d002d 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -183,20 +183,16 @@ class ChatWindow : public Window, public gcn::ActionListener, * // for simple message by a user /- message * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); */ - void - chatSend(const std::string &nick, std::string msg); + void chatSend(const std::string &nick, std::string msg); /** Called when key is pressed */ - void - keyPressed(gcn::KeyEvent &event); + void keyPressed(gcn::KeyEvent &event); /** Called to set current text */ - void - setInputText(std::string input_str); + void setInputText(std::string input_str); /** Override to reset mTmpVisible */ - void - setVisible(bool visible); + void setVisible(bool visible); /** * Scrolls the chat window @@ -205,8 +201,7 @@ class ChatWindow : public Window, public gcn::ActionListener, * up, positive numbers scroll down. The absolute amount indicates the * amount of 1/8ths of chat window real estate that should be scrolled. */ - void - scroll(int amount); + void scroll(int amount); /** * help implements the /help command @@ -214,15 +209,13 @@ class ChatWindow : public Window, public gcn::ActionListener, * @param msg1 is the command that the player needs help on * @param msg2 is the sub-command relating to the command */ - void - help(const std::string &msg1, const std::string &msg2); + void help(const std::string &msg1, const std::string &msg2); private: Network *mNetwork; bool mTmpVisible; - void - whisper(const std::string &nick, std::string msg, int prefixlen); + void whisper(const std::string &nick, std::string msg, int prefixlen); /** One item in the chat log */ struct CHATLOG diff --git a/src/gui/window.h b/src/gui/window.h index 984c6f06..d40e8c91 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -163,8 +163,7 @@ class Window : public gcn::Window, gcn::WidgetListener * * @return The parent window or <code>NULL</code> if there is none. */ - Window* - getParentWindow() { return mParent; } + Window *getParentWindow() { return mParent; } /** * Schedule this window for deletion. It will be deleted at the start @@ -204,14 +203,12 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the name of the window. This is not the window title. */ - void - setWindowName(const std::string &name) { mWindowName = name; } + void setWindowName(const std::string &name) { mWindowName = name; } /** * Returns the name of the window. This is not the window title. */ - const std::string& - getWindowName() { return mWindowName; } + const std::string &getWindowName() { return mWindowName; } /** * Reads the position (and the size for resizable windows) in the diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 044f62bf..aa27607c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -276,10 +276,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::setWalkingDir(int dir) { - if (mWalkingDir != dir) - { - mWalkingDir = dir; - } + mWalkingDir = dir; // If we're not already walking, start walking. if (mAction != WALK && dir) diff --git a/src/properties.h b/src/properties.h index 2eafeeca..a593e8c2 100644 --- a/src/properties.h +++ b/src/properties.h @@ -35,8 +35,7 @@ class Properties /** * Destructor. */ - virtual - ~Properties() {} + virtual ~Properties() {} /** * Get a map property. @@ -46,8 +45,8 @@ class Properties * @return the value of the given property or the given default when it * doesn't exist. */ - const std::string& - getProperty(const std::string &name, const std::string &def = "") const + const std::string &getProperty(const std::string &name, + const std::string &def = "") const { PropertyMap::const_iterator i = mProperties.find(name); return (i != mProperties.end()) ? i->second : def; @@ -61,7 +60,7 @@ class Properties * @return the value of the given property, or 0.0f when it doesn't * exist. */ - float getFloatProperty(std::string const &name, float def = 0.0f) const + float getFloatProperty(const std::string &name, float def = 0.0f) const { PropertyMap::const_iterator i = mProperties.find(name); float ret = def; @@ -81,8 +80,7 @@ class Properties * @return <code>true</code> when a property is defined, * <code>false</code> otherwise. */ - bool - hasProperty(const std::string &name) const + bool hasProperty(const std::string &name) const { return (mProperties.find(name) != mProperties.end()); } @@ -93,8 +91,7 @@ class Properties * @param name The name of the property. * @param value The value of the property. */ - void - setProperty(const std::string &name, const std::string &value) + void setProperty(const std::string &name, const std::string &value) { mProperties[name] = value; } diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 3be105d8..d180d725 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -26,7 +26,7 @@ #include "../log.h" -Palette::Palette(std::string const &description) +Palette::Palette(const std::string &description) { int size = description.length(); if (size == 0) return; @@ -109,7 +109,7 @@ void Palette::getColor(int intensity, int color[3]) const color[2] = ((255 - t) * b1 + t * b2) / 255; } -Dye::Dye(std::string const &description) +Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) mPalettes[i] = 0; @@ -175,7 +175,7 @@ void Dye::update(int color[3]) const mPalettes[i - 1]->getColor(cmax, color); } -void Dye::instantiate(std::string &target, std::string const &palettes) +void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type next_pos = target.find('|'); if (next_pos == std::string::npos || palettes.empty()) return; diff --git a/src/resources/dye.h b/src/resources/dye.h index 528a1d91..f0bd7aab 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -36,7 +36,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(std::string const &); + Palette(const std::string &); /** * Gets a pixel color depending on its intensity. @@ -63,7 +63,7 @@ class Dye * The parts of string are separated by semi-colons. Each part starts * by an uppercase letter, followed by a colon and then a palette name. */ - Dye(std::string const &); + Dye(const std::string &); /** * Destroys the associated palettes. @@ -79,7 +79,7 @@ class Dye * Fills the blank in a dye placeholder with some palette names. */ static void instantiate(std::string &target, - std::string const &palettes); + const std::string &palettes); private: diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index 29458ba3..835ba100 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -88,7 +88,7 @@ void ProxyImage::convertToDisplayFormat() mSDLImage = NULL; } -gcn::Image *ImageLoader::load(std::string const &filename, bool convert) +gcn::Image *ImageLoader::load(const std::string &filename, bool convert) { ResourceManager *resman = ResourceManager::getInstance(); ProxyImage *i = new ProxyImage(resman->loadSDLSurface(filename)); diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h index 7979fd2f..821a0254 100644 --- a/src/resources/imageloader.h +++ b/src/resources/imageloader.h @@ -61,7 +61,8 @@ class ProxyImage : public gcn::Image class ImageLoader : public gcn::ImageLoader { public: - gcn::Image *load(std::string const &filename, bool convertToDisplayFormat); + gcn::Image *load(const std::string &filename, + bool convertToDisplayFormat); }; #endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a1965d57..3d42d92e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -215,7 +215,7 @@ std::string ResourceManager::getPath(const std::string &file) return path; } -Resource *ResourceManager::get(std::string const &idPath, generator fun, +Resource *ResourceManager::get(const std::string &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. @@ -267,7 +267,7 @@ struct ResourceLoader } }; -Resource *ResourceManager::load(std::string const &path, loader fun) +Resource *ResourceManager::load(const std::string &path, loader fun) { ResourceLoader l = { this, path, fun }; return get(path, ResourceLoader::load, &l); @@ -309,7 +309,7 @@ struct DyedImageLoader } }; -Image *ResourceManager::getImage(std::string const &idPath) +Image *ResourceManager::getImage(const std::string &idPath) { DyedImageLoader l = { this, idPath }; return static_cast<Image*>(get(idPath, DyedImageLoader::load, &l)); @@ -351,8 +351,7 @@ struct SpriteDefLoader } }; -SpriteDef *ResourceManager::getSprite - (std::string const &path, int variant) +SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) { SpriteDefLoader l = { path, variant }; std::stringstream ss; @@ -381,7 +380,8 @@ void ResourceManager::release(Resource *res) ResourceManager *ResourceManager::getInstance() { // Create a new instance if necessary. - if (instance == NULL) instance = new ResourceManager(); + if (!instance) + instance = new ResourceManager(); return instance; } diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index c1007f4a..e70dfb9d 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -98,7 +98,8 @@ class ResourceManager bool isDirectory(const std::string &path); /** - * Returns the real path to a file + * Returns the real path to a file. Note that this method will always + * return a path, it does not check whether the file exists. * * @param file The file to get the real path to. * @return The real path. @@ -114,7 +115,7 @@ class ResourceManager * @return A valid resource or <code>NULL</code> if the resource could * not be generated. */ - Resource *get(std::string const &idPath, generator fun, void *data); + Resource *get(const std::string &idPath, generator fun, void *data); /** * Loads a resource from a file and adds it to the resource map. @@ -124,7 +125,7 @@ class ResourceManager * @return A valid resource or <code>NULL</code> if the resource could * not be loaded. */ - Resource *load(std::string const &path, loader fun); + Resource *load(const std::string &path, loader fun); /** * Convenience wrapper around ResourceManager::get for loading @@ -154,7 +155,7 @@ class ResourceManager * Creates a sprite definition based on a given path and the supplied * variant. */ - SpriteDef *getSprite(std::string const &path, int variant = 0); + SpriteDef *getSprite(const std::string &path, int variant = 0); /** * Releases a resource, placing it in the set of orphaned resources. diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 3eb1d92b..28db0452 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -46,7 +46,7 @@ Action *SpriteDef::getAction(SpriteAction action) const return i->second; } -SpriteDef *SpriteDef::load(std::string const &animationFile, int variant) +SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) { std::string::size_type pos = animationFile.find('|'); std::string palettes; @@ -121,7 +121,7 @@ void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, } } -void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) +void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) { const std::string name = XML::getProperty(node, "name", ""); @@ -146,8 +146,7 @@ void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) mImageSets[name] = imageSet; } -void -SpriteDef::loadAction(xmlNodePtr node, int variant_offset) +void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); @@ -187,10 +186,9 @@ SpriteDef::loadAction(xmlNodePtr node, int variant_offset) } } -void -SpriteDef::loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset) +void SpriteDef::loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset) { const std::string directionName = XML::getProperty(animationNode, "direction", ""); @@ -267,8 +265,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, } // for frameNode } -void -SpriteDef::includeSprite(xmlNodePtr includeNode) +void SpriteDef::includeSprite(xmlNodePtr includeNode) { // TODO: Perform circular dependency check, since it's easy to crash the // client this way. @@ -289,8 +286,7 @@ SpriteDef::includeSprite(xmlNodePtr includeNode) loadSprite(rootNode, 0); } -void -SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) +void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) { if (mActions.find(complete) == mActions.end()) { @@ -324,8 +320,7 @@ SpriteDef::~SpriteDef() } } -SpriteAction -SpriteDef::makeSpriteAction(const std::string& action) +SpriteAction SpriteDef::makeSpriteAction(const std::string &action) { if (action == "" || action == "default") { return ACTION_DEFAULT; @@ -377,8 +372,7 @@ SpriteDef::makeSpriteAction(const std::string& action) } } -SpriteDirection -SpriteDef::makeSpriteDirection(const std::string& direction) +SpriteDirection SpriteDef::makeSpriteDirection(const std::string& direction) { if (direction == "" || direction == "default") { return DIRECTION_DEFAULT; @@ -397,5 +391,5 @@ SpriteDef::makeSpriteDirection(const std::string& direction) } else { return DIRECTION_INVALID; - }; + } } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 88f9b7b7..49a4ca51 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -71,7 +71,7 @@ class SpriteDef : public Resource /** * Loads a sprite definition file. */ - static SpriteDef *load(std::string const &file, int variant); + static SpriteDef *load(const std::string &file, int variant); /** * Returns the specified action. @@ -81,8 +81,7 @@ class SpriteDef : public Resource /** * Converts a string into a SpriteAction enum. */ - static SpriteAction - makeSpriteAction(const std::string &action); + static SpriteAction makeSpriteAction(const std::string &action); /** * Converts a string into a SpriteDirection enum. @@ -111,27 +110,24 @@ class SpriteDef : public Resource /** * Loads an imageset element. */ - void loadImageSet(xmlNodePtr node, std::string const &palettes); + void loadImageSet(xmlNodePtr node, const std::string &palettes); /** * Loads an action element. */ - void - loadAction(xmlNodePtr node, int variant_offset); + void loadAction(xmlNodePtr node, int variant_offset); /** * Loads an animation element. */ - void - loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset); + void loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset); /** * Include another sprite into this one. */ - void - includeSprite(xmlNodePtr includeNode); + void includeSprite(xmlNodePtr includeNode); /** * Complete missing actions by copying existing ones. @@ -142,8 +138,7 @@ class SpriteDef : public Resource * When there are no animations defined for the action "complete", its * animations become a copy of those of the action "with". */ - void - substituteAction(SpriteAction complete, SpriteAction with); + void substituteAction(SpriteAction complete, SpriteAction with); typedef std::map<std::string, ImageSet*> ImageSets; |