From 272882d7961ea2cfe38c2e6e9bf5d70f3fcd1385 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Wed, 6 Feb 2013 20:40:30 +0000 Subject: [PATCH] ios stuff --- iOS/CustomGLKView.h | 8 +- iOS/CustomGLKView.m | 72 ------------ iOS/CustomGLKView.mm | 13 +++ iOS/ViewController.h | 6 +- iOS/ViewController.m | 111 ------------------- iOS/ViewController.mm | 31 ++++++ iOS/ios_api.cpp | 51 +-------- iOS/ios_api.h | 17 +-- iOS/salmontemplate.xcodeproj/project.pbxproj | 16 +-- jni/main_code.cpp | 2 +- jni/main_code.h | 2 +- 11 files changed, 63 insertions(+), 266 deletions(-) delete mode 100644 iOS/CustomGLKView.m create mode 100644 iOS/CustomGLKView.mm delete mode 100644 iOS/ViewController.m create mode 100644 iOS/ViewController.mm diff --git a/iOS/CustomGLKView.h b/iOS/CustomGLKView.h index 59184d3..77acd11 100644 --- a/iOS/CustomGLKView.h +++ b/iOS/CustomGLKView.h @@ -6,12 +6,8 @@ // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // -#import +#import "include/Utils/IosApi/ObjC/GLKViewTemplate.h" -@interface CustomGLKView : GLKView - -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; +@interface CustomGLKView : GLKViewTemplate @end diff --git a/iOS/CustomGLKView.m b/iOS/CustomGLKView.m deleted file mode 100644 index 3fc8e01..0000000 --- a/iOS/CustomGLKView.m +++ /dev/null @@ -1,72 +0,0 @@ -// -// CustomGLKView.m -// doublehitballs -// -// Created by vvv ооо on 15.07.12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. -// - -#import "CustomGLKView.h" -#import "ios_api.h" - -bool touchMoved = false; -CGPoint prev_loc; - - -@implementation CustomGLKView - -- (id)initWithFrame:(CGRect)frame -{ - self = [super initWithFrame:frame]; - if (self) { - // Initialization code - } - return self; -} - - -- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event -{ - - CGPoint location = [[[touches allObjects] objectAtIndex:0] locationInView:self]; - - prev_loc = location; - - touchMoved = false; - - AppOnTapDown(location.x, self.bounds.size.height - location.y); - -} - -- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event -{ - CGPoint location = [[[touches allObjects] objectAtIndex:0] locationInView:self]; - - CGPoint prevLocation = [[[touches allObjects] objectAtIndex:0] previousLocationInView:self]; - - if (abs(prev_loc.x - location.x) > 10 || abs(prev_loc.y - location.y) > 10) - { - touchMoved = true; - } - - AppOnScroll(prevLocation.x - location.x, -(prevLocation.y - location.y)); -} - -- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event -{ - CGPoint location = [[[touches allObjects] objectAtIndex:0] locationInView:self]; - - if (touchMoved) - { - AppOnTapUpAfterScroll(location.x, self.bounds.size.height - location.y); - } - else - { - AppOnTapUp(location.x, self.bounds.size.height - location.y); - } -} - - - - -@end diff --git a/iOS/CustomGLKView.mm b/iOS/CustomGLKView.mm new file mode 100644 index 0000000..db5690f --- /dev/null +++ b/iOS/CustomGLKView.mm @@ -0,0 +1,13 @@ +// +// CustomGLKView.m +// doublehitballs +// +// Created by vvv ооо on 15.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "CustomGLKView.h" + +@implementation CustomGLKView + +@end diff --git a/iOS/ViewController.h b/iOS/ViewController.h index e7f9748..ec4f6cd 100644 --- a/iOS/ViewController.h +++ b/iOS/ViewController.h @@ -6,9 +6,9 @@ // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // -#import -#import -@interface ViewController : GLKViewController +#import "include/Utils/IosApi/ObjC/ViewControllerTemplate.h" + +@interface ViewController : ViewControllerTemplate @end diff --git a/iOS/ViewController.m b/iOS/ViewController.m deleted file mode 100644 index 2c92f8d..0000000 --- a/iOS/ViewController.m +++ /dev/null @@ -1,111 +0,0 @@ -// -// ViewController.m -// doublehitballs -// -// Created by vvv ооо on 13.07.12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. -// - -#import "ViewController.h" -#import "ios_api.h" - - -extern GLKView* defaultView; - -@interface ViewController () { -} - -@property (strong, nonatomic) EAGLContext *context; -@property (strong, nonatomic) GLKBaseEffect *effect; - -- (void)setupGL; -- (void)tearDownGL; - -@end - -@implementation ViewController - -@synthesize context = _context; -@synthesize effect = _effect; - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - - if (!self.context) { - NSLog(@"Failed to create ES context"); - } - - GLKView *view = (GLKView *)self.view; - view.context = self.context; - view.drawableDepthFormat = GLKViewDrawableDepthFormat24; - - defaultView = view; - - [self setupGL]; -} - -- (void)viewDidUnload -{ - [super viewDidUnload]; - - [self tearDownGL]; - - if ([EAGLContext currentContext] == self.context) { - [EAGLContext setCurrentContext:nil]; - } - self.context = nil; -} - -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Release any cached data, images, etc. that aren't in use. -} - -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - /* - if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { - return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); - } else { - return YES; - }*/ - //return UIInterfaceOrientationIsLandscape(interfaceOrientation); - return UIInterfaceOrientationIsPortrait(interfaceOrientation); -} - -- (void)setupGL -{ - [EAGLContext setCurrentContext:self.context]; - - AppInit(); - } - -- (void)tearDownGL -{ - [EAGLContext setCurrentContext:self.context]; - - AppDeinit(); - -} - -#pragma mark - GLKView and GLKViewController delegate methods - -- (void)update -{ - - AppUpdate(self.timeSinceLastUpdate * 1000); -} - -- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect -{ - - AppDraw(); - -} - - -@end diff --git a/iOS/ViewController.mm b/iOS/ViewController.mm new file mode 100644 index 0000000..2b88e2b --- /dev/null +++ b/iOS/ViewController.mm @@ -0,0 +1,31 @@ +// +// ViewController.m +// doublehitballs +// +// Created by vvv ооо on 13.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "ViewController.h" +#import "ios_api.h" + + +@interface ViewController () { +} +@end + +@implementation ViewController + + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation +{ + return UIInterfaceOrientationIsPortrait(interfaceOrientation); +} + + +- (void) appInitCaller +{ + CustomAppInit(); +} + +@end diff --git a/iOS/ios_api.cpp b/iOS/ios_api.cpp index 92380de..9f4dbb2 100644 --- a/iOS/ios_api.cpp +++ b/iOS/ios_api.cpp @@ -1,56 +1,9 @@ #include "include/Engine.h" #include "main_code.h" -TMyApplication* App; - -extern "C" void AppInit() +void CustomAppInit() { - CreateEngine(); - App = new TMyApplication; - App->OuterInit(320, 480, 320, 480); - -} - -extern "C" void AppDeinit() -{ - - App->OuterDeinit(); - delete App; - DestroyEngine(); - -} - - -extern "C" void AppUpdate(int dt) -{ - App->OuterUpdate(dt); -} - - - -extern "C" void AppDraw() -{ - App->OuterDraw(); -} - -extern "C" void AppOnTapDown(int posx, int posy) -{ - App->OuterOnTapDown(vec2(posx, posy)); -} - -extern "C" void AppOnTapUp(int posx, int posy) -{ - App->OuterOnTapUp(vec2(posx, posy)); -} - -extern "C" void AppOnTapUpAfterScroll(int posx, int posy) -{ - App->OuterOnTapUpAfterShift(vec2(posx, posy)); -} - -extern "C" void AppOnScroll(int shiftx, int shifty) -{ - App->OuterOnMove(vec2(shiftx, shifty)); + AppInit(320, 480); } diff --git a/iOS/ios_api.h b/iOS/ios_api.h index aa8d8bf..844fe7e 100644 --- a/iOS/ios_api.h +++ b/iOS/ios_api.h @@ -1,16 +1,3 @@ -// -// Header.h -// doublehitballs -// -// Created by vvv ооо on 15.07.12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. -// +#include "include/Utils/IosApi/IosWrapper.h" -void AppInit(); -void AppDeinit(); -void AppUpdate(int dt); -void AppDraw(); -void AppOnTapDown(int posx, int posy); -void AppOnTapUp(int posx, int posy); -void AppOnTapUpAfterScroll(int posx, int posy); -void AppOnScroll(int shiftx, int shifty); \ No newline at end of file +void CustomAppInit(); diff --git a/iOS/salmontemplate.xcodeproj/project.pbxproj b/iOS/salmontemplate.xcodeproj/project.pbxproj index 2d30973..3d6aa00 100644 --- a/iOS/salmontemplate.xcodeproj/project.pbxproj +++ b/iOS/salmontemplate.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 4C49B2CC15B0991B003512CD /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4C49B2CA15B0991B003512CD /* InfoPlist.strings */; }; 4C49B2CE15B0991B003512CD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C49B2CD15B0991B003512CD /* main.m */; }; 4C49B2D215B0991B003512CD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C49B2D115B0991B003512CD /* AppDelegate.m */; }; - 4C49B2D915B0991B003512CD /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C49B2D815B0991B003512CD /* ViewController.m */; }; + 4C49B2D915B0991B003512CD /* ViewController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4C49B2D815B0991B003512CD /* ViewController.mm */; }; 4C49B2DC15B0991B003512CD /* ViewController_iPhone.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C49B2DA15B0991B003512CD /* ViewController_iPhone.xib */; }; 4C49B2DF15B0991B003512CD /* ViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4C49B2DD15B0991B003512CD /* ViewController_iPad.xib */; }; 4C4C807515BA8F460037C6CE /* libsquirrel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C4C807415BA8F460037C6CE /* libsquirrel.a */; }; @@ -31,7 +31,7 @@ 4C7AD44C15B1D77700A599F6 /* ios_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C7AD44B15B1D77700A599F6 /* ios_api.cpp */; }; 4C7C584B15C31E6500CAE4F4 /* libboost.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C7C584A15C31E6500CAE4F4 /* libboost.a */; }; 4CC971AC15C57DCE00359A2B /* libSalmon Engine.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C902A7815C5735700FBC901 /* libSalmon Engine.a */; }; - 4CCC0ECC15B30D6B005432FB /* CustomGLKView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CCC0ECB15B30D6B005432FB /* CustomGLKView.m */; }; + 4CCC0ECC15B30D6B005432FB /* CustomGLKView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CCC0ECB15B30D6B005432FB /* CustomGLKView.mm */; }; 4CE6A9D215B2F979006A3965 /* assets in Resources */ = {isa = PBXBuildFile; fileRef = 4CE6A9D115B2F979006A3965 /* assets */; }; /* End PBXBuildFile section */ @@ -59,7 +59,7 @@ 4C49B2D015B0991B003512CD /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 4C49B2D115B0991B003512CD /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 4C49B2D715B0991B003512CD /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 4C49B2D815B0991B003512CD /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 4C49B2D815B0991B003512CD /* ViewController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewController.mm; sourceTree = ""; }; 4C49B2DB15B0991B003512CD /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPhone.xib; sourceTree = ""; }; 4C49B2DE15B0991B003512CD /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController_iPad.xib; sourceTree = ""; }; 4C4C807415BA8F460037C6CE /* libsquirrel.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libsquirrel.a; path = "../../libs/SQUIRREL2_1_1_sqplus/build-ios/ios-device/libsquirrel.a"; sourceTree = ""; }; @@ -77,7 +77,7 @@ 4C7C584A15C31E6500CAE4F4 /* libboost.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libboost.a; path = "../../libs/boost_1_47_0/build-ios/ios-simulator/libboost.a"; sourceTree = ""; }; 4C902A7015C5735500FBC901 /* Salmon Engine.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "Salmon Engine.xcodeproj"; path = "../../Engine/iOS/Salmon Engine/Salmon Engine.xcodeproj"; sourceTree = ""; }; 4CCC0ECA15B30D6A005432FB /* CustomGLKView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomGLKView.h; sourceTree = ""; }; - 4CCC0ECB15B30D6B005432FB /* CustomGLKView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomGLKView.m; sourceTree = ""; }; + 4CCC0ECB15B30D6B005432FB /* CustomGLKView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CustomGLKView.mm; sourceTree = ""; }; 4CCC0ECD15B310FB005432FB /* ios_api.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ios_api.h; sourceTree = ""; }; 4CE6A9D115B2F979006A3965 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = ../assets; sourceTree = ""; }; /* End PBXFileReference section */ @@ -149,12 +149,12 @@ 4C49B2D015B0991B003512CD /* AppDelegate.h */, 4C49B2D115B0991B003512CD /* AppDelegate.m */, 4C49B2D715B0991B003512CD /* ViewController.h */, - 4C49B2D815B0991B003512CD /* ViewController.m */, + 4C49B2D815B0991B003512CD /* ViewController.mm */, 4C49B2DA15B0991B003512CD /* ViewController_iPhone.xib */, 4C49B2DD15B0991B003512CD /* ViewController_iPad.xib */, 4C49B2C815B0991B003512CD /* Supporting Files */, 4CCC0ECA15B30D6A005432FB /* CustomGLKView.h */, - 4CCC0ECB15B30D6B005432FB /* CustomGLKView.m */, + 4CCC0ECB15B30D6B005432FB /* CustomGLKView.mm */, ); name = Sources; sourceTree = ""; @@ -295,9 +295,9 @@ files = ( 4C49B2CE15B0991B003512CD /* main.m in Sources */, 4C49B2D215B0991B003512CD /* AppDelegate.m in Sources */, - 4C49B2D915B0991B003512CD /* ViewController.m in Sources */, + 4C49B2D915B0991B003512CD /* ViewController.mm in Sources */, 4C7AD44C15B1D77700A599F6 /* ios_api.cpp in Sources */, - 4CCC0ECC15B30D6B005432FB /* CustomGLKView.m in Sources */, + 4CCC0ECC15B30D6B005432FB /* CustomGLKView.mm in Sources */, 4C74849815C5AF7C0056EC44 /* main_code.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/jni/main_code.cpp b/jni/main_code.cpp index 3adb619..36aef34 100644 --- a/jni/main_code.cpp +++ b/jni/main_code.cpp @@ -309,7 +309,7 @@ void TMyApplication::InnerOnTapUp(vec2 p) } } -void TMyApplication::InnerOnTapUpAfterShift(vec2 p) +void TMyApplication::InnerOnTapUpAfterMove(vec2 p) { RotateShift = vec2(0.f, 0.f); diff --git a/jni/main_code.h b/jni/main_code.h index 0d750bc..30f34c9 100644 --- a/jni/main_code.h +++ b/jni/main_code.h @@ -60,7 +60,7 @@ public: virtual void InnerOnMove(vec2 shift); virtual void InnerOnTapUp(vec2 p); - virtual void InnerOnTapUpAfterShift(vec2 p); + virtual void InnerOnTapUpAfterMove(vec2 p); virtual void OnMouseWheel(short int delta);