Implement a simple priority system.
authorSteinar H. Gunderson <sesse@samfundet.no>
Tue, 1 Mar 2005 01:12:51 +0000 (01:12 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Tue, 1 Mar 2005 01:12:51 +0000 (01:12 +0000)
The priority system is used to determine which screen is shown first if two or more screens
have updated information (ie. a group screen is more important than a "today's high scores"
screen, which is in turn more important than "today's most chosen songs", as the latter is
mainly a curiosity).

- Add a get_priority() to GenericScreen, default 0.
- Implement get_priority() for GroupScreen and Top10ScoreScreen, set to 10 and 5 resp.
- Make RotateScreen automatically pick the screen with the highest priority if two or more
  have forced updates.

bigscreen/groupscreen.cpp
bigscreen/groupscreen.h
bigscreen/rotatescreen.cpp
bigscreen/screen.cpp
bigscreen/screen.h
bigscreen/top10scorescreen.cpp
bigscreen/top10scorescreen.h

index 83a7082..8d408ec 100644 (file)
@@ -501,3 +501,7 @@ void GroupScreen::draw(unsigned char *buf)
        last_text = td;
 }
 
+int GroupScreen::get_priority()
+{
+       return 10;
+}
index 21ab172..1bff23f 100644 (file)
@@ -27,6 +27,7 @@ public:
 
        bool check_invalidated();
        void draw(unsigned char *buf);
+       int get_priority();
 };
 
 #endif /* !defined(_GROUPSCREEN_H) */
index 275b73e..fcc975c 100644 (file)
@@ -103,12 +103,14 @@ void RotateScreen::draw(unsigned char *buf)
                // 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) {
-                       if (subscreens[i].screen->check_invalidated()) {
+                       if (subscreens[i].screen->check_invalidated() && subscreens[i].screen->get_priority() > priority) {
                                current_screen = i;
                                force = true;
+                               priority = subscreens[i].screen->get_priority();
                        }
                }
 
index 850ca94..279d21d 100644 (file)
@@ -3,3 +3,7 @@
 GenericScreen::GenericScreen() {}
 GenericScreen::~GenericScreen() {}
 
+int GenericScreen::get_priority()
+{
+       return 0;
+}
index 37edb56..b35e3af 100644 (file)
@@ -10,6 +10,7 @@ public:
        virtual ~GenericScreen();
        virtual bool check_invalidated() = 0;
        virtual void draw(unsigned char *buf) = 0;
+       virtual int get_priority();
 };
 
 #endif /* !defined(_SCREEN_H) */
index 2db7bfd..6ae58fd 100644 (file)
@@ -87,3 +87,7 @@ void Top10ScoreScreen::draw(unsigned char *buf)
        std::copy(scores.begin(), scores.end(), std::inserter(seen_topscore, seen_topscore.end()));
 }
 
+int Top10ScoreScreen::get_priority()
+{
+       return 5;
+}
index 143c291..2a32901 100644 (file)
@@ -23,6 +23,7 @@ public:
 
        bool check_invalidated();
        void draw(unsigned char *buf);
+       int get_priority();
 };
 
 #endif /* !defined(_TOP10SCORESCREEN_H) */