forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
50
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h
Normal file
50
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.h
Normal file
@ -0,0 +1,50 @@
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#ifdef KINC_METAL
|
||||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
#else
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
#import <OpenGLES/ES1/glext.h>
|
||||
#endif
|
||||
#ifndef KINC_TVOS
|
||||
#import <CoreMotion/CMMotionManager.h>
|
||||
#endif
|
||||
|
||||
struct kinc_g5_render_target;
|
||||
|
||||
@interface GLView : UIView <UIKeyInput> {
|
||||
@private
|
||||
#ifdef KINC_METAL
|
||||
id<MTLDevice> device;
|
||||
id<MTLCommandQueue> commandQueue;
|
||||
id<MTLCommandBuffer> commandBuffer;
|
||||
id<MTLRenderCommandEncoder> commandEncoder;
|
||||
id<CAMetalDrawable> drawable;
|
||||
id<MTLLibrary> library;
|
||||
MTLRenderPassDescriptor *renderPassDescriptor;
|
||||
id<MTLTexture> depthTexture;
|
||||
#else
|
||||
EAGLContext *context;
|
||||
GLuint defaultFramebuffer, colorRenderbuffer, depthStencilRenderbuffer;
|
||||
#endif
|
||||
|
||||
#ifndef KINC_TVOS
|
||||
CMMotionManager *motionManager;
|
||||
#endif
|
||||
bool hasAccelerometer;
|
||||
float lastAccelerometerX, lastAccelerometerY, lastAccelerometerZ;
|
||||
}
|
||||
|
||||
- (void)begin;
|
||||
- (void)end;
|
||||
- (void)showKeyboard;
|
||||
- (void)hideKeyboard;
|
||||
#ifdef KINC_METAL
|
||||
- (CAMetalLayer *)metalLayer;
|
||||
- (id<MTLDevice>)metalDevice;
|
||||
- (id<MTLLibrary>)metalLibrary;
|
||||
- (id<MTLCommandQueue>)metalQueue;
|
||||
#endif
|
||||
|
||||
@end
|
450
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h
Normal file
450
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/GLView.m.h
Normal file
@ -0,0 +1,450 @@
|
||||
#import "GLView.h"
|
||||
|
||||
#include <kinc/graphics5/graphics.h>
|
||||
#include <kinc/graphics5/rendertarget.h>
|
||||
#include <kinc/input/acceleration.h>
|
||||
#include <kinc/input/keyboard.h>
|
||||
#include <kinc/input/mouse.h>
|
||||
#include <kinc/input/pen.h>
|
||||
#include <kinc/input/rotation.h>
|
||||
#include <kinc/input/surface.h>
|
||||
#include <kinc/system.h>
|
||||
|
||||
#ifdef KINC_OPENGL
|
||||
#include <kinc/backend/graphics4/OpenGLWindow.h>
|
||||
#endif
|
||||
|
||||
static const int touchmaxcount = 20;
|
||||
static void *touches[touchmaxcount];
|
||||
|
||||
static void initTouches(void) {
|
||||
for (int i = 0; i < touchmaxcount; ++i) {
|
||||
touches[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int getTouchIndex(void *touch) {
|
||||
for (int i = 0; i < touchmaxcount; ++i) {
|
||||
if (touches[i] == touch)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int addTouch(void *touch) {
|
||||
for (int i = 0; i < touchmaxcount; ++i) {
|
||||
if (touches[i] == NULL) {
|
||||
touches[i] = touch;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int removeTouch(void *touch) {
|
||||
for (int i = 0; i < touchmaxcount; ++i) {
|
||||
if (touches[i] == touch) {
|
||||
touches[i] = NULL;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static GLint backingWidth, backingHeight;
|
||||
|
||||
int kinc_window_width(int window) {
|
||||
return backingWidth;
|
||||
}
|
||||
|
||||
int kinc_window_height(int window) {
|
||||
return backingHeight;
|
||||
}
|
||||
|
||||
@implementation GLView
|
||||
|
||||
#ifdef KINC_METAL
|
||||
+ (Class)layerClass {
|
||||
return [CAMetalLayer class];
|
||||
}
|
||||
#else
|
||||
+ (Class)layerClass {
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KINC_OPENGL
|
||||
extern int kinc_ios_gl_framebuffer;
|
||||
#endif
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:(CGRect)frame];
|
||||
self.contentScaleFactor = [UIScreen mainScreen].scale;
|
||||
|
||||
backingWidth = frame.size.width * self.contentScaleFactor;
|
||||
backingHeight = frame.size.height * self.contentScaleFactor;
|
||||
|
||||
initTouches();
|
||||
|
||||
device = MTLCreateSystemDefaultDevice();
|
||||
commandQueue = [device newCommandQueue];
|
||||
library = [device newDefaultLibrary];
|
||||
|
||||
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
|
||||
|
||||
metalLayer.device = device;
|
||||
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||
metalLayer.framebufferOnly = YES;
|
||||
// metalLayer.presentsWithTransaction = YES;
|
||||
|
||||
metalLayer.opaque = YES;
|
||||
metalLayer.backgroundColor = nil;
|
||||
|
||||
return self;
|
||||
}
|
||||
#else
|
||||
- (id)initWithFrame:(CGRect)frame {
|
||||
self = [super initWithFrame:(CGRect)frame];
|
||||
self.contentScaleFactor = [UIScreen mainScreen].scale;
|
||||
|
||||
backingWidth = frame.size.width * self.contentScaleFactor;
|
||||
backingHeight = frame.size.height * self.contentScaleFactor;
|
||||
|
||||
initTouches();
|
||||
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
eaglLayer.opaque = YES;
|
||||
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking,
|
||||
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
|
||||
|
||||
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
|
||||
if (!context || ![EAGLContext setCurrentContext:context]) {
|
||||
//[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
glGenFramebuffersOES(1, &defaultFramebuffer);
|
||||
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
|
||||
kinc_ios_gl_framebuffer = defaultFramebuffer;
|
||||
|
||||
glGenRenderbuffersOES(1, &colorRenderbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
|
||||
|
||||
glGenRenderbuffersOES(1, &depthStencilRenderbuffer);
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthStencilRenderbuffer);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthStencilRenderbuffer);
|
||||
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_STENCIL_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthStencilRenderbuffer);
|
||||
|
||||
// Start acceletometer
|
||||
hasAccelerometer = false;
|
||||
#ifndef KINC_TVOS
|
||||
motionManager = [[CMMotionManager alloc] init];
|
||||
if ([motionManager isAccelerometerAvailable]) {
|
||||
motionManager.accelerometerUpdateInterval = 0.033;
|
||||
[motionManager startAccelerometerUpdates];
|
||||
hasAccelerometer = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef KINC_TVOS
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onKeyboardHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
#endif
|
||||
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (void)begin {
|
||||
}
|
||||
#else
|
||||
- (void)begin {
|
||||
[EAGLContext setCurrentContext:context];
|
||||
// glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
|
||||
// glViewport(0, 0, backingWidth, backingHeight);
|
||||
|
||||
#ifndef KINC_TVOS
|
||||
// Accelerometer updates
|
||||
if (hasAccelerometer) {
|
||||
|
||||
CMAcceleration acc = motionManager.accelerometerData.acceleration;
|
||||
|
||||
if (acc.x != lastAccelerometerX || acc.y != lastAccelerometerY || acc.z != lastAccelerometerZ) {
|
||||
|
||||
kinc_internal_on_acceleration(acc.x, acc.y, acc.z);
|
||||
|
||||
lastAccelerometerX = acc.x;
|
||||
lastAccelerometerY = acc.y;
|
||||
lastAccelerometerZ = acc.z;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (void)end {
|
||||
}
|
||||
#else
|
||||
- (void)end {
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
|
||||
[context presentRenderbuffer:GL_RENDERBUFFER_OES]; // crash at end
|
||||
}
|
||||
#endif
|
||||
|
||||
void kinc_internal_call_resize_callback(int window, int width, int height);
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (void)layoutSubviews {
|
||||
backingWidth = self.frame.size.width * self.contentScaleFactor;
|
||||
backingHeight = self.frame.size.height * self.contentScaleFactor;
|
||||
|
||||
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
|
||||
metalLayer.drawableSize = CGSizeMake(backingWidth, backingHeight);
|
||||
|
||||
kinc_internal_call_resize_callback(0, backingWidth, backingHeight);
|
||||
}
|
||||
#else
|
||||
- (void)layoutSubviews {
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
|
||||
[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer *)self.layer];
|
||||
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
|
||||
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
|
||||
|
||||
printf("backingWitdh/Height: %i, %i\n", backingWidth, backingHeight);
|
||||
|
||||
glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthStencilRenderbuffer);
|
||||
glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH24_STENCIL8_OES, backingWidth, backingHeight);
|
||||
|
||||
if (glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
|
||||
NSLog(@"Failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
|
||||
}
|
||||
|
||||
kinc_internal_call_resize_callback(0, backingWidth, backingHeight);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (void)dealloc {
|
||||
}
|
||||
#else
|
||||
- (void)dealloc {
|
||||
if (defaultFramebuffer) {
|
||||
glDeleteFramebuffersOES(1, &defaultFramebuffer);
|
||||
defaultFramebuffer = 0;
|
||||
}
|
||||
|
||||
if (colorRenderbuffer) {
|
||||
glDeleteRenderbuffersOES(1, &colorRenderbuffer);
|
||||
colorRenderbuffer = 0;
|
||||
}
|
||||
|
||||
if (depthStencilRenderbuffer) {
|
||||
glDeleteRenderbuffersOES(1, &depthStencilRenderbuffer);
|
||||
depthStencilRenderbuffer = 0;
|
||||
}
|
||||
|
||||
if ([EAGLContext currentContext] == context)
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
|
||||
//[context release];
|
||||
context = nil;
|
||||
|
||||
//[super dealloc];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (UITouch *touch in touches) {
|
||||
int index = getTouchIndex((__bridge void *)touch);
|
||||
if (index == -1)
|
||||
index = addTouch((__bridge void *)touch);
|
||||
if (index >= 0) {
|
||||
CGPoint point = [touch locationInView:self];
|
||||
float x = point.x * self.contentScaleFactor;
|
||||
float y = point.y * self.contentScaleFactor;
|
||||
if (index == 0) {
|
||||
kinc_internal_mouse_trigger_press(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y);
|
||||
}
|
||||
kinc_internal_surface_trigger_touch_start(index, x, y);
|
||||
|
||||
if (touch.type == UITouchTypePencil) {
|
||||
kinc_internal_pen_trigger_press(0, x, y, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (UITouch *touch in touches) {
|
||||
int index = getTouchIndex((__bridge void *)touch);
|
||||
if (index >= 0) {
|
||||
CGPoint point = [touch locationInView:self];
|
||||
float x = point.x * self.contentScaleFactor;
|
||||
float y = point.y * self.contentScaleFactor;
|
||||
if (index == 0) {
|
||||
kinc_internal_mouse_trigger_move(0, x, y);
|
||||
}
|
||||
kinc_internal_surface_trigger_move(index, x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEstimatedPropertiesUpdated:(NSSet<UITouch *> *)touches {
|
||||
for (UITouch *touch in touches) {
|
||||
if (touch.type == UITouchTypePencil) {
|
||||
CGPoint point = [touch locationInView:self];
|
||||
float x = point.x * self.contentScaleFactor;
|
||||
float y = point.y * self.contentScaleFactor;
|
||||
kinc_internal_pen_trigger_move(0, x, y, touch.force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (UITouch *touch in touches) {
|
||||
int index = removeTouch((__bridge void *)touch);
|
||||
if (index >= 0) {
|
||||
CGPoint point = [touch locationInView:self];
|
||||
float x = point.x * self.contentScaleFactor;
|
||||
float y = point.y * self.contentScaleFactor;
|
||||
if (index == 0) {
|
||||
kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y);
|
||||
}
|
||||
kinc_internal_surface_trigger_touch_end(index, x, y);
|
||||
|
||||
if (touch.type == UITouchTypePencil) {
|
||||
kinc_internal_pen_trigger_release(0, x, y, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
for (UITouch *touch in touches) {
|
||||
int index = removeTouch((__bridge void *)touch);
|
||||
if (index >= 0) {
|
||||
CGPoint point = [touch locationInView:self];
|
||||
float x = point.x * self.contentScaleFactor;
|
||||
float y = point.y * self.contentScaleFactor;
|
||||
if (index == 0) {
|
||||
kinc_internal_mouse_trigger_release(0, event.buttonMask == UIEventButtonMaskSecondary ? 1 : 0, x, y);
|
||||
}
|
||||
kinc_internal_surface_trigger_touch_end(index, x, y);
|
||||
|
||||
if (touch.type == UITouchTypePencil) {
|
||||
kinc_internal_pen_trigger_release(0, x, y, 0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NSString *keyboardstring;
|
||||
static UITextField *myTextField = NULL;
|
||||
static bool shiftDown = false;
|
||||
|
||||
- (void)showKeyboard {
|
||||
[self becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)hideKeyboard {
|
||||
[self resignFirstResponder];
|
||||
}
|
||||
|
||||
- (BOOL)hasText {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)insertText:(NSString *)text {
|
||||
if ([text length] == 1) {
|
||||
unichar ch = [text characterAtIndex:[text length] - 1];
|
||||
if (ch == 8212)
|
||||
ch = '_';
|
||||
if (ch == L'\n') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_RETURN);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_RETURN);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch == L'.') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_PERIOD);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_PERIOD);
|
||||
}
|
||||
else if (ch == L'%') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_PERCENT);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_PERCENT);
|
||||
}
|
||||
else if (ch == L'(') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_OPEN_PAREN);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_OPEN_PAREN);
|
||||
}
|
||||
else if (ch == L'&') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_AMPERSAND);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_AMPERSAND);
|
||||
}
|
||||
else if (ch == L'$') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_DOLLAR);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_DOLLAR);
|
||||
}
|
||||
else if (ch == L'#') {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_HASH);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_HASH);
|
||||
}
|
||||
else if (ch >= L'a' && ch <= L'z') {
|
||||
if (shiftDown) {
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_SHIFT);
|
||||
shiftDown = false;
|
||||
}
|
||||
kinc_internal_keyboard_trigger_key_down(ch + KINC_KEY_A - L'a');
|
||||
kinc_internal_keyboard_trigger_key_up(ch + KINC_KEY_A - L'a');
|
||||
}
|
||||
else {
|
||||
if (!shiftDown) {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_SHIFT);
|
||||
shiftDown = true;
|
||||
}
|
||||
kinc_internal_keyboard_trigger_key_down(ch + KINC_KEY_A - L'A');
|
||||
kinc_internal_keyboard_trigger_key_up(ch + KINC_KEY_A - L'A');
|
||||
}
|
||||
|
||||
kinc_internal_keyboard_trigger_key_press(ch);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)deleteBackward {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_BACKSPACE);
|
||||
kinc_internal_keyboard_trigger_key_up(KINC_KEY_BACKSPACE);
|
||||
}
|
||||
|
||||
- (BOOL)canBecomeFirstResponder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)onKeyboardHide:(NSNotification *)notification {
|
||||
kinc_keyboard_hide();
|
||||
}
|
||||
|
||||
#ifdef KINC_METAL
|
||||
- (CAMetalLayer *)metalLayer {
|
||||
return (CAMetalLayer *)self.layer;
|
||||
}
|
||||
|
||||
- (id<MTLDevice>)metalDevice {
|
||||
return device;
|
||||
}
|
||||
|
||||
- (id<MTLLibrary>)metalLibrary {
|
||||
return library;
|
||||
}
|
||||
|
||||
- (id<MTLCommandQueue>)metalQueue {
|
||||
return commandQueue;
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
@ -0,0 +1,17 @@
|
||||
#import <OpenGLES/ES1/gl.h>
|
||||
#import <OpenGLES/ES1/glext.h>
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#ifndef KINC_TVOS
|
||||
#import <CoreMotion/CMMotionManager.h>
|
||||
#endif
|
||||
|
||||
@interface GLViewController : UIViewController {
|
||||
@private
|
||||
}
|
||||
|
||||
- (void)loadView;
|
||||
|
||||
- (void)setVisible:(BOOL)value;
|
||||
|
||||
@end
|
@ -0,0 +1,72 @@
|
||||
#import "GLView.h"
|
||||
#import "GLViewController.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <kinc/graphics5/rendertarget.h>
|
||||
#include <kinc/math/core.h>
|
||||
|
||||
#include <objc/runtime.h>
|
||||
|
||||
static GLView *glView;
|
||||
|
||||
static bool visible;
|
||||
|
||||
void beginGL(void) {
|
||||
#ifdef KINC_METAL
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
[glView begin];
|
||||
}
|
||||
|
||||
void endGL(void) {
|
||||
#ifdef KINC_METAL
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
[glView end];
|
||||
}
|
||||
|
||||
void showKeyboard(void) {
|
||||
[glView showKeyboard];
|
||||
}
|
||||
|
||||
void hideKeyboard(void) {
|
||||
[glView hideKeyboard];
|
||||
}
|
||||
|
||||
#ifdef KINC_METAL
|
||||
|
||||
CAMetalLayer *getMetalLayer(void) {
|
||||
return [glView metalLayer];
|
||||
}
|
||||
|
||||
id getMetalDevice(void) {
|
||||
return [glView metalDevice];
|
||||
}
|
||||
|
||||
id getMetalLibrary(void) {
|
||||
return [glView metalLibrary];
|
||||
}
|
||||
|
||||
id getMetalQueue(void) {
|
||||
return [glView metalQueue];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@implementation GLViewController
|
||||
|
||||
- (void)loadView {
|
||||
visible = true;
|
||||
self.view = glView = [[GLView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
}
|
||||
|
||||
- (void)setVisible:(BOOL)value {
|
||||
visible = value;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,8 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class GLView;
|
||||
|
||||
@interface KoreAppDelegate : NSObject <UIApplicationDelegate> {
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,142 @@
|
||||
#import "GLView.h"
|
||||
#import "GLViewController.h"
|
||||
#import "KoreAppDelegate.h"
|
||||
#import <AVFAudio/AVFAudio.h>
|
||||
|
||||
#include <kinc/system.h>
|
||||
#include <wchar.h>
|
||||
|
||||
@implementation KoreAppDelegate
|
||||
|
||||
static UIWindow *window;
|
||||
static GLViewController *glViewController;
|
||||
|
||||
void loadURL(const char *url) {
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:url]]];
|
||||
}
|
||||
|
||||
- (void)mainLoop {
|
||||
// NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// try {
|
||||
@autoreleasepool {
|
||||
kickstart(0, NULL);
|
||||
}
|
||||
//}
|
||||
// catch (Kt::Exception& ex) {
|
||||
// printf("Exception\n");
|
||||
// printf("%s", ex.what());
|
||||
//}
|
||||
|
||||
//[pool drain];
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
AVAudioSession *sessionInstance = [AVAudioSession sharedInstance];
|
||||
NSError *error;
|
||||
|
||||
// set the session category
|
||||
NSString *category = AVAudioSessionCategoryAmbient;
|
||||
bool success = [sessionInstance setCategory:category error:&error];
|
||||
if (!success)
|
||||
NSLog(@"Error setting AVAudioSession category! %@\n", [error localizedDescription]);
|
||||
// CGRect rect = [[UIScreen mainScreen] applicationFrame];
|
||||
// CGRect screenBounds = [[UIScreen mainScreen] bounds];
|
||||
|
||||
// window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, Kore::max(screenBounds.size.width, screenBounds.size.height),
|
||||
// Kore::max(screenBounds.size.width, screenBounds.size.height))];
|
||||
// CGRect bounds = [[UIScreen mainScreen] bounds];
|
||||
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
[window setBackgroundColor:[UIColor blackColor]];
|
||||
|
||||
// glView = [[GLView alloc] initWithFrame:CGRectMake(0, 0, Kore::max(screenBounds.size.width, screenBounds.size.height), Kore::max(screenBounds.size.width,
|
||||
// screenBounds.size.height))];
|
||||
glViewController = [[GLViewController alloc] init];
|
||||
#ifndef KINC_TVOS
|
||||
glViewController.view.multipleTouchEnabled = YES;
|
||||
#endif
|
||||
// glViewController.view = glView;
|
||||
//[glViewController ]
|
||||
//[window addSubview:glView];
|
||||
[window setRootViewController:glViewController];
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[self performSelectorOnMainThread:@selector(mainLoop) withObject:nil waitUntilDone:NO];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
#ifndef KINC_TVOS
|
||||
// static Kore::Orientation convertOrientation(UIDeviceOrientation orientation) {
|
||||
// switch (orientation) {
|
||||
// case UIDeviceOrientationLandscapeLeft:
|
||||
// return Kore::OrientationLandscapeRight;
|
||||
// case UIDeviceOrientationLandscapeRight:
|
||||
// return Kore::OrientationLandscapeLeft;
|
||||
// case UIDeviceOrientationPortrait:
|
||||
// return Kore::OrientationPortrait;
|
||||
// case UIDeviceOrientationPortraitUpsideDown:
|
||||
// return Kore::OrientationPortraitUpsideDown;
|
||||
// default:
|
||||
// return Kore::OrientationUnknown;
|
||||
// }
|
||||
//}
|
||||
|
||||
// static UIInterfaceOrientation convertAppleOrientation(UIDeviceOrientation orientation, UIInterfaceOrientation lastOrientation) {
|
||||
// switch (orientation) {
|
||||
// case UIDeviceOrientationLandscapeLeft:
|
||||
// return UIInterfaceOrientationLandscapeRight;
|
||||
// case UIDeviceOrientationLandscapeRight:
|
||||
// return UIInterfaceOrientationLandscapeLeft;
|
||||
// case UIDeviceOrientationPortrait:
|
||||
// return UIInterfaceOrientationPortrait;
|
||||
// case UIDeviceOrientationPortraitUpsideDown:
|
||||
// return UIInterfaceOrientationPortraitUpsideDown;
|
||||
// default:
|
||||
// return lastOrientation;
|
||||
// }
|
||||
//}
|
||||
#endif
|
||||
|
||||
void KoreUpdateKeyboard(void);
|
||||
/*
|
||||
- (void)didRotate:(NSNotification*)notification {
|
||||
if (Kore::Application::the() != nullptr && Kore::Application::the()->orientationCallback != nullptr)
|
||||
Kore::Application::the()->orientationCallback(convertOrientation([[UIDevice currentDevice] orientation]));
|
||||
[UIApplication sharedApplication].statusBarOrientation = convertAppleOrientation([[UIDevice currentDevice] orientation], [UIApplication
|
||||
sharedApplication].statusBarOrientation);
|
||||
KoreUpdateKeyboard();
|
||||
}
|
||||
*/
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
[glViewController setVisible:YES];
|
||||
kinc_internal_foreground_callback();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
kinc_internal_resume_callback();
|
||||
//[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
|
||||
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
kinc_internal_pause_callback();
|
||||
//[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
[glViewController setVisible:NO];
|
||||
kinc_internal_background_callback();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
kinc_internal_shutdown_callback();
|
||||
}
|
||||
|
||||
//- (void)dealloc {
|
||||
// [window release];
|
||||
// [glView release];
|
||||
// [super dealloc];
|
||||
//}
|
||||
|
||||
@end
|
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="qVO-8e-Oj3"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="Y9C-1R-Fay"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="0" green="0" blue="0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
223
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h
Normal file
223
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/audio.m.h
Normal file
@ -0,0 +1,223 @@
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <kinc/audio2/audio.h>
|
||||
#include <kinc/backend/video.h>
|
||||
#include <kinc/math/core.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define kOutputBus 0
|
||||
|
||||
static kinc_internal_video_sound_stream_t *video = NULL;
|
||||
|
||||
void iosPlayVideoSoundStream(kinc_internal_video_sound_stream_t *v) {
|
||||
video = v;
|
||||
}
|
||||
|
||||
void iosStopVideoSoundStream(void) {
|
||||
video = NULL;
|
||||
}
|
||||
|
||||
static void affirm(OSStatus err) {
|
||||
if (err) {
|
||||
fprintf(stderr, "Error: %i\n", (int)err);
|
||||
}
|
||||
}
|
||||
|
||||
static bool initialized;
|
||||
static bool soundPlaying;
|
||||
static AudioStreamBasicDescription deviceFormat;
|
||||
static AudioComponentInstance audioUnit;
|
||||
static bool isFloat = false;
|
||||
static bool isInterleaved = true;
|
||||
|
||||
static kinc_a2_buffer_t a2_buffer;
|
||||
|
||||
static void copySample(void *buffer, void *secondary_buffer) {
|
||||
float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location];
|
||||
float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location];
|
||||
a2_buffer.read_location += 1;
|
||||
if (a2_buffer.read_location >= a2_buffer.data_size) {
|
||||
a2_buffer.read_location = 0;
|
||||
}
|
||||
|
||||
if (video != NULL) {
|
||||
float *frame = kinc_internal_video_sound_stream_next_frame(video);
|
||||
left_value += frame[0];
|
||||
left_value = kinc_max(kinc_min(left_value, 1.0f), -1.0f);
|
||||
right_value += frame[1];
|
||||
right_value = kinc_max(kinc_min(right_value, 1.0f), -1.0f);
|
||||
if (kinc_internal_video_sound_stream_ended(video)) {
|
||||
video = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (secondary_buffer == NULL) {
|
||||
if (isFloat) {
|
||||
((float *)buffer)[0] = left_value;
|
||||
((float *)buffer)[1] = right_value;
|
||||
}
|
||||
else {
|
||||
((int16_t *)buffer)[0] = (int16_t)(left_value * 32767);
|
||||
((int16_t *)buffer)[1] = (int16_t)(right_value * 32767);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isFloat) {
|
||||
*(float *)buffer = left_value;
|
||||
*(float *)secondary_buffer = right_value;
|
||||
}
|
||||
else {
|
||||
*(int16_t *)buffer = (int16_t)(left_value * 32767);
|
||||
*(int16_t *)secondary_buffer = (int16_t)(right_value * 32767);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static OSStatus renderInput(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber,
|
||||
UInt32 inNumberFrames, AudioBufferList *outOutputData) {
|
||||
kinc_a2_internal_callback(&a2_buffer, inNumberFrames);
|
||||
if (isInterleaved) {
|
||||
if (isFloat) {
|
||||
float *output = (float *)outOutputData->mBuffers[0].mData;
|
||||
for (int i = 0; i < inNumberFrames; ++i) {
|
||||
copySample(output, NULL);
|
||||
output += 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int16_t *output = (int16_t *)outOutputData->mBuffers[0].mData;
|
||||
for (int i = 0; i < inNumberFrames; ++i) {
|
||||
copySample(output, NULL);
|
||||
output += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isFloat) {
|
||||
float *out1 = (float *)outOutputData->mBuffers[0].mData;
|
||||
float *out2 = (float *)outOutputData->mBuffers[1].mData;
|
||||
for (int i = 0; i < inNumberFrames; ++i) {
|
||||
copySample(out1++, out2++);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int16_t *out1 = (int16_t *)outOutputData->mBuffers[0].mData;
|
||||
int16_t *out2 = (int16_t *)outOutputData->mBuffers[1].mData;
|
||||
for (int i = 0; i < inNumberFrames; ++i) {
|
||||
copySample(out1++, out2++);
|
||||
}
|
||||
}
|
||||
}
|
||||
return noErr;
|
||||
}
|
||||
|
||||
static uint32_t samples_per_second = 44100;
|
||||
|
||||
static void sampleRateListener(void *inRefCon, AudioUnit inUnit, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement) {
|
||||
Float64 sampleRate;
|
||||
UInt32 size = sizeof(sampleRate);
|
||||
affirm(AudioUnitGetProperty(inUnit, kAudioUnitProperty_SampleRate, kAudioUnitScope_Output, 0, &sampleRate, &size));
|
||||
|
||||
if (samples_per_second != (uint32_t)sampleRate) {
|
||||
samples_per_second = (uint32_t)sampleRate;
|
||||
kinc_a2_internal_sample_rate_callback();
|
||||
}
|
||||
}
|
||||
|
||||
static bool initialized = false;
|
||||
|
||||
void kinc_a2_init(void) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
kinc_a2_internal_init();
|
||||
initialized = true;
|
||||
|
||||
a2_buffer.read_location = 0;
|
||||
a2_buffer.write_location = 0;
|
||||
a2_buffer.data_size = 128 * 1024;
|
||||
a2_buffer.channel_count = 2;
|
||||
a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float));
|
||||
a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float));
|
||||
|
||||
initialized = false;
|
||||
|
||||
AudioComponentDescription desc;
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_RemoteIO;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
|
||||
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
|
||||
|
||||
// Get audio units
|
||||
affirm(AudioComponentInstanceNew(comp, &audioUnit));
|
||||
UInt32 flag = 1;
|
||||
affirm(AudioUnitSetProperty(audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, kOutputBus, &flag, sizeof(UInt32)));
|
||||
|
||||
if (soundPlaying)
|
||||
return;
|
||||
|
||||
affirm(AudioOutputUnitStart(audioUnit));
|
||||
|
||||
UInt32 size = sizeof(AudioStreamBasicDescription);
|
||||
affirm(AudioUnitGetProperty(audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &deviceFormat, &size));
|
||||
|
||||
if (deviceFormat.mFormatID != kAudioFormatLinearPCM) {
|
||||
fprintf(stderr, "mFormatID != kAudioFormatLinearPCM\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (deviceFormat.mFormatFlags & kLinearPCMFormatFlagIsFloat) {
|
||||
isFloat = true;
|
||||
}
|
||||
|
||||
if (deviceFormat.mFormatFlags & kAudioFormatFlagIsNonInterleaved) {
|
||||
isInterleaved = false;
|
||||
}
|
||||
|
||||
AudioUnitAddPropertyListener(audioUnit, kAudioUnitProperty_StreamFormat, sampleRateListener, nil);
|
||||
|
||||
initialized = true;
|
||||
|
||||
printf("mSampleRate = %g\n", deviceFormat.mSampleRate);
|
||||
printf("mFormatFlags = %08X\n", (unsigned int)deviceFormat.mFormatFlags);
|
||||
printf("mBytesPerPacket = %d\n", (unsigned int)deviceFormat.mBytesPerPacket);
|
||||
printf("mFramesPerPacket = %d\n", (unsigned int)deviceFormat.mFramesPerPacket);
|
||||
printf("mChannelsPerFrame = %d\n", (unsigned int)deviceFormat.mChannelsPerFrame);
|
||||
printf("mBytesPerFrame = %d\n", (unsigned int)deviceFormat.mBytesPerFrame);
|
||||
printf("mBitsPerChannel = %d\n", (unsigned int)deviceFormat.mBitsPerChannel);
|
||||
|
||||
if (samples_per_second != (uint32_t)deviceFormat.mSampleRate) {
|
||||
samples_per_second = (uint32_t)deviceFormat.mSampleRate;
|
||||
kinc_a2_internal_sample_rate_callback();
|
||||
}
|
||||
|
||||
AURenderCallbackStruct callbackStruct;
|
||||
callbackStruct.inputProc = renderInput;
|
||||
callbackStruct.inputProcRefCon = NULL;
|
||||
affirm(AudioUnitSetProperty(audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Global, kOutputBus, &callbackStruct, sizeof(callbackStruct)));
|
||||
|
||||
soundPlaying = true;
|
||||
}
|
||||
|
||||
void kinc_a2_update(void) {}
|
||||
|
||||
void kinc_a2_shutdown(void) {
|
||||
if (!initialized)
|
||||
return;
|
||||
if (!soundPlaying)
|
||||
return;
|
||||
|
||||
affirm(AudioOutputUnitStop(audioUnit));
|
||||
|
||||
soundPlaying = false;
|
||||
}
|
||||
|
||||
uint32_t kinc_a2_samples_per_second(void) {
|
||||
return samples_per_second;
|
||||
}
|
12
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/display.h
Normal file
12
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/display.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace Kore {
|
||||
namespace Display {
|
||||
int count();
|
||||
int x(int index);
|
||||
int y(int index);
|
||||
int height(int index);
|
||||
int width(int index);
|
||||
bool isPrimary(int index);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include <kinc/display.h>
|
||||
#include <kinc/log.h>
|
||||
|
||||
void kinc_display_init(void) {}
|
||||
|
||||
kinc_display_mode_t kinc_display_available_mode(int display, int mode) {
|
||||
kinc_display_mode_t dm;
|
||||
dm.width = kinc_window_width(0);
|
||||
dm.height = kinc_window_height(0);
|
||||
dm.frequency = 60;
|
||||
dm.bits_per_pixel = 32;
|
||||
return dm;
|
||||
}
|
||||
|
||||
int kinc_display_count_available_modes(int display) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool kinc_display_available(int display) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *kinc_display_name(int display) {
|
||||
return "Display";
|
||||
}
|
||||
|
||||
kinc_display_mode_t kinc_display_current_mode(int display) {
|
||||
kinc_display_mode_t dm;
|
||||
dm.width = kinc_window_width(0);
|
||||
dm.height = kinc_window_height(0);
|
||||
dm.frequency = (int)[[UIScreen mainScreen] maximumFramesPerSecond];
|
||||
dm.bits_per_pixel = 32;
|
||||
return dm;
|
||||
}
|
||||
|
||||
int kinc_count_displays(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int kinc_primary_display(void) {
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
struct DisplayData {
|
||||
DisplayData();
|
||||
};
|
49
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/ios.plist
Normal file
49
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/ios.plist
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(BUNDLE_VERSION)</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(BUILD_VERSION)</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
@ -0,0 +1,9 @@
|
||||
#include "GLView.m.h"
|
||||
#include "GLViewController.m.h"
|
||||
#include "KoreAppDelegate.m.h"
|
||||
#include "audio.m.h"
|
||||
#include "display.m.h"
|
||||
#include "motion.m.h"
|
||||
#include "mouse.c.h"
|
||||
#include "system.m.h"
|
||||
#include "window.c.h"
|
11
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/motion.h
Normal file
11
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/motion.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#import <UIKit/UIKit.h>
|
||||
// #include <Kt/Input/GyroHandler.h>
|
||||
|
||||
@interface Motion : NSObject <UIAccelerometerDelegate> {
|
||||
// Kt::GyroHandler* gyroHandler;
|
||||
}
|
||||
|
||||
// + (Motion*)the;
|
||||
|
||||
@end
|
26
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/motion.m.h
Normal file
26
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/motion.m.h
Normal file
@ -0,0 +1,26 @@
|
||||
#import "motion.h"
|
||||
|
||||
@implementation Motion
|
||||
/*
|
||||
Motion* the = [[Motion alloc]init];
|
||||
+ (Motion*) the {return the;};
|
||||
|
||||
-(void)configureAccelerometerWithGyroHandler: (Kt::GyroHandler*) gyroHandler
|
||||
AndUpdateInterval: (int) updateInterval
|
||||
{
|
||||
UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer];
|
||||
accelerometer.updateInterval = 1 / updateInterval;
|
||||
|
||||
accelerometer.delegate = self;
|
||||
self->gyroHandler = gyroHandler;
|
||||
}
|
||||
|
||||
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
|
||||
//gyroHandler->updateAccelerometerData(acceleration.x, acceleration.y, acceleration.z);
|
||||
}
|
||||
|
||||
void Kt::GyroHandler::configAccelerometer(int updateInterval){
|
||||
[[Motion the]configureAccelerometerWithGyroHandler:this AndUpdateInterval:updateInterval];
|
||||
};
|
||||
*/
|
||||
@end
|
19
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/mouse.c.h
Normal file
19
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/mouse.c.h
Normal file
@ -0,0 +1,19 @@
|
||||
#include <kinc/input/mouse.h>
|
||||
|
||||
void kinc_internal_mouse_lock(int window) {}
|
||||
|
||||
void kinc_internal_mouse_unlock(void) {}
|
||||
|
||||
bool kinc_mouse_can_lock(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void kinc_mouse_show(void) {}
|
||||
|
||||
void kinc_mouse_hide(void) {}
|
||||
|
||||
void kinc_mouse_set_position(int window, int x, int y) {}
|
||||
|
||||
void kinc_mouse_get_position(int window, int *x, int *y) {}
|
||||
|
||||
void kinc_mouse_set_cursor(int cursor_index) {}
|
191
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h
Normal file
191
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/system.m.h
Normal file
@ -0,0 +1,191 @@
|
||||
#import "KoreAppDelegate.h"
|
||||
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/input/gamepad.h>
|
||||
#include <kinc/input/keyboard.h>
|
||||
#include <kinc/system.h>
|
||||
#include <kinc/video.h>
|
||||
#include <kinc/window.h>
|
||||
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
bool withAutoreleasepool(bool (*f)(void)) {
|
||||
@autoreleasepool {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
||||
static bool keyboardshown = false;
|
||||
|
||||
const char *iphonegetresourcepath(void) {
|
||||
return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:1];
|
||||
}
|
||||
|
||||
bool kinc_internal_handle_messages(void) {
|
||||
SInt32 result;
|
||||
do {
|
||||
result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
|
||||
} while (result == kCFRunLoopRunHandledSource);
|
||||
return true;
|
||||
}
|
||||
|
||||
void kinc_set_keep_screen_on(bool on) {}
|
||||
|
||||
void showKeyboard(void);
|
||||
void hideKeyboard(void);
|
||||
|
||||
void kinc_keyboard_show(void) {
|
||||
keyboardshown = true;
|
||||
showKeyboard();
|
||||
}
|
||||
|
||||
void kinc_keyboard_hide(void) {
|
||||
keyboardshown = false;
|
||||
hideKeyboard();
|
||||
}
|
||||
|
||||
bool kinc_keyboard_active(void) {
|
||||
return keyboardshown;
|
||||
}
|
||||
|
||||
void loadURL(const char *url);
|
||||
|
||||
void kinc_load_url(const char *url) {
|
||||
loadURL(url);
|
||||
}
|
||||
|
||||
// On iOS you can't set the length of the vibration.
|
||||
void kinc_vibrate(int ms) {
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
};
|
||||
|
||||
static char language[3];
|
||||
|
||||
const char *kinc_language(void) {
|
||||
NSString *nsstr = [[NSLocale preferredLanguages] objectAtIndex:0];
|
||||
const char *lang = [nsstr UTF8String];
|
||||
language[0] = lang[0];
|
||||
language[1] = lang[1];
|
||||
language[2] = 0;
|
||||
return language;
|
||||
}
|
||||
|
||||
// called on rotation event
|
||||
void KoreUpdateKeyboard(void) {
|
||||
if (keyboardshown) {
|
||||
hideKeyboard();
|
||||
showKeyboard();
|
||||
}
|
||||
else {
|
||||
hideKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef KINC_KONG
|
||||
void kong_init(void);
|
||||
#endif
|
||||
|
||||
void kinc_internal_shutdown(void) {}
|
||||
|
||||
int kinc_init(const char *name, int width, int height, struct kinc_window_options *win, struct kinc_framebuffer_options *frame) {
|
||||
kinc_window_options_t defaultWin;
|
||||
if (win == NULL) {
|
||||
kinc_window_options_set_defaults(&defaultWin);
|
||||
win = &defaultWin;
|
||||
}
|
||||
kinc_framebuffer_options_t defaultFrame;
|
||||
if (frame == NULL) {
|
||||
kinc_framebuffer_options_set_defaults(&defaultFrame);
|
||||
frame = &defaultFrame;
|
||||
}
|
||||
kinc_g4_internal_init();
|
||||
kinc_g4_internal_init_window(0, frame->depth_bits, frame->stencil_bits, true);
|
||||
|
||||
#ifdef KINC_KONG
|
||||
kong_init();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void endGL(void);
|
||||
|
||||
void swapBuffersiOS(void) {
|
||||
endGL();
|
||||
}
|
||||
|
||||
static char sysid[512];
|
||||
|
||||
const char *kinc_system_id(void) {
|
||||
const char *name = [[[UIDevice currentDevice] name] UTF8String];
|
||||
const char *vendorId = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] UTF8String];
|
||||
strcpy(sysid, name);
|
||||
strcat(sysid, "-");
|
||||
strcat(sysid, vendorId);
|
||||
return sysid;
|
||||
}
|
||||
|
||||
static const char *getSavePath(void) {
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSString *resolvedPath = [paths objectAtIndex:0];
|
||||
NSString *appName = [NSString stringWithUTF8String:kinc_application_name()];
|
||||
resolvedPath = [resolvedPath stringByAppendingPathComponent:appName];
|
||||
|
||||
NSFileManager *fileMgr = [[NSFileManager alloc] init];
|
||||
|
||||
NSError *error;
|
||||
[fileMgr createDirectoryAtPath:resolvedPath withIntermediateDirectories:YES attributes:nil error:&error];
|
||||
|
||||
resolvedPath = [resolvedPath stringByAppendingString:@"/"];
|
||||
return [resolvedPath cStringUsingEncoding:1];
|
||||
}
|
||||
|
||||
const char *kinc_internal_save_path(void) {
|
||||
return getSavePath();
|
||||
}
|
||||
|
||||
static const char *videoFormats[] = {"mp4", NULL};
|
||||
|
||||
const char **kinc_video_formats(void) {
|
||||
return videoFormats;
|
||||
}
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
double kinc_frequency(void) {
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
return (double)info.denom / (double)info.numer / 1e-9;
|
||||
}
|
||||
|
||||
kinc_ticks_t kinc_timestamp(void) {
|
||||
kinc_ticks_t time = mach_absolute_time();
|
||||
return time;
|
||||
}
|
||||
|
||||
void kinc_login(void) {}
|
||||
|
||||
void kinc_unlock_achievement(int id) {}
|
||||
|
||||
const char *kinc_gamepad_vendor(int gamepad) {
|
||||
return "nobody";
|
||||
}
|
||||
|
||||
const char *kinc_gamepad_product_name(int gamepad) {
|
||||
return "none";
|
||||
}
|
||||
|
||||
bool kinc_gamepad_connected(int num) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void kinc_gamepad_rumble(int gamepad, float left, float right) {}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int retVal = 0;
|
||||
@autoreleasepool {
|
||||
[KoreAppDelegate description]; // otherwise removed by the linker
|
||||
retVal = UIApplicationMain(argc, argv, nil, @"KoreAppDelegate");
|
||||
}
|
||||
return retVal;
|
||||
}
|
71
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h
Normal file
71
Kha/Kinc/Backends/System/iOS/Sources/kinc/backend/window.c.h
Normal file
@ -0,0 +1,71 @@
|
||||
#include <kinc/display.h>
|
||||
#include <kinc/graphics4/graphics.h>
|
||||
#include <kinc/window.h>
|
||||
|
||||
static void (*resizeCallback)(int x, int y, void *data) = NULL;
|
||||
static void *resizeCallbackData = NULL;
|
||||
|
||||
int kinc_window_x(int window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kinc_window_y(int window) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int kinc_count_windows(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void kinc_window_resize(int window, int width, int height) {}
|
||||
|
||||
void kinc_window_move(int window, int x, int y) {}
|
||||
|
||||
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame);
|
||||
|
||||
void kinc_window_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {
|
||||
kinc_internal_change_framebuffer(0, frame);
|
||||
}
|
||||
|
||||
#ifdef KINC_METAL
|
||||
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {}
|
||||
#endif
|
||||
|
||||
void kinc_window_change_features(int window, int features) {}
|
||||
|
||||
void kinc_window_change_mode(int window, kinc_window_mode_t mode) {}
|
||||
|
||||
void kinc_window_destroy(int window) {}
|
||||
|
||||
void kinc_window_show(int window) {}
|
||||
|
||||
void kinc_window_hide(int window) {}
|
||||
|
||||
void kinc_window_set_title(int window, const char *title) {}
|
||||
|
||||
int kinc_window_create(kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kinc_window_set_resize_callback(int window, void (*callback)(int x, int y, void *data), void *data) {
|
||||
resizeCallback = callback;
|
||||
resizeCallbackData = data;
|
||||
}
|
||||
|
||||
void kinc_internal_call_resize_callback(int window, int width, int height) {
|
||||
if (resizeCallback != NULL) {
|
||||
resizeCallback(width, height, resizeCallbackData);
|
||||
}
|
||||
}
|
||||
|
||||
void kinc_window_set_ppi_changed_callback(int window, void (*callback)(int ppi, void *data), void *data) {}
|
||||
|
||||
void kinc_window_set_close_callback(int window, bool (*callback)(void *), void *data) {}
|
||||
|
||||
kinc_window_mode_t kinc_window_get_mode(int window) {
|
||||
return KINC_WINDOW_MODE_FULLSCREEN;
|
||||
}
|
||||
|
||||
int kinc_window_display(int window) {
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
struct WindowData {
|
||||
WindowData();
|
||||
};
|
Reference in New Issue
Block a user