docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#Game loop

本页内容

A 60 fps loop that keeps the garbage collector out of its frames: a pause goal, particles in a frame arena, drawing in a region that never collects, and a minor collection in the time left of each frame.

#Code

#Walkthrough

  • gc::set_pause_goal(2.0) sizes the young generation so a minor collection takes about 2 ms, from what the last ones cost (Garbage collector pauses).
  • The particles of a frame live in an Arena<Particle>: alloc appends each one in place and parts.reset() drops them all at once. An ArenaRef from an earlier frame panics when used, so a stale reference cannot read this frame's particle (Arena).
  • The entities change in place with for ref e in ents, which binds each element as a place instead of a copy (Collections and iterators).
  • The debug lines are ordinary strings: garbage by the next frame, freed by the minor collection.
  • Drawing runs inside gc::no_collect: no allocation there starts a collection, on any thread; if the young budget runs out, the heap grows and the collection waits for the end of the region.
  • At the end of the frame gc::collect_young_within runs a minor collection only if the last ones say it fits in what is left of the frame, minus a millisecond of margin. The frame then sleeps to the next 16.7 ms tick.
  • To see the frame times, keep the longest ms and print it, or run with NABIR_GC_STATS=1: the summary gives each kind of pause's p99 and longest.

Found a mistake? Edit this page on GitHub. Last updated