collinsmith / riiablo

Diablo II remade using Java and LibGDX
http://riiablo.com
Apache License 2.0
872 stars 99 forks source link

Apply correct windowed setting at startup #85

Open collinsmith opened 4 years ago

collinsmith commented 4 years ago

When starting without windowed -w argument, fullscreen mode is briefly set and then unset when the cvar value is eventually loaded after the application is actually created. Using -w argument skips this behavior by overriding the client.windowed cvar (-w indicates that windowed mode is forced and client.windowed is ignored). The expected behavior should be:

The issue lies with when the StateListener is added and when Client.Windowed is loaded. The check of to && Gdx.graphics.isFullscreen() within the Client.Windowed StateListener within DesktopLauncher#main doesn't work correctly in the initial state and sets to fullscreen mode (after this initial set, this appears to work as expected though).

I experimented with adding Cvar#addStateListener(boolean, StateListener) to Cvar which uses the boolean argument to tell whether or not the passed StateListener should have onLoaded called to set the initial value. This circumvents the behavior by delaying onLoaded until the program has started and client.windowed loaded. This fixed the bug where the program has fullscreen set erroneously, however it doesn't fix the problem of having the value we want set late. The state listener is added without this parameter until this issue can be looked into properly and we can evaluate if Cvar#addStateListener(boolean, StateListener) should be kept or deprecated/removed.

Something I didn't try which might give the results I'm after are to use some external serialization of client.windowed to apply a default value (changing client.windowed would reserialize it). So when the application starts, we can read this without having to init Riiablo.cvars and apply the correct value.