separate global tick from draw so on tick any node can request a redraw
This commit is contained in:
@@ -155,11 +155,14 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
{
|
||||
static double _timeFreq = CVGetHostClockFrequency();
|
||||
static double _prevTime = (double)outputTime->hostTime / _timeFreq;
|
||||
static double elapsed = 0;
|
||||
double hostTime = (double)outputTime->hostTime;
|
||||
double now = hostTime / _timeFreq;
|
||||
double dt = now - _prevTime;
|
||||
_prevTime = now;
|
||||
|
||||
// this will not update unless 1/30th of a second has passed since the last update
|
||||
if (1 /*now < _prevTime + (1.0 / 30.0) &&*/ )
|
||||
//if (now < _prevTime + (1.0 / 30.0))
|
||||
{
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
{
|
||||
@@ -180,17 +183,14 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
working_list.pop_front();
|
||||
}
|
||||
|
||||
double dt = now - _prevTime;
|
||||
|
||||
if (dt > 0.1)
|
||||
App::I.redraw = true;
|
||||
App::I.tick(dt);
|
||||
|
||||
if (App::I.redraw)
|
||||
{
|
||||
App::I.clear();
|
||||
App::I.update(dt);
|
||||
App::I.update(elapsed);
|
||||
elapsed = 0;
|
||||
CGLFlushDrawable([glctx CGLContextObj]);
|
||||
_prevTime = now;
|
||||
}
|
||||
|
||||
//[[self openGLContext] flushBuffer];
|
||||
@@ -199,13 +199,6 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
CGLUnlockContext([glctx CGLContextObj]);
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
// change whatever you want to change here, as a function of time elapsed
|
||||
_prevTime = now;
|
||||
// return YES to have your layer redrawn
|
||||
return YES;
|
||||
}
|
||||
|
||||
return kCVReturnSuccess;
|
||||
}
|
||||
|
||||
@@ -427,8 +427,11 @@ std::set<UITouch*> ignored_touch;
|
||||
- (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<float>(now - time);
|
||||
time = now;
|
||||
elapsed += dt.count();
|
||||
|
||||
std::deque<std::packaged_task<void()>> working_list;
|
||||
if (!tasklist.empty())
|
||||
@@ -437,6 +440,8 @@ std::set<UITouch*> ignored_touch;
|
||||
working_list = std::move(tasklist);
|
||||
}
|
||||
|
||||
App::I.tick(dt.count());
|
||||
|
||||
[self async_lock];
|
||||
if (!(App::I.redraw || App::I.animate || !working_list.empty()))
|
||||
{
|
||||
@@ -451,10 +456,10 @@ std::set<UITouch*> ignored_touch;
|
||||
working_list.pop_front();
|
||||
}
|
||||
App::I.clear();
|
||||
App::I.update(dt.count());
|
||||
App::I.update(elapsed);
|
||||
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||
[self async_unlock];
|
||||
time = now;
|
||||
elapsed = 0;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -442,8 +442,6 @@ void App::update(float dt)
|
||||
if (canvas && canvas->m_canvas)
|
||||
canvas->m_canvas->stroke_draw();
|
||||
|
||||
layout[main_id]->tick(dt);
|
||||
|
||||
if (!(redraw || animate))
|
||||
return;
|
||||
|
||||
|
||||
@@ -112,6 +112,7 @@ public:
|
||||
bool request_close();
|
||||
void terminate();
|
||||
void clear();
|
||||
void tick(float dt);
|
||||
void update(float dt);
|
||||
void async_start();
|
||||
void async_update();
|
||||
|
||||
@@ -11,6 +11,11 @@ std::string win32_open_file();
|
||||
|
||||
using namespace ui;
|
||||
|
||||
void App::tick(float dt)
|
||||
{
|
||||
layout[main_id]->tick(dt);
|
||||
}
|
||||
|
||||
void App::resize(float w, float h)
|
||||
{
|
||||
redraw = true;
|
||||
|
||||
@@ -35,6 +35,11 @@
|
||||
#include "node_changelog.h"
|
||||
#include "node_usermanual.h"
|
||||
|
||||
void Node::app_redraw()
|
||||
{
|
||||
App::I.redraw = true;
|
||||
}
|
||||
|
||||
void Node::async_start()
|
||||
{
|
||||
App::I.async_start();
|
||||
|
||||
@@ -211,6 +211,7 @@ public:
|
||||
virtual void removed(Node* parent);
|
||||
const Node* init_template(const char* id);
|
||||
void tick(float dt);
|
||||
void app_redraw();
|
||||
void async_start();
|
||||
void async_update();
|
||||
void async_end();
|
||||
|
||||
@@ -16,7 +16,10 @@ void NodeTextInput::on_tick(float dt)
|
||||
{
|
||||
timer = 0;
|
||||
if (m_cursor)
|
||||
{
|
||||
m_cursor->m_display = !m_cursor->m_display;
|
||||
app_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user