workadventure icon indicating copy to clipboard operation
workadventure copied to clipboard

Pause mode for idling

Open loleg opened this issue 4 years ago • 5 comments

When not actively using WorkAdventure, I may want to leave it running in the background and wait for someone to drop in and say hello. An "idle" or "sleep" mode typical in games could be activated by a PAUSE user interface, or automatically after a minute or so of no user input. This would turn off the camera and microphone, and present an info-screen similar to that when entering a world or changing your name.

This is my first issue, and I want to first of all say - merci beaucoup - for a really great project, for making it open source, and for keeping up with what looks like a flood of interest & user demands!

My motivation for raising this issue is performance. I can't afford one tab affecting my CPU/GPU usage all day long. I trust overall performance will improve with time, but in the meantime, having a pause mode would be a quick win.

See also #170 / #514 / GameScene.ts#L395

loleg avatar Jan 29 '21 13:01 loleg

@loleg Did you already try lowering your Game quality in the settings to Minimum video quality (40 fps)? In my experience, this lowers the CPU usage by about 50% while still giving an acceptable experience.

That said, a pause mode which makes sure that the rendering engine (I assume that is what mainly takes up CPU?) is inactive when the game tab is not active could be very useful as well.

djmaze avatar Jan 29 '21 14:01 djmaze

@djmaze Yes, I saw those settings, thanks. Even on low quality, I'm seeing CPU usage of Firefox between 30-50% even when I'm alone in the map, with my own video and micro off. With the tab closed it drops quickly to < 10%.

If nobody else takes on this issue I might just try to hack it on the weekend. I don't see a contributor's guide, but plenty of open PR's to follow the lead of ;-)

loleg avatar Jan 29 '21 15:01 loleg

I just made a short snapshot using the firefox performance thingy. Does this really need to check collisions and redraw tiles when standing still? This seems quite unnecessary or am I missing something crucial behind that logic? I kinda get the collisions in case the user is going to move but the tiles redraw seems wrong. But that even might be a red herring as I only saw a function name mentioning tiles redraw but did not actually looked at what it does.

Edit: While testing there was no other person on the map and i not moved and the cursor animation also wasn't happening.

MTRNord avatar Jan 30 '21 07:01 MTRNord

I can't answer the questions from @MTRNord above, but I did get a local dev env running and tried this code to pause the scene on pressing the P button. The CPU usage drops noticeably with scene.sleep, but this.scene.pause(this.scene.key) has no effect on performance. There are some Pause examples from Phaser, probably some better strategies out there.

loleg avatar Jan 30 '21 22:01 loleg

I also like to idle in workadventure. I'm not certain, but I think that Phaser is constantly rendering the scene, whether or not there's any change to the scene. So what I did to lower cpu usage is to simply reduce the number of pixels Phaser has to render by making the window smaller (and/or zooming in to reduce resolution). It's still usually around 9% cpu usage which isn't great but better than 30%. At least my laptop fan isn't noisy anymore :)

brodavi avatar Apr 09 '21 15:04 brodavi