1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Fix some minor code issues all over the place

This commit is contained in:
sfan5 2020-12-23 22:03:49 +01:00
parent 289425f6bd
commit 74762470b2
19 changed files with 45 additions and 109 deletions

View file

@ -1165,7 +1165,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
}
}
if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) {
if (!getParent() && node && fabs(m_prop.automatic_rotate) > 0.001f) {
// This is the child node's rotation. It is only used for automatic_rotate.
v3f local_rot = node->getRotation();
local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG *
@ -1174,7 +1174,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
}
if (!getParent() && m_prop.automatic_face_movement_dir &&
(fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
(fabs(m_velocity.Z) > 0.001f || fabs(m_velocity.X) > 0.001f)) {
float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_per_sec =

View file

@ -186,7 +186,7 @@ struct LocalFormspecHandler : public TextDest
return;
}
if (m_client && m_client->modsLoaded())
if (m_client->modsLoaded())
m_client->getScript()->on_formspec_input(m_formname, fields);
}
@ -583,7 +583,7 @@ public:
virtual IShaderConstantSetter* create()
{
GameGlobalShaderConstantSetter *scs = new GameGlobalShaderConstantSetter(
auto *scs = new GameGlobalShaderConstantSetter(
m_sky, m_force_fog_off, m_fog_range, m_client);
if (!m_sky)
created_nosky.push_back(scs);
@ -1338,7 +1338,7 @@ bool Game::createClient(const GameStartData &start_data)
return false;
}
GameGlobalShaderConstantSetterFactory *scsf = new GameGlobalShaderConstantSetterFactory(
auto *scsf = new GameGlobalShaderConstantSetterFactory(
&m_flags.force_fog_off, &runData.fog_range, client);
shader_src->addShaderConstantSetterFactory(scsf);
@ -1348,20 +1348,14 @@ bool Game::createClient(const GameStartData &start_data)
/* Camera
*/
camera = new Camera(*draw_control, client);
if (!camera || !camera->successfullyCreated(*error_message))
if (!camera->successfullyCreated(*error_message))
return false;
client->setCamera(camera);
/* Clouds
*/
if (m_cache_enable_clouds) {
if (m_cache_enable_clouds)
clouds = new Clouds(smgr, -1, time(0));
if (!clouds) {
*error_message = "Memory allocation error (clouds)";
errorstream << *error_message << std::endl;
return false;
}
}
/* Skybox
*/
@ -1369,12 +1363,6 @@ bool Game::createClient(const GameStartData &start_data)
scsf->setSky(sky);
skybox = NULL; // This is used/set later on in the main run loop
if (!sky) {
*error_message = "Memory allocation error sky";
errorstream << *error_message << std::endl;
return false;
}
/* Pre-calculated values
*/
video::ITexture *t = texture_src->getTexture("crack_anylength.png");
@ -1404,12 +1392,6 @@ bool Game::createClient(const GameStartData &start_data)
hud = new Hud(guienv, client, player, &player->inventory);
if (!hud) {
*error_message = "Memory error: could not create HUD";
errorstream << *error_message << std::endl;
return false;
}
mapper = client->getMinimap();
if (mapper && client->modsLoaded())
@ -1431,11 +1413,6 @@ bool Game::initGui()
// Chat backend and console
gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(),
-1, chat_backend, client, &g_menumgr);
if (!gui_chat_console) {
*error_message = "Could not allocate memory for chat console";
errorstream << *error_message << std::endl;
return false;
}
#ifdef HAVE_TOUCHSCREENGUI
@ -1492,9 +1469,6 @@ bool Game::connectToServer(const GameStartData &start_data,
itemdef_manager, nodedef_manager, sound, eventmgr,
connect_address.isIPv6(), m_game_ui.get());
if (!client)
return false;
client->m_simple_singleplayer_mode = simple_singleplayer_mode;
infostream << "Connecting to server at ";

View file

@ -1055,9 +1055,9 @@ void drawItemStack(
if (def.type == ITEM_TOOL && item.wear != 0) {
// Draw a progressbar
float barheight = rect.getHeight() / 16;
float barpad_x = rect.getWidth() / 16;
float barpad_y = rect.getHeight() / 16;
float barheight = static_cast<float>(rect.getHeight()) / 16;
float barpad_x = static_cast<float>(rect.getWidth()) / 16;
float barpad_y = static_cast<float>(rect.getHeight()) / 16;
core::rect<s32> progressrect(
rect.UpperLeftCorner.X + barpad_x,

View file

@ -1201,13 +1201,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
MapBlockMesh::~MapBlockMesh()
{
for (scene::IMesh *m : m_mesh) {
if (m_enable_vbo && m)
if (m_enable_vbo) {
for (u32 i = 0; i < m->getMeshBufferCount(); i++) {
scene::IMeshBuffer *buf = m->getMeshBuffer(i);
RenderingEngine::get_video_driver()->removeHardwareBuffer(buf);
}
}
m->drop();
m = NULL;
}
delete m_minimap_mapblock;
}

View file

@ -1633,6 +1633,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
/* IMPORTANT: When changing this, getTextureForMesh() needs to be
* updated too. */
if (!baseimg) {
errorstream << "generateImagePart(): baseimg == NULL "
<< "for part_of_name=\"" << part_of_name
<< "\", cancelling." << std::endl;
return false;
}
// Apply the "clean transparent" filter, if configured.
if (g_settings->getBool("texture_clean_transparent"))
imageCleanTransparent(baseimg, 127);