mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Use smart-ptrs in GUIEngine
This commit is contained in:
parent
ceec560779
commit
b201c03625
@ -143,19 +143,19 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
texture.texture = NULL;
|
texture.texture = NULL;
|
||||||
}
|
}
|
||||||
// is deleted by guiformspec!
|
// is deleted by guiformspec!
|
||||||
m_buttonhandler = new TextDestGuiEngine(this);
|
auto buttonhandler = std::make_unique<TextDestGuiEngine>(this);
|
||||||
|
m_buttonhandler = buttonhandler.get();
|
||||||
|
|
||||||
// create texture source
|
// 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
|
// create soundmanager
|
||||||
MenuMusicFetcher soundfetcher;
|
|
||||||
#if USE_SOUND
|
#if USE_SOUND
|
||||||
if (g_settings->getBool("enable_sound") && g_sound_manager_singleton.get())
|
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
|
#endif
|
||||||
if (!m_sound_manager)
|
if (!m_sound_manager)
|
||||||
m_sound_manager = &dummySoundManager;
|
m_sound_manager = std::make_unique<DummySoundManager>();
|
||||||
|
|
||||||
// create topleft header
|
// create topleft header
|
||||||
m_toplefttext = L"";
|
m_toplefttext = L"";
|
||||||
@ -168,19 +168,21 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
m_toplefttext, rect, false, true, 0, -1);
|
m_toplefttext, rect, false, true, 0, -1);
|
||||||
|
|
||||||
// create formspecsource
|
// create formspecsource
|
||||||
m_formspecgui = new FormspecFormSource("");
|
auto formspecgui = std::make_unique<FormspecFormSource>("");
|
||||||
|
m_formspecgui = formspecgui.get();
|
||||||
|
|
||||||
/* Create menu */
|
/* Create menu */
|
||||||
m_menu = new GUIFormSpecMenu(joystick,
|
m_menu = make_irr<GUIFormSpecMenu>(
|
||||||
|
joystick,
|
||||||
m_parent,
|
m_parent,
|
||||||
-1,
|
-1,
|
||||||
m_menumanager,
|
m_menumanager,
|
||||||
NULL /* &client */,
|
nullptr /* &client */,
|
||||||
m_rendering_engine->get_gui_env(),
|
m_rendering_engine->get_gui_env(),
|
||||||
m_texture_source,
|
m_texture_source.get(),
|
||||||
m_sound_manager,
|
m_sound_manager.get(),
|
||||||
m_formspecgui,
|
formspecgui.release(),
|
||||||
m_buttonhandler,
|
buttonhandler.release(),
|
||||||
"",
|
"",
|
||||||
false);
|
false);
|
||||||
|
|
||||||
@ -191,7 +193,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
|
|
||||||
infostream << "GUIEngine: Initializing Lua" << std::endl;
|
infostream << "GUIEngine: Initializing Lua" << std::endl;
|
||||||
|
|
||||||
m_script = new MainMenuScripting(this);
|
m_script = std::make_unique<MainMenuScripting>(this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_script->setMainMenuData(&m_data->script_data);
|
m_script->setMainMenuData(&m_data->script_data);
|
||||||
@ -209,8 +211,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_menu->quitMenu();
|
m_menu->quitMenu();
|
||||||
m_menu->drop();
|
m_menu.reset();
|
||||||
m_menu = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -327,13 +328,10 @@ void GUIEngine::run()
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
GUIEngine::~GUIEngine()
|
GUIEngine::~GUIEngine()
|
||||||
{
|
{
|
||||||
if (m_sound_manager != &dummySoundManager){
|
m_sound_manager.reset();
|
||||||
delete m_sound_manager;
|
|
||||||
m_sound_manager = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
infostream<<"GUIEngine: Deinitializing scripting"<<std::endl;
|
infostream<<"GUIEngine: Deinitializing scripting"<<std::endl;
|
||||||
delete m_script;
|
m_script.reset();
|
||||||
|
|
||||||
m_irr_toplefttext->setText(L"");
|
m_irr_toplefttext->setText(L"");
|
||||||
|
|
||||||
@ -343,16 +341,15 @@ GUIEngine::~GUIEngine()
|
|||||||
m_rendering_engine->get_video_driver()->removeTexture(texture.texture);
|
m_rendering_engine->get_video_driver()->removeTexture(texture.texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_texture_source;
|
m_texture_source.reset();
|
||||||
|
|
||||||
if (m_cloud.clouds)
|
m_cloud.clouds.reset();
|
||||||
m_cloud.clouds->drop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
void GUIEngine::cloudInit()
|
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->setHeight(100.0f);
|
||||||
m_cloud.clouds->update(v3f(0, 0, 0), video::SColor(255,240,240,255));
|
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 "irrlichttypes.h"
|
||||||
#include "guiFormSpecMenu.h"
|
#include "guiFormSpecMenu.h"
|
||||||
|
#include "client/clouds.h"
|
||||||
#include "client/sound.h"
|
#include "client/sound.h"
|
||||||
#include "client/tile.h"
|
#include "client/tile.h"
|
||||||
#include "util/enriched_string.h"
|
#include "util/enriched_string.h"
|
||||||
@ -52,7 +53,6 @@ struct image_definition {
|
|||||||
class GUIEngine;
|
class GUIEngine;
|
||||||
class RenderingEngine;
|
class RenderingEngine;
|
||||||
class MainMenuScripting;
|
class MainMenuScripting;
|
||||||
class Clouds;
|
|
||||||
struct MainMenuData;
|
struct MainMenuData;
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -164,7 +164,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
MainMenuScripting *getScriptIface()
|
MainMenuScripting *getScriptIface()
|
||||||
{
|
{
|
||||||
return m_script;
|
return m_script.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,17 +195,19 @@ private:
|
|||||||
scene::ISceneManager *m_smgr = nullptr;
|
scene::ISceneManager *m_smgr = nullptr;
|
||||||
/** pointer to data beeing transfered back to main game handling */
|
/** pointer to data beeing transfered back to main game handling */
|
||||||
MainMenuData *m_data = nullptr;
|
MainMenuData *m_data = nullptr;
|
||||||
/** pointer to texture source */
|
/** texture source */
|
||||||
ISimpleTextureSource *m_texture_source = nullptr;
|
std::unique_ptr<ISimpleTextureSource> m_texture_source;
|
||||||
/** pointer to soundmanager*/
|
/** sound fetcher, used by sound manager*/
|
||||||
ISoundManager *m_sound_manager = nullptr;
|
MenuMusicFetcher m_soundfetcher{};
|
||||||
|
/** sound manager*/
|
||||||
|
std::unique_ptr<ISoundManager> m_sound_manager;
|
||||||
|
|
||||||
/** representation of form source to be used in mainmenu formspec */
|
/** representation of form source to be used in mainmenu formspec */
|
||||||
FormspecFormSource *m_formspecgui = nullptr;
|
FormspecFormSource *m_formspecgui = nullptr;
|
||||||
/** formspec input receiver */
|
/** formspec input receiver */
|
||||||
TextDestGuiEngine *m_buttonhandler = nullptr;
|
TextDestGuiEngine *m_buttonhandler = nullptr;
|
||||||
/** the formspec menu */
|
/** the formspec menu */
|
||||||
GUIFormSpecMenu *m_menu = nullptr;
|
irr_ptr<GUIFormSpecMenu> m_menu;
|
||||||
|
|
||||||
/** reference to kill variable managed by SIGINT handler */
|
/** reference to kill variable managed by SIGINT handler */
|
||||||
bool &m_kill;
|
bool &m_kill;
|
||||||
@ -214,7 +216,7 @@ private:
|
|||||||
bool m_startgame = false;
|
bool m_startgame = false;
|
||||||
|
|
||||||
/** scripting interface */
|
/** scripting interface */
|
||||||
MainMenuScripting *m_script = nullptr;
|
std::unique_ptr<MainMenuScripting> m_script;
|
||||||
|
|
||||||
/** script basefolder */
|
/** script basefolder */
|
||||||
std::string m_scriptdir = "";
|
std::string m_scriptdir = "";
|
||||||
@ -285,7 +287,7 @@ private:
|
|||||||
/** absolute time of last cloud processing */
|
/** absolute time of last cloud processing */
|
||||||
u32 lasttime;
|
u32 lasttime;
|
||||||
/** pointer to cloud class */
|
/** pointer to cloud class */
|
||||||
Clouds *clouds = nullptr;
|
irr_ptr<Clouds> clouds;
|
||||||
/** camera required for drawing clouds */
|
/** camera required for drawing clouds */
|
||||||
scene::ICameraSceneNode *camera = nullptr;
|
scene::ICameraSceneNode *camera = nullptr;
|
||||||
};
|
};
|
||||||
|
@ -516,7 +516,7 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
|
|||||||
engine->m_parent,
|
engine->m_parent,
|
||||||
-1,
|
-1,
|
||||||
engine->m_menumanager,
|
engine->m_menumanager,
|
||||||
engine->m_texture_source);
|
engine->m_texture_source.get());
|
||||||
kmenu->drop();
|
kmenu->drop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user