D.V.D
Make a wish
- Reaction score
- 73
Hello, I was looking at virtual functions and I was trying to use them to structure my gaming project to have the option of running multiple engines based on which was chosen upon startup or part way through with the use of a framework that gets overridden by the needed engine code. This would benefit not having to create a new visual studio project for every little graphics stuff I want to test out. The idea goes like this, I have a class that has the OpenGL engine running and it has virtual functions for rendering, or when a mouse is clicked, or when a keyboard event occurs, or any other standard glut functionality.
I have an object of this framework class created in the main.cpp function which executes the game loop and initializes the program. Now I want to have these functions get overwritten by some other game engines, but I don't want to have to specify which one gets overwritten in the code, but upon starting the program. So it would kinda be like a demo window pops up and asks you to choose which game to run out of a list of options, each one potentially overwritting the main frameworks functions but it isn't decided which one does so until I choose one in the demo program.
How would I do this because from my understanding, I'd have to do something like this:
Is there a way of getting around this? Im pretty sure there is, I just couldn't seem to figure it out.
Code:
class GameFramework {
public:
virtual void OnMouseClick ();
virtual void OnKeyboard ();
virtual void OnRender ();
//...etc
private:
};
Code:
class GameFramework {
public:
virtual void OnMouseClick ();
virtual void OnKeyboard ();
virtual void OnRender ();
//...etc
void startup () {
create window
float chosen getinput();
make class options[chosen] override class
}
private:
std::vector <&GameEngine> options;
};
Code:
class GameFramework :: Prespecified Game Engine {
public:
virtual void OnMouseClick ();
virtual void OnKeyboard ();
virtual void OnRender ();
virtual void OnStartup ();
//...etc
void startup () {
run OnStartup();
}
private:
std::vector <&GameEngine> options;
};