tzachshabtay / MonoAGS

AGS (Adventure Game Studio) reimagined in Mono
https://tzachshabtay.github.io/MonoAGS/
Artistic License 2.0
27 stars 8 forks source link

Having no rooms in game causes CPU load spikes in render loop #160

Closed ghost closed 6 years ago

ghost commented 6 years ago

Sorry for the weird title, but that's basically how I stumbled across this.

If you make a blank new game project with no actual content, and open game window, the game window never gets redrawn (you can see common artifacts from underlying windows in it), and simply leaving it running will cause CPU load spikes every couple of seconds, or so.

Having no actual idea how to do profiling with MSVS 2017, I was only able to experimentally find out that these spikes are caused by _graphics.ClearScreen() call in default GameWindow.RenderFrame implementation, or more precisely, calling ClearScreen and not calling GameWindow.SwapBuffers().

If I make it call SwapBuffers regardless of RenderLoop.Tick return value, then this issue also goes away.

BTW, may window not redrawing if no room is available considered a bug, or it is intentional? I wanted to suggest making it clear window black anyway.

For the reference, this is the only code I have in game's shared project:

using System;
using AGS.API;
using AGS.Engine;

namespace Game
{
    public class GameStarter
    {
        public static void Run()
        {
            IGame game = AGSGame.CreateEmpty();
            game.Start(new AGSGameSettings("A Game", new AGS.API.Size(1280, 720), windowState: WindowState.Normal));
        }
    }
}
tzachshabtay commented 6 years ago

Thanks, I think this should be fixed now, would be great if you can verify (also should clear the window black, like you suggested).

Side-note regarding profiling on VS2017, there's actually basic profiling built into the debugger, you don't even need to open a profiling session or anything, just go to debug menu -> show diagnostic tools while debugging (see here for more details: https://blogs.msdn.microsoft.com/visualstudio/2016/02/15/analyze-cpu-memory-while-debugging/).

ghost commented 6 years ago

Yes, it does not cause issues now, and the window is painted black if there is no room.