refacto: remove get_gui_env & draw_load_screen from RenderingEngine singleton

This commit is contained in:
Loic Blot 2021-04-29 20:38:35 +02:00 committed by Loïc Blot
parent a93712458b
commit 48d5abd5be
11 changed files with 38 additions and 46 deletions

@ -1731,7 +1731,7 @@ typedef struct TextureUpdateArgs {
ITextureSource *tsrc; ITextureSource *tsrc;
} TextureUpdateArgs; } TextureUpdateArgs;
void texture_update_progress(void *args, u32 progress, u32 max_progress) void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress)
{ {
TextureUpdateArgs* targs = (TextureUpdateArgs*) args; TextureUpdateArgs* targs = (TextureUpdateArgs*) args;
u16 cur_percent = ceil(progress / (double) max_progress * 100.); u16 cur_percent = ceil(progress / (double) max_progress * 100.);
@ -1750,7 +1750,7 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress)
targs->last_time_ms = time_ms; targs->last_time_ms = time_ms;
std::basic_stringstream<wchar_t> strm; std::basic_stringstream<wchar_t> strm;
strm << targs->text_base << " " << targs->last_percent << "%..."; strm << targs->text_base << " " << targs->last_percent << "%...";
RenderingEngine::draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0, m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
72 + (u16) ((18. / 100.) * (double) targs->last_percent), true); 72 + (u16) ((18. / 100.) * (double) targs->last_percent), true);
} }
} }
@ -1804,7 +1804,7 @@ void Client::afterContentReceived()
tu_args.last_percent = 0; tu_args.last_percent = 0;
tu_args.text_base = wgettext("Initializing nodes"); tu_args.text_base = wgettext("Initializing nodes");
tu_args.tsrc = m_tsrc; tu_args.tsrc = m_tsrc;
m_nodedef->updateTextures(this, texture_update_progress, &tu_args); m_nodedef->updateTextures(this, &tu_args);
delete[] tu_args.text_base; delete[] tu_args.text_base;
// Start mesh update thread after setting up content definitions // Start mesh update thread after setting up content definitions

@ -347,6 +347,7 @@ public:
float mediaReceiveProgress(); float mediaReceiveProgress();
void afterContentReceived(); void afterContentReceived();
void showUpdateProgressTexture(void *args, u32 progress, u32 max_progress);
float getRTT(); float getRTT();
float getCurRate(); float getCurRate();

@ -2047,8 +2047,8 @@ void Game::openInventory()
|| !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) { || !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) {
TextDest *txt_dst = new TextDestPlayerInventory(client); TextDest *txt_dst = new TextDestPlayerInventory(client);
auto *&formspec = m_game_ui->updateFormspec(""); auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src, GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFormSpec(fs_src->getForm(), inventoryloc); formspec->setFormSpec(fs_src->getForm(), inventoryloc);
} }
@ -2626,8 +2626,8 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
new TextDestPlayerInventory(client, *(event->show_formspec.formname)); new TextDestPlayerInventory(client, *(event->show_formspec.formname));
auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname)); auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
GUIFormSpecMenu::create(formspec, client, &input->joystick, GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
fs_src, txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
} }
delete event->show_formspec.formspec; delete event->show_formspec.formspec;
@ -2639,8 +2639,8 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec); FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec);
LocalFormspecHandler *txt_dst = LocalFormspecHandler *txt_dst =
new LocalFormspecHandler(*event->show_formspec.formname, client); new LocalFormspecHandler(*event->show_formspec.formname, client);
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick, GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, m_rendering_engine->get_gui_env(),
fs_src, txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
delete event->show_formspec.formspec; delete event->show_formspec.formspec;
delete event->show_formspec.formname; delete event->show_formspec.formname;
@ -3332,8 +3332,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client); TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client);
auto *&formspec = m_game_ui->updateFormspec(""); auto *&formspec = m_game_ui->updateFormspec("");
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src, GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFormSpec(meta->getString("formspec"), inventoryloc); formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
return false; return false;
@ -4082,8 +4082,8 @@ void Game::showDeathFormspec()
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client); LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client);
auto *&formspec = m_game_ui->getFormspecGUI(); auto *&formspec = m_game_ui->getFormspecGUI();
GUIFormSpecMenu::create(formspec, client, &input->joystick, GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
fs_src, txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFocus("btn_respawn"); formspec->setFocus("btn_respawn");
} }
@ -4216,8 +4216,8 @@ void Game::showPauseMenu()
LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU");
auto *&formspec = m_game_ui->getFormspecGUI(); auto *&formspec = m_game_ui->getFormspecGUI();
GUIFormSpecMenu::create(formspec, client, &input->joystick, GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(),
fs_src, txt_dst, client->getFormspecPrepend(), sound); &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound);
formspec->setFocus("btn_continue"); formspec->setFocus("btn_continue");
formspec->doPause = true; formspec->doPause = true;

@ -493,7 +493,7 @@ bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file)
Text will be removed when the screen is drawn the next time. Text will be removed when the screen is drawn the next time.
Additionally, a progressbar can be drawn when percent is set between 0 and 100. Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/ */
void RenderingEngine::_draw_load_screen(const std::wstring &text, void RenderingEngine::draw_load_screen(const std::wstring &text,
gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime,
int percent, bool clouds) int percent, bool clouds)
{ {

@ -95,19 +95,14 @@ public:
return m_device->getTimer()->getTime(); return m_device->getTimer()->getTime();
} }
static gui::IGUIEnvironment *get_gui_env() gui::IGUIEnvironment *get_gui_env()
{ {
sanity_check(s_singleton && s_singleton->m_device); return m_device->getGUIEnvironment();
return s_singleton->m_device->getGUIEnvironment();
} }
inline static void draw_load_screen(const std::wstring &text, void draw_load_screen(const std::wstring &text,
gui::IGUIEnvironment *guienv, ITextureSource *tsrc, gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
float dtime = 0, int percent = 0, bool clouds = true) float dtime = 0, int percent = 0, bool clouds = true);
{
s_singleton->_draw_load_screen(
text, guienv, tsrc, dtime, percent, clouds);
}
void draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds); void draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds);
void draw_scene(video::SColor skycolor, bool show_hud, void draw_scene(video::SColor skycolor, bool show_hud,
@ -125,10 +120,6 @@ public:
static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers(); static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
private: private:
void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
ITextureSource *tsrc, float dtime = 0, int percent = 0,
bool clouds = true);
v2u32 _getWindowSize() const; v2u32 _getWindowSize() const;
std::unique_ptr<RenderingCore> core; std::unique_ptr<RenderingCore> core;

@ -170,6 +170,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
-1, -1,
m_menumanager, m_menumanager,
NULL /* &client */, NULL /* &client */,
m_rendering_engine->get_gui_env(),
m_texture_source, m_texture_source,
m_sound_manager, m_sound_manager,
m_formspecgui, m_formspecgui,

@ -96,10 +96,10 @@ inline u32 clamp_u8(s32 value)
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick, GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
Client *client, ISimpleTextureSource *tsrc, ISoundManager *sound_manager, Client *client, gui::IGUIEnvironment *guienv, ISimpleTextureSource *tsrc,
IFormSource *fsrc, TextDest *tdst, ISoundManager *sound_manager, IFormSource *fsrc, TextDest *tdst,
const std::string &formspecPrepend, bool remap_dbl_click): const std::string &formspecPrepend, bool remap_dbl_click):
GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click), GUIModalMenu(guienv, parent, id, menumgr, remap_dbl_click),
m_invmgr(client), m_invmgr(client),
m_tsrc(tsrc), m_tsrc(tsrc),
m_sound_manager(sound_manager), m_sound_manager(sound_manager),
@ -145,12 +145,12 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
} }
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client, void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src,
const std::string &formspecPrepend, ISoundManager *sound_manager) TextDest *txt_dest, const std::string &formspecPrepend, ISoundManager *sound_manager)
{ {
if (cur_formspec == nullptr) { if (cur_formspec == nullptr) {
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr, cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
client, client->getTextureSource(), sound_manager, fs_src, client, guienv, client->getTextureSource(), sound_manager, fs_src,
txt_dest, formspecPrepend); txt_dest, formspecPrepend);
cur_formspec->doPause = false; cur_formspec->doPause = false;

@ -152,6 +152,7 @@ public:
gui::IGUIElement* parent, s32 id, gui::IGUIElement* parent, s32 id,
IMenuManager *menumgr, IMenuManager *menumgr,
Client *client, Client *client,
gui::IGUIEnvironment *guienv,
ISimpleTextureSource *tsrc, ISimpleTextureSource *tsrc,
ISoundManager *sound_manager, ISoundManager *sound_manager,
IFormSource* fs_src, IFormSource* fs_src,
@ -162,8 +163,9 @@ public:
~GUIFormSpecMenu(); ~GUIFormSpecMenu();
static void create(GUIFormSpecMenu *&cur_formspec, Client *client, static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src,
const std::string &formspecPrepend, ISoundManager *sound_manager); TextDest *txt_dest, const std::string &formspecPrepend,
ISoundManager *sound_manager);
void setFormSpec(const std::string &formspec_string, void setFormSpec(const std::string &formspec_string,
const InventoryLocation &current_inventory_location) const InventoryLocation &current_inventory_location)

@ -1435,9 +1435,7 @@ void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &o
} }
} }
void NodeDefManager::updateTextures(IGameDef *gamedef, void NodeDefManager::updateTextures(IGameDef *gamedef, void *progress_callback_args)
void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress),
void *progress_callback_args)
{ {
#ifndef SERVER #ifndef SERVER
infostream << "NodeDefManager::updateTextures(): Updating " infostream << "NodeDefManager::updateTextures(): Updating "
@ -1456,7 +1454,7 @@ void NodeDefManager::updateTextures(IGameDef *gamedef,
for (u32 i = 0; i < size; i++) { for (u32 i = 0; i < size; i++) {
ContentFeatures *f = &(m_content_features[i]); ContentFeatures *f = &(m_content_features[i]);
f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings); f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings);
progress_callback(progress_callback_args, i, size); client->showUpdateProgressTexture(progress_callback_args, i, size);
} }
#endif #endif
} }

@ -660,9 +660,7 @@ public:
* total ContentFeatures. * total ContentFeatures.
* @param progress_cbk_args passed to the callback function * @param progress_cbk_args passed to the callback function
*/ */
void updateTextures(IGameDef *gamedef, void updateTextures(IGameDef *gamedef, void *progress_cbk_args);
void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
void *progress_cbk_args);
/*! /*!
* Writes the content of this manager to the given output stream. * Writes the content of this manager to the given output stream.

@ -397,7 +397,8 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
GUIEngine* engine = getGuiEngine(L); GUIEngine* engine = getGuiEngine(L);
sanity_check(engine != NULL); sanity_check(engine != NULL);
GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(), GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(
engine->m_rendering_engine->get_gui_env(),
engine->m_parent, engine->m_parent,
-1, -1,
engine->m_menumanager, engine->m_menumanager,
@ -694,7 +695,7 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
bool is_file_select = readParam<bool>(L, 3); bool is_file_select = readParam<bool>(L, 3);
GUIFileSelectMenu* fileOpenMenu = GUIFileSelectMenu* fileOpenMenu =
new GUIFileSelectMenu(RenderingEngine::get_gui_env(), new GUIFileSelectMenu(engine->m_rendering_engine->get_gui_env(),
engine->m_parent, engine->m_parent,
-1, -1,
engine->m_menumanager, engine->m_menumanager,