aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/GameRenderer.cpp
diff options
context:
space:
mode:
authorqwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com>2026-03-16 21:44:26 -0500
committerGitHub <noreply@github.com>2026-03-16 21:44:26 -0500
commitce739f6045ec72127491286ea3f3f21e537c1b55 (patch)
treef33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /Minecraft.Client/GameRenderer.cpp
parent255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff)
parent5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff)
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/GameRenderer.cpp')
-rw-r--r--Minecraft.Client/GameRenderer.cpp414
1 files changed, 213 insertions, 201 deletions
diff --git a/Minecraft.Client/GameRenderer.cpp b/Minecraft.Client/GameRenderer.cpp
index 174d356c..fe8171c1 100644
--- a/Minecraft.Client/GameRenderer.cpp
+++ b/Minecraft.Client/GameRenderer.cpp
@@ -74,7 +74,7 @@ ResourceLocation GameRenderer::SNOW_LOCATION = ResourceLocation(TN_ENVIRONMENT_S
GameRenderer::GameRenderer(Minecraft *mc)
{
// 4J - added this block of initialisers
- renderDistance = 0;
+ renderDistance = static_cast<float>(16 * 16 >> mc->options->viewDistance);
_tick = 0;
hovered = nullptr;
thirdDistance = 4;
@@ -106,8 +106,8 @@ GameRenderer::GameRenderer(Minecraft *mc)
zoom = 1;
zoom_x = 0;
zoom_y = 0;
- rainXa = NULL;
- rainZa = NULL;
+ rainXa = nullptr;
+ rainZa = nullptr;
lastActiveTime = Minecraft::currentTimeMillis();
lastNsTime = 0;
random = new Random();
@@ -139,7 +139,7 @@ GameRenderer::GameRenderer(Minecraft *mc)
}
this->mc = mc;
- itemInHandRenderer = NULL;
+ itemInHandRenderer = nullptr;
// 4J-PB - set up the local players iteminhand renderers here - needs to be done with lighting enabled so that the render geometry gets compiled correctly
glEnable(GL_LIGHTING);
@@ -170,7 +170,7 @@ GameRenderer::GameRenderer(Minecraft *mc)
m_updateEvents->Set(eUpdateEventIsFinished);
InitializeCriticalSection(&m_csDeleteStack);
- m_updateThread = new C4JThread(runUpdate, NULL, "Chunk update");
+ m_updateThread = new C4JThread(runUpdate, nullptr, "Chunk update");
#ifdef __PS3__
m_updateThread->SetPriority(THREAD_PRIORITY_ABOVE_NORMAL);
#endif// __PS3__
@@ -182,8 +182,8 @@ 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;
+ if(rainXa != nullptr) delete [] rainXa;
+ if(rainZa != nullptr) delete [] rainZa;
}
void GameRenderer::tick(bool first) // 4J - add bFirst
@@ -211,7 +211,7 @@ void GameRenderer::tick(bool first) // 4J - add bFirst
accumulatedSmoothYO = 0;
}
- if (mc->cameraTargetPlayer == NULL)
+ if (mc->cameraTargetPlayer == nullptr)
{
mc->cameraTargetPlayer = dynamic_pointer_cast<Mob>(mc->player);
}
@@ -230,7 +230,7 @@ void GameRenderer::tick(bool first) // 4J - add bFirst
darkenWorldAmountO = darkenWorldAmount;
if (BossMobGuiInfo::darkenWorld)
{
- darkenWorldAmount += 1.0f / ((float) SharedConstants::TICKS_PER_SECOND * 1);
+ darkenWorldAmount += 1.0f / (static_cast<float>(SharedConstants::TICKS_PER_SECOND) * 1);
if (darkenWorldAmount > 1)
{
darkenWorldAmount = 1;
@@ -239,7 +239,7 @@ void GameRenderer::tick(bool first) // 4J - add bFirst
}
else if (darkenWorldAmount > 0)
{
- darkenWorldAmount -= 1.0f / ((float) SharedConstants::TICKS_PER_SECOND * 4);
+ darkenWorldAmount -= 1.0f / (static_cast<float>(SharedConstants::TICKS_PER_SECOND) * 4);
}
if( mc->player != mc->localplayers[ProfileManager.GetPrimaryPad()] ) return; // 4J added for split screen - only do rest of processing for once per frame
@@ -249,8 +249,8 @@ void GameRenderer::tick(bool first) // 4J - add bFirst
void GameRenderer::pick(float a)
{
- if (mc->cameraTargetPlayer == NULL) return;
- if (mc->level == NULL) return;
+ if (mc->cameraTargetPlayer == nullptr) return;
+ if (mc->level == nullptr) return;
mc->crosshairPickMob = nullptr;
@@ -280,7 +280,7 @@ void GameRenderer::pick(float a)
( hitz < minxz ) || ( hitz > maxxz) )
{
delete mc->hitResult;
- mc->hitResult = NULL;
+ mc->hitResult = nullptr;
}
}
@@ -297,7 +297,7 @@ void GameRenderer::pick(float a)
range = dist;
}
- if (mc->hitResult != NULL)
+ if (mc->hitResult != nullptr)
{
dist = mc->hitResult->pos->distanceTo(from);
}
@@ -327,13 +327,14 @@ void GameRenderer::pick(float a)
else if (p != nullptr)
{
double dd = from->distanceTo(p->pos);
- if (e == mc->cameraTargetPlayer->riding != NULL)
- {
- if (nearest == 0)
- {
- hovered = e;
- }
- }
+ auto const riding = mc->cameraTargetPlayer->riding;
+ if (riding != nullptr && e == riding)
+ {
+ if (nearest == 0)
+ {
+ hovered = e;
+ }
+ }
else
{
hovered = e;
@@ -343,11 +344,11 @@ void GameRenderer::pick(float a)
delete p;
}
- if (hovered != NULL)
+ if (hovered != nullptr)
{
- if (nearest < dist || (mc->hitResult == NULL))
+ if (nearest < dist || (mc->hitResult == nullptr))
{
- if( mc->hitResult != NULL )
+ if( mc->hitResult != nullptr )
delete mc->hitResult;
mc->hitResult = new HitResult(hovered);
if (hovered->instanceof(eTYPE_LIVINGENTITY))
@@ -393,7 +394,7 @@ float GameRenderer::getFov(float a, bool applyEffects)
if (applyEffects)
{
- fov += mc->options->fov * 40;
+ //fov += mc->options->fov * 40;
fov *= oFov[playerIdx] + (this->fov[playerIdx] - oFov[playerIdx]) * a;
}
if (player->getHealth() <= 0)
@@ -477,7 +478,7 @@ void GameRenderer::moveCameraToPlayer(float a)
int data = mc->level->getData(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z));
int direction = data & 3;
- glRotatef((float)direction * 90,0.0f, 1.0f, 0.0f);
+ glRotatef(static_cast<float>(direction) * 90,0.0f, 1.0f, 0.0f);
}
glRotatef(player->yRotO + (player->yRot - player->yRotO) * a + 180, 0, -1, 0);
glRotatef(player->xRotO + (player->xRot - player->xRotO) * a, -1, 0, 0);
@@ -495,7 +496,7 @@ void GameRenderer::moveCameraToPlayer(float a)
float rotationY = thirdRotationO + (thirdRotation - thirdRotationO) * a;
float xRot = thirdTiltO + (thirdTilt - thirdTiltO) * a;
- glTranslatef(0, 0, (float) -cameraDist);
+ glTranslatef(0, 0, static_cast<float>(-cameraDist));
glRotatef(xRot, 1, 0, 0);
glRotatef(rotationY, 0, 1, 0);
}
@@ -524,9 +525,9 @@ void GameRenderer::moveCameraToPlayer(float a)
for (int i = 0; i < 8; i++)
{
- float xo = (float)((i & 1) * 2 - 1);
- float yo = (float)(((i >> 1) & 1) * 2 - 1);
- float zo = (float)(((i >> 2) & 1) * 2 - 1);
+ float xo = static_cast<float>((i & 1) * 2 - 1);
+ float yo = static_cast<float>(((i >> 1) & 1) * 2 - 1);
+ float zo = static_cast<float>(((i >> 2) & 1) * 2 - 1);
xo *= 0.1f;
yo *= 0.1f;
@@ -534,7 +535,7 @@ void GameRenderer::moveCameraToPlayer(float a)
// 4J - corrected bug here where zo was also added to x component
HitResult *hr = mc->level->clip(Vec3::newTemp(x + xo, y + yo, z + zo), Vec3::newTemp(x - xd + xo, y - yd + yo, z - zd + zo));
- if (hr != NULL)
+ if (hr != nullptr)
{
double dist = hr->pos->distanceTo(Vec3::newTemp(x, y, z));
if (dist < cameraDist) cameraDist = dist;
@@ -542,7 +543,7 @@ void GameRenderer::moveCameraToPlayer(float a)
}
}
- glTranslatef(0, 0, (float) -cameraDist);
+ glTranslatef(0, 0, static_cast<float>(-cameraDist));
}
}
else
@@ -595,9 +596,10 @@ void GameRenderer::unZoomRegion()
// 4J added as we have more complex adjustments to make for fov & aspect on account of viewports
void GameRenderer::getFovAndAspect(float& fov, float& aspect, float a, bool applyEffects)
{
- // 4J - split out aspect ratio and fov here so we can adjust for viewports - we might need to revisit these as
- // they are maybe be too generous for performance.
- aspect = mc->width / (float) mc->height;
+ // Use the real window dimensions so the perspective updates on resize.
+ extern int g_rScreenWidth;
+ extern int g_rScreenHeight;
+ aspect = g_rScreenWidth / static_cast<float>(g_rScreenHeight);
fov = getFov(a, applyEffects);
if( ( mc->player->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_TOP ) ||
@@ -616,7 +618,15 @@ void GameRenderer::getFovAndAspect(float& fov, float& aspect, float a, bool appl
void GameRenderer::setupCamera(float a, int eye)
{
- renderDistance = (float)(16 * 16 >> (mc->options->viewDistance));
+ if (mc->options->viewDistance >= 0)
+ {
+ renderDistance = static_cast<float>(16 * 16 >> mc->options->viewDistance);
+ }
+ else
+ {
+ renderDistance = static_cast<float>((16 * 16) << (-mc->options->viewDistance));
+ }
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -629,7 +639,7 @@ void GameRenderer::setupCamera(float a, int eye)
if (zoom != 1)
{
- glTranslatef((float) zoom_x, (float) -zoom_y, 0);
+ glTranslatef(static_cast<float>(zoom_x), static_cast<float>(-zoom_y), 0);
glScaled(zoom, zoom, 1);
}
gluPerspective(fov, aspect, 0.05f, renderDistance * 2);
@@ -694,7 +704,7 @@ void GameRenderer::renderItemInHand(float a, int eye)
bool renderHand = true;
// 4J-PB - to turn off the hand for screenshots, but not when the item held is a map
- if ( localplayer!=NULL)
+ if ( localplayer!=nullptr)
{
shared_ptr<ItemInstance> item = localplayer->inventory->getSelected();
if(!(item && item->getItem()->id==Item::map_Id) && app.GetGameSettings(localplayer->GetXboxPad(),eGameSetting_DisplayHand)==0 ) renderHand = false;
@@ -712,7 +722,7 @@ void GameRenderer::renderItemInHand(float a, int eye)
if (zoom != 1)
{
- glTranslatef((float) zoom_x, (float) -zoom_y, 0);
+ glTranslatef(static_cast<float>(zoom_x), static_cast<float>(-zoom_y), 0);
glScaled(zoom, zoom, 1);
}
gluPerspective(fov, aspect, 0.05f, renderDistance * 2);
@@ -824,8 +834,8 @@ void GameRenderer::turnOnLightLayer(double alpha)
// 4J - change brought forward from 1.8.2
void GameRenderer::tickLightTexture()
{
- blrt += (float)((Math::random() - Math::random()) * Math::random() * Math::random());
- blgt += (float)((Math::random() - Math::random()) * Math::random() * Math::random());
+ blrt += static_cast<float>((Math::random() - Math::random()) * Math::random() * Math::random());
+ blgt += static_cast<float>((Math::random() - Math::random()) * Math::random() * Math::random());
blrt *= 0.9;
blgt *= 0.9;
blr += (blrt - blr) * 1;
@@ -939,94 +949,77 @@ float GameRenderer::ComputeGammaFromSlider(float slider0to100)
slider = min(slider, 100.0f);
if (slider > 50.0f)
- return 1.0f + (slider - 50.0f) / 50.0f * 3.0f; // 1.0 -> 4.0
+ return 1.0f + (slider - 50.0f) / 50.0f * 1.2f; // 1.0 -> 1.5
else
- return 1.0f - (50.0f - slider) / 50.0f * 0.85f; // 1.0 -> 0.15
+ return 1.0f - (50.0f - slider) / 50.0f * 0.4f; // 1.0 -> 0.5
}
void GameRenderer::CachePlayerGammas()
{
- for (int j = 0; j < XUSER_MAX_COUNT && j < NUM_LIGHT_TEXTURES; ++j)
- {
- std::shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->localplayers[j];
- if (!player)
- {
- m_cachedGammaPerPlayer[j] = 1.0f;
- continue;
- }
+ const float slider = app.GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Gamma);
+ const float gamma = ComputeGammaFromSlider(slider);
- const float slider = app.GetGameSettings(j, eGameSetting_Gamma); // 0..100
- m_cachedGammaPerPlayer[j] = ComputeGammaFromSlider(slider);
- }
+ for (int j = 0; j < XUSER_MAX_COUNT && j < NUM_LIGHT_TEXTURES; ++j)
+ m_cachedGammaPerPlayer[j] = gamma;
}
bool GameRenderer::ComputeViewportForPlayer(int j, D3D11_VIEWPORT &outViewport) const
{
- int active = 0;
- int indexMap[NUM_LIGHT_TEXTURES] = {-1, -1, -1, -1};
- for (int i = 0; i < XUSER_MAX_COUNT && i < NUM_LIGHT_TEXTURES; ++i)
- {
- if (Minecraft::GetInstance()->localplayers[i])
- indexMap[active++] = i;
- }
+ extern int g_rScreenWidth;
+ extern int g_rScreenHeight;
- if (active <= 1)
- {
- outViewport.TopLeftX = 0.0f;
- outViewport.TopLeftY = 0.0f;
- outViewport.Width = static_cast<FLOAT>(mc->width);
- outViewport.Height = static_cast<FLOAT>(mc->height);
- outViewport.MinDepth = 0.0f;
- outViewport.MaxDepth = 1.0f;
- return true;
- }
-
- int k = -1;
- for (int ord = 0; ord < active; ++ord)
- if (indexMap[ord] == j)
- {
- k = ord;
- break;
- }
- if (k < 0)
+ std::shared_ptr<MultiplayerLocalPlayer> player = Minecraft::GetInstance()->localplayers[j];
+ if (!player)
return false;
- const float width = static_cast<float>(mc->width);
- const float height = static_cast<float>(mc->height);
+ const float w = static_cast<float>(g_rScreenWidth);
+ const float h = static_cast<float>(g_rScreenHeight);
+ const float halfW = w * 0.5f;
+ const float halfH = h * 0.5f;
- if (active == 2)
- {
- const float halfH = height * 0.5f;
- outViewport.TopLeftX = 0.0f;
- outViewport.Width = width;
- outViewport.MinDepth = 0.0f;
- outViewport.MaxDepth = 1.0f;
- if (k == 0)
- {
- outViewport.TopLeftY = 0.0f;
- outViewport.Height = halfH;
- }
- else
- {
- outViewport.TopLeftY = halfH;
- outViewport.Height = halfH;
- }
- return true;
- }
- else
+ outViewport.MinDepth = 0.0f;
+ outViewport.MaxDepth = 1.0f;
+
+ switch (static_cast<C4JRender::eViewportType>(player->m_iScreenSection))
{
- const float halfW = width * 0.5f;
- const float halfH = height * 0.5f;
- const int row = (k >= 2) ? 1 : 0;
- const int col = (k % 2);
- outViewport.TopLeftX = col ? halfW : 0.0f;
- outViewport.TopLeftY = row ? halfH : 0.0f;
- outViewport.Width = halfW;
- outViewport.Height = halfH;
- outViewport.MinDepth = 0.0f;
- outViewport.MaxDepth = 1.0f;
- return true;
+ case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
+ outViewport.Width = w; outViewport.Height = halfH;
+ break;
+ case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = halfH;
+ outViewport.Width = w; outViewport.Height = halfH;
+ break;
+ case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
+ outViewport.Width = halfW; outViewport.Height = h;
+ break;
+ case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
+ outViewport.TopLeftX = halfW; outViewport.TopLeftY = 0;
+ outViewport.Width = halfW; outViewport.Height = h;
+ break;
+ case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
+ outViewport.Width = halfW; outViewport.Height = halfH;
+ break;
+ case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
+ outViewport.TopLeftX = halfW; outViewport.TopLeftY = 0;
+ outViewport.Width = halfW; outViewport.Height = halfH;
+ break;
+ case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = halfH;
+ outViewport.Width = halfW; outViewport.Height = halfH;
+ break;
+ case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
+ outViewport.TopLeftX = halfW; outViewport.TopLeftY = halfH;
+ outViewport.Width = halfW; outViewport.Height = halfH;
+ break;
+ default:
+ outViewport.TopLeftX = 0; outViewport.TopLeftY = 0;
+ outViewport.Width = w; outViewport.Height = h;
+ break;
}
+ return true;
}
uint32_t GameRenderer::BuildPlayerViewports(D3D11_VIEWPORT *outViewports, float *outGammas, UINT maxCount) const
@@ -1051,20 +1044,36 @@ void GameRenderer::ApplyGammaPostProcess() const
D3D11_VIEWPORT vps[NUM_LIGHT_TEXTURES];
float gammas[NUM_LIGHT_TEXTURES];
const UINT n = BuildPlayerViewports(vps, gammas, NUM_LIGHT_TEXTURES);
- if (n == 0)
- return;
- bool anyEffect = false;
- for (UINT i = 0; i < n; ++i)
+ float gamma = 1.0f;
+ bool hasPlayers = n > 0;
+
+ if (hasPlayers)
{
- if (gammas[i] < 0.99f || gammas[i] > 1.01f)
+ bool anyEffect = false;
+ for (UINT i = 0; i < n; ++i)
{
- anyEffect = true;
- break;
+ if (gammas[i] < 0.99f || gammas[i] > 1.01f)
+ {
+ anyEffect = true;
+ break;
+ }
}
+ if (!anyEffect)
+ return;
}
- if (!anyEffect)
+ else
+ {
+ const float slider = app.GetGameSettings(0, eGameSetting_Gamma);
+ gamma = ComputeGammaFromSlider(slider);
+ if (gamma < 0.99f || gamma > 1.01f)
+ {
+ PostProcesser::GetInstance().SetGamma(gamma);
+ PostProcesser::GetInstance().Apply();
+ return;
+ }
return;
+ }
if (n == 1)
{
@@ -1110,6 +1119,11 @@ int GameRenderer::getLightTexture(int iPad, Level *level)
void GameRenderer::render(float a, bool bFirst)
{
+ if (mc->player == nullptr)
+ {
+ return;
+ }
+
if( _updateLightTexture && bFirst) updateLightTexture(a);
if (Display::isActive())
{
@@ -1146,58 +1160,56 @@ void GameRenderer::render(float a, bool bFirst)
}
#endif
- if (mc->noRender) return;
- GameRenderer::anaglyph3d = mc->options->anaglyph3d;
+ if (mc->noRender)
+ return;
+ anaglyph3d = mc->options->anaglyph3d;
- glViewport(0, 0, mc->width, mc->height); // 4J - added
+ glViewport(0, 0, mc->width, mc->height); // 4J - added (no-op on Win64, viewport set by StateSetViewport)
ScreenSizeCalculator ssc(mc->options, mc->width, mc->height);
- int screenWidth = ssc.getWidth();
- int screenHeight = ssc.getHeight();
- int xMouse = Mouse::getX() * screenWidth / mc->width;
- int yMouse = screenHeight - Mouse::getY() * screenHeight / mc->height - 1;
-
- int maxFps = getFpsCap(mc->options->framerateLimit);
-
- if (mc->level != NULL)
- {
- if (mc->options->framerateLimit == 0)
- {
- renderLevel(a, 0);
- }
- else
- {
- renderLevel(a, lastNsTime + 1000000000 / maxFps);
- }
-
- lastNsTime = System::nanoTime();
+ const int screenWidth = ssc.getWidth();
+ const int screenHeight = ssc.getHeight();
+ const int xMouse = Mouse::getX() * screenWidth / mc->width;
+ const int yMouse = screenHeight - Mouse::getY() * screenHeight / mc->height - 1;
- ApplyGammaPostProcess();
+ const int maxFps = getFpsCap(mc->options->framerateLimit);
- if (!mc->options->hideGui || mc->screen != NULL)
- {
- mc->gui->render(a, mc->screen != NULL, xMouse, yMouse);
- }
- }
- else
- {
- glViewport(0, 0, mc->width, mc->height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- setupGuiScreen();
-
- lastNsTime = System::nanoTime();
- }
+ if (mc->level != nullptr)
+ {
+ if (mc->options->framerateLimit == 0)
+ {
+ renderLevel(a, 0);
+ }
+ else
+ {
+ renderLevel(a, lastNsTime + 1000000000 / maxFps);
+ }
+ lastNsTime = System::nanoTime();
- if (mc->screen != NULL)
- {
- glClear(GL_DEPTH_BUFFER_BIT);
- mc->screen->render(xMouse, yMouse, a);
- if (mc->screen != NULL && mc->screen->particles != NULL) mc->screen->particles->render(a);
- }
+ if (!mc->options->hideGui || mc->screen != nullptr)
+ {
+ mc->gui->render(a, mc->screen != nullptr, xMouse, yMouse);
+ }
+ }
+ else
+ {
+ glViewport(0, 0, mc->width, mc->height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ setupGuiScreen();
+
+ lastNsTime = System::nanoTime();
+ }
+ if (mc->screen != nullptr)
+ {
+ glClear(GL_DEPTH_BUFFER_BIT);
+ mc->screen->render(xMouse, yMouse, a);
+ if (mc->screen != nullptr && mc->screen->particles != nullptr)
+ mc->screen->particles->render(a);
+ }
}
void GameRenderer::renderLevel(float a)
@@ -1353,7 +1365,7 @@ void GameRenderer::DisableUpdateThread()
#endif
}
-void GameRenderer::renderLevel(float a, __int64 until)
+void GameRenderer::renderLevel(float a, int64_t until)
{
// if (updateLightTexture) updateLightTexture(); // 4J - TODO - Java 1.0.1 has this line enabled, should check why - don't want to put it in now in case it breaks split-screen
@@ -1364,7 +1376,7 @@ void GameRenderer::renderLevel(float a, __int64 until)
// going to do for the primary player, and the other players can just view whatever they have loaded in - we're sharing render data between players.
bool updateChunks = ( mc->player == mc->localplayers[ProfileManager.GetPrimaryPad()] );
- // if (mc->cameraTargetPlayer == NULL) // 4J - removed condition as we want to update this is mc->player changes for different local players
+ // if (mc->cameraTargetPlayer == nullptr) // 4J - removed condition as we want to update this is mc->player changes for different local players
{
mc->cameraTargetPlayer = mc->player;
}
@@ -1436,7 +1448,7 @@ void GameRenderer::renderLevel(float a, __int64 until)
if (until == 0) break;
- __int64 diff = until - System::nanoTime();
+ int64_t diff = until - System::nanoTime();
if (diff < 0) break;
if (diff > 1000000000) break;
} while (true);
@@ -1492,7 +1504,7 @@ void GameRenderer::renderLevel(float a, __int64 until)
PIXEndNamedEvent();
turnOffLightLayer(a); // 4J - brought forward from 1.8.2
- if ( (mc->hitResult != NULL) && cameraEntity->isUnderLiquid(Material::water) && cameraEntity->instanceof(eTYPE_PLAYER) ) //&& !mc->options.hideGui)
+ if ( (mc->hitResult != nullptr) && cameraEntity->isUnderLiquid(Material::water) && cameraEntity->instanceof(eTYPE_PLAYER) ) //&& !mc->options.hideGui)
{
shared_ptr<Player> player = dynamic_pointer_cast<Player>(cameraEntity);
glDisable(GL_ALPHA_TEST);
@@ -1561,7 +1573,7 @@ void GameRenderer::renderLevel(float a, __int64 until)
if ( (zoom == 1) && cameraEntity->instanceof(eTYPE_PLAYER) ) //&& !mc->options.hideGui)
{
- if (mc->hitResult != NULL && !cameraEntity->isUnderLiquid(Material::water))
+ if (mc->hitResult != nullptr && !cameraEntity->isUnderLiquid(Material::water))
{
shared_ptr<Player> player = dynamic_pointer_cast<Player>(cameraEntity);
glDisable(GL_ALPHA_TEST);
@@ -1651,7 +1663,7 @@ void GameRenderer::tickRain()
double rainPosZ = 0;
int rainPosSamples = 0;
- int rainCount = (int) (100 * rainLevel * rainLevel);
+ int rainCount = static_cast<int>(100 * rainLevel * rainLevel);
if (mc->options->particles == 1)
{
rainCount >>= 1;
@@ -1674,7 +1686,7 @@ void GameRenderer::tickRain()
{
if (Tile::tiles[t]->material == Material::lava)
{
- mc->particleEngine->add( shared_ptr<SmokeParticle>( new SmokeParticle(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za, 0, 0, 0) ) );
+ mc->particleEngine->add(std::make_shared<SmokeParticle>(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za, 0, 0, 0));
}
else
{
@@ -1684,7 +1696,7 @@ void GameRenderer::tickRain()
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(std::make_shared<WaterDropParticle>(level, x + xa, y + 0.1f - Tile::tiles[t]->getShapeY0(), z + za));
}
}
}
@@ -1719,7 +1731,7 @@ void GameRenderer::renderSnowAndRain(float a)
turnOnLightLayer(a);
- if (rainXa == NULL)
+ if (rainXa == nullptr)
{
rainXa = new float[32 * 32];
rainZa = new float[32 * 32];
@@ -1866,11 +1878,11 @@ void GameRenderer::renderSnowAndRain(float a)
t->begin();
}
float ra = (((_tick) & 511) + a) / 512.0f;
- float uo = random->nextFloat() + time * 0.01f * (float) random->nextGaussian();
- float vo = random->nextFloat() + time * (float) random->nextGaussian() * 0.001f;
+ float uo = random->nextFloat() + time * 0.01f * static_cast<float>(random->nextGaussian());
+ float vo = random->nextFloat() + time * static_cast<float>(random->nextGaussian()) * 0.001f;
double xd = (x + 0.5f) - player->x;
double zd = (z + 0.5f) - player->z;
- float dd = (float) sqrt(xd * xd + zd * zd) / r;
+ float dd = static_cast<float>(sqrt(xd * xd + zd * zd)) / r;
float br = 1;
t->offset(-xo * 1, -yo * 1, -zo * 1);
#ifdef __PSVITA__
@@ -1912,7 +1924,7 @@ void GameRenderer::setupGuiScreen(int forceScale /*=-1*/)
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0, (float)ssc.rawWidth, (float)ssc.rawHeight, 0, 1000, 3000);
+ glOrtho(0, static_cast<float>(ssc.rawWidth), static_cast<float>(ssc.rawHeight), 0, 1000, 3000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -2000);
@@ -1924,27 +1936,27 @@ void GameRenderer::setupClearColor(float a)
shared_ptr<LivingEntity> player = mc->cameraTargetPlayer;
float whiteness = 1.0f / (4 - mc->options->viewDistance);
- whiteness = 1 - (float) pow((double)whiteness, 0.25);
+ whiteness = 1 - static_cast<float>(pow(static_cast<double>(whiteness), 0.25));
Vec3 *skyColor = level->getSkyColor(mc->cameraTargetPlayer, a);
- float sr = (float) skyColor->x;
- float sg = (float) skyColor->y;
- float sb = (float) skyColor->z;
+ float sr = static_cast<float>(skyColor->x);
+ float sg = static_cast<float>(skyColor->y);
+ float sb = static_cast<float>(skyColor->z);
Vec3 *fogColor = level->getFogColor(a);
- fr = (float) fogColor->x;
- fg = (float) fogColor->y;
- fb = (float) fogColor->z;
+ fr = static_cast<float>(fogColor->x);
+ fg = static_cast<float>(fogColor->y);
+ fb = static_cast<float>(fogColor->z);
if (mc->options->viewDistance < 2)
{
Vec3 *sunAngle = Mth::sin(level->getSunAngle(a)) > 0 ? Vec3::newTemp(-1, 0, 0) : Vec3::newTemp(1, 0, 0);
- float d = (float) player->getViewVector(a)->dot(sunAngle);
+ float d = static_cast<float>(player->getViewVector(a)->dot(sunAngle));
if (d < 0) d = 0;
if (d > 0)
{
float *c = level->dimension->getSunriseColor(level->getTimeOfDay(a), a);
- if (c != NULL)
+ if (c != nullptr)
{
d *= c[3];
fr = fr * (1 - d) + c[0] * d;
@@ -1980,9 +1992,9 @@ void GameRenderer::setupClearColor(float a)
if (isInClouds)
{
Vec3 *cc = level->getCloudColor(a);
- fr = (float) cc->x;
- fg = (float) cc->y;
- fb = (float) cc->z;
+ fr = static_cast<float>(cc->x);
+ fg = static_cast<float>(cc->y);
+ fb = static_cast<float>(cc->z);
}
else if (t != 0 && Tile::tiles[t]->material == Material::water)
{
@@ -1993,9 +2005,9 @@ void GameRenderer::setupClearColor(float a)
byte greenComponent = ((colour>>8)&0xFF);
byte blueComponent = ((colour)&0xFF);
- fr = (float)redComponent/256 + clearness;//0.02f;
- fg = (float)greenComponent/256 + clearness;//0.02f;
- fb = (float)blueComponent/256 + clearness;//0.2f;
+ fr = static_cast<float>(redComponent)/256 + clearness;//0.02f;
+ fg = static_cast<float>(greenComponent)/256 + clearness;//0.02f;
+ fb = static_cast<float>(blueComponent)/256 + clearness;//0.2f;
}
else if (t != 0 && Tile::tiles[t]->material == Material::lava)
{
@@ -2004,9 +2016,9 @@ void GameRenderer::setupClearColor(float a)
byte greenComponent = ((colour>>8)&0xFF);
byte blueComponent = ((colour)&0xFF);
- fr = (float)redComponent/256;//0.6f;
- fg = (float)greenComponent/256;//0.1f;
- fb = (float)blueComponent/256;//0.00f;
+ fr = static_cast<float>(redComponent)/256;//0.6f;
+ fg = static_cast<float>(greenComponent)/256;//0.1f;
+ fb = static_cast<float>(blueComponent)/256;//0.00f;
}
float brr = fogBrO + (fogBr - fogBrO) * a;
@@ -2021,7 +2033,7 @@ void GameRenderer::setupClearColor(float a)
int duration = player->getEffect(MobEffect::blindness)->getDuration();
if (duration < 20)
{
- yy = yy * (1.0f - (float) duration / 20.0f);
+ yy = yy * (1.0f - static_cast<float>(duration) / 20.0f);
}
else
{
@@ -2126,7 +2138,7 @@ void GameRenderer::setupFog(int i, float alpha)
int duration = player->getEffect(MobEffect::blindness)->getDuration();
if (duration < 20)
{
- distance = 5.0f + (renderDistance - 5.0f) * (1.0f - (float) duration / 20.0f);
+ distance = 5.0f + (renderDistance - 5.0f) * (1.0f - static_cast<float>(duration) / 20.0f);
}
glFogi(GL_FOG_MODE, GL_LINEAR);
@@ -2181,7 +2193,7 @@ void GameRenderer::setupFog(int i, float alpha)
{
if (yy < 0) yy = 0;
yy = yy * yy;
- float dist = 100 * (float) yy;
+ float dist = 100 * static_cast<float>(yy);
if (dist < 5) dist = 5;
if (distance > dist) distance = dist;
}
@@ -2208,7 +2220,7 @@ void GameRenderer::setupFog(int i, float alpha)
}
*/
- if (mc->level->dimension->isFoggyAt((int) player->x, (int) player->z))
+ if (mc->level->dimension->isFoggyAt(static_cast<int>(player->x), static_cast<int>(player->z)))
{
glFogf(GL_FOG_START, distance * 0.05f);
glFogf(GL_FOG_END, min(distance, 16 * 16 * .75f) * .5f);