aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2017-08-16 08:26:04 +0200
committerLoic Blot <loic.blot@unix-experience.fr>2017-08-16 08:26:04 +0200
commit90dfafcda2d4bc33356983c7145bf10202c26bbd (patch)
tree8a3e97d11f3b4f1dee9b181215e7624f8c2e3eac
parent9dd0f952e09471f15f59a98c1ae650d99499cd77 (diff)
downloadminetest-90dfafcda2d4bc33356983c7145bf10202c26bbd.tar.gz
minetest-90dfafcda2d4bc33356983c7145bf10202c26bbd.tar.bz2
minetest-90dfafcda2d4bc33356983c7145bf10202c26bbd.zip
cavegen.cpp, chat.cpp: modernize code
-rw-r--r--src/cavegen.cpp9
-rw-r--r--src/chat.cpp39
-rw-r--r--src/chat.h6
3 files changed, 20 insertions, 34 deletions
diff --git a/src/cavegen.cpp b/src/cavegen.cpp
index fc9526b4f..0a950ecf4 100644
--- a/src/cavegen.cpp
+++ b/src/cavegen.cpp
@@ -515,7 +515,7 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;
- if (vm->m_area.contains(p) == false)
+ if (!vm->m_area.contains(p))
continue;
u32 i = vm->m_area.index(p);
@@ -819,7 +819,7 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz,
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;
- if (vm->m_area.contains(p) == false)
+ if (!vm->m_area.contains(p))
continue;
u32 i = vm->m_area.index(p);
@@ -858,7 +858,8 @@ inline s16 CavesV6::getSurfaceFromHeightmap(v3s16 p)
p.X >= node_min.X && p.X <= node_max.X) {
u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
return heightmap[index];
- } else {
- return water_level;
}
+
+ return water_level;
+
}
diff --git a/src/chat.cpp b/src/chat.cpp
index 72abc4669..3785b7797 100644
--- a/src/chat.cpp
+++ b/src/chat.cpp
@@ -34,10 +34,6 @@ ChatBuffer::ChatBuffer(u32 scrollback):
m_empty_formatted_line.first = true;
}
-ChatBuffer::~ChatBuffer()
-{
-}
-
void ChatBuffer::addLine(std::wstring name, std::wstring text)
{
ChatLine line(name, text);
@@ -79,9 +75,8 @@ const ChatLine& ChatBuffer::getLine(u32 index) const
void ChatBuffer::step(f32 dtime)
{
- for (u32 i = 0; i < m_unformatted.size(); ++i)
- {
- m_unformatted[i].age += dtime;
+ for (ChatLine &line : m_unformatted) {
+ line.age += dtime;
}
}
@@ -198,8 +193,8 @@ const ChatFormattedLine& ChatBuffer::getFormattedLine(u32 row) const
s32 index = m_scroll + (s32) row;
if (index >= 0 && index < (s32) m_formatted.size())
return m_formatted[index];
- else
- return m_empty_formatted_line;
+
+ return m_empty_formatted_line;
}
void ChatBuffer::scroll(s32 rows)
@@ -357,10 +352,11 @@ s32 ChatBuffer::getTopScrollPos() const
s32 rows = (s32) m_rows;
if (rows == 0)
return 0;
- else if (formatted_count <= rows)
+
+ if (formatted_count <= rows)
return formatted_count - rows;
- else
- return 0;
+
+ return 0;
}
s32 ChatBuffer::getBottomScrollPos() const
@@ -381,10 +377,6 @@ ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
{
}
-ChatPrompt::~ChatPrompt()
-{
-}
-
void ChatPrompt::input(wchar_t ch)
{
m_line.insert(m_cursor, 1, ch);
@@ -484,18 +476,15 @@ void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwa
// find all names that start with the selected prefix
std::vector<std::wstring> completions;
- for (std::list<std::string>::const_iterator
- i = names.begin();
- i != names.end(); ++i)
- {
- if (str_starts_with(narrow_to_wide(*i), prefix, true))
- {
- std::wstring completion = narrow_to_wide(*i);
+ for (const std::string &name : names) {
+ if (str_starts_with(narrow_to_wide(name), prefix, true)) {
+ std::wstring completion = narrow_to_wide(name);
if (prefix_start == 0)
completion += L": ";
completions.push_back(completion);
}
}
+
if (completions.empty())
return;
@@ -658,10 +647,6 @@ ChatBackend::ChatBackend():
{
}
-ChatBackend::~ChatBackend()
-{
-}
-
void ChatBackend::addMessage(std::wstring name, std::wstring text)
{
// Note: A message may consist of multiple lines, for example the MOTD.
diff --git a/src/chat.h b/src/chat.h
index 6a6b7c26f..e3961b3fa 100644
--- a/src/chat.h
+++ b/src/chat.h
@@ -73,7 +73,7 @@ class ChatBuffer
{
public:
ChatBuffer(u32 scrollback);
- ~ChatBuffer();
+ ~ChatBuffer() = default;
// Append chat line
// Removes oldest chat line if scrollback size is reached
@@ -145,7 +145,7 @@ class ChatPrompt
{
public:
ChatPrompt(const std::wstring &prompt, u32 history_limit);
- ~ChatPrompt();
+ ~ChatPrompt() = default;
// Input character or string
void input(wchar_t ch);
@@ -252,7 +252,7 @@ class ChatBackend
{
public:
ChatBackend();
- ~ChatBackend();
+ ~ChatBackend() = default;
// Add chat message
void addMessage(std::wstring name, std::wstring text);