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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user