mardi 25 août 2020

load config file for game, singleton or passing down the tree or anything else?

I'm trying to create simple game in C++. At one point I want to have some setting, save and load from config file. The config file should be read from the beginning, and should be accessible anywhere it needed.

  • So far I only see Singleton pattern as a solution.
  • Another way is to create an object an pass it down, but it can mess up the current code.
  • I've also search and found something called Dependency Injection.
  1. Is dependency injection useful in C++
  2. Which design patterns can be applied to the configuration settings problem?

But I don't quite understand it, you still have to create an object in main and pass it down, right? Singleton is quite simple, but some consider it antipattern, while pass it down the tree can mess up my current code. Is there any other Patterns?
I'm also curious how games load their setting.

Aucun commentaire:

Enregistrer un commentaire