1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Replace some raw pointers by unique_ptr (#16304)

This commit is contained in:
Lucas OH 2025-08-06 23:17:34 +02:00 committed by GitHub
parent c611a1f9e8
commit ecc876045f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 56 additions and 48 deletions

View file

@ -122,7 +122,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
// This is only global so it can be used by RenderingEngine::draw_load_screen(). // This is only global so it can be used by RenderingEngine::draw_load_screen().
assert(!g_menucloudsmgr && !g_menuclouds); assert(!g_menucloudsmgr && !g_menuclouds);
std::unique_ptr<IWritableShaderSource> ssrc(createShaderSource()); std::unique_ptr<IWritableShaderSource> ssrc(createShaderSource());
ssrc->addShaderUniformSetterFactory(new FogShaderUniformSetterFactory()); ssrc->addShaderUniformSetterFactory(std::make_unique<FogShaderUniformSetterFactory>());
g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager(); g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager();
g_menuclouds = new Clouds(g_menucloudsmgr, ssrc.get(), -1, rand()); g_menuclouds = new Clouds(g_menucloudsmgr, ssrc.get(), -1, rand());
g_menuclouds->setHeight(100.0f); g_menuclouds->setHeight(100.0f);

View file

@ -1360,13 +1360,15 @@ bool Game::createClient(const GameStartData &start_data)
return false; return false;
} }
shader_src->addShaderConstantSetter(new NodeShaderConstantSetter()); shader_src->addShaderConstantSetter(
std::make_unique<NodeShaderConstantSetter>());
auto *scsf = new GameGlobalShaderUniformSetterFactory(client); auto scsf_up = std::make_unique<GameGlobalShaderUniformSetterFactory>(client);
shader_src->addShaderUniformSetterFactory(scsf); auto* scsf = scsf_up.get();
shader_src->addShaderUniformSetterFactory(std::move(scsf_up));
shader_src->addShaderUniformSetterFactory( shader_src->addShaderUniformSetterFactory(
new FogShaderUniformSetterFactory()); std::make_unique<FogShaderUniformSetterFactory>());
ShadowRenderer::preInit(shader_src); ShadowRenderer::preInit(shader_src);

View file

@ -11,10 +11,10 @@ void MeshCollector::append(const TileSpec &tile, const video::S3DVertex *vertice
u32 numVertices, const u16 *indices, u32 numIndices) u32 numVertices, const u16 *indices, u32 numIndices)
{ {
for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) { for (int layernum = 0; layernum < MAX_TILE_LAYERS; layernum++) {
const TileLayer *layer = &tile.layers[layernum]; const TileLayer &layer = tile.layers[layernum];
if (layer->empty()) if (layer.empty())
continue; continue;
append(*layer, vertices, numVertices, indices, numIndices, layernum); append(layer, vertices, numVertices, indices, numIndices, layernum);
} }
} }

View file

@ -9,17 +9,15 @@
#include "settings.h" #include "settings.h"
RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud, RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud,
ShadowRenderer *_shadow_renderer, RenderPipeline *_pipeline, v2f _virtual_size_scale) std::unique_ptr<ShadowRenderer> _shadow_renderer,
: device(_device), client(_client), hud(_hud), shadow_renderer(_shadow_renderer), std::unique_ptr<RenderPipeline> _pipeline,
pipeline(_pipeline), virtual_size_scale(_virtual_size_scale) v2f _virtual_size_scale)
: device(_device), client(_client), hud(_hud), shadow_renderer(std::move(_shadow_renderer)),
pipeline(std::move(_pipeline)), virtual_size_scale(_virtual_size_scale)
{ {
} }
RenderingCore::~RenderingCore() RenderingCore::~RenderingCore() = default;
{
delete pipeline;
delete shadow_renderer;
}
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, void RenderingCore::draw(video::SColor _skycolor, bool _show_hud,
bool _draw_wield_tool, bool _draw_crosshair) bool _draw_wield_tool, bool _draw_crosshair)
@ -27,7 +25,7 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud,
v2u32 screensize = device->getVideoDriver()->getScreenSize(); v2u32 screensize = device->getVideoDriver()->getScreenSize();
virtual_size = v2u32(screensize.X * virtual_size_scale.X, screensize.Y * virtual_size_scale.Y); virtual_size = v2u32(screensize.X * virtual_size_scale.X, screensize.Y * virtual_size_scale.Y);
PipelineContext context(device, client, hud, shadow_renderer, _skycolor, screensize); PipelineContext context(device, client, hud, shadow_renderer.get(), _skycolor, screensize);
context.draw_crosshair = _draw_crosshair; context.draw_crosshair = _draw_crosshair;
context.draw_wield_tool = _draw_wield_tool; context.draw_wield_tool = _draw_wield_tool;
context.show_hud = _show_hud; context.show_hud = _show_hud;

View file

@ -7,6 +7,7 @@
#include "irr_v2d.h" #include "irr_v2d.h"
#include <SColor.h> #include <SColor.h>
#include <memory>
class IrrlichtDevice; class IrrlichtDevice;
@ -21,16 +22,17 @@ protected:
IrrlichtDevice *device; IrrlichtDevice *device;
Client *client; Client *client;
Hud *hud; Hud *hud;
ShadowRenderer *shadow_renderer; std::unique_ptr<ShadowRenderer> shadow_renderer;
RenderPipeline *pipeline; std::unique_ptr<RenderPipeline> pipeline;
v2f virtual_size_scale; v2f virtual_size_scale;
v2u32 virtual_size { 0, 0 }; v2u32 virtual_size { 0, 0 };
public: public:
RenderingCore(IrrlichtDevice *device, Client *client, Hud *hud, RenderingCore(IrrlichtDevice *device, Client *client, Hud *hud,
ShadowRenderer *shadow_renderer, RenderPipeline *pipeline, std::unique_ptr<ShadowRenderer> shadow_renderer,
std::unique_ptr<RenderPipeline> pipeline,
v2f virtual_size_scale); v2f virtual_size_scale);
RenderingCore(const RenderingCore &) = delete; RenderingCore(const RenderingCore &) = delete;
RenderingCore(RenderingCore &&) = delete; RenderingCore(RenderingCore &&) = delete;
@ -44,5 +46,5 @@ public:
v2u32 getVirtualSize() const; v2u32 getVirtualSize() const;
ShadowRenderer *get_shadow_renderer() { return shadow_renderer; }; ShadowRenderer *get_shadow_renderer() { return shadow_renderer.get(); };
}; };

View file

@ -4,6 +4,7 @@
// Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru> // Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
#include "factory.h" #include "factory.h"
#include "log.h" #include "log.h"
#include "plain.h" #include "plain.h"
#include "anaglyph.h" #include "anaglyph.h"
@ -12,11 +13,13 @@
#include "secondstage.h" #include "secondstage.h"
#include "client/shadows/dynamicshadowsrender.h" #include "client/shadows/dynamicshadowsrender.h"
#include <memory>
struct CreatePipelineResult struct CreatePipelineResult
{ {
v2f virtual_size_scale; v2f virtual_size_scale;
ShadowRenderer *shadow_renderer { nullptr }; std::unique_ptr<ShadowRenderer> shadow_renderer;
RenderPipeline *pipeline { nullptr }; std::unique_ptr<RenderPipeline> pipeline;
}; };
void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Client *client, Hud *hud, CreatePipelineResult &result); void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Client *client, Hud *hud, CreatePipelineResult &result);
@ -27,44 +30,46 @@ RenderingCore *createRenderingCore(const std::string &stereo_mode, IrrlichtDevic
CreatePipelineResult created_pipeline; CreatePipelineResult created_pipeline;
createPipeline(stereo_mode, device, client, hud, created_pipeline); createPipeline(stereo_mode, device, client, hud, created_pipeline);
return new RenderingCore(device, client, hud, return new RenderingCore(device, client, hud,
created_pipeline.shadow_renderer, created_pipeline.pipeline, created_pipeline.virtual_size_scale); std::move(created_pipeline.shadow_renderer),
std::move(created_pipeline.pipeline),
created_pipeline.virtual_size_scale);
} }
void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Client *client, Hud *hud, CreatePipelineResult &result) void createPipeline(const std::string &stereo_mode, IrrlichtDevice *device, Client *client, Hud *hud, CreatePipelineResult &result)
{ {
result.shadow_renderer = createShadowRenderer(device, client); result.shadow_renderer = createShadowRenderer(device, client);
result.virtual_size_scale = v2f(1.0f); result.virtual_size_scale = v2f(1.0f);
result.pipeline = new RenderPipeline(); result.pipeline = std::make_unique<RenderPipeline>();
if (result.shadow_renderer) if (result.shadow_renderer)
result.pipeline->addStep<RenderShadowMapStep>(); result.pipeline->addStep<RenderShadowMapStep>();
if (stereo_mode == "none") { if (stereo_mode == "none") {
populatePlainPipeline(result.pipeline, client); populatePlainPipeline(result.pipeline.get(), client);
return; return;
} }
if (stereo_mode == "anaglyph") { if (stereo_mode == "anaglyph") {
populateAnaglyphPipeline(result.pipeline, client); populateAnaglyphPipeline(result.pipeline.get(), client);
return; return;
} }
if (stereo_mode == "interlaced") { if (stereo_mode == "interlaced") {
populateInterlacedPipeline(result.pipeline, client); populateInterlacedPipeline(result.pipeline.get(), client);
return; return;
} }
if (stereo_mode == "sidebyside") { if (stereo_mode == "sidebyside") {
populateSideBySidePipeline(result.pipeline, client, false, false, result.virtual_size_scale); populateSideBySidePipeline(result.pipeline.get(), client, false, false, result.virtual_size_scale);
return; return;
} }
if (stereo_mode == "topbottom") { if (stereo_mode == "topbottom") {
populateSideBySidePipeline(result.pipeline, client, true, false, result.virtual_size_scale); populateSideBySidePipeline(result.pipeline.get(), client, true, false, result.virtual_size_scale);
return; return;
} }
if (stereo_mode == "crossview") { if (stereo_mode == "crossview") {
populateSideBySidePipeline(result.pipeline, client, false, true, result.virtual_size_scale); populateSideBySidePipeline(result.pipeline.get(), client, false, true, result.virtual_size_scale);
return; return;
} }
// fallback to plain renderer // fallback to plain renderer
errorstream << "Invalid rendering mode: " << stereo_mode << std::endl; errorstream << "Invalid rendering mode: " << stereo_mode << std::endl;
populatePlainPipeline(result.pipeline, client); populatePlainPipeline(result.pipeline.get(), client);
} }

View file

@ -4,13 +4,13 @@
// Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru> // Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
#pragma once #pragma once
#include "stereo.h" #include "pipeline.h"
class InitInterlacedMaskStep : public TrivialRenderStep class InitInterlacedMaskStep : public TrivialRenderStep
{ {
public: public:
InitInterlacedMaskStep(TextureBuffer *buffer, u8 index); InitInterlacedMaskStep(TextureBuffer *buffer, u8 index);
void run(PipelineContext &context); void run(PipelineContext &context) override;
private: private:
TextureBuffer *buffer; TextureBuffer *buffer;
video::ITexture *last_mask { nullptr }; video::ITexture *last_mask { nullptr };

View file

@ -378,14 +378,14 @@ public:
// Shall be called from the main thread. // Shall be called from the main thread.
void rebuildShaders() override; void rebuildShaders() override;
void addShaderConstantSetter(IShaderConstantSetter *setter) override void addShaderConstantSetter(std::unique_ptr<IShaderConstantSetter> setter) override
{ {
m_constant_setters.emplace_back(setter); m_constant_setters.emplace_back(std::move(setter));
} }
void addShaderUniformSetterFactory(IShaderUniformSetterFactory *setter) override void addShaderUniformSetterFactory(std::unique_ptr<IShaderUniformSetterFactory> setter) override
{ {
m_uniform_factories.emplace_back(setter); m_uniform_factories.emplace_back(std::move(setter));
} }
private: private:
@ -441,8 +441,8 @@ ShaderSource::ShaderSource()
m_shaderinfo_cache.emplace_back(); m_shaderinfo_cache.emplace_back();
// Add global stuff // Add global stuff
addShaderConstantSetter(new MainShaderConstantSetter()); addShaderConstantSetter(std::make_unique<MainShaderConstantSetter>());
addShaderUniformSetterFactory(new MainShaderUniformSetterFactory()); addShaderUniformSetterFactory(std::make_unique<MainShaderUniformSetterFactory>());
} }
ShaderSource::~ShaderSource() ShaderSource::~ShaderSource()

View file

@ -274,10 +274,10 @@ public:
virtual void rebuildShaders()=0; virtual void rebuildShaders()=0;
/// @note Takes ownership of @p setter. /// @note Takes ownership of @p setter.
virtual void addShaderConstantSetter(IShaderConstantSetter *setter) = 0; virtual void addShaderConstantSetter(std::unique_ptr<IShaderConstantSetter> setter) = 0;
/// @note Takes ownership of @p setter. /// @note Takes ownership of @p setter.
virtual void addShaderUniformSetterFactory(IShaderUniformSetterFactory *setter) = 0; virtual void addShaderUniformSetterFactory(std::unique_ptr<IShaderUniformSetterFactory> setter) = 0;
}; };
IWritableShaderSource *createShaderSource(); IWritableShaderSource *createShaderSource();

View file

@ -107,7 +107,7 @@ void ShadowRenderer::disable()
void ShadowRenderer::preInit(IWritableShaderSource *shsrc) void ShadowRenderer::preInit(IWritableShaderSource *shsrc)
{ {
if (g_settings->getBool("enable_dynamic_shadows")) { if (g_settings->getBool("enable_dynamic_shadows")) {
shsrc->addShaderUniformSetterFactory(new ShadowUniformSetterFactory()); shsrc->addShaderUniformSetterFactory(std::make_unique<ShadowUniformSetterFactory>());
} }
} }
@ -687,7 +687,7 @@ std::string ShadowRenderer::readShaderFile(const std::string &path)
return prefix + content; return prefix + content;
} }
ShadowRenderer *createShadowRenderer(IrrlichtDevice *device, Client *client) std::unique_ptr<ShadowRenderer> createShadowRenderer(IrrlichtDevice *device, Client *client)
{ {
if (!g_settings->getBool("enable_dynamic_shadows")) if (!g_settings->getBool("enable_dynamic_shadows"))
return nullptr; return nullptr;
@ -701,7 +701,7 @@ ShadowRenderer *createShadowRenderer(IrrlichtDevice *device, Client *client)
return nullptr; return nullptr;
} }
ShadowRenderer *shadow_renderer = new ShadowRenderer(device, client); auto shadow_renderer = std::make_unique<ShadowRenderer>(device, client);
shadow_renderer->initialize(); shadow_renderer->initialize();
return shadow_renderer; return shadow_renderer;
} }

View file

@ -6,6 +6,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include <IrrlichtDevice.h> #include <IrrlichtDevice.h>
#include "client/shadows/dynamicshadows.h" #include "client/shadows/dynamicshadows.h"
#include <ISceneNode.h> #include <ISceneNode.h>
@ -165,4 +166,4 @@ private:
* @param client Reference to the client context. * @param client Reference to the client context.
* @return A new ShadowRenderer instance or nullptr if shadows are disabled or not supported. * @return A new ShadowRenderer instance or nullptr if shadows are disabled or not supported.
*/ */
ShadowRenderer *createShadowRenderer(IrrlichtDevice *device, Client *client); std::unique_ptr<ShadowRenderer> createShadowRenderer(IrrlichtDevice *device, Client *client);