mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-15 19:42:10 +00:00
Code optimizations / refactor (#12704)
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
ff6dcfea82
commit
038da00e79
38 changed files with 84 additions and 94 deletions
|
@ -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(),
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; };
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue