Services #852
gamecoder-nz
started this conversation in
General
Services
#852
Replies: 3 comments 1 reply
|
Do you mean service as in service locator? In this case, it's a well known pattern (see here for an example). Definitely not invented here. 🙂 |
0 replies
|
Ah I see. Is there an example of how it is used with entt?
…On Tue, Mar 8, 2022 at 8:33 PM Michele Caini ***@***.***> wrote:
Do you mean *service* as in *service locator*? In this case, it's a well
known pattern (see here
<https://gameprogrammingpatterns.com/service-locator.html> for an
example). Definitely not invented here. 🙂
—
Reply to this email directly, view it on GitHub
<#852 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKHPB7VH6EYXOXMV4QP6RHLU637FPANCNFSM5QESAZUQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
0 replies
|
I figured it out. If anyone needs an example: #include <iostream>
#include <entt/entt.hpp>
using namespace std;
class Audio
{
public:
virtual ~Audio() {}
virtual void playSound(int soundID) = 0;
virtual void stopSound(int soundID) = 0;
virtual void stopAllSounds() = 0;
};
class ConsoleAudio : public Audio
{
public:
virtual void playSound(int soundID)
{
printf("Play sound\n");
}
virtual void stopSound(int soundID)
{
printf("Stop sound\n");
}
virtual void stopAllSounds()
{
printf("Stop all sounds\n");
}
};
int main()
{
entt::locator<Audio>::emplace<ConsoleAudio>();
Audio &service = entt::locator<Audio>::value();
service.playSound(0);
return 0;
} |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
What is a service? Is that another name for a system?
All reactions