perf: WPO/LTCG, fix potential memory leaks, reduce busy-waits, loop opts; general optimizations

This commit is contained in:
2026-08-01 10:17:35 -07:00
parent dbc183bdf8
commit 8f89209699
18 changed files with 98 additions and 72 deletions
@@ -1,7 +1,7 @@
/*
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
Copyright (C) 2004-2008 Ren Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
@@ -21,7 +21,7 @@
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
Ren Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
@@ -41,7 +41,7 @@ static inline bool is_base64(unsigned char c) {
}
// 4J ADDED,
std::string base64_encode(std::string str)
std::string base64_encode(const std::string& str)
{
return base64_encode( reinterpret_cast<const unsigned char*>(str.c_str()), str.length() );
}
@@ -2,6 +2,6 @@
#include <string>
std::string base64_encode(std::string str);
std::string base64_encode(const std::string& str);
std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);
@@ -314,13 +314,13 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft *minecraft, LPVOID lpParame
Minecraft *pMinecraft = Minecraft::GetInstance();
// Make sure that we have transitioned through any joining/creating stages and are actually playing the game, so that we know the players should be valid
bool changedMessage = false;
while(!IsReadyToPlayOrIdle())
{
changedMessage = true;
pMinecraft->progressRenderer->progressStage( g_NetworkManager.CorrectErrorIDS(IDS_PROGRESS_SAVING_TO_DISC) ); // "Finalizing..." vaguest message I could find
pMinecraft->progressRenderer->progressStagePercentage( g_NetworkManager.GetJoiningReadyPercentage() );
Sleep(10);
}
while(!IsReadyToPlayOrIdle())
{
changedMessage = true;
pMinecraft->progressRenderer->progressStage( g_NetworkManager.CorrectErrorIDS(IDS_PROGRESS_SAVING_TO_DISC) ); // "Finalizing..." vaguest message I could find
pMinecraft->progressRenderer->progressStagePercentage( g_NetworkManager.GetJoiningReadyPercentage() );
Sleep(0);
}
if( changedMessage )
{
pMinecraft->progressRenderer->progressStagePercentage( 100 );
@@ -898,7 +898,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc( void* lpParameter )
TexturePack *tPack = Minecraft::GetInstance()->skins->getSelected();
while ( tPack->isLoadingData() || (Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()) )
{
Sleep(1);
Sleep(0);
}
ui.CleanUpSkinReload();
if(app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None)
@@ -935,7 +935,7 @@ int CGameNetworkManager::ServerThreadProc( void* lpParameter )
{
while((Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()))
{
Sleep(1);
Sleep(0);
}
param->levelGen->loadBaseSaveData();
}
@@ -977,7 +977,7 @@ int CGameNetworkManager::ExitAndJoinFromInviteThreadProc( void* lpParam )
while( g_NetworkManager.IsInSession() )
{
Sleep(1);
Sleep(0);
}
// Xbox should always be online when receiving invites - on PS3 we need to check & ask the user to sign in
@@ -1237,7 +1237,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc( void* lpParam )
// wait for the current session to end
while( g_NetworkManager.IsInSession() )
{
Sleep(1);
Sleep(0);
}
// Reset this flag as the we don't need to know that we only lost the room only from this point onwards, the behaviour is exactly the same
+5 -4
View File
@@ -145,10 +145,11 @@ void EnderDragonRenderer::render(shared_ptr<Entity> _mob, double x, double y, do
int steps = 8;
for (int i = 0; i <= steps; i++)
{
double d=i % steps * PI * 2 / steps;
float s = sin(i % steps * PI * 2 / steps) * 0.75f;
float c = cos(i % steps * PI * 2 / steps) * 0.75f;
float u = i % steps * 1.0f / steps;
int idx = i % steps;
double d = idx * PI * 2 / steps;
float s = sin(d) * 0.75f;
float c = cos(d) * 0.75f;
float u = idx * 1.0f / steps;
//t->color(0x000000);
t->vertexUV(s * 0.2f, c * 0.2f, 0, u, v1);
//t->color(0xffffff);
@@ -94,6 +94,17 @@ void EntityRenderDispatcher::staticCtor()
instance = new EntityRenderDispatcher();
}
EntityRenderDispatcher::~EntityRenderDispatcher()
{
AUTO_VAR(itEnd, renderers.end());
for( classToRendererMap::iterator it = renderers.begin(); it != itEnd; it++ )
{
delete it->second;
it->second = NULL;
}
renderers.clear();
}
EntityRenderDispatcher::EntityRenderDispatcher()
{
glEnable(GL_LIGHTING);
+2 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "EntityRenderer.h"
#include "..\Minecraft.World\Entity.h"
#include "..\Minecraft.World\JavaIntHash.h"
class Entity;
class font;
using namespace std;
@@ -37,6 +37,7 @@ public:
private:
EntityRenderDispatcher();
~EntityRenderDispatcher();
public:
EntityRenderer *getRenderer(eINSTANCEOF e);
+33 -27
View File
@@ -105,8 +105,6 @@ GameRenderer::GameRenderer(Minecraft *mc)
zoom = 1;
zoom_x = 0;
zoom_y = 0;
rainXa = NULL;
rainZa = NULL;
lastActiveTime = Minecraft::currentTimeMillis();
lastNsTime = 0;
random = new Random();
@@ -181,8 +179,9 @@ GameRenderer::GameRenderer(Minecraft *mc)
// 4J Stu Added to go with 1.8.2 change
GameRenderer::~GameRenderer()
{
if(rainXa != NULL) delete [] rainXa;
if(rainZa != NULL) delete [] rainZa;
delete random;
delete cameraPos;
delete lb;
}
void GameRenderer::tick(bool first) // 4J - add bFirst
@@ -838,19 +837,21 @@ void GameRenderer::updateLightTexture(float a)
Level *level = player->level; // 4J - was mc->level when it was just to update the one light texture
float skyDarken1 = level->getSkyDarken((float) 1);
float darken = skyDarken1 * 0.95f + 0.05f;
float rsGsMul = skyDarken1 * 0.65f + 0.35f;
float blockMul = blr * 0.1f + 1.5f;
for (int i = 0; i < 256; i++)
{
float darken = skyDarken1 * 0.95f + 0.05f;
float sky = level->dimension->brightnessRamp[i / 16] * darken;
float block = level->dimension->brightnessRamp[i % 16] * (blr * 0.1f + 1.5f);
float block = level->dimension->brightnessRamp[i % 16] * blockMul;
if (level->skyFlashTime > 0)
{
sky = level->dimension->brightnessRamp[i / 16];
}
float rs = sky * (skyDarken1 * 0.65f + 0.35f);
float gs = sky * (skyDarken1 * 0.65f + 0.35f);
float rs = sky * rsGsMul;
float gs = sky * rsGsMul;
float bs = sky;
float rb = block;
@@ -1526,27 +1527,30 @@ void GameRenderer::tickRain()
int x = x0 + random->nextInt(r) - random->nextInt(r);
int z = z0 + random->nextInt(r) - random->nextInt(r);
int y = level->getTopRainBlock(x, z);
int t = level->getTile(x, y - 1, z);
Biome *biome = level->getBiome(x,z);
if (y <= y0 + r && y >= y0 - r && biome->hasRain() && biome->getTemperature() >= 0.2f)
if (y <= y0 + r && y >= y0 - r)
{
float xa = random->nextFloat();
float za = random->nextFloat();
if (t > 0)
int t = level->getTile(x, y - 1, z);
Biome *biome = level->getBiome(x,z);
if (biome->hasRain() && biome->getTemperature() >= 0.2f)
{
if (Tile::tiles[t]->material == Material::lava)
float xa = random->nextFloat();
float za = random->nextFloat();
if (t > 0)
{
mc->particleEngine->add( shared_ptr<SmokeParticle>( new SmokeParticle(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za, 0, 0, 0) ) );
}
else
{
if (random->nextInt(++rainPosSamples) == 0)
if (Tile::tiles[t]->material == Material::lava)
{
rainPosX = x + xa;
rainPosY = y + 0.1f - Tile::tiles[t]->getShapeY0();
rainPosZ = z + za;
mc->particleEngine->add( shared_ptr<SmokeParticle>( new SmokeParticle(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za, 0, 0, 0) ) );
}
else
{
if (random->nextInt(++rainPosSamples) == 0)
{
rainPosX = x + xa;
rainPosY = y + 0.1f - Tile::tiles[t]->getShapeY0();
rainPosZ = z + za;
}
mc->particleEngine->add( shared_ptr<WaterDropParticle>( new WaterDropParticle(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za) ) );
}
mc->particleEngine->add( shared_ptr<WaterDropParticle>( new WaterDropParticle(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za) ) );
}
}
}
@@ -1581,10 +1585,12 @@ void GameRenderer::renderSnowAndRain(float a)
turnOnLightLayer(a);
if (rainXa == NULL)
static float rainXa[32 * 32];
static float rainZa[32 * 32];
static bool rainArraysInitialized = false;
if (!rainArraysInitialized)
{
rainXa = new float[32 * 32];
rainZa = new float[32 * 32];
rainArraysInitialized = true;
for (int z = 0; z < 32; z++)
{
-2
View File
@@ -128,8 +128,6 @@ private:
void tickRain();
private:
// 4J - brought forward from 1.8.2
float *rainXa;
float *rainZa;
protected:
void renderSnowAndRain(float a);
volatile int xMod;
+4 -4
View File
@@ -10,7 +10,7 @@ ResourceLocation HorseRenderer::HORSE_DONKEY_LOCATION = ResourceLocation(TN_MOB_
ResourceLocation HorseRenderer::HORSE_ZOMBIE_LOCATION = ResourceLocation(TN_MOB_HORSE_ZOMBIE);
ResourceLocation HorseRenderer::HORSE_SKELETON_LOCATION = ResourceLocation(TN_MOB_HORSE_SKELETON);
std::map<wstring, ResourceLocation *> HorseRenderer::LAYERED_LOCATION_CACHE;
std::map<wstring, ResourceLocation> HorseRenderer::LAYERED_LOCATION_CACHE;
HorseRenderer::HorseRenderer(Model *model, float f) : MobRenderer(model, f)
{
@@ -114,14 +114,14 @@ ResourceLocation *HorseRenderer::getOrCreateLayeredTextureLocation(shared_ptr<En
ResourceLocation *location;
if (it != LAYERED_LOCATION_CACHE.end())
{
location = it->second;
location = &(it->second);
}
else
{
LAYERED_LOCATION_CACHE[textureName] = new ResourceLocation(horse->getLayeredTextureLayers());
LAYERED_LOCATION_CACHE[textureName] = ResourceLocation(horse->getLayeredTextureLayers());
it = LAYERED_LOCATION_CACHE.find(textureName);
location = it->second;
location = &(it->second);
}
return location;
+1 -1
View File
@@ -8,7 +8,7 @@ class PathfinderMob;
class HorseRenderer : public MobRenderer
{
private:
static std::map<wstring, ResourceLocation *> LAYERED_LOCATION_CACHE;
static std::map<wstring, ResourceLocation> LAYERED_LOCATION_CACHE;
static ResourceLocation HORSE_LOCATION;
static ResourceLocation HORSE_MULE_LOCATION;
+8 -3
View File
@@ -277,6 +277,7 @@
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
@@ -1445,10 +1446,11 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata"</Command>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)$(ProjectName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>d3d11.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib;wsock32.lib</AdditionalDependencies>
<AdditionalDependencies>d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>NotSet</ShowProgress>
<SuppressStartupBanner>false</SuppressStartupBanner>
</Link>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
<ImageXex>
<ConfigurationFile>$(ProjectDir)xbox\xex-dev.xml</ConfigurationFile>
</ImageXex>
@@ -1568,7 +1570,7 @@ xcopy /q /y /i /s /e $(ProjectDir)DurangoMedia\CU $(LayoutDir)Image\Loose\CU</C
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;NDEBUG;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling>
<AdditionalIncludeDirectories>Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
@@ -1576,6 +1578,9 @@ xcopy /q /y /i /s /e $(ProjectDir)DurangoMedia\CU $(LayoutDir)Image\Loose\CU</C
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<ShowIncludes>false</ShowIncludes>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FunctionLevelLinking>true</FunctionLevelLinking>
<StringPooling>true</StringPooling>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
+3 -3
View File
@@ -165,7 +165,7 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW
//localIp = settings->getString(L"server-ip", L"");
//onlineMode = settings->getBoolean(L"online-mode", true);
//motd = settings->getString(L"motd", L"A Minecraft Server");
//motd.replace('§', '$');
//motd.replace('', '$');
setAnimals(settings->getBoolean(L"spawn-animals", true));
setNpcsEnabled(settings->getBoolean(L"spawn-npcs", true));
@@ -210,7 +210,7 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW
// 4J-JEV: Need to wait for levelGenerationOptions to load.
while ( app.getLevelGenerationOptions() != NULL && !app.getLevelGenerationOptions()->hasLoadedData() )
Sleep(1);
Sleep(0);
if ( app.getLevelGenerationOptions() != NULL && !app.getLevelGenerationOptions()->ready() )
{
@@ -319,7 +319,7 @@ int MinecraftServer::runPostUpdate(void* lpParam)
{
LeaveCriticalSection(&server->m_postProcessCS);
}
Sleep(1);
Sleep(0);
} while (!server->m_postUpdateTerminate && ShutdownManager::ShouldRun(ShutdownManager::ePostProcessThread));
//#ifndef __PS3__
// One final pass through updates to make sure we're done
@@ -1,7 +1,7 @@
/*
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
Copyright (C) 2004-2008 Ren Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
@@ -21,7 +21,7 @@
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
Ren Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
@@ -41,7 +41,7 @@ static inline bool is_base64(unsigned char c) {
}
// 4J ADDED,
std::string base64_encode(std::string str)
std::string base64_encode(const std::string& str)
{
return base64_encode( reinterpret_cast<const unsigned char*>(str.c_str()), str.length() );
}
+1 -1
View File
@@ -2,6 +2,6 @@
#include <string>
std::string base64_encode(std::string str);
std::string base64_encode(const std::string& str);
std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);
+3 -3
View File
@@ -1,7 +1,7 @@
/*
base64.cpp and base64.h
Copyright (C) 2004-2008 René Nyffenegger
Copyright (C) 2004-2008 Ren Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
@@ -21,7 +21,7 @@
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
Ren Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
@@ -41,7 +41,7 @@ static inline bool is_base64(unsigned char c) {
}
// 4J ADDED,
std::string base64_encode(std::string str)
std::string base64_encode(const std::string& str)
{
return base64_encode( reinterpret_cast<const unsigned char*>(str.c_str()), str.length() );
}
+1 -1
View File
@@ -2,6 +2,6 @@
#include <string>
std::string base64_encode(std::string str);
std::string base64_encode(const std::string& str);
std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);
+3 -3
View File
@@ -341,7 +341,7 @@ bool Connection::readTick()
// printf("Con:0x%x readTick close EOS\n",this);
// 4J Stu - Remove this line
// Fix for #10410 - UI: If the player is removed from a splitscreened hosts game, the next game that player joins will produce a message stating that the host has left.
// Fix for #10410 - UI: If the player is removed from a splitscreened hosts game, the next game that player joins will produce a message stating that the host has left.
//close(DisconnectPacket::eDisconnect_EndOfStream);
}
@@ -666,7 +666,7 @@ int Connection::runClose(void* lpParam)
//try {
Sleep(2000);
Sleep(500);
if (con->running)
{
// 4J TODO writeThread.interrupt();
@@ -690,7 +690,7 @@ int Connection::runSendAndQuit(void* lpParam)
//try {
Sleep(2000);
Sleep(500);
if (con->running)
{
// 4J TODO writeThread.interrupt();
+5 -1
View File
@@ -274,6 +274,7 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
@@ -1195,7 +1196,7 @@
<BufferSecurityCheck>false</BufferSecurityCheck>
<PrecompiledHeaderOutputFile>$(OutDir)$(ProjectName).pch</PrecompiledHeaderOutputFile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;NDEBUG;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<CallAttributedProfiling>Disabled</CallAttributedProfiling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<ShowIncludes>false</ShowIncludes>
@@ -1203,6 +1204,9 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<FunctionLevelLinking>true</FunctionLevelLinking>
<StringPooling>true</StringPooling>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>