Use smart-ptrs in GUIEngine

This commit is contained in:
Desour 2023-04-10 18:43:58 +02:00 committed by DS
parent ceec560779
commit b201c03625
3 changed files with 51 additions and 52 deletions

@ -143,19 +143,19 @@ GUIEngine::GUIEngine(JoystickController *joystick,
texture.texture = NULL;
}
// is deleted by guiformspec!
m_buttonhandler = new TextDestGuiEngine(this);
auto buttonhandler = std::make_unique<TextDestGuiEngine>(this);
m_buttonhandler = buttonhandler.get();
// create texture source
m_texture_source = new MenuTextureSource(rendering_engine->get_video_driver());
m_texture_source = std::make_unique<MenuTextureSource>(rendering_engine->get_video_driver());
// create soundmanager
MenuMusicFetcher soundfetcher;
#if USE_SOUND
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get())
m_sound_manager = createOpenALSoundManager(g_sound_manager_singleton.get(), &soundfetcher);
m_sound_manager.reset(createOpenALSoundManager(g_sound_manager_singleton.get(), &m_soundfetcher));
#endif
if (!m_sound_manager)
m_sound_manager = &dummySoundManager;
m_sound_manager = std::make_unique<DummySoundManager>();
// create topleft header
m_toplefttext = L"";
@ -168,19 +168,21 @@ GUIEngine::GUIEngine(JoystickController *joystick,
m_toplefttext, rect, false, true, 0, -1);
// create formspecsource
m_formspecgui = new FormspecFormSource("");
auto formspecgui = std::make_unique<FormspecFormSource>("");
m_formspecgui = formspecgui.get();
/* Create menu */
m_menu = new GUIFormSpecMenu(joystick,
m_menu = make_irr<GUIFormSpecMenu>(
joystick,
m_parent,
-1,
m_menumanager,
NULL /* &client */,
nullptr /* &client */,
m_rendering_engine->get_gui_env(),
m_texture_source,
m_sound_manager,
m_formspecgui,
m_buttonhandler,
m_texture_source.get(),
m_sound_manager.get(),
formspecgui.release(),
buttonhandler.release(),
"",
false);
@ -191,7 +193,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
infostream << "GUIEngine: Initializing Lua" << std::endl;
m_script = new MainMenuScripting(this);
m_script = std::make_unique<MainMenuScripting>(this);
try {
m_script->setMainMenuData(&m_data->script_data);
@ -209,8 +211,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
}
m_menu->quitMenu();
m_menu->drop();
m_menu = NULL;
m_menu.reset();
}
/******************************************************************************/
@ -327,13 +328,10 @@ void GUIEngine::run()
/******************************************************************************/
GUIEngine::~GUIEngine()
{
if (m_sound_manager != &dummySoundManager){
delete m_sound_manager;
m_sound_manager = NULL;
}
m_sound_manager.reset();
infostream<<"GUIEngine: Deinitializing scripting"<<std::endl;
delete m_script;
m_script.reset();
m_irr_toplefttext->setText(L"");
@ -343,16 +341,15 @@ GUIEngine::~GUIEngine()
m_rendering_engine->get_video_driver()->removeTexture(texture.texture);
}
delete m_texture_source;
m_texture_source.reset();
if (m_cloud.clouds)
m_cloud.clouds->drop();
m_cloud.clouds.reset();
}
/******************************************************************************/
void GUIEngine::cloudInit()
{
m_cloud.clouds = new Clouds(m_smgr, -1, rand());
m_cloud.clouds = make_irr<Clouds>(m_smgr, -1, rand());
m_cloud.clouds->setHeight(100.0f);
m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255));

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/******************************************************************************/
#include "irrlichttypes.h"
#include "guiFormSpecMenu.h"
#include "client/clouds.h"
#include "client/sound.h"
#include "client/tile.h"
#include "util/enriched_string.h"
@ -52,7 +53,6 @@ struct image_definition {
class GUIEngine;
class RenderingEngine;
class MainMenuScripting;
class Clouds;
struct MainMenuData;
/******************************************************************************/
@ -164,7 +164,7 @@ public:
*/
MainMenuScripting *getScriptIface()
{
return m_script;
return m_script.get();
}
/**
@ -195,17 +195,19 @@ private:
scene::ISceneManager *m_smgr = nullptr;
/** pointer to data beeing transfered back to main game handling */
MainMenuData *m_data = nullptr;
/** pointer to texture source */
ISimpleTextureSource *m_texture_source = nullptr;
/** pointer to soundmanager*/
ISoundManager *m_sound_manager = nullptr;
/** texture source */
std::unique_ptr<ISimpleTextureSource> m_texture_source;
/** sound fetcher, used by sound manager*/
MenuMusicFetcher m_soundfetcher{};
/** sound manager*/
std::unique_ptr<ISoundManager> m_sound_manager;
/** representation of form source to be used in mainmenu formspec */
FormspecFormSource *m_formspecgui = nullptr;
/** formspec input receiver */
TextDestGuiEngine *m_buttonhandler = nullptr;
/** the formspec menu */
GUIFormSpecMenu *m_menu = nullptr;
irr_ptr<GUIFormSpecMenu> m_menu;
/** reference to kill variable managed by SIGINT handler */
bool &m_kill;
@ -214,7 +216,7 @@ private:
bool m_startgame = false;
/** scripting interface */
MainMenuScripting *m_script = nullptr;
std::unique_ptr<MainMenuScripting> m_script;
/** script basefolder */
std::string m_scriptdir = "";
@ -285,7 +287,7 @@ private:
/** absolute time of last cloud processing */
u32 lasttime;
/** pointer to cloud class */
Clouds *clouds = nullptr;
irr_ptr<Clouds> clouds;
/** camera required for drawing clouds */
scene::ICameraSceneNode *camera = nullptr;
};

@ -516,7 +516,7 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
engine->m_parent,
-1,
engine->m_menumanager,
engine->m_texture_source);
engine->m_texture_source.get());
kmenu->drop();
return 0;
}