2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gl_view.mm */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2019-01-01 12:53:14 +01:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
#import "gl_view.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
#include "core/os/keyboard.h"
|
2017-07-30 22:53:40 +02:00
|
|
|
#include "core/project_settings.h"
|
2017-04-09 14:18:49 +02:00
|
|
|
#include "os_iphone.h"
|
2014-05-14 06:22:15 +02:00
|
|
|
#include "servers/audio_server.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
#import <OpenGLES/EAGLDrawable.h>
|
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
@interface GLView (private)
|
|
|
|
|
|
|
|
- (id)initGLES;
|
|
|
|
- (BOOL)createFramebuffer;
|
|
|
|
- (void)destroyFramebuffer;
|
|
|
|
@end
|
|
|
|
*/
|
|
|
|
|
2018-12-11 14:49:34 +01:00
|
|
|
bool gles3_available = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
int gl_view_base_fb;
|
|
|
|
static String keyboard_text;
|
2017-04-09 14:18:49 +02:00
|
|
|
static GLView *_instance = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-05-14 06:22:15 +02:00
|
|
|
static bool video_found_error = false;
|
2014-05-24 06:35:47 +02:00
|
|
|
static bool video_playing = false;
|
2014-11-26 18:24:13 +01:00
|
|
|
static CMTime video_current_time;
|
2014-05-14 06:22:15 +02:00
|
|
|
|
2015-11-16 01:07:21 +01:00
|
|
|
void _show_keyboard(String);
|
|
|
|
void _hide_keyboard();
|
|
|
|
bool _play_video(String, float, String, String);
|
|
|
|
bool _is_video_playing();
|
2016-02-19 05:09:06 +01:00
|
|
|
void _pause_video();
|
2015-11-16 01:07:21 +01:00
|
|
|
void _focus_out_video();
|
|
|
|
void _unpause_video();
|
|
|
|
void _stop_video();
|
2017-10-04 10:39:31 +02:00
|
|
|
CGFloat _points_to_pixels(CGFloat);
|
2015-11-16 01:07:21 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _show_keyboard(String p_existing) {
|
|
|
|
keyboard_text = p_existing;
|
|
|
|
printf("instance on show is %p\n", _instance);
|
|
|
|
[_instance open_keyboard];
|
|
|
|
};
|
|
|
|
|
|
|
|
void _hide_keyboard() {
|
|
|
|
printf("instance on hide is %p\n", _instance);
|
|
|
|
[_instance hide_keyboard];
|
|
|
|
keyboard_text = "";
|
|
|
|
};
|
|
|
|
|
2018-04-10 12:35:30 +02:00
|
|
|
Rect2 _get_ios_window_safe_area(float p_window_width, float p_window_height) {
|
|
|
|
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
|
|
|
|
if (_instance != nil && [_instance respondsToSelector:@selector(safeAreaInsets)]) {
|
|
|
|
insets = [_instance safeAreaInsets];
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND_V(insets.left < 0 || insets.top < 0 || insets.right < 0 || insets.bottom < 0,
|
|
|
|
Rect2(0, 0, p_window_width, p_window_height));
|
2018-12-04 09:33:39 +01:00
|
|
|
UIEdgeInsets window_insets = UIEdgeInsetsMake(_points_to_pixels(insets.top), _points_to_pixels(insets.left), _points_to_pixels(insets.bottom), _points_to_pixels(insets.right));
|
|
|
|
return Rect2(window_insets.left, window_insets.top, p_window_width - window_insets.right - window_insets.left, p_window_height - window_insets.bottom - window_insets.top);
|
2018-04-10 12:35:30 +02:00
|
|
|
}
|
|
|
|
|
2014-11-17 11:46:11 +01:00
|
|
|
bool _play_video(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
|
2017-07-19 22:00:46 +02:00
|
|
|
p_path = ProjectSettings::get_singleton()->globalize_path(p_path);
|
2014-11-17 11:46:11 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
NSString *file_path = [[[NSString alloc] initWithUTF8String:p_path.utf8().get_data()] autorelease];
|
2014-11-17 11:46:11 +01:00
|
|
|
|
|
|
|
_instance.avAsset = [AVAsset assetWithURL:[NSURL fileURLWithPath:file_path]];
|
2016-02-19 05:09:06 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
_instance.avPlayerItem = [[AVPlayerItem alloc] initWithAsset:_instance.avAsset];
|
2014-11-26 18:24:13 +01:00
|
|
|
[_instance.avPlayerItem addObserver:_instance forKeyPath:@"status" options:0 context:nil];
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
_instance.avPlayer = [[AVPlayer alloc] initWithPlayerItem:_instance.avPlayerItem];
|
|
|
|
_instance.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:_instance.avPlayer];
|
2014-11-17 11:46:11 +01:00
|
|
|
|
2016-02-19 05:09:06 +01:00
|
|
|
[_instance.avPlayer addObserver:_instance forKeyPath:@"status" options:0 context:nil];
|
2017-04-09 14:18:49 +02:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:_instance
|
|
|
|
selector:@selector(playerItemDidReachEnd:)
|
|
|
|
name:AVPlayerItemDidPlayToEndTimeNotification
|
|
|
|
object:[_instance.avPlayer currentItem]];
|
2014-11-17 11:46:11 +01:00
|
|
|
|
2015-03-03 18:39:13 +01:00
|
|
|
[_instance.avPlayer addObserver:_instance forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:0];
|
|
|
|
|
2016-02-19 05:09:06 +01:00
|
|
|
[_instance.avPlayerLayer setFrame:_instance.bounds];
|
|
|
|
[_instance.layer addSublayer:_instance.avPlayerLayer];
|
|
|
|
[_instance.avPlayer play];
|
2014-11-17 11:46:11 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
AVMediaSelectionGroup *audioGroup = [_instance.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible];
|
2014-11-17 11:46:11 +01:00
|
|
|
|
2014-12-02 18:02:41 +01:00
|
|
|
NSMutableArray *allAudioParams = [NSMutableArray array];
|
2017-04-09 13:22:40 +02:00
|
|
|
for (id track in audioGroup.options) {
|
2017-04-09 14:18:49 +02:00
|
|
|
NSString *language = [[track locale] localeIdentifier];
|
2014-11-17 11:46:11 +01:00
|
|
|
NSLog(@"subtitle lang: %@", language);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
if ([language isEqualToString:[NSString stringWithUTF8String:p_audio_track.utf8()]]) {
|
2014-12-02 18:02:41 +01:00
|
|
|
AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters];
|
|
|
|
[audioInputParams setVolume:p_volume atTime:kCMTimeZero];
|
|
|
|
[audioInputParams setTrackID:[track trackID]];
|
|
|
|
[allAudioParams addObject:audioInputParams];
|
|
|
|
|
|
|
|
AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
|
|
|
|
[audioMix setInputParameters:allAudioParams];
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
[_instance.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:audioGroup];
|
2014-12-02 18:02:41 +01:00
|
|
|
[_instance.avPlayer.currentItem setAudioMix:audioMix];
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-11-17 11:46:11 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
AVMediaSelectionGroup *subtitlesGroup = [_instance.avAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
|
2014-11-17 11:46:11 +01:00
|
|
|
NSArray *useableTracks = [AVMediaSelectionGroup mediaSelectionOptionsFromArray:subtitlesGroup.options withoutMediaCharacteristics:[NSArray arrayWithObject:AVMediaCharacteristicContainsOnlyForcedSubtitles]];
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
for (id track in useableTracks) {
|
2017-04-09 14:18:49 +02:00
|
|
|
NSString *language = [[track locale] localeIdentifier];
|
2014-11-17 11:46:11 +01:00
|
|
|
NSLog(@"subtitle lang: %@", language);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
if ([language isEqualToString:[NSString stringWithUTF8String:p_subtitle_track.utf8()]]) {
|
2017-04-09 14:18:49 +02:00
|
|
|
[_instance.avPlayer.currentItem selectMediaOption:track inMediaSelectionGroup:subtitlesGroup];
|
2017-04-09 13:22:40 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-11-17 11:46:11 +01:00
|
|
|
}
|
|
|
|
|
2016-02-19 05:09:06 +01:00
|
|
|
video_playing = true;
|
2014-11-17 11:46:11 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
|
|
|
|
bool _is_video_playing() {
|
2016-02-19 05:09:06 +01:00
|
|
|
if (_instance.avPlayer.error) {
|
2016-04-02 20:26:12 +02:00
|
|
|
printf("Error during playback\n");
|
2016-02-19 05:09:06 +01:00
|
|
|
}
|
|
|
|
return (_instance.avPlayer.rate > 0 && !_instance.avPlayer.error);
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void _pause_video() {
|
2014-11-26 18:24:13 +01:00
|
|
|
video_current_time = _instance.avPlayer.currentTime;
|
2014-11-17 11:46:11 +01:00
|
|
|
[_instance.avPlayer pause];
|
2014-05-24 06:35:47 +02:00
|
|
|
video_playing = false;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-02 18:02:41 +01:00
|
|
|
void _focus_out_video() {
|
|
|
|
printf("focus out pausing video\n");
|
|
|
|
[_instance.avPlayer pause];
|
|
|
|
};
|
|
|
|
|
2014-11-26 18:24:13 +01:00
|
|
|
void _unpause_video() {
|
2014-12-02 18:02:41 +01:00
|
|
|
|
2014-11-26 18:24:13 +01:00
|
|
|
[_instance.avPlayer play];
|
|
|
|
video_playing = true;
|
|
|
|
};
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void _stop_video() {
|
2014-11-17 11:46:11 +01:00
|
|
|
[_instance.avPlayer pause];
|
|
|
|
[_instance.avPlayerLayer removeFromSuperlayer];
|
|
|
|
_instance.avPlayer = nil;
|
2014-05-24 06:35:47 +02:00
|
|
|
video_playing = false;
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2017-10-04 10:39:31 +02:00
|
|
|
CGFloat _points_to_pixels(CGFloat points) {
|
|
|
|
float pixelPerInch;
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
pixelPerInch = 132;
|
|
|
|
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
pixelPerInch = 163;
|
|
|
|
} else {
|
|
|
|
pixelPerInch = 160;
|
|
|
|
}
|
|
|
|
CGFloat pointsPerInch = 72.0;
|
|
|
|
return (points / pointsPerInch * pixelPerInch);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
@implementation GLView
|
|
|
|
|
|
|
|
@synthesize animationInterval;
|
|
|
|
|
|
|
|
static const int max_touches = 8;
|
2017-04-09 14:18:49 +02:00
|
|
|
static UITouch *touches[max_touches];
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static void init_touches() {
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
for (int i = 0; i < max_touches; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
touches[i] = NULL;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
static int get_touch_id(UITouch *p_touch) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int first = -1;
|
2017-04-09 14:18:49 +02:00
|
|
|
for (int i = 0; i < max_touches; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (first == -1 && touches[i] == NULL) {
|
|
|
|
first = i;
|
|
|
|
continue;
|
|
|
|
};
|
|
|
|
if (touches[i] == p_touch)
|
|
|
|
return i;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (first != -1) {
|
|
|
|
touches[first] = p_touch;
|
|
|
|
return first;
|
|
|
|
};
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
static int remove_touch(UITouch *p_touch) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int remaining = 0;
|
2017-04-09 14:18:49 +02:00
|
|
|
for (int i = 0; i < max_touches; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (touches[i] == NULL)
|
|
|
|
continue;
|
|
|
|
if (touches[i] == p_touch)
|
|
|
|
touches[i] = NULL;
|
|
|
|
else
|
|
|
|
++remaining;
|
|
|
|
};
|
|
|
|
return remaining;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void clear_touches() {
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
for (int i = 0; i < max_touches; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
touches[i] = NULL;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Implement this to override the default layer class (which is [CALayer class]).
|
|
|
|
// We do this so that our view will be backed by a layer that is capable of OpenGL ES rendering.
|
2017-04-09 14:18:49 +02:00
|
|
|
+ (Class)layerClass {
|
2014-02-10 02:10:30 +01:00
|
|
|
return [CAEAGLLayer class];
|
|
|
|
}
|
|
|
|
|
|
|
|
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
|
2017-04-09 14:18:49 +02:00
|
|
|
- (id)initWithCoder:(NSCoder *)coder {
|
2014-02-10 02:10:30 +01:00
|
|
|
active = FALSE;
|
2017-04-09 14:18:49 +02:00
|
|
|
if ((self = [super initWithCoder:coder])) {
|
2014-02-10 02:10:30 +01:00
|
|
|
self = [self initGLES];
|
2016-04-02 20:26:12 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
- (id)initGLES {
|
2014-02-10 02:10:30 +01:00
|
|
|
// Get our backing layer
|
2017-04-09 14:18:49 +02:00
|
|
|
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// Configure it so that it is opaque, does not retain the contents of the backbuffer when displayed, and uses RGBA8888 color.
|
|
|
|
eaglLayer.opaque = YES;
|
2017-04-09 14:18:49 +02:00
|
|
|
eaglLayer.drawableProperties = [NSDictionary
|
|
|
|
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE],
|
|
|
|
kEAGLDrawablePropertyRetainedBacking,
|
|
|
|
kEAGLColorFormatRGBA8,
|
|
|
|
kEAGLDrawablePropertyColorFormat,
|
|
|
|
nil];
|
2019-03-15 02:36:33 +01:00
|
|
|
bool fallback_gl2 = false;
|
|
|
|
// Create a GL ES 3 context based on the gl driver from project settings
|
2019-03-14 23:14:20 +01:00
|
|
|
if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3") {
|
|
|
|
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
|
2019-03-15 02:36:33 +01:00
|
|
|
NSLog(@"Setting up an OpenGL ES 3.0 context. Based on Project Settings \"rendering/quality/driver/driver_name\"");
|
|
|
|
if (!context && GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
|
|
|
gles3_available = false;
|
|
|
|
fallback_gl2 = true;
|
|
|
|
NSLog(@"Failed to create OpenGL ES 3.0 context. Falling back to OpenGL ES 2.0");
|
|
|
|
}
|
2019-03-14 23:14:20 +01:00
|
|
|
}
|
2019-03-15 02:36:33 +01:00
|
|
|
|
|
|
|
// Create GL ES 2 context
|
|
|
|
if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2" || fallback_gl2) {
|
|
|
|
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
|
|
|
NSLog(@"Setting up an OpenGL ES 2.0 context.");
|
|
|
|
if (!context) {
|
|
|
|
NSLog(@"Failed to create OpenGL ES 2.0 context!");
|
|
|
|
return nil;
|
|
|
|
}
|
2019-03-14 23:14:20 +01:00
|
|
|
}
|
2019-03-15 02:36:33 +01:00
|
|
|
|
2019-03-14 23:14:20 +01:00
|
|
|
if (![EAGLContext setCurrentContext:context]) {
|
|
|
|
NSLog(@"Failed to set EAGLContext!");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
if (![self createFramebuffer]) {
|
|
|
|
NSLog(@"Failed to create frame buffer!");
|
|
|
|
return nil;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// Default the animation interval to 1/60th of a second.
|
|
|
|
animationInterval = 1.0 / 60.0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
- (id<GLViewDelegate>)delegate {
|
2014-02-10 02:10:30 +01:00
|
|
|
return delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the delegate, and if it needs a -setupView: call, set our internal flag so that it will be called.
|
2017-04-09 14:18:49 +02:00
|
|
|
- (void)setDelegate:(id<GLViewDelegate>)d {
|
2014-02-10 02:10:30 +01:00
|
|
|
delegate = d;
|
|
|
|
delegateSetup = ![delegate respondsToSelector:@selector(setupView:)];
|
|
|
|
}
|
|
|
|
|
2015-10-23 02:31:09 +02:00
|
|
|
@synthesize useCADisplayLink;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// If our view is resized, we'll be asked to layout subviews.
|
|
|
|
// This is the perfect opportunity to also update the framebuffer so that it is
|
|
|
|
// the same size as our display area.
|
2014-03-14 02:57:24 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
- (void)layoutSubviews {
|
2014-02-10 02:10:30 +01:00
|
|
|
[EAGLContext setCurrentContext:context];
|
|
|
|
[self destroyFramebuffer];
|
|
|
|
[self createFramebuffer];
|
2019-10-29 08:58:59 +01:00
|
|
|
[self drawView];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (BOOL)createFramebuffer {
|
2014-02-10 02:10:30 +01:00
|
|
|
// Generate IDs for a framebuffer object and a color renderbuffer
|
2017-04-09 14:18:49 +02:00
|
|
|
UIScreen *mainscr = [UIScreen mainScreen];
|
2014-03-14 02:57:24 +01:00
|
|
|
printf("******** screen size %i, %i\n", (int)mainscr.currentMode.size.width, (int)mainscr.currentMode.size.height);
|
2018-04-10 12:35:30 +02:00
|
|
|
self.contentScaleFactor = mainscr.nativeScale;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
glGenFramebuffersOES(1, &viewFramebuffer);
|
|
|
|
glGenRenderbuffersOES(1, &viewRenderbuffer);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
|
|
|
|
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
|
|
|
// This call associates the storage for the current render buffer with the EAGLDrawable (our CAEAGLLayer)
|
2017-03-24 21:45:31 +01:00
|
|
|
// allowing us to draw into a buffer that will later be rendered to screen wherever the layer is (which corresponds with our view).
|
2014-02-10 02:10:30 +01:00
|
|
|
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
|
|
|
|
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
|
|
|
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// For this sample, we also need a depth buffer, so we'll create and attach one via another renderbuffer.
|
|
|
|
glGenRenderbuffersOES(1, &depthRenderbuffer);
|
|
|
|
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
|
|
|
|
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
|
|
|
|
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
|
2014-02-10 02:10:30 +01:00
|
|
|
NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OS::get_singleton()) {
|
|
|
|
OS::VideoMode vm;
|
|
|
|
vm.fullscreen = true;
|
|
|
|
vm.width = backingWidth;
|
|
|
|
vm.height = backingHeight;
|
|
|
|
vm.resizable = false;
|
|
|
|
OS::get_singleton()->set_video_mode(vm);
|
|
|
|
OSIPhone::get_singleton()->set_base_framebuffer(viewFramebuffer);
|
|
|
|
};
|
|
|
|
gl_view_base_fb = viewFramebuffer;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up any buffers we have allocated.
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)destroyFramebuffer {
|
2014-02-10 02:10:30 +01:00
|
|
|
glDeleteFramebuffersOES(1, &viewFramebuffer);
|
|
|
|
viewFramebuffer = 0;
|
|
|
|
glDeleteRenderbuffersOES(1, &viewRenderbuffer);
|
|
|
|
viewRenderbuffer = 0;
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if (depthRenderbuffer) {
|
2014-02-10 02:10:30 +01:00
|
|
|
glDeleteRenderbuffersOES(1, &depthRenderbuffer);
|
|
|
|
depthRenderbuffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)startAnimation {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (active)
|
|
|
|
return;
|
|
|
|
active = TRUE;
|
|
|
|
printf("start animation!\n");
|
2015-10-23 02:31:09 +02:00
|
|
|
if (useCADisplayLink) {
|
|
|
|
|
|
|
|
// Approximate frame rate
|
|
|
|
// assumes device refreshes at 60 fps
|
2017-04-09 14:18:49 +02:00
|
|
|
int frameInterval = (int)floor(animationInterval * 60.0f);
|
2015-10-23 02:31:09 +02:00
|
|
|
|
|
|
|
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
|
|
|
|
[displayLink setFrameInterval:frameInterval];
|
|
|
|
|
|
|
|
// Setup DisplayLink in main thread
|
|
|
|
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
2017-04-09 13:22:40 +02:00
|
|
|
} else {
|
2015-10-23 02:31:09 +02:00
|
|
|
animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
|
|
|
|
}
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
if (video_playing) {
|
2014-11-26 18:24:13 +01:00
|
|
|
_unpause_video();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)stopAnimation {
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
active = FALSE;
|
|
|
|
printf("******** stop animation!\n");
|
2015-10-23 02:31:09 +02:00
|
|
|
|
|
|
|
if (useCADisplayLink) {
|
|
|
|
[displayLink invalidate];
|
|
|
|
displayLink = nil;
|
2017-04-09 13:22:40 +02:00
|
|
|
} else {
|
2015-10-23 02:31:09 +02:00
|
|
|
[animationTimer invalidate];
|
|
|
|
animationTimer = nil;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
clear_touches();
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
if (video_playing) {
|
2014-11-26 18:24:13 +01:00
|
|
|
// save position
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)setAnimationInterval:(NSTimeInterval)interval {
|
2014-02-10 02:10:30 +01:00
|
|
|
animationInterval = interval;
|
2017-04-09 14:18:49 +02:00
|
|
|
if ((useCADisplayLink && displayLink) || (!useCADisplayLink && animationTimer)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
[self stopAnimation];
|
|
|
|
[self startAnimation];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the OpenGL view when the timer fires
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)drawView {
|
2019-10-29 08:58:59 +01:00
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
printf("draw view not active!\n");
|
|
|
|
return;
|
|
|
|
};
|
2015-10-23 02:31:09 +02:00
|
|
|
if (useCADisplayLink) {
|
|
|
|
// Pause the CADisplayLink to avoid recursion
|
2017-04-09 14:18:49 +02:00
|
|
|
[displayLink setPaused:YES];
|
2015-02-10 20:54:22 +01:00
|
|
|
|
2015-10-23 02:31:09 +02:00
|
|
|
// Process all input events
|
2019-10-29 08:58:59 +01:00
|
|
|
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.0, TRUE) == kCFRunLoopRunHandledSource)
|
2017-04-09 14:18:49 +02:00
|
|
|
;
|
2015-02-10 20:54:22 +01:00
|
|
|
|
2015-10-23 02:31:09 +02:00
|
|
|
// We are good to go, resume the CADisplayLink
|
2017-04-09 14:18:49 +02:00
|
|
|
[displayLink setPaused:NO];
|
2015-10-23 02:31:09 +02:00
|
|
|
}
|
2015-02-10 20:54:22 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// Make sure that you are drawing to the current context
|
|
|
|
[EAGLContext setCurrentContext:context];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// If our drawing delegate needs to have the view setup, then call -setupView: and flag that it won't need to be called again.
|
2017-04-09 14:18:49 +02:00
|
|
|
if (!delegateSetup) {
|
2014-02-10 02:10:30 +01:00
|
|
|
[delegate setupView:self];
|
|
|
|
delegateSetup = YES;
|
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
|
|
|
|
|
|
|
|
[delegate drawView:self];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
|
|
|
|
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-11-26 18:24:13 +01:00
|
|
|
#ifdef DEBUG_ENABLED
|
2014-02-10 02:10:30 +01:00
|
|
|
GLenum err = glGetError();
|
2017-04-09 14:18:49 +02:00
|
|
|
if (err)
|
2017-07-28 02:32:08 +02:00
|
|
|
NSLog(@"DrawView: %x error", err);
|
2014-11-26 18:24:13 +01:00
|
|
|
#endif
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
2017-04-09 14:18:49 +02:00
|
|
|
NSArray *tlist = [[event allTouches] allObjects];
|
|
|
|
for (unsigned int i = 0; i < [tlist count]; i++) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if ([touches containsObject:[tlist objectAtIndex:i]]) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
UITouch *touch = [tlist objectAtIndex:i];
|
2014-02-10 02:10:30 +01:00
|
|
|
if (touch.phase != UITouchPhaseBegan)
|
|
|
|
continue;
|
|
|
|
int tid = get_touch_id(touch);
|
|
|
|
ERR_FAIL_COND(tid == -1);
|
|
|
|
CGPoint touchPoint = [touch locationInView:self];
|
2018-02-24 03:04:30 +01:00
|
|
|
OSIPhone::get_singleton()->touch_press(tid, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, true, touch.tapCount > 1);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
NSArray *tlist = [[event allTouches] allObjects];
|
|
|
|
for (unsigned int i = 0; i < [tlist count]; i++) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if ([touches containsObject:[tlist objectAtIndex:i]]) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
UITouch *touch = [tlist objectAtIndex:i];
|
2014-02-10 02:10:30 +01:00
|
|
|
if (touch.phase != UITouchPhaseMoved)
|
|
|
|
continue;
|
|
|
|
int tid = get_touch_id(touch);
|
|
|
|
ERR_FAIL_COND(tid == -1);
|
|
|
|
CGPoint touchPoint = [touch locationInView:self];
|
|
|
|
CGPoint prev_point = [touch previousLocationInView:self];
|
2018-02-24 03:04:30 +01:00
|
|
|
OSIPhone::get_singleton()->touch_drag(tid, prev_point.x * self.contentScaleFactor, prev_point.y * self.contentScaleFactor, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
2017-04-09 14:18:49 +02:00
|
|
|
NSArray *tlist = [[event allTouches] allObjects];
|
|
|
|
for (unsigned int i = 0; i < [tlist count]; i++) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if ([touches containsObject:[tlist objectAtIndex:i]]) {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
UITouch *touch = [tlist objectAtIndex:i];
|
2014-02-10 02:10:30 +01:00
|
|
|
if (touch.phase != UITouchPhaseEnded)
|
|
|
|
continue;
|
|
|
|
int tid = get_touch_id(touch);
|
|
|
|
ERR_FAIL_COND(tid == -1);
|
2018-02-24 03:04:30 +01:00
|
|
|
remove_touch(touch);
|
2014-02-10 02:10:30 +01:00
|
|
|
CGPoint touchPoint = [touch locationInView:self];
|
2018-02-24 03:04:30 +01:00
|
|
|
OSIPhone::get_singleton()->touch_press(tid, touchPoint.x * self.contentScaleFactor, touchPoint.y * self.contentScaleFactor, false, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
OSIPhone::get_singleton()->touches_cancelled();
|
|
|
|
clear_touches();
|
|
|
|
};
|
|
|
|
|
|
|
|
- (BOOL)canBecomeFirstResponder {
|
|
|
|
return YES;
|
|
|
|
};
|
|
|
|
|
|
|
|
- (void)open_keyboard {
|
|
|
|
//keyboard_text = p_existing;
|
|
|
|
[self becomeFirstResponder];
|
|
|
|
};
|
|
|
|
|
|
|
|
- (void)hide_keyboard {
|
|
|
|
//keyboard_text = p_existing;
|
|
|
|
[self resignFirstResponder];
|
|
|
|
};
|
|
|
|
|
2017-10-04 10:39:31 +02:00
|
|
|
- (void)keyboardOnScreen:(NSNotification *)notification {
|
|
|
|
NSDictionary *info = notification.userInfo;
|
|
|
|
NSValue *value = info[UIKeyboardFrameEndUserInfoKey];
|
|
|
|
|
|
|
|
CGRect rawFrame = [value CGRectValue];
|
|
|
|
CGRect keyboardFrame = [self convertRect:rawFrame fromView:nil];
|
|
|
|
|
|
|
|
OSIPhone::get_singleton()->set_virtual_keyboard_height(_points_to_pixels(keyboardFrame.size.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyboardHidden:(NSNotification *)notification {
|
|
|
|
OSIPhone::get_singleton()->set_virtual_keyboard_height(0);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
- (void)deleteBackward {
|
|
|
|
if (keyboard_text.length())
|
|
|
|
keyboard_text.erase(keyboard_text.length() - 1, 1);
|
|
|
|
OSIPhone::get_singleton()->key(KEY_BACKSPACE, true);
|
|
|
|
};
|
|
|
|
|
|
|
|
- (BOOL)hasText {
|
|
|
|
return keyboard_text.length() ? YES : NO;
|
|
|
|
};
|
|
|
|
|
|
|
|
- (void)insertText:(NSString *)p_text {
|
|
|
|
String character;
|
|
|
|
character.parse_utf8([p_text UTF8String]);
|
|
|
|
keyboard_text = keyboard_text + character;
|
2017-04-09 14:18:49 +02:00
|
|
|
OSIPhone::get_singleton()->key(character[0] == 10 ? KEY_ENTER : character[0], true);
|
2018-12-16 01:44:18 +01:00
|
|
|
printf("inserting text with character %lc\n", (CharType)character[0]);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
- (void)audioRouteChangeListenerCallback:(NSNotification *)notification {
|
2015-11-16 01:07:21 +01:00
|
|
|
printf("*********** route changed!\n");
|
2015-03-03 18:39:13 +01:00
|
|
|
NSDictionary *interuptionDict = notification.userInfo;
|
|
|
|
|
|
|
|
NSInteger routeChangeReason = [[interuptionDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
|
|
|
|
|
|
|
|
switch (routeChangeReason) {
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
case AVAudioSessionRouteChangeReasonNewDeviceAvailable: {
|
2015-03-03 18:39:13 +01:00
|
|
|
NSLog(@"AVAudioSessionRouteChangeReasonNewDeviceAvailable");
|
|
|
|
NSLog(@"Headphone/Line plugged in");
|
2017-04-09 13:22:40 +02:00
|
|
|
}; break;
|
2015-03-03 18:39:13 +01:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: {
|
2015-03-03 18:39:13 +01:00
|
|
|
NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
|
|
|
|
NSLog(@"Headphone/Line was pulled. Resuming video play....");
|
2015-10-23 02:31:09 +02:00
|
|
|
if (_is_video_playing()) {
|
2015-03-03 18:39:13 +01:00
|
|
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
2017-04-09 14:18:49 +02:00
|
|
|
[_instance.avPlayer play]; // NOTE: change this line according your current player implementation
|
|
|
|
NSLog(@"resumed play");
|
2015-03-03 18:39:13 +01:00
|
|
|
});
|
|
|
|
};
|
2017-04-09 13:22:40 +02:00
|
|
|
}; break;
|
2015-03-03 18:39:13 +01:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
case AVAudioSessionRouteChangeReasonCategoryChange: {
|
2015-03-03 18:39:13 +01:00
|
|
|
// called at start - also when other audio wants to play
|
|
|
|
NSLog(@"AVAudioSessionRouteChangeReasonCategoryChange");
|
2017-04-09 13:22:40 +02:00
|
|
|
}; break;
|
2015-03-03 18:39:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// When created via code however, we get initWithFrame
|
2017-04-09 14:18:49 +02:00
|
|
|
- (id)initWithFrame:(CGRect)frame {
|
2014-02-10 02:10:30 +01:00
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
_instance = self;
|
|
|
|
printf("after init super %p\n", self);
|
2017-04-09 14:18:49 +02:00
|
|
|
if (self != nil) {
|
2014-02-10 02:10:30 +01:00
|
|
|
self = [self initGLES];
|
|
|
|
printf("after init gles %p\n", self);
|
|
|
|
}
|
|
|
|
init_touches();
|
2017-04-09 14:18:49 +02:00
|
|
|
self.multipleTouchEnabled = YES;
|
2018-04-10 12:35:30 +02:00
|
|
|
self.autocorrectionType = UITextAutocorrectionTypeNo;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-03-03 18:39:13 +01:00
|
|
|
printf("******** adding observer for sound routing changes\n");
|
2017-04-09 14:18:49 +02:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(audioRouteChangeListenerCallback:)
|
|
|
|
name:AVAudioSessionRouteChangeNotification
|
|
|
|
object:nil];
|
2015-03-03 18:39:13 +01:00
|
|
|
|
2017-10-04 10:39:31 +02:00
|
|
|
printf("******** adding observer for keyboard show/hide\n");
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(keyboardOnScreen:)
|
|
|
|
name:UIKeyboardDidShowNotification
|
|
|
|
object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(keyboardHidden:)
|
|
|
|
name:UIKeyboardDidHideNotification
|
|
|
|
object:nil];
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
//self.autoresizesSubviews = YES;
|
|
|
|
//[self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
//- (BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
|
|
|
|
// return YES;
|
|
|
|
//}
|
2014-04-05 17:39:30 +02:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
|
|
|
|
// return YES;
|
|
|
|
//}
|
2014-04-05 17:39:30 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// Stop animating and release resources when they are no longer needed.
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)dealloc {
|
2014-02-10 02:10:30 +01:00
|
|
|
[self stopAnimation];
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if ([EAGLContext currentContext] == context) {
|
2014-02-10 02:10:30 +01:00
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
2016-04-02 20:26:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
[context release];
|
|
|
|
context = nil;
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
2014-11-26 18:24:13 +01:00
|
|
|
|
|
|
|
if (object == _instance.avPlayerItem && [keyPath isEqualToString:@"status"]) {
|
2017-04-09 13:22:40 +02:00
|
|
|
if (_instance.avPlayerItem.status == AVPlayerStatusFailed || _instance.avPlayer.status == AVPlayerStatusFailed) {
|
|
|
|
_stop_video();
|
2017-04-09 14:18:49 +02:00
|
|
|
video_found_error = true;
|
2017-04-09 13:22:40 +02:00
|
|
|
}
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
if (_instance.avPlayer.status == AVPlayerStatusReadyToPlay &&
|
|
|
|
_instance.avPlayerItem.status == AVPlayerItemStatusReadyToPlay &&
|
|
|
|
CMTIME_COMPARE_INLINE(video_current_time, ==, kCMTimeZero)) {
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2017-04-09 13:22:40 +02:00
|
|
|
//NSLog(@"time: %@", video_current_time);
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2017-04-09 14:18:49 +02:00
|
|
|
[_instance.avPlayer seekToTime:video_current_time];
|
|
|
|
video_current_time = kCMTimeZero;
|
2014-11-26 18:24:13 +01:00
|
|
|
}
|
2017-04-09 13:22:40 +02:00
|
|
|
}
|
2015-03-03 18:39:13 +01:00
|
|
|
|
|
|
|
if (object == _instance.avPlayer && [keyPath isEqualToString:@"rate"]) {
|
|
|
|
NSLog(@"Player playback rate changed: %.5f", _instance.avPlayer.rate);
|
|
|
|
if (_is_video_playing() && _instance.avPlayer.rate == 0.0 && !_instance.avPlayer.error) {
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
2017-04-09 14:18:49 +02:00
|
|
|
[_instance.avPlayer play]; // NOTE: change this line according your current player implementation
|
|
|
|
NSLog(@"resumed play");
|
2015-03-03 18:39:13 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
NSLog(@" . . . PAUSED (or just started)");
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 11:46:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)playerItemDidReachEnd:(NSNotification *)notification {
|
2017-04-09 14:18:49 +02:00
|
|
|
_stop_video();
|
2014-11-17 11:46:11 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
@end
|