mirror of
https://github.com/celisej567/mcpe.git
synced 2025-12-31 17:49:17 +03:00
Fix Texture Detection
This commit is contained in:
committed by
iProgramInCpp
parent
ec12755632
commit
433b1532d9
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16.0)
|
||||
project(reminecraftpe-android)
|
||||
|
||||
# Project Root
|
||||
set(MC_ROOT ../../../../../../..)
|
||||
set(MC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../..")
|
||||
|
||||
# Native Android Build
|
||||
add_compile_definitions(USE_NATIVE_ANDROID)
|
||||
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
int getScreenWidth() const override;
|
||||
int getScreenHeight() const override;
|
||||
Texture loadTexture(const std::string& path, bool b = false) override = 0;
|
||||
virtual bool doesTextureExist(const std::string& path) = 0;
|
||||
int getUserInputStatus() override;
|
||||
SoundSystem* const getSoundSystem() const override { return m_pSoundSystem; }
|
||||
std::string getDateString(int time) override;
|
||||
|
||||
@@ -172,6 +172,25 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
|
||||
// Return
|
||||
return out;
|
||||
}
|
||||
bool AppPlatform_sdl::doesTextureExist(const std::string& path)
|
||||
{
|
||||
// Get Full Path
|
||||
std::string realPath = getAssetPath(path);
|
||||
|
||||
// Open File
|
||||
SDL_RWops *io = SDL_RWFromFile(realPath.c_str(), "rb");
|
||||
if (!io)
|
||||
{
|
||||
// Does Not Exist
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// File Exists
|
||||
SDL_RWclose(io);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool AppPlatform_sdl::hasFileSystemAccess()
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
|
||||
void saveScreenshot(const std::string& fileName, int width, int height) override;
|
||||
Texture loadTexture(const std::string& path, bool b = false) override;
|
||||
bool doesTextureExist(const std::string& path) override;
|
||||
|
||||
bool hasFileSystemAccess() override;
|
||||
|
||||
|
||||
@@ -28,3 +28,23 @@ 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
|
||||
std::string realPath = getAssetPath(path);
|
||||
|
||||
// Open File
|
||||
int width = 0, height = 0;
|
||||
char *data = emscripten_get_preloaded_image_data(("/" + realPath).c_str(), &width, &height);
|
||||
if (!data)
|
||||
{
|
||||
// Does Not Exist
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// File Exists
|
||||
free(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,5 @@ public:
|
||||
AppPlatform_sdl(std::string storageDir, SDL_Window *window);
|
||||
|
||||
Texture loadTexture(const std::string& path, bool b = false) override;
|
||||
bool doesTextureExist(const std::string& path) override;
|
||||
};
|
||||
|
||||
@@ -294,29 +294,12 @@ extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp
|
||||
extern bool g_bIsGrassColorAvailable; // world/level/GrassColor.cpp
|
||||
extern bool g_bIsFoliageColorAvailable; // world/level/FoliageColor.cpp
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
bool DoesAssetExist(const std::string & fileName)
|
||||
{
|
||||
std::string realPath = g_pAppPlatform->getAssetPath(fileName);
|
||||
int width = 0, height = 0;
|
||||
char *data = emscripten_get_preloaded_image_data(("/" + realPath).c_str(), &width, &height);
|
||||
if (data == NULL)
|
||||
return false;
|
||||
|
||||
free(data);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
// access works just fine on linux and friends
|
||||
#define DoesAssetExist(fileName) (XPL_ACCESS("assets/" fileName, 0) == 0)
|
||||
#endif
|
||||
|
||||
void CheckOptionalTextureAvailability()
|
||||
{
|
||||
g_bIsMenuBackgroundAvailable = DoesAssetExist("gui/background/panorama_0.png");
|
||||
g_bAreCloudsAvailable = DoesAssetExist("environment/clouds.png");
|
||||
g_bIsGrassColorAvailable = DoesAssetExist("misc/grasscolor.png");
|
||||
g_bIsFoliageColorAvailable = DoesAssetExist("misc/foliagecolor.png");
|
||||
g_bIsMenuBackgroundAvailable = g_pAppPlatform->doesTextureExist("gui/background/panorama_0.png");
|
||||
g_bAreCloudsAvailable = g_pAppPlatform->doesTextureExist("environment/clouds.png");
|
||||
g_bIsGrassColorAvailable = g_pAppPlatform->doesTextureExist("misc/grasscolor.png");
|
||||
g_bIsFoliageColorAvailable = g_pAppPlatform->doesTextureExist("misc/foliagecolor.png");
|
||||
}
|
||||
|
||||
// Main
|
||||
|
||||
Reference in New Issue
Block a user