diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 3f92098c..1ef82cb4 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -394,12 +394,12 @@ int main( int argc, char** argv ) if( initFileOpen ) { - view = std::make_unique( RunOnMainThread, *initFileOpen, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, *initFileOpen, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); initFileOpen.reset(); } else if( connectTo ) { - view = std::make_unique( RunOnMainThread, connectTo, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, connectTo, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } tracy::Fileselector::Init(); @@ -921,11 +921,11 @@ static void DrawContents() { std::string addrPart = std::string( addr, ptr ); uint16_t portPart = (uint16_t)atoi( ptr+1 ); - view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } else { - view = std::make_unique( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } } if( s_config.memoryLimit ) @@ -948,7 +948,7 @@ static void DrawContents() loadThread = std::thread( [f] { try { - view = std::make_unique( RunOnMainThread, *f, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, *f, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } catch( const tracy::UnsupportedVersion& e ) { @@ -1081,7 +1081,7 @@ static void DrawContents() } if( selected && !loadThread.joinable() ) { - view = std::make_unique( RunOnMainThread, v.second.address.c_str(), v.second.port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, v.second.address.c_str(), v.second.port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } ImGui::NextColumn(); const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll; @@ -1250,7 +1250,7 @@ static void DrawContents() viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed ); if( reconnect ) { - view = std::make_unique( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config ); + view = std::make_unique( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, &s_achievements ); } break; default: diff --git a/profiler/src/profiler/TracyView.cpp b/profiler/src/profiler/TracyView.cpp index 67d61aac..3b462ab7 100644 --- a/profiler/src/profiler/TracyView.cpp +++ b/profiler/src/profiler/TracyView.cpp @@ -35,7 +35,7 @@ namespace tracy double s_time = 0; -View::View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config ) +View::View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr ) : m_worker( addr, port, config.memoryLimit == 0 ? -1 : ( config.memoryLimitPercent * tracy::GetPhysicalMemorySize() / 100 ) ) , m_staticView( false ) , m_viewMode( ViewMode::LastFrames ) @@ -55,13 +55,15 @@ View::View( void(*cbMainThread)(const std::function&, bool), const char* , m_acb( acb ) , m_userData() , m_cbMainThread( cbMainThread ) + , m_achievementsMgr( amgr ) + , m_achievements( config.achievements ) { InitTextEditor(); m_vd.frameTarget = config.targetFps; } -View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config ) +View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr ) : m_worker( f ) , m_filename( f.GetFilename() ) , m_staticView( true ) @@ -78,6 +80,8 @@ View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f , m_acb( acb ) , m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() ) , m_cbMainThread( cbMainThread ) + , m_achievementsMgr( amgr ) + , m_achievements( config.achievements ) { m_notificationTime = 4; m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() ); @@ -117,6 +121,12 @@ void View::InitTextEditor() m_sourceViewFile = nullptr; } +void View::Achieve( const char* id ) +{ + if( !m_achievements || !m_achievementsMgr ) return; + m_achievementsMgr->Achieve( id ); +} + void View::ViewSource( const char* fileName, int line ) { assert( fileName ); diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index e2e48373..b73ad30d 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -11,6 +11,7 @@ #include "imgui.h" +#include "TracyAchievements.hpp" #include "TracyBadVersion.hpp" #include "TracyBuzzAnim.hpp" #include "TracyConfig.hpp" @@ -103,8 +104,8 @@ public: using SetScaleCallback = void(*)( float ); using AttentionCallback = void(*)(); - View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config ); - View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config ); + View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr ); + View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb, const Config& config, AchievementsMgr* amgr ); ~View(); bool Draw(); @@ -223,6 +224,7 @@ private: }; void InitTextEditor(); + void Achieve( const char* id ); bool DrawImpl(); void DrawNotificationArea(); @@ -867,6 +869,9 @@ private: bool m_attnFailure = false; bool m_attnWorking = false; bool m_attnDisconnected = false; + + AchievementsMgr* m_achievementsMgr; + bool m_achievements = false; }; }