I have this code which is called once when the state is entered for the first time the idea was each state would load/setup everything it needs to function the problem I encountered so far with this approach creating some objects such as the model takes a few seconds so when switching to the state there's a bit of a delay and I'm trying to figure out what I can do about that. I've done some research and it seems like this is where the use of threads come in so that you can load assets in the background without delaying code, but this seems just a bit out of my learning scope lol so my idea was to just do everything when the game starts, but I realized I wouldn't be able to do anything since I can't pass it to the state since it inherits from a base class so every other state would need the same parameters.
// GameState.h
class GameState {
public:
bool initialized = false;
virtual void Init() {
initialized = true;
}
virtual void Enter(GameState* previousState) {}
virtual void Leave() {}
virtual void Resume() {}
virtual void Update() {}
};
// PlayState.cpp
void PlayState::Init() {
std::cout << "Play Initialized.\n";
GameState::Init();
camera = new Camera;
shader = new Shader("Resources/Shaders/Model.vert", "Resources/Shaders/Model.frag");
model = new Model("Resources/Models/Maria/Maria J J Ong.dae");
idleAnimation = new Animation("Resources/Animations/Idle.dae", model);
animator = new Animator(idleAnimation);
}