FrameMetrics.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. /** FrameMetrics.h */
  24. #pragma once
  25. #ifndef __FRAMEMETRICS_H
  26. #define __FRAMEMETRICS_H
  27. #include "Lib/BaseType.h"
  28. #include "GameNetwork/NetworkDefs.h"
  29. class FrameMetrics {
  30. public:
  31. FrameMetrics();
  32. virtual ~FrameMetrics();
  33. void init();
  34. void reset();
  35. void doPerFrameMetrics(UnsignedInt frame);
  36. void processLatencyResponse(UnsignedInt frame);
  37. void addCushion(Int cushion);
  38. Real getAverageLatency();
  39. Int getAverageFPS();
  40. Int getMinimumCushion();
  41. protected:
  42. // These are used for keeping track of parameters to the run ahead equation.
  43. // frames per second history variables.
  44. Real *m_fpsList; ///< A record of how many game logic frames per second there were for the last 60 seconds.
  45. time_t m_lastFpsTimeThing; ///< The time when the last fps entry started being recorded.
  46. Int m_fpsListIndex; ///< Index into the array of the current fps list entry being measured.
  47. Real m_averageFps; ///< The current average logic fps, computed just like m_averageLatency below but with the fps numbers.
  48. // round trip time to packet router variables.
  49. // The lists are indexed off the frame number of the frame info packet they are associated with.
  50. // The index used should be the frame number mod the array length.
  51. Real *m_latencyList; ///< A record of the round trip latencies of the frame info packets to the packet router. Values in seconds.
  52. time_t *m_pendingLatencies; ///< The latencies of frame info packets that are "in the air."
  53. Real m_averageLatency; ///< The current average latency, this is used to save calculation time.
  54. ///< When a new latency value is received, the old one is subtracted out and the new
  55. ///< one is added in.
  56. // packet arrival cushion variables.
  57. // Keeps track of the cushion for the incoming commands.
  58. UnsignedInt m_cushionIndex; ///< The next index to use for the cushion list.
  59. Int m_minimumCushion; ///< The average cushion for the history.
  60. };
  61. #endif // __FRAMEMETRICS_H