/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Utilities/Stats.h
66 строк
3 KB
Jan Krassnigg
Even more migration to ezStringView (Tools, Plugins, Foundation) (#979)
08 июн 2023, 15:18
Не верифицирован
08 июн 2023, 15:18
568268d
Код
Авторство
О чём код?
#pragma once #include <Foundation/Basics.h> #include <Foundation/Communication/Event.h> #include <Foundation/Containers/Map.h> #include <Foundation/Strings/String.h> #include <Foundation/Types/Variant.h> /// \brief This class holds a simple map that maps strings (keys) to strings (values), which represent certain stats. /// /// This can be used by a game to store (and continuously update) information about the internal game state. Other tools can then /// display this information in a convenient manner. For example the stats can be shown on screen. The data is also transmitted through /// ezTelemetry, and the ezInspector tool will display the information. class EZ_FOUNDATION_DLL ezStats { public: using MapType = ezMap<ezString, ezVariant>; /// \brief Removes the stat with the given name. /// /// This will also send a 'remove' message through ezTelemetry, such that external tools can remove it from their list. static void RemoveStat(ezStringView sStatName); /// \brief Sets the value of the given stat, adds it if it did not exist before. /// /// szStatName may contain slashes (but not backslashes) to define groups and subgroups, which can be used by tools such as ezInspector /// to display the stats in a hierarchical way. /// This function will also send the name and value of the stat through ezTelemetry, such that tools like ezInspector will show the /// changed value. static void SetStat(ezStringView sStatName, const ezVariant& value); /// \brief Returns the value of the given stat. Returns an invalid ezVariant, if the stat did not exist before. static const ezVariant& GetStat(ezStringView sStatName) { return s_Stats[sStatName]; } /// \brief Returns the entire map of stats, can be used to display them. static const MapType& GetAllStats() { return s_Stats; } /// \brief The event data that is broadcast whenever a stat is changed. struct StatsEventData { /// \brief Which type of event this is. enum EventType { Add, ///< A variable has been set for the first time. Set, ///< A variable has been changed. Remove ///< A variable that existed has been removed. }; EventType m_EventType; ezStringView m_sStatName; ezVariant m_NewStatValue; }; using ezEventStats = ezEvent<const StatsEventData&, ezMutex>; /// \brief Adds an event handler that is called every time a stat is changed. static void AddEventHandler(ezEventStats::Handler handler) { s_StatsEvents.AddEventHandler(handler); } /// \brief Removes a previously added event handler. static void RemoveEventHandler(ezEventStats::Handler handler) { s_StatsEvents.RemoveEventHandler(handler); } private: static ezMutex s_Mutex; static MapType s_Stats; static ezEventStats s_StatsEvents; };