Project modernization (#630)

* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
This commit is contained in:
ModMaker101
2026-03-07 21:56:03 -05:00
committed by GitHub
parent 1be5faaea7
commit a9be52c41a
1373 changed files with 19903 additions and 19449 deletions

View File

@@ -74,7 +74,7 @@ ResourceLocation GameRenderer::SNOW_LOCATION = ResourceLocation(TN_ENVIRONMENT_S
GameRenderer::GameRenderer(Minecraft *mc)
{
// 4J - added this block of initialisers
renderDistance = (float)(16 * 16 >> mc->options->viewDistance);
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))
@@ -475,7 +476,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);
@@ -493,7 +494,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);
}
@@ -522,9 +523,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;
@@ -532,7 +533,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;
@@ -540,7 +541,7 @@ void GameRenderer::moveCameraToPlayer(float a)
}
}
glTranslatef(0, 0, (float) -cameraDist);
glTranslatef(0, 0, static_cast<float>(-cameraDist));
}
}
else
@@ -595,7 +596,7 @@ void GameRenderer::getFovAndAspect(float& fov, float& aspect, float a, bool appl
{
// 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;
aspect = mc->width / static_cast<float>(mc->height);
fov = getFov(a, applyEffects);
if( ( mc->player->m_iScreenSection == C4JRender::VIEWPORT_TYPE_SPLIT_TOP ) ||
@@ -616,11 +617,11 @@ void GameRenderer::setupCamera(float a, int eye)
{
if (mc->options->viewDistance >= 0)
{
renderDistance = (float)(16 * 16 >> mc->options->viewDistance);
renderDistance = static_cast<float>(16 * 16 >> mc->options->viewDistance);
}
else
{
renderDistance = (float)((16 * 16) << (-mc->options->viewDistance));
renderDistance = static_cast<float>((16 * 16) << (-mc->options->viewDistance));
}
glMatrixMode(GL_PROJECTION);
@@ -635,7 +636,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);
@@ -700,7 +701,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;
@@ -718,7 +719,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);
@@ -830,8 +831,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;
@@ -1168,56 +1169,57 @@ void GameRenderer::render(float a, bool bFirst)
}
#endif
if (mc->noRender) return;
GameRenderer::anaglyph3d = mc->options->anaglyph3d;
if (mc->noRender)
return;
GameRenderer::anaglyph3d = mc->options->anaglyph3d;
glViewport(0, 0, mc->width, mc->height); // 4J - added
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;
glViewport(0, 0, mc->width, mc->height); // 4J - added
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);
int maxFps = getFpsCap(mc->options->framerateLimit);
if (mc->level != NULL)
{
if (mc->options->framerateLimit == 0)
{
renderLevel(a, 0);
}
else
{
renderLevel(a, lastNsTime + 1000000000 / maxFps);
}
if (mc->level != nullptr)
{
if (mc->options->framerateLimit == 0)
{
renderLevel(a, 0);
}
else
{
renderLevel(a, lastNsTime + 1000000000 / maxFps);
}
lastNsTime = System::nanoTime();
lastNsTime = System::nanoTime();
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();
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();
}
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->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)
{
@@ -1383,7 +1385,7 @@ void GameRenderer::renderLevel(float a, int64_t 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;
}
@@ -1511,7 +1513,7 @@ void GameRenderer::renderLevel(float a, int64_t 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);
@@ -1580,7 +1582,7 @@ void GameRenderer::renderLevel(float a, int64_t 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);
@@ -1670,7 +1672,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;
@@ -1693,7 +1695,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
{
@@ -1703,7 +1705,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));
}
}
}
@@ -1738,7 +1740,7 @@ void GameRenderer::renderSnowAndRain(float a)
turnOnLightLayer(a);
if (rainXa == NULL)
if (rainXa == nullptr)
{
rainXa = new float[32 * 32];
rainZa = new float[32 * 32];
@@ -1885,11 +1887,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__
@@ -1931,7 +1933,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);
@@ -1943,27 +1945,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;
@@ -1999,9 +2001,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)
{
@@ -2012,9 +2014,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)
{
@@ -2023,9 +2025,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;
@@ -2040,7 +2042,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
{
@@ -2145,7 +2147,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);
@@ -2200,7 +2202,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;
}
@@ -2227,7 +2229,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);