Objects in my game have both update and draw functions as expected, the update function sometimes need a delta time variable and the draw function sometimes needs a window object.
I have seen lots of engines pass in the delta time variable through every update function and pass in the window object through every draw function like so:
//C++
void State::update(float deltaTime)
{
sprite.pos += vel * deltaTime;
}
void State::draw(Window window)
{
window.draw(sprite);
}
The problem with passing these objects through every single update and draw method is that sometimes the're not used. For example, a main menu does not need a delta time variable but does need a window object, but you can't just omit the parameter if you don't need it because the main menu inherits from the game state object which contains the parameters.
So would it be better in design to never pass these objects into functions but instead make them static like so?
//C++
void State::update()
{
sprite.pos += vel * GameManager::deltaTime;
}
void State::draw()
{
GameManager::window.draw(sprite);
}
I'm asking because this is a very fundamental concept to game engines and the latter example just seems to make more since but it seems like the former example is favored.
Which is better code design? Thanks.