mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-17 20:10:23 +03:00
* Fixes to fancy pants grass detection, etc.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
# * The X and Y destination coordinates will be multiplied by 16.
|
||||
# * The texture doesn't have to be 16x16, all of it will be patched on to terrain.png.
|
||||
|
||||
terrain|4|5|grass_side_transparent.png
|
||||
grass_sides_tint|true
|
||||
|
||||
# Stop now to ignore the below commands. They're for a patch I'm working on that I don't want to release yet.
|
||||
|
||||
@@ -134,7 +134,7 @@ std::string AppPlatform_android::getDateString(int time)
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
Texture AppPlatform_android::loadTexture(const std::string& str, bool b)
|
||||
Texture AppPlatform_android::loadTexture(const std::string& str, bool bIsRequired)
|
||||
{
|
||||
std::string realPath = str;
|
||||
if (realPath.size() && realPath[0] == '/')
|
||||
@@ -144,19 +144,22 @@ Texture AppPlatform_android::loadTexture(const std::string& str, bool b)
|
||||
AAsset* asset = AAssetManager_open(m_app->activity->assetManager, str.c_str(), AASSET_MODE_BUFFER);
|
||||
if (!asset) {
|
||||
LOG_E("File %s couldn't be opened", realPath.c_str());
|
||||
assert(!bIsRequired && "Hey, a texture couldn't be loaded");
|
||||
return Texture(0, 0, nullptr, 1, 0);
|
||||
}
|
||||
size_t cnt = AAsset_getLength(asset);
|
||||
unsigned char* buffer = (unsigned char*)calloc(cnt, sizeof(unsigned char));
|
||||
AAsset_read(asset, (void*)buffer, cnt);
|
||||
AAsset_close(asset);
|
||||
|
||||
|
||||
int width = 0, height = 0, channels = 0;
|
||||
|
||||
stbi_uc* img = stbi_load_from_memory(buffer, cnt, &width, &height, &channels, STBI_rgb_alpha);
|
||||
if (!img)
|
||||
{
|
||||
LOG_E("File %s couldn't be loaded via stb_image", realPath.c_str());
|
||||
assert(!bIsRequired && "Hey, a texture couldn't be loaded");
|
||||
return Texture(0, 0, nullptr, 1, 0);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
const char* const getWindowTitle() const;
|
||||
int getScreenWidth() const override;
|
||||
int getScreenHeight() const override;
|
||||
Texture loadTexture(const std::string& path, bool b = false) override = 0;
|
||||
Texture loadTexture(const std::string& path, bool bIsRequired = false) override = 0;
|
||||
virtual bool doesTextureExist(const std::string& path) = 0;
|
||||
int getUserInputStatus() override;
|
||||
SoundSystem* const getSoundSystem() const override { return m_pSoundSystem; }
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
AppPlatform_sdl::AppPlatform_sdl(std::string storageDir, SDL_Window *window)
|
||||
: AppPlatform_sdl_base(storageDir, window)
|
||||
{
|
||||
setIcon(loadTexture("icon.png"));
|
||||
setIcon(loadTexture("icon.png", false));
|
||||
}
|
||||
|
||||
// Take Screenshot
|
||||
@@ -128,7 +128,7 @@ void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, i
|
||||
}
|
||||
}
|
||||
|
||||
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool bIsRequired)
|
||||
{
|
||||
Texture out;
|
||||
out.field_C = 1;
|
||||
@@ -156,6 +156,7 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
if (!img)
|
||||
{
|
||||
// Failed To Parse Image
|
||||
LOG_E("The image could not be loaded properly: %s", path.c_str());
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ AppPlatform_sdl::AppPlatform_sdl(std::string storageDir, SDL_Window *window)
|
||||
{
|
||||
}
|
||||
|
||||
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool bIsRequired)
|
||||
{
|
||||
Texture out;
|
||||
out.field_C = 1;
|
||||
@@ -28,6 +28,7 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
LOG_E("Couldn't find file: %s", realPath.c_str());
|
||||
return out;
|
||||
}
|
||||
|
||||
bool AppPlatform_sdl::doesTextureExist(const std::string& path)
|
||||
{
|
||||
// Get Full Path
|
||||
|
||||
@@ -151,7 +151,7 @@ std::string AppPlatform_win32::getDateString(int time)
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
Texture AppPlatform_win32::loadTexture(const std::string& str, bool b)
|
||||
Texture AppPlatform_win32::loadTexture(const std::string& str, bool bIsRequired)
|
||||
{
|
||||
std::string realPath = str;
|
||||
if (realPath.size() && realPath[0] == '/')
|
||||
@@ -166,6 +166,9 @@ Texture AppPlatform_win32::loadTexture(const std::string& str, bool b)
|
||||
LOG_E("File %s couldn't be opened", realPath.c_str());
|
||||
|
||||
_error:
|
||||
if (!bIsRequired)
|
||||
return Texture(0, 0, nullptr, 1, 0);
|
||||
|
||||
const std::string msg = "Error loading " + realPath + ". Did you unzip the Minecraft assets?";
|
||||
MessageBoxA(GetHWND(), msg.c_str(), getWindowTitle(), MB_OK);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
int getScreenHeight() const override { return m_ScreenHeight; }
|
||||
void showDialog(eDialogType) override;
|
||||
std::string getDateString(int time) override;
|
||||
Texture loadTexture(const std::string& str, bool b) override;
|
||||
Texture loadTexture(const std::string& str, bool bIsRequired) override;
|
||||
|
||||
// From v0.1.1. Also add these to determine touch screen use within the game.
|
||||
bool isTouchscreen() override;
|
||||
|
||||
@@ -101,7 +101,7 @@ void AppPlatform::uploadPlatformDependentData(int, void*)
|
||||
}
|
||||
|
||||
|
||||
Texture AppPlatform::loadTexture(const std::string&, bool)
|
||||
Texture AppPlatform::loadTexture(const std::string&, bool bIsRequired)
|
||||
{
|
||||
return Texture(0, 0, nullptr, 1, 0);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
virtual void saveScreenshot(const std::string&, int, int);
|
||||
virtual void showDialog(eDialogType);
|
||||
virtual void uploadPlatformDependentData(int, void*);
|
||||
virtual Texture loadTexture(const std::string&, bool);
|
||||
virtual Texture loadTexture(const std::string&, bool bIsRequired);
|
||||
|
||||
#ifndef ORIGINAL_CODE
|
||||
// From v0.1.1. Also add these to determine touch screen use within the game.
|
||||
|
||||
@@ -791,6 +791,20 @@ void Minecraft::init()
|
||||
{
|
||||
GetPatchManager()->LoadPatchData(platform()->getPatchData());
|
||||
|
||||
m_pTextures = new Textures(m_options, platform());
|
||||
m_pTextures->addDynamicTexture(new WaterTexture);
|
||||
m_pTextures->addDynamicTexture(new WaterSideTexture);
|
||||
m_pTextures->addDynamicTexture(new LavaTexture);
|
||||
m_pTextures->addDynamicTexture(new LavaSideTexture);
|
||||
m_pTextures->addDynamicTexture(new FireTexture(0));
|
||||
|
||||
m_pTextures->loadAndBindTexture(C_TERRAIN_NAME);
|
||||
GetPatchManager()->PatchTextures(platform(), TYPE_TERRAIN);
|
||||
m_pTextures->loadAndBindTexture(C_ITEMS_NAME);
|
||||
GetPatchManager()->PatchTextures(platform(), TYPE_ITEMS);
|
||||
|
||||
GetPatchManager()->PatchTiles();
|
||||
|
||||
if (platform()->hasFileSystemAccess())
|
||||
m_options = new Options(m_externalStorageDir);
|
||||
else
|
||||
@@ -805,12 +819,6 @@ void Minecraft::init()
|
||||
m_pSoundEngine = new SoundEngine(platform()->getSoundSystem());
|
||||
m_pSoundEngine->init(m_options);
|
||||
|
||||
m_pTextures = new Textures(m_options, platform());
|
||||
m_pTextures->addDynamicTexture(new WaterTexture);
|
||||
m_pTextures->addDynamicTexture(new WaterSideTexture);
|
||||
m_pTextures->addDynamicTexture(new LavaTexture);
|
||||
m_pTextures->addDynamicTexture(new LavaSideTexture);
|
||||
m_pTextures->addDynamicTexture(new FireTexture(0));
|
||||
m_pLevelRenderer = new LevelRenderer(this, m_pTextures);
|
||||
m_pGameRenderer = new GameRenderer(this);
|
||||
m_pParticleEngine = new ParticleEngine(m_pLevel, m_pTextures);
|
||||
@@ -832,14 +840,6 @@ void Minecraft::init()
|
||||
{
|
||||
FoliageColor::init(m_pPlatform->loadTexture("misc/foliagecolor.png", true));
|
||||
}
|
||||
|
||||
|
||||
m_pTextures->loadAndBindTexture(C_TERRAIN_NAME);
|
||||
GetPatchManager()->PatchTextures(platform(), TYPE_TERRAIN);
|
||||
m_pTextures->loadAndBindTexture(C_ITEMS_NAME);
|
||||
GetPatchManager()->PatchTextures(platform(), TYPE_ITEMS);
|
||||
|
||||
GetPatchManager()->PatchTiles();
|
||||
}
|
||||
|
||||
Minecraft::~Minecraft()
|
||||
|
||||
@@ -258,9 +258,7 @@ void Options::_load()
|
||||
{
|
||||
m_bFancyGrass = readBool(value);
|
||||
if (!(GetPatchManager()->IsGrassSidesTinted()))
|
||||
{
|
||||
m_bFancyGrass = false;
|
||||
}
|
||||
}
|
||||
else if (key == "gfx_biomecolors")
|
||||
{
|
||||
|
||||
@@ -144,6 +144,11 @@ void PatchManager::LoadPatchData(const std::string& patchData)
|
||||
if (command == "grass_sides_tint")
|
||||
{
|
||||
ReadBool(lineStream, m_bGrassSidesTinted);
|
||||
|
||||
if (m_bGrassSidesTinted)
|
||||
// push a magic value so we can determine whether to disable it if the file doesn't exist
|
||||
m_patchData.push_back(PatchData(TYPE_TERRAIN, 100, 100, "grass_side_transparent.png"));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -160,10 +165,24 @@ void PatchManager::PatchTextures(AppPlatform* pAppPlatform, ePatchType patchType
|
||||
if (pd.m_type != patchType)
|
||||
continue;
|
||||
|
||||
Texture texture = pAppPlatform->loadTexture("patches/" + pd.m_filename, true);
|
||||
if (texture.m_width == 0)
|
||||
bool bDisableFancyGrassIfFailed = false;
|
||||
|
||||
// got the magic value, we can determine whether to disable fancy pants grass if the file doesn't exist
|
||||
if (pd.m_destX == 1600 && pd.m_destY == 1600 && pd.m_type == TYPE_TERRAIN)
|
||||
{
|
||||
LOG_W("Image %s has width 0, not found?! Skipping", pd.m_filename.c_str());
|
||||
pd.m_destX = 4 * 16;
|
||||
pd.m_destY = 5 * 16;
|
||||
|
||||
bDisableFancyGrassIfFailed = true;
|
||||
}
|
||||
|
||||
// N.B. Well, in some cases, you do want things to fail nicely.
|
||||
Texture texture = pAppPlatform->loadTexture("patches/" + pd.m_filename, false);
|
||||
if (!texture.m_pixels || !texture.m_width || !texture.m_height)
|
||||
{
|
||||
LOG_W("Image %s was not found?! Skipping", pd.m_filename.c_str());
|
||||
if (bDisableFancyGrassIfFailed)
|
||||
m_bGrassSidesTinted = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
bool Textures::MIPMAP = false;
|
||||
|
||||
int Textures::loadTexture(const std::string& name, bool b)
|
||||
int Textures::loadTexture(const std::string& name, bool bIsRequired)
|
||||
{
|
||||
std::map<std::string, GLuint>::iterator i = m_textures.find(name);
|
||||
if (i != m_textures.end())
|
||||
return i->second;
|
||||
|
||||
Texture t = m_pPlatform->loadTexture(name, b);
|
||||
Texture t = m_pPlatform->loadTexture(name, bIsRequired);
|
||||
|
||||
int result = -1;
|
||||
if (t.m_pixels)
|
||||
|
||||
Reference in New Issue
Block a user