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
Migrate from libRocket to RmlUi #1715
Conversation
I do not know how CI passes, but here I can't compile at all, something unsets the -std=c++14 that I put in the CXXFLAGS, somewhere, somehow, and since this is required for RMLUI, it does not builds. Also, I think the review process could be easier if a pre-commit would do |
You can check out the The 1st commit I believe just contains the trivial find-and-replace stuff like Rocket -> Rml and CString -> c_str. I guess we have to replace that stuff at some point. I want it to be reviewable but I don't understand how putting it in a later commit would help, can you explain more? |
Nope, there's more than just that, I've seen stuff removed, notably.
Well, when the code have things like: |
@bmorel I've moved the most common and trivial renaming parts into a separate commit (the 2nd one). The 1st commit now consists of the original first 20 or so commits squashed together. The minimal stuff to get it to build and launch (though mostly without displaying anything). I used a define hack to delay the renaming stuff. |
Just realized this contradicts our compatibility guidelines by making it impossible to use master gamelogic with the latest release's DPKs. Thoughts anyone? Should it go on the 0.53 branch? |
It's fine to go on 0.53. |
How does it conflicts? The unvanquished.dpk also contains the GUI configuration files. If the RML changes are to be considered breaking compat, then some of the changes I made to bots also are, since I changed interface of BotGetHealScore (and probably other stuff) and the BTs are not in the nexe. What is likely required though, is to have this PR accompanied with the |
I want master gamelogic to be in a more-or-less usable state without any -pakpath flags, if you have the latest release installed. The bot changes were small enough that they still mostly work with 0.52 behavior trees. Similarly the yellow build shader is broken without new assets, but it's a minor point that doesn't prevent testing most things. |
Thanks for taking this over! |
It builds for me. I'll go test it some more later tonight. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only reviewed the 1st commit, which LGTM despite some very minor details.
I will continue reviewing the other commits later.
src/cgame/rocket/rocket.cpp
Outdated
@@ -196,34 +196,34 @@ class DaemonRenderInterface : public Rocket::Core::RenderInterface | |||
public: | |||
DaemonRenderInterface() { } | |||
|
|||
void RenderGeometry( Rocket::Core::Vertex *verticies, int numVerticies, int *indices, int numIndicies, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation ) | |||
void RenderGeometry( Rocket::Core::Vertex *verticies, int numVerticies, int *indices, int numIndicies, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation ) override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those changes (the override thing) could already be merged. Not that important though, let's not waste time on such details.
|
||
void SetTransform( const Rocket::Core::Matrix4f* transform ) override | ||
{ | ||
// TODO: implement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use and ASSERT( false ) in here? Just in case nobody ever fix that TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already have a Log::Warn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment was done when reading 1st commit, the warn was added in "RMLUI: warn if it calls unimplemented transform"
@@ -317,35 +320,31 @@ class RocketChatField : public Rocket::Core::Element, Rocket::Core::EventListene | |||
|
|||
void UpdateCursorPosition() | |||
{ | |||
if ( text_element->GetFontFaceHandle() == nullptr ) | |||
if ( text_element->GetFontFaceHandle() == 0 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from their code: RmlUi/Core/Types.h:using FontFaceHandle = uintptr_t;
GetFontFaceHandle() returns a pointer, so let's use a nullptr instead of 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uintptr_t is a kind of integer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I see:
- if ( text_element->GetFontFaceHandle() == nullptr )
+ if ( text_element->GetFontFaceHandle() == 0 )
You mean that 0, NULL are integers? That is technically true (even if this comment seems to disagree for some cases), but I don't see the point to change from a semantically clearer version to a semantically less clear version. To use 6 less characters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 is an integer, and if you have using FontFaceHandle = uintptr_t;
, then you should test for equality against the same type like slipher did, so ==0.
src/cgame/rocket/rocketElement.h
Outdated
@@ -53,7 +53,7 @@ class RocketElement : public Rocket::Core::Element | |||
RocketElement( const Rocket::Core::String &tag ) : Rocket::Core::Element( tag ) { } | |||
~RocketElement() { } | |||
|
|||
bool GetIntrinsicDimensions( Rocket::Core::Vector2f &dimension ) | |||
bool GetIntrinsicDimensions( Rocket::Core::Vector2f &dimension ) override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see previous comment about override (I won't annotate the other ones)
} | ||
|
||
if ( changed_properties.find( "image" ) != changed_properties.end() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking that this is not accidental change and that I understand (could be useful some day): image is no longer a property, but an attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the stuff you're talking about must have been deleted in the later commit which changes the class to inherit from ElementProgressBar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I didn't reviewed the squashed PR but each commits one by one
|
||
document->RemoveReference(); | ||
} | ||
// TODO: Remove. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this TODO is done in later commits? Can't really assert anything here, but maybe it would be possible to use deprecated attribute to avoid forgetting (would have a compiler warning, which can be checked or turned as error)?
Since C++14 is required for RMLUI anyway, let's use it?
src/cgame/rocket/rocket.cpp
Outdated
@@ -679,7 +679,8 @@ class EngineCursor | |||
} | |||
else if ( show_cursor ) | |||
{ | |||
mode = MouseMode::CustomCursor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe get some Log::Notice for this?
@@ -55,7 +55,7 @@ class RocketKeyBinder : public Rml::Core::Element, public Rml::Core::EventListen | |||
{ | |||
} | |||
|
|||
void OnAttributeChange( const Rml::Core::ElementAttributes &changed_attributes ) | |||
void OnAttributeChange( const Rml::Core::ElementAttributes &changed_attributes ) override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of those changes could have been done in the rocket code (would have fixed a bunch of warnings, too, and possibly could enable treating the lack of override as error).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I was referring to the override changes, in the commit they were introduced.
src/cgame/cg_rocket.cpp
Outdated
@@ -99,13 +99,7 @@ void CG_Rocket_Init( glconfig_t gl ) | |||
{ | |||
token = COM_Parse2( &text_p ); | |||
|
|||
rocketInfo.cursor = trap_R_RegisterShader( token, (RegisterShaderFlags_t) RSF_DEFAULT ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it could be squashed with 18adf9a ?
// Scale cursor with resolution while maintaining the original aspect ratio. | ||
int x, y; | ||
trap_R_GetTextureSize( rocketInfo.cursor, &x, &y ); | ||
float ratio = static_cast<float>( x ) / static_cast<float>( y ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reminds me a TODO I kept in another PR :) a single cast would suffice (not important at all though).
} | ||
} | ||
} | ||
virtual ~RocketProgressBar() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override?
Also, there is the = default
thing. It's a bit longer, though, but makes it easy to notice with syntax coloration. Dunno about it's use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, since the class inherits, the DTor could use override instead.
// Scale the UI proportional to the screen size | ||
void Rocket_SetDocumentScale( Rml::Core::ElementDocument& document ) | ||
{ | ||
// This gets 12pt on 1920�1080 screen, which is libRocket default for 1em |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: not sure it's worth using the UTF8 character for ×
here, looks like just asking for problems to me (even if should not do problems to most).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a comment, so what's the worst that could happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true
@@ -2130,17 +2130,20 @@ class PredictedMineEfficiencyElement : public HudElement | |||
{ | |||
if ( deltaBudget < 0 ) { | |||
color = Color::Red; | |||
msg = va( "<span class='material-icon error'></span> You are losing build points!" | |||
// Icon U+E000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've seen in other commits things to convert to/from UTF-8, maybe it would be possible to use them instead of manually made UTF-8 codes? (I might be wrong though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are Private Use Area characters, not displayable by normal fonts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then, but I would not expect anyone to be able to guess that. Is there something to do to help on that? (adding comment everywhere might be counter-productive, if this happens in other places, but I do not think I've seen other ones?)
rocketElementType_t type; | ||
}; | ||
|
||
// This kind of element is a hack left over from when VMs could only use C code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just asking, maybe this could use the deprecate
thingy of C++14? Or a TODO, since this looks like a pretty good candidate of things to get rid of soon (those manually sorted list are quite annoying, but at least here it's documented...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how, since deprecation warnings would fire for all uses, not only new ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but it might help encourage us to fix the situation if we see them :)
@@ -140,6 +140,14 @@ class DaemonSystemInterface : public Rml::Core::SystemInterface | |||
|
|||
void SetMouseCursor(const Rml::Core::String& cursor_name) override | |||
{ | |||
if ( cursor_name.empty() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's somehow possible to prevent the cursor's name to get empty, instead?
Also, this commit looks like it could be squashed with e61b3a3 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cursor name becomes empty when there is no document in menuContext under the cursor's position. I guess that could be prevented by drawing an invisible document over the whole screen, but that hardly seems nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clearly would feel like dirty hack. Maybe in later rmlui version it's possible to get a default cursor... we'll see I guess.
I have reviewed each commits one by one, still have to read the companion PR though. Overall things seems ok, but I really think the The thing I would like to see changed the most is the addition of a macro where a template could apply. Since templates are instantiated once per type and since there's exactly one instance of each instanciers, this would work. What would probably be needed in my patch is some added documentation in the template or even better, some kind of actual security, no idea how (verifying that the function is called exactly once, maybe?). |
sed -b -i -E 's/\bRocket::/Rml::/g; s/namespace Rocket/namespace Rml/; s/CString/c_str/g; s/\.Append\b/.append/; s/\.Empty\b/.empty/g; s/\.Length\b/.size/; s/PropertyNameList/PropertyIdSet/; ' $(find src -type f)
TODO: Revisit this in the future.
In the future, we should dynamically load cursors, but that's TODO.
This way, they will always be received by the event listener.
This allows individual menus to have custom cursors if they want.
Use this instead of our custom one for our progress bar.
In cg_rocket_draw.cpp, we would create a new instancer, and never delete it. Instead, we store it in a static unique_ptr<> so it will be cleaned up when the program terminates or the next time rocket is initialized. Also, consolidate the RegisterElement logic.
RmlUi apparently recognizes the border-width shorthand unlike librocket, so rename it to momentum-border-width to avoid conflicts.
Apparently HTML entities were removed from RmlUi, so I had to replace them with the UTF-8 byte sequences.
In RmlUi modifying the element in OnRender no longer works well: if you change the element text in OnRender, then the element becomes blank for one frame, causing flickering.
Also fix the calculation for how many lines can be shown. This was broken before RMLUI and it was stuck at the fallback value of 4 lines.
This is used for example if you type Chinese characters in a chat message, since they are not in Roboto.
Instead of intercepting events at the root element, I've added a Lua snippet to the RML to focus the chatfield element when it is opened. There are a lot of bugs with the chat field, but I think I've squashed all of the ones that are new with RmlUi.
In particular it happened when the console is closed on the main menu. To prevent the bug from recurring in another case, when the console is open and the mouse is outside the window after the vid_restart, a commit to remove the duplicate call to IN_Init in Daemon is needed.
Co-authored-by: Morel Bérenger <berengermorel76@gmail.com>
The first commit of the branch had a wrong submodule because of UnvanquishedAssets/unvanquished_src.dpkdir#95 (comment) If you have pulled Unvanquished |
Note that this is based on a March 2020 version of RmlUi, so there is still a bit of migration to get up to the latest version.
Companion UnvanquishedAssets/unvanquished_src.dpkdir#95
Fixes #1200.
Fixes #1551.
TODO: consider squashing commits up to the point where it at least compiles and runs without crashing.
Edit by illwieckz.
Needs: