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

The Big CMake + MinGW + Sound PR #127

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

TheBrokenRail
Copy link
Contributor

@TheBrokenRail TheBrokenRail commented Jun 18, 2024

This PR:

  • Refactors the CMake build-system:
    • There is now a top-level CMakeLists.txt so you no longer need to cd platforms/sdl before building the project.
    • SDL is now loaded in platforms/sdl/CMakeLists.txt like you would expect instead of in source/CMakeLists.txt.
    • Sound systems have been decoupled from SDL/Win32. You can now build SDL with DirectSound or Win32 with OpenAL.
    • The Win32 platform can now be built with CMake using MinGW-w64.
    • The SDL platform can also now be built with CMake using MinGW-w64.
    • Both of those configurations have been added to the CI.'
  • Sound is now loaded at runtime instead of being loaded from the binary! (Fixes Load Sounds From Filesystem #119)
    • tools/grabsounds.py now extracts sounds to game/assets/sound using LIEF (which is downloaded automatically).
    • Sound data is loaded using AppPlatform::readAssetFile, which has been implemented (and tested) for both SDL, Win32, and native Android.
    • AppPlatform::getPatchData has been changed to use AppPlatform::readAssetFile.
  • Extra Notes:
    • The macOS build currently only works because I added a ln -s to the CI, someone should probably fix that.
    • I also adjusted the line width calculation for block outlines.
    • And I updated the GLES Compatibility Layer.
    • Finally, I fixed some bugs with Logger.

};

#define SOUND_SYSTEM SoundSystemDS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with renaming all sound systems to CustomSoundSystem. I especially disagree with your choice of using a #define where a typedef would have fit incredibly well.

I would say revert this and then in each AppPlatform, use preprocessor conditions to determine the sound system in that AppPlatform. And use typedef for that.

You can't really use DirectSound on non-Windows; nor can you use OpenSL ES on desktop Linux and Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't really use DirectSound on non-Windows; nor can you use OpenSL ES on desktop Linux and Windows.

The issue is OpenAL. It can be used on both SDL and Win32, so you end up with:

#ifdef USE_OPENAL
#include "SoundSystemAL.h"
#define SOUND_SYSTEM SoundSystemAL
#else
#include "SoundSystemDS.h"
#define SOUND_SYSTEM SoundSystemDS
#endif

In both platforms/sdl/main.cpp and platforms/windows/main.cpp.

I'll switch to typedefs though, that is nicer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's fine. I don't mind that at all.

return "";
AssetFile file = readAssetFile("patches/patch_data.txt");
std::string out = std::string(file.data, file.data + file.size);
delete file.data;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should delete data within the destructor and add move and copy constructors to AssetFile. Because we're using C++.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that require SoundDesc maintaining a copy of AssetFile so the sound data isn't deleted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But you return AssetFile from AppPlatform::readAssetFile so you can just keep the AssetFile in memory (ideally you'd also use std::move to avoid copying)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, funny story. Turns out SoundRepository copies SoundDesc a lot.

So the options are:

  • Modify SoundRepository to store pointers or references (which in turn would require modifying the SoundSystems).
  • Add a copy constructor to AssetFile and copy the sound data whenever it is used, which sounds... really inefficient.
  • Keep the data externally-managed.

@@ -176,7 +176,7 @@ void MobRenderer::renderNameTag(Mob* mob, const std::string& str, float x, float

glPushMatrix();
glTranslatef(x + 0.0f, y + 2.3f, z);
glNormal3f(0.0f, 1.0f, 0.0f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

@iProgramMC
Copy link
Member

Also worth noting that I don't really like giant PRs. Which is why I ask that you create separate PRs for different changes from now on.

@TheBrokenRail
Copy link
Contributor Author

Yeah, sorry about that. I got a bit carried away (clearly).

@TheBrokenRail
Copy link
Contributor Author

Also, I added tools/extract_apk.py. It just calls grabsounds,py and extracts the other assets to game/assets. I mainly created it because I got annoyed with having to figure out how to merge-copy the game assets into game/assets. It also shows a file chooser if you run it by itself, which should make it easier to use for beginners.

@TheBrokenRail
Copy link
Contributor Author

When I get more time, I'm going to split this up into multiple PRs. Until then, I'll mark it as WIP.

@TheBrokenRail TheBrokenRail marked this pull request as draft January 4, 2025 05:50
 * Fixed building on Windows
 * Added support for mob sounds
 * Added support for fire sounds
@BrentDaMage
Copy link
Collaborator

We should really be loading all of our SoundDesc structs dynamically based on the file hierarchy inside /assets/sounds. MCPE 0.12.1 has an "example" of this, even though it's getting most of its info from a JSON file.

 * Re-enabled lighting & normals that were disabled due to merge
 * Re-added smooth outline rendering as fallback
 * Fixed OpenGL reference in CMake files
@BrentDaMage
Copy link
Collaborator

@TheBrokenRail Could you please fix the CMake files? Not sure why the SDL2 and GLES compatibility layer stuff is throwing back errors. I'm gonna make sure the Xcode project works for macOS and iOS tomorrow.

@BrentDaMage BrentDaMage added enhancement New feature or request help wanted Extra attention is needed labels Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load Sounds From Filesystem
3 participants