Skip to content

Commit

Permalink
cavegen.cpp, chat.cpp: modernize code
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Aug 16, 2017
1 parent 9dd0f95 commit 90dfafc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
9 changes: 5 additions & 4 deletions src/cavegen.cpp
Expand Up @@ -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); v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of; p += of;


if (vm->m_area.contains(p) == false) if (!vm->m_area.contains(p))
continue; continue;


u32 i = vm->m_area.index(p); u32 i = vm->m_area.index(p);
Expand Down Expand Up @@ -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); v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of; p += of;


if (vm->m_area.contains(p) == false) if (!vm->m_area.contains(p))
continue; continue;


u32 i = vm->m_area.index(p); u32 i = vm->m_area.index(p);
Expand Down Expand Up @@ -858,7 +858,8 @@ inline s16 CavesV6::getSurfaceFromHeightmap(v3s16 p)
p.X >= node_min.X && p.X <= node_max.X) { p.X >= node_min.X && p.X <= node_max.X) {
u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X); u32 index = (p.Z - node_min.Z) * ystride + (p.X - node_min.X);
return heightmap[index]; return heightmap[index];
} else {
return water_level;
} }

return water_level;

} }
39 changes: 12 additions & 27 deletions src/chat.cpp
Expand Up @@ -34,10 +34,6 @@ ChatBuffer::ChatBuffer(u32 scrollback):
m_empty_formatted_line.first = true; m_empty_formatted_line.first = true;
} }


ChatBuffer::~ChatBuffer()
{
}

void ChatBuffer::addLine(std::wstring name, std::wstring text) void ChatBuffer::addLine(std::wstring name, std::wstring text)
{ {
ChatLine line(name, text); ChatLine line(name, text);
Expand Down Expand Up @@ -79,9 +75,8 @@ const ChatLine& ChatBuffer::getLine(u32 index) const


void ChatBuffer::step(f32 dtime) void ChatBuffer::step(f32 dtime)
{ {
for (u32 i = 0; i < m_unformatted.size(); ++i) for (ChatLine &line : m_unformatted) {
{ line.age += dtime;
m_unformatted[i].age += dtime;
} }
} }


Expand Down Expand Up @@ -198,8 +193,8 @@ const ChatFormattedLine& ChatBuffer::getFormattedLine(u32 row) const
s32 index = m_scroll + (s32) row; s32 index = m_scroll + (s32) row;
if (index >= 0 && index < (s32) m_formatted.size()) if (index >= 0 && index < (s32) m_formatted.size())
return m_formatted[index]; return m_formatted[index];
else
return m_empty_formatted_line; return m_empty_formatted_line;
} }


void ChatBuffer::scroll(s32 rows) void ChatBuffer::scroll(s32 rows)
Expand Down Expand Up @@ -357,10 +352,11 @@ s32 ChatBuffer::getTopScrollPos() const
s32 rows = (s32) m_rows; s32 rows = (s32) m_rows;
if (rows == 0) if (rows == 0)
return 0; return 0;
else if (formatted_count <= rows)
if (formatted_count <= rows)
return formatted_count - rows; return formatted_count - rows;
else
return 0; return 0;
} }


s32 ChatBuffer::getBottomScrollPos() const s32 ChatBuffer::getBottomScrollPos() const
Expand All @@ -381,10 +377,6 @@ ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
{ {
} }


ChatPrompt::~ChatPrompt()
{
}

void ChatPrompt::input(wchar_t ch) void ChatPrompt::input(wchar_t ch)
{ {
m_line.insert(m_cursor, 1, ch); m_line.insert(m_cursor, 1, ch);
Expand Down Expand Up @@ -484,18 +476,15 @@ void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwa


// find all names that start with the selected prefix // find all names that start with the selected prefix
std::vector<std::wstring> completions; std::vector<std::wstring> completions;
for (std::list<std::string>::const_iterator for (const std::string &name : names) {
i = names.begin(); if (str_starts_with(narrow_to_wide(name), prefix, true)) {
i != names.end(); ++i) std::wstring completion = narrow_to_wide(name);
{
if (str_starts_with(narrow_to_wide(*i), prefix, true))
{
std::wstring completion = narrow_to_wide(*i);
if (prefix_start == 0) if (prefix_start == 0)
completion += L": "; completion += L": ";
completions.push_back(completion); completions.push_back(completion);
} }
} }

if (completions.empty()) if (completions.empty())
return; return;


Expand Down Expand Up @@ -658,10 +647,6 @@ ChatBackend::ChatBackend():
{ {
} }


ChatBackend::~ChatBackend()
{
}

void ChatBackend::addMessage(std::wstring name, std::wstring text) void ChatBackend::addMessage(std::wstring name, std::wstring text)
{ {
// Note: A message may consist of multiple lines, for example the MOTD. // Note: A message may consist of multiple lines, for example the MOTD.
Expand Down
6 changes: 3 additions & 3 deletions src/chat.h
Expand Up @@ -73,7 +73,7 @@ class ChatBuffer
{ {
public: public:
ChatBuffer(u32 scrollback); ChatBuffer(u32 scrollback);
~ChatBuffer(); ~ChatBuffer() = default;


// Append chat line // Append chat line
// Removes oldest chat line if scrollback size is reached // Removes oldest chat line if scrollback size is reached
Expand Down Expand Up @@ -145,7 +145,7 @@ class ChatPrompt
{ {
public: public:
ChatPrompt(const std::wstring &prompt, u32 history_limit); ChatPrompt(const std::wstring &prompt, u32 history_limit);
~ChatPrompt(); ~ChatPrompt() = default;


// Input character or string // Input character or string
void input(wchar_t ch); void input(wchar_t ch);
Expand Down Expand Up @@ -252,7 +252,7 @@ class ChatBackend
{ {
public: public:
ChatBackend(); ChatBackend();
~ChatBackend(); ~ChatBackend() = default;


// Add chat message // Add chat message
void addMessage(std::wstring name, std::wstring text); void addMessage(std::wstring name, std::wstring text);
Expand Down

0 comments on commit 90dfafc

Please sign in to comment.