From 009bac7802f2a4a430068410888c8ddbaf926ce7 Mon Sep 17 00:00:00 2001 From: Benau Date: Tue, 16 Jul 2019 13:48:25 +0800 Subject: [PATCH] Share more ifdef with android and iOS --- src/graphics/explosion.cpp | 8 ++++---- src/graphics/sp/sp_texture.cpp | 20 +++++++++---------- src/main.cpp | 9 ++++++--- src/modes/overworld.cpp | 4 ++-- src/modes/world_status.cpp | 2 +- src/scriptengine/script_challenges.cpp | 2 +- .../dialogs/init_android_dialog.cpp | 14 +++---------- .../dialogs/race_paused_dialog.cpp | 2 +- .../options/options_screen_video.cpp | 4 ++-- src/utils/debug.cpp | 2 +- 10 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/graphics/explosion.cpp b/src/graphics/explosion.cpp index 6c2e95291..3bdbddced 100644 --- a/src/graphics/explosion.cpp +++ b/src/graphics/explosion.cpp @@ -45,9 +45,9 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char #ifndef SERVER_ONLY std::string filename = particle_file; - -#ifdef ANDROID - // Use a lower quality effect on Android for better performance + +#ifdef MOBILE_STK + // Use a lower quality effect on mobile for better performance if (filename == "explosion.xml" || filename == "explosion_bomb.xml" || filename == "explosion_cake.xml") @@ -55,7 +55,7 @@ Explosion::Explosion(const Vec3& coord, const char* explosion_sound, const char filename = "explosion_low.xml"; } #endif - + ParticleKindManager* pkm = ParticleKindManager::get(); ParticleKind* particles = pkm->getParticles(filename); m_emitter = NULL; diff --git a/src/graphics/sp/sp_texture.cpp b/src/graphics/sp/sp_texture.cpp index f6ec22bc3..7087cde8a 100644 --- a/src/graphics/sp/sp_texture.cpp +++ b/src/graphics/sp/sp_texture.cpp @@ -29,14 +29,14 @@ #include "utils/log.hpp" #include "utils/string_utils.hpp" -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) #include static_assert(squish::kColourClusterFit == (1 << 5), "Wrong header"); static_assert(squish::kColourRangeFit == (1 << 6), "Wrong header"); static_assert(squish::kColourIterativeClusterFit == (1 << 8), "Wrong header"); #endif -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) extern "C" { #include @@ -46,7 +46,7 @@ extern "C" #include -#if !defined(ANDROID) +#if !defined(MOBILE_STK) static const uint8_t CACHE_VERSION = 1; #endif @@ -233,7 +233,7 @@ bool SPTexture::compressedTexImage2d(std::shared_ptr texture, >& mipmap_sizes) { -#if !defined(SERVER_ONLY) && !defined(ANDROID) +#if !defined(SERVER_ONLY) && !defined(MOBILE_STK) unsigned format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; if (m_undo_srgb && CVS->isEXTTextureCompressionS3TCSRGBUsable()) { @@ -331,7 +331,7 @@ bool SPTexture::saveCompressedTexture(std::shared_ptr texture, >& sizes, const std::string& cache_location) { -#if !defined(SERVER_ONLY) && !defined(ANDROID) +#if !defined(SERVER_ONLY) && !defined(MOBILE_STK) const unsigned total_size = std::accumulate(sizes.begin(), sizes.end(), 0, [] (const unsigned int previous, const std::pair & cur_sizes) @@ -396,7 +396,7 @@ std::shared_ptr SPTexture::getTextureCache(const std::string& p, std::vector >* sizes) { std::shared_ptr cache; -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) io::IReadFile* file = irr::io::createReadFile(p.c_str()); if (file == NULL) { @@ -486,7 +486,7 @@ bool SPTexture::threadedLoad() } else { -#ifndef ANDROID +#ifndef MOBILE_STK if (UserConfigParams::m_hq_mipmap && image->getDimension().Width > 1 && image->getDimension().Height > 1) { @@ -684,7 +684,7 @@ void SPTexture::generateHQMipmap(void* in, >& mms, uint8_t* out) { -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) imMipmapCascade cascade; imReduceOptions options; imReduceSetOptions(&options, @@ -716,7 +716,7 @@ void SPTexture::generateHQMipmap(void* in, void SPTexture::squishCompressImage(uint8_t* rgba, int width, int height, int pitch, void* blocks, unsigned flags) { -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) // This function is copied from CompressImage in libsquish to avoid omp // if enabled by shared libsquish, because we are already using // multiple thread @@ -766,7 +766,7 @@ std::vector > { std::vector > mipmap_sizes; -#if !(defined(SERVER_ONLY) || defined(ANDROID)) +#if !(defined(SERVER_ONLY) || defined(MOBILE_STK)) unsigned width = image->getDimension().Width; unsigned height = image->getDimension().Height; mipmap_sizes.emplace_back(core::dimension2du(width, height), 0); diff --git a/src/main.cpp b/src/main.cpp index 5ecc17a81..b77b14e8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2093,18 +2093,21 @@ int main(int argc, char *argv[]) Log::warn("main", "Screen size is too small!"); } - #ifdef ANDROID + #ifdef MOBILE_STK if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_UNDEFINED) { + #ifdef ANDROID int32_t touch = AConfiguration_getTouchscreen( global_android_app->config); - if (touch != ACONFIGURATION_TOUCHSCREEN_NOTOUCH) { + #endif InitAndroidDialog* init_android = new InitAndroidDialog( 0.6f, 0.6f); GUIEngine::DialogQueue::get()->pushDialog(init_android); + #ifdef ANDROID } + #endif } #endif @@ -2123,7 +2126,7 @@ int main(int argc, char *argv[]) } else if (!CVS->isGLSL()) { - #if !defined(ANDROID) + #if !defined(MOBILE_STK) if (UserConfigParams::m_old_driver_popup) { #ifdef USE_GLES2 diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index 3f8363670..890bc7642 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -255,8 +255,8 @@ void OverWorld::onFirePressed(Controller* who) } const unsigned int val = challenge->getNumTrophies(); -// Android may have less challenges available than the main version -#ifdef ANDROID +// Mobile STK may have less challenges available than the main version +#ifdef MOBILE_STK bool enough_challenges = true; #else const unsigned int val2 = challenge->getNumChallenges(); diff --git a/src/modes/world_status.cpp b/src/modes/world_status.cpp index b353ceb7c..56249cb67 100644 --- a/src/modes/world_status.cpp +++ b/src/modes/world_status.cpp @@ -274,7 +274,7 @@ void WorldStatus::updateTime(int ticks) auto cl = LobbyProtocol::get(); assert(cl); cl->finishedLoadingWorld(); -#ifndef ANDROID +#ifndef MOBILE_STK static bool helper_msg_shown = false; if (!helper_msg_shown && cl->isSpectator()) { diff --git a/src/scriptengine/script_challenges.cpp b/src/scriptengine/script_challenges.cpp index dfa2aeee7..0e683e2d4 100644 --- a/src/scriptengine/script_challenges.cpp +++ b/src/scriptengine/script_challenges.cpp @@ -101,7 +101,7 @@ namespace Scripting const unsigned int val = challenge->getNumTrophies(); // Android may have less challenges available than the main version -#ifdef ANDROID +#ifdef MOBILE_STK bool enough_challenges = true; #else const unsigned int val2 = challenge->getNumChallenges(); diff --git a/src/states_screens/dialogs/init_android_dialog.cpp b/src/states_screens/dialogs/init_android_dialog.cpp index a93ff12e8..175627cad 100644 --- a/src/states_screens/dialogs/init_android_dialog.cpp +++ b/src/states_screens/dialogs/init_android_dialog.cpp @@ -27,10 +27,6 @@ #include "input/multitouch_device.hpp" #include "utils/translation.hpp" -#ifdef ANDROID -#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h" -#endif - #include @@ -66,13 +62,9 @@ void InitAndroidDialog::beforeAddingWidgets() bool accelerometer_available = false; bool gyroscope_available = false; -#ifdef ANDROID - CIrrDeviceAndroid* android_device = dynamic_cast( - irr_driver->getDevice()); - assert(android_device != NULL); - accelerometer_available = android_device->isAccelerometerAvailable(); - gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available; -#endif + IrrlichtDevice* irrlicht_device = irr_driver->getDevice(); + accelerometer_available = irrlicht_device->isAccelerometerAvailable(); + gyroscope_available = irrlicht_device->isGyroscopeAvailable() && accelerometer_available; if (!accelerometer_available) { diff --git a/src/states_screens/dialogs/race_paused_dialog.cpp b/src/states_screens/dialogs/race_paused_dialog.cpp index ad2d2e9ee..c0f3add17 100644 --- a/src/states_screens/dialogs/race_paused_dialog.cpp +++ b/src/states_screens/dialogs/race_paused_dialog.cpp @@ -110,7 +110,7 @@ RacePausedDialog::RacePausedDialog(const float percentWidth, World::getWorld()->schedulePause(WorldStatus::IN_GAME_MENU_PHASE); } -#ifndef ANDROID +#ifndef MOBILE_STK if (m_text_box && UserConfigParams::m_lobby_chat) m_text_box->setFocusForPlayer(PLAYER_ID_GAME_MASTER); #endif diff --git a/src/states_screens/options/options_screen_video.cpp b/src/states_screens/options/options_screen_video.cpp index a3880059f..30998ce16 100644 --- a/src/states_screens/options/options_screen_video.cpp +++ b/src/states_screens/options/options_screen_video.cpp @@ -272,7 +272,7 @@ void OptionsScreenVideo::init() } } // next found resolution -#ifndef ANDROID +#ifndef MOBILE_STK // Add default resolutions that were not found by irrlicht if (!found_1024_768) { @@ -356,7 +356,7 @@ void OptionsScreenVideo::init() gfx->setActive(!in_game); getWidget("custom")->setActive(!in_game); -#if defined(ANDROID) +#if defined(MOBILE_STK) applyBtn->setVisible(false); full->setVisible(false); getWidget("fullscreenText")->setVisible(false); diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index 1d8de8f3a..087f5f36a 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -881,7 +881,7 @@ bool onEvent(const SEvent &event) return true; // Create the menu (only one menu at a time) - #ifdef ANDROID + #ifdef MOBILE_STK if (event.MouseInput.X < 30 && event.MouseInput.Y < 30 && #else if (event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN &&