]> git.sesse.net Git - ccbs/blobdiff - bigscreen/rotatescreen.cpp
Replace 800x600 width a resolution from a .h file. Lots of positions are still hardco...
[ccbs] / bigscreen / rotatescreen.cpp
index 96a3ebc7bad1137f957e1971642f611ddd34247e..78a0e783693ceb3b1ff8fcbeb7964f7c49b6c6af 100644 (file)
@@ -4,7 +4,7 @@
 RotateScreen::RotateScreen()
        : valid(false), current_screen(0), in_fade(false)
 {
 RotateScreen::RotateScreen()
        : valid(false), current_screen(0), in_fade(false)
 {
-       fadefrom_buf = new unsigned char[800 * 600 * 4];
+       fadefrom_buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
 }
 
 RotateScreen::~RotateScreen()
 }
 
 RotateScreen::~RotateScreen()
@@ -20,6 +20,8 @@ bool RotateScreen::check_invalidated()
                return true;
        if (needs_update())
                return true;
                return true;
        if (needs_update())
                return true;
+       if (!can_update())
+               return false;
        
        for (unsigned i = 0; i < subscreens.size(); ++i) {
                if (subscreens[i].screen->check_invalidated())
        
        for (unsigned i = 0; i < subscreens.size(); ++i) {
                if (subscreens[i].screen->check_invalidated())
@@ -32,6 +34,12 @@ bool RotateScreen::check_invalidated()
 void RotateScreen::draw(unsigned char *buf)
 {
        bool force = false;
 void RotateScreen::draw(unsigned char *buf)
 {
        bool force = false;
+
+       if (subscreens.size() == 0) {
+               valid = true;
+               gettimeofday(&last_update, NULL);
+               return;
+       }
        
        // if we're in a fade, complete it before doing anything else
        if (in_fade) {
        
        // if we're in a fade, complete it before doing anything else
        if (in_fade) {
@@ -46,17 +54,17 @@ void RotateScreen::draw(unsigned char *buf)
                double elapsed_fade = double(now.tv_sec - fade_started.tv_sec) +
                        double(now.tv_usec - fade_started.tv_usec) * 1.0e-6;
                
                double elapsed_fade = double(now.tv_sec - fade_started.tv_sec) +
                        double(now.tv_usec - fade_started.tv_usec) * 1.0e-6;
                
-               if (elapsed_fade > 5.5 || (!same_fade && elapsed_fade > 0.5)) {
+               if (elapsed_fade > 5.5 || (!fade_to_new_info && elapsed_fade > 0.5)) {
                        in_fade = false;
 
                        // ugly hack here? :-)
                        subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
                        
                        in_fade = false;
 
                        // ugly hack here? :-)
                        subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
                        
-                       memcpy(buf, subscreens[current_screen].buf, 800 * 600 * 4);
+                       memcpy(buf, subscreens[current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
                } else {
                        // find the fade factors
                        int fr, fg, fb, fa;
                } else {
                        // find the fade factors
                        int fr, fg, fb, fa;
-                       if (same_fade) {
+                       if (fade_to_new_info) {
                                if (elapsed_fade < 0.5) {
                                        fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0);
                                } else {
                                if (elapsed_fade < 0.5) {
                                        fr = fg = fb = fa = unsigned(elapsed_fade/0.5 * 256.0);
                                } else {
@@ -70,9 +78,9 @@ void RotateScreen::draw(unsigned char *buf)
                        unsigned char *sptr2 = subscreens[current_screen].buf;
                        unsigned char *dptr = buf;
 
                        unsigned char *sptr2 = subscreens[current_screen].buf;
                        unsigned char *dptr = buf;
 
-                       if (same_fade && elapsed_fade >= 0.5) {
+                       if (fade_to_new_info && elapsed_fade >= 0.5) {
                                // fade G&B to be = R
                                // fade G&B to be = R
-                               for (unsigned i = 0; i < 800 * 600; ++i) {
+                               for (unsigned i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) {
                                        dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * fb) >> 8);
                                        dptr[1] = sptr2[1] + (((int(sptr2[2]) - int(sptr2[1])) * fg) >> 8);
                                        dptr[2] = sptr2[2];
                                        dptr[0] = sptr2[0] + (((int(sptr2[2]) - int(sptr2[0])) * fb) >> 8);
                                        dptr[1] = sptr2[1] + (((int(sptr2[2]) - int(sptr2[1])) * fg) >> 8);
                                        dptr[2] = sptr2[2];
@@ -81,7 +89,7 @@ void RotateScreen::draw(unsigned char *buf)
                                        sptr1 += 4, sptr2 += 4, dptr += 4;
                                }
                        } else {
                                        sptr1 += 4, sptr2 += 4, dptr += 4;
                                }
                        } else {
-                               for (unsigned i = 0; i < 800 * 600; ++i) {
+                               for (unsigned i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; ++i) {
                                        dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fb) >> 8);
                                        dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8);
                                        dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fr) >> 8);
                                        dptr[0] = sptr1[0] + (((int(sptr2[0]) - int(sptr1[0])) * fb) >> 8);
                                        dptr[1] = sptr1[1] + (((int(sptr2[1]) - int(sptr1[1])) * fg) >> 8);
                                        dptr[2] = sptr1[2] + (((int(sptr2[2]) - int(sptr1[2])) * fr) >> 8);
@@ -95,12 +103,14 @@ void RotateScreen::draw(unsigned char *buf)
                // determine if we want to switch screens
        
                unsigned old_current_screen = current_screen;
                // determine if we want to switch screens
        
                unsigned old_current_screen = current_screen;
+               int priority = -9999;  // bah :-P
                
                // push any invalidated screen first (for now)
                for (unsigned i = 0; i < subscreens.size(); ++i) {
                
                // push any invalidated screen first (for now)
                for (unsigned i = 0; i < subscreens.size(); ++i) {
-                       if (subscreens[i].screen->check_invalidated()) {
+                       if (subscreens[i].screen->check_invalidated() && subscreens[i].screen->get_priority() > priority) {
                                current_screen = i;
                                force = true;
                                current_screen = i;
                                force = true;
+                               priority = subscreens[i].screen->get_priority();
                        }
                }
 
                        }
                }
 
@@ -110,13 +120,13 @@ void RotateScreen::draw(unsigned char *buf)
                        gettimeofday(&last_update, NULL);
                }
 
                        gettimeofday(&last_update, NULL);
                }
 
-               if (current_screen != old_current_screen || subscreens[current_screen].screen->check_invalidated()) {
+               if (!valid || current_screen != old_current_screen || subscreens[current_screen].screen->check_invalidated()) {
                        // initialize a fade
                        in_fade = true;
                        fade_found_start_time = false;
                        // initialize a fade
                        in_fade = true;
                        fade_found_start_time = false;
-                       same_fade = (current_screen == old_current_screen);
+                       fade_to_new_info = force;
                        
                        
-                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, 800 * 600 * 4);
+                       memcpy(fadefrom_buf, subscreens[old_current_screen].buf, SCREEN_WIDTH * SCREEN_HEIGHT * 4);
 
                        if (subscreens[current_screen].screen->check_invalidated())
                                subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
 
                        if (subscreens[current_screen].screen->check_invalidated())
                                subscreens[current_screen].screen->draw(subscreens[current_screen].buf);
@@ -141,12 +151,30 @@ bool RotateScreen::needs_update()
        return (since >= 10.0);
 }
 
        return (since >= 10.0);
 }
 
+// hold all screens for minimum three seconds, hold all screens with new info for at minimum eight seconds
+bool RotateScreen::can_update()
+{
+       struct timeval now;
+       gettimeofday(&now, NULL);
+
+       double since = double(now.tv_sec - last_update.tv_sec) +
+               double(now.tv_usec - last_update.tv_usec) * 1.0e-6;
+
+       if (since < 3.0)
+               return false;
+       if (fade_to_new_info && since < 8.0)
+               return false;
+       return true;
+}
+
 void RotateScreen::add_screen(GenericScreen *screen)
 {
        Subscreen ss;
 void RotateScreen::add_screen(GenericScreen *screen)
 {
        Subscreen ss;
-       ss.buf = new unsigned char[800 * 600 * 4];
+       ss.buf = new unsigned char[SCREEN_WIDTH * SCREEN_HEIGHT * 4];
        ss.screen = screen;
 
        ss.screen = screen;
 
+       screen->draw(ss.buf);
+       
        subscreens.push_back(ss);
 }
 
        subscreens.push_back(ss);
 }