mirror of
https://github.com/minetest/minetest.git
synced 2024-11-14 14:30:31 +01:00
Reserve vectors before pushing and other code quality changes (#11161)
This commit is contained in:
parent
3e1904fa8c
commit
f0bad0e2ba
|
@ -499,12 +499,12 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
|
|||
static v3f z_directions[50] = {
|
||||
v3f(-100, 0, 0)
|
||||
};
|
||||
static f32 z_offsets[sizeof(z_directions)/sizeof(*z_directions)] = {
|
||||
static f32 z_offsets[50] = {
|
||||
-1000,
|
||||
};
|
||||
|
||||
if(z_directions[0].X < -99){
|
||||
for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
|
||||
if (z_directions[0].X < -99) {
|
||||
for (u32 i = 0; i < ARRLEN(z_directions); i++) {
|
||||
// Assumes FOV of 72 and 16/9 aspect ratio
|
||||
z_directions[i] = v3f(
|
||||
0.02 * myrand_range(-100, 100),
|
||||
|
@ -520,7 +520,8 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
|
|||
if(sunlight_min_d > 35*BS)
|
||||
sunlight_min_d = 35*BS;
|
||||
std::vector<int> values;
|
||||
for(u32 i=0; i<sizeof(z_directions)/sizeof(*z_directions); i++){
|
||||
values.reserve(ARRLEN(z_directions));
|
||||
for (u32 i = 0; i < ARRLEN(z_directions); i++) {
|
||||
v3f z_dir = z_directions[i];
|
||||
core::CMatrix4<f32> a;
|
||||
a.buildRotateFromTo(v3f(0,1,0), z_dir);
|
||||
|
|
|
@ -170,7 +170,7 @@ void Clouds::render()
|
|||
|
||||
// Read noise
|
||||
|
||||
std::vector<char> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2); // vector<bool> is broken
|
||||
std::vector<bool> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2);
|
||||
std::vector<video::S3DVertex> vertices;
|
||||
vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i);
|
||||
|
||||
|
|
|
@ -336,22 +336,22 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
||||
|
||||
// Reorder elements by z_index
|
||||
std::vector<size_t> ids;
|
||||
std::vector<HudElement*> elems;
|
||||
elems.reserve(player->maxHudId());
|
||||
|
||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||
HudElement *e = player->getHud(i);
|
||||
if (!e)
|
||||
continue;
|
||||
|
||||
auto it = ids.begin();
|
||||
while (it != ids.end() && player->getHud(*it)->z_index <= e->z_index)
|
||||
auto it = elems.begin();
|
||||
while (it != elems.end() && (*it)->z_index <= e->z_index)
|
||||
++it;
|
||||
|
||||
ids.insert(it, i);
|
||||
elems.insert(it, e);
|
||||
}
|
||||
|
||||
for (size_t i : ids) {
|
||||
HudElement *e = player->getHud(i);
|
||||
for (HudElement *e : elems) {
|
||||
|
||||
v2s32 pos(floor(e->pos.X * (float) m_screensize.X + 0.5),
|
||||
floor(e->pos.Y * (float) m_screensize.Y + 0.5));
|
||||
|
@ -522,8 +522,8 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
|
|||
client->getMinimap()->drawMinimap(rect);
|
||||
break; }
|
||||
default:
|
||||
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
|
||||
" of hud element ID " << i << " due to unrecognized type" << std::endl;
|
||||
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type
|
||||
<< " due to unrecognized type" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,13 +82,13 @@ Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) :
|
|||
// Ensures that sun and moon textures and tonemaps are correct.
|
||||
setSkyDefaults();
|
||||
m_sun_texture = tsrc->isKnownSourceImage(m_sun_params.texture) ?
|
||||
tsrc->getTextureForMesh(m_sun_params.texture) : NULL;
|
||||
tsrc->getTextureForMesh(m_sun_params.texture) : nullptr;
|
||||
m_moon_texture = tsrc->isKnownSourceImage(m_moon_params.texture) ?
|
||||
tsrc->getTextureForMesh(m_moon_params.texture) : NULL;
|
||||
tsrc->getTextureForMesh(m_moon_params.texture) : nullptr;
|
||||
m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) ?
|
||||
tsrc->getTexture(m_sun_params.tonemap) : NULL;
|
||||
tsrc->getTexture(m_sun_params.tonemap) : nullptr;
|
||||
m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ?
|
||||
tsrc->getTexture(m_moon_params.tonemap) : NULL;
|
||||
tsrc->getTexture(m_moon_params.tonemap) : nullptr;
|
||||
|
||||
if (m_sun_texture) {
|
||||
m_materials[3] = baseMaterial();
|
||||
|
@ -744,14 +744,14 @@ void Sky::place_sky_body(
|
|||
}
|
||||
}
|
||||
|
||||
void Sky::setSunTexture(std::string sun_texture,
|
||||
std::string sun_tonemap, ITextureSource *tsrc)
|
||||
void Sky::setSunTexture(const std::string &sun_texture,
|
||||
const std::string &sun_tonemap, ITextureSource *tsrc)
|
||||
{
|
||||
// Ignore matching textures (with modifiers) entirely,
|
||||
// but lets at least update the tonemap before hand.
|
||||
m_sun_params.tonemap = sun_tonemap;
|
||||
m_sun_tonemap = tsrc->isKnownSourceImage(m_sun_params.tonemap) ?
|
||||
tsrc->getTexture(m_sun_params.tonemap) : NULL;
|
||||
tsrc->getTexture(m_sun_params.tonemap) : nullptr;
|
||||
m_materials[3].Lighting = !!m_sun_tonemap;
|
||||
|
||||
if (m_sun_params.texture == sun_texture)
|
||||
|
@ -780,7 +780,7 @@ void Sky::setSunTexture(std::string sun_texture,
|
|||
}
|
||||
}
|
||||
|
||||
void Sky::setSunriseTexture(std::string sunglow_texture,
|
||||
void Sky::setSunriseTexture(const std::string &sunglow_texture,
|
||||
ITextureSource* tsrc)
|
||||
{
|
||||
// Ignore matching textures (with modifiers) entirely.
|
||||
|
@ -792,14 +792,14 @@ void Sky::setSunriseTexture(std::string sunglow_texture,
|
|||
);
|
||||
}
|
||||
|
||||
void Sky::setMoonTexture(std::string moon_texture,
|
||||
std::string moon_tonemap, ITextureSource *tsrc)
|
||||
void Sky::setMoonTexture(const std::string &moon_texture,
|
||||
const std::string &moon_tonemap, ITextureSource *tsrc)
|
||||
{
|
||||
// Ignore matching textures (with modifiers) entirely,
|
||||
// but lets at least update the tonemap before hand.
|
||||
m_moon_params.tonemap = moon_tonemap;
|
||||
m_moon_tonemap = tsrc->isKnownSourceImage(m_moon_params.tonemap) ?
|
||||
tsrc->getTexture(m_moon_params.tonemap) : NULL;
|
||||
tsrc->getTexture(m_moon_params.tonemap) : nullptr;
|
||||
m_materials[4].Lighting = !!m_moon_tonemap;
|
||||
|
||||
if (m_moon_params.texture == moon_texture)
|
||||
|
@ -893,7 +893,7 @@ void Sky::setSkyColors(const SkyColor &sky_color)
|
|||
}
|
||||
|
||||
void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
|
||||
std::string use_sun_tint)
|
||||
const std::string &use_sun_tint)
|
||||
{
|
||||
// Change sun and moon tinting:
|
||||
m_sky_params.fog_sun_tint = sun_tint;
|
||||
|
@ -907,7 +907,7 @@ void Sky::setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
|
|||
m_default_tint = true;
|
||||
}
|
||||
|
||||
void Sky::addTextureToSkybox(std::string texture, int material_id,
|
||||
void Sky::addTextureToSkybox(const std::string &texture, int material_id,
|
||||
ITextureSource *tsrc)
|
||||
{
|
||||
// Sanity check for more than six textures.
|
||||
|
|
|
@ -65,15 +65,15 @@ public:
|
|||
}
|
||||
|
||||
void setSunVisible(bool sun_visible) { m_sun_params.visible = sun_visible; }
|
||||
void setSunTexture(std::string sun_texture,
|
||||
std::string sun_tonemap, ITextureSource *tsrc);
|
||||
void setSunTexture(const std::string &sun_texture,
|
||||
const std::string &sun_tonemap, ITextureSource *tsrc);
|
||||
void setSunScale(f32 sun_scale) { m_sun_params.scale = sun_scale; }
|
||||
void setSunriseVisible(bool glow_visible) { m_sun_params.sunrise_visible = glow_visible; }
|
||||
void setSunriseTexture(std::string sunglow_texture, ITextureSource* tsrc);
|
||||
void setSunriseTexture(const std::string &sunglow_texture, ITextureSource* tsrc);
|
||||
|
||||
void setMoonVisible(bool moon_visible) { m_moon_params.visible = moon_visible; }
|
||||
void setMoonTexture(std::string moon_texture,
|
||||
std::string moon_tonemap, ITextureSource *tsrc);
|
||||
void setMoonTexture(const std::string &moon_texture,
|
||||
const std::string &moon_tonemap, ITextureSource *tsrc);
|
||||
void setMoonScale(f32 moon_scale) { m_moon_params.scale = moon_scale; }
|
||||
|
||||
void setStarsVisible(bool stars_visible) { m_star_params.visible = stars_visible; }
|
||||
|
@ -87,21 +87,21 @@ public:
|
|||
void setVisible(bool visible) { m_visible = visible; }
|
||||
// Set only from set_sky API
|
||||
void setCloudsEnabled(bool clouds_enabled) { m_clouds_enabled = clouds_enabled; }
|
||||
void setFallbackBgColor(const video::SColor &fallback_bg_color)
|
||||
void setFallbackBgColor(video::SColor fallback_bg_color)
|
||||
{
|
||||
m_fallback_bg_color = fallback_bg_color;
|
||||
}
|
||||
void overrideColors(const video::SColor &bgcolor, const video::SColor &skycolor)
|
||||
void overrideColors(video::SColor bgcolor, video::SColor skycolor)
|
||||
{
|
||||
m_bgcolor = bgcolor;
|
||||
m_skycolor = skycolor;
|
||||
}
|
||||
void setSkyColors(const SkyColor &sky_color);
|
||||
void setHorizonTint(video::SColor sun_tint, video::SColor moon_tint,
|
||||
std::string use_sun_tint);
|
||||
const std::string &use_sun_tint);
|
||||
void setInClouds(bool clouds) { m_in_clouds = clouds; }
|
||||
void clearSkyboxTextures() { m_sky_params.textures.clear(); }
|
||||
void addTextureToSkybox(std::string texture, int material_id,
|
||||
void addTextureToSkybox(const std::string &texture, int material_id,
|
||||
ITextureSource *tsrc);
|
||||
const video::SColorf &getCurrentStarColor() const { return m_star_color; }
|
||||
|
||||
|
@ -126,7 +126,7 @@ private:
|
|||
}
|
||||
|
||||
// Mix two colors by a given amount
|
||||
video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
|
||||
static video::SColor m_mix_scolor(video::SColor col1, video::SColor col2, f32 factor)
|
||||
{
|
||||
video::SColor result = video::SColor(
|
||||
col1.getAlpha() * (1 - factor) + col2.getAlpha() * factor,
|
||||
|
@ -135,7 +135,7 @@ private:
|
|||
col1.getBlue() * (1 - factor) + col2.getBlue() * factor);
|
||||
return result;
|
||||
}
|
||||
video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
|
||||
static video::SColorf m_mix_scolorf(video::SColorf col1, video::SColorf col2, f32 factor)
|
||||
{
|
||||
video::SColorf result =
|
||||
video::SColorf(col1.r * (1 - factor) + col2.r * factor,
|
||||
|
|
|
@ -671,7 +671,6 @@ void ClientInterface::UpdatePlayerList()
|
|||
std::vector<session_t> clients = getClientIDs();
|
||||
m_clients_names.clear();
|
||||
|
||||
|
||||
if (!clients.empty())
|
||||
infostream<<"Players:"<<std::endl;
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ using namespace gui;
|
|||
|
||||
GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment,
|
||||
gui::IGUIElement *parent, s32 id, core::rect<s32> rectangle,
|
||||
ISimpleTextureSource *tsrc, std::string item, Client *client,
|
||||
ISimpleTextureSource *tsrc, const std::string &item, Client *client,
|
||||
bool noclip)
|
||||
: GUIButton (environment, parent, id, rectangle, tsrc, noclip)
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ GUIButtonItemImage::GUIButtonItemImage(gui::IGUIEnvironment *environment,
|
|||
|
||||
GUIButtonItemImage *GUIButtonItemImage::addButton(IGUIEnvironment *environment,
|
||||
const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
|
||||
IGUIElement *parent, s32 id, const wchar_t *text, std::string item,
|
||||
IGUIElement *parent, s32 id, const wchar_t *text, const std::string &item,
|
||||
Client *client)
|
||||
{
|
||||
GUIButtonItemImage *button = new GUIButtonItemImage(environment,
|
||||
|
|
|
@ -33,13 +33,13 @@ public:
|
|||
//! constructor
|
||||
GUIButtonItemImage(gui::IGUIEnvironment *environment, gui::IGUIElement *parent,
|
||||
s32 id, core::rect<s32> rectangle, ISimpleTextureSource *tsrc,
|
||||
std::string item, Client *client, bool noclip = false);
|
||||
const std::string &item, Client *client, bool noclip = false);
|
||||
|
||||
//! Do not drop returned handle
|
||||
static GUIButtonItemImage *addButton(gui::IGUIEnvironment *environment,
|
||||
const core::rect<s32> &rectangle, ISimpleTextureSource *tsrc,
|
||||
IGUIElement *parent, s32 id, const wchar_t *text, std::string item,
|
||||
Client *client);
|
||||
IGUIElement *parent, s32 id, const wchar_t *text,
|
||||
const std::string &item, Client *client);
|
||||
|
||||
private:
|
||||
Client *m_client;
|
||||
|
|
|
@ -965,13 +965,14 @@ InventoryList * Inventory::getList(const std::string &name)
|
|||
{
|
||||
s32 i = getListIndex(name);
|
||||
if(i == -1)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return m_lists[i];
|
||||
}
|
||||
|
||||
std::vector<const InventoryList*> Inventory::getLists()
|
||||
{
|
||||
std::vector<const InventoryList*> lists;
|
||||
lists.reserve(m_lists.size());
|
||||
for (auto list : m_lists) {
|
||||
lists.push_back(list);
|
||||
}
|
||||
|
@ -990,11 +991,11 @@ bool Inventory::deleteList(const std::string &name)
|
|||
return true;
|
||||
}
|
||||
|
||||
const InventoryList * Inventory::getList(const std::string &name) const
|
||||
const InventoryList *Inventory::getList(const std::string &name) const
|
||||
{
|
||||
s32 i = getListIndex(name);
|
||||
if(i == -1)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return m_lists[i];
|
||||
}
|
||||
|
||||
|
|
|
@ -1544,10 +1544,10 @@ void NodeDefManager::deSerialize(std::istream &is)
|
|||
}
|
||||
|
||||
|
||||
void NodeDefManager::addNameIdMapping(content_t i, std::string name)
|
||||
void NodeDefManager::addNameIdMapping(content_t i, const std::string &name)
|
||||
{
|
||||
m_name_id_mapping.set(i, name);
|
||||
m_name_id_mapping_with_aliases.insert(std::make_pair(name, i));
|
||||
m_name_id_mapping_with_aliases.emplace(name, i);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -725,7 +725,7 @@ private:
|
|||
* @param i a content ID
|
||||
* @param name a node name
|
||||
*/
|
||||
void addNameIdMapping(content_t i, std::string name);
|
||||
void addNameIdMapping(content_t i, const std::string &name);
|
||||
|
||||
/*!
|
||||
* Removes a content ID from all groups.
|
||||
|
|
|
@ -206,10 +206,9 @@ NodeMetadataList::~NodeMetadataList()
|
|||
std::vector<v3s16> NodeMetadataList::getAllKeys()
|
||||
{
|
||||
std::vector<v3s16> keys;
|
||||
|
||||
NodeMetadataMap::const_iterator it;
|
||||
for (it = m_data.begin(); it != m_data.end(); ++it)
|
||||
keys.push_back(it->first);
|
||||
keys.reserve(m_data.size());
|
||||
for (const auto &it : m_data)
|
||||
keys.push_back(it.first);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
@ -218,7 +217,7 @@ NodeMetadata *NodeMetadataList::get(v3s16 p)
|
|||
{
|
||||
NodeMetadataMap::const_iterator n = m_data.find(p);
|
||||
if (n == m_data.end())
|
||||
return NULL;
|
||||
return nullptr;
|
||||
return n->second;
|
||||
}
|
||||
|
||||
|
@ -235,7 +234,7 @@ void NodeMetadataList::remove(v3s16 p)
|
|||
void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
|
||||
{
|
||||
remove(p);
|
||||
m_data.insert(std::make_pair(p, d));
|
||||
m_data.emplace(p, d);
|
||||
}
|
||||
|
||||
void NodeMetadataList::clear()
|
||||
|
@ -251,9 +250,8 @@ void NodeMetadataList::clear()
|
|||
int NodeMetadataList::countNonEmpty() const
|
||||
{
|
||||
int n = 0;
|
||||
NodeMetadataMap::const_iterator it;
|
||||
for (it = m_data.begin(); it != m_data.end(); ++it) {
|
||||
if (!it->second->empty())
|
||||
for (const auto &it : m_data) {
|
||||
if (!it.second->empty())
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
|
|
|
@ -1428,7 +1428,7 @@ std::string Pathfinder::dirToName(PathDirections dir)
|
|||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void Pathfinder::printPath(std::vector<v3s16> path)
|
||||
void Pathfinder::printPath(const std::vector<v3s16> &path)
|
||||
{
|
||||
unsigned int current = 0;
|
||||
for (std::vector<v3s16>::iterator i = path.begin();
|
||||
|
|
|
@ -43,11 +43,11 @@ std::unordered_map<std::string, const FlagDesc *> Settings::s_flags;
|
|||
Settings *Settings::createLayer(SettingsLayer sl, const std::string &end_tag)
|
||||
{
|
||||
if ((int)sl < 0 || sl >= SL_TOTAL_COUNT)
|
||||
throw new BaseException("Invalid settings layer");
|
||||
throw BaseException("Invalid settings layer");
|
||||
|
||||
Settings *&pos = s_layers[(size_t)sl];
|
||||
if (pos)
|
||||
throw new BaseException("Setting layer " + std::to_string(sl) + " already exists");
|
||||
throw BaseException("Setting layer " + std::to_string(sl) + " already exists");
|
||||
|
||||
pos = new Settings(end_tag);
|
||||
pos->m_settingslayer = sl;
|
||||
|
@ -638,6 +638,7 @@ std::vector<std::string> Settings::getNames() const
|
|||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
std::vector<std::string> names;
|
||||
names.reserve(m_settings.size());
|
||||
for (const auto &settings_it : m_settings) {
|
||||
names.push_back(settings_it.first);
|
||||
}
|
||||
|
|
|
@ -96,16 +96,15 @@ void AreaStore::deserialize(std::istream &is)
|
|||
|
||||
u16 num_areas = readU16(is);
|
||||
std::vector<Area> areas;
|
||||
areas.reserve(num_areas);
|
||||
for (u32 i = 0; i < num_areas; ++i) {
|
||||
Area a(U32_MAX);
|
||||
a.minedge = readV3S16(is);
|
||||
a.maxedge = readV3S16(is);
|
||||
u16 data_len = readU16(is);
|
||||
char *data = new char[data_len];
|
||||
is.read(data, data_len);
|
||||
a.data = std::string(data, data_len);
|
||||
areas.emplace_back(a);
|
||||
delete [] data;
|
||||
a.data = std::string(data_len, '\0');
|
||||
is.read(&a.data[0], data_len);
|
||||
areas.emplace_back(std::move(a));
|
||||
}
|
||||
|
||||
bool read_ids = is.good(); // EOF for old formats
|
||||
|
|
|
@ -90,8 +90,7 @@ public:
|
|||
bool get(const Key &name, Value *result) const
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
typename std::map<Key, Value>::const_iterator n =
|
||||
m_values.find(name);
|
||||
auto n = m_values.find(name);
|
||||
if (n == m_values.end())
|
||||
return false;
|
||||
if (result)
|
||||
|
@ -103,11 +102,9 @@ public:
|
|||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
std::vector<Value> result;
|
||||
for (typename std::map<Key, Value>::const_iterator
|
||||
it = m_values.begin();
|
||||
it != m_values.end(); ++it){
|
||||
result.reserve(m_values.size());
|
||||
for (auto it = m_values.begin(); it != m_values.end(); ++it)
|
||||
result.push_back(it->second);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -136,7 +133,7 @@ public:
|
|||
return m_queue.empty();
|
||||
}
|
||||
|
||||
void push_back(T t)
|
||||
void push_back(const T &t)
|
||||
{
|
||||
MutexAutoLock lock(m_mutex);
|
||||
m_queue.push_back(t);
|
||||
|
@ -151,7 +148,7 @@ public:
|
|||
if (m_signal.wait(wait_time_max_ms)) {
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.front();
|
||||
T t = std::move(m_queue.front());
|
||||
m_queue.pop_front();
|
||||
return t;
|
||||
}
|
||||
|
@ -164,7 +161,7 @@ public:
|
|||
if (m_signal.wait(wait_time_max_ms)) {
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.front();
|
||||
T t = std::move(m_queue.front());
|
||||
m_queue.pop_front();
|
||||
return t;
|
||||
}
|
||||
|
@ -178,7 +175,7 @@ public:
|
|||
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.front();
|
||||
T t = std::move(m_queue.front());
|
||||
m_queue.pop_front();
|
||||
return t;
|
||||
}
|
||||
|
@ -188,7 +185,7 @@ public:
|
|||
if (m_signal.wait(wait_time_max_ms)) {
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.back();
|
||||
T t = std::move(m_queue.back());
|
||||
m_queue.pop_back();
|
||||
return t;
|
||||
}
|
||||
|
@ -204,7 +201,7 @@ public:
|
|||
if (m_signal.wait(wait_time_max_ms)) {
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.back();
|
||||
T t = std::move(m_queue.back());
|
||||
m_queue.pop_back();
|
||||
return t;
|
||||
}
|
||||
|
@ -218,7 +215,7 @@ public:
|
|||
|
||||
MutexAutoLock lock(m_mutex);
|
||||
|
||||
T t = m_queue.back();
|
||||
T t = std::move(m_queue.back());
|
||||
m_queue.pop_back();
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -65,12 +65,14 @@ void EnrichedString::operator=(const wchar_t *str)
|
|||
addAtEnd(translate_string(std::wstring(str)), m_default_color);
|
||||
}
|
||||
|
||||
void EnrichedString::addAtEnd(const std::wstring &s, const SColor &initial_color)
|
||||
void EnrichedString::addAtEnd(const std::wstring &s, SColor initial_color)
|
||||
{
|
||||
SColor color(initial_color);
|
||||
bool use_default = (m_default_length == m_string.size() &&
|
||||
color == m_default_color);
|
||||
|
||||
m_colors.reserve(m_colors.size() + s.size());
|
||||
|
||||
size_t i = 0;
|
||||
while (i < s.length()) {
|
||||
if (s[i] != L'\x1b') {
|
||||
|
@ -200,12 +202,6 @@ const std::wstring &EnrichedString::getString() const
|
|||
return m_string;
|
||||
}
|
||||
|
||||
void EnrichedString::setDefaultColor(const irr::video::SColor &color)
|
||||
{
|
||||
m_default_color = color;
|
||||
updateDefaultColor();
|
||||
}
|
||||
|
||||
void EnrichedString::updateDefaultColor()
|
||||
{
|
||||
sanity_check(m_default_length <= m_colors.size());
|
||||
|
|
|
@ -23,18 +23,22 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include <vector>
|
||||
#include <SColor.h>
|
||||
|
||||
using namespace irr;
|
||||
|
||||
class EnrichedString {
|
||||
public:
|
||||
EnrichedString();
|
||||
EnrichedString(const std::wstring &s,
|
||||
const irr::video::SColor &color = irr::video::SColor(255, 255, 255, 255));
|
||||
const video::SColor &color = video::SColor(255, 255, 255, 255));
|
||||
EnrichedString(const wchar_t *str,
|
||||
const irr::video::SColor &color = irr::video::SColor(255, 255, 255, 255));
|
||||
const video::SColor &color = video::SColor(255, 255, 255, 255));
|
||||
EnrichedString(const std::wstring &string,
|
||||
const std::vector<irr::video::SColor> &colors);
|
||||
void clear();
|
||||
const std::vector<video::SColor> &colors);
|
||||
void operator=(const wchar_t *str);
|
||||
void addAtEnd(const std::wstring &s, const irr::video::SColor &color);
|
||||
|
||||
void clear();
|
||||
|
||||
void addAtEnd(const std::wstring &s, video::SColor color);
|
||||
|
||||
// Adds the character source[i] at the end.
|
||||
// An EnrichedString should always be able to be copied
|
||||
|
@ -49,12 +53,16 @@ public:
|
|||
EnrichedString operator+(const EnrichedString &other) const;
|
||||
void operator+=(const EnrichedString &other);
|
||||
const wchar_t *c_str() const;
|
||||
const std::vector<irr::video::SColor> &getColors() const;
|
||||
const std::vector<video::SColor> &getColors() const;
|
||||
const std::wstring &getString() const;
|
||||
|
||||
void setDefaultColor(const irr::video::SColor &color);
|
||||
inline void setDefaultColor(video::SColor color)
|
||||
{
|
||||
m_default_color = color;
|
||||
updateDefaultColor();
|
||||
}
|
||||
void updateDefaultColor();
|
||||
inline const irr::video::SColor &getDefaultColor() const
|
||||
inline const video::SColor &getDefaultColor() const
|
||||
{
|
||||
return m_default_color;
|
||||
}
|
||||
|
@ -80,11 +88,11 @@ public:
|
|||
{
|
||||
return m_has_background;
|
||||
}
|
||||
inline irr::video::SColor getBackground() const
|
||||
inline video::SColor getBackground() const
|
||||
{
|
||||
return m_background;
|
||||
}
|
||||
inline void setBackground(const irr::video::SColor &color)
|
||||
inline void setBackground(video::SColor color)
|
||||
{
|
||||
m_background = color;
|
||||
m_has_background = true;
|
||||
|
@ -92,10 +100,10 @@ public:
|
|||
|
||||
private:
|
||||
std::wstring m_string;
|
||||
std::vector<irr::video::SColor> m_colors;
|
||||
std::vector<video::SColor> m_colors;
|
||||
bool m_has_background;
|
||||
irr::video::SColor m_default_color;
|
||||
irr::video::SColor m_background;
|
||||
video::SColor m_default_color;
|
||||
video::SColor m_background;
|
||||
// This variable defines the length of the default-colored text.
|
||||
// Change this to a std::vector if an "end coloring" tag is wanted.
|
||||
size_t m_default_length = 0;
|
||||
|
|
|
@ -65,7 +65,7 @@ struct ChangingLight {
|
|||
|
||||
ChangingLight() = default;
|
||||
|
||||
ChangingLight(const relative_v3 &rel_pos, const mapblock_v3 &block_pos,
|
||||
ChangingLight(relative_v3 rel_pos, mapblock_v3 block_pos,
|
||||
MapBlock *b, direction source_dir) :
|
||||
rel_position(rel_pos),
|
||||
block_position(block_pos),
|
||||
|
@ -125,8 +125,8 @@ struct LightQueue {
|
|||
* The parameters are the same as in ChangingLight's constructor.
|
||||
* \param light light level of the ChangingLight
|
||||
*/
|
||||
inline void push(u8 light, const relative_v3 &rel_pos,
|
||||
const mapblock_v3 &block_pos, MapBlock *block,
|
||||
inline void push(u8 light, relative_v3 rel_pos,
|
||||
mapblock_v3 block_pos, MapBlock *block,
|
||||
direction source_dir)
|
||||
{
|
||||
assert(light <= LIGHT_SUN);
|
||||
|
@ -467,7 +467,7 @@ bool is_sunlight_above(Map *map, v3s16 pos, const NodeDefManager *ndef)
|
|||
static const LightBank banks[] = { LIGHTBANK_DAY, LIGHTBANK_NIGHT };
|
||||
|
||||
void update_lighting_nodes(Map *map,
|
||||
std::vector<std::pair<v3s16, MapNode> > &oldnodes,
|
||||
const std::vector<std::pair<v3s16, MapNode>> &oldnodes,
|
||||
std::map<v3s16, MapBlock*> &modified_blocks)
|
||||
{
|
||||
const NodeDefManager *ndef = map->getNodeDefManager();
|
||||
|
@ -482,8 +482,7 @@ void update_lighting_nodes(Map *map,
|
|||
// won't change, since they didn't get their light from a
|
||||
// modified node.
|
||||
u8 min_safe_light = 0;
|
||||
for (std::vector<std::pair<v3s16, MapNode> >::iterator it =
|
||||
oldnodes.begin(); it < oldnodes.end(); ++it) {
|
||||
for (auto it = oldnodes.cbegin(); it < oldnodes.cend(); ++it) {
|
||||
u8 old_light = it->second.getLight(bank, ndef);
|
||||
if (old_light > min_safe_light) {
|
||||
min_safe_light = old_light;
|
||||
|
@ -495,8 +494,7 @@ void update_lighting_nodes(Map *map,
|
|||
min_safe_light++;
|
||||
}
|
||||
// For each changed node process sunlight and initialize
|
||||
for (std::vector<std::pair<v3s16, MapNode> >::iterator it =
|
||||
oldnodes.begin(); it < oldnodes.end(); ++it) {
|
||||
for (auto it = oldnodes.cbegin(); it < oldnodes.cend(); ++it) {
|
||||
// Get position and block of the changed node
|
||||
v3s16 p = it->first;
|
||||
relative_v3 rel_pos;
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace voxalgo
|
|||
*/
|
||||
void update_lighting_nodes(
|
||||
Map *map,
|
||||
std::vector<std::pair<v3s16, MapNode> > &oldnodes,
|
||||
const std::vector<std::pair<v3s16, MapNode>> &oldnodes,
|
||||
std::map<v3s16, MapBlock*> &modified_blocks);
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue
Block a user