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

Live view panel #29136

Closed
wants to merge 3 commits into from
Closed

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented May 23, 2019

On top of some non-breaking changes to Image and a cross-platform implementation of shared memory, this is a dock that shows a small view of the running game.

After a lot of thought and given the current limitations of the Godot editor UI, I've concluded that making it a dock was the best option.

To avoid it taking editor space when it isn't in use, in the default layout, it will be beneath the file system tab. It also has settings (enabled by default) to auto-switch to it and back to whatever other tab was active before running the game.

Also by default, it's enabled the option that makes it stand by while the editor is not focused. That is good because it prevents it from stealing performance from the running game and anyway you don't need to look at a small view in the editor while the game window is the focused one. Nonetheless any user wanting to do so will be able to.

It has a maximum FPS limit to keep it's load light, set to 15 by default. Someone using this on a powerful enough system will be able to raise it.

Furthermore, whenever it's not visible (because another dock in the same tab group is active), it is effectively disabled.

Given that the framebuffer data is transferred via shared memory, this only works when both the game and the editor are running on the same host.

I've not been able to confirm image capture is working on Mac. If anyone could test and report, that'd be great. UPDATE: It seems it does!

UPDATE:
I'm marking this as work-in-progress because I will add some more pieces of functionality to make it more useful. However, the trickiest part is done and testing is welcome.

UPDATE 2:
No longer work-in-progress. I've moved it to the output dock. Additional functionality will come in future PRs.

image
image

core/os/shared_memory.h Outdated Show resolved Hide resolved
@@ -318,7 +318,7 @@ def configure(env):

env.Prepend(CPPPATH=['#platform/x11'])
env.Append(CPPFLAGS=['-DX11_ENABLED', '-DUNIX_ENABLED', '-DOPENGL_ENABLED', '-DGLES_ENABLED'])
env.Append(LIBS=['GL', 'pthread'])
env.Append(LIBS=['GL', 'pthread', 'rt'])
Copy link
Member Author

@RandomShaper RandomShaper May 23, 2019

Choose a reason for hiding this comment

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

@akien-mga, @hpvb, I think this has implications for CI and build containers.
EDIT: I'm referring to the added lib.

@aaronfranke
Copy link
Member

Doesn't this then require that the game be running? How useful is this exactly if by running the game it brings itself to focus as a separate window anyway?

@RandomShaper
Copy link
Member Author

The main idea is using it for live scene editing and debugging without having to switch back and forth between the game and the editor.
It's not a one-fits-all solution, neither regarding use cases nor projects, but it was requested by some people to a extent that it was added to the roadmap.

@Zireael07
Copy link
Contributor

Is this for 2D only or 3D, too?

@santouits
Copy link
Contributor

beautiful code but I don't get why is this needed. Is there anywhere any discussion about it to read?

@RandomShaper
Copy link
Member Author

@Zireael07, it's for both. It mirrors anything displayed in the root (builtin) viewport.

@santouits, you're right in that it's not needed, but that doesn't mean users cannot benefit from it.

I'm not sure there's a thread somewhere about it. I just know several users requested it during spoken conversations.

Then we talked about it during the Godot Sprint and decided to include it in the roadmap.

Thanks for your words about the code.

@AinaSG
Copy link
Contributor

AinaSG commented May 24, 2019

Hey @RandomShaper, I compiled it in a Mac and I see an static image after hitting play and closing the game, I don't know if this the expected behaviour :)
Screen Shot 2019-05-24 at 16 11 18

@Zireael07
Copy link
Contributor

If I'm reading it correctly, game must be running for it to work, so if you close it, it won't work.

@AinaSG
Copy link
Contributor

AinaSG commented May 24, 2019

Oh, right, it shows when I give focus back to the editor, but is's still static. I can't seem to be able to interact with it and the animations are not playing.

@RandomShaper
Copy link
Member Author

@AinaSG, thank you very much for testing!

Yes, as it is currently this is quite basic, but actually being able to mirror the game image into the editor was the hardest part.

I think I'm marking this PR as work-in-progress, because I will do some improvements to make it more useful.

@RandomShaper RandomShaper changed the title Live view dock Live view dock [wip] May 24, 2019
@Jummit
Copy link
Contributor

Jummit commented May 24, 2019

Thank you for making this! I switch between the game and the editor very often, so this will be very useful.

@swarnimarun
Copy link
Contributor

Cool feature. But what kind of performance repercussions will be there? I mean I saw from my quick look that it's locked at 15 fps by default, and I am assuming it needs to redraw the editor or can it just work by redrawing the dock separately in a different thread?
(Probably I should have seen the code rather than asking).

@RandomShaper
Copy link
Member Author

@swarnimarun, the editor is redrawn on every frame. That's why by default it will be in stand by while the game window is focused, to avoid disrupting normal game performance.

When you focus the editor back, with the game still running, then a slight FPS drop is not as important since you are then focusing on fixing/editing/debugging.

@Calinou
Copy link
Member

Calinou commented May 24, 2019

@AinaSG Does this occur if you disable fullscreen in the Project Settings? Maybe alt-tabbing out of a fullscreen project causes the renderer to stop outputting new frames (as the result won't be visible in an usual situation).

@swarnimarun
Copy link
Contributor

@RandomShaper That's nice, actually really awesome. 👍
(At least I can't think of anything better unless we get detachable dock windows)

@RandomShaper RandomShaper requested a review from vnen as a code owner July 2, 2019 07:11
@RandomShaper RandomShaper changed the title Live view dock Live view panel Jul 2, 2019
@RandomShaper RandomShaper force-pushed the gameview-dock branch 2 times, most recently from 4ddc7d6 to 5acfdda Compare July 3, 2019 20:17
@codecustard
Copy link
Contributor

Clicking on the preview to freeze/unfreeze the preview would be cool.

class SharedMemory {

protected:
static const char *const ERR_STR_ALREADY_OPEN;
Copy link
Member

Choose a reason for hiding this comment

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

We know build with -std=c++11 so I think you could move the definitions in the header (at last!).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, as well as other C++11-related improvements.

@RandomShaper RandomShaper force-pushed the gameview-dock branch 5 times, most recently from 3970a7e to c2160f9 Compare August 29, 2019 17:58
Optimize nearest neighbor scaling and expose the function to process raw buffers.
Allow non-COW access to image data.
@Anutrix
Copy link
Contributor

Anutrix commented Jan 29, 2020

Is this editor only or can it work as good minimap inside the game?

@RandomShaper
Copy link
Member Author

Editor-only. The mechanism used to transfer the image from the game to the editor would be cumbersome for in-game use.

@akien-mga
Copy link
Member

But unless I miss something, you don't need this feature at all in game. You already have a unified scene tree and you can use Viewports to achieve this kind of result, without having to bother with a cross-process communication channel.

@aaronfranke
Copy link
Member

Closing because:

  • This PR has not received any new commits for over a year, it needs rebasing.

  • This feature needs a proposal written to justify it.

    • I'm still not convinced that this feature is actually useful, or actually solving any particular problems. You can't control the game through this view. I think it's bloat, therefore I think it needs justification to be included in Godot.

    • I think this feature would be feasible to do in an add-on in the asset library. All it really needs is some way to grab another window and put it in a texture, then the add-on can display that texture anywhere, in a panel or dock, maybe even the main screen. If this would be included in Godot, a proposal needs to show that this isn't possible in a GDNative plugin (and if so, justify why we can't improve GDNative to allow this).

@starry-abyss
Copy link
Contributor

starry-abyss commented Jun 17, 2020

I'm still not convinced that this feature is actually useful

I was under impression OP was directly hired by Godot to implement this?

@RandomShaper
Copy link
Member Author

I was under impression OP was directly hired by Godot to implement this?

I wasn't. I did this because of an informal request for it, so to speak. It turned out to be a huge waste of time.

I hope that at some point shared memory is wanted for something else and at least that part can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.