BVB Source Codes

CRYENGINE Show GameStats.h Source code

Return Download CRYENGINE: download GameStats.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.    Description:
  8.  
  9.    -------------------------------------------------------------------------
  10.    History:
  11.    - 17:11:2006   15:38 : Created by Stas Spivakov
  12.  
  13. *************************************************************************/
  14. #ifndef __GAMESTATS_H__
  15. #define __GAMESTATS_H__
  16.  
  17. #if _MSC_VER > 1000
  18.         #pragma once
  19. #endif
  20.  
  21. #include "IGameplayRecorder.h"
  22. #include "IActorSystem.h"
  23. #include "ILevelSystem.h"
  24.  
  25. struct IStatsTrack;
  26. struct IServerReport;
  27.  
  28. class CGameStats :
  29.         public IGameplayListener,
  30.         public ILevelSystemListener,
  31.         public IGameFrameworkListener,
  32.         public IHostMigrationEventListener
  33. {
  34. private:
  35.  
  36.         struct  SPlayerStats;
  37.         struct  SRoundStats;
  38.  
  39.         struct  SPlayerInfo
  40.         {
  41.                 //these are used to report score/status to server list
  42.                 string                name;
  43.                 int                   team;
  44.                 int                   rank;
  45.                 bool                  spectator;
  46.                 std::map<string, int> scores;
  47.                 //these are 'real' statistics
  48.                 int                   id;
  49.  
  50.                 typedef std::vector<_smart_ptr<SPlayerStats>> TStatsVct;
  51.                 TStatsVct stats;
  52.  
  53.                 void      GetMemoryUsage(ICrySizer* pSizer) const;
  54.  
  55.         };
  56.         typedef std::map<int, SPlayerInfo> PlayerStatsMap;
  57.  
  58.         struct STeamStats
  59.         {
  60.                 int    id;
  61.                 string name;
  62.                 int    score;
  63.         };
  64.         typedef std::map<int, STeamStats> TeamStatsMap;
  65.  
  66.         typedef std::map<string, int>     TStatsKeyMap;
  67.  
  68.         struct Listener;
  69.         struct SStatsTrackHelper;
  70.  
  71. public:
  72.         CGameStats(CCryAction* pGameFramework);
  73.         virtual ~CGameStats();
  74.  
  75.         int ILINE GetChannelId(IEntity* pEntity)
  76.         {
  77.                 IActor* pActor = m_pActorSystem->GetActor(pEntity->GetId());
  78.                 if (pActor)
  79.                         return pActor->GetChannelId();
  80.                 return 0;
  81.         }
  82.  
  83.         //IGamePlayListener
  84.         virtual void OnGameplayEvent(IEntity* pEntity, const GameplayEvent& event);
  85.         //
  86.  
  87.         //ILevelSystemListener
  88.         virtual void OnLevelNotFound(const char* levelName);
  89.         virtual void OnLoadingStart(ILevelInfo* pLevel);
  90.         virtual void OnLoadingLevelEntitiesStart(ILevelInfo* pLevel);
  91.         virtual void OnLoadingComplete(ILevelInfo* pLevel);
  92.         virtual void OnLoadingError(ILevelInfo* pLevel, const char* error);
  93.         virtual void OnLoadingProgress(ILevelInfo* pLevel, int progressAmount);
  94.         virtual void OnUnloadComplete(ILevelInfo* pLevel);
  95.         //
  96.  
  97.         //IGameFrameworkListener
  98.         virtual void OnActionEvent(const SActionEvent& event);
  99.         virtual void OnPostUpdate(float fDeltaTime)    {}
  100.         virtual void OnSaveGame(ISaveGame* pSaveGame)  {}
  101.         virtual void OnLoadGame(ILoadGame* pLoadGame)  {}
  102.         virtual void OnLevelEnd(const char* nextLevel) {}
  103.         //
  104.  
  105.         // IHostMigrationEventListener
  106.         virtual EHostMigrationReturn OnInitiate(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  107.         virtual EHostMigrationReturn OnDisconnectClient(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  108.         virtual EHostMigrationReturn OnDemoteToClient(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  109.         virtual EHostMigrationReturn OnPromoteToServer(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  110.         virtual EHostMigrationReturn OnReconnectClient(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  111.         virtual EHostMigrationReturn OnFinalise(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  112.         virtual void                 OnComplete(SHostMigrationInfo& hostMigrationInfo) {}
  113.         virtual EHostMigrationReturn OnTerminate(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  114.         virtual EHostMigrationReturn OnReset(SHostMigrationInfo& hostMigrationInfo, HMStateType& state);
  115.         // ~IHostMigrationEventListener
  116.  
  117.         void StartSession();
  118.         void EndSession();
  119.         void OnMapSwitch();
  120.         void StartGame(bool server);
  121.         void EndGame(bool server);
  122.         void SuddenDeath(bool server);
  123.         void EndRound(bool server, int winner);
  124.         void NewPlayer(int plr, int team, bool spectator, bool restored);
  125.         void RemovePlayer(int plr, bool keep);
  126.         void CreateNewLifeStats(int plr);
  127.         void ResetScore(int plr);
  128.         void StartLevel();
  129.         void OnKill(int plr, EntityId* extra);
  130.         void OnDeath(int plr, int shooterId);
  131.  
  132.         void GameReset();
  133.         void Connected();
  134.  
  135.         void SetName(int plr, const char* name);
  136.         void SetScore(int plr, const char* score, int value);
  137.         void SetTeam(int plr, int value);
  138.         void SetRank(int plr, int value);
  139.         void SetSpectator(int plr, int value);
  140.         void Update();
  141.  
  142.         void Dump();
  143.         void SaveStats();
  144.         void ResetStats();
  145.  
  146.         void GetMemoryStatistics(ICrySizer* s);
  147.  
  148.         void PromoteToServer();
  149.  
  150. private:
  151.         void Init();
  152.         //set session-wide parameters
  153.         void ReportSession();
  154.         //set game(map)-wide parameters
  155.         void ReportGame();
  156.         //set dynamic parameters
  157.         void Report();
  158.         //submit stats for player to StatsTrack service
  159.         void SubmitPlayerStats(const SPlayerInfo& plr, bool server, bool client);
  160.         //submit stats for server
  161.         void SubmitServerStats();
  162.  
  163.         //player stats
  164.         void ProcessPlayerStat(IEntity* pEntity, const GameplayEvent& event);
  165.  
  166.         bool GetLevelName(string& mapname);
  167.  
  168.         CCryAction*    m_pGameFramework;
  169.         IActorSystem*  m_pActorSystem;
  170.  
  171.         bool           m_playing;
  172.         bool           m_stateChanged;
  173.         bool           m_startReportNeeded;
  174.         bool           m_reportStarted;
  175.  
  176.         PlayerStatsMap m_playerMap;
  177.         TeamStatsMap   m_teamMap;
  178.  
  179.         IStatsTrack*   m_statsTrack;
  180.         IServerReport* m_serverReport;
  181.         Listener*      m_pListener;
  182.         CTimeValue     m_lastUpdate;
  183.         CTimeValue     m_lastReport; //sync data to network engine
  184.  
  185.         //some data about game started
  186.         string                       m_gameMode;
  187.         string                       m_mapName;
  188.  
  189.         CGameStatsConfig*            m_config;
  190.  
  191.         CTimeValue                   m_lastPosUpdate;
  192.         CTimeValue                   m_roundStart;
  193.  
  194.         std::unique_ptr<SRoundStats> m_roundStats;
  195. };
  196.  
  197. #endif /*__GAMESTATS_H__*/
  198.  
downloadGameStats.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top