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 #1136

Closed
Closed

Conversation

ivan-mogilko
Copy link
Contributor

@ivan-mogilko ivan-mogilko commented Nov 29, 2020

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) labels Nov 29, 2020
@ivan-mogilko ivan-mogilko added this to the 3.6.0 milestone Nov 29, 2020
@ivan-mogilko ivan-mogilko added the backend: sdl2 related to sdl2 library label Nov 29, 2020
@jdiperla
Copy link

jdiperla commented Nov 29, 2020 via email

@ericoporto
Copy link
Member

ericoporto commented Nov 29, 2020

This is amazing! 🤯

At first I was a bit confused with how the merge was possible but then I checked ags3--sdl commits and it's really ags3 (for now), so this PR is as planned in #1121 . 🎆 🎆 🎆 😄

Must update CI scripts. What is necessary here?

This means updating the CI scripts in this PR or after merge? I think it's fine to update after.

It probably needs to update Dockerfiles for everything to include SDL and SDL_Sound libraries required, and then have the environment variables in Cirrus-CI yml point to where they are on the Windows builds, and disable the Android build temporarily since it won't work with current Android project (which is based in the old Allegro Android backend). There may be things that can be removed from the dockerfiles, like Allegro4.

@morganwillcock will definitely know more details


I made a branch with some modifications to get the CI to build but hasn't been able to finish it, once it works I can create a new branch with properly organized commits.

@ivan-mogilko ivan-mogilko changed the base branch from ags3--sdl to ags3--sdl2 November 29, 2020 17:16
@ivan-mogilko ivan-mogilko deleted the branch adventuregamestudio:ags3--sdl2 November 29, 2020 17:16
@ivan-mogilko
Copy link
Contributor Author

ivan-mogilko commented Nov 29, 2020

Sorry, I was renaming target branch in the main repository and deleted the wrong one afterwards, so this pr got closed and I could not realize how to restore it again.

I opened a new identical one instead: #1137

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.

3 participants