From: numzero Date: Tue, 14 Mar 2023 15:48:34 +0000 (+0300) Subject: Remove CIrrDeviceiOS X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=df8881898d08234920696e32f777ee31b7431386;p=irrlicht.git Remove CIrrDeviceiOS --- diff --git a/source/Irrlicht/CEAGLManager.h b/source/Irrlicht/CEAGLManager.h deleted file mode 100644 index 65caa7a..0000000 --- a/source/Irrlicht/CEAGLManager.h +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (C) 2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#ifndef __C_EAGL_MANAGER_H_INCLUDED__ -#define __C_EAGL_MANAGER_H_INCLUDED__ - - -#ifdef _IRR_COMPILE_WITH_EAGL_MANAGER_ - -#include "SIrrCreationParameters.h" -#include "SExposedVideoData.h" -#include "IContextManager.h" - -namespace irr -{ -namespace video -{ - // EAGL manager. - class CEAGLManager : public IContextManager - { - public: - //! Constructor. - CEAGLManager(); - - //! Destructor. - virtual ~CEAGLManager(); - - // Initialize EAGL. - /* This method checks if a view has CAEAGLLayer and grabs it if it does, anyway surface and context - aren't create. */ - bool initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data); - - // Terminate EAGL. - /* Terminate EAGL context. This method break both existed surface and context. */ - void terminate(); - - // Create EAGL surface. - /* This method configure CAEAGLLayer. */ - bool generateSurface(); - - // Destroy EAGL surface. - /* This method reset CAEAGLLayer states. */ - void destroySurface(); - - // Create EAGL context. - /* This method create and activate EAGL context. */ - bool generateContext(); - - // Destroy EAGL context. - /* This method destroy EAGL context. */ - void destroyContext(); - - const SExposedVideoData& getContext() const; - - bool activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero); - - // Swap buffers. - bool swapBuffers(); - - private: - SIrrlichtCreationParameters Params; - SExposedVideoData Data; - - bool Configured; - - void* DataStorage; - - struct SFrameBuffer - { - SFrameBuffer() : BufferID(0), ColorBuffer(0), DepthBuffer(0) - { - } - - u32 BufferID; - u32 ColorBuffer; - u32 DepthBuffer; - }; - - SFrameBuffer FrameBuffer; - }; -} -} - -#endif -#endif diff --git a/source/Irrlicht/CEAGLManager.mm b/source/Irrlicht/CEAGLManager.mm deleted file mode 100644 index 931f92a..0000000 --- a/source/Irrlicht/CEAGLManager.mm +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (C) 2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in Irrlicht.h - -#include "CEAGLManager.h" - -#ifdef _IRR_COMPILE_WITH_EAGL_MANAGER_ - -#include "irrString.h" -#include "os.h" - -#import -#import - -#if defined(_IRR_COMPILE_WITH_OGLES1_) -#include -#include -#elif defined(_IRR_COMPILE_WITH_OGLES2_) -#include -#include -#endif - -namespace irr -{ -namespace video -{ - -struct SEAGLManagerDataStorage -{ - SEAGLManagerDataStorage() : Layer(0), Context(0) - { - } - - CAEAGLLayer* Layer; - EAGLContext* Context; -}; - -CEAGLManager::CEAGLManager() : IContextManager(), Configured(false), DataStorage(0) -{ -#ifdef _DEBUG - setDebugName("CEAGLManager"); -#endif - - DataStorage = new SEAGLManagerDataStorage(); -} - -CEAGLManager::~CEAGLManager() -{ - destroyContext(); - destroySurface(); - terminate(); - - delete static_cast(DataStorage); -} - -bool CEAGLManager::initialize(const SIrrlichtCreationParameters& params, const SExposedVideoData& data) -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - if (dataStorage->Layer != nil) - return true; - - Params = params; - Data = data; - - UIView* view = (__bridge UIView*)data.OpenGLiOS.View; - - if (view == nil || ![[view layer] isKindOfClass:[CAEAGLLayer class]]) - { - os::Printer::log("Could not get EAGL display."); - return false; - } - - dataStorage->Layer = (CAEAGLLayer*)[view layer]; - - return true; -} - -void CEAGLManager::terminate() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - [EAGLContext setCurrentContext:0]; - - destroySurface(); - - if (dataStorage->Layer != nil) - dataStorage->Layer = 0; -} - -bool CEAGLManager::generateSurface() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - CAEAGLLayer* layer = dataStorage->Layer; - - if (layer == nil) - return false; - - if (Configured) - return true; - - NSDictionary* attribs = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:NO], - kEAGLDrawablePropertyRetainedBacking, - (Params.Bits > 16) ? kEAGLColorFormatRGBA8 : kEAGLColorFormatRGB565, - kEAGLDrawablePropertyColorFormat, - nil]; - - [layer setOpaque:(Params.WithAlphaChannel) ? YES : NO]; - [layer setDrawableProperties:attribs]; - - Configured = true; - - return true; -} - -void CEAGLManager::destroySurface() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - CAEAGLLayer* layer = dataStorage->Layer; - - if (layer == nil) - return; - - [layer setOpaque:NO]; - [layer setDrawableProperties:nil]; - - Configured = false; -} - -bool CEAGLManager::generateContext() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - if (dataStorage->Context != nil || !Configured) - return false; - - EAGLRenderingAPI OpenGLESVersion = kEAGLRenderingAPIOpenGLES2; - - switch (Params.DriverType) - { - case EDT_OGLES1: - OpenGLESVersion = kEAGLRenderingAPIOpenGLES1; - break; - case EDT_OGLES2: - OpenGLESVersion = kEAGLRenderingAPIOpenGLES2; - break; - default: - break; - } - - dataStorage->Context = [[EAGLContext alloc] initWithAPI:OpenGLESVersion]; - - if (dataStorage->Context == nil) - { - os::Printer::log("Could not create EAGL context.", ELL_ERROR); - return false; - } - - Data.OpenGLiOS.Context = (__bridge void*)dataStorage->Context; - - os::Printer::log("EAGL context created with OpenGLESVersion: ", core::stringc(static_cast(OpenGLESVersion)), ELL_DEBUG); - - return true; -} - -void CEAGLManager::destroyContext() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - - [dataStorage->Context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:nil]; - - if (FrameBuffer.BufferID != 0) - { - glDeleteFramebuffersOES(1, &FrameBuffer.BufferID); - FrameBuffer.BufferID = 0; - } - - if (FrameBuffer.ColorBuffer != 0) - { - glDeleteRenderbuffersOES(1, &FrameBuffer.ColorBuffer); - FrameBuffer.ColorBuffer = 0; - } - - if (FrameBuffer.DepthBuffer != 0) - { - glDeleteRenderbuffersOES(1, &FrameBuffer.DepthBuffer); - FrameBuffer.DepthBuffer = 0; - } - - [EAGLContext setCurrentContext:0]; - - if (dataStorage->Context != nil) - dataStorage->Context = 0; - - Data.OpenGLiOS.Context = 0; -} - -bool CEAGLManager::activateContext(const SExposedVideoData& videoData, bool restorePrimaryOnZero) -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - EAGLContext* context = dataStorage->Context; - - bool status = false; - - if (context != nil) - { - status = ([EAGLContext currentContext] == context || [EAGLContext setCurrentContext:context]); - } - - if (status) - { - if (FrameBuffer.ColorBuffer == 0) - { - glGenRenderbuffersOES(1, &FrameBuffer.ColorBuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:dataStorage->Layer]; - } - - if (FrameBuffer.DepthBuffer == 0) - { - GLenum depth = (Params.ZBufferBits >= 24) ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16_OES; - - glGenRenderbuffersOES(1, &FrameBuffer.DepthBuffer); - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer); - glRenderbufferStorageOES(GL_RENDERBUFFER_OES, depth, Params.WindowSize.Width, Params.WindowSize.Height); - } - - if (FrameBuffer.BufferID == 0) - { - glGenFramebuffersOES(1, &FrameBuffer.BufferID); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, FrameBuffer.BufferID); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, FrameBuffer.DepthBuffer); - } - - glBindFramebufferOES(GL_FRAMEBUFFER_OES, FrameBuffer.BufferID); - } - else - { - os::Printer::log("Could not make EGL context current."); - } - - return status; -} - -const SExposedVideoData& CEAGLManager::getContext() const -{ - return Data; -} - -bool CEAGLManager::swapBuffers() -{ - SEAGLManagerDataStorage* dataStorage = static_cast(DataStorage); - EAGLContext* context = dataStorage->Context; - - bool status = false; - - if (context != nil && context == [EAGLContext currentContext]) - { - glBindRenderbufferOES(GL_RENDERBUFFER_OES, FrameBuffer.ColorBuffer); - [context presentRenderbuffer:GL_RENDERBUFFER_OES]; - - status = true; - } - - return status; -} - -} -} - -#endif diff --git a/source/Irrlicht/CIrrDeviceiOS.h b/source/Irrlicht/CIrrDeviceiOS.h deleted file mode 100644 index 6130d27..0000000 --- a/source/Irrlicht/CIrrDeviceiOS.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2002-2008 Nikolaus Gebhardt -// Copyright (C) 2008 Redshift Software, Inc. -// Copyright (C) 2012-2015 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#ifndef __C_IRR_DEVICE_IOS_H_INCLUDED__ -#define __C_IRR_DEVICE_IOS_H_INCLUDED__ - - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - -#include "CIrrDeviceStub.h" -#include "IrrlichtDevice.h" - -namespace irr -{ - - class CIrrDeviceiOS : public CIrrDeviceStub - { - public: - CIrrDeviceiOS(const SIrrlichtCreationParameters& params); - virtual ~CIrrDeviceiOS(); - - bool run() override; - void yield() override; - void sleep(u32 timeMs, bool pauseTimer) override; - - void setWindowCaption(const wchar_t* text) override; - - bool isWindowActive() const override; - bool isWindowFocused() const override; - bool isWindowMinimized() const override; - - void closeDevice() override; - - void setResizable(bool resize = false) override; - - void minimizeWindow() override; - void maximizeWindow() override; - void restoreWindow() override; - - core::position2di getWindowPosition() override; - - bool activateAccelerometer(float updateInterval = 0.016666f) override; - bool deactivateAccelerometer() override; - bool isAccelerometerActive() override; - bool isAccelerometerAvailable() override; - bool activateGyroscope(float updateInterval = 0.016666f) override; - bool deactivateGyroscope() override; - bool isGyroscopeActive() override; - bool isGyroscopeAvailable() override; - bool activateDeviceMotion(float updateInterval = 0.016666f) override; - bool deactivateDeviceMotion() override; - bool isDeviceMotionActive() override; - bool isDeviceMotionAvailable() override; - - E_DEVICE_TYPE getType() const override; - - private: - void createWindow(); - void createViewAndDriver(); - - void* DataStorage; - - bool Close; - }; - -} - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ -extern void irrlicht_main(); -#endif - -#endif -#endif diff --git a/source/Irrlicht/CIrrDeviceiOS.mm b/source/Irrlicht/CIrrDeviceiOS.mm deleted file mode 100644 index 3a0575d..0000000 --- a/source/Irrlicht/CIrrDeviceiOS.mm +++ /dev/null @@ -1,819 +0,0 @@ -// Copyright (C) 2002-2008 Nikolaus Gebhardt -// Copyright (C) 2008 Redshift Software, Inc. -// Copyright (C) 2012 Patryk Nadrowski -// This file is part of the "Irrlicht Engine". -// For conditions of distribution and use, see copyright notice in irrlicht.h - -#import "CIrrDeviceiOS.h" - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - -#include "IFileSystem.h" -#include "CTimer.h" -#include "CEAGLManager.h" - -#import -#import - -/* Important information */ - -// The application state events and following methods: IrrlichtDevice::isWindowActive, IrrlichtDevice::isWindowFocused -// and IrrlichtDevice::isWindowMinimized works out of box only if you'll use built-in CIrrDelegateiOS, -// so _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ must be enabled in this case. If you need a custom UIApplicationDelegate you must -// handle all application events yourself. - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - -namespace irr -{ - class CIrrDeviceiOS; -} - -/* CIrrDelegateiOS */ - -@interface CIrrDelegateiOS : NSObject - -- (void)setDevice:(irr::CIrrDeviceiOS*)device; -- (bool)isActive; -- (bool)hasFocus; - -@property (strong, nonatomic) UIWindow* window; - -@end - -@implementation CIrrDelegateiOS -{ - irr::CIrrDeviceiOS* Device; - bool Active; - bool Focus; -} - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)options -{ - Device = nil; - Active = true; - Focus = false; - - [self performSelectorOnMainThread:@selector(runIrrlicht) withObject:nil waitUntilDone:NO]; - - return YES; -} - -- (void)applicationWillTerminate:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_TERMINATE; - - Device->postEventFromUser(ev); - - Device->closeDevice(); - } -} - -- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_MEMORY_WARNING; - - Device->postEventFromUser(ev); - } -} - -- (void)applicationWillResignActive:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_PAUSE; - - Device->postEventFromUser(ev); - } - - Focus = false; -} - -- (void)applicationDidEnterBackground:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_DID_PAUSE; - - Device->postEventFromUser(ev); - } - - Active = false; -} - -- (void)applicationWillEnterForeground:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_WILL_RESUME; - - Device->postEventFromUser(ev); - } - - Active = true; -} - -- (void)applicationDidBecomeActive:(UIApplication*)application -{ - if (Device != nil) - { - irr::SEvent ev; - ev.EventType = irr::EET_APPLICATION_EVENT; - ev.ApplicationEvent.EventType = irr::EAET_DID_RESUME; - - Device->postEventFromUser(ev); - } - - Focus = true; -} - -- (void)runIrrlicht -{ - irrlicht_main(); -} - -- (void)setDevice:(irr::CIrrDeviceiOS*)device -{ - Device = device; -} - -- (bool)isActive -{ - return Active; -} - -- (bool)hasFocus -{ - return Focus; -} - -@end - -#endif - -/* CIrrViewiOS */ - -@interface CIrrViewiOS : UIView - -- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device; - -@end - -@implementation CIrrViewiOS -{ - irr::CIrrDeviceiOS* Device; - float Scale; -} - -- (id)initWithFrame:(CGRect)frame forDevice:(irr::CIrrDeviceiOS*)device; -{ - self = [super initWithFrame:frame]; - - if (self) - { - Device = device; - Scale = ([self respondsToSelector:@selector(setContentScaleFactor:)]) ? [[UIScreen mainScreen] scale] : 1.f; - } - - return self; -} - -- (BOOL)isMultipleTouchEnabled -{ - return YES; -} - -- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_PRESSED_DOWN; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_MOVED; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_LEFT_UP; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event -{ - irr::SEvent ev; - ev.EventType = irr::EET_TOUCH_INPUT_EVENT; - ev.TouchInput.Event = irr::ETIE_LEFT_UP; - - for (UITouch* touch in touches) - { - ev.TouchInput.ID = (size_t)touch; - - CGPoint touchPoint = [touch locationInView:self]; - - ev.TouchInput.X = touchPoint.x*Scale; - ev.TouchInput.Y = touchPoint.y*Scale; - - Device->postEventFromUser(ev); - } -} - -@end - -/* CIrrViewEAGLiOS */ - -@interface CIrrViewEAGLiOS : CIrrViewiOS - -@end - -@implementation CIrrViewEAGLiOS - -+ (Class)layerClass -{ - return [CAEAGLLayer class]; -} - -@end - -namespace irr -{ - namespace video - { - IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - - IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager); - } - - struct SIrrDeviceiOSDataStorage - { - SIrrDeviceiOSDataStorage() : Window(0), ViewController(0), View(0), MotionManager(0), ReferenceAttitude(0) - { - MotionManager = [[CMMotionManager alloc] init]; - } - - UIWindow* Window; - UIViewController* ViewController; - CIrrViewiOS* View; - CMMotionManager* MotionManager; - CMAttitude* ReferenceAttitude; - }; - - CIrrDeviceiOS::CIrrDeviceiOS(const SIrrlichtCreationParameters& params) : CIrrDeviceStub(params), DataStorage(0), Close(false) - { -#ifdef _DEBUG - setDebugName("CIrrDeviceiOS"); -#endif - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - [delegate setDevice:this]; -#endif - - DataStorage = new SIrrDeviceiOSDataStorage(); - - FileSystem->changeWorkingDirectoryTo([[[NSBundle mainBundle] resourcePath] UTF8String]); - - createWindow(); - createViewAndDriver(); - - if (!VideoDriver) - return; - - createGUIAndScene(); - } - - CIrrDeviceiOS::~CIrrDeviceiOS() - { - deactivateDeviceMotion(); - deactivateGyroscope(); - deactivateAccelerometer(); - - delete static_cast(DataStorage); - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - [delegate setDevice:nil]; -#endif - } - - bool CIrrDeviceiOS::run() - { - if (!Close) - { - const CFTimeInterval timeInSeconds = 0.000002; - - s32 result = 0; - - do - { - result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, timeInSeconds, TRUE); - } - while (result == kCFRunLoopRunHandledSource); - - os::Timer::tick(); - - //! Update events - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - //! Accelerometer - if (motionManager.isAccelerometerActive) - { - irr::SEvent ev; - ev.EventType = irr::EET_ACCELEROMETER_EVENT; - ev.AccelerometerEvent.X = motionManager.accelerometerData.acceleration.x; - ev.AccelerometerEvent.Y = motionManager.accelerometerData.acceleration.y; - ev.AccelerometerEvent.Z = motionManager.accelerometerData.acceleration.z; - - postEventFromUser(ev); - } - - //! Gyroscope - if (motionManager.isGyroActive) - { - irr::SEvent ev; - ev.EventType = irr::EET_GYROSCOPE_EVENT; - ev.GyroscopeEvent.X = motionManager.gyroData.rotationRate.x; - ev.GyroscopeEvent.Y = motionManager.gyroData.rotationRate.y; - ev.GyroscopeEvent.Z = motionManager.gyroData.rotationRate.z; - - postEventFromUser(ev); - } - - //! Device Motion - if (motionManager.isDeviceMotionActive) - { - CMAttitude* currentAttitude = motionManager.deviceMotion.attitude; - CMAttitude* referenceAttitude = dataStorage->ReferenceAttitude; - - if (referenceAttitude != nil) - [currentAttitude multiplyByInverseOfAttitude: referenceAttitude]; - else - referenceAttitude = motionManager.deviceMotion.attitude; - - irr::SEvent ev; - ev.EventType = irr::EET_DEVICE_MOTION_EVENT; - ev.AccelerometerEvent.X = currentAttitude.roll; - ev.AccelerometerEvent.Y = currentAttitude.pitch; - ev.AccelerometerEvent.Z = currentAttitude.yaw; - - postEventFromUser(ev); - } - } - - return !Close; - } - - void CIrrDeviceiOS::yield() - { - struct timespec ts = {0,0}; - nanosleep(&ts, NULL); - } - - void CIrrDeviceiOS::sleep(u32 timeMs, bool pauseTimer=false) - { - bool wasStopped = Timer ? Timer->isStopped() : true; - - struct timespec ts; - ts.tv_sec = (time_t) (timeMs / 1000); - ts.tv_nsec = (long) (timeMs % 1000) * 1000000; - - if (pauseTimer && !wasStopped) - Timer->stop(); - - nanosleep(&ts, NULL); - - if (pauseTimer && !wasStopped) - Timer->start(); - } - - void CIrrDeviceiOS::setWindowCaption(const wchar_t* text) - { - } - - bool CIrrDeviceiOS::isWindowActive() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return [delegate isActive]; -#else - return false; -#endif - } - - bool CIrrDeviceiOS::isWindowFocused() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return [delegate hasFocus]; -#else - return false; -#endif - } - - bool CIrrDeviceiOS::isWindowMinimized() const - { -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ - CIrrDelegateiOS* delegate = [UIApplication sharedApplication].delegate; - - return ![delegate isActive]; -#else - return false; -#endif - } - - void CIrrDeviceiOS::closeDevice() - { - CFRunLoopStop(CFRunLoopGetMain()); - - Close = true; - } - - void CIrrDeviceiOS::setResizable(bool resize) - { - } - - void CIrrDeviceiOS::minimizeWindow() - { - } - - void CIrrDeviceiOS::maximizeWindow() - { - } - - void CIrrDeviceiOS::restoreWindow() - { - } - - core::position2di CIrrDeviceiOS::getWindowPosition() - { - return core::position2di(0, 0); - } - - bool CIrrDeviceiOS::activateAccelerometer(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isAccelerometerAvailable) - { - if (!motionManager.isAccelerometerActive) - { - motionManager.accelerometerUpdateInterval = updateInterval; - [motionManager startAccelerometerUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateAccelerometer() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isAccelerometerAvailable) - { - if (motionManager.isAccelerometerActive) - [motionManager stopAccelerometerUpdates]; - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isAccelerometerActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isAccelerometerActive); - } - - bool CIrrDeviceiOS::isAccelerometerAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isAccelerometerAvailable); - } - - bool CIrrDeviceiOS::activateGyroscope(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isGyroAvailable) - { - if (!motionManager.isGyroActive) - { - motionManager.gyroUpdateInterval = updateInterval; - [motionManager startGyroUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateGyroscope() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isGyroAvailable) - { - if (motionManager.isGyroActive) - [motionManager stopGyroUpdates]; - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isGyroscopeActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isGyroActive); - } - - bool CIrrDeviceiOS::isGyroscopeAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isGyroAvailable); - } - - bool CIrrDeviceiOS::activateDeviceMotion(float updateInterval) - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isDeviceMotionAvailable) - { - if (!motionManager.isDeviceMotionActive) - { - dataStorage->ReferenceAttitude = nil; - - motionManager.deviceMotionUpdateInterval = updateInterval; - [motionManager startDeviceMotionUpdates]; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::deactivateDeviceMotion() - { - bool status = false; - - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - CMMotionManager* motionManager = dataStorage->MotionManager; - - if (motionManager.isDeviceMotionAvailable) - { - if (motionManager.isDeviceMotionActive) - { - [motionManager stopDeviceMotionUpdates]; - - dataStorage->ReferenceAttitude = nil; - } - - status = true; - } - - return status; - } - - bool CIrrDeviceiOS::isDeviceMotionActive() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isDeviceMotionActive); - } - - bool CIrrDeviceiOS::isDeviceMotionAvailable() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - return (dataStorage->MotionManager.isDeviceMotionAvailable); - } - - E_DEVICE_TYPE CIrrDeviceiOS::getType() const - { - return EIDT_IOS; - } - - void CIrrDeviceiOS::createWindow() - { - if (CreationParams.DriverType != video::EDT_NULL) - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - UIView* externalView = (__bridge UIView*)CreationParams.WindowId; - - if (externalView == nil) - { - dataStorage->Window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - dataStorage->ViewController = [[UIViewController alloc] init]; - dataStorage->Window.rootViewController = dataStorage->ViewController; - - [dataStorage->Window makeKeyAndVisible]; - } - else - { - dataStorage->Window = externalView.window; - - UIResponder* currentResponder = externalView.nextResponder; - - do - { - if ([currentResponder isKindOfClass:[UIViewController class]]) - { - dataStorage->ViewController = (UIViewController*)currentResponder; - - currentResponder = nil; - } - else if ([currentResponder isKindOfClass:[UIView class]]) - { - currentResponder = currentResponder.nextResponder; - } - else - { - currentResponder = nil; - - // Could not find view controller. - _IRR_DEBUG_BREAK_IF(true); - } - } - while (currentResponder != nil); - } - } - } - - void CIrrDeviceiOS::createViewAndDriver() - { - SIrrDeviceiOSDataStorage* dataStorage = static_cast(DataStorage); - - video::SExposedVideoData data; - data.OpenGLiOS.Window = (__bridge void*)dataStorage->Window; - data.OpenGLiOS.ViewController = (__bridge void*)dataStorage->ViewController; - - UIView* externalView = (__bridge UIView*)CreationParams.WindowId; - - CGRect resolution = (externalView == nil) ? [[UIScreen mainScreen] bounds] : externalView.bounds; - - switch (CreationParams.DriverType) - { - case video::EDT_OGLES1: -#ifdef _IRR_COMPILE_WITH_OGLES1_ - { - CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this]; - CreationParams.WindowSize = core::dimension2d(view.frame.size.width, view.frame.size.height); - - dataStorage->View = view; - data.OpenGLiOS.View = (__bridge void*)view; - - ContextManager = new video::CEAGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager); - - if (!VideoDriver) - os::Printer::log("Could not create OpenGL ES 1.x driver.", ELL_ERROR); - } -#else - os::Printer::log("No OpenGL ES 1.x support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_OGLES2: -#ifdef _IRR_COMPILE_WITH_OGLES2_ - { - CIrrViewEAGLiOS* view = [[CIrrViewEAGLiOS alloc] initWithFrame:resolution forDevice:this]; - CreationParams.WindowSize = core::dimension2d(view.frame.size.width, view.frame.size.height); - - dataStorage->View = view; - data.OpenGLiOS.View = (__bridge void*)view; - - ContextManager = new video::CEAGLManager(); - ContextManager->initialize(CreationParams, data); - - VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); - - if (!VideoDriver) - os::Printer::log("Could not create OpenGL ES 2.x driver.", ELL_ERROR); - } -#else - os::Printer::log("No OpenGL ES 2.x support compiled in.", ELL_ERROR); -#endif - break; - - case video::EDT_SOFTWARE: - case video::EDT_BURNINGSVIDEO: - case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS: - case video::EDT_DIRECT3D9: - case video::EDT_OPENGL: - os::Printer::log("This driver is not available in iOS. Try OpenGL ES.", ELL_ERROR); - break; - - case video::EDT_NULL: - VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); - break; - - default: - os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); - break; - } - - if (externalView == nil) - dataStorage->ViewController.view = dataStorage->View; - else - [externalView addSubview:dataStorage->View]; - } -} - -#ifdef _IRR_COMPILE_WITH_IOS_BUILTIN_MAIN_ -int main(int argc, char** argv) -{ - int result = UIApplicationMain(argc, argv, 0, NSStringFromClass([CIrrDelegateiOS class])); - - return result; -} -#endif - -#endif diff --git a/source/Irrlicht/Irrlicht.cpp b/source/Irrlicht/Irrlicht.cpp index 50348e7..e598ec3 100644 --- a/source/Irrlicht/Irrlicht.cpp +++ b/source/Irrlicht/Irrlicht.cpp @@ -29,10 +29,6 @@ static const char* const copyright = "Irrlicht Engine (c) 2002-2017 Nikolaus Geb #include "CIrrDeviceSDL.h" #endif -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ -#include "CIrrDeviceiOS.h" -#endif - #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ #include "Android/CIrrDeviceAndroid.h" #endif @@ -78,11 +74,6 @@ namespace irr if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST)) dev = new CIrrDeviceLinux(params); #endif - -#ifdef _IRR_COMPILE_WITH_IOS_DEVICE_ - if (params.DeviceType == EIDT_IOS || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceiOS(params); -#endif #ifdef _IRR_COMPILE_WITH_ANDROID_DEVICE_ if (params.DeviceType == EIDT_ANDROID || (!dev && params.DeviceType == EIDT_BEST))