diff --git a/core/platform/CMakeLists.txt b/core/platform/CMakeLists.txt index 1b5be5139796..2b3a767ef9d0 100644 --- a/core/platform/CMakeLists.txt +++ b/core/platform/CMakeLists.txt @@ -86,6 +86,8 @@ elseif(APPLE) platform/ios/RenderViewImpl-ios.h platform/ios/StdC-ios.h platform/ios/InputView-ios.h + platform/ios/AxmolAppController.h + platform/ios/AxmolViewController.h ) set(_AX_PLATFORM_SPECIFIC_SRC ${_AX_PLATFORM_SPECIFIC_SRC} @@ -97,6 +99,8 @@ elseif(APPLE) platform/ios/RenderViewImpl-ios.mm platform/ios/Image-ios.mm platform/ios/InputView-ios.mm + platform/ios/AxmolAppController.mm + platform/ios/AxmolViewController.mm ) if(AX_USE_GL) @@ -162,6 +166,11 @@ elseif(EMSCRIPTEN) endif() endif() +# Add desktop-specific sources for platforms where GLFW is available +if((WIN32 AND NOT WINRT) OR LINUX OR MACOSX OR WASM) + list(APPEND _AX_PLATFORM_SPECIFIC_SRC "platform/desktop/Device-desktop.cpp") +endif() + set(_AX_PLATFORM_HEADER ${_AX_PLATFORM_SPECIFIC_HEADER} platform/Application.h diff --git a/core/platform/Device.h b/core/platform/Device.h index 0a7a150f217c..b6d1c43691f4 100644 --- a/core/platform/Device.h +++ b/core/platform/Device.h @@ -165,11 +165,112 @@ class AX_DLL Device int& height, bool& hasPremultipliedAlpha); +#pragma region Orientation control support + enum class Orientation + { + Unknown, + Portrait, // Portrait (upright) + ReversePortrait, // Portrait upside down + SensorPortrait, // Portrait + reverse portrait (auto-rotate with sensor) + + Landscape, // Landscape (left) + ReverseLandscape, // Landscape (right) + SensorLandscape, // Landscape + reverse landscape (auto-rotate with sensor) + + Sensor, // All orientations except upside down (auto-rotate with sensor) + FullSensor // All orientations including upside down (auto-rotate with sensor) + }; + + enum class OrientationMask + { + Portrait = 1 << 0, + ReversePortrait = 1 << 1, // Portrait upside down + Landscape = 1 << 2, // Landscape (left) + ReverseLandscape = 1 << 3, // Landscape (right) + All = Portrait | ReversePortrait | Landscape | ReverseLandscape + }; + + /** + * @brief Sets the preferred screen orientation for the application. + * + * This method attempts to switch the screen orientation to the specified value. + * If the orientation is supported by the platform (as declared in Info.plist or AndroidManifest), + * the system will rotate and lock to that orientation. + * Use Orientation::Auto to unlock and allow automatic rotation. + * + * @param orientation The desired screen orientation. Use Orientation::Auto to reset. + * @since axmol-2.9.0 + */ + static void setPreferredOrientation(Orientation orientation); + + /** + * @brief Gets the currently preferred (locked) screen orientation. + * + * Returns the orientation that was last set via setPreferredOrientation(). + * If Orientation::Auto is returned, the application is currently allowing automatic rotation. + * + * @return The current preferred orientation. + * @since axmol-2.9.0 + */ + static Orientation getPreferredOrientation(); + + /** + * @brief Gets the set of orientations supported by the platform. + * + * This reflects the maximum orientation capabilities declared in Info.plist (iOS) + * or AndroidManifest.xml (Android). The application can only rotate within this set. + * + * @return A bitmask representing supported orientations. + * @since axmol-2.9.0 + */ + static OrientationMask getSupportedOrientations(); + + /** + * @brief Gets the current screen orientation as rendered by the system. + * + * This reflects the actual orientation currently applied to the screen, + * which may differ from the preferred orientation if Orientation::Sensor is set. + * + * @return The current screen orientation. + * @since axmol-2.9.0 + */ + static Orientation getCurrentOrientation(); + + /** + * @brief Returns the device's physical orientation (hardware posture). + * + * Unlike getCurrentOrientation(), which reflects the UI's current interface + * orientation, this method reports the device's actual physical posture as + * detected by sensors (e.g., accelerometer). It may differ from the UI + * orientation when rotation is locked or when the app restricts supported + * orientations. + * + * Platform notes: + * - iOS: Maps from UIDeviceOrientation. FaceUp/FaceDown are treated as Unknown. + * You should ensure orientation notifications are active internally + * (beginGeneratingDeviceOrientationNotifications) if needed. + * - Android: Maps from display rotation and/or sensor readings to the closest + * Orientation value. Sensor-based "flat" states map to Unknown. + * + * Typical usage: + * - Use getCurrentOrientation() for layout, rendering, and UI decisions. + * - Use getPhysicalOrientation() for gameplay/input mechanics that depend on + * how the user is holding the device, independent of UI rotation. + * + * @return Orientation The device's physical orientation. + * @since axmol-2.9.0 + */ + static Orientation getPhysicalOrientation(); + +#pragma endregion Orientation control support + private: AX_DISALLOW_IMPLICIT_CONSTRUCTORS(Device); }; +AX_ENABLE_BITMASK_OPS(Device::OrientationMask) + // end group /// @} -} +} // namespace ax diff --git a/core/platform/android/Device-android.cpp b/core/platform/android/Device-android.cpp index 49bd6f787a30..958cc8c9041a 100644 --- a/core/platform/android/Device-android.cpp +++ b/core/platform/android/Device-android.cpp @@ -212,6 +212,37 @@ void Device::selectionChanged() JniHelper::callStaticVoidMethod(deviceHelperClassName, "selectionChanged"); } +static Device::Orientation s_preferredOrientation = Device::Orientation::Sensor; + +void Device::setPreferredOrientation(Device::Orientation orientation) +{ + s_preferredOrientation = orientation; + JniHelper::callStaticVoidMethod(deviceHelperClassName, "setPreferredOrientation", static_cast(orientation)); +} + +Device::Orientation Device::getPreferredOrientation() +{ + return s_preferredOrientation; +} + +Device::OrientationMask Device::getSupportedOrientations() +{ + jint mask = JniHelper::callStaticIntMethod(deviceHelperClassName, "getSupportedOrientations"); + return static_cast(mask); +} + +Device::Orientation Device::getCurrentOrientation() +{ + jint orientation = JniHelper::callStaticIntMethod(deviceHelperClassName, "getCurrentOrientation"); + return static_cast(orientation); +} + +Device::Orientation Device::getPhysicalOrientation() +{ + jint orientation = JniHelper::callStaticIntMethod(deviceHelperClassName, "getPhysicalOrientation"); + return static_cast(orientation); +} + } // this method is called by BitmapHelper diff --git a/core/platform/android/java/src/dev/axmol/lib/AxmolAccelerometer.java b/core/platform/android/java/src/dev/axmol/lib/AxmolAccelerometer.java index cc294cb33589..4002fe4c516e 100644 --- a/core/platform/android/java/src/dev/axmol/lib/AxmolAccelerometer.java +++ b/core/platform/android/java/src/dev/axmol/lib/AxmolAccelerometer.java @@ -82,13 +82,8 @@ public void enableAccel() { } public void setInterval(float interval) { - // Honeycomb version is 11 - if(android.os.Build.VERSION.SDK_INT < 11) { - this.mSensorManager.registerListener(this, this.mAccelerometer, SensorManager.SENSOR_DELAY_GAME); - } else { - //convert seconds to microseconds - this.mSensorManager.registerListener(this, this.mAccelerometer, (int)(interval*1000000)); - } + //convert seconds to microseconds + this.mSensorManager.registerListener(this, this.mAccelerometer, (int)(interval*1000000)); } public void disable() { diff --git a/core/platform/android/java/src/dev/axmol/lib/AxmolEngine.java b/core/platform/android/java/src/dev/axmol/lib/AxmolEngine.java index 3a47213ca26b..f470d9df069b 100644 --- a/core/platform/android/java/src/dev/axmol/lib/AxmolEngine.java +++ b/core/platform/android/java/src/dev/axmol/lib/AxmolEngine.java @@ -27,8 +27,13 @@ of this software and associated documentation files (the "Software"), to deal package dev.axmol.lib; import android.annotation.SuppressLint; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.graphics.Rect; +import android.hardware.Sensor; +import android.hardware.SensorEvent; +import android.hardware.SensorEventListener; +import android.hardware.SensorManager; import android.media.AudioManager; import android.app.Activity; import android.content.ComponentName; @@ -53,6 +58,7 @@ of this software and associated documentation files (the "Software"), to deal import android.view.DisplayCutout; import android.view.KeyCharacterMap; import android.view.KeyEvent; +import android.view.Surface; import android.view.View; import android.view.ViewConfiguration; import android.view.Window; @@ -76,6 +82,8 @@ of this software and associated documentation files (the "Software"), to deal import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; public class AxmolEngine { @@ -773,4 +781,212 @@ public static String[] getAssetsList(String path) { } return null; } + + // ===== Orientation constants (must match C++ enum values) ===== + public static final int ORIENTATION_UNKNOWN = 0; + public static final int ORIENTATION_PORTRAIT = 1; // Portrait (upright) + public static final int ORIENTATION_REVERSE_PORTRAIT = 2; // Portrait upside down + public static final int ORIENTATION_SENSOR_PORTRAIT = 3; // Portrait + reverse portrait (auto-rotate) + + public static final int ORIENTATION_LANDSCAPE = 4; // Landscape (left) + public static final int ORIENTATION_REVERSE_LANDSCAPE = 5; // Landscape (right) + public static final int ORIENTATION_SENSOR_LANDSCAPE = 6; // Landscape + reverse landscape (auto-rotate) + + public static final int ORIENTATION_SENSOR = 7; // All except upside down (auto-rotate) + public static final int ORIENTATION_FULL_SENSOR = 8; // All including upside down (auto-rotate) + + // ===== OrientationMask constants (must match C++ enum values) ===== + public static final int ORIENTATION_MASK_PORTRAIT = 1; + public static final int ORIENTATION_MASK_REVERSE_PORTRAIT = 1 << 1; + public static final int ORIENTATION_MASK_LANDSCAPE = 1 << 2; + public static final int ORIENTATION_MASK_REVERSE_LANDSCAPE= 1 << 3; + public static final int ORIENTATION_MASK_ALL = ORIENTATION_MASK_PORTRAIT | + ORIENTATION_MASK_REVERSE_PORTRAIT | + ORIENTATION_MASK_LANDSCAPE | + ORIENTATION_MASK_REVERSE_LANDSCAPE; + + // Cached supported orientation mask, -1 means uninitialized + private static int sSupportedOrientationMask = -1; + + /** + * Sets the preferred screen orientation for the current activity. + * @param orientation One of the ORIENTATION_* constants. + */ + @SuppressWarnings("unused") + public static void setPreferredOrientation(int orientation) { + if (sActivity == null) return; + + int androidOrientation; + switch (orientation) { + case ORIENTATION_PORTRAIT: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + break; + case ORIENTATION_REVERSE_PORTRAIT: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; + break; + case ORIENTATION_SENSOR_PORTRAIT: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; + break; + case ORIENTATION_LANDSCAPE: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + break; + case ORIENTATION_REVERSE_LANDSCAPE: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; + break; + case ORIENTATION_SENSOR_LANDSCAPE: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; + break; + case ORIENTATION_SENSOR: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR; + break; + case ORIENTATION_FULL_SENSOR: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR; + break; + default: + androidOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; + break; + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + sActivity.setRequestedOrientation(androidOrientation); + } + }); + } + + /** + * Returns the supported orientation mask for the device. + * This example assumes all orientations are supported. + * @return Bitmask of ORIENTATION_MASK_* constants. + */ + @SuppressWarnings("unused") + public static int getSupportedOrientations() { + // Return cached value if already initialized + if (sSupportedOrientationMask != -1) { + return sSupportedOrientationMask; + } + + if (sActivity == null) { + sSupportedOrientationMask = ORIENTATION_MASK_ALL; // fallback + return sSupportedOrientationMask; + } + + try { + PackageManager pm = sActivity.getPackageManager(); + ActivityInfo info = pm.getActivityInfo( + sActivity.getComponentName(), + PackageManager.GET_META_DATA + ); + + switch (info.screenOrientation) { + case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: + sSupportedOrientationMask = ORIENTATION_MASK_PORTRAIT; + break; + case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: + sSupportedOrientationMask = ORIENTATION_MASK_REVERSE_PORTRAIT; + break; + case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: + sSupportedOrientationMask = ORIENTATION_MASK_PORTRAIT | ORIENTATION_MASK_REVERSE_PORTRAIT; + break; + case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: + sSupportedOrientationMask = ORIENTATION_MASK_LANDSCAPE; + break; + case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: + sSupportedOrientationMask = ORIENTATION_MASK_REVERSE_LANDSCAPE; + break; + case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: + sSupportedOrientationMask = ORIENTATION_MASK_LANDSCAPE | ORIENTATION_MASK_REVERSE_LANDSCAPE; + break; + case ActivityInfo.SCREEN_ORIENTATION_SENSOR: + sSupportedOrientationMask = ORIENTATION_MASK_PORTRAIT | ORIENTATION_MASK_LANDSCAPE; + break; + default: + sSupportedOrientationMask = ORIENTATION_MASK_ALL; + break; + } + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + sSupportedOrientationMask = ORIENTATION_MASK_ALL; + } + + return sSupportedOrientationMask; + } + + /** + * Returns the current orientation of the device. + * @return One of the ORIENTATION_* constants. + */ + @SuppressWarnings("unused") + public static int getCurrentOrientation() { + int rotation = sActivity.getWindowManager().getDefaultDisplay().getRotation(); + switch (rotation) { + case Surface.ROTATION_0: + return ORIENTATION_PORTRAIT; + case Surface.ROTATION_90: + return ORIENTATION_LANDSCAPE; + case Surface.ROTATION_180: + return ORIENTATION_REVERSE_PORTRAIT; + case Surface.ROTATION_270: + return ORIENTATION_REVERSE_LANDSCAPE; + default: + return ORIENTATION_UNKNOWN; + } + } + + @SuppressWarnings("unused") + public static int getPhysicalOrientation() { + SensorManager sm = (SensorManager) sActivity.getSystemService(Context.SENSOR_SERVICE); + Sensor rotationVector = sm.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); + if (rotationVector == null) { + return 0; + } + + final CountDownLatch latch = new CountDownLatch(1); + final int[] result = new int[1]; + SensorEventListener listener = new SensorEventListener() { + @Override + public void onSensorChanged(SensorEvent event) { + float[] rotationMatrix = new float[9]; + float[] orientationVals = new float[3]; + SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values); + SensorManager.getOrientation(rotationMatrix, orientationVals); + + float pitch = orientationVals[1]; + float roll = orientationVals[2]; + + if (Math.abs(roll) > Math.PI/4) { + // landscape + if (roll > 0) { + result[0] = ORIENTATION_LANDSCAPE; + } else { + result[0] = ORIENTATION_REVERSE_LANDSCAPE; + } + } else { + // portrait + if (pitch > 0) { + result[0] = ORIENTATION_REVERSE_PORTRAIT; + } else { + result[0] = ORIENTATION_PORTRAIT; + } + } + + sm.unregisterListener(this); + latch.countDown(); + } + + @Override + public void onAccuracyChanged(Sensor sensor, int accuracy) {} + }; + + sm.registerListener(listener, rotationVector, SensorManager.SENSOR_DELAY_UI); + + try { + latch.await(500, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + + return result[0]; + } } diff --git a/core/platform/android/javaactivity-android.cpp b/core/platform/android/javaactivity-android.cpp index e34f4e9c078e..25f6d552bf8f 100644 --- a/core/platform/android/javaactivity-android.cpp +++ b/core/platform/android/javaactivity-android.cpp @@ -148,6 +148,15 @@ JNIEXPORT jintArray JNICALL Java_dev_axmol_lib_AxmolActivity_getGLContextAttrs(J JNIEXPORT void JNICALL Java_dev_axmol_lib_AxmolRenderer_nativeOnSurfaceChanged(JNIEnv*, jclass, jint w, jint h) { + auto director = ax::Director::getInstance(); + auto renderView = director->getRenderView(); + if (renderView) + { + renderView->setFrameSize(w, h); + auto designSize = renderView->getDesignResolutionSize(); + auto resolutionPolicy = renderView->getResolutionPolicy(); + renderView->setDesignResolutionSize(designSize.width, designSize.height, resolutionPolicy); + } ax::Application::getInstance()->applicationScreenSizeChanged(w, h); } } diff --git a/core/platform/desktop/Device-desktop.cpp b/core/platform/desktop/Device-desktop.cpp new file mode 100644 index 000000000000..cddd9db26720 --- /dev/null +++ b/core/platform/desktop/Device-desktop.cpp @@ -0,0 +1,53 @@ + +/**************************************************************************** +Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + +https://axmol.dev/ + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ \ +#include "platform/Device.h" +#include "GLFW/glfw3.h" + +namespace ax +{ + +void Device::setPreferredOrientation(Device::Orientation /*orientation*/) {} + +Device::Orientation Device::getPreferredOrientation() +{ + return Orientation::Unknown; +} + +Device::OrientationMask Device::getSupportedOrientations() +{ + return OrientationMask::All; +} + +Device::Orientation Device::getCurrentOrientation() +{ + return Orientation::Unknown; +} + +Device::Orientation Device::getPhysicalOrientation() +{ + return Orientation::Unknown; +} + +} // namespace ax diff --git a/core/platform/ios/Application-ios.mm b/core/platform/ios/Application-ios.mm index 44ce7cdd4cfd..ba94c5fdb85c 100644 --- a/core/platform/ios/Application-ios.mm +++ b/core/platform/ios/Application-ios.mm @@ -31,11 +31,18 @@ of this software and associated documentation files (the "Software"), to deal #import "platform/ios/DirectorCaller-ios.h" #import "base/Utils.h" +#include "AxmolAppController.h" + namespace ax { Application* Application::sm_pSharedApplication = nullptr; +// Force the Objective‑C runtime to reference AxmolAppController, +// ensuring the class symbol is linked into the final binary +// (prevents the linker from stripping it out when inside a static library). +__attribute__((unused)) static Class kForceLink_AxmolAppController = [AxmolAppController class]; + Application::Application() { AX_ASSERT(!sm_pSharedApplication); diff --git a/tests/fairygui-tests/proj.ios/RootViewController.h b/core/platform/ios/AxmolAppController.h similarity index 84% rename from tests/fairygui-tests/proj.ios/RootViewController.h rename to core/platform/ios/AxmolAppController.h index df5f05405a18..8bfd005340a1 100644 --- a/tests/fairygui-tests/proj.ios/RootViewController.h +++ b/core/platform/ios/AxmolAppController.h @@ -1,20 +1,18 @@ /**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + https://axmol.dev/ - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,12 +21,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#pragma once #import +@interface AxmolAppController : NSObject { +} -@interface RootViewController : UIViewController { +@property(nonatomic, readonly) UIViewController* viewController; -} -- (BOOL)prefersStatusBarHidden; @end diff --git a/templates/common/proj.ios_mac/ios/AppController.mm b/core/platform/ios/AxmolAppController.mm similarity index 86% rename from templates/common/proj.ios_mac/ios/AppController.mm rename to core/platform/ios/AxmolAppController.mm index c38fa83b085b..6a74f56dbd69 100644 --- a/templates/common/proj.ios_mac/ios/AppController.mm +++ b/core/platform/ios/AxmolAppController.mm @@ -1,7 +1,4 @@ /**************************************************************************** - Copyright (c) 2010-2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -25,42 +22,47 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "AppController.h" -#import "axmol.h" -#import "AppDelegate.h" -#import "RootViewController.h" +#import "AxmolAppController.h" +#import "AxmolViewController.h" -@implementation AppController +#include "base/Director.h" +#include "platform/Application.h" +#include "platform/ios/RenderViewImpl-ios.h" + +using namespace ax; + +@implementation AxmolAppController #pragma mark - #pragma mark Application lifecycle // axmol application instance -static AppDelegate s_sharedApplication; +// static AppDelegate s_sharedApplication; + +- (UIViewController*)createRootViewController { + return [[AxmolViewController alloc] initWithNibName:nil bundle:nil]; +} - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - ax::Application* app = ax::Application::getInstance(); + auto axmolApp = Application::getInstance(); // Initialize the RenderView attributes - app->initGfxContextAttrs(); + axmolApp->initGfxContextAttrs(); // Override point for customization after application launch. auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - - // uncumment if you want disable multiple touches - // renderView->setMultipleTouchEnabled(false); + _viewController = [self createRootViewController]; renderView->showWindow(_viewController); // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); + Director::getInstance()->setRenderView(renderView); // run the axmol game scene - app->run(); + axmolApp->run(); return YES; } diff --git a/tests/lua-tests/proj.ios_mac/ios/RootViewController.h b/core/platform/ios/AxmolViewController.h similarity index 87% rename from tests/lua-tests/proj.ios_mac/ios/RootViewController.h rename to core/platform/ios/AxmolViewController.h index 661d0edf3604..0c1a096627e0 100644 --- a/tests/lua-tests/proj.ios_mac/ios/RootViewController.h +++ b/core/platform/ios/AxmolViewController.h @@ -1,7 +1,5 @@ /**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -23,10 +21,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ +#pragma once #import -@interface RootViewController : UIViewController { +@interface AxmolViewController : UIViewController { } - (BOOL)prefersStatusBarHidden; + @end diff --git a/templates/common/proj.ios_mac/ios/RootViewController.mm b/core/platform/ios/AxmolViewController.mm similarity index 72% rename from templates/common/proj.ios_mac/ios/RootViewController.mm rename to core/platform/ios/AxmolViewController.mm index b8417db20fba..42dbfa0ba93b 100644 --- a/templates/common/proj.ios_mac/ios/RootViewController.mm +++ b/core/platform/ios/AxmolViewController.mm @@ -1,7 +1,4 @@ /**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -25,11 +22,15 @@ of this software and associated documentation files (the "Software"), to deal THE SOFTWARE. ****************************************************************************/ -#import "RootViewController.h" -#import "axmol.h" +#import "AxmolViewController.h" #import "platform/ios/EARenderView-ios.h" +#include "platform/Device.h" +#include "platform/Application.h" +#include "base/Director.h" -@implementation RootViewController +using namespace ax; + +@implementation AxmolViewController /* // The designated initializer. Override if you create the controller programmatically and want to perform @@ -63,13 +64,32 @@ - (void)viewDidDisappear:(BOOL)animated [super viewDidDisappear:animated]; } -// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead -#ifdef __IPHONE_6_0 - (NSUInteger)supportedInterfaceOrientations { - return UIInterfaceOrientationMaskAllButUpsideDown; + const auto preferred = Device::getPreferredOrientation(); + + switch (preferred) { + case Device::Orientation::Portrait: + return UIInterfaceOrientationMaskPortrait; + case Device::Orientation::ReversePortrait: + return UIInterfaceOrientationMaskPortraitUpsideDown; + case Device::Orientation::Landscape: + return UIInterfaceOrientationMaskLandscapeLeft; + case Device::Orientation::ReverseLandscape: + return UIInterfaceOrientationMaskLandscapeRight; + case Device::Orientation::SensorLandscape: + return UIInterfaceOrientationMaskLandscape; + case Device::Orientation::SensorPortrait: + return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; + case Device::Orientation::Sensor: + return UIInterfaceOrientationMaskAllButUpsideDown; + case Device::Orientation::FullSensor: + return UIInterfaceOrientationMaskAll; + default: + break; + } + return UIInterfaceOrientationUnknown; } -#endif - (BOOL)shouldAutorotate { diff --git a/core/platform/ios/Device-ios.mm b/core/platform/ios/Device-ios.mm index 7c4494242851..6a41809f0f1a 100644 --- a/core/platform/ios/Device-ios.mm +++ b/core/platform/ios/Device-ios.mm @@ -762,4 +762,116 @@ static bool _initWithString(std::string_view text, #endif } +static Device::Orientation _preferredOrientation = Device::Orientation::Sensor; + +void Device::setPreferredOrientation(Device::Orientation orientation) +{ +#if !defined(AX_TARGET_OS_TVOS) + _preferredOrientation = orientation; + + auto renderView = Director::getInstance()->getRenderView(); + if (!renderView) + return; // will take affect when creating renderView + + // Always perform UI work on main thread and obtain window/VC there. + dispatch_async(dispatch_get_main_queue(), ^{ + auto mainWindow = (__bridge UIWindow*) renderView->getEAWindow(); + UIViewController* vc = mainWindow.rootViewController; + + if (@available(iOS 16.0, *)) { + // Modern API: mark for update then attempt rotation + [vc setNeedsUpdateOfSupportedInterfaceOrientations]; + } + else { + // Fallback: present/dismiss minimal full-screen controller to force re-evaluation. + // Present from the top-most VC to avoid container interception. + UIViewController *dummy = [[UIViewController alloc] init]; + dummy.view.backgroundColor = [UIColor clearColor]; + dummy.modalPresentationStyle = UIModalPresentationFullScreen; + + [vc presentViewController:dummy animated:NO completion:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + [dummy dismissViewControllerAnimated:NO completion:^{ + [UIViewController attemptRotationToDeviceOrientation]; + }]; + }); + }]; + } + }); +#endif +} + + +Device::Orientation Device::getPreferredOrientation() +{ + return _preferredOrientation; +} + +Device::OrientationMask Device::getSupportedOrientations() +{ + NSArray *plistOrientations = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UISupportedInterfaceOrientations"]; + OrientationMask mask = static_cast(0); + for (NSString *entry in plistOrientations) { + if ([entry isEqualToString:@"UIInterfaceOrientationPortrait"]) { + mask = static_cast(mask | OrientationMask::Portrait); + } else if ([entry isEqualToString:@"UIInterfaceOrientationPortraitUpsideDown"]) { + mask = static_cast(mask | OrientationMask::ReversePortrait); + } else if ([entry isEqualToString:@"UIInterfaceOrientationLandscapeLeft"]) { + mask = static_cast(mask | OrientationMask::Landscape); + } else if ([entry isEqualToString:@"UIInterfaceOrientationLandscapeRight"]) { + mask = static_cast(mask | OrientationMask::ReverseLandscape); + } + } + + return mask; +} + +Device::Orientation Device::getCurrentOrientation() +{ +#if !defined(AX_TARGET_OS_TVOS) + auto renderView = Director::getInstance()->getRenderView(); + if (!renderView) + return Orientation::Unknown; + auto window = (__bridge UIWindow*) renderView->getEAWindow(); + UIInterfaceOrientation uiOrientation; + if (@available(iOS 13.0, *)) { + uiOrientation = window.windowScene.interfaceOrientation; + } else { + // Fallback on earlier versions + uiOrientation = UIApplication.sharedApplication.statusBarOrientation; + } + switch(uiOrientation) + { + case UIInterfaceOrientationPortrait: + return Orientation::Portrait; + case UIInterfaceOrientationLandscapeLeft: + return Orientation::Landscape; + case UIInterfaceOrientationLandscapeRight: + return Orientation::ReverseLandscape; + case UIInterfaceOrientationPortraitUpsideDown: + return Orientation::ReversePortrait; + default:; + } +#else + return Orientation::Unknown; +#endif +} + +Device::Orientation Device::getPhysicalOrientation() +{ +#if !defined(AX_TARGET_OS_TVOS) + UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; + + switch (deviceOrientation) { + case UIDeviceOrientationPortrait: return Orientation::Portrait; + case UIDeviceOrientationPortraitUpsideDown: return Orientation::ReversePortrait; + case UIDeviceOrientationLandscapeLeft: return Orientation::Landscape; + case UIDeviceOrientationLandscapeRight: return Orientation::ReverseLandscape; + default: return Orientation::Unknown; + } +#else + return Orientation::Unknown; +#endif +} + } diff --git a/core/platform/ios/EARenderView-ios.mm b/core/platform/ios/EARenderView-ios.mm index 18480ad8dff2..1e664310823d 100644 --- a/core/platform/ios/EARenderView-ios.mm +++ b/core/platform/ios/EARenderView-ios.mm @@ -333,6 +333,15 @@ - (void)layoutSubviews size.height = size_.height; // ax::Director::getInstance()->reshapeProjection(size); #endif + + auto renderView = ax::Director::getInstance()->getRenderView(); + if (renderView) + { + auto&& designSize = renderView->getDesignResolutionSize(); + auto resolutionPolicy = renderView->getResolutionPolicy(); + renderView->setFrameSize(size_.width, size_.height); + renderView->setDesignResolutionSize(designSize.width, designSize.height, resolutionPolicy); + } // Avoid flicker. Issue #350 if ([NSThread isMainThread]) diff --git a/core/platform/winrt/Device-winrt.cpp b/core/platform/winrt/Device-winrt.cpp index 1d8317d8cd54..b899acdaa5cb 100644 --- a/core/platform/winrt/Device-winrt.cpp +++ b/core/platform/winrt/Device-winrt.cpp @@ -575,6 +575,23 @@ void Device::prepareSelectionFeedbackGenerator() {} void Device::selectionChanged() {} +void Device::setPreferredOrientation(Device::Orientation /*orientation*/) {} + +Device::Orientation Device::getPreferredOrientation() +{ + return Orientation::Unknown; +} + +Device::OrientationMask Device::getSupportedOrientations() +{ + return OrientationMask::All; +} + +Device::Orientation Device::getPhysicalOrientation() +{ + return Orientation::Unknown; +} + } #endif // (AX_TARGET_PLATFORM == AX_PLATFORM_WINRT) diff --git a/templates/common/proj.ios_mac/ios/AppController.h b/templates/common/proj.ios_mac/ios/GameAppController.h similarity index 88% rename from templates/common/proj.ios_mac/ios/AppController.h rename to templates/common/proj.ios_mac/ios/GameAppController.h index f2573586aa69..15c099cb3c3d 100644 --- a/templates/common/proj.ios_mac/ios/AppController.h +++ b/templates/common/proj.ios_mac/ios/GameAppController.h @@ -26,13 +26,9 @@ ****************************************************************************/ #pragma once -#import +#import "platform/ios/AxmolAppController.h" -@class RootViewController; - -@interface AppController : NSObject { +@interface GameAppController : AxmolAppController { } -@property(nonatomic, readonly) RootViewController* viewController; - @end diff --git a/templates/common/proj.ios_mac/ios/GameAppController.mm b/templates/common/proj.ios_mac/ios/GameAppController.mm new file mode 100644 index 000000000000..c4a3469ca8b8 --- /dev/null +++ b/templates/common/proj.ios_mac/ios/GameAppController.mm @@ -0,0 +1,41 @@ +/**************************************************************************** + Copyright (c) 2010-2013 cocos2d-x.org + Copyright (c) 2013-2016 Chukong Technologies Inc. + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + + https://axmol.dev/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +#import "GameAppController.h" +#import "GameViewController.h" + +@implementation GameAppController + +#pragma mark - +#pragma mark Application lifecycle + +- createRootViewController { + GameViewController* viewController = [[GameViewController alloc] init]; + return viewController; +} + +@end diff --git a/templates/common/proj.ios_mac/ios/RootViewController.h b/templates/common/proj.ios_mac/ios/GameViewController.h similarity index 93% rename from templates/common/proj.ios_mac/ios/RootViewController.h rename to templates/common/proj.ios_mac/ios/GameViewController.h index 6053ee69edee..cb0c75428f21 100644 --- a/templates/common/proj.ios_mac/ios/RootViewController.h +++ b/templates/common/proj.ios_mac/ios/GameViewController.h @@ -26,10 +26,9 @@ ****************************************************************************/ #pragma once -#import +#import "platform/ios/AxmolViewController.h" -@interface RootViewController : UIViewController { +@interface GameViewController : AxmolViewController { } -- (BOOL)prefersStatusBarHidden; @end diff --git a/tests/unit-tests/proj.ios/Source/testsAppDelegate.h b/templates/common/proj.ios_mac/ios/GameViewController.mm similarity index 87% rename from tests/unit-tests/proj.ios/Source/testsAppDelegate.h rename to templates/common/proj.ios_mac/ios/GameViewController.mm index 8f5d22bab32e..0c60a20d308c 100644 --- a/tests/unit-tests/proj.ios/Source/testsAppDelegate.h +++ b/templates/common/proj.ios_mac/ios/GameViewController.mm @@ -2,6 +2,7 @@ Copyright (c) 2013 cocos2d-x.org Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). https://axmol.dev/ @@ -24,13 +25,10 @@ THE SOFTWARE. ****************************************************************************/ -#import +#import "GameViewController.h" -@class RootViewController; +@implementation GameViewController -@interface AppController : NSObject { - UIWindow* window; - RootViewController* viewController; -} +// Override to allow custom control the app behavior. @end diff --git a/templates/common/proj.ios_mac/ios/main.m b/templates/common/proj.ios_mac/ios/main.m deleted file mode 100644 index 62178533b733..000000000000 --- a/templates/common/proj.ios_mac/ios/main.m +++ /dev/null @@ -1,7 +0,0 @@ -#import - -int main(int argc, char *argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, @"AppController"); - } -} diff --git a/tests/unit-tests/proj.ios/Source/RootViewController.h b/templates/common/proj.ios_mac/ios/main.mm similarity index 81% rename from tests/unit-tests/proj.ios/Source/RootViewController.h rename to templates/common/proj.ios_mac/ios/main.mm index ddd0ca16a494..65e496be8d33 100644 --- a/tests/unit-tests/proj.ios/Source/RootViewController.h +++ b/templates/common/proj.ios_mac/ios/main.mm @@ -1,9 +1,7 @@ /**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - https://axmol.dev/ +https://axmol.dev/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,10 +21,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #import +#include "AppDelegate.h" -@interface RootViewController : UIViewController { +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"GameAppController"); + } } -- (BOOL)prefersStatusBarHidden; -@end diff --git a/templates/cpp/cmake/modules/AXGameSourceSetup.cmake b/templates/cpp/cmake/modules/AXGameSourceSetup.cmake index 77700df00e5a..5a23eea5c2d4 100644 --- a/templates/cpp/cmake/modules/AXGameSourceSetup.cmake +++ b/templates/cpp/cmake/modules/AXGameSourceSetup.cmake @@ -31,8 +31,8 @@ elseif(WINDOWS) elseif(APPLE) if(IOS) list(APPEND GAME_HEADER - proj.ios_mac/ios/AppController.h - proj.ios_mac/ios/RootViewController.h + proj.ios_mac/ios/GameAppController.h + proj.ios_mac/ios/GameViewController.h ) if(TVOS) @@ -50,9 +50,9 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios_mac/ios/main.m - proj.ios_mac/ios/AppController.mm - proj.ios_mac/ios/RootViewController.mm + proj.ios_mac/ios/main.mm + proj.ios_mac/ios/GameAppController.mm + proj.ios_mac/ios/GameViewController.mm proj.ios_mac/ios/Prefix.pch ${APP_UI_RES} ) diff --git a/templates/lua/cmake/modules/AXGameSourceSetup.cmake b/templates/lua/cmake/modules/AXGameSourceSetup.cmake index d321fcdb740e..c585047e4e13 100644 --- a/templates/lua/cmake/modules/AXGameSourceSetup.cmake +++ b/templates/lua/cmake/modules/AXGameSourceSetup.cmake @@ -29,8 +29,8 @@ elseif(WINDOWS) elseif(APPLE) if(IOS) list(APPEND GAME_HEADER - proj.ios_mac/ios/AppController.h - proj.ios_mac/ios/RootViewController.h + proj.ios_mac/ios/GameAppController.h + proj.ios_mac/ios/GameViewController.h ) if(TVOS) @@ -48,9 +48,9 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios_mac/ios/main.m - proj.ios_mac/ios/AppController.mm - proj.ios_mac/ios/RootViewController.mm + proj.ios_mac/ios/main.mm + proj.ios_mac/ios/GameAppController.mm + proj.ios_mac/ios/GameViewController.mm proj.ios_mac/ios/Prefix.pch ${APP_UI_RES} ) diff --git a/tests/cpp-tests/CMakeLists.txt b/tests/cpp-tests/CMakeLists.txt index 6d9dbaabadfe..ed9bc95c4359 100644 --- a/tests/cpp-tests/CMakeLists.txt +++ b/tests/cpp-tests/CMakeLists.txt @@ -76,11 +76,6 @@ elseif(WINDOWS) list(APPEND GAME_SOURCE ${common_content_files}) elseif(APPLE) if(IOS) - list(APPEND GAME_HEADER - proj.ios/Source/testsAppDelegate.h - proj.ios/Source/RootViewController.h - ) - if (TVOS) set(APP_UI_RES proj.ios/LaunchScreenBackground.png @@ -96,9 +91,7 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios/main.m - proj.ios/Source/testsAppDelegate.mm - proj.ios/Source/RootViewController.mm + proj.ios/main.mm proj.ios/Prefix.pch ${APP_UI_RES} ) diff --git a/tests/cpp-tests/Source/AppDelegate.cpp b/tests/cpp-tests/Source/AppDelegate.cpp index 66e496bf7b29..ec2f5984c2ec 100644 --- a/tests/cpp-tests/Source/AppDelegate.cpp +++ b/tests/cpp-tests/Source/AppDelegate.cpp @@ -53,6 +53,8 @@ void AppDelegate::initGfxContextAttrs() GfxContextAttrs gfxContextAttrs = {8, 8, 8, 8, 24, 8, 0}; RenderView::setGfxContextAttrs(gfxContextAttrs); + + Device::setPreferredOrientation(Device::Orientation::SensorLandscape); } bool AppDelegate::applicationDidFinishLaunching() diff --git a/tests/cpp-tests/proj.android/app/AndroidManifest.xml b/tests/cpp-tests/proj.android/app/AndroidManifest.xml index 344e07e6aee1..7dabc42452a9 100644 --- a/tests/cpp-tests/proj.android/app/AndroidManifest.xml +++ b/tests/cpp-tests/proj.android/app/AndroidManifest.xml @@ -18,7 +18,7 @@ initGfxContextAttrs(); - - // Override point for customization after application launch. - - auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - - // Use RootViewController manage EARenderView and UIWindow - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - - renderView->showWindow(viewController); - - // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); - - app->run(); - - return YES; -} - -- (void)applicationWillResignActive:(UIApplication*)application -{ - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of - temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and - it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and - throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ - // We don't need to call this method any more. It will interrupt user defined game pause&resume logic - // ax::Director::getInstance()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication*)application -{ - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was - previously in the background, optionally refresh the user interface. - */ - // We don't need to call this method any more. It will interrupt user defined game pause&resume logic - // ax::Director::getInstance()->resume(); -} - -- (void)applicationDidEnterBackground:(UIApplication*)application -{ - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state - information to restore your application to its current state in case it is terminated later. If your application - supports background execution, called instead of applicationWillTerminate: when the user quits. - */ - ax::Application::getInstance()->applicationDidEnterBackground(); -} - -- (void)applicationWillEnterForeground:(UIApplication*)application -{ - /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made - on entering the background. - */ - ax::Application::getInstance()->applicationWillEnterForeground(); -} - -- (void)applicationWillTerminate:(UIApplication*)application -{ - /* - Called when the application is about to terminate. - See also applicationDidEnterBackground:. - */ -} - -#pragma mark - -#pragma mark Memory management - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application -{ - /* - Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) - later. - */ -} - -- (void)dealloc -{ - [super dealloc]; -} - -@end diff --git a/tests/cpp-tests/proj.ios/main.m b/tests/cpp-tests/proj.ios/main.m deleted file mode 100644 index 59bc34dfe91b..000000000000 --- a/tests/cpp-tests/proj.ios/main.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// main.m -// iphone -// -// Created by Walzer on 10-11-16. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import - - -int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); - [pool release]; - return retVal; -} diff --git a/tests/cpp-tests/proj.ios/Source/RootViewController.h b/tests/cpp-tests/proj.ios/main.mm similarity index 82% rename from tests/cpp-tests/proj.ios/Source/RootViewController.h rename to tests/cpp-tests/proj.ios/main.mm index ddd0ca16a494..281de791415c 100644 --- a/tests/cpp-tests/proj.ios/Source/RootViewController.h +++ b/tests/cpp-tests/proj.ios/main.mm @@ -1,9 +1,8 @@ /**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - https://axmol.dev/ +https://axmol.dev/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,10 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #import +#include "AppDelegate.h" -@interface RootViewController : UIViewController { +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"AxmolAppController"); + } } -- (BOOL)prefersStatusBarHidden; -@end diff --git a/tests/fairygui-tests/CMakeLists.txt b/tests/fairygui-tests/CMakeLists.txt index 4d748f66ac53..6cc2fda04786 100644 --- a/tests/fairygui-tests/CMakeLists.txt +++ b/tests/fairygui-tests/CMakeLists.txt @@ -109,11 +109,6 @@ elseif(WINDOWS) list(APPEND GAME_SOURCE ${common_content_files}) elseif(APPLE) if(IOS) - list(APPEND GAME_HEADER - proj.ios/AppController.h - proj.ios/RootViewController.h - ) - if (TVOS) set(APP_UI_RES proj.ios/LaunchScreenBackground.png @@ -129,9 +124,7 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios/main.m - proj.ios/AppController.mm - proj.ios/RootViewController.mm + proj.ios/main.mm ${APP_UI_RES} ) elseif(MACOSX) diff --git a/tests/fairygui-tests/proj.ios/AppController.h b/tests/fairygui-tests/proj.ios/AppController.h deleted file mode 100644 index cbb7d1790bca..000000000000 --- a/tests/fairygui-tests/proj.ios/AppController.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -@class RootViewController; - -@interface AppController : NSObject { - UIWindow *window; - RootViewController *viewController; -} - -@end - diff --git a/tests/fairygui-tests/proj.ios/AppController.mm b/tests/fairygui-tests/proj.ios/AppController.mm deleted file mode 100644 index 2d860588e30c..000000000000 --- a/tests/fairygui-tests/proj.ios/AppController.mm +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#import -#import "AppController.h" -#import "axmol.h" -#import "AppDelegate.h" -#import "RootViewController.h" - -@implementation AppController - -#pragma mark - -#pragma mark Application lifecycle - -// axmol application instance -static AppDelegate s_sharedApplication; - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - - ax::Application *app = ax::Application::getInstance(); - app->initGfxContextAttrs(); - - // Override point for customization after application launch. - - auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - renderView->showWindow(viewController); - - // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); - - app->run(); - return YES; -} - - -- (void)applicationWillResignActive:(UIApplication *)application { - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ - ax::Director::getInstance()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - */ - ax::Director::getInstance()->resume(); -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - If your application supports background execution, called instead of applicationWillTerminate: when the user quits. - */ - ax::Application::getInstance()->applicationDidEnterBackground(); -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. - */ - ax::Application::getInstance()->applicationWillEnterForeground(); -} - -- (void)applicationWillTerminate:(UIApplication *)application { - /* - Called when the application is about to terminate. - See also applicationDidEnterBackground:. - */ -} - - -#pragma mark - -#pragma mark Memory management - -- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { - /* - Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. - */ -} - - -- (void)dealloc { - [super dealloc]; -} - - -@end - diff --git a/tests/fairygui-tests/proj.ios/RootViewController.mm b/tests/fairygui-tests/proj.ios/RootViewController.mm deleted file mode 100644 index 2a34c8596eff..000000000000 --- a/tests/fairygui-tests/proj.ios/RootViewController.mm +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import "RootViewController.h" - - -@implementation RootViewController - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; -} -*/ - -/* -// Implement loadView to create a view hierarchy programmatically, without using a nib. -- (void)loadView { -} -*/ - -/* -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -- (void)viewDidLoad { - [super viewDidLoad]; -} - -*/ -// Override to allow orientations other than the default portrait orientation. -// This method is deprecated on ios6 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - return UIInterfaceOrientationIsLandscape( interfaceOrientation ); -} - -// For ios6.0 and higher, use supportedInterfaceOrientations & shouldAutorotate instead -- (NSUInteger) supportedInterfaceOrientations -{ -#ifdef __IPHONE_6_0 - return UIInterfaceOrientationMaskAllButUpsideDown; -#endif -} - -- (BOOL) shouldAutorotate { - return YES; -} - -//fix not hide status on ios7 -- (BOOL)prefersStatusBarHidden -{ - return YES; -} - -// Controls the application's preferred home indicator auto-hiding when this view controller is shown. -- (BOOL)prefersHomeIndicatorAutoHidden { - return YES; -} - -- (void)didReceiveMemoryWarning { - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -- (void)viewDidUnload { - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - - -- (void)dealloc { - [super dealloc]; -} - - -@end diff --git a/tests/fairygui-tests/proj.ios/main.m b/tests/fairygui-tests/proj.ios/main.m deleted file mode 100644 index bd577a036ea5..000000000000 --- a/tests/fairygui-tests/proj.ios/main.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// main.m -// iphone -// -// Created by Walzer on 10-11-16. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import - -int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); - [pool release]; - return retVal; -} diff --git a/tests/cpp-tests/proj.ios/Source/testsAppDelegate.h b/tests/fairygui-tests/proj.ios/main.mm similarity index 82% rename from tests/cpp-tests/proj.ios/Source/testsAppDelegate.h rename to tests/fairygui-tests/proj.ios/main.mm index 8f5d22bab32e..281de791415c 100644 --- a/tests/cpp-tests/proj.ios/Source/testsAppDelegate.h +++ b/tests/fairygui-tests/proj.ios/main.mm @@ -1,9 +1,8 @@ /**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). - https://axmol.dev/ +https://axmol.dev/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,14 +22,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ - #import +#include "AppDelegate.h" -@class RootViewController; - -@interface AppController : NSObject { - UIWindow* window; - RootViewController* viewController; +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"AxmolAppController"); + } } - -@end diff --git a/tests/live2d-tests/CMakeLists.txt b/tests/live2d-tests/CMakeLists.txt index 72daaef8cd59..d72318f4dbef 100644 --- a/tests/live2d-tests/CMakeLists.txt +++ b/tests/live2d-tests/CMakeLists.txt @@ -110,11 +110,6 @@ elseif(WINDOWS) list(APPEND GAME_SOURCE ${common_content_files}) elseif(APPLE) if(IOS) - list(APPEND GAME_HEADER - proj.ios/AppController.h - proj.ios/RootViewController.h - ) - if (TVOS) set(APP_UI_RES proj.ios/LaunchScreenBackground.png @@ -130,9 +125,7 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios/main.m - proj.ios/AppController.mm - proj.ios/RootViewController.mm + proj.ios/main.mm ${APP_UI_RES} ) elseif(MACOSX) diff --git a/tests/live2d-tests/proj.ios/AppController.h b/tests/live2d-tests/proj.ios/AppController.h deleted file mode 100644 index cbb7d1790bca..000000000000 --- a/tests/live2d-tests/proj.ios/AppController.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -@class RootViewController; - -@interface AppController : NSObject { - UIWindow *window; - RootViewController *viewController; -} - -@end - diff --git a/tests/live2d-tests/proj.ios/AppController.mm b/tests/live2d-tests/proj.ios/AppController.mm deleted file mode 100644 index 406de6b29b76..000000000000 --- a/tests/live2d-tests/proj.ios/AppController.mm +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#import -#import "AppController.h" -#import "axmol.h" -#import "platform/ios/EARenderView-ios.h" -#import "AppDelegate.h" -#import "RootViewController.h" - -@implementation AppController - -#pragma mark - -#pragma mark Application lifecycle - -// axmol application instance -static AppDelegate s_sharedApplication; - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - - ax::Application *app = ax::Application::getInstance(); - app->initGfxContextAttrs(); - - // Override point for customization after application launch. - - auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - - // Add the view controller's view to the window and display. - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - - renderView->showWindow(viewController); - - // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); - - app->run(); - return YES; -} - - -- (void)applicationWillResignActive:(UIApplication *)application { - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ - ax::Director::getInstance()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - */ - ax::Director::getInstance()->resume(); -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - If your application supports background execution, called instead of applicationWillTerminate: when the user quits. - */ - ax::Application::getInstance()->applicationDidEnterBackground(); -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. - */ - ax::Application::getInstance()->applicationWillEnterForeground(); -} - -- (void)applicationWillTerminate:(UIApplication *)application { - /* - Called when the application is about to terminate. - See also applicationDidEnterBackground:. - */ -} - - -#pragma mark - -#pragma mark Memory management - -- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { - /* - Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. - */ -} - - -- (void)dealloc { - [super dealloc]; -} - - -@end - diff --git a/tests/live2d-tests/proj.ios/RootViewController.h b/tests/live2d-tests/proj.ios/RootViewController.h deleted file mode 100644 index df5f05405a18..000000000000 --- a/tests/live2d-tests/proj.ios/RootViewController.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import - - -@interface RootViewController : UIViewController { - -} -- (BOOL)prefersStatusBarHidden; -@end diff --git a/tests/live2d-tests/proj.ios/RootViewController.mm b/tests/live2d-tests/proj.ios/RootViewController.mm deleted file mode 100644 index 2a34c8596eff..000000000000 --- a/tests/live2d-tests/proj.ios/RootViewController.mm +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import "RootViewController.h" - - -@implementation RootViewController - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; -} -*/ - -/* -// Implement loadView to create a view hierarchy programmatically, without using a nib. -- (void)loadView { -} -*/ - -/* -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -- (void)viewDidLoad { - [super viewDidLoad]; -} - -*/ -// Override to allow orientations other than the default portrait orientation. -// This method is deprecated on ios6 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - return UIInterfaceOrientationIsLandscape( interfaceOrientation ); -} - -// For ios6.0 and higher, use supportedInterfaceOrientations & shouldAutorotate instead -- (NSUInteger) supportedInterfaceOrientations -{ -#ifdef __IPHONE_6_0 - return UIInterfaceOrientationMaskAllButUpsideDown; -#endif -} - -- (BOOL) shouldAutorotate { - return YES; -} - -//fix not hide status on ios7 -- (BOOL)prefersStatusBarHidden -{ - return YES; -} - -// Controls the application's preferred home indicator auto-hiding when this view controller is shown. -- (BOOL)prefersHomeIndicatorAutoHidden { - return YES; -} - -- (void)didReceiveMemoryWarning { - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -- (void)viewDidUnload { - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - - -- (void)dealloc { - [super dealloc]; -} - - -@end diff --git a/tests/live2d-tests/proj.ios/main.m b/tests/live2d-tests/proj.ios/main.m deleted file mode 100644 index bd577a036ea5..000000000000 --- a/tests/live2d-tests/proj.ios/main.m +++ /dev/null @@ -1,17 +0,0 @@ -// -// main.m -// iphone -// -// Created by Walzer on 10-11-16. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import - -int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); - [pool release]; - return retVal; -} diff --git a/tests/live2d-tests/proj.ios/main.mm b/tests/live2d-tests/proj.ios/main.mm new file mode 100644 index 000000000000..281de791415c --- /dev/null +++ b/tests/live2d-tests/proj.ios/main.mm @@ -0,0 +1,33 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + +https://axmol.dev/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#import +#include "AppDelegate.h" + +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"AxmolAppController"); + } +} diff --git a/tests/lua-tests/CMakeLists.txt b/tests/lua-tests/CMakeLists.txt index 70e1953e29c3..700f2df337db 100644 --- a/tests/lua-tests/CMakeLists.txt +++ b/tests/lua-tests/CMakeLists.txt @@ -116,9 +116,7 @@ elseif(WINDOWS) elseif(APPLE) if(IOS) list(APPEND GAME_HEADER - proj.ios_mac/ios/AppController.h proj.ios_mac/ios/LuaObjectCBridgeTest.h - proj.ios_mac/ios/RootViewController.h ) if (TVOS) @@ -136,10 +134,8 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios_mac/ios/main.m + proj.ios_mac/ios/main.mm proj.ios_mac/ios/LuaObjectCBridgeTest.mm - proj.ios_mac/ios/AppController.mm - proj.ios_mac/ios/RootViewController.mm ${APP_UI_RES} ) elseif(MACOSX) diff --git a/tests/lua-tests/proj.ios_mac/ios/AppController.h b/tests/lua-tests/proj.ios_mac/ios/AppController.h deleted file mode 100644 index 4fd5b4e8cf1b..000000000000 --- a/tests/lua-tests/proj.ios_mac/ios/AppController.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -@class RootViewController; - -@interface AppController : NSObject { - UIWindow* window; - RootViewController* viewController; -} - -@end diff --git a/tests/lua-tests/proj.ios_mac/ios/AppController.mm b/tests/lua-tests/proj.ios_mac/ios/AppController.mm deleted file mode 100644 index 1a195743bdf4..000000000000 --- a/tests/lua-tests/proj.ios_mac/ios/AppController.mm +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010 cocos2d-x.org - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ -#import -#import "AppController.h" -#import "axmol.h" -#import "platform/ios/EARenderView-ios.h" -#import "AppDelegate.h" - -#import "RootViewController.h" - -@implementation AppController - -#pragma mark - -#pragma mark Application lifecycle - -// axmol application instance -static AppDelegate s_sharedApplication; - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions -{ - - ax::Application* app = ax::Application::getInstance(); - app->initGfxContextAttrs(); - - // Override point for customization after application launch. - - auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - - // Use RootViewController manage EARenderView - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - renderView->showWindow(viewController); - - // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); - - app->run(); - return YES; -} - -- (void)applicationWillResignActive:(UIApplication*)application -{ - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of - temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and - it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and - throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ - ax::Director::getInstance()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication*)application -{ - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was - previously in the background, optionally refresh the user interface. - */ - ax::Director::getInstance()->resume(); -} - -- (void)applicationDidEnterBackground:(UIApplication*)application -{ - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state - information to restore your application to its current state in case it is terminated later. If your application - supports background execution, called instead of applicationWillTerminate: when the user quits. - */ - ax::Application::getInstance()->applicationDidEnterBackground(); -} - -- (void)applicationWillEnterForeground:(UIApplication*)application -{ - /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made - on entering the background. - */ - ax::Application::getInstance()->applicationWillEnterForeground(); -} - -- (void)applicationWillTerminate:(UIApplication*)application -{ - /* - Called when the application is about to terminate. - See also applicationDidEnterBackground:. - */ -} - -#pragma mark - -#pragma mark Memory management - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application -{ - /* - Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) - later. - */ - ax::Director::getInstance()->purgeCachedData(); -} - -- (void)dealloc -{ - [super dealloc]; -} - -@end diff --git a/tests/lua-tests/proj.ios_mac/ios/RootViewController.mm b/tests/lua-tests/proj.ios_mac/ios/RootViewController.mm deleted file mode 100644 index ec7c259b827c..000000000000 --- a/tests/lua-tests/proj.ios_mac/ios/RootViewController.mm +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - Copyright (c) 2010-2011 cocos2d-x.org - Copyright (c) 2010 Ricardo Quesada - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import "RootViewController.h" - -@implementation RootViewController - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform -customization that is not appropriate for viewDidLoad. -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; -} -*/ - -/* -// Implement loadView to create a view hierarchy programmatically, without using a nib. -- (void)loadView { -} -*/ - -/* -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -- (void)viewDidLoad { - [super viewDidLoad]; -} - -*/ -// Override to allow orientations other than the default portrait orientation. -// This method is deprecated on ios6 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - return UIInterfaceOrientationIsLandscape(interfaceOrientation); -} - -// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead -- (NSUInteger)supportedInterfaceOrientations -{ -#ifdef __IPHONE_6_0 - return UIInterfaceOrientationMaskAllButUpsideDown; -#endif -} - -- (BOOL)shouldAutorotate -{ - return YES; -} - -// fix not hide status on ios7 -- (BOOL)prefersStatusBarHidden -{ - return YES; -} - -// Controls the application's preferred home indicator auto-hiding when this view controller is shown. -- (BOOL)prefersHomeIndicatorAutoHidden -{ - return YES; -} - -- (void)didReceiveMemoryWarning -{ - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - -- (void)dealloc -{ - [super dealloc]; -} - -@end diff --git a/tests/lua-tests/proj.ios_mac/ios/main.m b/tests/lua-tests/proj.ios_mac/ios/main.m deleted file mode 100644 index b657da133484..000000000000 --- a/tests/lua-tests/proj.ios_mac/ios/main.m +++ /dev/null @@ -1,15 +0,0 @@ -// -// main.m -// TestLua -// -// Copyright __MyCompanyName__ 2011. All rights reserved. -// - -#import - -int main(int argc, char *argv[]) { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); - [pool release]; - return retVal; -} diff --git a/tests/lua-tests/proj.ios_mac/ios/main.mm b/tests/lua-tests/proj.ios_mac/ios/main.mm new file mode 100644 index 000000000000..281de791415c --- /dev/null +++ b/tests/lua-tests/proj.ios_mac/ios/main.mm @@ -0,0 +1,33 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + +https://axmol.dev/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#import +#include "AppDelegate.h" + +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"AxmolAppController"); + } +} diff --git a/tests/unit-tests/CMakeLists.txt b/tests/unit-tests/CMakeLists.txt index f7920ef68d62..8029f19801e0 100644 --- a/tests/unit-tests/CMakeLists.txt +++ b/tests/unit-tests/CMakeLists.txt @@ -92,11 +92,6 @@ elseif(WINDOWS) list(APPEND GAME_SOURCE ${common_content_files}) elseif(APPLE) if(IOS) - list(APPEND GAME_HEADER - proj.ios/Source/testsAppDelegate.h - proj.ios/Source/RootViewController.h - ) - if (TVOS) set(APP_UI_RES proj.ios/LaunchScreenBackground.png @@ -112,9 +107,7 @@ elseif(APPLE) endif() list(APPEND GAME_SOURCE - proj.ios/main.m - proj.ios/Source/testsAppDelegate.mm - proj.ios/Source/RootViewController.mm + proj.ios/main.mm proj.ios/Prefix.pch ${APP_UI_RES} ) diff --git a/tests/unit-tests/proj.ios/Source/RootViewController.mm b/tests/unit-tests/proj.ios/Source/RootViewController.mm deleted file mode 100644 index 52b2aa3d5e43..000000000000 --- a/tests/unit-tests/proj.ios/Source/RootViewController.mm +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import "RootViewController.h" - -@implementation RootViewController - -/* - // The designated initializer. Override if you create the controller programmatically and want to perform -customization that is not appropriate for viewDidLoad. -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { - // Custom initialization - } - return self; -} -*/ - -/* -// Implement loadView to create a view hierarchy programmatically, without using a nib. -- (void)loadView { -} -*/ - -/* -// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -- (void)viewDidLoad { - [super viewDidLoad]; -} - -*/ -// Override to allow orientations other than the default portrait orientation. -// This method is deprecated on ios6 -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - return UIInterfaceOrientationIsLandscape(interfaceOrientation); -} - -// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead -- (NSUInteger)supportedInterfaceOrientations -{ -#ifdef __IPHONE_6_0 - return UIInterfaceOrientationMaskAllButUpsideDown; -#endif -} - -- (BOOL)shouldAutorotate -{ - return YES; -} - -// fix not hide status on ios7 -- (BOOL)prefersStatusBarHidden -{ - return YES; -} - -// Controls the application's preferred home indicator auto-hiding when this view controller is shown. -- (BOOL)prefersHomeIndicatorAutoHidden -{ - return YES; -} - -- (void)didReceiveMemoryWarning -{ - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; -} - -- (void)dealloc -{ - [super dealloc]; -} - -@end diff --git a/tests/unit-tests/proj.ios/Source/testsAppDelegate.mm b/tests/unit-tests/proj.ios/Source/testsAppDelegate.mm deleted file mode 100644 index 70b2977edadb..000000000000 --- a/tests/unit-tests/proj.ios/Source/testsAppDelegate.mm +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** - Copyright (c) 2013 cocos2d-x.org - Copyright (c) 2013-2016 Chukong Technologies Inc. - Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. - - https://axmol.dev/ - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - ****************************************************************************/ - -#import "testsAppDelegate.h" - -#import "platform/ios/EARenderView-ios.h" -#import "axmol.h" -#import "AppDelegate.h" -#import "RootViewController.h" - -@implementation AppController - -#pragma mark - -#pragma mark Application lifecycle - -// axmol application instance -static AppDelegate s_sharedApplication; - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions -{ - - ax::Application* app = ax::Application::getInstance(); - app->initGfxContextAttrs(); - - // Override point for customization after application launch. - - auto renderView = ax::RenderViewImpl::createWithFullScreen("axmol2"); - viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; - renderView->showWindow(viewController); - - // IMPORTANT: Setting the RenderView should be done after creating the RootViewController - ax::Director::getInstance()->setRenderView(renderView); - - app->run(); - - return YES; -} - -- (void)applicationWillResignActive:(UIApplication*)application -{ - /* - Sent when the application is about to move from active to inactive state. This can occur for certain types of - temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and - it begins the transition to the background state. Use this method to pause ongoing tasks, disable timers, and - throttle down OpenGL ES frame rates. Games should use this method to pause the game. - */ - // We don't need to call this method any more. It will interrupt user defined game pause&resume logic - // ax::Director::getInstance()->pause(); -} - -- (void)applicationDidBecomeActive:(UIApplication*)application -{ - /* - Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was - previously in the background, optionally refresh the user interface. - */ - // We don't need to call this method any more. It will interrupt user defined game pause&resume logic - // ax::Director::getInstance()->resume(); -} - -- (void)applicationDidEnterBackground:(UIApplication*)application -{ - /* - Use this method to release shared resources, save user data, invalidate timers, and store enough application state - information to restore your application to its current state in case it is terminated later. If your application - supports background execution, called instead of applicationWillTerminate: when the user quits. - */ - ax::Application::getInstance()->applicationDidEnterBackground(); -} - -- (void)applicationWillEnterForeground:(UIApplication*)application -{ - /* - Called as part of transition from the background to the inactive state: here you can undo many of the changes made - on entering the background. - */ - ax::Application::getInstance()->applicationWillEnterForeground(); -} - -- (void)applicationWillTerminate:(UIApplication*)application -{ - /* - Called when the application is about to terminate. - See also applicationDidEnterBackground:. - */ -} - -#pragma mark - -#pragma mark Memory management - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application -{ - /* - Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) - later. - */ -} - -- (void)dealloc -{ - [window release]; - [super dealloc]; -} - -@end diff --git a/tests/unit-tests/proj.ios/main.m b/tests/unit-tests/proj.ios/main.m deleted file mode 100644 index 59bc34dfe91b..000000000000 --- a/tests/unit-tests/proj.ios/main.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// main.m -// iphone -// -// Created by Walzer on 10-11-16. -// Copyright 2010 __MyCompanyName__. All rights reserved. -// - -#import - - -int main(int argc, char *argv[]) { - - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); - [pool release]; - return retVal; -} diff --git a/tests/unit-tests/proj.ios/main.mm b/tests/unit-tests/proj.ios/main.mm new file mode 100644 index 000000000000..281de791415c --- /dev/null +++ b/tests/unit-tests/proj.ios/main.mm @@ -0,0 +1,33 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md). + +https://axmol.dev/ + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ +#import +#include "AppDelegate.h" + +int main(int argc, char *argv[]) { + AppDelegate app; + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, @"AxmolAppController"); + } +}