From 6ec81a421ece5a25fb6ae10005fdac55adfe18d7 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Wed, 6 Feb 2013 20:37:32 +0000 Subject: [PATCH] ios stuff --- .../Salmon Engine.xcodeproj/project.pbxproj | 40 +++++- include/SalmonEngineInterface.h | 6 +- include/SalmonEngineIos.h | 15 +++ include/Utils/IosApi/IosApi.h | 1 + include/Utils/IosApi/IosWrapper.h | 25 ++++ include/Utils/IosApi/ObjC/GLKViewTemplate.h | 23 ++++ .../IosApi/ObjC/ViewControllerTemplate.h | 18 +++ src/SalmonEngineInterface.cpp | 4 +- src/SalmonEngineIos.cpp | 61 ++++++++- src/Utils/IosApi/ObjC/GLKViewTemplate.mm | 71 +++++++++++ .../IosApi/ObjC/ViewControllerTemplate.mm | 119 ++++++++++++++++++ 11 files changed, 374 insertions(+), 9 deletions(-) create mode 100644 include/Utils/IosApi/IosWrapper.h create mode 100644 include/Utils/IosApi/ObjC/GLKViewTemplate.h create mode 100644 include/Utils/IosApi/ObjC/ViewControllerTemplate.h create mode 100644 src/Utils/IosApi/ObjC/GLKViewTemplate.mm create mode 100644 src/Utils/IosApi/ObjC/ViewControllerTemplate.mm diff --git a/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj b/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj index aab7783..f508b66 100644 --- a/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj +++ b/iOS/Salmon Engine/Salmon Engine.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 4C7AD45715B1E3D000A599F6 /* GlobalConst.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C7AD45515B1E3D000A599F6 /* GlobalConst.cpp */; }; 4C7AD45B15B1E3E300A599F6 /* ApplicationInterface.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C7AD45915B1E3E200A599F6 /* ApplicationInterface.h */; }; 4C7AD45C15B1E3E300A599F6 /* GlobalConst.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C7AD45A15B1E3E300A599F6 /* GlobalConst.h */; }; + 4C7BD6E716C28D3100BB8788 /* IosWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C7BD6E616C28D3100BB8788 /* IosWrapper.h */; }; 4C8CE90615B0A0F400078175 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C8CE90515B0A0F400078175 /* Foundation.framework */; }; 4C8CE91715B0A11A00078175 /* DataTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8CE91515B0A11A00078175 /* DataTypes.h */; }; 4C8CE91815B0A11A00078175 /* NewDataTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C8CE91615B0A11A00078175 /* NewDataTypes.h */; }; @@ -77,6 +78,10 @@ 4CD18A1A16727C3F00EDC335 /* SmartValueManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CD18A1916727C3F00EDC335 /* SmartValueManager.cpp */; }; 4CD18A1E16727C4E00EDC335 /* SmartValueManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CD18A1D16727C4E00EDC335 /* SmartValueManager.h */; }; 4CD18A2016727D4A00EDC335 /* BindableVar.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CD18A1F16727D4A00EDC335 /* BindableVar.h */; }; + 4CD41A2916C2D23C0071E598 /* GLKViewTemplate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CD41A2616C2D23C0071E598 /* GLKViewTemplate.h */; }; + 4CD41A2A16C2D23C0071E598 /* ViewControllerTemplate.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CD41A2716C2D23C0071E598 /* ViewControllerTemplate.h */; }; + 4CD41A3116C2D2490071E598 /* GLKViewTemplate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CD41A2E16C2D2490071E598 /* GLKViewTemplate.mm */; }; + 4CD41A3216C2D2490071E598 /* ViewControllerTemplate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4CD41A2F16C2D2490071E598 /* ViewControllerTemplate.mm */; }; 4CEE2DD215CDC55B00C4D5F5 /* SalmonRenderGLES20.h in Headers */ = {isa = PBXBuildFile; fileRef = 4CEE2DD115CDC55B00C4D5F5 /* SalmonRenderGLES20.h */; }; 4CEE2DD515CDC57200C4D5F5 /* SalmonRenderGLES20.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CEE2DD415CDC57200C4D5F5 /* SalmonRenderGLES20.cpp */; }; 4CF8747916B65210009B1214 /* ButtonWidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4CF8747616B65210009B1214 /* ButtonWidget.cpp */; }; @@ -110,6 +115,7 @@ 4C7AD45515B1E3D000A599F6 /* GlobalConst.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GlobalConst.cpp; path = ../../../src/GlobalConst.cpp; sourceTree = ""; }; 4C7AD45915B1E3E200A599F6 /* ApplicationInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ApplicationInterface.h; path = ../../../include/ApplicationInterface.h; sourceTree = ""; }; 4C7AD45A15B1E3E300A599F6 /* GlobalConst.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GlobalConst.h; path = ../../../include/GlobalConst.h; sourceTree = ""; }; + 4C7BD6E616C28D3100BB8788 /* IosWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IosWrapper.h; sourceTree = ""; }; 4C8CE90215B0A0F400078175 /* libSalmon Engine.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libSalmon Engine.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 4C8CE90515B0A0F400078175 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 4C8CE91515B0A11A00078175 /* DataTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataTypes.h; sourceTree = ""; }; @@ -158,7 +164,7 @@ 4CBC58AB16BE9D8200B30DB2 /* ThreadUtilsImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadUtilsImpl.h; path = ../../../include/Utils/ThreadUtilsImpl.h; sourceTree = ""; }; 4CBC58AF16BE9D9B00B30DB2 /* ThreadUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ThreadUtils.cpp; path = ../../../src/Utils/ThreadUtils.cpp; sourceTree = ""; }; 4CC1FC3C15B20E440025C6F7 /* IosApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IosApi.h; sourceTree = ""; }; - 4CC1FC3F15B20E5D0025C6F7 /* IosApi.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = IosApi.mm; sourceTree = ""; }; + 4CC1FC3F15B20E5D0025C6F7 /* IosApi.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = IosApi.mm; path = ../IosApi.mm; sourceTree = ""; }; 4CC857CC1693865C00110F77 /* NewModelManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewModelManager.cpp; sourceTree = ""; }; 4CC857CF1693867D00110F77 /* RenderParams.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderParams.cpp; path = ../../../src/Render/RenderParams.cpp; sourceTree = ""; }; 4CC857D1169386A300110F77 /* RenderParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RenderParams.h; path = ../../../include/Render/RenderParams.h; sourceTree = ""; }; @@ -166,6 +172,10 @@ 4CD18A1916727C3F00EDC335 /* SmartValueManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmartValueManager.cpp; sourceTree = ""; }; 4CD18A1D16727C4E00EDC335 /* SmartValueManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartValueManager.h; sourceTree = ""; }; 4CD18A1F16727D4A00EDC335 /* BindableVar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BindableVar.h; path = ../../../include/Utils/BindableVar.h; sourceTree = ""; }; + 4CD41A2616C2D23C0071E598 /* GLKViewTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLKViewTemplate.h; sourceTree = ""; }; + 4CD41A2716C2D23C0071E598 /* ViewControllerTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerTemplate.h; sourceTree = ""; }; + 4CD41A2E16C2D2490071E598 /* GLKViewTemplate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GLKViewTemplate.mm; sourceTree = ""; }; + 4CD41A2F16C2D2490071E598 /* ViewControllerTemplate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ViewControllerTemplate.mm; sourceTree = ""; }; 4CEE2DD115CDC55B00C4D5F5 /* SalmonRenderGLES20.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SalmonRenderGLES20.h; path = ../../../include/Render/SalmonRender/SalmonRenderGLES20.h; sourceTree = ""; }; 4CEE2DD415CDC57200C4D5F5 /* SalmonRenderGLES20.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SalmonRenderGLES20.cpp; path = ../../../src/Render/SalmonRender/SalmonRenderGLES20.cpp; sourceTree = ""; }; 4CF8747616B65210009B1214 /* ButtonWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ButtonWidget.cpp; path = ../../../src/GUIManager/ButtonWidget.cpp; sourceTree = ""; }; @@ -640,6 +650,8 @@ 4CC1FC3B15B20E440025C6F7 /* IosApi */ = { isa = PBXGroup; children = ( + 4CD41A2416C2D23C0071E598 /* ObjC */, + 4C7BD6E616C28D3100BB8788 /* IosWrapper.h */, 4CC1FC3C15B20E440025C6F7 /* IosApi.h */, ); name = IosApi; @@ -649,7 +661,7 @@ 4CC1FC3E15B20E5D0025C6F7 /* IosApi */ = { isa = PBXGroup; children = ( - 4CC1FC3F15B20E5D0025C6F7 /* IosApi.mm */, + 4CD41A2C16C2D2490071E598 /* ObjC */, ); name = IosApi; path = ../../../src/Utils/IosApi; @@ -673,6 +685,25 @@ path = ../../../include/SmartValueManager; sourceTree = ""; }; + 4CD41A2416C2D23C0071E598 /* ObjC */ = { + isa = PBXGroup; + children = ( + 4CD41A2616C2D23C0071E598 /* GLKViewTemplate.h */, + 4CD41A2716C2D23C0071E598 /* ViewControllerTemplate.h */, + ); + path = ObjC; + sourceTree = ""; + }; + 4CD41A2C16C2D2490071E598 /* ObjC */ = { + isa = PBXGroup; + children = ( + 4CD41A2E16C2D2490071E598 /* GLKViewTemplate.mm */, + 4CD41A2F16C2D2490071E598 /* ViewControllerTemplate.mm */, + 4CC1FC3F15B20E5D0025C6F7 /* IosApi.mm */, + ); + path = ObjC; + sourceTree = ""; + }; 4CF8747116B6514F009B1214 /* PhysicsManager */ = { isa = PBXGroup; children = ( @@ -779,6 +810,9 @@ 4C5E512116B6E602005521AC /* SimpleTimer.h in Headers */, 4CBC58AC16BE9D8200B30DB2 /* ThreadUtils.h in Headers */, 4CBC58AD16BE9D8200B30DB2 /* ThreadUtilsImpl.h in Headers */, + 4C7BD6E716C28D3100BB8788 /* IosWrapper.h in Headers */, + 4CD41A2916C2D23C0071E598 /* GLKViewTemplate.h in Headers */, + 4CD41A2A16C2D23C0071E598 /* ViewControllerTemplate.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -870,6 +904,8 @@ 4CF8749216B652ED009B1214 /* Cameras.cpp in Sources */, 4C5E512416B6E620005521AC /* SimpleTimer.cpp in Sources */, 4CBC58B016BE9D9B00B30DB2 /* ThreadUtils.cpp in Sources */, + 4CD41A3116C2D2490071E598 /* GLKViewTemplate.mm in Sources */, + 4CD41A3216C2D2490071E598 /* ViewControllerTemplate.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/include/SalmonEngineInterface.h b/include/SalmonEngineInterface.h index 5ff79d7..cb29bea 100644 --- a/include/SalmonEngineInterface.h +++ b/include/SalmonEngineInterface.h @@ -122,7 +122,7 @@ public: virtual void OuterOnTapUp(vec2 p); - virtual void OuterOnTapUpAfterShift(vec2 p); + virtual void OuterOnTapUpAfterMove(vec2 p); virtual void OuterOnMove(vec2 shift); @@ -130,7 +130,7 @@ public: virtual void InnerOnTapUp(vec2 p) { } - virtual void InnerOnTapUpAfterShift(vec2 p) { } + virtual void InnerOnTapUpAfterMove(vec2 p) { } virtual void InnerOnMove(vec2 shift) { } @@ -140,6 +140,8 @@ public: //To do on mouse wheel move virtual void OnKeyPress(cardinal key) { } //Try not to override this. But if you need to override, call ancestor! + + virtual void OnScale(float scale) { } }; diff --git a/include/SalmonEngineIos.h b/include/SalmonEngineIos.h index b779e45..d036151 100644 --- a/include/SalmonEngineIos.h +++ b/include/SalmonEngineIos.h @@ -22,6 +22,21 @@ public: void CreateEngine(); void DestroyEngine(); +extern TApplication* App; + + +template +APPTYPE* AppInit(int width, int height) +{ + CreateEngine(); + APPTYPE* result = new APPTYPE; + App = result; + App->OuterInit(width, height, static_cast(width), static_cast(height)); + + return result; +} + + } //namespace SE diff --git a/include/Utils/IosApi/IosApi.h b/include/Utils/IosApi/IosApi.h index a90a33f..7905aa6 100644 --- a/include/Utils/IosApi/IosApi.h +++ b/include/Utils/IosApi/IosApi.h @@ -22,4 +22,5 @@ std::string IosGetFilePathUserData(const std::string& filename); void IosSwitchToScreen(); + } //namespace SE diff --git a/include/Utils/IosApi/IosWrapper.h b/include/Utils/IosApi/IosWrapper.h new file mode 100644 index 0000000..202db5e --- /dev/null +++ b/include/Utils/IosApi/IosWrapper.h @@ -0,0 +1,25 @@ +// +// Header.h +// doublehitballs +// +// Created by vvv ооо on 15.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +//All of them can be found in SalmonEngineIos.cpp +//This header stores only declarations + +namespace SE +{ + +void AppDeinit(); +void AppUpdate(int dt); +void AppDraw(); +void AppOnTapDown(int posx, int posy); +void AppOnTapUp(int posx, int posy); +void AppOnScroll(int shiftx, int shifty); +void AppOnScale(float scale); +void AppOnTapUpAfterMove(int posx, int posy); + + +} \ No newline at end of file diff --git a/include/Utils/IosApi/ObjC/GLKViewTemplate.h b/include/Utils/IosApi/ObjC/GLKViewTemplate.h new file mode 100644 index 0000000..1cbb3ac --- /dev/null +++ b/include/Utils/IosApi/ObjC/GLKViewTemplate.h @@ -0,0 +1,23 @@ +// +// CustomGLKView.h +// doublehitballs +// +// Created by vvv ооо on 15.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import + +@interface GLKViewTemplate : GLKView +{ + + CGPoint touchBeganLocation; + + bool touchMoved; +} + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; +- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; + +@end diff --git a/include/Utils/IosApi/ObjC/ViewControllerTemplate.h b/include/Utils/IosApi/ObjC/ViewControllerTemplate.h new file mode 100644 index 0000000..18bd45b --- /dev/null +++ b/include/Utils/IosApi/ObjC/ViewControllerTemplate.h @@ -0,0 +1,18 @@ +// +// ViewController.h +// doublehitballs +// +// Created by vvv ооо on 13.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import +#import + +@interface ViewControllerTemplate : GLKViewController + + +- (void) appInitCaller; + + +@end diff --git a/src/SalmonEngineInterface.cpp b/src/SalmonEngineInterface.cpp index af68424..a2f9496 100644 --- a/src/SalmonEngineInterface.cpp +++ b/src/SalmonEngineInterface.cpp @@ -116,9 +116,9 @@ void TApplicationAncestor::OuterOnTapUp(vec2 p) InnerOnTapUp(p); } -void TApplicationAncestor::OuterOnTapUpAfterShift(vec2 p) +void TApplicationAncestor::OuterOnTapUpAfterMove(vec2 p) { - InnerOnTapUpAfterShift(p); + InnerOnTapUpAfterMove(p); } void TApplicationAncestor::OuterOnMove(vec2 shift) diff --git a/src/SalmonEngineIos.cpp b/src/SalmonEngineIos.cpp index d9982ad..c6f1eb3 100644 --- a/src/SalmonEngineIos.cpp +++ b/src/SalmonEngineIos.cpp @@ -48,7 +48,62 @@ void DestroyEngine() Console = NULL; } } + + + TApplication* App = NULL; + + void AppDeinit() + { + App->OuterDeinit(); + delete App; + App = NULL; + DestroyEngine(); + } + + + void AppUpdate(int dt) + { + App->OuterUpdate(dt); + } + + + void AppDraw() + { + App->OuterDraw(); + } + + + void AppOnTapDown(int posx, int posy) + { + App->OuterOnTapDown(vec2(posx, posy)); + } + + + void AppOnTapUp(int posx, int posy) + { + App->OuterOnTapUp(vec2(posx, posy)); + } + + + void AppOnTapUpAfterMove(int posx, int posy) + { + App->OuterOnTapUpAfterMove(vec2(posx, posy)); + } + + + void AppOnScroll(int shiftx, int shifty) + { + App->OuterOnMove(vec2(shiftx, shifty)); + } + + + void AppOnScale(float scale) + { + App->OnScale(scale); + } + + - - -} //namespace SE \ No newline at end of file +} //namespace SE + + \ No newline at end of file diff --git a/src/Utils/IosApi/ObjC/GLKViewTemplate.mm b/src/Utils/IosApi/ObjC/GLKViewTemplate.mm new file mode 100644 index 0000000..41247d0 --- /dev/null +++ b/src/Utils/IosApi/ObjC/GLKViewTemplate.mm @@ -0,0 +1,71 @@ +// +// CustomGLKView.m +// doublehitballs +// +// Created by vvv ооо on 15.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "include/Utils/IosApi/ObjC/GLKViewTemplate.h" +#include "include/Utils/IosApi/IosWrapper.h" + +@implementation GLKViewTemplate + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + + touchMoved = false; + + } + return self; +} + + +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + + CGPoint location = [[[touches allObjects] objectAtIndex:0] locationInView:self]; + + touchBeganLocation = location; + + touchMoved = false; + + SE::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(touchBeganLocation.x - location.x) > 10 || abs(touchBeganLocation.y - location.y) > 10) + { + touchMoved = true; + } + + SE::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) + { + SE::AppOnTapUpAfterMove(location.x, self.bounds.size.height - location.y); + } + else + { + SE::AppOnTapUp(location.x, self.bounds.size.height - location.y); + } +} + + + + +@end diff --git a/src/Utils/IosApi/ObjC/ViewControllerTemplate.mm b/src/Utils/IosApi/ObjC/ViewControllerTemplate.mm new file mode 100644 index 0000000..9593e54 --- /dev/null +++ b/src/Utils/IosApi/ObjC/ViewControllerTemplate.mm @@ -0,0 +1,119 @@ +// +// ViewController.m +// doublehitballs +// +// Created by vvv ооо on 13.07.12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "include/Utils/IosApi/ObjC/ViewControllerTemplate.h" +#include "include/Utils/IosApi/IosWrapper.h" + + +extern GLKView* defaultView; //Find this in IosApi.mm + + +@interface ViewControllerTemplate () { +} + +@property (strong, nonatomic) EAGLContext *context; +@property (strong, nonatomic) GLKBaseEffect *effect; + +- (void)setupGL; +- (void)tearDownGL; + +@end + +@implementation ViewControllerTemplate + +@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]; + + + + //Gesture Recognizers + + UIPinchGestureRecognizer *recognizer = [[UIPinchGestureRecognizer alloc] + initWithTarget:self action:@selector(respondToPinch:)]; + + [self.view addGestureRecognizer:recognizer]; +} + +- (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. +} + +- (void)setupGL +{ + [EAGLContext setCurrentContext:self.context]; + + [self appInitCaller]; +} + +- (void)tearDownGL +{ + [EAGLContext setCurrentContext:self.context]; + + SE::AppDeinit(); + +} + +- (void) appInitCaller +{ +} + +- (void)respondToPinch:(UIPinchGestureRecognizer *)gestureRecognizer +{ + SE::AppOnScale(gestureRecognizer.scale); +} + + +#pragma mark - GLKView and GLKViewController delegate methods + +- (void)update +{ + + SE::AppUpdate(self.timeSinceLastUpdate * 1000); +} + +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect +{ + + SE::AppDraw(); + +} + + +@end