Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef SERVERBENCHMARK_BASE_H
  7. #define SERVERBENCHMARK_BASE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. // The base server code calls into this.
  12. class IServerBenchmark
  13. {
  14. public:
  15. virtual bool StartBenchmark() = 0;
  16. virtual void UpdateBenchmark() = 0;
  17. virtual void EndBenchmark() = 0;
  18. virtual bool IsBenchmarkRunning() = 0;
  19. virtual bool IsLocalBenchmarkPlayer( CBasePlayer *pPlayer ) = 0;
  20. // Game-specific benchmark code should use this.
  21. virtual int RandomInt( int nMin, int nMax ) = 0;
  22. virtual float RandomFloat( float flMin, float flMax ) = 0;
  23. virtual int GetTickOffset() = 0;
  24. };
  25. extern IServerBenchmark *g_pServerBenchmark;
  26. //
  27. // Each game can derive from this to hook into the server benchmark.
  28. //
  29. // Hooks should always use g_pServerBenchmark->RandomInt/Float to get random numbers
  30. // so the benchmark is deterministic.
  31. //
  32. // If they use an absolute tick number for anything, then they should also call g_pServerBenchmark->GetTickOffset()
  33. // to get a tick count since the start of the benchmark instead of looking at gpGlobals->tickcount.
  34. //
  35. class CServerBenchmarkHook
  36. {
  37. public:
  38. CServerBenchmarkHook();
  39. virtual void StartBenchmark() {}
  40. virtual void UpdateBenchmark() {}
  41. virtual void EndBenchmark() {}
  42. // Give a list of model names that can be spawned in for physics props during the simulation.
  43. virtual void GetPhysicsModelNames( CUtlVector<char*> &modelNames ) = 0;
  44. // The benchmark will call this to create a bot each time it wants to create a player.
  45. // If you want to manage the bots yourself, you can return NULL here.
  46. virtual CBasePlayer* CreateBot() = 0;
  47. private:
  48. friend class CServerBenchmark;
  49. static CServerBenchmarkHook *s_pBenchmarkHook; // There can be only one!!
  50. };
  51. #endif // SERVERBENCHMARK_BASE_H