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
Closed
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6b54cd2
Add RmlUi to build system
p2004a Sep 27, 2023
d7ad618
render first light
loveridge Sep 30, 2023
13010e2
remove sdl2_image
loveridge Sep 30, 2023
1bb6420
VFS system integration
loveridge Oct 1, 2023
bb6ebfd
rmlui lua and sdl integration
loveridge Oct 3, 2023
5133197
rmlui reload support and better luaui integration
loveridge Oct 6, 2023
74f253e
delete extra file
loveridge Oct 6, 2023
0e5dde9
Temporarily switch to RmlUi branch with tracy integration fixed
p2004a Oct 9, 2023
2aaf8c6
data model change detection bad edition
loveridge Oct 21, 2023
f260dcc
fix for chobby support, better binds, translation table
loveridge Oct 22, 2023
ee297a5
key event handling, luaui reloading, rmlsol bug fixes
loveridge Nov 9, 2023
28857f1
remove rml demo files
loveridge Nov 9, 2023
f0386dc
create contexts lua side
loveridge Nov 10, 2023
aae1055
clean up comments
loveridge Nov 10, 2023
02a2344
allow multiple rmlui contexts
loveridge Nov 10, 2023
fc4e86b
pull out inner loop of processevent calls
loveridge Nov 10, 2023
5ccc2c4
add comment to make it clear certain events are not captured
loveridge Nov 10, 2023
3f6b957
Update RmlUi to latest git version
p2004a Nov 11, 2023
5c37983
headless building and lua support
loveridge Nov 12, 2023
8a7df4f
add lunasvg submodule
loveridge Nov 12, 2023
9258d2a
update lunasvg version
loveridge Nov 12, 2023
31a9bb6
reset build option
loveridge Nov 12, 2023
57d37f5
didnt need to build lunasvg as a shared lib
loveridge Nov 15, 2023
0929156
fix: uint is not standard and breaks mingw compile
p2004a Dec 16, 2023
62d7910
Rework RmlSolLua integration into build
p2004a Dec 16, 2023
f1dd515
Fix RmlSolLua compilation under MSVC
p2004a Dec 16, 2023
5d97998
Document the mouse press check
sprunk Dec 30, 2023
928e5d3
Change size() < 1 to empty. Move setActive after processContext loop
loveridge Dec 30, 2023
f86c877
Deeper MouseHandler integration for processing mouse events
loveridge Jan 10, 2024
426b364
Fix software rendered mouse cursor
loveridge Jan 14, 2024
ed12f48
Missed half of the move of this comment
loveridge Jan 14, 2024
66f2440
print sol aux_message
loveridge Jan 14, 2024
2b61a4b
add couple things to .gitignore
ChrisFloofyKitsune Jan 14, 2024
96f9a8b
do less bullying of the RmlSolLua lib
ChrisFloofyKitsune Jan 15, 2024
f4f11e4
add couple things to .gitignore
ChrisFloofyKitsune Jan 14, 2024
b1f5b40
do less bullying of the RmlSolLua lib
ChrisFloofyKitsune Jan 15, 2024
14245d6
Merge remote-tracking branch 'chrisfloofykitsune/rmlui-integration-fo…
ChrisFloofyKitsune Jan 15, 2024
0ceaf20
attempt to add thread safety to RmlGui::data->context accesses
ChrisFloofyKitsune Jan 16, 2024
01ccf83
have RmlGui store what cursor it would like (or "" to cede control of…
ChrisFloofyKitsune Jan 17, 2024
41bbfe5
Platform_RTS ended up being disliked, so re-renamed stuff to "RmlSyst…
ChrisFloofyKitsune Jan 18, 2024
8ddcb47
undo refactoring of import lists in non-Rml files
ChrisFloofyKitsune Jan 18, 2024
f57fd0e
check Rml input first
ChrisFloofyKitsune Jan 18, 2024
5f42a5a
fix a singular character to be lowercase blargh
ChrisFloofyKitsune Jan 18, 2024
b8a1e9d
Merge pull request #1 from ChrisFloofyKitsune/rmlui-integration-fork-…
loveridge Jan 18, 2024
fc72223
fix spelling
loveridge Jan 18, 2024
2ee7847
reference fix
loveridge Jan 18, 2024
641d2a3
use cbitmap texture binding
loveridge Jan 27, 2024
b86474b
spaces to tabs with clang-format
loveridge Jan 27, 2024
e8604eb
mask lua macros
loveridge Jan 28, 2024
5777014
Remove unused variable
loveridge Jan 28, 2024
2845335
add an explicit removeLua call
loveridge Jan 28, 2024
8f31df3
accurate tracking of lua added items
loveridge Jan 29, 2024
b931931
move general Rml::Context watching plugin outside of Lua init/destroy
ChrisFloofyKitsune Jan 29, 2024
0af0f42
left some mess in, sorry
ChrisFloofyKitsune Jan 29, 2024
7cea7bd
Merge pull request #3 from ChrisFloofyKitsune/floof/rmlui/rml-interfa…
loveridge Jan 29, 2024
8ac855f
create new <texture> element which hooks into the existing LuaOpenGL/…
ChrisFloofyKitsune Jan 27, 2024
c6d8c9a
create new <texture> element which hooks into the existing LuaOpenGL/…
ChrisFloofyKitsune Jan 27, 2024
7d310ed
what if we just kept the texture handle away from Rml
ChrisFloofyKitsune Jan 29, 2024
74fa133
clearer and more readable element tag name
ChrisFloofyKitsune Jan 29, 2024
3f8cb98
Remove unnecessary includes
loveridge Jan 30, 2024
2ab12a4
Merge pull request #2 from ChrisFloofyKitsune/floof/rmlui/add-lua-tex…
loveridge Jan 30, 2024
6762251
formatting
loveridge Jan 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ progress.make
/_ReSharper.Caches
.vs/
.vscode
/.idea

# Windows libraries used by spring when compiling with MinGW
# recommended: place the dir somewhere else, and specify with
Expand All @@ -74,6 +75,7 @@ progress.make

# Windows libraries used by spring when compiling with Visual Studio
/vclibs
/vclibs64

# Installer files
/external
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
[submodule "rts/lib/cereal"]
path = rts/lib/cereal
url = https://github.com/USCiLab/cereal.git
[submodule "rts/lib/RmlUi"]
path = rts/lib/RmlUi
url = https://github.com/mikke89/RmlUi.git
[submodule "rts/lib/lunasvg"]
path = rts/lib/lunasvg
url = https://github.com/sammycage/lunasvg.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ else()
set(JAVA_COMPILE_FLAG_CONDITIONAL "-g:lines,source")
endif()

# By default, the libraries that don't explicily specify SHARED/STATIC are build statically.
# See https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html
option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries" OFF)

# Tell windows to pass arguments around in @response files
# (32k arg limit workaround)
Expand Down
2 changes: 2 additions & 0 deletions rts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ add_subdirectory(Lua)
add_subdirectory(ExternalAI)
add_subdirectory(Rendering)
add_subdirectory(aGui)
add_subdirectory(Rml)
add_subdirectory(Menu)
add_subdirectory(Map)
add_subdirectory(Net)
Expand All @@ -146,6 +147,7 @@ make_global_var(engineSources
${sources_engine_Map}
${sources_engine_Rendering}
${sources_engine_aGui}
${sources_engine_Rml}
${sources_engine_Menu}
${sources_engine_System}
${sources_engine_ExternalAI}
Expand Down
44 changes: 30 additions & 14 deletions rts/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Rendering/GL/myGL.h"

#include <Rml/Backends/RmlUi_Backend.h>
#include "Game.h"
#include "Camera.h"
#include "CameraHandler.h"
Expand Down Expand Up @@ -127,6 +128,8 @@
#include "System/TimeProfiler.h"
#include "System/LoadLock.h"

#include <RmlUi/Core.h>


#undef CreateDirectory

Expand Down Expand Up @@ -292,6 +295,7 @@ CGame::~CGame()
ENTER_SYNCED_CODE();
LOG("[Game::%s][1]", __func__);

RmlGui::Shutdown();
helper->Kill();
KillLua(true);
KillMisc();
Expand Down Expand Up @@ -800,6 +804,7 @@ void CGame::LoadInterface()
GameSetupDrawer::Disable();
GameSetupDrawer::Enable();
}
RmlGui::Initialize(globalRendering->GetWindow(), globalRendering->GetContext(), globalRendering->winSizeX, globalRendering->winSizeY);
}

void CGame::LoadLua(bool dryRun, bool onlyUnsynced)
Expand Down Expand Up @@ -1068,6 +1073,9 @@ int CGame::KeyPressed(int keyCode, int scanCode, bool isRepeat)

lastActionList = keyBindings.GetActionList(curKeyCodeChain, curScanCodeChain);

if (RmlGui::ProcessKeyPressed(keyCode, scanCode, isRepeat))
return 0;

if (gameTextInput.ConsumePressedKey(keyCode, scanCode, lastActionList))
return 0;

Expand Down Expand Up @@ -1107,6 +1115,9 @@ int CGame::KeyPressed(int keyCode, int scanCode, bool isRepeat)

int CGame::KeyReleased(int keyCode, int scanCode)
{
if (RmlGui::ProcessKeyReleased(keyCode, scanCode))
return 0;

if (gameTextInput.ConsumeReleasedKey(keyCode, scanCode))
return 0;

Expand Down Expand Up @@ -1140,6 +1151,9 @@ int CGame::KeyMapChanged()

int CGame::TextInput(const std::string& utf8Text)
{
if (RmlGui::ProcessTextInput(utf8Text))
return 0;

if (eventHandler.TextInput(utf8Text))
return 0;

Expand Down Expand Up @@ -1259,7 +1273,7 @@ bool CGame::UpdateUnsynced(const spring_time currentTime)
globalRendering->lastFrameStart = currentTime;
// Update the interpolation coefficient (globalRendering->timeOffset)
if (!gs->paused && !IsSimLagging() && !gs->PreSimFrame() && !videoCapturing->AllowRecord()) {
globalRendering->weightedSpeedFactor = 0.001f * gu->simFPS;
globalRendering->weightedSpeedFactor = 0.001f * gu->simFPS;
globalRendering->lastTimeOffset = globalRendering->timeOffset;
globalRendering->timeOffset = (currentTime - lastFrameTime).toMilliSecsf() * globalRendering->weightedSpeedFactor;

Expand All @@ -1279,36 +1293,36 @@ bool CGame::UpdateUnsynced(const spring_time currentTime)
float CTO = globalRendering->timeOffset;

// This mode forces a strict time step of 0.5 simframes per draw frames. Only useful for testing @ 60hz
if (SmoothTimeOffset == -1) {
if (SmoothTimeOffset == -1) {
if (newSimFrame) {
if (LTO > (1.0f - drawsimratio * strictness))
if (LTO > (1.0f - drawsimratio * strictness))
globalRendering->timeOffset = drawsimratio;
else
else
globalRendering->timeOffset = 0.0f;
} else {
if (LTO > drawsimratio * strictness)
if (LTO > drawsimratio * strictness)
globalRendering->timeOffset = std::fmin(LTO + drawsimratio * strictness, 1.0f);
else
globalRendering->timeOffset = std::fmin(drawsimratio * strictness, 1.0f);
}
}

// This mode tries to correct for the wrongly calculated timeOffset adaptively,
// while trying to maintain a smooth interpolation rate
// This mode tries to correct for the wrongly calculated timeOffset adaptively,
// while trying to maintain a smooth interpolation rate
// As frame rates dip below 45fps, this method is only marginally better than old method
// But that is heavily dependent on wether the load is sim or draw based.
// TODO: the camera smoothing still seems to take sim load into account heavily. So large sim loads jitter the camera quite a bit when moving
if (SmoothTimeOffset > 0){

// if we have a new sim frame, then check when the time and CTO of the previous draw frame was.
// if we have a new sim frame, then check when the time and CTO of the previous draw frame was.
drawsimratio = std::fmin(drawsimratio, 1.0); // Clamp it otherwise we will accumulate delay when < 30 FPS
float oldCTO = globalRendering->timeOffset;
float newCTO = globalRendering->timeOffset;

if (newSimFrame) {
// newsimframe is a special case, as our new time offset is kind of wrong.
if (newSimFrame) {
// newsimframe is a special case, as our new time offset is kind of wrong.
// What we want to know is when the last draw happened, and at what offset.
// There are two special cases here, if the last draw happened "on time", then we want to 'pull in' CTO to 0,
// There are two special cases here, if the last draw happened "on time", then we want to 'pull in' CTO to 0,
// irrespective of the time spent in sim.
// If the last draw frame didnt happend on time, and had a large CTO, then we need to 'carry over' some time offset

Expand All @@ -1319,7 +1333,7 @@ bool CGame::UpdateUnsynced(const spring_time currentTime)
}
}
else {
// On draw frames that dont have a preceding sim frame, we want to 'smooth' the CTO out a bit.
// On draw frames that dont have a preceding sim frame, we want to 'smooth' the CTO out a bit.
// Otherwise, the sim frame is also calculated into the offset, making things jittery
if ((CTO - LTO < (drawsimratio) * strictness)) {
newCTO = std::fmin(LTO + drawsimratio * strictness, 1.3f);
Expand Down Expand Up @@ -1431,6 +1445,7 @@ bool CGame::Draw() {
if (UpdateUnsynced(currentTimePreUpdate))
return false;

RmlGui::Update();
const spring_time currentTimePreDraw = spring_gettime();

SCOPED_SPECIAL_TIMER("Draw");
Expand Down Expand Up @@ -1518,6 +1533,7 @@ bool CGame::Draw() {
DrawInputReceivers();
DrawInputText();
DrawInterfaceWidgets();
RmlGui::RenderFrame();
mouse->DrawCursor();

eventHandler.DrawScreenPost();
Expand Down Expand Up @@ -1674,7 +1690,7 @@ void CGame::SimFrame() {

// note: starts at -1, first actual frame is 0
gs->frameNum += 1;
lastFrameTime = spring_gettime();
lastFrameTime = spring_gettime();
// This is not very ideal, as the timeoffset of each new draw frame is also calculated from this
// with a strange side effect: if the timeOffset was a high number, like 0.9, then this will force the next draw frame to have an offset of 0.0x
// What this means, is that in the case where we have frames to spare, and and over rendering, then the following can happen at 60hz:
Expand All @@ -1684,7 +1700,7 @@ void CGame::SimFrame() {
// drawframe timeoffset ~ 1.0 (1 extra draw!)
// simframe
// drawframe timeoffset ~ 0.0 // THIS is the problematic case, as visually, this frame is 'near identical' to the previously drawn one!
// simframe
// simframe
// drawframe timeoffset ~ 0.0
// drawframe timeoffset ~ 0.5
// simframe
Expand Down
2 changes: 2 additions & 0 deletions rts/Game/UI/GuiHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "GuiHandler.h"

#include <Rml/Backends/RmlUi_Backend.h>
#include "CommandColors.h"
#include "KeyBindings.h"
#include "KeyCodes.h"
Expand Down Expand Up @@ -168,6 +169,7 @@ bool CGuiHandler::EnableLuaUI(bool enableCommand)
}
}

RmlGui::Reload();
CLuaUI::ReloadHandler();

if (luaUI != nullptr) {
Expand Down
7 changes: 6 additions & 1 deletion rts/Game/UI/InputReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "InputReceiver.h"
#include "Lua/LuaInputReceiver.h"
#include "Rendering/GL/myGL.h"
#include "Rml/Backends/RmlUi_Backend.h"
#include "System/Rectangle.h"


Expand Down Expand Up @@ -68,7 +69,11 @@ void CInputReceiver::DrawReceivers()

CInputReceiver* CInputReceiver::GetReceiverAt(int x, int y)
{
// always ask Lua first
// check RmlUI first
if (RmlGui::IsMouseInteractingWith())
return RmlGui::GetInputReceiver();

// check lua second
if (luaInputReceiver != nullptr && luaInputReceiver->IsAbove(x, y))
return luaInputReceiver;

Expand Down
40 changes: 39 additions & 1 deletion rts/Game/UI/MouseHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "System/StringUtil.h"
#include "System/Input/KeyInput.h"
#include "System/Input/MouseInput.h"
#include "Rml/Backends/RmlUi_Backend.h"

#include <algorithm>

Expand Down Expand Up @@ -272,6 +273,12 @@ void CMouseHandler::MouseMove(int x, int y, int dx, int dy)
if (game != nullptr && !game->IsGameOver())
playerHandler.Player(gu->myPlayerNum)->currentStats.mousePixels += movedPixels;

/* 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. */
if (!ButtonPressed() && RmlGui::ProcessMouseMove(x, lasty, dx, dy, activeButtonIdx)) {
return;
}

if (activeReceiver != nullptr)
activeReceiver->MouseMove(x, lasty, dx, dy, activeButtonIdx);

Expand All @@ -297,7 +304,12 @@ void CMouseHandler::MousePress(int x, int y, int button)
if (game != nullptr && !game->IsGameOver())
playerHandler.Player(gu->myPlayerNum)->currentStats.mouseClicks++;

ButtonPressEvt& bp = buttons[activeButtonIdx = button];
if (RmlGui::ProcessMousePress(x, y, button)) {
return;
}

activeButtonIdx = button;
ButtonPressEvt& bp = buttons[activeButtonIdx];
bp.chorded = (buttons[SDL_BUTTON_LEFT].pressed || buttons[SDL_BUTTON_RIGHT].pressed);
bp.pressed = true;
bp.time = gu->gameTime;
Expand All @@ -307,6 +319,8 @@ void CMouseHandler::MousePress(int x, int y, int button)
bp.dir = (dir = GetCursorCameraDir(x, y));
bp.movement = 0;

pressedBitMask |= 1 << button;

if (activeReceiver != nullptr && activeReceiver->MousePress(x, y, button))
return;

Expand Down Expand Up @@ -366,6 +380,10 @@ bool CMouseHandler::GetSelectionBoxVertices(float3& bl, float3& br, float3& tl,
if (activeReceiver != nullptr)
return false;

if (RmlGui::IsMouseInteractingWith()) {
return false;
}

if (gu->fpsMode)
return false;

Expand Down Expand Up @@ -463,12 +481,17 @@ void CMouseHandler::MouseRelease(int x, int y, int button)
dir = GetCursorCameraDir(x, y);

buttons[button].pressed = false;
pressedBitMask &= ~(1 << button);

if (inMapDrawer != nullptr && inMapDrawer->IsDrawMode()) {
inMapDrawer->MouseRelease(x, y, button);
return;
}

if (RmlGui::ProcessMouseRelease(x, y, button)) {
return;
}

if (activeReceiver != nullptr) {
activeReceiver->MouseRelease(x, y, button);

Expand Down Expand Up @@ -543,9 +566,17 @@ void CMouseHandler::MouseRelease(int x, int y, int button)
}
}

bool CMouseHandler::ButtonPressed()
{
return pressedBitMask > 0;
}

void CMouseHandler::MouseWheel(float delta)
{
if (RmlGui::ProcessMouseWheel(delta)) {
return;
}

if (eventHandler.MouseWheel(delta > 0.0f, delta))
return;

Expand Down Expand Up @@ -674,6 +705,13 @@ std::string CMouseHandler::GetCurrentTooltip() const

void CMouseHandler::Update()
{
// Rml is very polite about asking for changes to the cursor
// so let's make sure it's not ignored!
if (RmlGui::IsMouseInteractingWith())
// if the cursor string is empty, then Rml is cedeing control of it
if (auto& rmlCursor = RmlGui::GetMouseCursor(); !rmlCursor.empty())
queuedCursorName = rmlCursor;

SetCursor(queuedCursorName);

if (!hideCursor) {
Expand Down
3 changes: 3 additions & 0 deletions rts/Game/UI/MouseHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class CMouseHandler

bool GetSelectionBoxVertices(float3& bl, float3& br, float3& tl, float3& tr) const;

bool ButtonPressed();

private:
int2 GetViewMouseCenter() const;
void SetCursor(const std::string& cmdName, const bool forceRebind = false);
Expand Down Expand Up @@ -116,6 +118,7 @@ class CMouseHandler
bool wasLocked = false;
bool offscreen = false;
bool mmbScroll = false;
uint32_t pressedBitMask = 0;

private:
bool hideCursor = true;
Expand Down
Loading