-
-
Notifications
You must be signed in to change notification settings - Fork 126
Protected SFML Methods cannot be consumed by CSFML consumers #394
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
Comments
Let's consider all of the protected virtual methods in SFML and how CSFML deals with them:
My thoughts about this are:
The important part about this is that CSFML knows how to deal with abstract methods, but it doesn't have a solution for virtual methods that already have an implementation available. We could use something similar to mixins to allow CSFML users to override those methods. For example: // implementation
typedef bool (*sfMusicOnGetDataOriginal)(sfMusic*, sfChunk*); ///< sf::Music::onGetData callback
typedef bool (*sfMusicOnGetDataMixin)(sfMusicOnGetDataOriginal, sfMusic*, sfChunk*); ///< mixin
CSFML_AUDIO_API void sfMusic_setOnGetData(const sfMusic* music, sfMusicOnGetDataMixin mixin);
// sample usage
bool myCustomOnGetData(sfMusicOnGetDataOriginal original, sfMusic* music, sfChunk* data) {
// do something before the call
bool result = original(music, data);
// do something after the call with data
return result;
}
sfMusic_setOnGetData(myMusic, myCustomOnGetData); // sets the override
sfMusic_setOnGetData(myMusic, NULL); // restores the original sf::Music implementation Then CSFML would use the given callback in a wrapper class that extends bool onGetDataOriginal(sfMusic* music, sfChunk* data) {
sf::SoundStream::Chunk cppData;
// copy from data to cppData
bool result = music->onGetData(&cppData);
// copy from cppData to data
return result;
}
bool sfMusic::onGetData(sf::SoundStream::Chunk& data) {
if (!m_onGetData)
return sf::Music::onGetData(data);
sfChunk cData;
// copy from data to cData
bool result = m_onGetData(onGetDataOriginal, this, &cData);
// copy from cData to data
return result;
} This code might not be correct or make sense that much, but you get the idea. CSFML users would be allowed to do anything they want in the mixin, including doing stuff before the original method, after the original method, and potentially not call the original method to begin with. |
Consider sf::Audio
This is a protected method, intended to be overriden by user classes for custom behaviour when required.
Consider the usecase of wanting to present and draw the waveform of Audio streamed from disk with sf::Audio
This is impossible with consumers of CSFML or those downstream (e.g.: SFML.Net C# Consumers)
I do not know how it ought to be done, but consumers of CSFML should have a way to consume and override or obtain information from these protected methods.
As of right now, if one wants said waveform in C# they would need to fork SFML, create a new class that overrides onGetData, fork CSFML to bind that functionality, and then bind that into C# via SFML.Net. That's a bit much, ain't it?
The text was updated successfully, but these errors were encountered: