Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:22:10+00:00 2026-05-25T13:22:10+00:00

I am coding an Audio Manager for a game engine, and I would like

  • 0

I am coding an Audio Manager for a game engine, and I would like to keep it generic so that different games could use the same engine. Right now I am using a Dictionary<string,SoundEffect> to store the sounds and the events they are associated with. I would much rather use an Enum for the Key, for the many benefits it would entail. Right now, someone could AddSound("Explosion", explosionSound) and another programmer on our team could PlaySound("ExplosionSpelledWrong") and so forth.

I would like the Audio Manager to reference a “SoundEvent” enum. My problem is that the contents of this enum are going to be game-specific. Some games might have:

enum SoundEvent {    
    Explosion,
    GameOver
}

another might have

enum SoundEvent {    
    Jump,
    Laser
 }

and so on.

Note that I don’t need to ever reference the contents of the enum in the Audio Manager, since it is just going to be a key in the dictionary — the specific SoundEvent will always be specified in the game-specific project.

So how do I keep my engine separate from the game-specific project? I don’t want to refer to anything game-specific in the audio manager.

The first thing I thought of was just to make a namespace GameSpecificEnums that would nonetheless be part of the Engine project and put them in there. However, for making a different game, one would therefore have to alter this part of the Engine project. It wouldn’t be a big deal in reality, but it doesn’t sit right.

My other thought is to change the Dictionary to Dictionary<int,SoundEffect> and then have something like this in game-specific code:

static class SoundEvent {
    private const int Explosion = 0;
    private const int Laser     = 1;
    // etc.
}

and then call the Audio Manager with things like:

AudioManager.Add(SoundEvent.Explosion, explosionSound);

but this doesn’t feel right either, since someone could AudioManager.PlaySound(2112)

Is there another solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:22:10+00:00Added an answer on May 25, 2026 at 1:22 pm

    It sounds like you might want to make AudioManager generic in the key type. You could do that without any restrictions, or you could try to constrain it to enums. That isn’t feasible with “normal” C#, but I have a project called Unconstrained Melody which accomplishes it with IL rewriting. That’s probably overkill here – you could always constrain the key type to be a struct and just expect everyone to use it properly.

    Then your PlaySound method would take a key of type TKey etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I would like somehow that given an audio file as input (most
Our coding standards ask that we minimise the use of C# var (suggests limiting
I would like to build a live coding framework. I should explain what is
When coding, what is a good rule of thumb to keep in mind with
I'm coding an audio player where a thread updates the TextView representing the track's
I'm coding in ASP.NET and want to store audio files (.mp3, or smaller formats)
I have a feed coming from Wordpress and flowing through Feedburner. I would like
I'm looking for a media player (audio) that I can embed in my website
I am creating a music streaming website like Grooveshark. I have done the coding
I have this code to send an emai with an audio attachment that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.