1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Some globals (un-)init fixes

This commit is contained in:
sfan5 2024-04-11 13:54:09 +02:00
parent 2af5191070
commit d8190e1c5f
16 changed files with 58 additions and 62 deletions

View file

@ -47,11 +47,6 @@ gui::IGUIEnvironment *guienv = nullptr;
gui::IGUIStaticText *guiroot = nullptr;
MainMenuManager g_menumgr;
bool isMenuActive()
{
return g_menumgr.menuCount() != 0;
}
// Passed to menus to allow disconnecting and exiting
MainGameCallback *g_gamecallback = nullptr;
@ -74,13 +69,20 @@ ClientLauncher::~ClientLauncher()
{
delete input;
delete receiver;
delete g_fontengine;
g_fontengine = nullptr;
delete g_gamecallback;
g_gamecallback = nullptr;
guiroot = nullptr;
guienv = nullptr;
assert(g_menumgr.menuCount() == 0);
delete m_rendering_engine;
// delete event receiver only after all Irrlicht stuff is gone
delete receiver;
#if USE_SOUND
g_sound_manager_singleton.reset();
#endif
@ -103,10 +105,8 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
g_sound_manager_singleton = createSoundManagerSingleton();
#endif
if (!init_engine()) {
errorstream << "Could not initialize game engine." << std::endl;
if (!init_engine())
return false;
}
if (!m_rendering_engine->get_video_driver()) {
errorstream << "Could not initialize video driver." << std::endl;
@ -129,7 +129,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
init_guienv(guienv);
g_fontengine = new FontEngine(guienv);
FATAL_ERROR_IF(!g_fontengine, "Font engine creation failed.");
// Create the menu clouds
// This is only global so it can be used by RenderingEngine::draw_load_screen().
@ -301,8 +300,12 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar
bool ClientLauncher::init_engine()
{
receiver = new MyEventReceiver();
m_rendering_engine = new RenderingEngine(receiver);
return m_rendering_engine->get_raw_device() != nullptr;
try {
m_rendering_engine = new RenderingEngine(receiver);
} catch (std::exception &e) {
errorstream << e.what() << std::endl;
}
return !!m_rendering_engine;
}
void ClientLauncher::init_input()

View file

@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "camera.h" // CameraModes
#include "collision.h"
#include "content_cso.h"
#include "clientobject.h"
#include "environment.h"
#include "itemdef.h"
#include "localplayer.h"
@ -218,14 +219,15 @@ private:
};
// Prototype
TestCAO proto_TestCAO(NULL, NULL);
static TestCAO proto_TestCAO(nullptr, nullptr);
TestCAO::TestCAO(Client *client, ClientEnvironment *env):
ClientActiveObject(0, client, env),
m_node(NULL),
m_position(v3f(0,10*BS,0))
{
ClientActiveObject::registerType(getType(), create);
if (!client)
ClientActiveObject::registerType(getType(), create);
}
std::unique_ptr<ClientActiveObject> TestCAO::create(Client *client, ClientEnvironment *env)
@ -322,8 +324,6 @@ void TestCAO::processMessage(const std::string &data)
GenericCAO
*/
#include "clientobject.h"
GenericCAO::GenericCAO(Client *client, ClientEnvironment *env):
ClientActiveObject(0, client, env)
{
@ -2082,4 +2082,4 @@ void GenericCAO::updateMeshCulling()
}
// Prototype
GenericCAO proto_GenericCAO(NULL, NULL);
static GenericCAO proto_GenericCAO(nullptr, nullptr);

View file

@ -27,16 +27,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlicht_changes/CGUITTFont.h"
#include "util/numeric.h" // rangelim
/** maximum size distance for getting a "similar" font size */
#define MAX_FONT_SIZE_OFFSET 10
/** reference to access font engine, has to be initialized by main */
FontEngine* g_fontengine = NULL;
FontEngine *g_fontengine = nullptr;
/** callback to be used on change of font size setting */
static void font_setting_changed(const std::string &name, void *userdata)
{
g_fontengine->readSettings();
if (g_fontengine)
g_fontengine->readSettings();
}
/******************************************************************************/
@ -226,7 +224,7 @@ gui::IGUIFont *FontEngine::initFont(const FontSpec &spec)
u16 divisible_by = g_settings->getU16(setting_prefix + "font_size_divisible_by");
if (divisible_by > 1) {
size = std::max<u32>(
std::round((double)size / divisible_by) * divisible_by, divisible_by);
std::round((float)size / divisible_by) * divisible_by, divisible_by);
}
sanity_check(size != 0);

View file

@ -29,12 +29,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
* converting textures back into images repeatedly, and some don't even
* allow it at all.
*/
std::map<io::path, video::IImage *> g_imgCache;
static std::map<io::path, video::IImage *> g_imgCache;
/* Maintain a static cache of all pre-scaled textures. These need to be
* cleared as well when the cached images.
*/
std::map<io::path, video::ITexture *> g_txrCache;
static std::map<io::path, video::ITexture *> g_txrCache;
/* Manually insert an image into the cache, useful to avoid texture-to-image
* conversion whenever we can intercept it.

View file

@ -355,12 +355,11 @@ const KeyPress CancelKey("KEY_CANCEL");
*/
// A simple cache for quicker lookup
std::unordered_map<std::string, KeyPress> g_key_setting_cache;
static std::unordered_map<std::string, KeyPress> g_key_setting_cache;
KeyPress getKeySetting(const char *settingname)
{
std::unordered_map<std::string, KeyPress>::iterator n;
n = g_key_setting_cache.find(settingname);
auto n = g_key_setting_cache.find(settingname);
if (n != g_key_setting_cache.end())
return n->second;

View file

@ -253,8 +253,11 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver)
RenderingEngine::~RenderingEngine()
{
sanity_check(s_singleton == this);
core.reset();
m_device->closeDevice();
m_device->drop();
s_singleton = nullptr;
}
@ -278,10 +281,7 @@ void RenderingEngine::removeMesh(const scene::IMesh* mesh)
void RenderingEngine::cleanupMeshCache()
{
auto mesh_cache = m_device->getSceneManager()->getMeshCache();
while (mesh_cache->getMeshCount() != 0) {
if (scene::IAnimatedMesh *mesh = mesh_cache->getMeshByIndex(0))
mesh_cache->removeMesh(mesh);
}
mesh_cache->clear();
}
bool RenderingEngine::setupTopLevelWindow()

View file

@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
/*
A cache from shader name to shader path
*/
MutexedMap<std::string, std::string> g_shadername_to_path_cache;
static MutexedMap<std::string, std::string> g_shadername_to_path_cache;
/*
Gets the path to a shader by first checking if the file

View file

@ -191,7 +191,7 @@ private:
scene::IMesh *m_cube;
};
ExtrusionMeshCache *g_extrusion_mesh_cache = NULL;
static ExtrusionMeshCache *g_extrusion_mesh_cache = nullptr;
WieldMeshSceneNode::WieldMeshSceneNode(scene::ISceneManager *mgr, s32 id, bool lighting):