Merge pull request #306 from Merc6/refactor/remove-int-cache

refactor: remove integer caching
This commit is contained in:
ffqq 2026-03-25 16:17:17 +03:00 committed by GitHub
commit 4a2b05f4e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 6622 additions and 5844 deletions

View file

@ -61,7 +61,6 @@
#include "../Minecraft.World/Headers/net.minecraft.world.entity.animal.h" #include "../Minecraft.World/Headers/net.minecraft.world.entity.animal.h"
#include "../Minecraft.World/Headers/net.minecraft.world.entity.monster.h" #include "../Minecraft.World/Headers/net.minecraft.world.entity.monster.h"
#include "../Minecraft.World/WorldGen/Features/StrongholdFeature.h" #include "../Minecraft.World/WorldGen/Features/StrongholdFeature.h"
#include "../Minecraft.World/Util/IntCache.h"
#include "../Minecraft.World/Entities/Mobs/Villager.h" #include "../Minecraft.World/Entities/Mobs/Villager.h"
#include "../Minecraft.World/Level/Storage/SparseLightStorage.h" #include "../Minecraft.World/Level/Storage/SparseLightStorage.h"
#include "../Minecraft.World/Level/Storage/SparseDataStorage.h" #include "../Minecraft.World/Level/Storage/SparseDataStorage.h"
@ -2078,9 +2077,11 @@ void Minecraft::run_middle() {
// If there's an unoccupied quadrant, then clear that to black // If there's an unoccupied quadrant, then clear that to black
if (unoccupiedQuadrant > -1) { if (unoccupiedQuadrant > -1) {
// render a logo // render a logo
RenderManager.StateSetViewport((C4JRender::eViewportType)( RenderManager.StateSetViewport((
C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT + C4JRender::
unoccupiedQuadrant)); eViewportType)(C4JRender::
VIEWPORT_TYPE_QUADRANT_TOP_LEFT +
unoccupiedQuadrant));
glClearColor(0, 0, 0, 0); glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -2400,7 +2401,6 @@ void Minecraft::levelTickUpdateFunc(void* pParam) {
void Minecraft::levelTickThreadInitFunc() { void Minecraft::levelTickThreadInitFunc() {
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage();
} }
@ -2596,8 +2596,8 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
if (player->isRiding()) { if (player->isRiding()) {
std::shared_ptr<Entity> mount = player->riding; std::shared_ptr<Entity> mount = player->riding;
if (mount->instanceof (eTYPE_MINECART) || mount->instanceof if (mount->instanceof(eTYPE_MINECART) ||
(eTYPE_BOAT)) { mount->instanceof(eTYPE_BOAT)) {
*piAlt = IDS_TOOLTIPS_EXIT; *piAlt = IDS_TOOLTIPS_EXIT;
} else { } else {
*piAlt = IDS_TOOLTIPS_DISMOUNT; *piAlt = IDS_TOOLTIPS_DISMOUNT;
@ -3623,7 +3623,7 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) {
break; break;
default: default:
if (hitResult->entity->instanceof (eTYPE_MOB)) { if (hitResult->entity->instanceof(eTYPE_MOB)) {
std::shared_ptr<Mob> mob = std::shared_ptr<Mob> mob =
std::dynamic_pointer_cast<Mob>( std::dynamic_pointer_cast<Mob>(
hitResult->entity); hitResult->entity);
@ -4914,7 +4914,7 @@ void Minecraft::main() {
} }
app.DebugPrintf("\n\n\n\n\n"); app.DebugPrintf("\n\n\n\n\n");
for(unsigned int i = 0; i < 256; ++i) for(unsigned int i = 0; i < 256; ++i)
{ {
if(Tile::tiles[i] != NULL) if(Tile::tiles[i] != NULL)

View file

@ -37,7 +37,6 @@
#include "Player/ServerPlayer.h" #include "Player/ServerPlayer.h"
#include "Rendering/GameRenderer.h" #include "Rendering/GameRenderer.h"
#include "../Minecraft.World/Util/ThreadName.h" #include "../Minecraft.World/Util/ThreadName.h"
#include "../Minecraft.World/Util/IntCache.h"
#include "../Minecraft.World/Level/Storage/CompressedTileStorage.h" #include "../Minecraft.World/Level/Storage/CompressedTileStorage.h"
#include "../Minecraft.World/Level/Storage/SparseLightStorage.h" #include "../Minecraft.World/Level/Storage/SparseLightStorage.h"
#include "../Minecraft.World/Level/Storage/SparseDataStorage.h" #include "../Minecraft.World/Level/Storage/SparseDataStorage.h"
@ -315,7 +314,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
MinecraftServer* server = (MinecraftServer*)lpParam; MinecraftServer* server = (MinecraftServer*)lpParam;
Entity::useSmallIds(); // This thread can end up spawning entities as Entity::useSmallIds(); // This thread can end up spawning entities as
// resources // resources
IntCache::CreateNewThreadStorage();
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage();
@ -366,7 +364,6 @@ int MinecraftServer::runPostUpdate(void* lpParam) {
LeaveCriticalSection(&server->m_postProcessCS); LeaveCriticalSection(&server->m_postProcessCS);
// #endif //__PS3__ // #endif //__PS3__
Tile::ReleaseThreadStorage(); Tile::ReleaseThreadStorage();
IntCache::ReleaseThreadStorage();
AABB::ReleaseThreadStorage(); AABB::ReleaseThreadStorage();
Vec3::ReleaseThreadStorage(); Vec3::ReleaseThreadStorage();
Level::destroyLightingCache(); Level::destroyLightingCache();
@ -889,8 +886,7 @@ void MinecraftServer::overwriteHellBordersForNewWorldSize(ServerLevel* level,
#endif #endif
void MinecraftServer::setProgress(const std::wstring& status, void MinecraftServer::setProgress(const std::wstring& status, int progress) {
int progress) {
progressStatus = status; progressStatus = status;
this->progress = progress; this->progress = progress;
// logger.info(status + ": " + progress + "%"); // logger.info(status + ": " + progress + "%");
@ -1817,9 +1813,7 @@ void MinecraftServer::info(const std::wstring& string) {}
void MinecraftServer::warn(const std::wstring& string) {} void MinecraftServer::warn(const std::wstring& string) {}
std::wstring MinecraftServer::getConsoleName() { std::wstring MinecraftServer::getConsoleName() { return L"CONSOLE"; }
return L"CONSOLE";
}
ServerLevel* MinecraftServer::getLevel(int dimension) { ServerLevel* MinecraftServer::getLevel(int dimension) {
if (dimension == -1) if (dimension == -1)

View file

@ -25,7 +25,6 @@
#include "../../Minecraft.Client/UI/Gui.h" #include "../../Minecraft.Client/UI/Gui.h"
#include "../../Minecraft.Client/Rendering/LevelRenderer.h" #include "../../Minecraft.Client/Rendering/LevelRenderer.h"
#include "../../Minecraft.World/Util/IntCache.h"
#include "../GameRules/ConsoleGameRules.h" #include "../GameRules/ConsoleGameRules.h"
#include "GameNetworkManager.h" #include "GameNetworkManager.h"
@ -952,7 +951,6 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
Vec3::UseDefaultThreadStorage(); Vec3::UseDefaultThreadStorage();
Compression::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage();
Tile::CreateNewThreadStorage(); Tile::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
g_NetworkManager.m_bNetworkThreadRunning = true; g_NetworkManager.m_bNetworkThreadRunning = true;
bool success = g_NetworkManager._RunNetworkGame(lpParameter); bool success = g_NetworkManager._RunNetworkGame(lpParameter);
@ -984,7 +982,6 @@ int CGameNetworkManager::RunNetworkGameThreadProc(void* lpParameter) {
#endif #endif
Tile::ReleaseThreadStorage(); Tile::ReleaseThreadStorage();
IntCache::ReleaseThreadStorage();
return 0; return 0;
} }
@ -1012,7 +1009,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
SetThreadName(-1, "Minecraft Server thread"); SetThreadName(-1, "Minecraft Server thread");
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Compression::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage();
OldChunkStorage::UseDefaultThreadStorage(); OldChunkStorage::UseDefaultThreadStorage();
Entity::useSmallIds(); Entity::useSmallIds();
@ -1027,7 +1023,6 @@ int CGameNetworkManager::ServerThreadProc(void* lpParameter) {
Tile::ReleaseThreadStorage(); Tile::ReleaseThreadStorage();
AABB::ReleaseThreadStorage(); AABB::ReleaseThreadStorage();
Vec3::ReleaseThreadStorage(); Vec3::ReleaseThreadStorage();
IntCache::ReleaseThreadStorage();
Level::destroyLightingCache(); Level::destroyLightingCache();
if (lpParameter != NULL) delete (NetworkGameInitData*)lpParameter; if (lpParameter != NULL) delete (NetworkGameInitData*)lpParameter;

View file

@ -9,7 +9,6 @@
#include "../../Minecraft.World/Level/Storage/LevelSettings.h" #include "../../Minecraft.World/Level/Storage/LevelSettings.h"
#include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Util/StringHelpers.h"
#include "../../Minecraft.World/WorldGen/Biomes/BiomeSource.h" #include "../../Minecraft.World/WorldGen/Biomes/BiomeSource.h"
#include "../../Minecraft.World/Util/IntCache.h"
#include "../../Minecraft.World/Level/Storage/LevelType.h" #include "../../Minecraft.World/Level/Storage/LevelType.h"
#include "../../Minecraft.Client/Textures/Packs/DLCTexturePack.h" #include "../../Minecraft.Client/Textures/Packs/DLCTexturePack.h"
@ -1373,7 +1372,6 @@ int UIScene_CreateWorldMenu::StartGame_SignInReturned(void* pParam,
} else { } else {
// This is NOT called from a storage manager thread, and is in // This is NOT called from a storage manager thread, and is in
// fact called from the main thread in the Profile library tick. // fact called from the main thread in the Profile library tick.
// Therefore we use the main threads IntCache.
CreateGame(pClass, localUsersMask); CreateGame(pClass, localUsersMask);
} }
} }

View file

@ -1873,7 +1873,6 @@ int UIScene_LoadMenu::StartGame_SignInReturned(void* pParam, bool bContinue,
#endif #endif
// This is NOT called from a storage manager thread, and is in // This is NOT called from a storage manager thread, and is in
// fact called from the main thread in the Profile library tick. // fact called from the main thread in the Profile library tick.
// Therefore we use the main threads IntCache.
StartGameFromSave(pClass, localUsersMask); StartGameFromSave(pClass, localUsersMask);
} }
} }
@ -1935,4 +1934,4 @@ int UIScene_LoadMenu::MustSignInReturnedPSN(void* pParam, int iPad,
// pClass->m_bIgnoreInput=false; // pClass->m_bIgnoreInput=false;
// return 0; // return 0;
// } // }
#endif #endif

View file

@ -9,7 +9,6 @@
#include "../../Minecraft.World/Level/Storage/LevelSettings.h" #include "../../Minecraft.World/Level/Storage/LevelSettings.h"
#include "XUI_MultiGameLaunchMoreOptions.h" #include "XUI_MultiGameLaunchMoreOptions.h"
#include "../../Minecraft.World/WorldGen/Biomes/BiomeSource.h" #include "../../Minecraft.World/WorldGen/Biomes/BiomeSource.h"
#include "../../Minecraft.World/Util/IntCache.h"
#include "../../Minecraft.World/Level/Storage/LevelType.h" #include "../../Minecraft.World/Level/Storage/LevelType.h"
#include "../../Minecraft.Client/Textures/Packs/TexturePackRepository.h" #include "../../Minecraft.Client/Textures/Packs/TexturePackRepository.h"
#include "../../Minecraft.Client/Textures/Packs/TexturePack.h" #include "../../Minecraft.Client/Textures/Packs/TexturePack.h"
@ -614,12 +613,14 @@ int CScene_MultiGameCreate::WarningTrialTexturePackReturned(
ProfileManager.GetPrimaryPad(), NULL, NULL, ProfileManager.GetPrimaryPad(), NULL, NULL,
app.GetStringTable()); app.GetStringTable());
} else { } else {
// This is called from a storage manager thread... need to set up // 4J - This is called from a storage manager thread... need to set
// thread storage for IntCache as CreateGame requires this to search // up thread storage for IntCache as CreateGame requires this to
// for a suitable seed if we haven't set a seed. // search for a suitable seed if we haven't set a seed.
IntCache::CreateNewThreadStorage(); //
// 4jcraft - removed reliance on int caching, old 4J comment is
// moot, and we can search for suitable seeds without said cache
// initialization.
CreateGame(pScene, 0); CreateGame(pScene, 0);
IntCache::ReleaseThreadStorage();
} }
} }
@ -825,9 +826,11 @@ int CScene_MultiGameCreate::ConfirmCreateReturned(
// This is called from a storage manager thread... need to set // This is called from a storage manager thread... need to set
// up thread storage for IntCache as CreateGame requires this to // up thread storage for IntCache as CreateGame requires this to
// search for a suitable seed if we haven't set a seed. // search for a suitable seed if we haven't set a seed.
IntCache::CreateNewThreadStorage(); //
// 4jcraft - removed reliance on int caching, old 4J comment is
// moot, and we can search for suitable seeds without said cache
// initialization.
CreateGame(pClass, 0); CreateGame(pClass, 0);
IntCache::ReleaseThreadStorage();
} }
} }
} else { } else {
@ -895,7 +898,6 @@ int CScene_MultiGameCreate::StartGame_SignInReturned(void* pParam,
} else { } else {
// This is NOT called from a storage manager thread, and is in // This is NOT called from a storage manager thread, and is in
// fact called from the main thread in the Profile library tick. // fact called from the main thread in the Profile library tick.
// Therefore we use the main threads IntCache.
CreateGame(pClass, dwLocalUsersMask); CreateGame(pClass, dwLocalUsersMask);
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -65,7 +65,6 @@ static void sigsegv_handler(int sig) {
#include "../../Rendering/Tesselator.h" #include "../../Rendering/Tesselator.h"
#include "../../GameState/Options.h" #include "../../GameState/Options.h"
#include "../Linux/Sentient/SentientManager.h" #include "../Linux/Sentient/SentientManager.h"
#include "../../../Minecraft.World/Util/IntCache.h"
#include "../../Textures/Textures.h" #include "../../Textures/Textures.h"
#include "../../../Minecraft.World/IO/Streams/Compression.h" #include "../../../Minecraft.World/IO/Streams/Compression.h"
#include "../../../Minecraft.World/Level/Storage/OldChunkStorage.h" #include "../../../Minecraft.World/Level/Storage/OldChunkStorage.h"
@ -870,7 +869,6 @@ return -1;
// Initialise TLS for AABB and Vec3 pools, for this main thread // Initialise TLS for AABB and Vec3 pools, for this main thread
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Compression::CreateNewThreadStorage(); Compression::CreateNewThreadStorage();
OldChunkStorage::CreateNewThreadStorage(); OldChunkStorage::CreateNewThreadStorage();
Level::enableLightingCache(); Level::enableLightingCache();
@ -940,7 +938,6 @@ return -1;
pMinecraft->soundEngine->tick(NULL, 0.0f); pMinecraft->soundEngine->tick(NULL, 0.0f);
MemSect(0); MemSect(0);
pMinecraft->textures->tick(true, false); pMinecraft->textures->tick(true, false);
IntCache::Reset();
if (app.GetReallyChangingSessionType()) { if (app.GetReallyChangingSessionType()) {
pMinecraft pMinecraft
->tickAllConnections(); // Added to stop timing out when we ->tickAllConnections(); // Added to stop timing out when we

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -36,7 +36,6 @@
#include "../../Minecraft.World/Util/JavaMath.h" #include "../../Minecraft.World/Util/JavaMath.h"
#include "../../Minecraft.World/Util/Facing.h" #include "../../Minecraft.World/Util/Facing.h"
#include "../../Minecraft.World/Entities/MobEffect.h" #include "../../Minecraft.World/Entities/MobEffect.h"
#include "../../Minecraft.World/Util/IntCache.h"
#include "../../Minecraft.World/Util/SmoothFloat.h" #include "../../Minecraft.World/Util/SmoothFloat.h"
#include "../../Minecraft.World/Entities/MobEffectInstance.h" #include "../../Minecraft.World/Entities/MobEffectInstance.h"
#include "../../Minecraft.World/Items/Item.h" #include "../../Minecraft.World/Items/Item.h"
@ -351,7 +350,7 @@ void GameRenderer::pick(float a) {
if (nearest < dist || (mc->hitResult == NULL)) { if (nearest < dist || (mc->hitResult == NULL)) {
if (mc->hitResult != NULL) delete mc->hitResult; if (mc->hitResult != NULL) delete mc->hitResult;
mc->hitResult = new HitResult(hovered); mc->hitResult = new HitResult(hovered);
if (hovered->instanceof (eTYPE_LIVINGENTITY)) { if (hovered->instanceof(eTYPE_LIVINGENTITY)) {
mc->crosshairPickMob = mc->crosshairPickMob =
std::dynamic_pointer_cast<LivingEntity>(hovered); std::dynamic_pointer_cast<LivingEntity>(hovered);
} }
@ -424,7 +423,7 @@ void GameRenderer::bobHurt(float a) {
} }
void GameRenderer::bobView(float a) { void GameRenderer::bobView(float a) {
if (!mc->cameraTargetPlayer->instanceof (eTYPE_LIVINGENTITY)) return; if (!mc->cameraTargetPlayer->instanceof(eTYPE_LIVINGENTITY)) return;
std::shared_ptr<Player> player = std::shared_ptr<Player> player =
std::dynamic_pointer_cast<Player>(mc->cameraTargetPlayer); std::dynamic_pointer_cast<Player>(mc->cameraTargetPlayer);
@ -673,8 +672,7 @@ void GameRenderer::renderItemInHand(float a, int eye) {
// 4J-JEV: I'm fairly confident this method would crash if the cameratarget // 4J-JEV: I'm fairly confident this method would crash if the cameratarget
// isnt a local player anyway, but oh well. // isnt a local player anyway, but oh well.
std::shared_ptr<LocalPlayer> localplayer = std::shared_ptr<LocalPlayer> localplayer =
mc->cameraTargetPlayer->instanceof mc->cameraTargetPlayer->instanceof(eTYPE_LOCALPLAYER)
(eTYPE_LOCALPLAYER)
? std::dynamic_pointer_cast<LocalPlayer>(mc->cameraTargetPlayer) ? std::dynamic_pointer_cast<LocalPlayer>(mc->cameraTargetPlayer)
: nullptr; : nullptr;
@ -807,9 +805,8 @@ void GameRenderer::turnOnLightLayer(
static int logCount = 0; static int logCount = 0;
if (logCount < 16) { if (logCount < 16) {
++logCount; ++logCount;
app.DebugPrintf( app.DebugPrintf("[linux-lightmap] turnOnLightLayer tex=%d scale=%d\n",
"[linux-lightmap] turnOnLightLayer tex=%d scale=%d\n", textureId, textureId, scaleLight ? 1 : 0);
scaleLight ? 1 : 0);
} }
RenderManager.TextureBindVertex(textureId, scaleLight); RenderManager.TextureBindVertex(textureId, scaleLight);
@ -1118,7 +1115,6 @@ int GameRenderer::runUpdate(void* lpParam) {
Minecraft* minecraft = Minecraft::GetInstance(); Minecraft* minecraft = Minecraft::GetInstance();
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024); Tesselator::CreateNewThreadStorage(1024 * 1024);
Compression::UseDefaultThreadStorage(); Compression::UseDefaultThreadStorage();
RenderManager.InitialiseContext(); RenderManager.InitialiseContext();
@ -1199,7 +1195,6 @@ int GameRenderer::runUpdate(void* lpParam) {
AABB::resetPool(); AABB::resetPool();
Vec3::resetPool(); Vec3::resetPool();
IntCache::Reset();
m_updateEvents->Set(eUpdateEventIsFinished); m_updateEvents->Set(eUpdateEventIsFinished);
} }
@ -1254,7 +1249,9 @@ void GameRenderer::renderLevel(float a, int64_t until) {
// if (mc->cameraTargetPlayer == NULL) // 4J - removed condition as we // if (mc->cameraTargetPlayer == NULL) // 4J - removed condition as we
// want to update this is mc->player changes for different local players // want to update this is mc->player changes for different local players
{ mc->cameraTargetPlayer = mc->player; } {
mc->cameraTargetPlayer = mc->player;
}
pick(a); pick(a);
std::shared_ptr<LivingEntity> cameraEntity = mc->cameraTargetPlayer; std::shared_ptr<LivingEntity> cameraEntity = mc->cameraTargetPlayer;
@ -1394,9 +1391,9 @@ void GameRenderer::renderLevel(float a, int64_t until) {
turnOffLightLayer(a); // 4J - brought forward from 1.8.2 turnOffLightLayer(a); // 4J - brought forward from 1.8.2
if ((mc->hitResult != NULL) && if ((mc->hitResult != NULL) &&
cameraEntity->isUnderLiquid(Material::water) && cameraEntity->isUnderLiquid(Material::water) &&
cameraEntity->instanceof cameraEntity->instanceof(
(eTYPE_PLAYER)) //&& !mc->options.hideGui) eTYPE_PLAYER)) //&& !mc->options.hideGui)
{ {
std::shared_ptr<Player> player = std::shared_ptr<Player> player =
std::dynamic_pointer_cast<Player>(cameraEntity); std::dynamic_pointer_cast<Player>(cameraEntity);
@ -1472,8 +1469,8 @@ void GameRenderer::renderLevel(float a, int64_t until) {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glDisable(GL_BLEND); glDisable(GL_BLEND);
if ((zoom == 1) && cameraEntity->instanceof if ((zoom == 1) &&
(eTYPE_PLAYER)) //&& !mc->options.hideGui) cameraEntity->instanceof(eTYPE_PLAYER)) //&& !mc->options.hideGui)
{ {
if (mc->hitResult != NULL && if (mc->hitResult != NULL &&
!cameraEntity->isUnderLiquid(Material::water)) { !cameraEntity->isUnderLiquid(Material::water)) {
@ -2008,7 +2005,7 @@ void GameRenderer::setupFog(int i, float alpha) {
// 4J - check for creative mode brought forward from 1.2.3 // 4J - check for creative mode brought forward from 1.2.3
bool creative = false; bool creative = false;
if (player->instanceof (eTYPE_PLAYER)) { if (player->instanceof(eTYPE_PLAYER)) {
creative = creative =
(std::dynamic_pointer_cast<Player>(player))->abilities.instabuild; (std::dynamic_pointer_cast<Player>(player))->abilities.instabuild;
} }

View file

@ -42,7 +42,6 @@
#include "../GameState/Options.h" #include "../GameState/Options.h"
#include "../Network/MultiPlayerChunkCache.h" #include "../Network/MultiPlayerChunkCache.h"
#include "../../Minecraft.World/Util/ParticleTypes.h" #include "../../Minecraft.World/Util/ParticleTypes.h"
#include "../../Minecraft.World/Util/IntCache.h"
#include "../../Minecraft.World/IO/Streams/IntBuffer.h" #include "../../Minecraft.World/IO/Streams/IntBuffer.h"
#include "../../Minecraft.World/Util/JavaMath.h" #include "../../Minecraft.World/Util/JavaMath.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.level.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.h"
@ -586,7 +585,7 @@ void LevelRenderer::renderEntities(Vec3* cam, Culler* culler, float a) {
(entity->noCulling || culler->isVisible(entity->bb))); (entity->noCulling || culler->isVisible(entity->bb)));
// Render the mob if the mob's leash holder is within the culler // Render the mob if the mob's leash holder is within the culler
if (!shouldRender && entity->instanceof (eTYPE_MOB)) { if (!shouldRender && entity->instanceof(eTYPE_MOB)) {
std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(entity); std::shared_ptr<Mob> mob = std::dynamic_pointer_cast<Mob>(entity);
if (mob->isLeashed() && (mob->getLeashHolder() != NULL)) { if (mob->isLeashed() && (mob->getLeashHolder() != NULL)) {
std::shared_ptr<Entity> leashHolder = mob->getLeashHolder(); std::shared_ptr<Entity> leashHolder = mob->getLeashHolder();
@ -600,10 +599,10 @@ void LevelRenderer::renderEntities(Vec3* cam, Culler* culler, float a) {
// !mc->options->thirdPersonView && // !mc->options->thirdPersonView &&
// !mc->cameraTargetPlayer->isSleeping()) continue; // !mc->cameraTargetPlayer->isSleeping()) continue;
std::shared_ptr<LocalPlayer> localplayer = std::shared_ptr<LocalPlayer> localplayer =
mc->cameraTargetPlayer->instanceof mc->cameraTargetPlayer->instanceof(eTYPE_LOCALPLAYER)
(eTYPE_LOCALPLAYER) ? std::dynamic_pointer_cast<LocalPlayer>( ? std::dynamic_pointer_cast<LocalPlayer>(
mc->cameraTargetPlayer) mc->cameraTargetPlayer)
: nullptr; : nullptr;
if (localplayer && entity == mc->cameraTargetPlayer && if (localplayer && entity == mc->cameraTargetPlayer &&
!localplayer->ThirdPersonView() && !localplayer->ThirdPersonView() &&
@ -1198,7 +1197,7 @@ void LevelRenderer::renderSky(float alpha) {
// 4J - can't work out what this big black box is for. Taking it out // 4J - can't work out what this big black box is for. Taking it out
// until someone misses it... it causes a big black box to visible // until someone misses it... it causes a big black box to visible
// appear in 3rd person mode whilst under the ground. // appear in 3rd person mode whilst under the ground.
#if 0 #if 0
float ss = 1; float ss = 1;
float yo = -(float) (yy + 65); float yo = -(float) (yy + 65);
float y0 = -ss; float y0 = -ss;
@ -2748,7 +2747,9 @@ void LevelRenderer::cull_SPU(int playerIndex, Culler* culler, float a) {
m_jobPort_CullSPU->submitSync(); m_jobPort_CullSPU->submitSync();
// static int doSort = false; // static int doSort = false;
// if(doSort) // if(doSort)
{ m_jobPort_CullSPU->submitJob(&sortJob); } {
m_jobPort_CullSPU->submitJob(&sortJob);
}
// doSort ^= 1; // doSort ^= 1;
m_bSPUCullStarted[playerIndex] = true; m_bSPUCullStarted[playerIndex] = true;
} }
@ -3221,7 +3222,7 @@ std::shared_ptr<Particle> LevelRenderer::addParticleInternal(
} }
void LevelRenderer::entityAdded(std::shared_ptr<Entity> entity) { void LevelRenderer::entityAdded(std::shared_ptr<Entity> entity) {
if (entity->instanceof (eTYPE_PLAYER)) { if (entity->instanceof(eTYPE_PLAYER)) {
std::shared_ptr<Player> player = std::shared_ptr<Player> player =
std::dynamic_pointer_cast<Player>(entity); std::dynamic_pointer_cast<Player>(entity);
player->prepareCustomTextures(); player->prepareCustomTextures();
@ -3239,7 +3240,7 @@ void LevelRenderer::entityAdded(std::shared_ptr<Entity> entity) {
} }
void LevelRenderer::entityRemoved(std::shared_ptr<Entity> entity) { void LevelRenderer::entityRemoved(std::shared_ptr<Entity> entity) {
if (entity->instanceof (eTYPE_PLAYER)) { if (entity->instanceof(eTYPE_PLAYER)) {
std::shared_ptr<Player> player = std::shared_ptr<Player> player =
std::dynamic_pointer_cast<Player>(entity); std::dynamic_pointer_cast<Player>(entity);
if (player->customTextureUrl != L"") { if (player->customTextureUrl != L"") {
@ -4040,7 +4041,6 @@ void LevelRenderer::staticCtor() {
int LevelRenderer::rebuildChunkThreadProc(void* lpParam) { int LevelRenderer::rebuildChunkThreadProc(void* lpParam) {
Vec3::CreateNewThreadStorage(); Vec3::CreateNewThreadStorage();
AABB::CreateNewThreadStorage(); AABB::CreateNewThreadStorage();
IntCache::CreateNewThreadStorage();
Tesselator::CreateNewThreadStorage(1024 * 1024); Tesselator::CreateNewThreadStorage(1024 * 1024);
RenderManager.InitialiseContext(); RenderManager.InitialiseContext();
Chunk::CreateNewThreadStorage(); Chunk::CreateNewThreadStorage();

View file

@ -8,7 +8,6 @@
#include "../WorldGen/Layers/DownfallMixerLayer.h" #include "../WorldGen/Layers/DownfallMixerLayer.h"
#include "../WorldGen/Layers/FlatLayer.h" #include "../WorldGen/Layers/FlatLayer.h"
#include "../WorldGen/Layers/FuzzyZoomLayer.h" #include "../WorldGen/Layers/FuzzyZoomLayer.h"
#include "../Util/IntCache.h"
#include "../WorldGen/Layers/IslandLayer.h" #include "../WorldGen/Layers/IslandLayer.h"
#include "../WorldGen/Layers/Layer.h" #include "../WorldGen/Layers/Layer.h"
#include "../WorldGen/Layers/RiverInitLayer.h" #include "../WorldGen/Layers/RiverInitLayer.h"
@ -25,4 +24,4 @@
// 1.1. // 1.1.
#include "../WorldGen/Layers/RegionHillsLayer.h" #include "../WorldGen/Layers/RegionHillsLayer.h"
#include "../WorldGen/Layers/SwampRiversLayer.h" #include "../WorldGen/Layers/SwampRiversLayer.h"

View file

@ -1,140 +0,0 @@
#include "../Platform/stdafx.h"
#include "IntCache.h"
unsigned int IntCache::tlsIdx = TlsAlloc();
void IntCache::CreateNewThreadStorage() {
ThreadStorage* tls = new ThreadStorage();
TlsSetValue(tlsIdx, (void*)tls);
tls->maxSize = TINY_CUTOFF;
}
IntCache::ThreadStorage::~ThreadStorage() {
for (unsigned int i = 0; i < tcache.size(); i++) {
delete[] tcache[i].data;
}
for (unsigned int i = 0; i < tallocated.size(); i++) {
delete[] tallocated[i].data;
}
for (unsigned int i = 0; i < cache.size(); i++) {
delete[] cache[i].data;
}
for (unsigned int i = 0; i < allocated.size(); i++) {
delete[] allocated[i].data;
}
for (int i = 0; i < toosmall.size(); i++) {
delete[] toosmall[i].data;
}
}
void IntCache::ReleaseThreadStorage() {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
delete tls;
}
intArray IntCache::allocate(int size) {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
if (size <= TINY_CUTOFF) {
if (tls->tcache.empty()) {
intArray result = intArray(TINY_CUTOFF, true);
tls->tallocated.push_back(result);
return result;
} else {
intArray result = tls->tcache.back();
tls->tcache.pop_back();
tls->tallocated.push_back(result);
return result;
}
}
if (size > tls->maxSize) {
// app.DebugPrintf("IntCache: New max size: %d\n" , size);
tls->maxSize = size;
// 4J - added - all the vectors in cache & allocated are smaller than
// maxSize so should be discarded. However, we can't delete them until
// the next releaseAll so copy into another vector until then
tls->toosmall.insert(tls->toosmall.end(), tls->cache.begin(),
tls->cache.end());
tls->toosmall.insert(tls->toosmall.end(), tls->allocated.begin(),
tls->allocated.end());
tls->cache.clear();
tls->allocated.clear();
intArray result = intArray(tls->maxSize, true);
tls->allocated.push_back(result);
return result;
} else {
if (tls->cache.empty()) {
intArray result = intArray(tls->maxSize, true);
tls->allocated.push_back(result);
return result;
} else {
intArray result = tls->cache.back();
tls->cache.pop_back();
tls->allocated.push_back(result);
return result;
}
}
}
void IntCache::releaseAll() {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
// 4J - added - we can now remove the vectors that were deemed as too small
// (see comment in IntCache::allocate)
for (int i = 0; i < tls->toosmall.size(); i++) {
delete[] tls->toosmall[i].data;
}
tls->toosmall.clear();
if (!tls->cache.empty()) {
delete[] tls->cache.back().data;
tls->cache.pop_back();
}
if (!tls->tcache.empty()) {
delete[] tls->tcache.back().data;
tls->tcache.pop_back();
}
tls->cache.insert(tls->cache.end(), tls->allocated.begin(),
tls->allocated.end());
tls->tcache.insert(tls->tcache.end(), tls->tallocated.begin(),
tls->tallocated.end());
tls->allocated.clear();
tls->tallocated.clear();
}
// 4J added so that we can fully reset between levels
void IntCache::Reset() {
ThreadStorage* tls = (ThreadStorage*)TlsGetValue(tlsIdx);
tls->maxSize = TINY_CUTOFF;
for (int i = 0; i < tls->allocated.size(); i++) {
delete[] tls->allocated[i].data;
}
tls->allocated.clear();
for (int i = 0; i < tls->cache.size(); i++) {
delete[] tls->cache[i].data;
}
tls->cache.clear();
for (int i = 0; i < tls->tallocated.size(); i++) {
delete[] tls->tallocated[i].data;
}
tls->tallocated.clear();
for (int i = 0; i < tls->tcache.size(); i++) {
delete[] tls->tcache[i].data;
}
tls->tcache.clear();
for (int i = 0; i < tls->toosmall.size(); i++) {
delete[] tls->toosmall[i].data;
}
tls->toosmall.clear();
}

View file

@ -1,30 +0,0 @@
#pragma once
#include "ArrayWithLength.h"
class IntCache {
private:
class ThreadStorage {
public:
int maxSize;
std::vector<intArray> tcache;
std::vector<intArray> tallocated;
std::vector<intArray> cache;
std::vector<intArray> allocated;
std::vector<intArray> toosmall; // 4J added
~ThreadStorage();
};
static unsigned int tlsIdx;
static const int TINY_CUTOFF = 256;
public:
static intArray allocate(int size);
static void releaseAll();
static void CreateNewThreadStorage();
static void ReleaseThreadStorage();
static void Reset(); // 4J added
};

View file

@ -75,7 +75,6 @@ floatArray BiomeSource::getDownfallBlock(int x, int z, int w, int h) const {
// downfall layers brought forward from 1.2.3 // downfall layers brought forward from 1.2.3
void BiomeSource::getDownfallBlock(floatArray& downfalls, int x, int z, int w, void BiomeSource::getDownfallBlock(floatArray& downfalls, int x, int z, int w,
int h) const { int h) const {
IntCache::releaseAll();
// if (downfalls == NULL || downfalls->length < w * h) // if (downfalls == NULL || downfalls->length < w * h)
if (downfalls.data == NULL || downfalls.length < w * h) { if (downfalls.data == NULL || downfalls.length < w * h) {
if (downfalls.data != NULL) delete[] downfalls.data; if (downfalls.data != NULL) delete[] downfalls.data;
@ -112,7 +111,6 @@ floatArray BiomeSource::getTemperatureBlock(int x, int z, int w, int h) const {
// downfall layers brought forward from 1.2.3 // downfall layers brought forward from 1.2.3
void BiomeSource::getTemperatureBlock(floatArray& temperatures, int x, int z, void BiomeSource::getTemperatureBlock(floatArray& temperatures, int x, int z,
int w, int h) const { int w, int h) const {
IntCache::releaseAll();
// if (temperatures == null || temperatures.length < w * h) { // if (temperatures == null || temperatures.length < w * h) {
if (temperatures.data == NULL || temperatures.length < w * h) { if (temperatures.data == NULL || temperatures.length < w * h) {
if (temperatures.data != NULL) delete[] temperatures.data; if (temperatures.data != NULL) delete[] temperatures.data;
@ -137,7 +135,6 @@ BiomeArray BiomeSource::getRawBiomeBlock(int x, int z, int w, int h) const {
// 4J added // 4J added
void BiomeSource::getRawBiomeIndices(intArray& biomes, int x, int z, int w, void BiomeSource::getRawBiomeIndices(intArray& biomes, int x, int z, int w,
int h) const { int h) const {
IntCache::releaseAll();
intArray result = layer->getArea(x, z, w, h); intArray result = layer->getArea(x, z, w, h);
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
@ -147,7 +144,6 @@ void BiomeSource::getRawBiomeIndices(intArray& biomes, int x, int z, int w,
void BiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w, void BiomeSource::getRawBiomeBlock(BiomeArray& biomes, int x, int z, int w,
int h) const { int h) const {
IntCache::releaseAll();
// if (biomes == null || biomes.length < w * h) // if (biomes == null || biomes.length < w * h)
if (biomes.data == NULL || biomes.length < w * h) { if (biomes.data == NULL || biomes.length < w * h) {
if (biomes.data != NULL) delete[] biomes.data; if (biomes.data != NULL) delete[] biomes.data;
@ -178,7 +174,6 @@ BiomeArray BiomeSource::getBiomeBlock(int x, int z, int w, int h) const {
// 4J - caller is responsible for deleting biomes array // 4J - caller is responsible for deleting biomes array
void BiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, void BiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h,
bool useCache) const { bool useCache) const {
IntCache::releaseAll();
// if (biomes == null || biomes.length < w * h) // if (biomes == null || biomes.length < w * h)
if (biomes.data == NULL || biomes.length < w * h) { if (biomes.data == NULL || biomes.length < w * h) {
if (biomes.data != NULL) delete[] biomes.data; if (biomes.data != NULL) delete[] biomes.data;
@ -211,7 +206,6 @@ byteArray BiomeSource::getBiomeIndexBlock(int x, int z, int w, int h) const {
// 4J - caller is responsible for deleting biomes array // 4J - caller is responsible for deleting biomes array
void BiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z, void BiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z,
int w, int h, bool useCache) const { int w, int h, bool useCache) const {
IntCache::releaseAll();
// if (biomes == null || biomes.length < w * h) // if (biomes == null || biomes.length < w * h)
if (biomeIndices.data == NULL || biomeIndices.length < w * h) { if (biomeIndices.data == NULL || biomeIndices.length < w * h) {
if (biomeIndices.data != NULL) delete[] biomeIndices.data; if (biomeIndices.data != NULL) delete[] biomeIndices.data;
@ -239,7 +233,6 @@ void BiomeSource::getBiomeIndexBlock(byteArray& biomeIndices, int x, int z,
*/ */
bool BiomeSource::containsOnly(int x, int z, int r, bool BiomeSource::containsOnly(int x, int z, int r,
std::vector<Biome*> allowed) { std::vector<Biome*> allowed) {
IntCache::releaseAll();
int x0 = ((x - r) >> 2); int x0 = ((x - r) >> 2);
int z0 = ((z - r) >> 2); int z0 = ((z - r) >> 2);
int x1 = ((x + r) >> 2); int x1 = ((x + r) >> 2);
@ -266,7 +259,6 @@ bool BiomeSource::containsOnly(int x, int z, int r,
* NO other biomes, add a margin of at least four blocks to the radius * NO other biomes, add a margin of at least four blocks to the radius
*/ */
bool BiomeSource::containsOnly(int x, int z, int r, Biome* allowed) { bool BiomeSource::containsOnly(int x, int z, int r, Biome* allowed) {
IntCache::releaseAll();
int x0 = ((x - r) >> 2); int x0 = ((x - r) >> 2);
int z0 = ((z - r) >> 2); int z0 = ((z - r) >> 2);
int x1 = ((x + r) >> 2); int x1 = ((x + r) >> 2);
@ -292,7 +284,6 @@ bool BiomeSource::containsOnly(int x, int z, int r, Biome* allowed) {
*/ */
TilePos* BiomeSource::findBiome(int x, int z, int r, Biome* toFind, TilePos* BiomeSource::findBiome(int x, int z, int r, Biome* toFind,
Random* random) { Random* random) {
IntCache::releaseAll();
int x0 = ((x - r) >> 2); int x0 = ((x - r) >> 2);
int z0 = ((z - r) >> 2); int z0 = ((z - r) >> 2);
int x1 = ((x + r) >> 2); int x1 = ((x + r) >> 2);
@ -327,7 +318,6 @@ TilePos* BiomeSource::findBiome(int x, int z, int r, Biome* toFind,
*/ */
TilePos* BiomeSource::findBiome(int x, int z, int r, TilePos* BiomeSource::findBiome(int x, int z, int r,
std::vector<Biome*> allowed, Random* random) { std::vector<Biome*> allowed, Random* random) {
IntCache::releaseAll();
int x0 = ((x - r) >> 2); int x0 = ((x - r) >> 2);
int z0 = ((z - r) >> 2); int z0 = ((z - r) >> 2);
int x1 = ((x + r) >> 2); int x1 = ((x + r) >> 2);
@ -593,4 +583,4 @@ bool BiomeSource::getIsMatch(float* frac) {
// or more - currently there's 8 critical so this just forces at least 1 // or more - currently there's 8 critical so this just forces at least 1
// more others // more others
return (typeCount >= 9); return (typeCount >= 9);
} }

View file

@ -14,7 +14,7 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int n1 = p[(x + 0) + (y + 0) * pw]; int n1 = p[(x + 0) + (y + 0) * pw];
@ -53,4 +53,4 @@ intArray AddIslandLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -15,7 +15,7 @@ intArray AddMushroomIslandLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int n1 = p[(x + 0) + (y + 0) * pw]; int n1 = p[(x + 0) + (y + 0) * pw];
@ -33,4 +33,4 @@ intArray AddMushroomIslandLayer::getArea(int xo, int yo, int w, int h) {
} }
} }
return result; return result;
} }

View file

@ -14,7 +14,7 @@ intArray AddSnowLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int c = p[(x + 1) + (y + 1) * pw]; int c = p[(x + 1) + (y + 1) * pw];
@ -32,4 +32,4 @@ intArray AddSnowLayer::getArea(int xo, int yo, int w, int h) {
} }
} }
return result; return result;
} }

View file

@ -34,7 +34,7 @@ BiomeInitLayer::~BiomeInitLayer() { delete[] startBiomes.data; }
intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) { intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(x + xo, y + yo); initRandom(x + xo, y + yo);
@ -58,4 +58,4 @@ intArray BiomeInitLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -49,7 +49,7 @@ BiomeOverrideLayer::BiomeOverrideLayer(int seedMixup) : Layer(seedMixup) {
} }
intArray BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) { intArray BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) {
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
int xOrigin = xo + width / 2; int xOrigin = xo + width / 2;
int yOrigin = yo + height / 2; int yOrigin = yo + height / 2;
@ -70,4 +70,4 @@ intArray BiomeOverrideLayer::getArea(int xo, int yo, int w, int h) {
} }
} }
return result; return result;
} }

View file

@ -9,10 +9,10 @@ DownfallLayer::DownfallLayer(std::shared_ptr<Layer> parent) : Layer(0) {
intArray DownfallLayer::getArea(int xo, int yo, int w, int h) { intArray DownfallLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
result[i] = Biome::biomes[b[i]]->getDownfallInt(); result[i] = Biome::biomes[b[i]]->getDownfallInt();
} }
return result; return result;
} }

View file

@ -14,11 +14,11 @@ intArray DownfallMixerLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray d = downfall->getArea(xo, yo, w, h); intArray d = downfall->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
result[i] = result[i] =
d[i] + (Biome::biomes[b[i]]->getDownfallInt() - d[i]) / (layer + 1); d[i] + (Biome::biomes[b[i]]->getDownfallInt() - d[i]) / (layer + 1);
} }
return result; return result;
} }

View file

@ -4,11 +4,11 @@
FlatLayer::FlatLayer(int val) : Layer(0) { this->val = val; } FlatLayer::FlatLayer(int val) : Layer(0) { this->val = val; }
intArray FlatLayer::getArea(int xo, int yo, int w, int h) { intArray FlatLayer::getArea(int xo, int yo, int w, int h) {
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
result[x + y * w] = val; result[x + y * w] = val;
} }
} }
return result; return result;
} }

View file

@ -15,7 +15,7 @@ intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) {
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
// 4jcraft added casts to unsigned to prevent shift of neg value // 4jcraft added casts to unsigned to prevent shift of neg value
intArray tmp = IntCache::allocate((pw * 2) * (ph * 2)); intArray tmp{static_cast<unsigned int>(pw * ph * 4)};
int ww = ((unsigned int)pw << 1); int ww = ((unsigned int)pw << 1);
for (int y = 0; y < ph - 1; y++) { for (int y = 0; y < ph - 1; y++) {
int ry = (unsigned int)y << 1; int ry = (unsigned int)y << 1;
@ -37,7 +37,7 @@ intArray FuzzyZoomLayer::getArea(int xo, int yo, int w, int h) {
dl = dr; dl = dr;
} }
} }
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
System::arraycopy(tmp, System::arraycopy(tmp,
(y + (yo & 1)) * ((unsigned int)pw << 1) + (xo & 1), (y + (yo & 1)) * ((unsigned int)pw << 1) + (xo & 1),

View file

@ -15,7 +15,7 @@ intArray GrowMushroomIslandLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int n1 = p[(x + 0) + (y + 0) * pw]; int n1 = p[(x + 0) + (y + 0) * pw];
@ -36,4 +36,4 @@ intArray GrowMushroomIslandLayer::getArea(int xo, int yo, int w, int h) {
} }
} }
return result; return result;
} }

View file

@ -4,7 +4,7 @@
IslandLayer::IslandLayer(int64_t seedMixup) : Layer(seedMixup) {} IslandLayer::IslandLayer(int64_t seedMixup) : Layer(seedMixup) {}
intArray IslandLayer::getArea(int xo, int yo, int w, int h) { intArray IslandLayer::getArea(int xo, int yo, int w, int h) {
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(xo + x, yo + y); initRandom(xo + x, yo + y);
@ -16,4 +16,4 @@ intArray IslandLayer::getArea(int xo, int yo, int w, int h) {
result[-xo + -yo * w] = 1; result[-xo + -yo * w] = 1;
} }
return result; return result;
} }

View file

@ -1,6 +1,5 @@
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "../../Headers/net.minecraft.world.level.biome.h" #include "../../Headers/net.minecraft.world.level.biome.h"
#include "../../Util/IntCache.h"
#include "RegionHillsLayer.h" #include "RegionHillsLayer.h"
RegionHillsLayer::RegionHillsLayer(int64_t seed, std::shared_ptr<Layer> parent) RegionHillsLayer::RegionHillsLayer(int64_t seed, std::shared_ptr<Layer> parent)
@ -11,7 +10,7 @@ RegionHillsLayer::RegionHillsLayer(int64_t seed, std::shared_ptr<Layer> parent)
intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) { intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(x + xo, y + yo); initRandom(x + xo, y + yo);
@ -51,4 +50,4 @@ intArray RegionHillsLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -9,7 +9,7 @@ RiverInitLayer::RiverInitLayer(int64_t seed, std::shared_ptr<Layer> parent)
intArray RiverInitLayer::getArea(int xo, int yo, int w, int h) { intArray RiverInitLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(x + xo, y + yo); initRandom(x + xo, y + yo);
@ -18,4 +18,4 @@ intArray RiverInitLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -14,7 +14,7 @@ intArray RiverLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int l = p[(x + 0) + (y + 1) * pw]; int l = p[(x + 0) + (y + 1) * pw];
@ -32,4 +32,4 @@ intArray RiverLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -19,7 +19,7 @@ intArray RiverMixerLayer::getArea(int xo, int yo, int w, int h) {
intArray b = biomes->getArea(xo, yo, w, h); intArray b = biomes->getArea(xo, yo, w, h);
intArray r = rivers->getArea(xo, yo, w, h); intArray r = rivers->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
if (b[i] == Biome::ocean->id) { if (b[i] == Biome::ocean->id) {
result[i] = b[i]; result[i] = b[i];
@ -45,4 +45,4 @@ intArray RiverMixerLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -10,7 +10,7 @@ ShoreLayer::ShoreLayer(int64_t seed, std::shared_ptr<Layer> parent)
intArray ShoreLayer::getArea(int xo, int yo, int w, int h) { intArray ShoreLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(x + xo, y + yo); initRandom(x + xo, y + yo);
@ -59,4 +59,4 @@ intArray ShoreLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -13,7 +13,7 @@ intArray SmoothLayer::getArea(int xo, int yo, int w, int h) {
int ph = h + 2; int ph = h + 2;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
int l = p[(x + 0) + (y + 1) * pw]; int l = p[(x + 0) + (y + 1) * pw];
@ -37,4 +37,4 @@ intArray SmoothLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -15,7 +15,7 @@ intArray SmoothZoomLayer::getArea(int xo, int yo, int w, int h) {
int ph = (h >> 1) + 3; int ph = (h >> 1) + 3;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray tmp = IntCache::allocate((pw * 2) * (ph * 2)); intArray tmp{static_cast<unsigned int>(pw * ph * 4)};
int ww = (pw << 1); int ww = (pw << 1);
for (int y = 0; y < ph - 1; y++) { for (int y = 0; y < ph - 1; y++) {
int ry = y << 1; int ry = y << 1;
@ -40,7 +40,7 @@ intArray SmoothZoomLayer::getArea(int xo, int yo, int w, int h) {
dl = dr; dl = dr;
} }
} }
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
System::arraycopy(tmp, (y + (yo & 1)) * (pw << 1) + (xo & 1), &result, System::arraycopy(tmp, (y + (yo & 1)) * (pw << 1) + (xo & 1), &result,
y * w, w); y * w, w);
@ -56,4 +56,4 @@ std::shared_ptr<Layer> SmoothZoomLayer::zoom(int64_t seed,
result = std::shared_ptr<Layer>(new SmoothZoomLayer(seed + i, result)); result = std::shared_ptr<Layer>(new SmoothZoomLayer(seed + i, result));
} }
return result; return result;
} }

View file

@ -1,6 +1,5 @@
#include "../../Platform/stdafx.h" #include "../../Platform/stdafx.h"
#include "../../Headers/net.minecraft.world.level.biome.h" #include "../../Headers/net.minecraft.world.level.biome.h"
#include "../../Util/IntCache.h"
#include "SwampRiversLayer.h" #include "SwampRiversLayer.h"
SwampRiversLayer::SwampRiversLayer(int64_t seed, std::shared_ptr<Layer> parent) SwampRiversLayer::SwampRiversLayer(int64_t seed, std::shared_ptr<Layer> parent)
@ -11,7 +10,7 @@ SwampRiversLayer::SwampRiversLayer(int64_t seed, std::shared_ptr<Layer> parent)
intArray SwampRiversLayer::getArea(int xo, int yo, int w, int h) { intArray SwampRiversLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2); intArray b = parent->getArea(xo - 1, yo - 1, w + 2, h + 2);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) { for (int x = 0; x < w; x++) {
initRandom(x + xo, y + yo); initRandom(x + xo, y + yo);
@ -27,4 +26,4 @@ intArray SwampRiversLayer::getArea(int xo, int yo, int w, int h) {
} }
return result; return result;
} }

View file

@ -9,9 +9,9 @@ TemperatureLayer::TemperatureLayer(std::shared_ptr<Layer> parent) : Layer(0) {
intArray TemperatureLayer::getArea(int xo, int yo, int w, int h) { intArray TemperatureLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
result[i] = Biome::biomes[b[i]]->getTemperatureInt(); result[i] = Biome::biomes[b[i]]->getTemperatureInt();
} }
return result; return result;
} }

View file

@ -15,11 +15,11 @@ intArray TemperatureMixerLayer::getArea(int xo, int yo, int w, int h) {
intArray b = parent->getArea(xo, yo, w, h); intArray b = parent->getArea(xo, yo, w, h);
intArray t = temp->getArea(xo, yo, w, h); intArray t = temp->getArea(xo, yo, w, h);
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int i = 0; i < w * h; i++) { for (int i = 0; i < w * h; i++) {
result[i] = t[i] + (Biome::biomes[b[i]]->getTemperatureInt() - t[i]) / result[i] = t[i] + (Biome::biomes[b[i]]->getTemperatureInt() - t[i]) /
(layer * 2 + 1); (layer * 2 + 1);
} }
return result; return result;
} }

View file

@ -21,7 +21,7 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) {
// 4jcraft added all those casts to unsigned // 4jcraft added all those casts to unsigned
int ww = (unsigned)pw << bits; int ww = (unsigned)pw << bits;
int hh = (unsigned)ph << bits; int hh = (unsigned)ph << bits;
intArray tmp = IntCache::allocate(ww * hh); intArray tmp{static_cast<unsigned int>(ww * hh)};
for (int y = 0; y < ph - 1; y++) { for (int y = 0; y < ph - 1; y++) {
int ul = p[(0 + 0) + (y + 0) * pw]; int ul = p[(0 + 0) + (y + 0) * pw];
int dl = p[(0 + 0) + (y + 1) * pw]; int dl = p[(0 + 0) + (y + 1) * pw];
@ -71,7 +71,7 @@ intArray VoronoiZoom::getArea(int xo, int yo, int w, int h) {
dl = dr; dl = dr;
} }
} }
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
System::arraycopy( System::arraycopy(
tmp, tmp,

View file

@ -14,7 +14,7 @@ intArray ZoomLayer::getArea(int xo, int yo, int w, int h) {
int ph = (h >> 1) + 3; int ph = (h >> 1) + 3;
intArray p = parent->getArea(px, py, pw, ph); intArray p = parent->getArea(px, py, pw, ph);
intArray tmp = IntCache::allocate((pw * 2) * (ph * 2)); intArray tmp{static_cast<unsigned int>(pw * ph * 4)};
// 4jcraft added casts to unsigned // 4jcraft added casts to unsigned
int ww = ((unsigned int)pw << 1); int ww = ((unsigned int)pw << 1);
for (int y = 0; y < ph - 1; y++) { for (int y = 0; y < ph - 1; y++) {
@ -37,7 +37,7 @@ intArray ZoomLayer::getArea(int xo, int yo, int w, int h) {
dl = dr; dl = dr;
} }
} }
intArray result = IntCache::allocate(w * h); intArray result{static_cast<unsigned int>(w * h)};
for (int y = 0; y < h; y++) { for (int y = 0; y < h; y++) {
System::arraycopy(tmp, System::arraycopy(tmp,
(y + (yo & 1)) * (unsigned int)(pw << 1) + (xo & 1), (y + (yo & 1)) * (unsigned int)(pw << 1) + (xo & 1),