mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02:00
Use smart-ptrs in GUIEngine
This commit is contained in:
parent
ceec560779
commit
b201c03625
@ -138,26 +138,26 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
||||
m_data(data),
|
||||
m_kill(kill)
|
||||
{
|
||||
//initialize texture pointers
|
||||
// initialize texture pointers
|
||||
for (image_definition &texture : m_textures) {
|
||||
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());
|
||||
// create texture source
|
||||
m_texture_source = std::make_unique<MenuTextureSource>(rendering_engine->get_video_driver());
|
||||
|
||||
//create soundmanager
|
||||
MenuMusicFetcher soundfetcher;
|
||||
// create soundmanager
|
||||
#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
|
||||
// create topleft header
|
||||
m_toplefttext = L"";
|
||||
|
||||
core::rect<s32> rect(0, 0, g_fontengine->getTextWidth(m_toplefttext.c_str()),
|
||||
@ -167,20 +167,22 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
||||
m_irr_toplefttext = gui::StaticText::add(rendering_engine->get_gui_env(),
|
||||
m_toplefttext, rect, false, true, 0, -1);
|
||||
|
||||
//create formspecsource
|
||||
m_formspecgui = new FormspecFormSource("");
|
||||
// create formspecsource
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,38 +186,40 @@ private:
|
||||
/** update size of topleftext element */
|
||||
void updateTopLeftTextSize();
|
||||
|
||||
RenderingEngine *m_rendering_engine = nullptr;
|
||||
RenderingEngine *m_rendering_engine = nullptr;
|
||||
/** parent gui element */
|
||||
gui::IGUIElement *m_parent = nullptr;
|
||||
gui::IGUIElement *m_parent = nullptr;
|
||||
/** manager to add menus to */
|
||||
IMenuManager *m_menumanager = nullptr;
|
||||
IMenuManager *m_menumanager = nullptr;
|
||||
/** scene manager to add scene elements to */
|
||||
scene::ISceneManager *m_smgr = nullptr;
|
||||
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;
|
||||
MainMenuData *m_data = 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;
|
||||
FormspecFormSource *m_formspecgui = nullptr;
|
||||
/** formspec input receiver */
|
||||
TextDestGuiEngine *m_buttonhandler = nullptr;
|
||||
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;
|
||||
bool &m_kill;
|
||||
|
||||
/** variable used to abort menu and return back to main game handling */
|
||||
bool m_startgame = false;
|
||||
bool m_startgame = false;
|
||||
|
||||
/** scripting interface */
|
||||
MainMenuScripting *m_script = nullptr;
|
||||
std::unique_ptr<MainMenuScripting> m_script;
|
||||
|
||||
/** script basefolder */
|
||||
std::string m_scriptdir = "";
|
||||
std::string m_scriptdir = "";
|
||||
|
||||
void setFormspecPrepend(const std::string &fs);
|
||||
|
||||
@ -281,11 +283,11 @@ private:
|
||||
/** internam data required for drawing clouds */
|
||||
struct clouddata {
|
||||
/** delta time since last cloud processing */
|
||||
f32 dtime;
|
||||
f32 dtime;
|
||||
/** absolute time of last cloud processing */
|
||||
u32 lasttime;
|
||||
u32 lasttime;
|
||||
/** pointer to cloud class */
|
||||
Clouds *clouds = nullptr;
|
||||
irr_ptr<Clouds> clouds;
|
||||
/** camera required for drawing clouds */
|
||||
scene::ICameraSceneNode *camera = nullptr;
|
||||
};
|
||||
|
@ -508,7 +508,7 @@ int ModApiMainMenu::l_check_mod_configuration(lua_State *L)
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_show_keys_menu(lua_State *L)
|
||||
{
|
||||
GUIEngine* engine = getGuiEngine(L);
|
||||
GUIEngine *engine = getGuiEngine(L);
|
||||
sanity_check(engine != NULL);
|
||||
|
||||
GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user