Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate irrlicht references and use a singleton #6041

Merged
merged 5 commits into from Jun 26, 2017

Conversation

nerzhul
Copy link
Member

@nerzhul nerzhul commented Jun 24, 2017

Isolate irrlichtdevice to a RenderingEngine class, with various static function related to the device singleton

This permits to remove many function cost passing irrlicht or scene_mgr or videodriver and isolate minetest code from irrlicht interfaces.
This is a first step needed to minetest to properly have a rendering interface permitting to use another rendering engine, if needed.

@nerzhul nerzhul added the Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements label Jun 24, 2017
move getSupportedVideoDrivers to Device3D

Add Device3D singleton & use it in various places

Rename Device3D to Rendering engine & add helper functions to various device pointers

More singleton work

RenderingEngine owns draw_load_screen

move draw functions to RenderingEngine

Reduce IrrlichtDevice exposure and guienvironment

RenderingEngine: Expose get_timer_time() to remove device from guiEngine

Make irrlichtdevice & scene manager less exposed
void init_texture(const v2u32& screensize,
video::ITexture** texture, const char* name);

video::ITexture* draw_image(const v2u32 &screensize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

video::ITexture *draw_image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

video::ITexture *drawImage


void draw_pageflip_3d_mode(Camera *camera, bool show_hud,
Hud *hud, const v2u32 &screensize, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment* guienv, const video::SColor &skycolor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gui::IGUIEnvironment *guienv

const video::SColor &skycolor);

void init_texture(const v2u32& screensize,
video::ITexture** texture, const char* name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

video::ITexture **texture, const char *name

Camera *camera, Hud *hud, bool draw_wield_tool, Client *client,
gui::IGUIEnvironment *guienv, const video::SColor &skycolor);

video::ITexture* draw_hud(const v2u32 &screensize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -238,15 +239,15 @@ class SourceImageCache
return NULL;
}
// Primarily fetches from cache, secondarily tries to read from filesystem
video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device)
video::IImage* getOrLoad(const std::string &name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

{
std::map<std::string, video::IImage*>::iterator n;
n = m_images.find(name);
if (n != m_images.end()){
n->second->grab(); // Grab for caller
return n->second;
}
video::IVideoDriver* driver = device->getVideoDriver();
video::IVideoDriver* driver = RenderingEngine::get_video_driver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -435,16 +428,13 @@ class TextureSource : public IWritableTextureSource
bool m_setting_anisotropic_filter;
};

IWritableTextureSource* createTextureSource(IrrlichtDevice *device)
IWritableTextureSource* createTextureSource()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -461,7 +451,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):

TextureSource::~TextureSource()
{
video::IVideoDriver* driver = m_device->getVideoDriver();
video::IVideoDriver* driver = RenderingEngine::get_video_driver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

m_source_image_existence.set(name, true);
}

void TextureSource::rebuildImagesAndTextures()
{
MutexAutoLock lock(m_textureinfo_cache_mutex);

video::IVideoDriver* driver = m_device->getVideoDriver();
video::IVideoDriver* driver = RenderingEngine::get_video_driver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -1196,13 +1181,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
video::IImage *& baseimg)
{
const char escape = '\\'; // same as in generateImage()
video::IVideoDriver* driver = m_device->getVideoDriver();
video::IVideoDriver* driver = RenderingEngine::get_video_driver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -1275,15 +1260,15 @@ bool TextureSource::generateImagePart(std::string part_of_name,
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
} else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
// Upscale overlying image
video::IImage* scaled_image = m_device->getVideoDriver()->
video::IImage* scaled_image = RenderingEngine::get_video_driver()->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

src/particles.h Outdated
void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
LocalPlayer *player, v3s16 pos, const MapNode &n,
const ContentFeatures &f);
void addNodeParticle(IGameDef* gamedef, LocalPlayer *player, v3s16 pos,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

@@ -843,7 +839,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
if (ModApiMainMenu::isMinetestPath(absolute_destination)) {
fs::CreateAllDirs(absolute_destination);

io::IFileSystem* fs = engine->m_device->getFileSystem();
io::IFileSystem* fs = RenderingEngine::get_filesystem();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

src/shader.cpp Outdated
@@ -332,17 +331,16 @@ class ShaderSource : public IWritableShaderSource
std::vector<ShaderCallback *> m_callbacks;
};

IWritableShaderSource* createShaderSource(IrrlichtDevice *device)
IWritableShaderSource* createShaderSource()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

src/shader.cpp Outdated
}

/*
Generate shader given the shader name.
*/
ShaderInfo generate_shader(const std::string &name,
u8 material_type, u8 drawtype,
IrrlichtDevice *device, std::vector<ShaderCallback *> &callbacks,
u8 material_type, u8 drawtype, std::vector<ShaderCallback *> &callbacks,
const std::vector<IShaderConstantSetterFactory*> &setter_factories,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<IShaderConstantSetterFactory *>

src/shader.cpp Outdated
}

bool enable_shaders = g_settings->getBool("enable_shaders");
if (!enable_shaders)
return shaderinfo;

video::IVideoDriver* driver = device->getVideoDriver();
sanity_check(driver);
video::IVideoDriver* driver = RenderingEngine::get_video_driver();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Copy link
Contributor

@Dumbeldor Dumbeldor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@minetest minetest deleted a comment from Dumbeldor Jun 24, 2017
static void setXorgClassHint(const video::SExposedVideoData &video_data,
const std::string &name);
bool setWindowIcon();
bool setXorgWindowIconFromPath(const std::string &icon_file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these part of the rendering engine?
IMO porting makes more sense

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setXorgWindowIconFromPath uses Irrlicht:

video::IVideoDriver *v_driver = m_device->getVideoDriver();
video::IImageLoader *image_loader = NULL;

then it make sense to link it with rendering engine

@sfan5 sfan5 added the Non-trivial A large amount of work is required to address this (sometimes to the point of being infeasible). label Jun 24, 2017
@nerzhul
Copy link
Member Author

nerzhul commented Jun 25, 2017

@sfan5 i don't know if it's really non trivial, it's a huge rework it's right, but the change itself in all engine is not difficult it just take some time :p

EDIT: also note i cleanup many IrrlichtDevice references, VideoDriver, SceneManager and guiEnvironment but all it not done yet, i prefer cleanup other parts after making this PR merged to ensure the work is okay

@nerzhul
Copy link
Member Author

nerzhul commented Jun 25, 2017

Okay PR is ready for merge if CI pass. @sfan5 @SmallJoker @Zeno- please do a review

…layDensity, getDisplaySize to RenderingEngine

Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly
return s_singleton->m_device->getGUIEnvironment();
}

static void draw_load_screen(const std::wstring &text,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inline draw_scene but not here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because function is not inlined itself, it's split between declaration & definition

static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();

private:
enum paralax_sign
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parallax_sign

irr::core::vector3df eye_pos;
irr::core::matrix4 movement;
movement.setTranslation(irr::core::vector3df(
(int)psign * g_settings->getFloat("3d_paralax_strength"), 0.0f,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/paralax/parallax over the whole file 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a new setting but an old setting, this is not for this PR, please do a fix PR after merging this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the enum as it's a private enum, but i don't modify the setting name which is out of this PR scope

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll do that

void init_texture(const v2u32 &screensize, video::ITexture **texture,
const char *name);

video::ITexture *draw_image(const v2u32 &screensize, paralax_sign psign,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parallax_sign psign for spelling fix

irr::video::ECF_A8R8G8B8);
}

video::ITexture *RenderingEngine::draw_image(const v2u32 &screensize, paralax_sign psign,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parallax_sign psign

@minetest minetest deleted a comment from pilino1234 Jun 25, 2017
@minetest minetest deleted a comment from pilino1234 Jun 25, 2017
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works.

@nerzhul nerzhul merged commit b3a36f7 into minetest:master Jun 26, 2017
@nerzhul nerzhul deleted the irrlicht_isolation branch August 19, 2017 10:23
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 11, 2019
* Add Device3D class which will contain IrrlichtDevice interface

move getSupportedVideoDrivers to Device3D

Add Device3D singleton & use it in various places

Rename Device3D to Rendering engine & add helper functions to various device pointers

More singleton work

RenderingEngine owns draw_load_screen

move draw functions to RenderingEngine

Reduce IrrlichtDevice exposure and guienvironment

RenderingEngine: Expose get_timer_time() to remove device from guiEngine

Make irrlichtdevice & scene manager less exposed

* Code style fixes

* Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine

Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly

* enum paralax => enum parallax
osjc pushed a commit to osjc/minetest that referenced this pull request Jan 23, 2019
* Add Device3D class which will contain IrrlichtDevice interface

move getSupportedVideoDrivers to Device3D

Add Device3D singleton & use it in various places

Rename Device3D to Rendering engine & add helper functions to various device pointers

More singleton work

RenderingEngine owns draw_load_screen

move draw functions to RenderingEngine

Reduce IrrlichtDevice exposure and guienvironment

RenderingEngine: Expose get_timer_time() to remove device from guiEngine

Make irrlichtdevice & scene manager less exposed

* Code style fixes

* Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine

Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly

* enum paralax => enum parallax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Tasks to keep the codebase and related parts in order, including architectural improvements Non-trivial A large amount of work is required to address this (sometimes to the point of being infeasible). One approval ✅ ◻️
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants