Newer
Older
Import / applications / HighwayDash / ports / Framework / SystemInformation.h
//  BlockyFroggy
//  Copyright © 2017 John Ryland.
//  All rights reserved.
#pragma once
#ifndef SYSTEM_INFO_H
#define SYSTEM_INFO_H


#include <chrono>


//! Time related functions
namespace GameTime
{
  //typedef std::chrono::time_point<std::chrono::high_resolution_clock, std::nano>  TimePoint;
  typedef std::chrono::high_resolution_clock::time_point     TimePoint;
  typedef std::chrono::duration<uint64_t, std::nano>         Duration;

  inline TimePoint now()
  {
    return std::chrono::high_resolution_clock::now();
  }
} // namespace GameTime


class SystemInformation
{
public:
  SystemInformation();
  ~SystemInformation();

  float  getCpuUsage();
  size_t getMemoryUsage();
  float  getFrameTime();
  float  getDrawTime();
  float  getFps();
  float  getAverageFps();

  void   preDraw();    // call before calling draw to measure time inside draw
  void   frameDrawn(); // call every frame to update fps values

private:
  float m_fps;
  float m_averageFps; // the average FPS over 15 frames
  float m_averageFpsSum;
  int   m_averageFpsCounter;
  GameTime::TimePoint m_lastFrameTimePoint;
  GameTime::Duration  m_lastFrameDuration;
  GameTime::TimePoint m_preDrawTimePoint;
  GameTime::Duration  m_postDrawFrameDuration;
};


#endif // SYSTEM_INFO_H