Skip to content

Commit

Permalink
* Fixed cloud scroll speed
Browse files Browse the repository at this point in the history
* Replaced global variable with LevelRenderer::areCloudsAvailable()
  • Loading branch information
BrentDaMage committed May 7, 2024
1 parent 8fc8a38 commit 8ac4093
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions platforms/android/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
}
}

extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp
extern bool g_bIsGrassColorAvailable; // world/level/GrassColor.cpp
extern bool g_bIsFoliageColorAvailable; // world/level/FoliageColor.cpp

Expand All @@ -408,7 +407,7 @@ static void CheckOptionalTextureAvailability()
#endif

#ifdef FEATURE_CLOUDS
g_bAreCloudsAvailable = true;
LevelRenderer::setAreCloudsAvailable(true);
#endif

#ifdef FEATURE_GRASS_COLOR
Expand Down
3 changes: 1 addition & 2 deletions platforms/sdl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,13 @@ static EM_BOOL main_loop(double time, void *user_data)
}
}

extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp
extern bool g_bIsGrassColorAvailable; // world/level/GrassColor.cpp
extern bool g_bIsFoliageColorAvailable; // world/level/FoliageColor.cpp

void CheckOptionalTextureAvailability()
{
Screen::setIsMenuPanoramaAvailable(g_pAppPlatform->doesTextureExist("gui/background/panorama_0.png"));
g_bAreCloudsAvailable = g_pAppPlatform->doesTextureExist("environment/clouds.png");
LevelRenderer::setAreCloudsAvailable(g_pAppPlatform->doesTextureExist("environment/clouds.png"));
g_bIsGrassColorAvailable = g_pAppPlatform->doesTextureExist("misc/grasscolor.png");
g_bIsFoliageColorAvailable = g_pAppPlatform->doesTextureExist("misc/foliagecolor.png");
}
Expand Down
3 changes: 1 addition & 2 deletions platforms/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,16 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
return 0;
}

extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp
extern bool g_bIsGrassColorAvailable; // world/level/GrassColor.cpp
extern bool g_bIsFoliageColorAvailable; // world/level/FoliageColor.cpp

void CheckOptionalTextureAvailability()
{
// Optional features that you really should be able to get away with not including.
Screen::setIsMenuPanoramaAvailable(XPL_ACCESS("assets/gui/background/panorama_0.png", 0) == 0);
LevelRenderer::setAreCloudsAvailable(XPL_ACCESS("assets/environment/clouds.png", 0) == 0);

// TODO: These should be inside of an initialized "Minecraft" instance rather than the global namespace
g_bAreCloudsAvailable = XPL_ACCESS("assets/environment/clouds.png", 0) == 0;
g_bIsGrassColorAvailable = XPL_ACCESS("assets/misc/grasscolor.png", 0) == 0;
g_bIsFoliageColorAvailable = XPL_ACCESS("assets/misc/foliagecolor.png", 0) == 0;
}
Expand Down
20 changes: 10 additions & 10 deletions source/client/renderer/LevelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "world/tile/LeafTile.hpp"
#include "world/tile/GrassTile.hpp"

bool LevelRenderer::_areCloudsAvailable = false; // false because 0.1 didn't have them

LevelRenderer::LevelRenderer(Minecraft* pMC, Textures* pTexs)
{
field_4 = -9999.0f;
Expand Down Expand Up @@ -1179,12 +1181,9 @@ void LevelRenderer::renderSky(float f)
glDepthMask(true);
}

// TODO: This should be inside of an initialized "Minecraft" instance rather than the global namespace
bool g_bAreCloudsAvailable = false; // false because 0.1 didn't have them

void LevelRenderer::renderClouds(float f)
{
if (!g_bAreCloudsAvailable)
if (!areCloudsAvailable())
return;

glEnable(GL_TEXTURE_2D);
Expand All @@ -1198,7 +1197,7 @@ void LevelRenderer::renderClouds(float f)

Vec3 cloudColor = m_pLevel->getCloudColor(f);

float offX = Mth::Lerp(m_pMinecraft->m_pMobPersp->field_3C.x, m_pMinecraft->m_pMobPersp->m_pos.x, f) + (float(m_ticksSinceStart) + f) * 0.3f;
float offX = Mth::Lerp(m_pMinecraft->m_pMobPersp->field_3C.x, m_pMinecraft->m_pMobPersp->m_pos.x, f) + (float(m_ticksSinceStart) + f) * 0.03f;
float offZ = Mth::Lerp(m_pMinecraft->m_pMobPersp->field_3C.z, m_pMinecraft->m_pMobPersp->m_pos.z, f);

int dx2048 = Mth::floor(offX / 2048.0f);
Expand All @@ -1209,17 +1208,18 @@ void LevelRenderer::renderClouds(float f)

Tesselator& t = Tesselator::instance;

float fYPos = (128.0f - yPos) + 0.33f;
float fYPos = ((float)C_MAX_Y - yPos) + 0.33f;
offX /= 2048.0f;
offZ /= 2048.0f;
t.begin();
t.color(cloudColor.x, cloudColor.y, cloudColor.z, 0.8f);

const int incr = 32;
const int in2 = 256 / incr;
for (int x = -incr * in2; x < incr * in2; x += incr)
const int incr = 16 * 2;
const int maxX = C_MAX_CHUNKS_X * 16;
const int maxZ = C_MAX_CHUNKS_Z * 16;
for (int x = -maxX; x < maxX; x += incr)
{
for (int z = -incr * in2; z < incr * in2; z += incr)
for (int z = -maxZ; z < maxZ; z += incr)
{
t.vertexUV(float(x) + 0.0f, fYPos, float(z) + incr, float(x + 0.0f) / 2048.0f + offX, float(z + incr) / 2048.0f + offZ);
t.vertexUV(float(x) + incr, fYPos, float(z) + incr, float(x + incr) / 2048.0f + offX, float(z + incr) / 2048.0f + offZ);
Expand Down
6 changes: 6 additions & 0 deletions source/client/renderer/LevelRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ class DirtyChunkSorter

class LevelRenderer : public LevelListener
{
private:
static bool _areCloudsAvailable;
public:
static bool areCloudsAvailable() { return _areCloudsAvailable; }
static void setAreCloudsAvailable(bool value) { _areCloudsAvailable = value; }

public:
LevelRenderer(Minecraft*, Textures*);

Expand Down

0 comments on commit 8ac4093

Please sign in to comment.