# Frame [[src]] [Document][doc] / Frame [Frame]: https://hackmd.io/@latte488/HyqvV0mSU [src]: https://github.com/latte488/rudps-cpp/blob/master/include/frame.hpp ###### tags: `Frame` [doc]: https://hackmd.io/@latte488/B1jeueVHL フレーム毎の情報を提供する。 ## Method ### explicit Frame() noexcept 初期化します。 ### void Update() noexcept フレーム毎に呼ばれることを想定します。 もしフレーム毎に呼ばれなかった場合、他のメソッドは正常に機能しません。 ### const size_t& Count() const noexcept Updateが呼ばれた回数を返します。 ### const long& Time() const noexcept UTCベースの現在の時刻を秒単位で返します。 ### const long& NanoTime() const noexcept UTCベースの現在の秒未満の時刻をナノ秒単位で返します。 ### const long& DeltaTime() const noexcept 現在の時刻と前回の時刻の差分をナノ秒単位で返します。 ## Example この例では、フレーム毎の情報を表示します。ただし、フレーム毎の処理が軽い場合、時刻の取得が速すぎて差分はうまく計測できないため、擬似的に重い処理をシュミレートさせています。 ```cpp #include <stdio.h> #include <frame.hpp> int main() { auto heavy = [] { size_t sum = 0; for (size_t i = 0; i < 1e8; ++i) { sum += i; } }; Frame frame; for (size_t i = 0; i < 8; ++i) { frame.Update(); printf("frame.Count : %lu\n", frame.Count()); printf("frame.Time : %lus\n", frame.Time()); printf("frame.NanoTime : %luns\n", frame.NanoTime()); printf("frame.DeltaTime : %ldns\n", frame.DeltaTime()); printf("\n"); heavy(); } return 0; } ``` ## Version - g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - c++17