Sorry for bothering, I am just studying state management in game loops, and I need some help to understand the reason why the author does things this way.
(抱歉,我只是在游戏循环中研究状态管理,我需要一些帮助来了解作者采用这种方式进行操作的原因。)
void Game::run() {
float newTime, frameTime, interpolation;
float accumulator = 0.f;
float currentTime = gameClock.getElapsedTime().asSeconds();
while(data->renderWindow.isOpen()){
data->stateManager.makeChanges();
newTime = gameClock.getElapsedTime().asSeconds();
frameTime = newTime - currentTime;
if(frameTime > 0.2f)
frameTime = 0.2f; //why this if?
currentTime = newTime;
accumulator += frameTime; //why don't he just make actions every dt time?
while(accumulator >= dt){
data->stateManager.getActiveState()->handleInput();
data->stateManager.getActiveState()->update(dt);
accumulator -= dt;
}
interpolation = accumulator/dt;
data->stateManager.getActiveState()->draw(interpolation); //really can't understand this :(
}
}
I made comments in what I don't understand.
(我对我不了解的地方发表了评论。)
ask by Lauro Rossi translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…