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

SDL2 Port #1137

Merged
merged 41 commits into from
Dec 2, 2020
Merged

Conversation

ivan-mogilko
Copy link
Contributor

Resolves #1096.

Replaces Allegro 4 backend with SDL2.

Main bulk of work was done by @sonneveld previously, now gathered it up, tidied the code, amended and fixed where necessary.
CMake changes by @ericoporto.

Library changes

  • SDL2 is used for window management, rendering and input.
  • SDL2_Sound library for decoding audio formats.
  • MojoAL (embedded) is an OpenAL implementation based on SDL2 and SDL2_Sound.
  • Allegro 4 (embedded) is kept in a stripped form, for memory bitmap handling and drawing, file/path functions, unicode text functions, decoding FLIC videos.
  • Apeg (embedded) is kept to play OGG Theora videos, rewritten by @sonneveld to use OpenAL api instead of Allegro 4 sound.

Notable issues / future todo:

  • Disabled Windows-only plugin functions that return DirectX interfaces from Allegro 4.
  • For the similar reason had to remove AVI/MPG video support, which was previously implemented through use of MS DirectShow (non-portable) and used DirectDraw interface. Might need to reimplement video differently in the future, and support all wanted formats similarily for all systems.

Audio

Audio playback is completely rewritten, uses OpenAL (through MojoAL currently) and SDL2_Sound.
Audio is now played only on a separate thread (this was optional previously).

Notable issues / future todo:

  • May need to add configuration options for audio device init;
  • Sync between audio and game events/animation may be broken in some situations (at least happened with threaded audio before). If such problem is found may need to invent some kind of a syncing mechanism.

Rendering

  • Direct3D and OpenGL work more or less same, except window is now created by SDL2 and OpenGL uses few SDL_GL functions for getting context etc (makes code more uniform between platforms).
  • Software renderer now is only software in how game's virtual screen is drawn, after that it presents final image using SDL_Renderer. In practice this means that it may output with DirectX or OpenGL.
  • For the same reason, had to remove Hqx scaling filters. Idk if they were much used nowadays anyway.

Notable issues / future todo:

  • May need to expand configuration option for renderer choice, e.g. to choose whether software mode uses hardware-accelerated output or not.
  • Apparently software mode works slow for non-32bit games (need to look if it's possible to improve the final rendering).

Building

Must update CI scripts. What is necessary here?

Notable issues / future todo:

  • Investigate if possible to remove Apeg dependency on libvorbis and libogg (as we have SDL2_Sound now).

SDL2: general backend;
SDL_Sound: for reading and decoding sound formats;
MojoAL: a SDL-based implementation of OpenAL API.
Based on the work of @sonneveld (Nick Sonneveld); only relevant code, plus tidied up a little.
Based on the work of @sonneveld (Nick Sonneveld); only relevant code, plus tidied up a little.
Based on the work of @sonneveld (Nick Sonneveld).

Audio now plays only on a separate thread, unconditionally.

Removed:
* Allegro4-based SOUNDCLIP implementations;
* old audio thread (now implemented in audio core module);
* obsolete config settings;
* PSP sound cache (may be reimplemented later).
There's some kind of race condition with MojoAL which may try to mix-in our new clip before it gets properly initialized with data. When it does so, it drops the clip out of the slot.
Here we prevent this by polling at least some data in before calling alSourcePlay.
Based on the work of @sonneveld (Nick Sonneveld).
Unfortunately, game processing is not fit for a single event poll, as game thread may be looping in a certain state for a while before returning to the main loop (such as running a dialog script, waiting for a blocking action to complete, etc). Fixing this is a task for another time.
At the moment we are adding event polls into each sub-state.
Based on the work of @sonneveld (Nick Sonneveld).

Plans for the future refactoring: make gfx driver *return* SDL_Window it creates from SetDisplayMode(), and let engine save it as current render window.
Based on the work of @sonneveld (Nick Sonneveld).

This simplifies the code and makes it uniform for Linux, Windows and MacOSX altogether.
Based on the work of @sonneveld (Nick Sonneveld).
Based on the work of @sonneveld (Nick Sonneveld).
Mouse speed control was necessary mostly for Direct3D fullscreen, because Allegro4 had some issues with mouse input in that mode. SDL2 does not seem to have such problem.
But I'd like to keep this functionality in the engine just in case, at least for some time.
Based on the work of @sonneveld (Nick Sonneveld) with certain simplifications.
Based on the work of @sonneveld (Nick Sonneveld) with certain simplifications.

This keeps original AGS keycodes (based on allegro scancodes, although that's irrelevant now) throughout the engine, and only replaces the way it's generated from backend events.
Note that this won't be compatible with unicode text events, and simple AGS code will have to be replaced with something to optionally store unicode text as well.
Also, in the future it may be beneficial to refactor event handling globally, and pass all wanted events to the engine components, either directly, or converted to convenient custom data.
Based on the work of @sonneveld (Nick Sonneveld) with minor modifications and fixes.
AGS still uses following from Allegro lib:
* bitmaps, drawing, blending and palette functions;
* functions for loading/saving bitmaps and pcx;
* playing FLIC;
* PACKFILE (used in limited situations, e.g. FLIC);
* fixed math functions;
* file path and find-file functions;
* unicode functions;
@ivan-mogilko ivan-mogilko added backend: allegro related to allegro 4 library ags3 related to ags3 (version with full backward compatibility) backend: sdl2 related to sdl2 library labels Nov 29, 2020
@ivan-mogilko ivan-mogilko added this to the 3.6.0 milestone Nov 29, 2020
@ivan-mogilko ivan-mogilko mentioned this pull request Nov 29, 2020
@ivan-mogilko ivan-mogilko merged commit d4b4ec4 into adventuregamestudio:ags3--sdl2 Dec 2, 2020
@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Dec 2, 2020

Ok, I merged this into ags3--sdl2 branch, guess it's easier for letting more people test it and find issues to fix.

I wonder, when would be a good time to merge this into ags4? Considering ags4 branch does not have any deadline/milestone yet, doubt it needs preliminary release with allegro 4 backend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ags3 related to ags3 (version with full backward compatibility) backend: allegro related to allegro 4 library backend: sdl2 related to sdl2 library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant