diff --git a/PanoPainter/Base.lproj/Main.storyboard b/PanoPainter/Base.lproj/Main.storyboard index 37934bd..0ed2d8c 100644 --- a/PanoPainter/Base.lproj/Main.storyboard +++ b/PanoPainter/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -17,7 +17,7 @@ - + diff --git a/PanoPainter/GameViewController.h b/PanoPainter/GameViewController.h index e29d85e..4a0f86b 100644 --- a/PanoPainter/GameViewController.h +++ b/PanoPainter/GameViewController.h @@ -10,14 +10,17 @@ #import #import "AppDelegate.h" -@interface GameViewController : GLKViewController< +@interface GameView : GLKView +@end + +@interface GameViewController : UIViewController< UIKeyInput, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIDocumentInteractionControllerDelegate > { -@public GLKView* glview; +@public GameView* glview; } - (void)display_file:(std::string)filename; - (void)reset_touch; diff --git a/PanoPainter/GameViewController.m b/PanoPainter/GameViewController.m index 53d5854..2f1e463 100644 --- a/PanoPainter/GameViewController.m +++ b/PanoPainter/GameViewController.m @@ -55,7 +55,7 @@ std::recursive_mutex lock_mutex; // lock_thread = [NSThread currentThread]; // lock_count++; [EAGLContext setCurrentContext:self.context]; - GLKView* view = (GLKView*)self.view; + GameView* view = (GameView*)self.view; [view bindDrawable]; } - (void)async_unlock @@ -194,7 +194,7 @@ std::recursive_mutex lock_mutex; NSDictionary* info = [aNotification userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; - GLKView *view = (GLKView *)self.view; + GameView *view = (GameView *)self.view; CGRect frame = view.frame; frame.size.height -= kbSize.height; view.frame = frame; @@ -380,7 +380,7 @@ std::set ignored_touch; App::I.initLog(); App::I.ios_view = self; - self.preferredFramesPerSecond = 60; + //self.preferredFramesPerSecond = 60; self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; if (!self.context) { @@ -389,9 +389,10 @@ std::set ignored_touch; gl_lock = [[NSLock alloc] init]; - GLKView *view = (GLKView *)self.view; + GameView *view = (GameView *)self.view; view.context = self.context; view.drawableDepthFormat = GLKViewDrawableDepthFormat24; + view.enableSetNeedsDisplay = NO; glview = view; App::I.width = view.frame.size.width * view.contentScaleFactor; @@ -433,8 +434,59 @@ std::set ignored_touch; - (void)setupGL { - [EAGLContext setCurrentContext:self.context]; + [self async_lock]; App::I.init(); + [self async_unlock]; + + std::thread([self]{ + while (true) + { + static auto time = std::chrono::steady_clock::now(); + static double elapsed = 0; + static double min_fps_timer = 0; + auto now = std::chrono::steady_clock::now(); + auto dt = std::chrono::duration(now - time); + time = now; + elapsed += dt.count(); + min_fps_timer += dt.count(); + + if (min_fps_timer > 0.1) + { + App::I.redraw = true; + min_fps_timer = 0; + } + + std::deque> working_list; + if (!tasklist.empty()) + { + std::lock_guard lock(task_mutex); + working_list = std::move(tasklist); + } + + App::I.tick(dt.count()); + + [self async_lock]; + if (!(App::I.redraw || App::I.animate || !working_list.empty())) + { + //[self.context presentRenderbuffer:GL_FRAMEBUFFER]; + [self async_unlock]; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + continue; + } + + while (!working_list.empty()) + { + working_list.front()(); + working_list.pop_front(); + } + App::I.clear(); + App::I.update(elapsed); + [self.context presentRenderbuffer:GL_FRAMEBUFFER]; + [self async_unlock]; + [self->glview display]; + elapsed = 0; + } + }).detach(); } - (void)tearDownGL @@ -442,44 +494,8 @@ std::set ignored_touch; [EAGLContext setCurrentContext:self.context]; } -#pragma mark - GLKView and GLKViewController delegate methods +@end -- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect -{ - static auto time = std::chrono::steady_clock::now(); - static double elapsed = 0; - auto now = std::chrono::steady_clock::now(); - auto dt = std::chrono::duration(now - time); - time = now; - elapsed += dt.count(); - - std::deque> working_list; - if (!tasklist.empty()) - { - std::lock_guard lock(task_mutex); - working_list = std::move(tasklist); - } - - App::I.tick(dt.count()); - - [self async_lock]; - if (!(App::I.redraw || App::I.animate || !working_list.empty())) - { - [self.context presentRenderbuffer:GL_FRAMEBUFFER]; - [self async_unlock]; - return; - } - - while (!working_list.empty()) - { - working_list.front()(); - working_list.pop_front(); - } - App::I.clear(); - App::I.update(elapsed); - [self.context presentRenderbuffer:GL_FRAMEBUFFER]; - [self async_unlock]; - elapsed = 0; -} +@implementation GameView @end diff --git a/src/node_stroke_preview.cpp b/src/node_stroke_preview.cpp index 3a7b30e..9ba92b0 100644 --- a/src/node_stroke_preview.cpp +++ b/src/node_stroke_preview.cpp @@ -477,10 +477,6 @@ void NodeStrokePreview::draw_stroke() { if (m_size.x == 0 || m_size.y == 0) return; -#if __IOS__ - draw_stroke_immediate(); - return; -#endif s_queue.mutex.lock(); if (!s_running) {