Skip to content
New issue

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

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

Already on GitHub? # to your account

Project AngelHUD #2490

Closed
wants to merge 30 commits into from
Closed

Project AngelHUD #2490

wants to merge 30 commits into from

Conversation

ohlidalp
Copy link
Member

@ohlidalp ohlidalp commented Mar 4, 2020

This is a replacement for our MyGUI-based custom HUD system. Goal: Allow modders to create and test custom vehicle HUD in-game using AngelScript + DearIMGUI.

image

image

User scenario:

  1. enter simulation and create a project using top menubar. Projects are created in "MyDocuments\MyGames\RigsOfRods\projects" as subdirectories, each containing project JSON and truckfiles (dubbed snapshots). Unlike regular mods, all resources within a project are always fully reloaded from disk, allowing modder to add/remove/change data on the go.
    image

  2. add angelscript file to the truckfile using button "+ Add example script" in projects top menu. Details: Project AngelHUD #2490 (comment)
    image

  3. within the angelscript, define function int setup(string arg) to be invoked once and function int loop() to be invoked on each rendered frame.

  4. within the angelscript function, draw the HUD using DearIMGUI, reading data from simbuffer (see example code). The simbuffer contains all data described in https://docs.rigsofrods.org/vehicle-creation/making-custom-hud/ and a lot more, allowing modder to create truly diagnostic GUI - DearIMGUI is packed with very capable widgets and a flexible drawing API. Graphical HUD can be done simply by calling ImGui::Image() with texture name.

Notes:

  • These scripts are executed separately from the classic RoR scripting subsystem - the "GameObject" interface is not available. The reason is multithreading - a script drawing HUD (or doing other visuals) should run on a rendering thread, while the classic scripts must run when both sim+rendering(main) threads are halted.

@tritonas00
Copy link
Collaborator

Impressive! Why not use this logic to draw the default HUD also?

@ohlidalp
Copy link
Member Author

ohlidalp commented Mar 4, 2020

I absolutely intend to do that - in fact, it's necessary because the default truck HUD is made via the MyGUI-based HUD system, so it must go away before we port to OGRE 1.12. The airplane HUD, in contrast, is hardcoded, which is also not optimal.

I'll also make ImGui available to terrain scripts - custom race scoreboards etc...

@CuriousMike56
Copy link
Collaborator

Pretty sweet. Might be a bit of a stretch, but would vehicles dashboards be able to draw IMGUI? (similar to renderdash). Would be awesome to finally be able to create digital dashboards.

@ohlidalp
Copy link
Member Author

ohlidalp commented Mar 5, 2020

@CuriousMike56 Not at all, in fact it's mandatory since the current MyGUI-HUD can also render to texture and some mods rely on it. Not to mention I want the feature, too. It should be pretty straightforward to implement.

I added initial bindings to SimBuffer - most of these fields are available, see screenshot on top or commit message for example use.

@tritonas00
Copy link
Collaborator

tritonas00 commented Mar 6, 2020

Got this warning when compiling

In file included from /home/babis/Downloads/ror-dependencies/rigs-of-rods/source/main/cotire/RoR_CXX_prefix.cxx:39,
                 from /home/babis/Downloads/ror-dependencies/rigs-of-rods/source/main/cotire/RoR_CXX_prefix.hxx:4:
/home/babis/Downloads/ror-dependencies/rigs-of-rods/source/main/scripting/ImGuiAngelscript.cpp: In lambda function:
/home/babis/Downloads/ror-dependencies/rigs-of-rods/source/main/scripting/ImGuiAngelscript.cpp:169:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  169 |         ImGui::Image((ImTextureID)u, ImVec2(v.x, v.y));

@ohlidalp
Copy link
Member Author

ohlidalp commented Mar 6, 2020

@tritonas00 Something goes wrong outside AngelScript, otherwise you'd see more detailed error messages from AngelScript itself. I'll tighten the surrounding checks and fix the warning.
EDIT - I just noticed it - you must use int loop(GfxActor@) as in the 2nd screenshot, the 1st is outdated. AngelScript doesn't report anything because the failing operation is RoR trying to find the function by signature. I'll add a console message for that.

@tritonas00
Copy link
Collaborator

tritonas00 commented Mar 6, 2020

Yes it works now, thanks!

Epic! Now need to find a way to use data.engine_rpm as an imgui histogram or progressbar input lol

Also @only-a-ptr have you seen this? http://floooh.github.io/oryol-sticky-tests/imgui-highdpi-sapp.html

@ohlidalp
Copy link
Member Author

ohlidalp commented Mar 7, 2020

I ❤️ AngelScript! I just register the internals 1:1 and it... just works. ☺️

image

@ohlidalp
Copy link
Member Author

ohlidalp commented Mar 14, 2020

I added an in-game example script. When you load a project-truck and click the "+ add example script" button in the projects menu, RoR will put the script to the project directory, assign it to the truck and reload the truck to activate it.

image

@ohlidalp
Copy link
Member Author

image

@ohlidalp ohlidalp closed this Mar 18, 2020
@ohlidalp ohlidalp reopened this Mar 18, 2020
@ohlidalp
Copy link
Member Author

image

@tritonas00 Segfault on import is fixed

@RigsOfRods RigsOfRods deleted a comment from tritonas00 Mar 19, 2020
@tritonas00
Copy link
Collaborator

tritonas00 commented Mar 19, 2020

Oh god, you rock! 👏👏👏

kk

@tritonas00
Copy link
Collaborator

tritonas00 commented Mar 20, 2020

Default HUD layout remake is almost ready, missing the coding stuff (rotated needles, on/off statements) and i think some icons

off

on

@ohlidalp ohlidalp force-pushed the angelhud branch 3 times, most recently from 821bf36 to 025c0c1 Compare March 26, 2020 04:16
@ohlidalp ohlidalp force-pushed the angelhud branch 3 times, most recently from 403bd35 to 8f49029 Compare May 5, 2020 12:05
@ohlidalp
Copy link
Member Author

ohlidalp commented May 5, 2020

I'm on the way to add support for multiple fonts (meaning also multiple sizes of the same font) loadable via AngelScript (for dashboards). In the process I updated imgui to 1.75 (was: 1.50WIP) which caused some positioning glitches. I'll work it out.
image

ohlidalp added 2 commits May 8, 2020 19:06
Added directory ROR_HOME/projects. Each subdir contains 'project.json', resources (meshes, materials, textures) and one or more truckfiles.
The ingame top menubar contains 'Projects' menu to spawn modified truckfiles and to import existing ones.
Status: import/export for nodes and beams

Added option to accept all ; as ;grp:
ohlidalp added 22 commits May 8, 2020 19:07
Goal: Allow modders to create and test custom vehicle HUD in-game using AngelScript + DearIMGUI.

User scenario:
1. enter simulation and create a project using top menubar. Projects are created in "MyDocuments\MyGames\RigsOfRods\projects" as subdirectories, each containing project JSON and truckfiles (dubbed snapshots). Unlike regular mods, all resources within a project are always fully reloaded from disk, allowing modder to add/remove/change data on the go.
2. add angelscript file to the truckfile via section 'scripts' (to be implemented)
3. within the angelscript, define a function to be invoked on each rendered frame.
4. within the angelscript function, draw the HUD using DearIMGUI (bindings partially implemented, see ImGuiAngelscript.cpp) reading data from simbuffer (bindings partially implemented, see GameScript.cpp). The simbuffer contains all data described in https://docs.rigsofrods.org/vehicle-creation/making-custom-hud/ and a lot more, allowing modder to create truly giagnostic GUI - DearIMGUI is packed by very capable widgets and a flexible drawing API. Graphical HUD can be done simply by calling ImGui::Image() with texture name.

-- TEST SCRIPT --

int setup(string arg)
{
    string msg;
    msg = "setup() works! arg: " + arg;
    log(msg);
    return 0;
}

int frame_num = 0;

int loop()
{
    string msg;
    msg = "Frame: " + frame_num;
    // Opens window "Debug" (DearIMGUI feat)
    ImGui::Text(msg);
    frame_num++;
    return 0;
}

-- TEST TRUCK --

scripts
    frame-step: test_script_filename.as, Any text (including spaces) passed to `setup()` as `arg`
// ----- Example script -----

int setup(string arg)
{
    return 0;
}

int loop(GfxActor@ actor)
{
    ImGui::Begin("SimBuffer test", true);
    ActorSimBuffer@ data = actor.GetSimDataBuffer();
    string str;
    str = "Pos: X" + data.pos.x
           + ", Y" + data.pos.y
           + ", Z" + data.pos.z;
    ImGui::Text(str);
    ImGui::End();
    return 0;
}
Added enums PropAnim[Flag|Mode] - copypastes from BeamData.h but used for different purpose (rendering vs. simulation)
Also fixed "color" (Ogre::ColourValue) not registered properly.
Thanks to @tritonas00 for the base layout.
@ohlidalp ohlidalp force-pushed the angelhud branch 2 times, most recently from 5a0bc37 to 60f8419 Compare May 8, 2020 17:23
ohlidalp added 2 commits May 11, 2020 22:11
Think of this as an excercise in understanding OGRE internals :)

I'd like to use OGRE 1.12x's builtin imgui support, but it seems it only supports one font, and I'd like fonts to be loadable ad-hoc via AngelScript.
Thus, I'm doing this middle-step where I copy OGRE code to RoR (see gui/imgui/README for all details) to experiment with it, develop a solution and contribute it back to OGRE.
@ohlidalp
Copy link
Member Author

ohlidalp commented Sep 2, 2021

Superseded by #2709 (project directories), #2786 (imgui), #2788 (cvars) and #2750 (addons).

@ohlidalp ohlidalp closed this Sep 2, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants