Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Questions regarding singletons and when to use them

$
0
0
Hello, i'm currently developing spaceshooter game and I encountered few problems with game code design. I have Application class where all managers are. class Application { public: ~Application(); Application(); void addShader(const std::string&, std::shared_ptr<Shader>); void loadTexture(const std::string&, const std::string&, int, int, glm::vec2); std::shared_ptr<Texture> getTexture(const std::string&); inline std::shared_ptr<Font> getFont(const std::string& name) { return fontManager->getFont(name); } void loadFont(const std::string&, const std::string&); inline GameState getState() const { return gameState; } inline void setState(GameState state) { gameState = state; } inline std::shared_ptr<InputManager> getInputManager() const { return inputManager; } inline std::shared_ptr<Renderer> getRender() const { return renderer; } private: std::shared_ptr<Renderer> renderer; std::shared_ptr<TextureManager> textureManager; std::shared_ptr<InputManager> inputManager; GameState gameState; std::shared_ptr<FontManager> fontManager; }; But problem is that I need to access in example TextureManager class somewhere in "OnCollision" method to change texture of collider. How do I do that? Do I create TextureManager singleton or what?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>