X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bigscreen%2Fccbs_bigscreen.cpp;h=40d5bad57b8aa3419ab2702b5010bc70a476e279;hb=03c6f0c4b7f83e671b52f33b655c6218538afdb3;hp=129206d4ec14d8db9aeda58434d947d044f16a99;hpb=570d0810ca5aefb7295d7cb5f1d81387d31c7420;p=ccbs diff --git a/bigscreen/ccbs_bigscreen.cpp b/bigscreen/ccbs_bigscreen.cpp index 129206d..40d5bad 100644 --- a/bigscreen/ccbs_bigscreen.cpp +++ b/bigscreen/ccbs_bigscreen.cpp @@ -13,6 +13,7 @@ #include "fetch_group.h" #include "fetch_auxilliary_screens.h" #include "fonts.h" +#include "theme.h" #include "groupscreen.h" #include "top10scorescreen.h" #include "top5chosenscreen.h" @@ -25,7 +26,8 @@ Tournament active_tournament; std::vector active_groups; std::vector screens; GenericScreen *mainscreen = NULL; -unsigned char framebuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4], screenbuf[SCREEN_WIDTH * SCREEN_HEIGHT * 4]; +unsigned char *framebuf, *screenbuf; +bool quit_requested = false; void init(pqxx::connection &conn) { @@ -39,8 +41,6 @@ void init(pqxx::connection &conn) } screens.erase(screens.begin(), screens.end()); - bool show_only_main_screen = (USE_SPLITSCREEN && screens.size() == 1); - #if !USE_SPLITSCREEN RotateScreen *rs = new RotateScreen(); mainscreen = rs; @@ -69,6 +69,8 @@ void init(pqxx::connection &conn) } } + bool show_only_main_screen = (USE_SPLITSCREEN && screens.size() == 1); + /* * Show auxilliary screens except if we have too many already, * or if we're in the special split-screen end-tournament mode, @@ -135,7 +137,7 @@ void init(pqxx::connection &conn) #endif } -void main_loop(pqxx::connection &conn) +void main_loop(pqxx::connection &conn, unsigned screen_width, unsigned screen_height) { if (active_tournament.id == -1) { // No active tournament, sleep a second or so and exit @@ -144,17 +146,17 @@ void main_loop(pqxx::connection &conn) } if (mainscreen && mainscreen->check_invalidated()) { - if (screen->pitch == SCREEN_WIDTH * 4) { + if (screen->pitch == screen_width * 4) { SDL_LockSurface(screen); - mainscreen->draw((unsigned char *)screen->pixels, SCREEN_WIDTH, SCREEN_HEIGHT); + mainscreen->draw((unsigned char *)screen->pixels, screen_width, screen_height); SDL_UnlockSurface(screen); } else { - mainscreen->draw(framebuf, SCREEN_WIDTH, SCREEN_HEIGHT); + mainscreen->draw(framebuf, screen_width, screen_height); SDL_LockSurface(screen); - for (unsigned y = 0; y < SCREEN_HEIGHT; ++y) { - unsigned char *sptr = framebuf + y * SCREEN_WIDTH * 4; + 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); + memcpy(dptr, sptr, screen_width * 4); } SDL_UnlockSurface(screen); } @@ -166,37 +168,72 @@ void main_loop(pqxx::connection &conn) } } +void handle_events() +{ + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + quit_requested = true; + } + if (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE) { + quit_requested = true; + } + } +} + int main(int argc, char **argv) { + init_theme(); + unsigned screen_width = atoi(get_theme_config("screen", "width").c_str()); + unsigned screen_height = atoi(get_theme_config("screen", "height").c_str()); + bool use_lcd = atoi(get_theme_config("screen", "fullscreen").c_str()); + SDL_Init(SDL_INIT_VIDEO); -#if USE_FULLSCREEN - screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN); - SDL_ShowCursor(SDL_DISABLE); -#else - screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_DOUBLEBUF); -#endif + if (use_lcd) { + screen = SDL_SetVideoMode(screen_width, screen_height, 32, SDL_DOUBLEBUF | SDL_FULLSCREEN); + SDL_ShowCursor(SDL_DISABLE); + } else { + screen = SDL_SetVideoMode(screen_width, screen_height, 32, SDL_DOUBLEBUF); + } if (screen == NULL) { fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError()); exit(1); } + + framebuf = new unsigned char[screen_width * screen_height * 4]; + screenbuf = new unsigned char[screen_width * screen_height * 4]; try { init_freetype(); - pqxx::connection conn("dbname=ccbs host=www.positivegaming.com user=ccbs password=GeT|>>B_"); + set_screen_size(screen_width, screen_height); + + char connstr[1024]; + snprintf(connstr, sizeof(connstr), "dbname=%s host=%s user=%s password=%s", + get_theme_config("db", "dbname").c_str(), + get_theme_config("db", "host").c_str(), + get_theme_config("db", "user").c_str(), + get_theme_config("db", "password").c_str()); + pqxx::connection conn(connstr); FlagTrigger tournament_changed(conn, "active_tournament"); FlagTrigger rounds_changed(conn, "active_groups"); // when active_tournament or active_rounds is changed, we destroy everything and start from scratch // (at least currently) - for ( ;; ) { + while (!quit_requested) { tournament_changed.reset_flag(); rounds_changed.reset_flag(); init(conn); do { - main_loop(conn); + main_loop(conn, screen_width, screen_height); conn.get_notifs(); - } while (!tournament_changed.get_flag() && !rounds_changed.get_flag()); - std::fprintf(stderr, "active_tournament or active_groups changed, resetting...\n"); + handle_events(); + } while (!tournament_changed.get_flag() && !rounds_changed.get_flag() && !quit_requested); + + if (quit_requested) { + fprintf(stderr, "Quitting...\n"); + } else { + fprintf(stderr, "active_tournament or active_groups changed, resetting...\n"); + } } } catch (const std::exception &e) { std::fprintf(stderr, "Exception: %s\n", e.what());