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 _timeFreq = CVGetHostClockFrequency();
|
||||||
static double _prevTime = (double)outputTime->hostTime / _timeFreq;
|
static double _prevTime = (double)outputTime->hostTime / _timeFreq;
|
||||||
|
static double elapsed = 0;
|
||||||
double hostTime = (double)outputTime->hostTime;
|
double hostTime = (double)outputTime->hostTime;
|
||||||
double now = hostTime / _timeFreq;
|
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
|
// 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;
|
std::deque<std::packaged_task<void()>> working_list;
|
||||||
{
|
{
|
||||||
@@ -180,17 +183,14 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|||||||
working_list.pop_front();
|
working_list.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
double dt = now - _prevTime;
|
App::I.tick(dt);
|
||||||
|
|
||||||
if (dt > 0.1)
|
|
||||||
App::I.redraw = true;
|
|
||||||
|
|
||||||
if (App::I.redraw)
|
if (App::I.redraw)
|
||||||
{
|
{
|
||||||
App::I.clear();
|
App::I.clear();
|
||||||
App::I.update(dt);
|
App::I.update(elapsed);
|
||||||
|
elapsed = 0;
|
||||||
CGLFlushDrawable([glctx CGLContextObj]);
|
CGLFlushDrawable([glctx CGLContextObj]);
|
||||||
_prevTime = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//[[self openGLContext] flushBuffer];
|
//[[self openGLContext] flushBuffer];
|
||||||
@@ -199,13 +199,6 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|||||||
CGLUnlockContext([glctx CGLContextObj]);
|
CGLUnlockContext([glctx CGLContextObj]);
|
||||||
return NO;
|
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;
|
return kCVReturnSuccess;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -427,8 +427,11 @@ std::set<UITouch*> ignored_touch;
|
|||||||
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
||||||
{
|
{
|
||||||
static auto time = std::chrono::steady_clock::now();
|
static auto time = std::chrono::steady_clock::now();
|
||||||
|
static double elapsed = 0;
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
auto dt = std::chrono::duration<float>(now - time);
|
auto dt = std::chrono::duration<float>(now - time);
|
||||||
|
time = now;
|
||||||
|
elapsed += dt.count();
|
||||||
|
|
||||||
std::deque<std::packaged_task<void()>> working_list;
|
std::deque<std::packaged_task<void()>> working_list;
|
||||||
if (!tasklist.empty())
|
if (!tasklist.empty())
|
||||||
@@ -436,6 +439,8 @@ std::set<UITouch*> ignored_touch;
|
|||||||
std::lock_guard<std::mutex> lock(task_mutex);
|
std::lock_guard<std::mutex> lock(task_mutex);
|
||||||
working_list = std::move(tasklist);
|
working_list = std::move(tasklist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::I.tick(dt.count());
|
||||||
|
|
||||||
[self async_lock];
|
[self async_lock];
|
||||||
if (!(App::I.redraw || App::I.animate || !working_list.empty()))
|
if (!(App::I.redraw || App::I.animate || !working_list.empty()))
|
||||||
@@ -451,10 +456,10 @@ std::set<UITouch*> ignored_touch;
|
|||||||
working_list.pop_front();
|
working_list.pop_front();
|
||||||
}
|
}
|
||||||
App::I.clear();
|
App::I.clear();
|
||||||
App::I.update(dt.count());
|
App::I.update(elapsed);
|
||||||
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
[self.context presentRenderbuffer:GL_FRAMEBUFFER];
|
||||||
[self async_unlock];
|
[self async_unlock];
|
||||||
time = now;
|
elapsed = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -442,8 +442,6 @@ void App::update(float dt)
|
|||||||
if (canvas && canvas->m_canvas)
|
if (canvas && canvas->m_canvas)
|
||||||
canvas->m_canvas->stroke_draw();
|
canvas->m_canvas->stroke_draw();
|
||||||
|
|
||||||
layout[main_id]->tick(dt);
|
|
||||||
|
|
||||||
if (!(redraw || animate))
|
if (!(redraw || animate))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ public:
|
|||||||
bool request_close();
|
bool request_close();
|
||||||
void terminate();
|
void terminate();
|
||||||
void clear();
|
void clear();
|
||||||
|
void tick(float dt);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
void async_start();
|
void async_start();
|
||||||
void async_update();
|
void async_update();
|
||||||
|
|||||||
@@ -11,6 +11,11 @@ std::string win32_open_file();
|
|||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
|
void App::tick(float dt)
|
||||||
|
{
|
||||||
|
layout[main_id]->tick(dt);
|
||||||
|
}
|
||||||
|
|
||||||
void App::resize(float w, float h)
|
void App::resize(float w, float h)
|
||||||
{
|
{
|
||||||
redraw = true;
|
redraw = true;
|
||||||
|
|||||||
@@ -35,6 +35,11 @@
|
|||||||
#include "node_changelog.h"
|
#include "node_changelog.h"
|
||||||
#include "node_usermanual.h"
|
#include "node_usermanual.h"
|
||||||
|
|
||||||
|
void Node::app_redraw()
|
||||||
|
{
|
||||||
|
App::I.redraw = true;
|
||||||
|
}
|
||||||
|
|
||||||
void Node::async_start()
|
void Node::async_start()
|
||||||
{
|
{
|
||||||
App::I.async_start();
|
App::I.async_start();
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ public:
|
|||||||
virtual void removed(Node* parent);
|
virtual void removed(Node* parent);
|
||||||
const Node* init_template(const char* id);
|
const Node* init_template(const char* id);
|
||||||
void tick(float dt);
|
void tick(float dt);
|
||||||
|
void app_redraw();
|
||||||
void async_start();
|
void async_start();
|
||||||
void async_update();
|
void async_update();
|
||||||
void async_end();
|
void async_end();
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ void NodeTextInput::on_tick(float dt)
|
|||||||
{
|
{
|
||||||
timer = 0;
|
timer = 0;
|
||||||
if (m_cursor)
|
if (m_cursor)
|
||||||
|
{
|
||||||
m_cursor->m_display = !m_cursor->m_display;
|
m_cursor->m_display = !m_cursor->m_display;
|
||||||
|
app_redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user