*/
void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> &destrect, const core::rect<s32> &srcrect,
- const core::rect<s32> *cliprect = 0, video::SColor *const colors = 0,
+ const core::rect<s32> *cliprect = 0, const video::SColor *const colors = 0,
bool usealpha = false);
unsigned long caller = HTTPFETCH_DISCARD;
unsigned long request_id = 0;
- HTTPFetchResult() {}
+ HTTPFetchResult() = default;
HTTPFetchResult(const HTTPFetchRequest &fetch_request)
: caller(fetch_request.caller), request_id(fetch_request.request_id)
m_hotbar_imagesize *= m_hud_scaling;
m_padding = m_hotbar_imagesize / 12;
- for (unsigned int i = 0; i < 4; i++)
- hbar_colors[i] = video::SColor(255, 255, 255, 255);
+ for (auto &hbar_color : hbar_colors)
+ hbar_color = video::SColor(255, 255, 255, 255);
tsrc = client->getTextureSource();
// Store hotbar_image in member variable, used by drawItem()
if (hotbar_image != player->hotbar_image) {
hotbar_image = player->hotbar_image;
- if (hotbar_image != "")
+ if (!hotbar_image.empty())
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
else
use_hotbar_image = false;
// Store hotbar_selected_image in member variable, used by drawItem()
if (hotbar_selected_image != player->hotbar_selected_image) {
hotbar_selected_image = player->hotbar_selected_image;
- if (hotbar_selected_image != "")
+ if (!hotbar_selected_image.empty())
use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
else
use_hotbar_selected_image = false;
m_selection_mesh = NULL;
}
- if (!m_selection_boxes.size()) {
+ if (m_selection_boxes.empty()) {
// No pointed object
return;
}
aabb3f halo_box(100.0, 100.0, 100.0, -100.0, -100.0, -100.0);
m_halo_boxes.clear();
- for (std::vector<aabb3f>::iterator
- i = m_selection_boxes.begin();
- i != m_selection_boxes.end(); ++i) {
- halo_box.addInternalBox(*i);
+ for (const auto &selection_box : m_selection_boxes) {
+ halo_box.addInternalBox(selection_box);
}
m_halo_boxes.push_back(halo_box);
#include "imagefilters.h"
#include "util/numeric.h"
-#include <math.h>
+#include <cmath>
/* Fill in RGB values for transparent pixels, to correct for odd colors
* appearing at borders when blending. This is because many PNG optimizers
if ( !this->IsEnabled )
break;
- if (Text.size())
- {
+ if (!Text.empty()) {
core::stringw s;
if (MarkBegin != MarkEnd)
if ( !this->IsEnabled )
break;
- if (Text.size() != 0)
- {
+ if (!Text.empty()) {
core::stringw s;
if (MarkBegin != MarkEnd)
const bool prevOver = OverrideColorEnabled;
const video::SColor prevColor = OverrideColor;
- if (Text.size())
- {
+ if (!Text.empty()) {
if (!IsEnabled && !OverrideColorEnabled)
{
OverrideColorEnabled = true;
// draw marked text
s = txtLine->subString(lineStartPos, lineEndPos - lineStartPos);
- if (s.size())
+ if (!s.empty())
font->draw(s.c_str(), CurrentTextRect,
OverrideColorEnabled ? OverrideColor : skin->getColor(EGDC_HIGH_LIGHT_TEXT),
false, true, &localClipRect);
else
{
if (!AbsoluteClippingRect.isPointInside(
- core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y)))
- {
+ core::position2d<s32>(event.MouseInput.X, event.MouseInput.Y))) {
return false;
}
- else
- {
- // move cursor
- CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
- s32 newMarkBegin = MarkBegin;
- if (!MouseMarking)
- newMarkBegin = CursorPos;
- MouseMarking = true;
- setTextMarkers( newMarkBegin, CursorPos);
- calculateScrollPos();
- return true;
- }
+ // move cursor
+ CursorPos = getCursorPos(event.MouseInput.X, event.MouseInput.Y);
+
+ s32 newMarkBegin = MarkBegin;
+ if (!MouseMarking)
+ newMarkBegin = CursorPos;
+
+ MouseMarking = true;
+ setTextMarkers( newMarkBegin, CursorPos);
+ calculateScrollPos();
+ return true;
}
default:
break;
if (c == L' ' || c == 0 || i == (size-1))
{
- if (word.size())
- {
+ if (!word.empty()) {
// here comes the next whitespace, look if
// we can break the last word to the next line.
s32 whitelgth = font->getDimension(whitespace.c_str()).Width;
setAutoScroll(in->getAttributeAsBool("AutoScroll"));
core::stringw ch = in->getAttributeAsStringW("PasswordChar");
- if (!ch.size())
+ if (ch.empty())
setPasswordBox(in->getAttributeAsBool("PasswordBox"));
else
setPasswordBox(in->getAttributeAsBool("PasswordBox"), ch[0]);
static content_t content_translate_from_19_to_internal(content_t c_from)
{
- for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
- {
- if(trans_table_19[i][1] == c_from)
- {
- return trans_table_19[i][0];
+ for (const auto &tt : trans_table_19) {
+ if(tt[1] == c_from) {
+ return tt[0];
}
}
return c_from;
NameIdMapping legacy_nimap;
content_mapnode_get_name_id_mapping(&legacy_nimap);
legacy_nimap.getName(material, name);
- if(name == "")
+ if(name.empty())
name = "unknown_block";
if (itemdef)
name = itemdef->getAlias(name);
NameIdMapping legacy_nimap;
content_mapnode_get_name_id_mapping(&legacy_nimap);
legacy_nimap.getName(material, name);
- if(name == "")
+ if(name.empty())
name = "unknown_block";
if (itemdef)
name = itemdef->getAlias(name);
// Read the count
std::string count_str;
std::getline(is, count_str, ' ');
- if(count_str.empty())
- {
+ if (count_str.empty()) {
count = 1;
break;
}
- else
- count = stoi(count_str);
+
+ count = stoi(count_str);
// Read the wear
std::string wear_str;
std::getline(is, wear_str, ' ');
if(wear_str.empty())
break;
- else
- wear = stoi(wear_str);
+
+ wear = stoi(wear_str);
// Read metadata
metadata.deSerialize(is);
clearItems();
}
-InventoryList::~InventoryList()
-{
-}
-
void InventoryList::clearItems()
{
m_items.clear();
- for(u32 i=0; i<m_size; i++)
- {
- m_items.push_back(ItemStack());
+ for (u32 i=0; i < m_size; i++) {
+ m_items.emplace_back();
}
//setDirty(true);
os<<"Width "<<m_width<<"\n";
- for(u32 i=0; i<m_items.size(); i++)
- {
- const ItemStack &item = m_items[i];
- if(item.empty())
- {
+ for (const auto &item : m_items) {
+ if (item.empty()) {
os<<"Empty";
- }
- else
- {
+ } else {
os<<"Item ";
item.serialize(os);
}
std::string name;
std::getline(iss, name, ' ');
- if(name == "EndInventoryList")
- {
+ if (name == "EndInventoryList") {
break;
}
+
// This is a temporary backwards compatibility fix
- else if(name == "end")
- {
+ if (name == "end") {
break;
}
- else if(name == "Width")
- {
+
+ if (name == "Width") {
iss >> m_width;
if (iss.fail())
throw SerializationError("incorrect width property");
u32 InventoryList::getUsedSlots() const
{
u32 num = 0;
- for(u32 i=0; i<m_items.size(); i++)
- {
- if(!m_items[i].empty())
+ for (const auto &m_item : m_items) {
+ if (!m_item.empty())
num++;
}
return num;
bool InventoryList::containsItem(const ItemStack &item, bool match_meta) const
{
u32 count = item.count;
- if(count == 0)
+ if (count == 0)
return true;
- for(std::vector<ItemStack>::const_reverse_iterator
- i = m_items.rbegin();
- i != m_items.rend(); ++i)
- {
- if(count == 0)
+
+ for (auto i = m_items.rbegin(); i != m_items.rend(); ++i) {
+ if (count == 0)
break;
- if (i->name == item.name
- && (!match_meta || (i->metadata == item.metadata))) {
+ if (i->name == item.name && (!match_meta || (i->metadata == item.metadata))) {
if (i->count >= count)
return true;
- else
- count -= i->count;
+
+ count -= i->count;
}
}
return false;
ItemStack InventoryList::removeItem(const ItemStack &item)
{
ItemStack removed;
- for(std::vector<ItemStack>::reverse_iterator
- i = m_items.rbegin();
- i != m_items.rend(); ++i)
- {
- if(i->name == item.name)
- {
+ for (auto i = m_items.rbegin(); i != m_items.rend(); ++i) {
+ if (i->name == item.name) {
u32 still_to_remove = item.count - removed.count;
removed.addItem(i->takeItem(still_to_remove), m_itemdef);
- if(removed.count == item.count)
+ if (removed.count == item.count)
break;
}
}
void Inventory::clear()
{
m_dirty = true;
- for(u32 i=0; i<m_lists.size(); i++)
- {
- delete m_lists[i];
+ for (auto &m_list : m_lists) {
+ delete m_list;
}
m_lists.clear();
}
void Inventory::clearContents()
{
m_dirty = true;
- for(u32 i=0; i<m_lists.size(); i++)
- {
- InventoryList *list = m_lists[i];
- for(u32 j=0; j<list->getSize(); j++)
- {
+ for (InventoryList *list : m_lists) {
+ for (u32 j=0; j<list->getSize(); j++) {
list->deleteItem(j);
}
}
m_dirty = true;
clear();
m_itemdef = other.m_itemdef;
- for(u32 i=0; i<other.m_lists.size(); i++)
- {
- m_lists.push_back(new InventoryList(*other.m_lists[i]));
+ for (InventoryList *list : other.m_lists) {
+ m_lists.push_back(new InventoryList(*list));
}
}
return *this;
void Inventory::serialize(std::ostream &os) const
{
- for(u32 i=0; i<m_lists.size(); i++)
- {
- InventoryList *list = m_lists[i];
+ for (InventoryList *list : m_lists) {
os<<"List "<<list->getName()<<" "<<list->getSize()<<"\n";
list->serialize(os);
}
std::string name;
std::getline(iss, name, ' ');
- if(name == "EndInventory")
- {
+ if (name == "EndInventory") {
break;
}
+
// This is a temporary backwards compatibility fix
- else if(name == "end")
- {
+ if (name == "end") {
break;
}
- else if(name == "List")
- {
+
+ if (name == "List") {
std::string listname;
u32 listsize;
}
return m_lists[i];
}
- else
- {
- //don't create list with invalid name
- if (name.find(" ") != std::string::npos) return NULL;
- InventoryList *list = new InventoryList(name, size, m_itemdef);
- m_lists.push_back(list);
- return list;
- }
+
+ //don't create list with invalid name
+ if (name.find(' ') != std::string::npos) return NULL;
+
+ InventoryList *list = new InventoryList(name, size, m_itemdef);
+ m_lists.push_back(list);
+ return list;
}
InventoryList * Inventory::getList(const std::string &name)
std::vector<const InventoryList*> Inventory::getLists()
{
std::vector<const InventoryList*> lists;
- for(u32 i=0; i<m_lists.size(); i++)
- {
- InventoryList *list = m_lists[i];
+ for (auto list : m_lists) {
lists.push_back(list);
}
return lists;
{
public:
InventoryList(const std::string &name, u32 size, IItemDefManager *itemdef);
- ~InventoryList();
+ ~InventoryList() = default;
void clearItems();
void setSize(u32 newsize);
void setWidth(u32 newWidth);
// Add the new replacements to the list
IItemDefManager *itemdef = gamedef->getItemDefManager();
- for (std::vector<ItemStack>::iterator it = temp.begin();
- it != temp.end(); ++it) {
- for (std::vector<ItemStack>::iterator jt = output_replacements.begin();
- jt != output_replacements.end(); ++jt) {
- if (it->name == jt->name) {
- *it = jt->addItem(*it, itemdef);
- if (it->empty())
+ for (auto &itemstack : temp) {
+ for (auto &output_replacement : output_replacements) {
+ if (itemstack.name == output_replacement.name) {
+ itemstack = output_replacement.addItem(itemstack, itemdef);
+ if (itemstack.empty())
continue;
}
}
- output_replacements.push_back(*it);
+ output_replacements.push_back(itemstack);
}
actionstream << player->getDescription()
// Decrement counter
if (count_remaining == 1)
break;
- else if (count_remaining > 1)
+
+ if (count_remaining > 1)
count_remaining--;
// Get next crafting result
// Put the replacements in the inventory or drop them on the floor, if
// the invenotry is full
- for (std::vector<ItemStack>::iterator it = output_replacements.begin();
- it != output_replacements.end(); ++it) {
+ for (auto &output_replacement : output_replacements) {
if (list_main)
- *it = list_main->addItem(*it);
- if (it->empty())
+ output_replacement = list_main->addItem(output_replacement);
+ if (output_replacement.empty())
continue;
- u16 count = it->count;
+ u16 count = output_replacement.count;
do {
- PLAYER_TO_SA(player)->item_OnDrop(*it, player,
+ PLAYER_TO_SA(player)->item_OnDrop(output_replacement, player,
player->getBasePosition());
- if (count >= it->count) {
+ if (count >= output_replacement.count) {
errorstream << "Couldn't drop replacement stack " <<
- it->getItemString() << " because drop loop didn't "
+ output_replacement.getItemString() << " because drop loop didn't "
"decrease count." << std::endl;
break;
}
- } while (!it->empty());
+ } while (!output_replacement.empty());
}
infostream<<"ICraftAction::apply(): crafted "
type = PLAYER;
name = name_;
}
- void setNodeMeta(v3s16 p_)
+ void setNodeMeta(const v3s16 &p_)
{
type = NODEMETA;
p = p_;
class InventoryManager
{
public:
- InventoryManager(){}
- virtual ~InventoryManager(){}
+ InventoryManager() = default;
+ virtual ~InventoryManager() = default;
// Get an inventory (server and client)
virtual Inventory* getInventory(const InventoryLocation &loc){return NULL;}
virtual void apply(InventoryManager *mgr, ServerActiveObject *player,
IGameDef *gamedef) = 0;
virtual void clientApply(InventoryManager *mgr, IGameDef *gamedef) = 0;
- virtual ~InventoryAction() {};
+ virtual ~InventoryAction() = default;;
};
struct IMoveAction : public InventoryAction
bool caused_by_move_somewhere = false;
u32 move_count = 0;
- IMoveAction() {}
+ IMoveAction() = default;
IMoveAction(std::istream &is, bool somewhere);
std::string from_list;
s16 from_i = -1;
- IDropAction() {}
+ IDropAction() = default;
IDropAction(std::istream &is);
u16 count = 0;
InventoryLocation craft_inv;
- ICraftAction() {}
+ ICraftAction() = default;
ICraftAction(std::istream &is);
{
std::ostringstream os2;
os2 << DESERIALIZE_START;
- for (StringMap::const_iterator
- it = m_stringvars.begin();
- it != m_stringvars.end(); ++it) {
- os2 << it->first << DESERIALIZE_KV_DELIM
- << it->second << DESERIALIZE_PAIR_DELIM;
+ for (const auto &stringvar : m_stringvars) {
+ os2 << stringvar.first << DESERIALIZE_KV_DELIM
+ << stringvar.second << DESERIALIZE_PAIR_DELIM;
}
os << serializeJsonStringIfNeeded(os2.str());
}