Hey,
I’m trying to have various components in my game pre-register themselves upon startup of the game. I’m using this pattern:
Here’s my registration code that is in one .cpp file. The register_init() function is available from anywhere:
std::vector&get_init() { static std::vector goods; return goods; } bool register_init(Init *v) { get_init().push_back(v); return true; }
Here’s how I auto-register some init code from some other file by calling register init to initialize a variable:
int _is_levedit_init = register_init(new LeveditInit());
Is there some case where this would NOT work or is somehow a really bad idea? Or is there some pattern that is better to use?
-Phil