Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Code modernization: subfolders (#6283)
* Code modernization: subfolders

Modernize various code on subfolders client, network, script, threading, unittests, util

* empty function
* default constructor/destructor
* for range-based loops
* use emplace_back instead of push_back
* C++ STL header style
* Make connection.cpp readable in a pointed place + typo
  • Loading branch information
nerzhul committed Aug 19, 2017
1 parent 7528986 commit 88b436e
Show file tree
Hide file tree
Showing 49 changed files with 396 additions and 516 deletions.
46 changes: 19 additions & 27 deletions src/client/tile.cpp
Expand Up @@ -484,43 +484,35 @@ u32 TextureSource::getTextureId(const std::string &name)
/*
Get texture
*/
if (std::this_thread::get_id() == m_main_thread)
{
if (std::this_thread::get_id() == m_main_thread) {
return generateTexture(name);
}
else
{
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;

// We're gonna ask the result to be put into here
static ResultQueue<std::string, u32, u8, u8> result_queue;

// Throw a request in
m_get_texture_queue.add(name, 0, 0, &result_queue);
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;

/*infostream<<"Waiting for texture from main thread, name=\""
<<name<<"\""<<std::endl;*/
// We're gonna ask the result to be put into here
static ResultQueue<std::string, u32, u8, u8> result_queue;

try
{
while(true) {
// Wait result for a second
GetResult<std::string, u32, u8, u8>
result = result_queue.pop_front(1000);
// Throw a request in
m_get_texture_queue.add(name, 0, 0, &result_queue);

if (result.key == name) {
return result.item;
}
try {
while(true) {
// Wait result for a second
GetResult<std::string, u32, u8, u8>
result = result_queue.pop_front(1000);

if (result.key == name) {
return result.item;
}
}
catch(ItemNotFoundException &e)
{
errorstream<<"Waiting for texture " << name << " timed out."<<std::endl;
return 0;
}
} catch(ItemNotFoundException &e) {
errorstream << "Waiting for texture " << name << " timed out." << std::endl;
return 0;
}

infostream<<"getTextureId(): Failed"<<std::endl;
infostream << "getTextureId(): Failed" << std::endl;

return 0;
}
Expand Down Expand Up @@ -673,7 +665,7 @@ Palette* TextureSource::getPalette(const std::string &name)
// Only the main thread may load images
sanity_check(std::this_thread::get_id() == m_main_thread);

if (name == "")
if (name.empty())
return NULL;

auto it = m_palettes.find(name);
Expand Down
6 changes: 4 additions & 2 deletions src/client/tile.h
Expand Up @@ -237,6 +237,8 @@ struct TileLayer
case TILE_MATERIAL_LIQUID_TRANSPARENT:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
break;
default:
break;
}
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
Expand Down Expand Up @@ -304,8 +306,8 @@ struct TileLayer
struct TileSpec
{
TileSpec() {
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
layers[layer] = TileLayer();
for (auto &layer : layers)
layer = TileLayer();
}

This comment has been minimized.

Copy link
@numberZero

numberZero Aug 21, 2017

Contributor

er, isn’t this what is done by the implicit default constructor?


/*!
Expand Down
10 changes: 5 additions & 5 deletions src/network/clientpackethandler.cpp
Expand Up @@ -221,7 +221,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
if (denyCode == SERVER_ACCESSDENIED_SHUTDOWN ||
denyCode == SERVER_ACCESSDENIED_CRASH) {
*pkt >> m_access_denied_reason;
if (m_access_denied_reason == "") {
if (m_access_denied_reason.empty()) {
m_access_denied_reason = accessDeniedStrings[denyCode];
}
u8 reconnect;
Expand All @@ -237,7 +237,7 @@ void Client::handleCommand_AccessDenied(NetworkPacket* pkt)
// Until then (which may be never), this is outside
// of the defined protocol.
*pkt >> m_access_denied_reason;
if (m_access_denied_reason == "") {
if (m_access_denied_reason.empty()) {
m_access_denied_reason = "Unknown";
}
}
Expand Down Expand Up @@ -683,7 +683,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt)
Strfnd sf(str);
while(!sf.at_end()) {
std::string baseurl = trim(sf.next(","));
if (baseurl != "")
if (!baseurl.empty())
m_media_downloader->addRemoteServer(baseurl);
}
}
Expand Down Expand Up @@ -1213,7 +1213,7 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
}
else if (param == HUD_PARAM_HOTBAR_IMAGE) {
// If value not empty verify image exists in texture source
if (value != "" && !getTextureSource()->isKnownSourceImage(value)) {
if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
errorstream << "Server sent wrong Hud hotbar image (sent value: '"
<< value << "')" << std::endl;
return;
Expand All @@ -1222,7 +1222,7 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
}
else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
// If value not empty verify image exists in texture source
if (value != "" && !getTextureSource()->isKnownSourceImage(value)) {
if (!value.empty() && !getTextureSource()->isKnownSourceImage(value)) {
errorstream << "Server sent wrong Hud hotbar selected image (sent value: '"
<< value << "')" << std::endl;
return;
Expand Down

0 comments on commit 88b436e

Please sign in to comment.