我刚刚在conflate
尝试过extrapolate
和akka-streams
。
由于conflate
对我来说很有意义,我没有得到extrapolate
的用例。
为什么我们应该为下游添加更多工作 - 当上游不要求它时?
来自Scala Doc:
允许更快的下游进度独立于较慢的上游。
举个例子:
在视频游戏中,通常至少有两个“循环”:逻辑/游戏循环和渲染循环。通常,游戏循环的速率(“滴答速率”)慢于渲染循环的速率(“帧速率”)。例如,逻辑节拍可能每秒发生10次,但帧速率通常应至少为每秒60帧。为了在刻度线之间呈现某些东西,游戏开发者使用extrapolation or interpolation。您可能已经猜到,外推函数非常适合外推。这是一个示例,其刻度率为每秒10个刻度,没有帧速率限制:
Source.tick(0.millis, 100.millis, 0)
.scan(intialGameState) { (g, _) => tick(g) }
.extrapolate(extrapolateFn)
.runForeach(render)
现在extrapolateFn
只需要返回一个按需提供外推游戏状态的迭代器:
def extrapolateFn(g: GameState) = Iterator.continually {
// Compute how long it has been since `g` was created
// Advance the state by that amount of time
// Return the new state
}