From 42d9e8967f185994fee3a5011e1ffeaa40214b47 Mon Sep 17 00:00:00 2001 From: Benau <Benau@users.noreply.github.com> Date: Fri, 18 Oct 2019 22:22:32 +0800 Subject: [PATCH] Add default config for iOS devices --- lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm | 8 ++ src/main_android.cpp | 77 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm index c73ecd66e..fdf630ffb 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceiOS.mm @@ -15,6 +15,9 @@ #import <CoreMotion/CoreMotion.h> #import <GLKit/GLKView.h> +#import <sys/utsname.h> + +extern void getConfigForDevice(const char* dev); /* Important information */ @@ -187,6 +190,11 @@ namespace irr name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]]; override_default_params_for_mobile(); + struct utsname system_info; + uname(&system_info); + NSString* model = [NSString stringWithCString:system_info.machine + encoding:NSUTF8StringEncoding]; + getConfigForDevice([model UTF8String]); ios_main(0, {}); // App store may not like this exit(0); diff --git a/src/main_android.cpp b/src/main_android.cpp index 4ea72b369..6db71dd8a 100644 --- a/src/main_android.cpp +++ b/src/main_android.cpp @@ -20,6 +20,7 @@ #include "config/user_config.hpp" #include "graphics/irr_driver.hpp" #include "utils/log.hpp" +#include "utils/string_utils.hpp" #ifdef ANDROID #include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h" @@ -102,6 +103,82 @@ void override_default_params_for_mobile() UserConfigParams::m_enforce_current_player = true; } +#ifdef IOS_STK +void getConfigForDevice(const char* dev) +{ + // Check browser.geekbench.com/ios-benchmarks metal benchmark + // https://gist.github.com/adamawolf/3048717 for device name mapping + std::string device = dev; + if (device.find("iPhone") != std::string::npos) + { + // Normal configuration default + UserConfigParams::m_multitouch_scale = 1.3f; + UserConfigParams::m_multitouch_sensitivity_x = 0.1f; + UserConfigParams::m_font_size = 5.0f; + device.erase(0, 6); + auto versions = StringUtils::splitToUInt(device, ','); + if (versions.size() == 2) + { + // A9 GPU + if (versions[0] >= 8) + { + UserConfigParams::m_dynamic_lights = true; + UserConfigParams::m_high_definition_textures = 1; + } + if (versions[0] < 7 || // iPhone 5s + (versions[0] == 7 && versions[1] == 2) || // iPhone 6 + (versions[0] == 8 && versions[1] == 1) || // iPhone 6S + (versions[0] == 8 && versions[1] == 4) || // iPhone SE + (versions[0] == 9 && versions[1] == 1) || // iPhone 7 + (versions[0] == 9 && versions[1] == 3) || // iPhone 7 + (versions[0] == 10 && versions[1] == 1) || // iPhone 8 + (versions[0] == 10 && versions[1] == 4) // iPhone 8 + ) + { + // Those phones have small screen + UserConfigParams::m_multitouch_scale = 1.45f; + } + } + } + else if (device.find("iPad") != std::string::npos) + { + // Normal configuration default + UserConfigParams::m_multitouch_scale = 1.1f; + UserConfigParams::m_multitouch_sensitivity_x = 0.2f; + UserConfigParams::m_font_size = 4.0f; + device.erase(0, 4); + auto versions = StringUtils::splitToUInt(device, ','); + if (versions.size() == 2) + { + if (versions[0] >= 7) + { + UserConfigParams::m_dynamic_lights = true; + UserConfigParams::m_high_definition_textures = 1; + } + } + } + else if (device.find("iPod") != std::string::npos) + { + // All iPod touch has small screen + UserConfigParams::m_font_size = 5.0f; + UserConfigParams::m_multitouch_scale = 1.45f; + UserConfigParams::m_multitouch_sensitivity_x = 0.1f; + device.erase(0, 4); + auto versions = StringUtils::splitToUInt(device, ','); + if (versions.size() == 2) + { + // iPod Touch 7th Generation (A10) + if (versions[0] >= 9) + { + UserConfigParams::m_dynamic_lights = true; + UserConfigParams::m_high_definition_textures = 1; + } + } + } +} + +#endif + #ifdef ANDROID void android_main(struct android_app* app) {