aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorHerman Semenov <GermanAizek@yandex.ru>2022-09-06 13:21:09 +0300
committerGitHub <noreply@github.com>2022-09-06 11:21:09 +0100
commit038da00e799b4bf3af824075a260083c56392964 (patch)
tree8c0e3218455073684c2521cec41b7df06fff8598 /src/client
parentff6dcfea82974df6db5a557e31aaddb6bdb7a71f (diff)
downloadminetest-038da00e799b4bf3af824075a260083c56392964.tar.xz
Code optimizations / refactor (#12704)
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com> Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/client')
-rw-r--r--src/client/camera.cpp5
-rw-r--r--src/client/clientlauncher.cpp6
-rw-r--r--src/client/clientmap.cpp2
-rw-r--r--src/client/game.cpp9
-rw-r--r--src/client/hud.cpp3
-rw-r--r--src/client/imagefilters.cpp3
-rw-r--r--src/client/keycode.cpp2
-rw-r--r--src/client/minimap.cpp6
-rw-r--r--src/client/minimap.h4
-rw-r--r--src/client/shader.cpp4
-rw-r--r--src/client/sound_openal.cpp2
-rw-r--r--src/client/tile.cpp3
12 files changed, 25 insertions, 24 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp
index fd60e6dde..994497224 100644
--- a/src/client/camera.cpp
+++ b/src/client/camera.cpp
@@ -676,11 +676,12 @@ void Camera::drawNametags()
screen_pos.Y = screensize.Y *
(0.5 - transformed_pos[1] * zDiv * 0.5) - textsize.Height / 2;
core::rect<s32> size(0, 0, textsize.Width, textsize.Height);
- core::rect<s32> bg_size(-2, 0, textsize.Width+2, textsize.Height);
auto bgcolor = nametag->getBgColor(m_show_nametag_backgrounds);
- if (bgcolor.getAlpha() != 0)
+ if (bgcolor.getAlpha() != 0) {
+ core::rect<s32> bg_size(-2, 0, textsize.Width + 2, textsize.Height);
driver->draw2DRectangle(bgcolor, bg_size + screen_pos);
+ }
font->draw(
translate_string(utf8_to_wide(nametag->text)).c_str(),
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 60c9525f3..514607fc3 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -417,7 +417,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
menudata.name = start_data.name;
menudata.password = start_data.password;
menudata.port = itos(start_data.socket_port);
- menudata.script_data.errormessage = error_message_lua;
+ menudata.script_data.errormessage = std::move(error_message_lua);
menudata.script_data.reconnect_requested = reconnect_requested;
main_menu(&menudata);
@@ -582,8 +582,8 @@ void ClientLauncher::speed_tests()
TimeTaker timer("Testing std::string speed");
const u32 jj = 10000;
for (u32 j = 0; j < jj; j++) {
- tempstring = "";
- tempstring2 = "";
+ tempstring.clear();
+ tempstring2.clear();
const u32 ii = 10;
for (u32 i = 0; i < ii; i++) {
tempstring2 += "asd";
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index 6764cf3ed..669c673aa 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -840,8 +840,6 @@ void ClientMap::updateDrawListShadow(v3f shadow_light_pos, v3f shadow_light_dir,
v3s16 p_blocks_max;
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max, radius + length);
- std::vector<v2s16> blocks_in_range;
-
for (auto &i : m_drawlist_shadow) {
MapBlock *block = i.second;
block->refDrop();
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 34bfb5aa6..6a4bff61a 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -112,7 +112,7 @@ struct TextDestPlayerInventory : public TextDest
TextDestPlayerInventory(Client *client)
{
m_client = client;
- m_formname = "";
+ m_formname.clear();
}
TextDestPlayerInventory(Client *client, const std::string &formname)
{
@@ -2985,14 +2985,15 @@ void Game::updateCamera(f32 dtime)
camera->update(player, dtime, tool_reload_ratio);
camera->step(dtime);
- v3f camera_position = camera->getPosition();
- v3f camera_direction = camera->getDirection();
f32 camera_fov = camera->getFovMax();
v3s16 camera_offset = camera->getOffset();
m_camera_offset_changed = (camera_offset != old_camera_offset);
if (!m_flags.disable_camera_update) {
+ v3f camera_position = camera->getPosition();
+ v3f camera_direction = camera->getDirection();
+
client->getEnv().getClientMap().updateCamera(camera_position,
camera_direction, camera_fov, camera_offset);
@@ -3149,7 +3150,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
runData.punching = false;
- soundmaker->m_player_leftpunch_sound.name = "";
+ soundmaker->m_player_leftpunch_sound.name.clear();
// Prepare for repeating, unless we're not supposed to
if (isKeyDown(KeyType::PLACE) && !g_settings->getBool("safe_dig_and_place"))
diff --git a/src/client/hud.cpp b/src/client/hud.cpp
index 3455908ce..e8ccdbb2b 100644
--- a/src/client/hud.cpp
+++ b/src/client/hud.cpp
@@ -411,7 +411,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
case HUD_ELEM_WAYPOINT: {
if (!calculateScreenPos(camera_offset, e, &pos))
break;
- v3f p_pos = player->getPosition() / BS;
+
pos += v2s32(e->offset.X, e->offset.Y);
video::SColor color(255, (e->number >> 16) & 0xFF,
(e->number >> 8) & 0xFF,
@@ -429,6 +429,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset)
font->draw(text.c_str(), bounds + v2s32((e->align.X - 1.0) * bounds.getWidth() / 2, 0), color);
if (draw_precision) {
std::ostringstream os;
+ v3f p_pos = player->getPosition() / BS;
float distance = std::floor(precision * p_pos.getDistanceFrom(e->world_pos)) / precision;
os << distance << unit;
text = unescape_translate(utf8_to_wide(os.str()));
diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp
index c9d1504ad..ed8483fcf 100644
--- a/src/client/imagefilters.cpp
+++ b/src/client/imagefilters.cpp
@@ -111,8 +111,6 @@ void imageCleanTransparent(video::IImage *src, u32 threshold)
if (bitmap.get(ctrx, ctry))
continue;
- video::SColor c = src->getPixel(ctrx, ctry);
-
// Sample size and total weighted r, g, b values
u32 ss = 0, sr = 0, sg = 0, sb = 0;
@@ -137,6 +135,7 @@ void imageCleanTransparent(video::IImage *src, u32 threshold)
// Set pixel to average weighted by alpha
if (ss > 0) {
+ video::SColor c = src->getPixel(ctrx, ctry);
c.setRed(sr / ss);
c.setGreen(sg / ss);
c.setBlue(sb / ss);
diff --git a/src/client/keycode.cpp b/src/client/keycode.cpp
index fac077f0f..85851cc9c 100644
--- a/src/client/keycode.cpp
+++ b/src/client/keycode.cpp
@@ -332,7 +332,7 @@ KeyPress::KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character)
else
m_name = lookup_keychar(Char).Name;
} catch (UnknownKeycode &e) {
- m_name = "";
+ m_name.clear();
};
}
diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp
index 320621d91..3c16c112c 100644
--- a/src/client/minimap.cpp
+++ b/src/client/minimap.cpp
@@ -327,7 +327,7 @@ void Minimap::addMode(MinimapModeDef mode)
int zoom = -1;
// Build a default standard label
- if (mode.label == "") {
+ if (mode.label.empty()) {
switch (mode.type) {
case MINIMAP_TYPE_OFF:
mode.label = gettext("Minimap hidden");
@@ -361,8 +361,8 @@ void Minimap::addMode(MinimapModeDef mode)
m_modes.push_back(mode);
}
-void Minimap::addMode(MinimapType type, u16 size, std::string label,
- std::string texture, u16 scale)
+void Minimap::addMode(MinimapType type, u16 size, const std::string &label,
+ const std::string &texture, u16 scale)
{
MinimapModeDef mode;
mode.type = type;
diff --git a/src/client/minimap.h b/src/client/minimap.h
index 87c9668ee..f06a2e173 100644
--- a/src/client/minimap.h
+++ b/src/client/minimap.h
@@ -130,8 +130,8 @@ public:
void clearModes() { m_modes.clear(); };
void addMode(MinimapModeDef mode);
- void addMode(MinimapType type, u16 size = 0, std::string label = "",
- std::string texture = "", u16 scale = 1);
+ void addMode(MinimapType type, u16 size = 0, const std::string &label = "",
+ const std::string &texture = "", u16 scale = 1);
void setModeIndex(size_t index);
size_t getModeIndex() const { return m_current_mode_index; };
diff --git a/src/client/shader.cpp b/src/client/shader.cpp
index e836d0131..f46807864 100644
--- a/src/client/shader.cpp
+++ b/src/client/shader.cpp
@@ -184,7 +184,7 @@ public:
ShaderCallback(const Factories &factories)
{
for (auto &&factory : factories)
- m_setters.push_back(std::unique_ptr<IShaderConstantSetter>(factory->create()));
+ m_setters.emplace_back(factory->create());
}
virtual void OnSetConstants(video::IMaterialRendererServices *services, s32 userData) override
@@ -402,7 +402,7 @@ public:
void addShaderConstantSetterFactory(IShaderConstantSetterFactory *setter) override
{
- m_setter_factories.push_back(std::unique_ptr<IShaderConstantSetterFactory>(setter));
+ m_setter_factories.emplace_back(setter);
}
private:
diff --git a/src/client/sound_openal.cpp b/src/client/sound_openal.cpp
index b015aba25..e84c62349 100644
--- a/src/client/sound_openal.cpp
+++ b/src/client/sound_openal.cpp
@@ -409,7 +409,7 @@ public:
}
std::vector<SoundBuffer*> bufs;
bufs.push_back(buf);
- m_buffers[name] = bufs;
+ m_buffers[name] = std::move(bufs);
}
SoundBuffer* getBuffer(const std::string &name)
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index 87d2818b4..133b0376f 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -979,8 +979,9 @@ video::IImage* TextureSource::generateImage(const std::string &name)
<< std::endl;
return NULL;
}
- core::dimension2d<u32> dim = tmp->getDimension();
+
if (baseimg) {
+ core::dimension2d<u32> dim = tmp->getDimension();
blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim);
tmp->drop();
} else {