summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-08 23:24:37 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-09 22:48:21 +0200
commit69d8407badcb703709534f5097b9b5697ac3404c (patch)
tree7a7e126b0ce0181f22397d62ca3d4e553482b439 /src
parent1158bce840bbd76a297c4f5eefd19444584f6fcd (diff)
downloadmana-client-69d8407badcb703709534f5097b9b5697ac3404c.tar.gz
mana-client-69d8407badcb703709534f5097b9b5697ac3404c.tar.bz2
mana-client-69d8407badcb703709534f5097b9b5697ac3404c.tar.xz
mana-client-69d8407badcb703709534f5097b9b5697ac3404c.zip
Made BeingManager methods const where appropriate
Diffstat (limited to 'src')
-rw-r--r--src/beingmanager.cpp42
-rw-r--r--src/beingmanager.h24
-rw-r--r--src/gui/chat.cpp6
-rw-r--r--src/gui/minimap.cpp4
-rw-r--r--src/gui/viewport.cpp5
-rw-r--r--src/gui/widgets/chattab.cpp5
-rw-r--r--src/gui/widgets/chattab.h1
7 files changed, 44 insertions, 43 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
index b8acb7c2..d128c3e0 100644
--- a/src/beingmanager.cpp
+++ b/src/beingmanager.cpp
@@ -114,9 +114,10 @@ void BeingManager::destroyBeing(Being *being)
delete being;
}
-Being *BeingManager::findBeing(int id)
+Being *BeingManager::findBeing(int id) const
{
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ for (Beings::const_iterator i = mBeings.begin(), i_end = mBeings.end();
+ i != i_end; ++i)
{
Being *being = (*i);
if (being->getId() == id)
@@ -125,21 +126,22 @@ Being *BeingManager::findBeing(int id)
return NULL;
}
-Being *BeingManager::findBeing(int x, int y, Being::Type type)
+Being *BeingManager::findBeing(int x, int y, Being::Type type) const
{
beingFinder.x = x;
beingFinder.y = y;
beingFinder.type = type;
- BeingIterator i = find_if(mBeings.begin(), mBeings.end(), beingFinder);
+ Beings::const_iterator i = find_if(mBeings.begin(), mBeings.end(),
+ beingFinder);
return (i == mBeings.end()) ? NULL : *i;
}
-Being *BeingManager::findBeingByPixel(int x, int y)
+Being *BeingManager::findBeingByPixel(int x, int y) const
{
- BeingIterator itr = mBeings.begin();
- BeingIterator itr_end = mBeings.end();
+ Beings::const_iterator itr = mBeings.begin();
+ Beings::const_iterator itr_end = mBeings.end();
for (; itr != itr_end; ++itr)
{
@@ -162,9 +164,11 @@ Being *BeingManager::findBeingByPixel(int x, int y)
return NULL;
}
-Being *BeingManager::findBeingByName(const std::string &name, Being::Type type)
+Being *BeingManager::findBeingByName(const std::string &name,
+ Being::Type type) const
{
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ for (Beings::const_iterator i = mBeings.begin(), i_end = mBeings.end();
+ i != i_end; ++i)
{
Being *being = (*i);
if (being->getName() == name &&
@@ -174,14 +178,14 @@ Being *BeingManager::findBeingByName(const std::string &name, Being::Type type)
return NULL;
}
-Beings &BeingManager::getAll()
+const Beings &BeingManager::getAll() const
{
return mBeings;
}
void BeingManager::logic()
{
- BeingIterator i = mBeings.begin();
+ Beings::iterator i = mBeings.begin();
while (i != mBeings.end())
{
Being *being = (*i);
@@ -197,7 +201,7 @@ void BeingManager::logic()
else
#endif
{
- i++;
+ ++i;
}
}
}
@@ -215,7 +219,7 @@ void BeingManager::clear()
}
Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist,
- Being::Type type)
+ Being::Type type) const
{
Being *closestBeing = NULL;
int dist = 0;
@@ -232,8 +236,8 @@ Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist,
maxdist = maxdist * 32;
#endif
- BeingIterator itr = mBeings.begin();
- BeingIterator itr_end = mBeings.end();
+ Beings::const_iterator itr = mBeings.begin();
+ Beings::const_iterator itr_end = mBeings.end();
for (; itr != itr_end; ++itr)
{
@@ -258,7 +262,7 @@ Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist,
}
Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
- Being::Type type)
+ Being::Type type) const
{
Being *closestBeing = NULL;
int dist = 0;
@@ -272,7 +276,8 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
int y = aroundBeing->mY;
#endif
- for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++)
+ for (Beings::const_iterator i = mBeings.begin(), i_end = mBeings.end();
+ i != i_end; ++i)
{
Being *being = (*i);
#ifdef TMWSERV_SUPPORT
@@ -297,7 +302,8 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist,
bool BeingManager::hasBeing(Being *being) const
{
- for (Beings::const_iterator i = mBeings.begin(); i != mBeings.end(); i++)
+ for (Beings::const_iterator i = mBeings.begin(), i_end = mBeings.end();
+ i != i_end; ++i)
{
if (being == *i)
return true;
diff --git a/src/beingmanager.h b/src/beingmanager.h
index 727918a8..0150f373 100644
--- a/src/beingmanager.h
+++ b/src/beingmanager.h
@@ -28,7 +28,6 @@ class LocalPlayer;
class Map;
typedef std::list<Being*> Beings;
-typedef Beings::iterator BeingIterator;
class BeingManager
{
@@ -38,12 +37,12 @@ class BeingManager
~BeingManager();
/**
- * Sets the map on which beings are created
+ * Sets the map on which beings are created.
*/
void setMap(Map *map);
/**
- * Sets the current player
+ * Sets the current player.
*/
void setPlayer(LocalPlayer *player);
@@ -60,13 +59,13 @@ class BeingManager
/**
* Returns a specific id Being.
*/
- Being *findBeing(int id);
+ Being *findBeing(int id) const;
/**
* Returns a being at specific coordinates.
*/
- Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN);
- Being *findBeingByPixel(int x, int y);
+ Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN) const;
+ Being *findBeingByPixel(int x, int y) const;
/**
* Returns a being nearest to specific coordinates.
@@ -78,13 +77,13 @@ class BeingManager
* @param type The type of being to look for.
*/
Being *findNearestLivingBeing(int x, int y, int maxdist,
- Being::Type type = Being::UNKNOWN);
+ Being::Type type = Being::UNKNOWN) const;
/**
* Finds a being by name and (optionally) by type.
*/
Being *findBeingByName(const std::string &name,
- Being::Type type = Being::UNKNOWN);
+ Being::Type type = Being::UNKNOWN) const;
/**
* Returns a being nearest to another being.
@@ -93,12 +92,12 @@ class BeingManager
* no being is returned
*/
Being *findNearestLivingBeing(Being *aroundBeing, int maxdist,
- Being::Type type = Being::UNKNOWN);
+ Being::Type type = Being::UNKNOWN) const;
/**
- * Returns the whole list of beings
+ * Returns the whole list of beings.
*/
- Beings &getAll();
+ const Beings &getAll() const;
/**
* Returns true if the given being is in the manager's list, false
@@ -109,7 +108,8 @@ class BeingManager
bool hasBeing(Being *being) const;
/**
- * Logic.
+ * Performs being logic and deletes dead beings when they have been
+ * dead long enough.
*/
void logic();
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index b7a57da5..ab98b594 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -287,11 +287,11 @@ void ChatWindow::chatInput(std::string &msg)
void ChatWindow::doPresent()
{
- Beings & beings = beingManager->getAll();
+ const Beings &beings = beingManager->getAll();
std::string response = "";
- for (BeingIterator bi = beings.begin(), be = beings.end();
- bi != be; ++bi)
+ for (Beings::const_iterator bi = beings.begin(), be = beings.end();
+ bi != be; ++bi)
{
if ((*bi)->getType() == Being::PLAYER)
{
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index bfd34390..061a2ace 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -136,9 +136,9 @@ void Minimap::draw(gcn::Graphics *graphics)
}
const Beings &beings = beingManager->getAll();
- Beings::const_iterator bi;
- for (bi = beings.begin(); bi != beings.end(); bi++)
+ for (Beings::const_iterator bi = beings.begin(), bi_end = beings.end();
+ bi != bi_end; ++bi)
{
const Being *being = (*bi);
int dotSize = 2;
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 6dd1cb92..3fc5f2d4 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -214,8 +214,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
}
// Draw player names, speech, and emotion sprite as needed
- Beings &beings = beingManager->getAll();
- for (BeingIterator i = beings.begin(); i != beings.end(); i++)
+ const Beings &beings = beingManager->getAll();
+ for (Beings::const_iterator i = beings.begin(), i_end = beings.end();
+ i != i_end; ++i)
{
(*i)->drawSpeech((int) mPixelViewX, (int) mPixelViewY);
(*i)->drawEmotion(graphics, (int) mPixelViewX, (int) mPixelViewY);
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 0dcb2fdf..f3258f04 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -68,11 +68,6 @@ ChatTab::~ChatTab()
delete mScrollArea;
}
-void ChatTab::chatLog(const char* line, int own, bool ignoreRecord)
-{
- chatLog(std::string(line), own, ignoreRecord);
-}
-
void ChatTab::chatLog(std::string line, int own, bool ignoreRecord)
{
// Trim whitespace
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index ad7c90bb..3d92e57f 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -69,7 +69,6 @@ class ChatTab : public Tab
* @param ignoreRecord should this not be recorded?
*/
void chatLog(std::string line, int own = BY_SERVER, bool ignoreRecord = false);
- void chatLog(const char* line, int own = BY_SERVER, bool ignoreRecord = false);
/**
* Adds the text to the message list