davidjoffe / dave_gnukem

Dave Gnukem is a cross-platform 2D scrolling platform shooter inspired by Duke Nukem 1
GNU General Public License v2.0
76 stars 23 forks source link

Live ingame full-screen switching #149

Open davidjoffe opened 1 year ago

davidjoffe commented 1 year ago

I started adding possible ability to do live in-game fullscreen switching and did some refactoring to that end - try enable new config option to try it out: djEXPERIMENTAL_FULLSCREEN_TOGGLE Then either press Ctrl+Shift+F in-game (or Esc and use ingame menu) - later we can extend these and make it everywhere. And/or make the shortcut configurable (not sure I like it).

But it's still crashy, I think some issues relating to window cleanup .. hopefully can be sorted soon

NB this is closely related to issue https://github.com/davidjoffe/dave_gnukem/issues/123 where I have other detailed thoughts

I suspect in some (say) console ports, port maintainers might want to e.g. do things like 'force fullscreen always' and stuff like that - so I may add a few more config options (some to possibly be passed in to the compiler and/or via Makefile e.g. maybe could have something like "-DdjFORCE_FULLSCREEN_ALWAYS" or stuff like that in future - I don't know, I'm thinking something like that - to allow e.g. a port maintainer to configure their Makefiles etc. to do things like that.

(Related: Same e.g. some consoles might not have a mouse, but if you have a mouse it might be nice to be able to use it in menus - but not ingame of course)

(Small Question to self: On fullscreen toggle I'm cleaning and recreating the 'hardware surfaces' as this is necessary or used to be necessary on some platforms when you switch between fullscreen and windowed as hardware surfaces could get lost but I'm not sujre whether that's an issue here or not in SDL2 as we're using it, so for now I'm doing it just in case (i.e. the hardware surfaces or "texture cache" one might one call it that get created corresponding to in-system-memory djImage instances of image data for sprites etc.) ... so doing it just in case on fullscreen toggle but not 100% sure if necessary but we can work that out later - it shouldn't cause any harm to do it just in case, for now I think better an unnecessary recreate of hardware surfaces than crashing or missing textures on some platforms if they may be getting lost in GPU memory or something on switching)

davidjoffe commented 1 year ago

Hm the sdl_createwindow probably just needs a corresponding call to sdl_destroywindow in the right place (and maybe the associated renderer etc. for main window), plus testing.

davidjoffe commented 1 year ago

I committed what I think is a fix for ingame fullscreen toggle: It stores a pointer now to the created main window and calls SDL_DestroyWindow and that seems to fix it for me (tested briefly on Mac, Windows, and Linux)

and I started adding a djDEV_STRESSTESTS development-only config option to enable a stress-tester for the ingame fullscreen toggle to help automate testing this that when enabled (a bit crude/gross for now) just toggles fullscreen every few seconds (obviously this config option NOT for live production release builds - dev only)

Please test more if you can