I'm working on a engine and game in C++ and I got a couple of manager/subsystem type classes which I probably won't have more then one of, but I don't want to make them singletons (although that would probably be the easiest solution) instead dependency injection seems to be a better alternative(?)
For some context I have a game class which originally was responsible for initializing everything, but the thought had occurred that subsystems like input manager, renderer are part of the engine which gets used throughout the game so I moved that stuff into the main function the problem though is how does the game use them?
My solution was this probably improper use of DI
// main function
inputManager = new InputManager();
toolOverlay = new ToolOverlay();
meshManager = new MeshManager();
shaderManager = new ShaderManager();
ui = new UI(rmlContext);
scene = new Scene();
game = new Game(*inputManager, *meshManager, *shaderManager, *ui, *scene);
// game.cpp
Game::Game(InputManager& inputManager, MeshManager& meshManager, ShaderManager& shaderManager, UI& ui, Scene& scene) :
inputManager(inputManager),
meshManager(meshManager),
shaderManager(shaderManager),
uiManager(ui),
scene(scene)
{
AssetHandle suzanne = meshManager.loadMesh("Assets/Meshes/suzanne.obj");
AssetHandle basic = shaderManager.loadShader("Assets/Shaders/Mesh.vert", "Assets/Shaders/Mesh.frag");
player = std::make_unique<Player>(suzanne, basic);
camera = std::make_unique<Camera>(inputManager);
}
All I really seem to do was add bloat to the parameter list lol.