]> git.sesse.net Git - ccbs/blobdiff - bigscreen/ccbs_bigscreen.cpp
Replace TinyPTC with SDL.
[ccbs] / bigscreen / ccbs_bigscreen.cpp
index b32c5b1405fa71bed93d5527ee978fcf75c98bc0..025d44bf6e435da5f4d116b12b712a9e753581d0 100644 (file)
@@ -3,7 +3,8 @@
 #include <iconv.h>
 #include <unistd.h>
 #include <pqxx/pqxx>
-#include <tinyptc.h>
+#include <SDL.h>
+
 #include "flagtrigger.h"
 #include "widestring.h"
 #include "fetch_current_tournament.h"
@@ -18,6 +19,8 @@
 #include "splitscreen.h"
 #include "rotatescreen.h"
 
+SDL_Surface *screen = NULL;
+
 Tournament active_tournament;
 std::vector<SkeletonGroup> active_groups;
 std::vector<GenericScreen *> screens;
@@ -83,17 +86,29 @@ void main_loop(pqxx::connection &conn)
 
        if (mainscreen && mainscreen->check_invalidated()) {
                mainscreen->draw(framebuf, SCREEN_WIDTH, SCREEN_HEIGHT);
-               ptc_update(framebuf);
+               SDL_LockSurface(screen);
+               for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) {
+                       unsigned char *sptr = framebuf + y * SCREEN_WIDTH * 4;
+                       unsigned char *dptr = (unsigned char *)screen->pixels + y * screen->pitch;
+                       memcpy(dptr, sptr, SCREEN_WIDTH * 4);
+               }
+               SDL_UnlockSurface(screen);
+               SDL_Flip(screen);
                conn.await_notification(0, 10000);
        } else {
-               ptc_update(framebuf);
+               SDL_Flip(screen);
                conn.await_notification(0, 200000);
        }
 }
 
 int main(int argc, char **argv)
 {
-       ptc_open("CCBS bigscreen", SCREEN_WIDTH, SCREEN_HEIGHT);
+       SDL_Init(SDL_INIT_VIDEO);
+       screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN);
+       if (screen == NULL) {
+               fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
+               exit(1);
+       }
        
        try {
                init_freetype();
@@ -117,6 +132,8 @@ int main(int argc, char **argv)
                std::fprintf(stderr, "Exception: %s\n", e.what());
                exit(1);
        }
+
+       SDL_Quit();
        
        return 0;
 }