Example #1
0
int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  enum {
    kTitle       = (1<<0),
    kDescription = (1<<1),
    kLevels      = (1<<2),
    kFilename    = (1<<3)
  };

  unsigned int mode = 0;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... [FILE]...");

  argp.add_option('h', "help",    "", "Displays this help");

  argp.add_option('t', "title", "", "Display title of the levelset");
  argp.add_option('d', "description", "", "Display description of the levelset");
  argp.add_option('l', "levels", "", "Display levels in this levelset");
  argp.add_option('f', "filename", "", "Display filename of the level");

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key())
    {
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 't':
        mode |= kTitle;
        break;

      case 'd':
        mode |= kDescription;
        break;

      case 'l':
        mode |= kLevels;
        break;

      case 'f':
        mode |= kFilename;
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }

  if (files.empty())
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    // FIXME: a little ugly that levelset loads sprites and savegames
    System::init_directories();
    g_path_manager.set_path("data/");
    SavegameManager savegame_manager("savegames/savegames.scm");
    StatManager stat_manager("savegames/variables.scm");
    Resource::init();

    Display::create_window(NULL_FRAMEBUFFER, Size(), false, false);

    for(auto it = files.begin(); it != files.end(); ++it)
    {
      const Pathname& path = *it;
      std::unique_ptr<Levelset> levelset = Levelset::from_file(path);

      if (mode == 0)
      {
        std::cout << "filename      : " << path << std::endl;
        std::cout << "title         : " << levelset->get_title() << std::endl;
        std::cout << "description   : " << levelset->get_description() << std::endl;
        std::cout << "levels        : " << std::endl;
        for(int i = 0; i < levelset->get_level_count(); ++i)
        {
          std::cout << "  " << levelset->get_level(i)->resname << std::endl;
        }
        std::cout << std::endl;
      }
      else
      {
        if (mode & kFilename)
        {
          std::cout << path << ": ";
        }

        if (mode & kTitle)
        {
          std::cout << levelset->get_title() << std::endl;
        }

        if (mode & kDescription)
        {
          std::cout << levelset->get_description() << std::endl;
        }

        if (mode & kLevels)
        {
          for(int i = 0; i < levelset->get_level_count(); ++i)
          {
            std::cout << "  " << levelset->get_level(i)->resname << std::endl;
          }
          std::cout << std::endl;
        }
      }
    }

    Resource::deinit();
  }

  return 0;
}
Example #2
0
int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  bool crop = false;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... LEVELFILE OUTPUTFILE");

  argp.add_option('h', "help",    "", "Displays this help");
  argp.add_option('b', "background",  "RRGGBBAA", "Set background color");
  argp.add_option('c', "crop", "", "crop output to the actual objects rendered, not levelsize ");

  argp.parse_args(argc, argv);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'c':
        crop = true;
        break;

      case 'b':
        // FIXME: not implemented
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }
  
  if (files.size() != 2)
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    g_path_manager.set_path("data/");
    Resource::init();

    // render all the objects
    WorldObjRenderer renderer;
    Size size;
    
    if (System::get_file_extension(files[0].get_raw_path()) == "prefab")
    {
      PrefabFile prefab = PrefabFile::from_path(files[0]);
      renderer.process(prefab.get_objects());
      crop = true;
    }
    else
    {
      PingusLevel plf(files[0]);
      renderer.process(plf.get_objects());
      size = plf.get_size();
    }

    Surface out_surface;

    if (crop)
    {
      Rect rect = renderer.get_clip_rect();
      
      out_surface = Surface(rect.get_width(), rect.get_height());
      
      // FIXME: alpha doesn't work, as the PNG saver can't handle that
      out_surface.fill(Color(255, 255, 255, 255));

      renderer.blit(out_surface, -rect.left, -rect.top);

      // create a .sprite file to handle the offset
      std::string outfile = System::cut_file_extension(files[1].get_sys_path()) + ".sprite";
      Vector2i offset(rect.left, rect.top);

      std::ostringstream out;
      SExprFileWriter writer(out);
      writer.begin_section("pingus-sprite");
      writer.write_string("image", System::cut_file_extension(System::basename(files[0].get_raw_path())) + ".png");
      writer.write_vector2i("offset", offset);
      writer.end_section();
      out << std::endl;
      log_info("writing: %1%", outfile);
      System::write_file(outfile, out.str());
    }
    else
    {
      out_surface = Surface(size.width, size.height);

      // FIXME: alpha doesn't work, as the PNG saver can't handle that
      out_surface.fill(Color(255, 255, 255, 255));

      renderer.blit(out_surface);
    }

    Screenshot::save(out_surface.get_surface(), files[1].get_sys_path());

    Resource::deinit();
  }

  return 0;
}
Example #3
0
int main(int argc, char** argv)
{
  std::vector<Pathname> files;
  enum { 
    kAuthor      = (1<<0),
    kName        = (1<<1),
    kChecksum    = (1<<2),
    kDescription = (1<<3),
    kMusic       = (1<<4),
    kFilename    = (1<<5),
    kSize        = (1<<6)
  };

  unsigned int mode = 0;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... [FILE]...");

  argp.add_option('h', "help",    "", "Displays this help");

  argp.add_option('a', "author", "", "Display author name");
  argp.add_option('n', "name", "", "Display level name");
  argp.add_option('s', "size", "", "Display level size");
  argp.add_option('c', "checksum", "", "Display checksum of the level");
  argp.add_option('d', "description", "", "Display description of the level");
  argp.add_option('m', "music", "", "Display music of the level");
  argp.add_option('f', "filename", "", "Display filename of the level");

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'a':
        mode |= kAuthor;
        break;

      case 'n':
        mode |= kName;
        break;

      case 'c':
        mode |= kChecksum;
        break;

      case 'd':
        mode |= kDescription;
        break;

      case 'm':
        mode |= kMusic;
        break;

      case 'f':
        mode |= kFilename;
        break;

      case 's':
        mode |= kSize;
        break;
        
      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }

  if (files.empty())
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    for(auto it = files.begin(); it != files.end(); ++it)
    {
      const Pathname& path = *it;
      PingusLevel plf(path);

      if (mode == 0)
      {
        std::cout << "filename      : " << path << std::endl;
        std::cout << "name          : " << plf.get_levelname() << std::endl;
        std::cout << "checksum      : " << plf.get_checksum() << std::endl;
        std::cout << "description   : " << plf.get_description() << std::endl;
        std::cout << "author        : " << plf.get_author() << std::endl;
        std::cout << "music         : " << plf.get_music() << std::endl;
        std::cout << "ambient light : " 
                  << static_cast<int>(plf.get_ambient_light().r) << " "
                  << static_cast<int>(plf.get_ambient_light().g) << " " 
                  << static_cast<int>(plf.get_ambient_light().b) << " " 
                  << static_cast<int>(plf.get_ambient_light().a)
                  << std::endl;
        std::cout << "objects       : " << plf.get_objects().size() << std::endl;
        std::cout << std::endl;
      }
      else
      {
        if (mode & kFilename)
        {
          std::cout << path << ": ";
        }

        if (mode & kChecksum)
        {
          std::cout << plf.get_checksum() << std::endl;
        }

        if (mode & kName)
        {
          std::cout << plf.get_levelname() << std::endl;
        }

        if (mode & kDescription)
        {
          std::cout << plf.get_description() << std::endl;
        }

        if (mode & kAuthor)
        {
          std::cout << plf.get_author() << std::endl;
        }

        if (mode & kSize)
        {
          std::cout << plf.get_size().width << "x" << plf.get_size().height << std::endl;
        }

        if (mode & kMusic)
        {
          std::cout << plf.get_music() << std::endl;
        }
      }
    }
  }

  return 0;
}
Example #4
0
int main(int argc, char** argv)
{
  try {
    bool fullscreen = false;
    int screen_width  = 800;
    int screen_height = 600;
    int canvas_width  = 2048;
    int canvas_height = 2048;
    std::string hostname;
    std::string port     = "4711";
    int rest_arg_count = 0;
    std::string stylus;

    CommandLine argp;

    argp.add_usage("[OPTIONS] HOSTNAME PORT");
    argp.add_group("Display:");
    argp.add_option('g', "geometry",  "WIDTHxHEIGHT", "Set the windows size to WIDTHxHEIGHT");
    argp.add_option('c', "canvas",    "WIDTHxHEIGHT", "Set the size of the paintable canvas to WIDTHxHEIGHT");
    argp.add_option('f', "fullscreen", "",            "Start the application in fullscreen mode");
    argp.add_option('w', "window",     "",            "Start the application in window mode");
    argp.add_option('v', "version",    "",            "Display the netBrush version");
    argp.add_option('i', "input",      "NAME",        "Use XInput device NAME for drawing (tablet support)");
    argp.add_option('h', "help",       "",            "Show this help text");

    argp.parse_args(argc, argv);

    while(argp.next())
      {
        switch(argp.get_key())
          {
          case 'g':
            {
              if (sscanf(argp.get_argument().c_str(), "%dx%d",
                         &screen_width, &screen_height) == 2)
                {
                  std::cout << "Geometry: " << screen_width << "x" << screen_height << std::endl;
                }
              else
                {
                  throw std::runtime_error("Geometry option '-g' requires argument of type {WIDTH}x{HEIGHT}");
                }
            }
            break;

          case 'i':
            {
              stylus = argp.get_argument();
            }
            break;

          case 'c':
            {
              if (sscanf(argp.get_argument().c_str(), "%dx%d",
                         &canvas_width, &canvas_height) == 2)
                {
                  std::cout << "Geometry: " << canvas_width << "x" << canvas_height << std::endl;
                }
              else
                {
                  throw std::runtime_error("Canvas option '-c' requires argument of type {WIDTH}x{HEIGHT}");
                }
            }
            break;

          case 'f':
            fullscreen = true;
            break;

          case 'w':
            fullscreen = false;
            break;

          case 'h':
            argp.print_help();
            return 0;
            break;

          case 'v':
            std::cout << "netBrush 0.1.0" << std::endl;
            break;

          case CommandLine::REST_ARG:
            //std::cout << "Rest: " << argp.get_argument() << std::endl;
            if (rest_arg_count == 0)
              {
                hostname = argp.get_argument();
                rest_arg_count += 1;
              }
            else if (rest_arg_count == 1)
              {
                port = argp.get_argument();
                rest_arg_count += 1;
              }
            else
              {
                std::cout << "Invalide argument " << argp.get_argument() << std::endl;
                exit(EXIT_FAILURE);
              }
            break;
          }
      }

    if(SDL_Init(SDL_INIT_VIDEO)== -1) {
      printf("SDL_Init: %s\n", SDL_GetError());
      exit(1);
    }
    atexit(SDL_Quit);

    if(SDLNet_Init()==-1) {
      printf("SDLNet_Init: %s\n", SDLNet_GetError());
      exit(2);
    }
    atexit(SDLNet_Quit);

    Uint32 flags = SDL_HWSURFACE;
    if (fullscreen)
      flags |= SDL_FULLSCREEN;
    screen = SDL_SetVideoMode(screen_width, screen_height, 32, flags); 
    if (screen == 0)
      printf("SDL_SetVideoMode: %s\n", SDL_GetError());
    SDL_WM_SetCaption("netBrush", "netBrush");

    if (!stylus.empty()) // enable tablet support
      {
        SDL_VERSION(&syswm.version); // this is important!
        if (SDL_GetWMInfo(&syswm) == -1)
          {
            std::cout << "Couldn't get WM info " << std::endl;
          }

        syswm.info.x11.lock_func();
        xinput = new InputDevice_XInput(syswm.info.x11.display, syswm.info.x11.window, stylus);
        syswm.info.x11.unlock_func();

        SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
      }

    // 18 is scrollbar
    screen_buffer = new ScreenBuffer(Rect(38, 2, screen->w - 128 - 18 - 2 - 2, screen->h - 16 - 4 - 38)); 
    draw_ctx      = new DrawingContext(canvas_width, canvas_height);
    stroke_buffer = new StrokeBuffer(canvas_width, canvas_height);
    
    //std::cout << "# clear screen" << std::endl;

    // clear screen
    draw_ctx->clear();

    //std::cout << "# clear screen done" << std::endl;

    client_draw_param = new DrawingParameter();
    stroke_buffer->set_param(client_draw_param);
  
    server = new ServerConnection();
    if (!hostname.empty() && !port.empty())
      {
        std::cout << "Connecting to: " << hostname << ":" << atoi(port.c_str()) << std::endl;
        server->connect(hostname.c_str(), atoi(port.c_str()));
        std::ostringstream title_line;
        title_line << "netBrush - online: " << hostname << ":" << atoi(port.c_str());
        SDL_WM_SetCaption(title_line.str().c_str(), "netBrush");
      }
    else
      {
        std::cout << "# use '" << argv[0] << " HOSTNAME PORT' to connect a networking session" << std::endl;
        SDL_WM_SetCaption("netBrush - offline mode", "netBrush");
      }
  
    widget_manager = new WidgetManager();
    controller     = new Controller();

    widget_manager->add(navigation = new Navigation(Rect(Point(screen->w - 128 - 2, screen->h - 128 - 2),
                                                         Size(128, 128))));
    {
      SDL_Rect color_rect;
      color_rect.x = 768;
      color_rect.y = 100;

      color_rect.w = 128;
      color_rect.h = 128;

      //widget_manager->add(new ColorSelector(&color_rect));
    }

    widget_manager->add(screen_buffer);

    widget_manager->add(vertical_scrollbar = 
                        new Scrollbar(0, canvas_height, screen_buffer->get_rect().get_height(), Scrollbar::VERTICAL,
                                      Rect(screen->w - 128 - 16 - 2 - 2, 2,
                                           screen->w - 128 - 2 - 2, screen->h - 16 - 4 - 38)));

    widget_manager->add(horizontal_scrollbar = 
                        new Scrollbar(0, canvas_width, screen_buffer->get_rect().get_width(), Scrollbar::HORIZONTAL,
                                      Rect(38, screen->h - 16 - 2 - 38,
                                           screen->w - 128 - 18 - 2 - 2, screen->h - 2 - 38)));

    // Main Loop
    while(true)
      {
        process_events();
        server->update();
        widget_manager->update();
        SDL_Delay(10);
      }
  } catch(std::exception& err) {
    std::cout << "Exception: " << err.what() << std::endl;
  }
  
  return 0;
}
Example #5
0
void
PingusMain::parse_args(int argc, char** argv)
{
  CommandLine argp;
  argp.add_usage(_("[OPTIONS]... [FILE]"));
  argp.add_doc(_("Pingus is a puzzle game where you need to guide a bunch of little penguins around the world."));

  argp.add_group(_("General Options:"));
  argp.add_option('h', "help", "", 
                  _("Displays this help"));
  argp.add_option('V', "version", "", 
                  _("Print version number and exit"));
  argp.add_option('v', "verbose", "",
                  _("Enable info level log output"));
  argp.add_option('D', "debug", "", 
                  _("Enable debug level log output"));
  argp.add_option('Q', "quiet", "", 
                  _("Disable all log output"));   

  argp.add_group(_("Display Options:"));
  argp.add_option('w', "window", "",
                  _("Start in Window Mode"));
  argp.add_option('f', "fullscreen", "",
                  _("Start in Fullscreen"));
  argp.add_option('r', "renderer", "RENDERER",
                  _("Use the given renderer (default: sdl)"));
  argp.add_option('g', "geometry", "{width}x{height}",  
                  _("Set the window resolution for pingus (default: 800x600)"));
  argp.add_option('R', "fullscreen-resolution", "{width}x{height}",  
                  _("Set the resolution used in fullscreen mode (default: 800x600)"));
  argp.add_option(346, "software-cursor", "",
                  _("Enable software cursor"));

  argp.add_group(_("Game Options:"));
  argp.add_option(337, "no-auto-scrolling", "",
                  _("Disable automatic scrolling"));
  argp.add_option(338, "drag-drop-scrolling", "",
                  _("Enable drag'n drop scrolling"));

  argp.add_group(_("Sound Options:"));
  argp.add_option('s', "disable-sound", "", 
                  _("Disable sound"));
  argp.add_option('m', "disable-music", "", 
                  _("Disable music"));

  argp.add_group("Language Options:");
  argp.add_option('l', "language", "LANG",
                  _("Select language to use with Pingus"));
  argp.add_option(365, "list-languages", "",
                  _("List all available languages"));

  argp.add_group("Editor Options:");
  argp.add_option('e', "editor", "",
                  _("Loads the level editor"));

  argp.add_group(_("Directory Options:"));
  argp.add_option('d', "datadir", _("DIR"),
                  _("Load game datafiles from DIR"));
  argp.add_option('u', "userdir", _("DIR"),
                  _("Load config files and store savegames in DIR"));
  argp.add_option('a', "addon", _("DIR"),
                  _("Load game modifications from DIR"));
  argp.add_option(342, "no-cfg-file", "",
                  _("Don't read ~/.pingus/config"));
  argp.add_option('c', "config", _("FILE"),
                  _("Read config options from FILE"));
  argp.add_option(360, "controller", "FILE",
                  _("Uses the controller given in FILE"));

  argp.add_group(_("Debug Options:"));
  argp.add_option(334, "developer-mode",  "",  
                  _("Enables some special features for developers"));
  argp.add_option('t', "speed", "SPEED",
                  _("Set the game speed (0=fastest, >0=slower)"));
  argp.add_option('k', "fps", "FPS",
                  _("Set the desired game framerate (frames per second)"));
  argp.add_option(344, "tile-size", "INT",
                  _("Set the size of the map tiles (default: 32)"));

  argp.parse_args(argc, argv);
  argp.set_help_indent(20);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'r': // --renderer
        if (argp.get_argument() == "help")
        {
          std::cout << "Available renderers: " << std::endl;
          std::cout << "   delta: Software rendering with dirty-rectangles" << std::endl;
          std::cout << "     sdl: Software rendering" << std::endl;
          std::cout << "  opengl: Hardware accelerated graphics" << std::endl;
          std::cout << "    null: No rendering at all, for debugging" << std::endl;
          exit(EXIT_SUCCESS);
        }
        else
        {
          cmd_options.framebuffer_type.set(framebuffer_type_from_string(argp.get_argument()));

          //FIXME:
          //std::cout << "Unknown renderer: " << argp.get_argument()
          //<< " use '--renderer help' to get a list of available renderer" << std::endl;
          //exit(EXIT_FAILURE);
        }
        break;

      case 'e': // -e, --editor
        cmd_options.editor.set(true);
        break;

      case 't': // -t, --set-speed
        cmd_options.speed.set(StringUtil::to<int>(argp.get_argument()));  
        break;

      case 'k': // -k, --set-fps
        cmd_options.desiredfps.set(StringUtil::to<float>(argp.get_argument()));
        break;

      case 's': // -s, --disable-sound
        cmd_options.disable_sound.set(true);
        break;

      case 'm': // -m, --disable-music
        cmd_options.disable_music.set(true);
        break;
            
      case 'g':
      {
        Size size; 
        if (sscanf(argp.get_argument().c_str(), "%dx%d", &size.width, &size.height) != 2)
        {
          std::cout << "Resolution std::string is wrong, it should be like: \n"
                    << "\"640x480\" or \"800x600\"" << std::endl;
          exit(EXIT_FAILURE);
        }
        cmd_options.geometry.set(size);
      }
      break;

      case 'R':
      {
        Size size; 
        if (sscanf(argp.get_argument().c_str(), "%dx%d", &size.width, &size.height) != 2)
        {
          std::cout << "Resolution std::string is wrong, it should be like: \n"
                    << "\"640x480\" or \"800x600\"" << std::endl;
          exit(EXIT_FAILURE);
        }
        cmd_options.fullscreen_resolution.set(size);
      }
      break;

      case 'd': // -d, --datadir
        cmd_options.datadir.set(argp.get_argument());
        break;

      case 'a': // -a, --addon
        g_path_manager.add_overlay_path(argp.get_argument());
        break;

      case 'u': // -u, --userdir
        cmd_options.userdir.set(argp.get_argument());
        break;

      case 'V':
        std::cout <<
          "Pingus 0.7.6\n"
          "Copyright (C) 1998-2011 Ingo Ruhnke <*****@*****.**>\n"
          "See the file AUTHORS for a complete list of contributors.\n"
          "Pingus comes with ABSOLUTELY NO WARRANTY. This is free software, and you are\n"
          "welcome to redistribute it under certain conditions; see the file COPYING for details."
                  << std::endl;
        exit(EXIT_SUCCESS);
        break;
          
      case 'f': // --fullscreen
        cmd_options.fullscreen.set(true);
        break;
          
      case 'w': // --window
        cmd_options.fullscreen.set(false);
        break;

      case 334: // --developer-mode
        cmd_options.developer_mode.set(true);
        globals::developer_mode = true;
        break;

      case 337:
        cmd_options.auto_scrolling.set(false);
        break;

      case 338:
        cmd_options.drag_drop_scrolling.set(true);
        break;

      case 342: // --no-cfg-file
        cmd_options.no_config_file.set(true); 
        break;

      case 344:
        cmd_options.tile_size.set(StringUtil::to<int>(argp.get_argument()));
        break;

      case 346:
        cmd_options.software_cursor.set(true);
        break;

      case 'c':
        cmd_options.merge(Options::from_file(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH)));
        break;

      case 'D':
        g_logger.set_log_level(Logger::kDebug);
        break;

      case 'v':
        g_logger.set_log_level(Logger::kInfo);
        break;

      case 'Q':
        g_logger.set_log_level(Logger::kNone);
        break;

      case 360:
        cmd_options.controller.set(argp.get_argument());
        break;

      case 'l': // language
        cmd_options.language.set(argp.get_argument());
        break;

      case 365: // list-languages
        cmd_options.list_languages.set(true);
        break;

      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case CommandLine::REST_ARG:
        if (!cmd_options.rest.is_set())
        {
          cmd_options.rest.set(argp.get_argument());
        }
        else
        {
          std::cout << "Wrong argument: '" << argp.get_argument() << "'" << std::endl;
          std::cout << "You can only give one file argument," << std::endl;
          exit(EXIT_FAILURE);
        }
        break;

      default:
        std::cout << "Error: Got " << argp.get_key() << " " << argp.get_argument() << std::endl;
        break;
    }
  }
}
Example #6
0
int main(int argc, char** argv)
{
  std::vector<Pathname> files;

  CommandLine argp;
  argp.add_usage("[OPTIONS]... LEVELFILE OUTPUTFILE");

  argp.add_option('h', "help",    "", "Displays this help");
  argp.add_option('b', "background",  "RRGGBBAA", "Set background color");
  argp.add_option('c', "colmap", "", "Render collision map instead of graphic map");

  argp.parse_args(argc, argv);

  while (argp.next())
  {
    switch (argp.get_key()) 
    {          
      case 'h':
        argp.print_help();
        exit(EXIT_SUCCESS);
        break;

      case 'c':
        // FIXME: not implemented
        break;

      case 'b':
        // FIXME: not implemented
        break;

      case CommandLine::REST_ARG:
        files.push_back(Pathname(argp.get_argument(), Pathname::SYSTEM_PATH));
        break;
    }
  }
  
  if (files.size() != 2)
  {
    argp.print_help();
    exit(EXIT_SUCCESS);
  }
  else
  {
    g_path_manager.set_path("data/");
    Resource::init();
    PingusLevel plf(files[0]);

    Surface out_surface(plf.get_size().width, plf.get_size().height);

    // FIXME: alpha doesn't work, as the PNG saver can't handle that
    out_surface.fill(Color(255, 255, 255, 255));

    const std::vector<FileReader>& objects = plf.get_objects();
    
    for(auto it = objects.begin(); it != objects.end(); ++it)
    {
      const FileReader& reader = *it;

      Vector3f pos;
      ResDescriptor desc;

      // FIXME: does not handle sprite alignment
      // FIXME: does not handle remove groundpieces
      // FIXME: does not handle liquid

      if (reader.get_name() != "surface-background" && 
          reader.get_name() != "starfield-background" &&
          reader.get_name() != "solidcolor-background")
      {
        if (reader.read_vector("position", pos) &&
            reader.read_desc("surface", desc))
        {
          Surface surface = Resource::load_surface(desc);
          if (reader.get_name() == "exit")
          {
            // FIXME: hack, should take that info from the resource file
            out_surface.blit(surface, 
                             static_cast<int>(pos.x) - surface.get_width()/2, 
                             static_cast<int>(pos.y) - surface.get_height());
          }
          else if (reader.get_name() == "groundpiece")
          {
            std::string type;
            reader.read_string("type", type);
            if (type == "remove")
            {
              // FIXME: don't have blit_remove()
              out_surface.blit(surface, 
                               static_cast<int>(pos.x), 
                               static_cast<int>(pos.y));
            }
            else
            {
              out_surface.blit(surface, 
                               static_cast<int>(pos.x), 
                               static_cast<int>(pos.y));
            }
          }
          else
          {
            out_surface.blit(surface, 
                             static_cast<int>(pos.x), 
                             static_cast<int>(pos.y));
          }
        }
      }
    }

    Screenshot::save(out_surface.get_surface(), files[1].get_sys_path());

    Resource::deinit();
  }

  return 0;
}
Example #7
0
int main(int argc, char** argv)
{
  try {
    std::string port;
    CommandLine argp;

    argp.add_usage("[OPTIONS] PORT");
    argp.add_group("General:");
    argp.add_option('v', "version", "", "Print the netBrush server version");
    argp.add_option('h', "help", "", "Print this help");

    argp.parse_args(argc, argv);
    while(argp.next())
      {
        switch(argp.get_key())
          {
          case 'h':
            argp.print_help();
            return 0;
            break;

          case 'v':
            std::cout << "netBrush Server 0.1.0" << std::endl;
            return 0;
            break;

          case CommandLine::REST_ARG:
            if (!port.empty())
              {
                std::cout << "Invalid argument: " << argp.get_argument() << std::endl;
                return 1;
              }
            else
              {
                port = argp.get_argument();
              }
            break;
          }
      }

    if (port.empty())
      {
        argp.print_help();
        return 1;
      }

    if(SDL_Init(0)==-1) {
      printf("SDL_Init: %s\n", SDL_GetError());
      exit(1);
    }

    if(SDLNet_Init()==-1) {
      printf("SDLNet_Init: %s\n", SDLNet_GetError());
      exit(2);
    }

    atexit(SDL_Quit);
    atexit(SDLNet_Quit);

    std::ostringstream filename;
    filename << "sessions/session-" << time(NULL) << ".nbr";

    std::cout << "# writing log to " << filename.str() << std::endl;
    outfile = new std::ofstream(filename.str().c_str());

    if (argc == 2)
      {
        std::cout << "# listening on: " << port << std::endl;
        connect(atoi(port.c_str()));
      }
    else
      {
        std::cout << "Usage: " << argv[0] << " PORT" << std::endl;
      }

    outfile->close();
    delete outfile;
  } catch (std::exception& err) {
    std::cout << "Exception: " << err.what() << std::endl;
  }
  return 0;
}