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

Rmlui integration #1076

Closed

Conversation

loveridge
Copy link
Collaborator

Ready for general reviews.

This MR integrates RmlUi into LuaUI so that Rml interfaces can be created in unsynced lua widgets. Overhead for games not adding RmlUi widgets is negligible.

Examples of two widgets using the rmlui interface can be found here.

@loveridge loveridge changed the title Rmlui integration fork Rmlui integration Nov 15, 2023
@@ -68,6 +69,9 @@ IMouseInput::~IMouseInput()

bool IMouseInput::HandleSDLMouseEvent(const SDL_Event& event)
{
if (!mouse->ButtonPressed() && RmlGui::ProcessMouseEvent(event)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why the !mouse->ButtonPressed() check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only want to give a mouse event to RmlUi if the mouse isn't currently performing a drag. Otherwise box selections get stuck when the mouse goes over an Rml element.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I've taken the liberty of putting that as a comment in the code ca9aeb0

CRmlInputReceiver() : CInputReceiver(FRONT), rml_active(false){};
~CRmlInputReceiver() = default;

bool IsAbove(int x, int y) { return rml_active; };
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this check if any actual gui panel is underneath?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinks like a dropdown combobox could drop below a gui panel?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, by "gui panel" I mean anything drawn by rml at the coordinates being asked about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IsAbove is used for determining which cursor icon should be displayed. I track if the mouse is over an rml element in ProcessMouseEvent and just return if rml is capturing the mouse since the xy is the mouse location.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good, put that in a comment at the function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added the comment, and integrated the mouse event handling with the main mouse handler

@@ -172,6 +172,10 @@ void CLuaHandle::KillLua(bool inFreeHandler)
if (inFreeHandler)
Shutdown();

if(rmlui) {
RmlGui::Reload();
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be some sort of shutdown and not reload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Completed. On luaui shutdown we will remove the lua rml plugin and all contexts/documents created from lua. This allows the engine to continue to use rml for it's interface.

@p2004a p2004a force-pushed the rmlui-integration-fork branch from ca9aeb0 to 449a692 Compare December 30, 2023 17:45
@@ -68,6 +69,10 @@ IMouseInput::~IMouseInput()

bool IMouseInput::HandleSDLMouseEvent(const SDL_Event& event)
{
/* Only want to give a mouse event to RmlUI if the mouse isn't currently performing a drag.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move this to rts/Game/UI/MouseHandler.cpp line 276.

@@ -1,5 +1,7 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it?

/*
* This source file is part of RmlUi, the HTML/CSS Interface Middleware
* This source file is dervied from the source code of RmlUi, the HTML/CSS Interface Middleware
Copy link
Collaborator

Choose a reason for hiding this comment

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

t. dervish

Suggested change
* This source file is dervied from the source code of RmlUi, the HTML/CSS Interface Middleware
* This source file is derived from the source code of RmlUi, the HTML/CSS Interface Middleware

but also idk if it makes sense to modify this. did we actually change anything substantial?

Copy link
Member

Choose a reason for hiding this comment

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

There is only minor changes that I do not know the full impact of.
The one I noted is that the shader GLSL version was changed.

@@ -59,7 +59,7 @@ static void ExitSpringProcess(const char* msg, const char* caption, unsigned int

static void ExitSpringProcess(const char* msg, const char* caption, unsigned int flags)
{
LOG_L(L_ERROR, "[%s] errorMsg=\"%s\" msgCaption=\"%s\" mainThread=%d", __func__, msg, caption, Threading::IsMainThread());
LOG_L(L_FATAL, "[%s] errorMsg=\"%s\" msgCaption=\"%s\" mainThread=%d", __func__, msg, caption, Threading::IsMainThread());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could probably go to mainline separately

loveridge and others added 11 commits January 28, 2024 10:40
get rid of never-going-to-be-used code in RmlUi_Renderer_GL3
rename file/class to RmlUi_Renderer_GL3_Spring since it's now more deeply integrated with Spring
move VFSInterface to own files
…ces-cleanup

rts/Rml code cleanup + move general plugin init/destroy out of Lua-related code
…Texture code to be able to reuse already made textures
…Texture code to be able to reuse already made textures
@lhog
Copy link
Collaborator

lhog commented Jan 29, 2024

As outlined in Discord, please extract the engine/build system integration and exclude:

  1. Unrelated trailing space and other formatting changes
  2. Lua integration
  3. Changes to the 3rd party libs.

Let this draft serve as work-in-progress branch, but extract the above into another PR/branch so it's easy to review and integrate.

@@ -657,6 +657,10 @@ bool RenderInterface_GL3_Spring::GenerateTexture(Rml::TextureHandle& texture_han

void RenderInterface_GL3_Spring::ReleaseTexture(Rml::TextureHandle texture_handle)
{
// Something was using a texture loaded/managed outside of Rml. Do nothing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds worrisome, when can this happen? What if "the outside" frees the texture while RML is still using it?

Copy link
Member

@ChrisFloofyKitsune ChrisFloofyKitsune Jan 31, 2024

Choose a reason for hiding this comment

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

Then you end up getting a broken texture when you try to render.
Same thing that can happen if RML (or anything else) frees up a texture that's still in use elsewhere.

I think it's a better solution than copying the texture data needlessly. Though I suppose someone could force a copy to happen.

This check was added because of the <lua-texture> custom element which asks for texture handles from LuaOpenGLUtils::ParseTextureImage.
Which I made because I think loading in another copy of all the buildpics/icons for use by RML is a terrible idea.

Copy link
Member

@ChrisFloofyKitsune ChrisFloofyKitsune Jan 31, 2024

Choose a reason for hiding this comment

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

A copy texture function/element could also be made- for when you aren't certain that the original texture handle is going to stick around when you need it to.

@ChrisFloofyKitsune
Copy link
Member

ChrisFloofyKitsune commented Jan 31, 2024

As outlined in Discord, please extract the engine/build system integration and exclude:

1. Unrelated trailing space and other formatting changes
2. Lua integration
3. Changes to the 3rd party libs.

Let this draft serve as work-in-progress branch, but extract the above into another PR/branch so it's easy to review and integrate.

Here is the PR for part 1: the non lua stuff

#1261

@loveridge loveridge marked this pull request as ready for review February 14, 2024 05:05
@p2004a
Copy link
Collaborator

p2004a commented Apr 6, 2024

I'm closing this PR as it's being replaced by #1415.

The only difference is:

  • It's based on the engine rmlui-integration-fork so anybody can make PRs to that branch, not to your fork @loveridge. In addition, being main engine branch, we can create preview builds off it.
  • It contains the full history of this branch + more changes on top by @ChrisFloofyKitsune
  • It's rebased on the current stable engine version

@p2004a p2004a closed this Apr 6, 2024
@p2004a p2004a mentioned this pull request Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants