コード例 #1
0
PingusLevel
PLFResMgr::load_plf_raw(const std::string& res_name,
                        const Pathname& pathname)
{
  pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: '" << res_name << "'  -> '" << pathname.str() << "'" << std::endl;

  PLFMap::iterator i = plf_map.find(res_name);

  if (i == plf_map.end())
    { // Entry not cached, so load it and add it to cache
      pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from DISK: '" << res_name << "' -> '"
                                 << pathname.str() << "'" << std::endl;

      PingusLevel plf(res_name, pathname);

      PLFEntry entry;
      entry.plf   = plf;
      entry.mtime = pathname.mtime();

      plf_map[res_name]  = entry;

      // FIXME: leaking pointers to the outsite work is not such a good
      // idea, could lead to trouble sooner or later

      return PingusLevel (entry.plf);
    }
  else
    {
      uint64_t current_mtime = pathname.mtime();
      if (current_mtime != i->second.mtime)
        {
          pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: level changed on DISK, reloading: '" << res_name
                                     << "' -> '" << pathname.str() << "'" << std::endl;

          // Reload the file since it has changed on disk
          PingusLevel plf(res_name, pathname);
          PLFEntry entry;

          entry.plf   = plf;
          entry.mtime = pathname.mtime();

          plf_map[res_name]  = entry;

          // FIXME: leaking pointers to the outsite work is not such a good
          // idea, could lead to trouble sooner or later
          return PingusLevel (entry.plf);
        }
      else
        { // File in cache is up to date, everything is all ready, return it
          pout(PINGUS_DEBUG_LOADING) << "PLFResMgr: Loading level from CACHE: '" << res_name << "' -> '"
                                     << pathname.str() << "'" << std::endl;

          return i->second.plf;
        }
    }
}
コード例 #2
0
/** Load a level and create the World for each given level, this
    allows to track missing resources and other problems in level
    creation */
int main(int argc, char** argv)
{
  g_path_manager.set_path("data");
  Resource::init();
 
  Display::create_window(NULL_FRAMEBUFFER, Size(640, 480), false, false);

  Fonts::init();
  Sound::PingusSound::init();

  for(int i = 1; i < argc; ++i)
  {
    try 
    {
      std::cout << "Processing: " << argv[i] << " " << i << "/" << (argc-1) << std::endl;
      PingusLevel plf(Pathname(argv[i], Pathname::SYSTEM_PATH));
      World world(plf);
    }
    catch(const std::exception& err)
    {
      log_error("%1%: exception catched: %2%", argv[i], err.what());
    }
  }

  Sound::PingusSound::deinit();
  Fonts::deinit();
  Resource::deinit();

  return 0;
}
コード例 #3
0
/*use to make a database
 * program [absolute name of logical file] [list of replicas]
 */
int main(int argc,char **argv){
   saga::url plf(argv[1]);
   plf.set_host("localhost");
   plf.set_scheme("any");
   saga::logical_file::logical_file lf(plf, saga::logical_file::Create | saga::logical_file::CreateParents | saga::logical_file::ReadWrite);
   for(int x=2;x<argc;x++){
      saga::url replica(argv[x]);
      replica.set_host("localhost");
      replica.set_scheme("any");
      lf.add_location(replica);
   } 
   return 0;
}
コード例 #4
0
int main(int argc, char** argv)
{
  for(int i = 1; i < argc; ++i)
  {
    Pathname filename(argv[i], Pathname::SYSTEM_PATH);
    if (filename.has_extension(".pingus"))
    {
      PingusLevel plf(filename);

      emit_msgid(plf.get_levelname());
      emit_msgid(plf.get_description());
    }
    else if (filename.has_extension(".worldmap"))
    {
      // worldmaps don't contain translatable strings at the moment
    }
    else if (filename.has_extension(".story"))
    {
      ReaderObject reader_object = FileReader::parse(filename);
      ReaderMapping reader = reader_object.get_mapping();

      std::string tmp;
      if (reader.read_string("title", tmp))
      {
        emit_msgid(tmp);
      }

      ReaderCollection all_pages = reader.read_collection("pages");
      const auto& childs = all_pages.get_objects();
      for(auto it = childs.begin(); it != childs.end(); ++it)
      {
        ReaderMapping r = it->get_mapping();
        if (r.read_string("text", tmp))
        {
          emit_msgid(tmp);
        }
      }
    }
    else
    {
      raise_exception(std::runtime_error, "unknown file type: " << filename);
    }
  }

  return 0;
}
コード例 #5
0
ファイル: editor_level.cpp プロジェクト: drewbug/pingus
std::unique_ptr<EditorLevel>
EditorLevel::from_level_file(const Pathname& pathname)
{
  log_info("%1%", pathname.str());

  // Load the level from the file - we don't care what it's res_name is.
  PingusLevel plf(pathname);

  std::unique_ptr<EditorLevel> level(new EditorLevel);

  // Assign all of the level information to our LevelImpl
  level->impl->levelname        = plf.get_levelname();
  level->impl->description      = plf.get_description();
  level->impl->ambient_light    = plf.get_ambient_light();
  level->impl->size             = plf.get_size();
  level->impl->number_of_pingus = plf.get_number_of_pingus();
  level->impl->number_to_save   = plf.get_number_to_save();
  level->impl->actions          = plf.get_actions();
  level->impl->time             = plf.get_time();
  level->impl->author           = plf.get_author();
  level->impl->music            = plf.get_music();

  // remove obsolete "none" tag
  if (level->impl->music == "none")
  {
    level->impl->music = "";
  }

  // Get the objects
  auto objs = plf.get_objects();
  for (auto i = objs.begin(); i != objs.end(); i++)
  {
    LevelObjPtr obj = LevelObjFactory::create(*i);
    if (obj)
    {
      level->add_object(obj);
    }
  }

  level->sort();

  return level;
}
コード例 #6
0
ファイル: pingus-level2png.cpp プロジェクト: AMDmi3/pingus
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;
}
コード例 #7
0
ファイル: pingus-level.cpp プロジェクト: jcs12311/pingus
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;
}
コード例 #8
0
ファイル: pingus-level2png.cpp プロジェクト: jcs12311/pingus
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;
}