This commit is contained in:
Saturneic 2018-12-26 14:34:31 +08:00
parent 009ba14184
commit 0a46ab5dc7
2 changed files with 50 additions and 54 deletions

View File

@ -10,14 +10,58 @@
#include <fields.hpp> #include <fields.hpp>
#include <wav.hpp> #include <wav.hpp>
/*
extern int if_fresh, if_draw;
list<Shape *> Window::shapes;
map<string,View2D *> Window::menus;
extern vector<Field*> fields;
extern int if_fresh, if_draw;
extern vector<Field*> fields;
extern Window *p_nwd; extern Window *p_nwd;
extern WAV twav; extern WAV twav;
extern Shape *p_avg; extern Shape *p_avg;
*/
void draw_fields(int signal){
if (if_fresh == 1 && if_draw == 0){
timeval timer_a, timer_b;
gettimeofday(&timer_a, NULL);
Data tmp_data = twav.getData();
tmp_data.Data2Color();
if(tmp_data.active == true){
if_fresh = 0;
if_draw = 1;
int idx = 1;
for(auto i = tmp_data.color_data.begin(); i!= tmp_data.color_data.end(); i++){
Color m_color = (*i);
//printf("%f %f %f\n",m_color.red, m_color.green, m_color.blue);
//m_color.brighter();
if(idx>fields.size()-1) break;
fields[idx]->color.setColor(m_color);
idx++;
}
p_avg->setColor(tmp_data.avg_color);
}
else{
for(auto i = fields.begin(); i!= fields.end(); i++){
(*i)->color.setColor({0,0,0});
}
p_avg->setColor({0,0,0});
}
gettimeofday(&timer_b, NULL);
//printf("Draw Time: %ums\n",(timer_b.tv_usec-timer_a.tv_usec)/1000);
}
glutTimerFunc(DRAW_TIMER, draw_fields, 1);
}
unsigned long fresh_screen(int signal){
if(if_draw == 1 && if_fresh == 0){
timeval timer_a, timer_b;
if_fresh = 1;
if_draw = 0;
gettimeofday(&timer_a, NULL);
p_nwd->displayEngine();
gettimeofday(&timer_b, NULL);
double ms = (timer_b.tv_usec-timer_a.tv_usec)/1000.0;
if(ms - (unsigned long)ms > 0.65) ms = (unsigned long)ms + 1;
//printf("MS: %lf\n",ms);
return ms;
}
return -1;
}

View File

@ -38,51 +38,3 @@ int main(int argc, char * argv[]) {
nwd.show(); nwd.show();
return 0; return 0;
} }
void draw_fields(int signal){
if (if_fresh == 1 && if_draw == 0){
timeval timer_a, timer_b;
gettimeofday(&timer_a, NULL);
Data tmp_data = twav.getData();
tmp_data.Data2Color();
if(tmp_data.active == true){
if_fresh = 0;
if_draw = 1;
int idx = 1;
for(auto i = tmp_data.color_data.begin(); i!= tmp_data.color_data.end(); i++){
Color m_color = (*i);
//printf("%f %f %f\n",m_color.red, m_color.green, m_color.blue);
//m_color.brighter();
if(idx>fields.size()-1) break;
fields[idx]->color.setColor(m_color);
idx++;
}
p_avg->setColor(tmp_data.avg_color);
}
else{
for(auto i = fields.begin(); i!= fields.end(); i++){
(*i)->color.setColor({0,0,0});
}
p_avg->setColor({0,0,0});
}
gettimeofday(&timer_b, NULL);
//printf("Draw Time: %ums\n",(timer_b.tv_usec-timer_a.tv_usec)/1000);
}
glutTimerFunc(DRAW_TIMER, draw_fields, 1);
}
unsigned long fresh_screen(int signal){
if(if_draw == 1 && if_fresh == 0){
timeval timer_a, timer_b;
if_fresh = 1;
if_draw = 0;
gettimeofday(&timer_a, NULL);
p_nwd->displayEngine();
gettimeofday(&timer_b, NULL);
double ms = (timer_b.tv_usec-timer_a.tv_usec)/1000.0;
if(ms - (unsigned long)ms > 0.65) ms = (unsigned long)ms + 1;
//printf("MS: %lf\n",ms);
return ms;
}
return -1;
}