3939// custom:
4040#include " client/renderer/PatchManager.hpp"
4141#include " client/locale/Language.hpp"
42+ #include " stats/AchievementMap.hpp"
43+ #include " stats/Stats.hpp"
4244
4345float Minecraft::_renderScaleMultiplier = 1 .0f ;
4446
@@ -72,20 +74,21 @@ Minecraft::Minecraft() :
7274 m_pGameMode = nullptr ;
7375 m_pTextures = nullptr ;
7476 m_pFont = nullptr ;
77+ m_pStatsCounter = nullptr ;
7578 m_pRakNetInstance = nullptr ;
7679 m_pNetEventCallback = nullptr ;
7780 field_2B0 = 0 ;
7881 m_pUser = nullptr ;
7982 m_pLevel = nullptr ;
8083 m_pPlayer = nullptr ;
81- m_pCameraEntity = nullptr ; // why is there a duplicate? (this is used for the camera)
84+ m_pCameraEntity = nullptr ;
8285 field_D0C = 0 ;
8386 m_pScreen = nullptr ;
8487 field_D18 = 10 ;
8588 m_pInputHolder = nullptr ;
8689 m_bGrabbedMouse = false ; // this was true by default. why? we do not start off in-game...
8790 m_bIsTouchscreen = false ;
88- m_pLevelStorageSource = nullptr ; // TODO
91+ m_pLevelStorageSource = nullptr ;
8992 m_bIsLevelLoaded = false ;
9093 m_ticks = 0 ;
9194 m_missTime = 0 ;
@@ -683,6 +686,7 @@ void Minecraft::tick()
683686
684687 tickInput ();
685688
689+ m_pStatsCounter->tick ();
686690 m_gui.tick ();
687691
688692 if (m_async.empty ())
@@ -830,6 +834,7 @@ void Minecraft::init()
830834 m_pGameRenderer = new GameRenderer (this );
831835 m_pParticleEngine = new ParticleEngine (m_pLevel, m_pTextures);
832836 m_pUser = new User (getOptions ()->m_playerName .get (), " " );
837+ m_pStatsCounter = new StatsCounter (m_pUser, m_externalStorageDir);
833838
834839 setScreen (new IntroScreen);
835840 m_async.emplace_back (std::bind (&Minecraft::initAssets, this ));
@@ -842,6 +847,7 @@ void Minecraft::initAssets()
842847 GrassColor::init (m_pPlatform->loadTexture (" misc/grasscolor.png" , true ));
843848 FoliageColor::init (m_pPlatform->loadTexture (" misc/foliagecolor.png" , true ));
844849 Language::getInstance ()->init (getOptions ());
850+ AchievementMap::getInstance ()->init ();
845851}
846852
847853Minecraft::~Minecraft ()
@@ -1043,7 +1049,7 @@ void Minecraft::setLevel(Level* pLevel, const std::string& text, std::shared_ptr
10431049
10441050 if (m_pRakNetInstance->m_bIsHost && m_pMinecraftServer && m_pMinecraftServer->m_pConnection ->m_onlinePlayers .empty ())
10451051 {
1046- m_pRakNetInstance->announceServer (m_pUser->m_guid );
1052+ m_pRakNetInstance->announceServer (m_pUser->m_username );
10471053 _levelGenerated ();
10481054 }
10491055 else if (!m_pRakNetInstance->m_bIsHost )
@@ -1120,12 +1126,18 @@ void Minecraft::selectLevel(const std::string& a, std::function<void(LevelData&)
11201126 hostMultiplayer ();
11211127 if (prepare)
11221128 prepare (m_pMinecraftServer->m_levelData );
1129+
1130+ m_pStatsCounter->addStat (Stats::startGame, 1 );
11231131 if (m_pMinecraftServer->m_bIsNew )
11241132 {
1133+ m_pStatsCounter->addStat (Stats::createWorld, 1 );
11251134 m_delayed.push_back (std::bind (&Minecraft::setLevel, this , m_pMinecraftServer->getLevel (), " Generating level" , nullptr ));
11261135 }
11271136 else
1137+ {
1138+ m_pStatsCounter->addStat (Stats::loadWorld, 1 );
11281139 m_delayed.push_back (std::bind (&Minecraft::setLevel, this , m_pMinecraftServer->getLevel (m_pMinecraftServer->m_levelData .getDimension ()), " Loading level" , nullptr ));
1140+ }
11291141 m_bIsLevelLoaded = true ;
11301142}
11311143
@@ -1155,7 +1167,7 @@ void Minecraft::leaveGame()
11551167void Minecraft::hostMultiplayer ()
11561168{
11571169#ifndef __EMSCRIPTEN__
1158- m_pRakNetInstance->host (m_pUser->m_guid , C_DEFAULT_PORT , C_MAX_CONNECTIONS );
1170+ m_pRakNetInstance->host (m_pUser->m_username , C_DEFAULT_PORT , C_MAX_CONNECTIONS );
11591171 ServerSideNetworkHandler* handler = new ServerSideNetworkHandler (this , m_pRakNetInstance);
11601172 m_pNetEventCallback = handler;
11611173 m_pMinecraftServer->setConnection (handler);
0 commit comments