c == biome->c_water) {
column_is_open = true;
continue;
- } else if (c == biome->c_river_water) {
+ }
+
+ if (c == biome->c_river_water) {
column_is_open = true;
is_under_river = true;
continue;
// Block is dummy if data doesn't exist.
// It means it has been not found from disk and not generated
- if(block->isDummy())
- {
+ if (block->isDummy()) {
surely_not_found_on_disk = true;
}
- if(block->isGenerated() == false)
+ if (!block->isGenerated())
block_is_invalid = true;
/*
Block is near ground level if night-time mesh
differs from day-time mesh.
*/
- if(d >= d_opt)
- {
- if(block->getDayNightDiff() == false)
+ if (d >= d_opt) {
+ if (!block->getDayNightDiff())
continue;
}
If block has been marked to not exist on disk (dummy)
and generating new ones is not wanted, skip block.
*/
- if(generate == false && surely_not_found_on_disk == true)
- {
+ if (!generate && surely_not_found_on_disk) {
// get next one.
continue;
}
m_nearest_unsent_d = 0;
m_nothing_to_send_pause_timer = 0;
- for(std::map<v3s16, MapBlock*>::iterator
- i = blocks.begin();
- i != blocks.end(); ++i)
- {
- v3s16 p = i->first;
+ for (auto &block : blocks) {
+ v3s16 p = block.first;
m_blocks_modified.insert(p);
if(m_blocks_sending.find(p) != m_blocks_sending.end())
{
MutexAutoLock clientslock(m_clients_mutex);
- for (RemoteClientMap::iterator i = m_clients.begin();
- i != m_clients.end(); ++i) {
+ for (auto &client_it : m_clients) {
// Delete client
- delete i->second;
+ delete client_it.second;
}
}
}
if(!clients.empty())
infostream<<"Players:"<<std::endl;
- for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) {
- RemotePlayer *player = m_env->getPlayer(*i);
+ for (u16 i : clients) {
+ RemotePlayer *player = m_env->getPlayer(i);
if (player == NULL)
continue;
{
MutexAutoLock clientslock(m_clients_mutex);
- RemoteClient* client = lockedGetClientNoEx(*i);
+ RemoteClient* client = lockedGetClientNoEx(i);
if (client)
client->PrintInfo(infostream);
}
- m_clients_names.push_back(player->getName());
+ m_clients_names.emplace_back(player->getName());
}
}
}
void ClientInterface::sendToAll(NetworkPacket *pkt)
{
MutexAutoLock clientslock(m_clients_mutex);
- for (RemoteClientMap::iterator i = m_clients.begin();
- i != m_clients.end(); ++i) {
- RemoteClient *client = i->second;
+ for (auto &client_it : m_clients) {
+ RemoteClient *client = client_it.second;
if (client->net_proto_version != 0) {
m_con->Send(client->peer_id,
u16 min_proto_ver)
{
MutexAutoLock clientslock(m_clients_mutex);
- for (std::unordered_map<u16, RemoteClient*>::iterator i = m_clients.begin();
- i != m_clients.end(); ++i) {
- RemoteClient *client = i->second;
+ for (auto &client_it : m_clients) {
+ RemoteClient *client = client_it.second;
NetworkPacket *pkt_to_send = nullptr;
if (client->net_proto_version >= min_proto_ver) {
if (n->second->getState() >= state_min)
return n->second;
- else
- return NULL;
+
+ return NULL;
}
RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
if (n->second->getState() >= state_min)
return n->second;
- else
- return NULL;
+
+ return NULL;
}
ClientState ClientInterface::getClientState(u16 peer_id)
//TODO this should be done by client destructor!!!
RemoteClient *client = n->second;
// Handle objects
- for (std::set<u16>::iterator i = client->m_known_objects.begin();
- i != client->m_known_objects.end(); ++i) {
+ for (u16 id : client->m_known_objects) {
// Get object
- u16 id = *i;
ServerActiveObject* obj = m_env->getActiveObject(id);
if(obj && obj->m_known_by_count > 0)
void clear()
{
- for (int l = 0; l < MAX_TILE_LAYERS; l++)
- lists[l].clear();
+ for (auto &list : lists)
+ list.clear();
}
void add(scene::IMeshBuffer *buf, u8 layer)
}
// Render all layers in order
- for (int layer = 0; layer < MAX_TILE_LAYERS; layer++) {
- std::vector<MeshBufList> &lists = drawbufs.lists[layer];
-
+ for (auto &lists : drawbufs.lists) {
int timecheck_counter = 0;
for (MeshBufList &list : lists) {
timecheck_counter++;
switch(i)
{
case 0: // top
- for(int j=0;j<4;j++){
- v[j].Normal.set(0,1,0);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Normal.set(0,1,0);
}
v[0].Pos.set(-rx, ry,-rz);
v[1].Pos.set(-rx, ry, rz);
if(grid[j])
continue;
}
- for(int j=0;j<4;j++){
- v[j].Color = c_side_1;
- v[j].Normal.set(0,0,-1);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Color = c_side_1;
+ vertex.Normal.set(0,0,-1);
}
v[0].Pos.set(-rx, ry,-rz);
v[1].Pos.set( rx, ry,-rz);
if(grid[j])
continue;
}
- for(int j=0;j<4;j++){
- v[j].Color = c_side_2;
- v[j].Normal.set(1,0,0);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Color = c_side_2;
+ vertex.Normal.set(1,0,0);
}
v[0].Pos.set( rx, ry,-rz);
v[1].Pos.set( rx, ry, rz);
if(grid[j])
continue;
}
- for(int j=0;j<4;j++){
- v[j].Color = c_side_1;
- v[j].Normal.set(0,0,-1);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Color = c_side_1;
+ vertex.Normal.set(0,0,-1);
}
v[0].Pos.set( rx, ry, rz);
v[1].Pos.set(-rx, ry, rz);
if(grid[j])
continue;
}
- for(int j=0;j<4;j++){
- v[j].Color = c_side_2;
- v[j].Normal.set(-1,0,0);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Color = c_side_2;
+ vertex.Normal.set(-1,0,0);
}
v[0].Pos.set(-rx, ry, rz);
v[1].Pos.set(-rx, ry,-rz);
v[3].Pos.set(-rx, 0, rz);
break;
case 5: // bottom
- for(int j=0;j<4;j++){
- v[j].Color = c_bottom;
- v[j].Normal.set(0,-1,0);
+ for (video::S3DVertex &vertex : v) {
+ vertex.Color = c_bottom;
+ vertex.Normal.set(0,-1,0);
}
v[0].Pos.set( rx, 0, rz);
v[1].Pos.set(-rx, 0, rz);
v3f pos(p0.X, m_params.height * BS, p0.Y);
pos -= intToFloat(m_camera_offset, BS);
- for(u16 i=0; i<4; i++)
- v[i].Pos += pos;
+ for (video::S3DVertex &vertex : v)
+ vertex.Pos += pos;
u16 indices[] = {0,1,2,2,3,0};
driver->drawVertexPrimitiveList(v, 4, indices, 2,
video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
m_env->getScriptIface()->luaentity_Remove(m_id);
}
- for (std::unordered_set<u32>::iterator it = m_attached_particle_spawners.begin();
- it != m_attached_particle_spawners.end(); ++it) {
- m_env->deleteParticleSpawner(*it, false);
+ for (u32 attached_particle_spawner : m_attached_particle_spawners) {
+ m_env->deleteParticleSpawner(attached_particle_spawner, false);
}
}
m_hp = m_prop.hp_max;
// Activate entity, supplying serialized state
m_env->getScriptIface()->
- luaentity_Activate(m_id, m_init_state.c_str(), dtime_s);
+ luaentity_Activate(m_id, m_init_state, dtime_s);
} else {
m_prop.infotext = m_init_name;
}
s16 hp = 1;
v3f velocity;
float yaw = 0;
- if(data != ""){
+ if (!data.empty()) {
std::istringstream is(data, std::ios::binary);
// read version
u8 version = readU8(is);
m_prop.visual = "upright_sprite";
m_prop.visual_size = v2f(1, 2);
m_prop.textures.clear();
- m_prop.textures.push_back("player.png");
- m_prop.textures.push_back("player_back.png");
+ m_prop.textures.emplace_back("player.png");
+ m_prop.textures.emplace_back("player_back.png");
m_prop.colors.clear();
- m_prop.colors.push_back(video::SColor(255, 255, 255, 255));
+ m_prop.colors.emplace_back(255, 255, 255, 255);
m_prop.spritediv = v2s16(1,1);
// end of default appearance
m_prop.is_visible = true;
ServerActiveObject::removingFromEnvironment();
if (m_player->getPlayerSAO() == this) {
unlinkPlayerSessionAndSave();
- for (std::unordered_set<u32>::iterator it = m_attached_particle_spawners.begin();
- it != m_attached_particle_spawners.end(); ++it) {
- m_env->deleteParticleSpawner(*it, false);
+ for (u32 attached_particle_spawner : m_attached_particle_spawners) {
+ m_env->deleteParticleSpawner(attached_particle_spawner, false);
}
}
}
return os.str();
}
-void PlayerSAO::getStaticData(std::string *) const
+void PlayerSAO::getStaticData(std::string * result) const
{
FATAL_ERROR("Deprecated function");
}
case CRAFT_HASH_TYPE_ITEM_NAMES: {
std::ostringstream os;
bool is_first = true;
- for (size_t i = 0; i < grid_names.size(); i++) {
- if (!grid_names[i].empty()) {
- os << (is_first ? "" : "\n") << grid_names[i];
+ for (const std::string &grid_name : grid_names) {
+ if (!grid_name.empty()) {
+ os << (is_first ? "" : "\n") << grid_name;
is_first = false;
}
}
return getHashForString(os.str());
} case CRAFT_HASH_TYPE_COUNT: {
u64 cnt = 0;
- for (size_t i = 0; i < grid_names.size(); i++)
- if (!grid_names[i].empty())
+ for (const std::string &grid_name : grid_names)
+ if (!grid_name.empty())
cnt++;
return cnt;
} case CRAFT_HASH_TYPE_UNHASHED:
bool success = false;
unsigned int x = 0;
unsigned int y = 0;
- for (std::vector<std::string>::size_type i = 0;
- i < items.size(); i++) {
+ for (const std::string &item : items) {
// Is this an actual item?
- if (!items[i].empty()) {
+ if (!item.empty()) {
if (!success) {
// This is the first nonempty item
min_x = max_x = x;
if (type == CRAFT_HASH_TYPE_ITEM_NAMES) {
return getHashForString(recipe_name);
}
+
if (type == CRAFT_HASH_TYPE_COUNT) {
return 1;
- } else {
- //illegal hash type for this CraftDefinition (pre-condition)
- assert(false);
- return 0;
}
+
+ // illegal hash type for this CraftDefinition (pre-condition)
+ assert(false);
+ return 0;
}
void CraftDefinitionCooking::initHash(IGameDef *gamedef)
if (type == CRAFT_HASH_TYPE_COUNT) {
return 1;
- } else {
- //illegal hash type for this CraftDefinition (pre-condition)
- assert(false);
- return 0;
}
+
+ // illegal hash type for this CraftDefinition (pre-condition)
+ assert(false);
+ return 0;
}
void CraftDefinitionFuel::initHash(IGameDef *gamedef)
{
for (int type = 0; type <= craft_hash_type_max; ++type) {
for (auto &it : m_craft_defs[type]) {
- for (auto iit = it.second.begin();
- iit != it.second.end(); ++iit) {
- delete *iit;
+ for (auto &iit : it.second) {
+ delete iit;
}
it.second.clear();
}
m_cache_nodetimer_interval = g_settings->getFloat("nodetimer_interval");
}
-Environment::~Environment()
-{
-}
-
u32 Environment::getDayNightRatio()
{
MutexAutoLock lock(this->m_time_lock);
if (state->m_objects_pointable) {
std::vector<PointedThing> found;
getSelectedActiveObjects(state->m_shootline, found);
- for (std::vector<PointedThing>::iterator pointed = found.begin();
- pointed != found.end(); ++pointed) {
- state->m_found.push(*pointed);
+ for (const PointedThing &pointed : found) {
+ state->m_found.push(pointed);
}
}
// Set search range
public:
// Environment will delete the map passed to the constructor
Environment(IGameDef *gamedef);
- virtual ~Environment();
+ virtual ~Environment() = default;
DISABLE_CLASS_COPY(Environment);
/*
m_env(env)
{
- for (unsigned int i = 0; i < FM_MaxMode; i++) {
- m_default_size[i] = (FontMode) FONT_SIZE_UNSPECIFIED;
+ for (u32 &i : m_default_size) {
+ i = (FontMode) FONT_SIZE_UNSPECIFIED;
}
assert(m_settings != NULL); // pre-condition
/******************************************************************************/
void FontEngine::cleanCache()
{
- for ( unsigned int i = 0; i < FM_MaxMode; i++) {
+ for (auto &font_cache_it : m_font_cache) {
- for (std::map<unsigned int, irr::gui::IGUIFont*>::iterator iter
- = m_font_cache[i].begin();
- iter != m_font_cache[i].end(); ++iter) {
- iter->second->drop();
- iter->second = NULL;
+ for (auto &font_it : font_cache_it) {
+ font_it.second->drop();
+ font_it.second = NULL;
}
- m_font_cache[i].clear();
+ font_cache_it.clear();
}
}
{
assert(mode == FM_Simple || mode == FM_SimpleMono); // pre-condition
- std::string font_path = "";
+ std::string font_path;
if (mode == FM_Simple) {
font_path = m_settings->get("font_path");
} else {
if (y + line_height < 0)
continue;
- for (u32 i = 0; i < line.fragments.size(); ++i)
- {
- const ChatFormattedFragment& fragment = line.fragments[i];
+ for (const ChatFormattedFragment &fragment : line.fragments) {
s32 x = (fragment.column + 1) * m_fontsize.X;
core::rect<s32> destrect(
x, y, x + m_fontsize.X * fragment.text.size(), y + m_fontsize.Y);
#if USE_FREETYPE
// Draw colored text if FreeType is enabled
- irr::gui::CGUITTFont *tmp = static_cast<irr::gui::CGUITTFont*>(m_font);
+ irr::gui::CGUITTFont *tmp = dynamic_cast<irr::gui::CGUITTFont *>(m_font);
tmp->draw(
fragment.text,
destrect,
if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
{
// Key input
- if(KeyPress(event.KeyInput) == getKeySetting("keymap_console"))
- {
+ if (KeyPress(event.KeyInput) == getKeySetting("keymap_console")) {
closeConsole();
// inhibit open so the_game doesn't reopen immediately
m_close_on_enter = false;
return true;
}
- else if(event.KeyInput.Key == KEY_ESCAPE)
- {
+
+ if (event.KeyInput.Key == KEY_ESCAPE) {
closeConsoleAtOnce();
m_close_on_enter = false;
// inhibit open so the_game doesn't reopen immediately
/******************************************************************************/
MenuTextureSource::~MenuTextureSource()
{
- for (std::set<std::string>::iterator it = m_to_delete.begin();
- it != m_to_delete.end(); ++it) {
- const char *tname = (*it).c_str();
+ for (const std::string &texture_to_delete : m_to_delete) {
+ const char *tname = texture_to_delete.c_str();
video::ITexture *texture = m_driver->getTexture(tname);
m_driver->removeTexture(texture);
}
m_kill(kill)
{
//initialize texture pointers
- for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
- m_textures[i].texture = NULL;
+ for (image_definition &texture : m_textures) {
+ texture.texture = NULL;
}
// is deleted by guiformspec!
m_buttonhandler = new TextDestGuiEngine(this);
m_irr_toplefttext->setText(L"");
//clean up texture pointers
- for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) {
- if (m_textures[i].texture)
- RenderingEngine::get_video_driver()->removeTexture(m_textures[i].texture);
+ for (image_definition &texture : m_textures) {
+ if (texture.texture)
+ RenderingEngine::get_video_driver()->removeTexture(texture.texture);
}
delete m_texture_source;
m_textures[layer].texture = NULL;
}
- if ((texturepath == "") || !fs::PathExists(texturepath)) {
+ if (texturepath.empty() || !fs::PathExists(texturepath)) {
return false;
}
m_textures[layer].tile = tile_image;
m_textures[layer].minsize = minsize;
- if (m_textures[layer].texture == NULL) {
+ if (!m_textures[layer].texture) {
return false;
}
{
removeChildren();
- for (u32 i = 0; i < m_tables.size(); ++i) {
- GUITable *table = m_tables[i].second;
- table->drop();
+ for (auto &table_it : m_tables) {
+ table_it.second->drop();
}
delete m_selected_item;
}
// 1. first empty editbox
- for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
- it != children.end(); ++it) {
- if ((*it)->getType() == gui::EGUIET_EDIT_BOX
- && (*it)->getText()[0] == 0) {
- Environment->setFocus(*it);
+ for (gui::IGUIElement *it : children) {
+ if (it->getType() == gui::EGUIET_EDIT_BOX
+ && it->getText()[0] == 0) {
+ Environment->setFocus(it);
return;
}
}
// 2. first editbox
- for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
- it != children.end(); ++it) {
- if ((*it)->getType() == gui::EGUIET_EDIT_BOX) {
- Environment->setFocus(*it);
+ for (gui::IGUIElement *it : children) {
+ if (it->getType() == gui::EGUIET_EDIT_BOX) {
+ Environment->setFocus(it);
return;
}
}
// 3. first table
- for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
- it != children.end(); ++it) {
- if ((*it)->getTypeName() == std::string("GUITable")) {
- Environment->setFocus(*it);
+ for (gui::IGUIElement *it : children) {
+ if (it->getTypeName() == std::string("GUITable")) {
+ Environment->setFocus(it);
return;
}
}
}
// 5. first focusable (not statictext, not tabheader)
- for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
- it != children.end(); ++it) {
- if ((*it)->getType() != gui::EGUIET_STATIC_TEXT &&
- (*it)->getType() != gui::EGUIET_TAB_CONTROL) {
- Environment->setFocus(*it);
+ for (gui::IGUIElement *it : children) {
+ if (it->getType() != gui::EGUIET_STATIC_TEXT &&
+ it->getType() != gui::EGUIET_TAB_CONTROL) {
+ Environment->setFocus(it);
return;
}
}
GUITable* GUIFormSpecMenu::getTable(const std::string &tablename)
{
- for (u32 i = 0; i < m_tables.size(); ++i) {
- if (tablename == m_tables[i].first.fname)
- return m_tables[i].second;
+ for (auto &table : m_tables) {
+ if (tablename == table.first.fname)
+ return table.second;
}
return 0;
}
std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &name)
{
- for (u32 i = 0; i < m_dropdowns.size(); ++i) {
- if (name == m_dropdowns[i].first.fname)
- return &m_dropdowns[i].second;
+ for (auto &dropdown : m_dropdowns) {
+ if (name == dropdown.first.fname)
+ return &dropdown.second;
}
return NULL;
}
std::string listname = parts[1];
std::vector<std::string> v_pos = split(parts[2],',');
std::vector<std::string> v_geom = split(parts[3],',');
- std::string startindex = "";
+ std::string startindex;
if (parts.size() == 5)
startindex = parts[4];
geom.Y = stoi(v_geom[1]);
s32 start_i = 0;
- if(startindex != "")
+ if (!startindex.empty())
start_i = stoi(startindex);
if (geom.X < 0 || geom.Y < 0 || start_i < 0) {
if(!data->explicit_size)
warningstream<<"invalid use of list without a size[] element"<<std::endl;
- m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom, start_i));
+ m_inventorylists.emplace_back(loc, listname, pos, geom, start_i);
return;
}
errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl;
else
loc.deSerialize(location);
- m_inventory_rings.push_back(ListRingSpec(loc, listname));
+ m_inventory_rings.emplace_back(loc, listname);
return;
- } else if ((element == "") && (m_inventorylists.size() > 1)) {
+ }
+
+ if (element.empty() && m_inventorylists.size() > 1) {
size_t siz = m_inventorylists.size();
// insert the last two inv list elements into the list ring
const ListDrawSpec &spa = m_inventorylists[siz - 2];
const ListDrawSpec &spb = m_inventorylists[siz - 1];
- m_inventory_rings.push_back(ListRingSpec(spa.inventoryloc, spa.listname));
- m_inventory_rings.push_back(ListRingSpec(spb.inventoryloc, spb.listname));
+ m_inventory_rings.emplace_back(spa.inventoryloc, spa.listname);
+ m_inventory_rings.emplace_back(spb.inventoryloc, spb.listname);
return;
}
+
errorstream<< "Invalid list ring element(" << parts.size() << ", "
<< m_inventorylists.size() << "): '" << element << "'" << std::endl;
}
std::vector<std::string> v_pos = split(parts[0],',');
std::string name = parts[1];
std::string label = parts[2];
- std::string selected = "";
+ std::string selected;
if (parts.size() >= 4)
selected = parts[3];
Environment->setFocus(e);
}
- m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e));
+ m_checkboxes.emplace_back(spec,e);
m_fields.push_back(spec);
return;
}
e->setSmallStep(10);
e->setLargeStep(100);
- m_scrollbars.push_back(std::pair<FieldSpec,gui::IGUIScrollBar*>(spec,e));
+ m_scrollbars.emplace_back(spec,e);
m_fields.push_back(spec);
return;
}
if (!data->explicit_size)
warningstream<<"invalid use of image without a size[] element"<<std::endl;
- m_images.push_back(ImageDrawSpec(name, pos, geom));
+ m_images.emplace_back(name, pos, geom);
return;
- } else if (parts.size() == 2) {
+ }
+
+ if (parts.size() == 2) {
std::vector<std::string> v_pos = split(parts[0],',');
std::string name = unescape_string(parts[1]);
if (!data->explicit_size)
warningstream<<"invalid use of image without a size[] element"<<std::endl;
- m_images.push_back(ImageDrawSpec(name, pos));
+ m_images.emplace_back(name, pos);
return;
}
errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
if(!data->explicit_size)
warningstream<<"invalid use of item_image without a size[] element"<<std::endl;
- m_itemimages.push_back(ImageDrawSpec("", name, pos, geom));
+ m_itemimages.emplace_back("", name, pos, geom);
return;
}
errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
pos.Y = stoi(v_pos[1]); //acts as offset
clip = true;
}
- m_backgrounds.push_back(ImageDrawSpec(name, pos, geom, clip));
+ m_backgrounds.emplace_back(name, pos, geom, clip);
return;
}
std::vector<std::string> parts = split(element,';');
data->table_options.clear();
- for (size_t i = 0; i < parts.size(); ++i) {
+ for (const std::string &part : parts) {
// Parse table option
- std::string opt = unescape_string(parts[i]);
+ std::string opt = unescape_string(part);
data->table_options.push_back(GUITable::splitOption(opt));
}
}
std::vector<std::string> parts = split(element,';');
data->table_columns.clear();
- for (size_t i = 0; i < parts.size(); ++i) {
- std::vector<std::string> col_parts = split(parts[i],',');
+ for (const std::string &part : parts) {
+ std::vector<std::string> col_parts = split(part,',');
GUITable::TableColumn column;
// Parse column type
if (!col_parts.empty())
std::vector<std::string> v_geom = split(parts[1],',');
std::string name = parts[2];
std::vector<std::string> items = split(parts[3],',');
- std::string str_initial_selection = "";
+ std::string str_initial_selection;
std::string str_transparent = "false";
if (parts.size() >= 5)
spec.ftype = f_Table;
- for (unsigned int i = 0; i < items.size(); ++i) {
- items[i] = unescape_enriched(unescape_string(items[i]));
+ for (std::string &item : items) {
+ item = unescape_enriched(unescape_string(item));
}
//now really show table
e->setDynamicData(data->table_dyndata[name]);
}
- if ((str_initial_selection != "") &&
- (str_initial_selection != "0"))
- e->setSelected(stoi(str_initial_selection.c_str()));
+ if (!str_initial_selection.empty() && str_initial_selection != "0")
+ e->setSelected(stoi(str_initial_selection));
- m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
+ m_tables.emplace_back(spec, e);
m_fields.push_back(spec);
return;
}
std::vector<std::string> v_geom = split(parts[1],',');
std::string name = parts[2];
std::vector<std::string> items = split(parts[3],',');
- std::string str_initial_selection = "";
+ std::string str_initial_selection;
std::string str_transparent = "false";
if (parts.size() >= 5)
spec.ftype = f_Table;
- for (unsigned int i = 0; i < items.size(); ++i) {
- items[i] = unescape_enriched(unescape_string(items[i]));
+ for (std::string &item : items) {
+ item = unescape_enriched(unescape_string(item));
}
//now really show list
e->setDynamicData(data->table_dyndata[name]);
}
- if ((str_initial_selection != "") &&
- (str_initial_selection != "0"))
- e->setSelected(stoi(str_initial_selection.c_str()));
+ if (!str_initial_selection.empty() && str_initial_selection != "0")
+ e->setSelected(stoi(str_initial_selection));
- m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
+ m_tables.emplace_back(spec, e);
m_fields.push_back(spec);
return;
}
std::vector<std::string> v_pos = split(parts[0],',');
std::string name = parts[2];
std::vector<std::string> items = split(parts[3],',');
- std::string str_initial_selection = "";
+ std::string str_initial_selection;
str_initial_selection = parts[4];
MY_CHECKPOS("dropdown",0);
Environment->setFocus(e);
}
- for (unsigned int i=0; i < items.size(); i++) {
+ for (const std::string &item : items) {
e->addItem(unescape_enriched(unescape_string(
- utf8_to_wide(items[i]))).c_str());
+ utf8_to_wide(item))).c_str());
}
- if (str_initial_selection != "")
- e->setSelected(stoi(str_initial_selection.c_str())-1);
+ if (!str_initial_selection.empty())
+ e->setSelected(stoi(str_initial_selection)-1);
m_fields.push_back(spec);
- m_dropdowns.push_back(std::pair<FieldSpec,
- std::vector<std::string> >(spec, std::vector<std::string>()));
+ m_dropdowns.emplace_back(spec, std::vector<std::string>());
std::vector<std::string> &values = m_dropdowns.back().second;
- for (unsigned int i = 0; i < items.size(); i++) {
- values.push_back(unescape_string(items[i]));
+ for (const std::string &item : items) {
+ values.push_back(unescape_string(item));
}
return;
evt.EventType = EET_KEY_INPUT_EVENT;
evt.KeyInput.Key = KEY_END;
evt.KeyInput.Char = 0;
- evt.KeyInput.Control = 0;
- evt.KeyInput.Shift = 0;
+ evt.KeyInput.Control = false;
+ evt.KeyInput.Shift = false;
evt.KeyInput.PressedDown = true;
e->OnEvent(evt);
258+m_fields.size()
);
- if (name == "")
- {
+ if (name.empty()) {
// spec field id to 0, this stops submit searching for a value that isn't there
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
- }
- else
- {
+ } else {
spec.send = true;
gui::IGUIElement *e;
#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
258+m_fields.size()
);
- if (name == "")
- {
+ if (name.empty()) {
// spec field id to 0, this stops submit searching for a value that isn't there
addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
- }
- else
- {
+ } else {
spec.send = true;
gui::IGUIEditBox *e;
if(!data->explicit_size)
warningstream<<"invalid use of label without a size[] element"<<std::endl;
- std::wstring label = L"";
+ std::wstring label;
- for (unsigned int i=0; i < text.length(); i++) {
- label += text[i];
+ for (wchar_t i : text) {
+ label += i;
label += L"\n";
}
bool noclip = false;
bool drawborder = true;
- std::string pressed_image_name = "";
+ std::string pressed_image_name;
if (parts.size() >= 7) {
if (parts[5] == "true")
video::ITexture *texture = 0;
video::ITexture *pressed_texture = 0;
texture = m_tsrc->getTexture(image_name);
- if (pressed_image_name != "")
+ if (!pressed_image_name.empty())
pressed_texture = m_tsrc->getTexture(pressed_image_name);
else
pressed_texture = texture;
e->setNotClipped(true);
- for (unsigned int i = 0; i < buttons.size(); i++) {
+ for (const std::string &button : buttons) {
e->addTab(unescape_enriched(unescape_string(
- utf8_to_wide(buttons[i]))).c_str(), -1);
+ utf8_to_wide(button))).c_str(), -1);
}
if ((tab_index >= 0) &&
pos = padding + AbsoluteRect.UpperLeftCorner + pos_offset * spacing;
pos.X += stof(v_pos[0]) * (float) spacing.X;
pos.Y += stof(v_pos[1]) * (float) spacing.Y;
- m_itemimages.push_back(ImageDrawSpec("", item_name, e, pos, geom));
- m_static_texts.push_back(StaticTextSpec(utf8_to_wide(label), rect, e));
+ m_itemimages.emplace_back("", item_name, e, pos, geom);
+ m_static_texts.emplace_back(utf8_to_wide(label), rect, e);
return;
}
errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
m_default_tooltip_bgcolor, m_default_tooltip_color);
return;
- } else if (parts.size() == 4) {
+ }
+
+ if (parts.size() == 4) {
std::string name = parts[0];
video::SColor tmp_color1, tmp_color2;
if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
bool GUIFormSpecMenu::parseVersionDirect(const std::string &data)
{
//some prechecks
- if (data == "")
+ if (data.empty())
return false;
std::vector<std::string> parts = split(data,'[');
bool GUIFormSpecMenu::parseSizeDirect(parserData* data, const std::string &element)
{
- if (element == "")
+ if (element.empty())
return false;
std::vector<std::string> parts = split(element,'[');
void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
{
//some prechecks
- if (element == "")
+ if (element.empty())
return;
std::vector<std::string> parts = split(element,'[');
parserData mydata;
//preserve tables
- for (u32 i = 0; i < m_tables.size(); ++i) {
- std::string tablename = m_tables[i].first.fname;
- GUITable *table = m_tables[i].second;
+ for (auto &m_table : m_tables) {
+ std::string tablename = m_table.first.fname;
+ GUITable *table = m_table.second;
mydata.table_dyndata[tablename] = table->getDynamicData();
}
if (focused_element && focused_element->getParent() == this) {
s32 focused_id = focused_element->getID();
if (focused_id > 257) {
- for (u32 i=0; i<m_fields.size(); i++) {
- if (m_fields[i].fid == focused_id) {
- mydata.focused_fieldname =
- m_fields[i].fname;
+ for (const GUIFormSpecMenu::FieldSpec &field : m_fields) {
+ if (field.fid == focused_id) {
+ mydata.focused_fieldname = field.fname;
break;
}
}
// Remove children
removeChildren();
- for (u32 i = 0; i < m_tables.size(); ++i) {
- GUITable *table = m_tables[i].second;
- table->drop();
+ for (auto &table_it : m_tables) {
+ table_it.second->drop();
}
mydata.size= v2s32(100,100);
unsigned int i = 0;
/* try to read version from first element only */
- if (elements.size() >= 1) {
+ if (!elements.empty()) {
if ( parseVersionDirect(elements[0]) ) {
i++;
}
// If there are fields without explicit size[], add a "Proceed"
// button and adjust size to fit all the fields.
- if (m_fields.size() && !mydata.explicit_size) {
+ if (!m_fields.empty() && !mydata.explicit_size) {
mydata.rect = core::rect<s32>(
mydata.screensize.X/2 - 580/2,
mydata.screensize.Y/2 - 300/2,
{
core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
- for(u32 i=0; i<m_inventorylists.size(); i++)
- {
- const ListDrawSpec &s = m_inventorylists[i];
-
+ for (const GUIFormSpecMenu::ListDrawSpec &s : m_inventorylists) {
for(s32 i=0; i<s.geom.X*s.geom.Y; i++) {
s32 item_i = i + s.start_item_i;
s32 x = (i%s.geom.X) * spacing.X;
}
// Draw tooltip
- std::wstring tooltip_text = L"";
+ std::wstring tooltip_text;
if (hovering && !m_selected_item) {
const std::string &desc = item.metadata.getString("description");
if (desc.empty())
/*
Draw backgrounds
*/
- for(u32 i=0; i<m_backgrounds.size(); i++)
- {
- const ImageDrawSpec &spec = m_backgrounds[i];
+ for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_backgrounds) {
video::ITexture *texture = m_tsrc->getTexture(spec.name);
if (texture != 0) {
/*
Draw Boxes
*/
- for(u32 i=0; i<m_boxes.size(); i++)
- {
- const BoxDrawSpec &spec = m_boxes[i];
-
+ for (const GUIFormSpecMenu::BoxDrawSpec &spec : m_boxes) {
irr::video::SColor todraw = spec.color;
todraw.setAlpha(140);
/*
Draw images
*/
- for(u32 i=0; i<m_images.size(); i++)
- {
- const ImageDrawSpec &spec = m_images[i];
+ for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_images) {
video::ITexture *texture = m_tsrc->getTexture(spec.name);
if (texture != 0) {
/*
Draw item images
*/
- for(u32 i=0; i<m_itemimages.size(); i++)
- {
+ for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_itemimages) {
if (m_client == 0)
break;
- const ImageDrawSpec &spec = m_itemimages[i];
IItemDefManager *idef = m_client->idef();
ItemStack item;
item.deSerialize(spec.item_name, idef);
bool item_hovered = false;
int start_phase = 0;
for (int phase = start_phase; phase <= 1; phase++) {
- for (u32 i = 0; i < m_inventorylists.size(); i++) {
- drawList(m_inventorylists[i], phase, item_hovered);
+ for (const GUIFormSpecMenu::ListDrawSpec &spec : m_inventorylists) {
+ drawList(spec, phase, item_hovered);
}
}
if (!item_hovered) {
/*
Draw static text elements
*/
- for (u32 i = 0; i < m_static_texts.size(); i++) {
- const StaticTextSpec &spec = m_static_texts[i];
+ for (const GUIFormSpecMenu::StaticTextSpec &spec : m_static_texts) {
core::rect<s32> rect = spec.rect;
if (spec.parent_button && spec.parent_button->isPressed()) {
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
// Find and update the current tooltip
if (id != -1 && delta >= m_tooltip_show_delay) {
- for (std::vector<FieldSpec>::iterator iter = m_fields.begin();
- iter != m_fields.end(); ++iter) {
+ for (const FieldSpec &field : m_fields) {
- if (iter->fid != id)
+ if (field.fid != id)
continue;
- const std::wstring &text = m_tooltips[iter->fname].tooltip;
+ const std::wstring &text = m_tooltips[field.fname].tooltip;
if (!text.empty())
- showTooltip(text, m_tooltips[iter->fname].color,
- m_tooltips[iter->fname].bgcolor);
+ showTooltip(text, m_tooltips[field.fname].color,
+ m_tooltips[field.fname].bgcolor);
break;
}
// WARNING: BLACK MAGIC
// See if there is a stack suited for our current guess.
// If such stack does not exist, clear the guess.
- if(m_selected_content_guess.name != "" &&
+ if (!m_selected_content_guess.name.empty() &&
selected.name == m_selected_content_guess.name &&
selected.count == m_selected_content_guess.count){
// Selected item fits the guess. Skip the black magic.
- }
- else if(m_selected_content_guess.name != ""){
+ } else if (!m_selected_content_guess.name.empty()) {
bool found = false;
for(u32 i=0; i<m_inventorylists.size() && !found; i++){
const ListDrawSpec &s = m_inventorylists[i];
// If craftresult is nonempty and nothing else is selected, select it now.
if(!m_selected_item)
{
- for(u32 i=0; i<m_inventorylists.size(); i++)
- {
- const ListDrawSpec &s = m_inventorylists[i];
+ for (const GUIFormSpecMenu::ListDrawSpec &s : m_inventorylists) {
if(s.listname == "craftpreview")
{
Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
current_keys_pending.key_escape = false;
}
- for(unsigned int i=0; i<m_fields.size(); i++) {
- const FieldSpec &s = m_fields[i];
+ for (const GUIFormSpecMenu::FieldSpec &s : m_fields) {
if(s.send) {
std::string name = s.fname;
if (s.ftype == f_Button) {
IGUIElement * element = getElementFromId(s.fid);
gui::IGUIComboBox *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
- e = static_cast<gui::IGUIComboBox*>(element);
+ e = dynamic_cast<gui::IGUIComboBox*>(element);
}
s32 selected = e->getSelected();
if (selected >= 0) {
IGUIElement * element = getElementFromId(s.fid);
gui::IGUITabControl *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
- e = static_cast<gui::IGUITabControl*>(element);
+ e = dynamic_cast<gui::IGUITabControl*>(element);
}
if (e != 0) {
IGUIElement * element = getElementFromId(s.fid);
gui::IGUICheckBox *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
- e = static_cast<gui::IGUICheckBox*>(element);
+ e = dynamic_cast<gui::IGUICheckBox*>(element);
}
if (e != 0) {
IGUIElement * element = getElementFromId(s.fid);
gui::IGUIScrollBar *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_SCROLL_BAR)) {
- e = static_cast<gui::IGUIScrollBar*>(element);
+ e = dynamic_cast<gui::IGUIScrollBar*>(element);
}
if (e != 0) {
((m_client != NULL) && (kp == getKeySetting("keymap_inventory"))))) {
tryClose();
return true;
- } else if (m_client != NULL && event.KeyInput.PressedDown &&
+ }
+
+ if (m_client != NULL && event.KeyInput.PressedDown &&
(kp == getKeySetting("keymap_screenshot"))) {
m_client->makeScreenshot();
}
if (event.GUIEvent.EventType == gui::EGET_TAB_CHANGED
&& isVisible()) {
// find the element that was clicked
- for (unsigned int i=0; i<m_fields.size(); i++) {
- FieldSpec &s = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
if ((s.ftype == f_TabHeader) &&
(s.fid == event.GUIEvent.Caller->getID())) {
s.send = true;
}
// find the element that was clicked
- for (u32 i = 0; i < m_fields.size(); i++) {
- FieldSpec &s = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
// if its a button, set the send field so
// lua knows which button was pressed
- if (((s.ftype == f_Button) || (s.ftype == f_CheckBox)) &&
- (s.fid == event.GUIEvent.Caller->getID())) {
+ if ((s.ftype == f_Button || s.ftype == f_CheckBox) &&
+ s.fid == event.GUIEvent.Caller->getID()) {
s.send = true;
if (s.is_exit) {
if (m_allowclose) {
m_text_dst->gotText(L"ExitButton");
}
return true;
- } else {
- acceptInput(quit_mode_no);
- s.send = false;
- return true;
}
+
+ acceptInput(quit_mode_no);
+ s.send = false;
+ return true;
+
} else if ((s.ftype == f_DropDown) &&
(s.fid == event.GUIEvent.Caller->getID())) {
// only send the changed dropdown
- for (u32 i = 0; i < m_fields.size(); i++) {
- FieldSpec &s2 = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s2 : m_fields) {
if (s2.ftype == f_DropDown) {
s2.send = false;
}
// revert configuration to make sure dropdowns are sent on
// regular button click
- for (u32 i = 0; i < m_fields.size(); i++) {
- FieldSpec &s2 = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s2 : m_fields) {
if (s2.ftype == f_DropDown) {
s2.send = true;
}
if (event.GUIEvent.EventType == gui::EGET_EDITBOX_ENTER) {
if (event.GUIEvent.Caller->getID() > 257) {
bool close_on_enter = true;
- for (u32 i = 0; i < m_fields.size(); i++) {
- FieldSpec &s = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
if (s.ftype == f_Unknown &&
s.fid == event.GUIEvent.Caller->getID()) {
current_field_enter_pending = s.fname;
int current_id = event.GUIEvent.Caller->getID();
if (current_id > 257) {
// find the element that was clicked
- for (u32 i = 0; i < m_fields.size(); i++) {
- FieldSpec &s = m_fields[i];
+ for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
// if it's a table, set the send field
// so lua knows which table was changed
if ((s.ftype == f_Table) && (s.fid == current_id)) {
*/
std::string GUIFormSpecMenu::getNameByID(s32 id)
{
- for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
- iter != m_fields.end(); ++iter) {
- if (iter->fid == id) {
- return iter->fname;
+ for (FieldSpec &spec : m_fields) {
+ if (spec.fid == id) {
+ return spec.fname;
}
}
return "";
*/
std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
{
- for(std::vector<FieldSpec>::iterator iter = m_fields.begin();
- iter != m_fields.end(); ++iter) {
- if (iter->fid == id) {
- return iter->flabel;
+ for (FieldSpec &spec : m_fields) {
+ if (spec.fid == id) {
+ return spec.flabel;
}
}
return L"";
struct TextDest
{
- virtual ~TextDest() {}
+ virtual ~TextDest() = default;
+
// This is deprecated I guess? -celeron55
virtual void gotText(const std::wstring &text) {}
virtual void gotText(const StringMap &fields) = 0;
class IFormSource
{
public:
- virtual ~IFormSource(){}
+ virtual ~IFormSource() = default;
virtual std::string getForm() = 0;
// Fill in variables in field text
virtual std::string resolveText(const std::string &str) { return str; }
{
struct ItemSpec
{
- ItemSpec() :
- i(-1)
- {
- }
+ ItemSpec() = default;
ItemSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
InventoryLocation inventoryloc;
std::string listname;
- s32 i;
+ s32 i = -1;
};
struct ListDrawSpec
{
- ListDrawSpec()
- {
- }
+ ListDrawSpec() = default;
+
ListDrawSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
struct ListRingSpec
{
- ListRingSpec()
- {
- }
+ ListRingSpec() = default;
+
ListRingSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname):
inventoryloc(a_inventoryloc),
struct FieldSpec
{
- FieldSpec()
- {
- }
+ FieldSpec() = default;
+
FieldSpec(const std::string &name, const std::wstring &label,
const std::wstring &default_text, int id) :
fname(name),
struct TooltipSpec
{
- TooltipSpec() {}
+ TooltipSpec() = default;
+
TooltipSpec(const std::string &a_tooltip, irr::video::SColor a_bgcolor,
irr::video::SColor a_color):
tooltip(utf8_to_wide(a_tooltip)),
{
}
- ~FormspecFormSource()
- {
- }
+ ~FormspecFormSource() = default;
void setForm(const std::string &formspec)
{
GUIModalMenu(env, parent, id, menumgr)
{
init_keys();
- for (size_t i = 0; i < key_settings.size(); i++)
- key_used.push_back(key_settings.at(i)->key);
+ for (key_setting *ks : key_settings)
+ key_used.push_back(ks->key);
}
GUIKeyChangeMenu::~GUIKeyChangeMenu()
{
removeChildren();
- for (std::vector<key_setting*>::iterator iter = key_settings.begin();
- iter != key_settings.end(); ++iter) {
- delete[] (*iter)->button_name;
- delete (*iter);
+ for (key_setting *ks : key_settings) {
+ delete[] ks->button_name;
+ delete ks;
}
key_settings.clear();
}
{
const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy;
- for (core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i
- != children.end(); i++)
- {
- children_copy.push_back(*i);
+ for (gui::IGUIElement*i : children) {
+ children_copy.push_back(i);
}
- for (core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i
- != children_copy.end(); i++)
- {
- (*i)->remove();
+
+ for (gui::IGUIElement *i : children_copy) {
+ i->remove();
}
}
bool GUIKeyChangeMenu::acceptInput()
{
- for(size_t i = 0; i < key_settings.size(); i++)
- {
- key_setting *k = key_settings.at(i);
+ for (key_setting *k : key_settings) {
g_settings->set(k->setting_name, k->key.sym());
}
+
{
gui::IGUIElement *e = getElementFromId(GUI_ID_CB_AUX1_DESCENDS);
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
{
if (activeKey >= 0)
{
- for(size_t i = 0; i < key_settings.size(); i++)
- {
- key_setting *k = key_settings.at(i);
- if(k->id == activeKey)
- {
+ for (key_setting *k : key_settings) {
+ if (k->id == activeKey) {
const wchar_t *text = wgettext(k->key.name());
k->button->setText(text);
delete[] text;
// But go on
{
key_setting *k = NULL;
- for(size_t i = 0; i < key_settings.size(); i++)
- {
- if(key_settings.at(i)->id == activeKey)
- {
- k = key_settings.at(i);
+ for (key_setting *ks : key_settings) {
+ if (ks->id == activeKey) {
+ k = ks;
break;
}
}
if(shift_went_down){
shift_down = true;
return false;
- }else{
- activeKey = -1;
- return true;
}
+
+ activeKey = -1;
+ return true;
}
} else if (event.EventType == EET_KEY_INPUT_EVENT && activeKey < 0
&& event.KeyInput.PressedDown
return true;
default:
key_setting *k = NULL;
- for(size_t i = 0; i < key_settings.size(); i++)
- {
- if(key_settings.at(i)->id == event.GUIEvent.Caller->getID())
- {
- k = key_settings.at(i);
+
+ for (key_setting *ks : key_settings) {
+ if (ks->id == event.GUIEvent.Caller->getID()) {
+ k = ks;
break;
}
}
{
const core::list<gui::IGUIElement *> &children = getChildren();
core::list<gui::IGUIElement *> children_copy;
- for (core::list<gui::IGUIElement *>::ConstIterator i = children.begin();
- i != children.end(); i++) {
- children_copy.push_back(*i);
+ for (gui::IGUIElement *i : children) {
+ children_copy.push_back(i);
}
- for (core::list<gui::IGUIElement *>::Iterator i = children_copy.begin();
- i != children_copy.end(); i++) {
- (*i)->remove();
+
+ for (gui::IGUIElement *i : children_copy) {
+ i->remove();
}
}
void GUIPasswordChange::regenerateGui(v2u32 screensize)
GUITable::~GUITable()
{
- for (size_t i = 0; i < m_rows.size(); ++i)
- delete[] m_rows[i].cells;
+ for (GUITable::Row &row : m_rows)
+ delete[] row.cells;
if (m_font)
m_font->drop();
size_t equal_pos = str.find('=');
if (equal_pos == std::string::npos)
return GUITable::Option(str, "");
- else
- return GUITable::Option(str.substr(0, equal_pos),
- str.substr(equal_pos + 1));
+
+ return GUITable::Option(str.substr(0, equal_pos),
+ str.substr(equal_pos + 1));
}
void GUITable::setTextList(const std::vector<std::string> &content,
// Handle table options
video::SColor default_color(255, 255, 255, 255);
s32 opendepth = 0;
- for (size_t k = 0; k < options.size(); ++k) {
- const std::string &name = options[k].name;
- const std::string &value = options[k].value;
+ for (const Option &option : options) {
+ const std::string &name = option.name;
+ const std::string &value = option.value;
if (name == "color")
parseColorString(value, m_color, false);
else if (name == "background")
// Append empty strings to content if there is an incomplete row
s32 cellcount = rowcount * colcount;
while (content.size() < (u32) cellcount)
- content.push_back("");
+ content.emplace_back("");
// Create temporary rows (for processing columns)
struct TempRow {
width = myround(em * 1.5); // default indent width
}
- for (size_t k = 0; k < columns[j].options.size(); ++k) {
- const std::string &name = columns[j].options[k].name;
- const std::string &value = columns[j].options[k].value;
+ for (const Option &option : columns[j].options) {
+ const std::string &name = option.name;
+ const std::string &value = option.value;
if (name == "padding")
padding = myround(stof(value) * em);
else if (name == "tooltip")
for (s32 i = 0; i < rowcount; ++i) {
video::SColor cellcolor(255, 255, 255, 255);
if (parseColorString(content[i * colcount + j], cellcolor, true))
- rows[i].colors.push_back(std::make_pair(cellcolor, j+span));
+ rows[i].colors.emplace_back(cellcolor, j+span);
}
}
else if (columntype == COLUMN_TYPE_INDENT ||
void GUITable::clear()
{
// Clean up cells and rows
- for (size_t i = 0; i < m_rows.size(); ++i)
- delete[] m_rows[i].cells;
+ for (GUITable::Row &row : m_rows)
+ delete[] row.cells;
m_rows.clear();
m_visible_rows.clear();
s32 rowcount = m_rows.size();
if (rowcount == 0 || index < 0) {
return;
- } else if (index >= rowcount) {
+ }
+
+ if (index >= rowcount) {
index = rowcount - 1;
}
return true;
}
- else if (event.KeyInput.PressedDown && (
+
+ if (event.KeyInput.PressedDown && (
event.KeyInput.Key == KEY_LEFT ||
event.KeyInput.Key == KEY_RIGHT)) {
// Open/close subtree via keyboard
if (it == m_alloc_strings.end()) {
s32 id = m_strings.size();
std::wstring wtext = utf8_to_wide(text);
- m_strings.push_back(core::stringw(wtext.c_str()));
+ m_strings.emplace_back(wtext.c_str());
m_alloc_strings.insert(std::make_pair(text, id));
return id;
}
- else {
- return it->second;
- }
+
+ return it->second;
}
s32 GUITable::allocImage(const std::string &imagename)
m_alloc_images.insert(std::make_pair(imagename, id));
return id;
}
- else {
- return it->second;
- }
+
+ return it->second;
}
void GUITable::allocationComplete()
{
if (i >= 0 && i < (s32) m_visible_rows.size())
return &m_rows[m_visible_rows[i]];
- else
- return NULL;
+
+ return NULL;
}
bool GUITable::doesRowStartWith(const Row *row, const core::stringw &str) const
really_hovering = true;
return i;
}
- else if (i < 0)
+ if (i < 0)
return 0;
- else
- return rowcount - 1;
+ return rowcount - 1;
}
s32 GUITable::getCellAt(s32 x, s32 row_i) const
if (rel_x >= cell->xmin && rel_x <= cell->xmax)
return pivot;
- else if (rel_x < cell->xmin)
+
+ if (rel_x < cell->xmin)
jmax = pivot - 1;
else
jmin = pivot + 1;
rel_x >= row->cells[jmin].xmin &&
rel_x <= row->cells[jmin].xmax)
return jmin;
- else
- return -1;
+
+ return -1;
}
void GUITable::autoScroll()
#include <sstream>
#include <list>
#include <map>
-#include <errno.h>
+#include <cerrno>
#include <mutex>
#include "threading/event.h"
#include "config.h"
std::list<CURL*> handles;
public:
- CurlHandlePool() {}
+ CurlHandlePool() = default;
+
~CurlHandlePool()
{
for (std::list<CURL*>::iterator it = handles.begin();
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
request.connect_timeout);
- if (request.useragent != "")
+ if (!request.useragent.empty())
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());
// Set up a write callback that writes to the
} else if (request.post_data.empty()) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string str;
- for (StringMap::iterator it = request.post_fields.begin();
- it != request.post_fields.end(); ++it) {
- if (str != "")
+ for (auto &post_field : request.post_fields) {
+ if (!str.empty())
str += "&";
- str += urlencode(it->first);
+ str += urlencode(post_field.first);
str += "=";
- str += urlencode(it->second);
+ str += urlencode(post_field.second);
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
str.size());
// modified until CURLOPT_POSTFIELDS is cleared
}
// Set additional HTTP headers
- for (std::vector<std::string>::iterator it = request.extra_headers.begin();
- it != request.extra_headers.end(); ++it) {
- http_header = curl_slist_append(http_header, it->c_str());
+ for (const std::string &extra_header : request.extra_headers) {
+ http_header = curl_slist_append(http_header, extra_header.c_str());
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header);
}
// Call curl_multi_remove_handle and cleanup easy handles
- for (size_t i = 0; i < m_all_ongoing.size(); ++i) {
- delete m_all_ongoing[i];
+ for (HTTPFetchOngoing *i : m_all_ongoing) {
+ delete i;
}
m_all_ongoing.clear();
struct ItemStack
{
- ItemStack() {}
+ ItemStack() = default;
+
ItemStack(const std::string &name_, u16 count_,
u16 wear, IItemDefManager *itemdef);
- ~ItemStack() {}
+ ~ItemStack() = default;
// Serialization
void serialize(std::ostream &os) const;
wear += amount;
return true;
}
- else
- {
- return false;
- }
+
+ return false;
}
// If possible, adds newitem to this item.
writeS16(os, stack_max);
writeU8(os, usable);
writeU8(os, liquids_pointable);
- std::string tool_capabilities_s = "";
+ std::string tool_capabilities_s;
if(tool_capabilities){
std::ostringstream tmp_os(std::ios::binary);
tool_capabilities->serialize(tmp_os, protocol_version);
}
os << serializeString(tool_capabilities_s);
writeU16(os, groups.size());
- for (ItemGroupList::const_iterator
- i = groups.begin(); i != groups.end(); ++i){
- os << serializeString(i->first);
- writeS16(os, i->second);
+ for (const auto &group : groups) {
+ os << serializeString(group.first);
+ writeS16(os, group.second);
}
os << serializeString(node_placement_prediction);
os << serializeString(sound_place.name);
ClientCached():
inventory_texture(NULL),
- wield_mesh(),
palette(NULL)
{}
};
{
#ifndef SERVER
const std::vector<ClientCached*> &values = m_clientcached.getValues();
- for(std::vector<ClientCached*>::const_iterator
- i = values.begin(); i != values.end(); ++i)
- {
- ClientCached *cc = *i;
+ for (ClientCached *cc : values) {
if (cc->wield_mesh.mesh)
cc->wield_mesh.mesh->drop();
delete cc;
}
#endif
- for (std::map<std::string, ItemDefinition*>::iterator iter =
- m_item_definitions.begin(); iter != m_item_definitions.end();
- ++iter) {
- delete iter->second;
+ for (auto &item_definition : m_item_definitions) {
+ delete item_definition.second;
}
m_item_definitions.clear();
}
virtual void getAll(std::set<std::string> &result) const
{
result.clear();
- for(std::map<std::string, ItemDefinition *>::const_iterator
- it = m_item_definitions.begin();
- it != m_item_definitions.end(); ++it) {
- result.insert(it->first);
+ for (const auto &item_definition : m_item_definitions) {
+ result.insert(item_definition.first);
}
- for (StringMap::const_iterator
- it = m_aliases.begin();
- it != m_aliases.end(); ++it) {
- result.insert(it->first);
+
+ for (const auto &alias : m_aliases) {
+ result.insert(alias.first);
}
}
virtual bool isKnown(const std::string &name_) const
// Create an inventory texture
cc->inventory_texture = NULL;
- if(def.inventory_image != "")
+ if (!def.inventory_image.empty())
cc->inventory_texture = tsrc->getTexture(def.inventory_image);
ItemStack item = ItemStack();
if (std::this_thread::get_id() == m_main_thread) {
return createClientCachedDirect(name, client);
- } else {
- // We're gonna ask the result to be put into here
- static ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
-
- // Throw a request in
- m_get_clientcached_queue.add(name, 0, 0, &result_queue);
- try{
- while(true) {
- // Wait result for a second
- GetResult<std::string, ClientCached*, u8, u8>
- result = result_queue.pop_front(1000);
-
- if (result.key == name) {
- return result.item;
- }
+ }
+
+ // We're gonna ask the result to be put into here
+ static ResultQueue<std::string, ClientCached*, u8, u8> result_queue;
+
+ // Throw a request in
+ m_get_clientcached_queue.add(name, 0, 0, &result_queue);
+ try {
+ while(true) {
+ // Wait result for a second
+ GetResult<std::string, ClientCached*, u8, u8>
+ result = result_queue.pop_front(1000);
+
+ if (result.key == name) {
+ return result.item;
}
}
- catch(ItemNotFoundException &e)
- {
- errorstream<<"Waiting for clientcached " << name << " timed out."<<std::endl;
- return &m_dummy_clientcached;
- }
+ } catch(ItemNotFoundException &e) {
+ errorstream << "Waiting for clientcached " << name
+ << " timed out." << std::endl;
+ return &m_dummy_clientcached;
}
}
// Get item inventory texture
// Look for direct color definition
const std::string &colorstring = stack.metadata.getString("color", 0);
video::SColor directcolor;
- if ((colorstring != "")
- && parseColorString(colorstring, directcolor, true))
+ if (!colorstring.empty() && parseColorString(colorstring, directcolor, true))
return directcolor;
// See if there is a palette
Palette *palette = getPalette(stack.name, client);
const std::string &index = stack.metadata.getString("palette_index", 0);
- if ((palette != NULL) && (index != ""))
+ if (palette && !index.empty())
return (*palette)[mystoi(index, 0, 255)];
// Fallback color
return get(stack.name).color;
{
verbosestream<<"ItemDefManager: registering \""<<def.name<<"\""<<std::endl;
// Ensure that the "" item (the hand) always has ToolCapabilities
- if(def.name == "")
+ if (def.name.empty())
FATAL_ERROR_IF(!def.tool_capabilities, "Hand does not have ToolCapabilities");
if(m_item_definitions.count(def.name) == 0)
// of a mapblock, because we must consider all view angles.
// sqrt(1^2 + 1^2 + 1^2) = 1.732
float endoff = -BS * MAP_BLOCKSIZE * 1.732050807569;
- v3s16 spn = cam_pos_nodes;
s16 bs2 = MAP_BLOCKSIZE / 2 + 1;
// to reduce the likelihood of falsely occluded blocks
// require at least two solid blocks
return (
// For the central point of the mapblock 'endoff' can be halved
- isOccluded(spn, cpn,
+ isOccluded(cam_pos_nodes, cpn,
step, stepfac, startoff, endoff / 2.0f, needed_count) &&
- isOccluded(spn, cpn + v3s16(bs2,bs2,bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(bs2,bs2,bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(bs2,bs2,-bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(bs2,bs2,-bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(bs2,-bs2,bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(bs2,-bs2,bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(bs2,-bs2,-bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(bs2,-bs2,-bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(-bs2,bs2,bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(-bs2,bs2,bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(-bs2,bs2,-bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(-bs2,bs2,-bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(-bs2,-bs2,bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(-bs2,-bs2,bs2),
step, stepfac, startoff, endoff, needed_count) &&
- isOccluded(spn, cpn + v3s16(-bs2,-bs2,-bs2),
+ isOccluded(cam_pos_nodes, cpn + v3s16(-bs2,-bs2,-bs2),
step, stepfac, startoff, endoff, needed_count));
}
scene::IMeshBuffer *buf = m_mesh[daynight_diff.first.first]->
getMeshBuffer(daynight_diff.first.second);
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
- for (auto j = daynight_diff.second.begin();
- j != daynight_diff.second.end(); ++j)
- {
- final_color_blend(&(vertices[j->first].Color),
- j->second, day_color);
+ for (const auto &j : daynight_diff.second) {
+ final_color_blend(&(vertices[j.first].Color), j.second, day_color);
}
}
m_last_daynight_ratio = daynight_ratio;
size_t DecoSimple::generate(MMVManip *vm, PcgRandom *pr, v3s16 p)
{
// Don't bother if there aren't any decorations to place
- if (c_decos.size() == 0)
+ if (c_decos.empty())
return 0;
if (!canPlaceDecoration(vm, p))
}
else if (type == NODEBOX_CONNECTED)
{
-#define READBOXES(box) do { \
+#define READBOXES(box) { \
count = readU16(is); \
(box).reserve(count); \
while (count--) { \
v3f min = readV3F1000(is); \
v3f max = readV3F1000(is); \
- (box).emplace_back(min, max); }; } while (0)
+ (box).emplace_back(min, max); }; }
u16 count;
std::string name = m_nodenames[m_nodenames_idx++];
bool success = m_ndef->getId(name, c);
- if (!success && node_alt != "") {
+ if (!success && !node_alt.empty()) {
name = node_alt;
success = m_ndef->getId(name, c);
}
updateVertices();
}
-Particle::~Particle()
-{
-}
-
void Particle::OnRegisterSceneNode()
{
if (IsVisible)
0, 0, 0, 0, m_color, tx0, ty0);
v3s16 camera_offset = m_env->getCameraOffset();
- for(u16 i=0; i<4; i++)
- {
+ for (video::S3DVertex &vertex : m_vertices) {
if (m_vertical) {
v3f ppos = m_player->getPosition()/BS;
- m_vertices[i].Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
+ vertex.Pos.rotateXZBy(atan2(ppos.Z-m_pos.Z, ppos.X-m_pos.X)/core::DEGTORAD+90);
} else {
- m_vertices[i].Pos.rotateYZBy(m_player->getPitch());
- m_vertices[i].Pos.rotateXZBy(m_player->getYaw());
+ vertex.Pos.rotateYZBy(m_player->getPitch());
+ vertex.Pos.rotateXZBy(m_player->getYaw());
}
- m_box.addInternalPoint(m_vertices[i].Pos);
- m_vertices[i].Pos += m_pos*BS - intToFloat(camera_offset, BS);
+ m_box.addInternalPoint(vertex.Pos);
+ vertex.Pos += m_pos*BS - intToFloat(camera_offset, BS);
}
}
}
}
-ParticleSpawner::~ParticleSpawner() {}
-
void ParticleSpawner::step(float dtime, ClientEnvironment* env)
{
m_time += dtime;
u8 glow,
video::SColor color = video::SColor(0xFFFFFFFF)
);
- ~Particle();
+ ~Particle() = default;
virtual const aabb3f &getBoundingBox() const
{
const struct TileAnimationParams &anim, u8 glow,
ParticleManager* p_manager);
- ~ParticleSpawner();
+ ~ParticleSpawner() = default;
void step(float dtime, ClientEnvironment *env);
Signal handler (grabs Ctrl-C on POSIX systems)
*/
-void signal_handler_init(void);
+void signal_handler_init();
// Returns a pointer to a bool.
// When the bool is true, program should quit.
-bool * signal_handler_killstatus(void);
+bool * signal_handler_killstatus();
/*
Path of static data directory.
bool secure_rand_fill_buf(void *buf, size_t len);
// This attaches to the parents process console, or creates a new one if it doesnt exist.
-void attachOrCreateConsole(void);
+void attachOrCreateConsole();
} // namespace porting
#ifdef __ANDROID__
const char *name = luaL_checkstring(L, 1);
const char *value = luaL_checkstring(L, 2);
- bool override_meta = lua_isboolean(L, 3) ? lua_toboolean(L, 3) : false;
+ bool override_meta = lua_isboolean(L, 3) && lua_toboolean(L, 3);
if (!settingsmgr->setMapSetting(name, value, override_meta)) {
errorstream << "set_mapgen_setting: cannot set '"
return 0;
}
- bool override_meta = lua_isboolean(L, 3) ? lua_toboolean(L, 3) : false;
+ bool override_meta = lua_isboolean(L, 3) && lua_toboolean(L, 3);
if (!settingsmgr->setMapSettingNoiseParams(name, &np, override_meta)) {
errorstream << "set_mapgen_setting_noiseparams: cannot set '"
return 0;
}
- bool set_default = lua_isboolean(L, 3) ? lua_toboolean(L, 3) : true;
+ bool set_default = !lua_isboolean(L, 3) || lua_toboolean(L, 3);
g_settings->setNoiseParams(name, np, set_default);
/*
Load shader programs
*/
-void load_shaders(std::string name, SourceShaderCache *sourcecache,
+void load_shaders(const std::string &name, SourceShaderCache *sourcecache,
video::E_DRIVER_TYPE drivertype, bool enable_shaders,
std::string &vertex_program, std::string &pixel_program,
std::string &geometry_program, bool &is_highlevel);
return shaderinfo;
}
-void load_shaders(std::string name, SourceShaderCache *sourcecache,
+void load_shaders(const std::string &name, SourceShaderCache *sourcecache,
video::E_DRIVER_TYPE drivertype, bool enable_shaders,
std::string &vertex_program, std::string &pixel_program,
std::string &geometry_program, bool &is_highlevel)
#include "socket.h"
-#include <stdio.h>
+#include <cstdio>
#include <iostream>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
#include <sstream>
#include <iomanip>
#include "util/string.h"
// Equality (address family, address and port must be equal)
bool Address::operator==(const Address &address)
{
- if(address.m_addr_family != m_addr_family || address.m_port != m_port)
+ if (address.m_addr_family != m_addr_family || address.m_port != m_port)
return false;
- else if(m_addr_family == AF_INET)
- {
+
+ if (m_addr_family == AF_INET) {
return m_address.ipv4.sin_addr.s_addr ==
address.m_address.ipv4.sin_addr.s_addr;
}
- else if(m_addr_family == AF_INET6)
- {
+
+ if (m_addr_family == AF_INET6) {
return memcmp(m_address.ipv6.sin6_addr.s6_addr,
address.m_address.ipv6.sin6_addr.s6_addr, 16) == 0;
}
- else
- return false;
+
+ return false;
}
bool Address::operator!=(const Address &address)
{
if (m_addr_family == AF_INET) {
return m_address.ipv4.sin_addr.s_addr == 0;
- } else if (m_addr_family == AF_INET6) {
+ }
+
+ if (m_addr_family == AF_INET6) {
static const char zero[16] = {0};
return memcmp(m_address.ipv6.sin6_addr.s6_addr,
zero, 16) == 0;
bool UDPSocket::init(bool ipv6, bool noExceptions)
{
- if (g_sockets_initialized == false) {
+ if (!g_sockets_initialized) {
dstream << "Sockets not initialized" << std::endl;
return false;
}
if (m_handle <= 0) {
if (noExceptions) {
return false;
- } else {
- throw SocketException(std::string("Failed to create socket: error ")
- + itos(LAST_SOCKET_ERR()));
}
+
+ throw SocketException(std::string("Failed to create socket: error ")
+ + itos(LAST_SOCKET_ERR()));
}
setTimeoutMs(0);
int UDPSocket::Receive(Address & sender, void *data, int size)
{
// Return on timeout
- if(WaitData(m_timeout_ms) == false)
+ if (!WaitData(m_timeout_ms))
return -1;
int received;
if (result == 0)
return false;
- else if (result < 0 && (errno == EINTR || errno == EBADF)) {
+
+ if (result < 0 && (errno == EINTR || errno == EBADF)) {
// N.B. select() fails when sockets are destroyed on Connection's dtor
// with EBADF. Instead of doing tricky synchronization, allow this
// thread to exit but don't throw an exception.
return false;
- } else if (result < 0) {
- dstream << (int) m_handle << ": Select failed: "
- << strerror(errno) << std::endl;
+ }
+
+ if (result < 0) {
+ dstream << m_handle << ": Select failed: " << strerror(errno) << std::endl;
#ifdef _WIN32
int e = WSAGetLastError();
#endif
throw SocketException("Select failed");
- } else if(FD_ISSET(m_handle, &readset) == false) {
+ } else if (!FD_ISSET(m_handle, &readset)) {
// No data
return false;
}
m_device = NULL;
for (auto &buffer : m_buffers) {
- for (std::vector<SoundBuffer*>::iterator iter = buffer.second.begin();
- iter != buffer.second.end(); ++iter) {
- delete *iter;
+ for (SoundBuffer *sb : buffer.second) {
+ delete sb;
}
buffer.second.clear();
}
}
return;
}
- else if (!def.inventory_image.empty()) {
+
+ if (!def.inventory_image.empty()) {
setExtruded(def.inventory_image, def.wield_scale, tsrc, 1);
m_colors.emplace_back();
return;