Esempio n. 1
0
static bool RemoveDirectoryFull(const Pathname &p, int part, char *buff, int bufsize)
{  
  if (p.GetPart(part+1,buff,bufsize,-1))
    if (RemoveDirectoryFull(p,part+1,buff,bufsize) == false) return false;
  p.GetPart(part,buff,bufsize, -1);
  return RemoveDirectory(buff) != FALSE;
}
Esempio n. 2
0
void Autoload::load()
{
  Thread * const thread = current_thread();
  void * last_special_binding = thread->last_special_binding();
  thread->bind_special(S_current_readtable, thread->symbol_value(S_standard_readtable));
  thread->bind_special(S_current_package, make_value(PACKAGE_SYS));
  thread->bind_special(S_read_base, FIXNUM_TEN);
  if (thread->symbol_value(S_autoload_verbose) != NIL)
    {
      String * prefix = new String(xcl_home());
      prefix->append_char('/');
      if (_filename == NULL)
        prefix->append("lisp/");
      Pathname * defaults = check_pathname(parse_namestring(prefix));
      Value device = defaults->device();
      Value directory = defaults->directory();
      Value name;
      if (_filename)
        name = make_value(new_simple_string(_filename));
      else
        name = make_value(the_symbol(operator_name())->name()->downcase());
      Value type = make_simple_string("xcl");
      Pathname * pathname = new Pathname(NIL, device, directory, name, type, NIL);
      if (CL_probe_file(make_value(pathname)) == NIL)
        {
          type = make_simple_string("lisp");
          pathname = new Pathname(NIL, device, directory, name, type, NIL);
        }
      AbstractString * namestring = pathname->namestring();
      AnsiStream * out = check_ansi_stream(thread->symbol_value(S_standard_output));
      String * message = new String("; Autoloading ");
      message->append(::prin1_to_string(operator_name())->as_c_string());
      message->append(" from ");
      message->append(namestring);
      message->append(" ...\n");
      out->fresh_line();
      out->write_string(message);
      CL_load(make_value(namestring));
      message = new String("; Autoloaded ");
      message->append(namestring);
      message->append("\n");
      out->fresh_line();
      out->write_string(message);
    }
  else if (_filename)
    {
      SYS_load_system_file(make_value(_filename));
    }
  else
    {
      String * namestring = new String("lisp/");
      namestring->append(the_symbol(operator_name())->name()->downcase());
      SYS_load_system_file(make_value(namestring));
    }
  thread->set_last_special_binding(last_special_binding);
}
Esempio n. 3
0
SpriteAction*
SpriteData::parse_action(const Pathname& dir, FileReader& reader)
{
  std::auto_ptr<SpriteAction> action (new SpriteAction);
  action->speed = 1.0;
  action->scale = 1.0f;
  action->offset = Vector2f(0, 0);
 
  reader.get("name", action->name);
  reader.get("speed", action->speed);
  reader.get("scale", action->scale);
  reader.get("offset", action->offset);
  
  FileReader grid_reader;
  std::vector<std::string> image_files;
  if(reader.get("images", image_files))
  {
    //parse_images(action.get(), dir, images);

    for(std::vector<std::string>::iterator file = image_files.begin(); file != image_files.end(); ++file)
    {
      Pathname path = dir;
      path.append_path(*file);
      action->surfaces.push_back(SurfaceManager::current()->get(path));
    }
  }
  else if(reader.get("image-grid", grid_reader)) 
  {
    std::string filename;
    int x_size = -1;
    int y_size = -1;
      
    grid_reader.get("file", filename);
    grid_reader.get("x-size", x_size);
    grid_reader.get("y-size", y_size);

    if(filename.empty() || x_size <= 0 || y_size <= 0)
      throw std::runtime_error("Invalid or too few data in image-grid");
      
    Pathname path = dir;
    path.append_path(filename);
    SurfaceManager::current()->load_grid(path, action->surfaces, x_size, y_size);
  }
    
  if(action->name == "")
    throw std::runtime_error("No Name defined for action");

  if(action->surfaces.size() == 0) 
  {
    std::ostringstream msg;
    msg << "Action '" << action->name << "' contains no images";
    throw std::runtime_error(msg.str());
  }
  return action.release();
}
Esempio n. 4
0
PingusLevel
PLFResMgr::load_plf_from_filename(const Pathname& pathname)
{
  // FIXME: Ugly resname guessing is ugly
  std::string res_name = System::basename(pathname.get_sys_path());

  // This should give us the tutorial/, wip/, etc. part of the res_name
  std::string dirname  = System::basename(System::dirname(pathname.get_sys_path()));

  return load_plf_raw(dirname + "/" + res_name.substr(0, res_name.length()-7),
                      pathname);
}
Esempio n. 5
0
bool Pathname::FullToRelative(const Pathname &relativeto)
{
  if (relativeto.IsNull() || IsNull()) return false;
  bool h1= HasDrive();
  bool h2= relativeto.HasDrive();
  if (h1 != h2) return false;         //rozdilny zpusob adresace - nelze vytvorit relatvni cestu
  if (h1== true && h2== true && toupper(GetDrive()) != toupper(relativeto.GetDrive()))
    return false;       //ruzne disky, nelze vytvorit relativni cestu
  if (strncmp(_path,"\\\\",2) == 0) //sitova cesta
  {
    int slsh = 0;           //citac lomitek
    const char *a = _path;
    const char *b = relativeto._path;
    while (toupper(*a) == toupper(*b) && *a && slsh<3)  //zacatek sitove cesty musi byt stejny
    {
      if (*a =='\\') slsh++;
      a++;b++;
    }
    if (slsh != 3) return false;      //pokud neni stejny, nelze vytvorit relativni cestu
  }
  int sublevel = 0;
  const char *ps1= _path;
  const char *ps2= relativeto._path;
  if (h1) 
  {ps1 += 2;ps2 += 2;}
  const char *sls = ps2;
  while (toupper(*ps1) == toupper(*ps2) && *ps1) 
  {
    if (*ps2=='\\') sls = ps2+1;
    ps1++;ps2++;
  }
  ps1 -= ps2-sls;
  if (sls)
  {    
    while (sls = strchr(sls,'\\'))
    {
      sls++;
      sublevel++;
    }
  }
  char *buff = (char *)alloca((sublevel*3+strlen(ps1)+1)*sizeof(*buff));
  char *pos = buff;
  for (int i = 0;i<sublevel;i++) 
  {strcpy(pos,"..\\");pos += 3;}
  strcpy(pos,ps1);
  SetDrive(0);
  SetDirectory(buff);
  return true;
}
Esempio n. 6
0
 bool visit_Pathname(Pathname & p)
 {
     //std::cout << "### apply(" << this->_base_dir << ") to " << p << " ... reset=" << this->_reset << std::endl;
     //std::cout << "p before: b<" << p.base_dir() << "> r<" << p.rel_path() << "> a<" << p.abs_path() << "> i<" << p.is_abs() << ">" << &p << std::endl;
     if(this->_reset)
     {
         p.reset_base_dir(this->_base_dir);
     }
     else
     {
         p.set_base_dir(this->_base_dir);
     }
     //std::cout << "p after:  b<" << p.base_dir() << "> r<" << p.rel_path() << "> a<" << p.abs_path() << "> i<" << p.is_abs() << ">" << &p << std::endl;
     return true;
 }
Esempio n. 7
0
PingusDemo::PingusDemo(const Pathname& pathname) :
  m_levelname(),
  m_checksum(),
  m_events()
{
  std::vector<FileReader> lines = FileReader::parse_many(pathname);

  if (lines.empty())
  {
    raise_exception(std::runtime_error, "'" << pathname.str() << "', demo file is empty");
  }
  else
  {
    if (lines.front().get_name() == "level")
    {
      const FileReader& reader = lines.front();
      if (!reader.read_string("name", m_levelname))
      {
        raise_exception(std::runtime_error, "(level (name ...)) entry missing in demo file '" << pathname.str() << "'");
      }

      reader.read_string("checksum", m_checksum);
    }

    for(std::vector<FileReader>::iterator i = lines.begin()+1; i != lines.end(); ++i)
    {
      if (i->get_name() != "checksum") // workaround for old incorrectly recorded demo files
      {
        m_events.push_back(ServerEvent(*i));
      }
    }
  }
}
Esempio n. 8
0
void
Options::save(const Pathname& filename) const
{
  std::ostringstream out;
  SExprFileWriter writer(out);

  writer.begin_section("pingus-config");

  if (framebuffer_type.is_set())
    writer.write_enum("renderer", framebuffer_type.get(), framebuffer_type_to_string);

  if (master_volume.is_set())
    writer.write_int("master-volume", master_volume.get());

  if (sound_volume.is_set())
    writer.write_int("sound-volume", sound_volume.get());

  if (music_volume.is_set())
    writer.write_int("music-volume", music_volume.get());

  if (geometry.is_set())
    writer.write_size("geometry", geometry.get());

  if (fullscreen_resolution.is_set())
    writer.write_size("fullscreen-resolution", fullscreen_resolution.get());

  if (fullscreen.is_set())
    writer.write_bool("fullscreen", fullscreen.get());

  if (resizable.is_set())
    writer.write_bool("resizable", resizable.get());

  if (mouse_grab.is_set())
    writer.write_bool("mouse-grab", mouse_grab.get());

  if (print_fps.is_set())
    writer.write_bool("print-fps", print_fps.get());

  if (controller.is_set())
    writer.write_string("controller", controller.get());

  if (language.is_set())
    writer.write_string("language", language.get());
  
  if (software_cursor.is_set())
    writer.write_bool("software-cursor", software_cursor.get());

  if (auto_scrolling.is_set())
    writer.write_bool("auto-scrolling", auto_scrolling.get());

  if (drag_drop_scrolling.is_set())
    writer.write_bool("drag-drop-scrolling", drag_drop_scrolling.get());
  
  writer.end_section(); // pingus-config

  out << std::endl;

  System::write_file(filename.get_sys_path(), out.str());
}
Esempio n. 9
0
Surface::Surface(const Pathname& pathname)
{
  SDL_Surface* surface = IMG_Load(pathname.get_sys_path().c_str());
  if (surface)
    {
      impl = boost::shared_ptr<SurfaceImpl>(new SurfaceImpl(surface, true));
    }
}
Esempio n. 10
0
// Save the current level
void
EditorScreen::save(const Pathname& file)
{
  std::string filename = file.get_sys_path();

  if (System::get_file_extension(filename) == "prefab")
  {
    level_pathname = file;
    log_info("Save to: %1%", file.str());
    plf->save_prefab(filename);
  }
  else
  {
    level_pathname = file;
    log_info("Save to: %1%", file.str());
    plf->save_level(filename);
  }
}
Esempio n. 11
0
Levelset::Levelset(const Pathname& pathname)
  : completion(0)
{
  FileReader reader = FileReader::parse(pathname);
  if (reader.get_name() != "pingus-levelset")
    {
      PingusError::raise("Error: " + pathname.str() + ": not a 'pingus-levelset' file");
    }
  else
    {
      reader.read_string("title",       title);
      reader.read_string("description", description);
      std::string image;
      if (reader.read_string("image", image))
        this->image = Resource::load_sprite(image);

      FileReader level_reader = reader.read_section("levels");
      std::vector<FileReader> sections = level_reader.get_sections();
      for(std::vector<FileReader>::iterator i = sections.begin(); i != sections.end(); ++i)
        {
          if (i->get_name() == "level")
            {
              Level* level = new Level();

              if (i->read_string("filename", level->resname))
                {
                  level->plf        = PLFResMgr::load_plf(level->resname);
                  
                  level->accessible = false;
                  level->finished   = false;
                      
                  levels.push_back(level);
                }
              else
                {
                  std::cout << "Levelset: " << pathname.str() << " is missing filename tag" << std::endl;
                  delete level;
                }
            }
        }
    }

  refresh();
}
Esempio n. 12
0
void
ResourceManager::add_resources_from_directory(const Pathname& path)
{
  assert(path.get_type() == Pathname::DATA_PATH);

  std::vector<std::string> files = System::opendir_recursive(path.get_sys_path());
  for(auto it = files.begin(); it != files.end(); ++it)
  {
    if (StringUtil::has_suffix(*it, ".sprite") ||
        StringUtil::has_suffix(*it, ".png") ||
        StringUtil::has_suffix(*it, ".jpg"))
    {
      // FIXME: ugly hack to remove "data/images/" prefix, need better
      // way to cut stuff away
      m_resources.push_back(System::cut_file_extension(it->substr(12)));
    }
  }

  std::sort(m_resources.begin(), m_resources.end());
}
Esempio n. 13
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;
        }
    }
}
Esempio n. 14
0
bool Pathname::RelativeToFull(const Pathname &ref)
{
  if (ref.IsNull() || IsNull()) return false;  
  const char *beg;
  if (HasDrive())
    if (toupper(GetDrive()) != toupper(ref.GetDrive())) return false;
    else beg = _path+2;
  else beg = _path;
  const char *end = strchr(ref._path,0);  
  if (beg[0] =='\\')
  {
    int np;
    if (ref.HasDrive()) end = ref._path+2;
    else  if (np = ref.IsNetworkPath()) end = ref._path+np;
    else end = ref._path;
  }
  else while (strncmp(beg,"..\\",3) == 0 || strncmp(beg,".\\",2) == 0)
  {
    if (beg[1] =='.')
    {
      if (end>ref._path)
      {
        end--;
        while (end>ref._path && end[-1]!='\\') end--;
      }      
      beg += 3;
    }
    else 
      beg += 2;
  }
  int partln = end-ref._path;
  char *buff = (char *)alloca((partln+strlen(beg)+1)*sizeof(*buff));
  memcpy(buff,ref._path,partln);
  strcpy(buff+partln,beg);
  SetDrive(0);
  SetDirectory(buff);
  return true;
}
Esempio n. 15
0
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;
}
Esempio n. 16
0
static bool RemoveDirRecursive(const char *dir, const char *mask)
{
  if (dir == 0 || dir[0] == 0) return false;
  if (strcmp(dir,"\\") == 0) return false;
  bool res = true;
  Pathname newp;
  newp.SetDirectory(dir);
  if (mask)
  {
    WIN32_FIND_DATAA fnd;
    HANDLE h;
    newp.SetFilename(mask);
    h = FindFirstFileA(newp,&fnd);
    if (h) 
    {
      do
      {
        if (!(fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
        {
          newp.SetFilename(fnd.cFileName);
          if (DeleteFile(newp) == FALSE) res = false;
        }
      }while (FindNextFileA(h,&fnd));
      CloseHandle(h);
    }
  }
  {
    WIN32_FIND_DATAA fnd;
    HANDLE h;
    newp.SetFilename("*.*");
    h = FindFirstFileA(newp,&fnd);
    if (h) 
    {
      do
      {
        if ((fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(fnd.cFileName,".") != 0 && strcmp(fnd.cFileName,"..") != 0)
        {
          newp.SetFilename(fnd.cFileName);
          if (RemoveDirRecursive(newp,mask) == false) res = false;
          else DeleteFile(newp);
        }
      }while (FindNextFileA(h,&fnd));
      CloseHandle(h);
    }
  }
  return res;

}
Esempio n. 17
0
std::vector<ReaderObject>
Reader::parse_many(const Pathname& pathname)
{
  return {};
#if 0
  std::shared_ptr<lisp::Lisp> sexpr = lisp::Parser::parse(pathname.get_sys_path());
  if (sexpr)
  {
    std::vector<Reader> sections;
    for(size_t i = 0; i < sexpr->get_list_size(); ++i)
    {
      sections.push_back(Reader(std::make_shared<SExprReaderImpl>(sexpr->get_list_elem(i))));
    }

    return sections;
  }
  else
  {
    return std::vector<Reader>();
  }
#endif
}
Esempio n. 18
0
std::unique_ptr<EditorLevel>
EditorLevel::from_prefab_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.
  PrefabFile prefab = PrefabFile::from_path(pathname);

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

  // FIMXE: there would be better way to handle prefab size, but it's
  // probably not worth the effort
  level->impl->size.width  = 1920;
  level->impl->size.height = 1200;

  // FIXME: overrides are getting ignored

  // Get the objects
  auto objs = prefab.get_objects();
  for (auto i = objs.begin(); i != objs.end(); i++)
  {
    LevelObjPtr obj = LevelObjFactory::create(*i);
    if (obj)
    {
      // move origin of the level to the center of it
      obj->set_pos(obj->get_pos() + Vector3f(static_cast<float>(level->impl->size.width)/2.0f,
                                             static_cast<float>(level->impl->size.height)/2.0f));

      level->add_object(obj);
    }
  }

  level->sort();

  return level;
}
Esempio n. 19
0
// Load a new level
void
EditorScreen::load(const Pathname& file)
{
  try
  {
    std::string filename = file.get_sys_path();

    if (System::get_file_extension(filename) == "prefab")
    {
      level_pathname = file;
      set_level(EditorLevel::from_prefab_file(level_pathname));
    }
    else
    {
      level_pathname = file;
      set_level(EditorLevel::from_level_file(level_pathname));
    }
  }
  catch(const std::exception& err)
  {
    // FIXME: show a MessageBox
    log_error("%1%", err.what());
  }
}
Esempio n. 20
0
std::string
System::checksum(const Pathname& pathname)
{
  return checksum(pathname.get_sys_path());
}
Esempio n. 21
0
ControllerPtr
Manager::create_controller(const Pathname& filename)
{
  ControllerPtr controller(new Controller(desc));

  ReaderObject reader_object = Reader::parse(filename);

  if (reader_object.get_name() != "pingus-controller")
  {
    raise_exception(std::runtime_error,
                    "Controller: invalid config file '" << filename.str() << "'");
  }
  else
  {
    ReaderMapping reader = reader_object.get_mapping();

    ReaderMapping controls_mapping;
    if (!reader.read_mapping("controls", controls_mapping))
    {
      log_warn("%1%: 'controls' section missing", filename);
    }
    else
    {
      for (const auto& key : controls_mapping.get_keys())
      {
        ReaderCollection collection;
        if (!controls_mapping.read_collection(key.c_str(), collection))
        {
          log_error("%1%: mapping must contain object at %2%", filename, key);
        }
        else
        {
          if (StringUtil::has_suffix(key, "pointer"))
          {
            int id = desc.get_definition(key).id;
            ControllerPointer* ctrl_pointer = controller->get_pointer(id);
            for(const auto& object : collection.get_objects())
            {
              auto pointer = create_pointer(object, ctrl_pointer);
              if (pointer)
              {
                ctrl_pointer->add_pointer(std::move(pointer));
              }
              else
              {
                log_error("Manager: pointer: Couldn't create pointer %1%", object.get_name());
              }
            }
          }
          else if (StringUtil::has_suffix(key, "scroller"))
          {
            int id = desc.get_definition(key).id;
            ControllerScroller* ctrl_scroller = controller->get_scroller(id);
            for(const auto& object : collection.get_objects())
            {
              auto scroller = create_scroller(object, ctrl_scroller);
              if (scroller)
              {
                ctrl_scroller->add_scroller(std::move(scroller));
              }
              else
              {
                log_error("Manager: scroller: Couldn't create scroller %1%", object.get_name());
              }
            }
          }
          else if (StringUtil::has_suffix(key, "button"))
          {
            int id = desc.get_definition(key).id;
            ControllerButton* ctrl_button = controller->get_button(id);
            for(const auto& object : collection.get_objects())
            {
              auto button = create_button(object, ctrl_button);
              if (button)
              {
                ctrl_button->add_button(std::move(button));
              }
              else
              {
                log_error("Manager: button: Couldn't create button %1%", object.get_name());
              }
            }
          }
          else if (StringUtil::has_suffix(key, "axis"))
          {
            int id = desc.get_definition(key).id;
            ControllerAxis* ctrl_axis = controller->get_axis(id);
            for(const auto& object : collection.get_objects())
            {
              auto axis = create_axis(object, ctrl_axis);
              if (axis)
              {
                ctrl_axis->add_axis(std::move(axis));
              }
              else
              {
                log_error("Manager: axis: Couldn't create axis %1%", object.get_name());
              }
            }
          }
          else if (StringUtil::has_suffix(key, "keyboard"))
          {
            int id = desc.get_definition(key).id;
            ControllerKeyboard* ctrl_keyboard = controller->get_keyboard(id);
            for(const auto& object : collection.get_objects())
            {
              std::unique_ptr<Keyboard> keyboard = create_keyboard(object, ctrl_keyboard);
              if (keyboard)
              {
                ctrl_keyboard->add_keyboard(std::move(keyboard));
              }
              else
              {
                log_error("Manager: keyboard: Couldn't create keyboard %1%", object.get_name());
              }
            }
          }
          else
          {
            raise_exception(std::runtime_error, "Manager: Unkown Element in Controller Config: "
                            << key);
          }
        }
      }
    }
  }

  controllers.push_back(controller);
  return controller;
}
Esempio n. 22
0
void
PingusLevel::load(const std::string& resname,
                  const Pathname& pathname)
{
  impl->checksum = System::checksum(pathname);

  impl->resname = resname;
  ReaderObject reader_object = FileReader::parse(pathname);

  if (reader_object.get_name() != "pingus-level")
  {
    raise_exception(std::runtime_error, "Error: " << pathname.str() << ": not a 'pingus-level' file");
  }
  else
  {
    ReaderMapping reader = reader_object.get_mapping();

    int version;
    if (reader.read_int("version", version))
      log_info("Levelfile Version: %1%", version);
    else
      log_info("Unknown Levelfile Version: %1%", version);

    ReaderMapping head;
    if (!reader.read_mapping("head", head))
    {
      raise_exception(std::runtime_error, "Error: (head) section not found in '" << pathname.str() << "'");
    }
    else
    {
      log_info("Reading head");
      head.read_string("levelname",        impl->levelname);
      head.read_string("description",      impl->description);
      head.read_size  ("levelsize",        impl->size);
      head.read_string("music",            impl->music);
      head.read_int   ("time",             impl->time);
      head.read_int   ("number-of-pingus", impl->number_of_pingus);
      head.read_int   ("number-to-save",   impl->number_to_save);
      head.read_colorf("ambient-light",    impl->ambient_light);
      head.read_string("author",           impl->author);

      log_info("Size: %1%x%2%", impl->size.width, impl->size.height);

      ReaderMapping actions;
      if (head.read_mapping("actions", actions))
      {
        std::vector<std::string> lst = actions.get_keys();
        for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i)
        {
          int count = 0;
          log_info("Actions: %1%", i->c_str());
          if (actions.read_int(i->c_str(), count))
            impl->actions[*i] = count;
        }
      }
      else
      {
        raise_exception(std::runtime_error,
                        "Error: (pingus-level head actions) not found in '" << pathname.str() << "'");
      }
    }

    ReaderCollection collection;
    if (reader.read_collection("objects", collection))
    {
      std::vector<ReaderObject> object_lst = collection.get_objects();
      for(auto i = object_lst.begin(); i != object_lst.end(); ++i)
      {
        impl->objects.push_back(*i);
      }
    }
  }
}
Esempio n. 23
0
Credits::Credits(const Pathname& filename) :
  scene_context(),
  fast_scrolling(false),
  background("core/menu/wood"),
  blackboard("core/menu/blackboard"),
  pingu("core/misc/creditpingu"),
  font(),
  font_small(),
  is_init(),
  end_offset(),
  offset(),
  credits()
{
  scene_context = util::make_unique<SceneContext>();
  fast_scrolling = false;
  gui_manager->add(util::make_unique<CreditsOkButton>(this));

  font       = Fonts::chalk_normal;
  font_small = Fonts::chalk_large;

  // The credits vector holds the strings to display. The first
  // character of each string is a special character, which indicates
  // the size of the font or other special stuff. "-" means large
  // font, "_" is a small font and "n" means a newline.

  { // read credit information from filename
    std::ifstream in(filename.get_sys_path());
    if (!in)
    {
      log_error("couldn't open %1%", filename);

      std::ostringstream out;
      out << "couldn't open " << filename;
      credits.push_back(out.str());
    }
    else
    {
      std::string line;
      while(std::getline(in, line))
      {
        credits.push_back(line);
      }
    }
  }

  end_offset = -static_cast<float>(Display::get_height())/2 - 50; // screen height + grace time
  for (std::vector<std::string>::iterator i = credits.begin(); i != credits.end(); ++i)
  {
    switch ((*i)[0])
    {
      case '-':
        end_offset += static_cast<float>(font.get_height() + 5);
        break;
      case '_':
        end_offset += static_cast<float>(font_small.get_height() + 5);
        break;
      case 'n':
        end_offset += 50;
        break;
      default:
        log_error("Credits: Syntax error: Unknown format: '%1%'", (*i)[0]);
        break;
    }
  }
  end_offset = -end_offset;
}
Esempio n. 24
0
void
PingusLevel::load(const std::string& resname,
                  const Pathname& pathname)
{
  impl->resname = resname;
  FileReader reader = FileReader::parse(pathname);

  if (reader.get_name() != "pingus-level")
    {
      PingusError::raise("Error: " + pathname.str() + ": not a 'pingus-level' file");
    }
  else
    {
      int version;
      if (reader.read_int("version", version))
        pout(PINGUS_DEBUG_LOADING) << "Levelfile Version: " << version << std::endl;
      else
        pout(PINGUS_DEBUG_LOADING) << "Unknown Levelfile Version: " << version << std::endl;

      FileReader head;
      if (!reader.read_section("head", head))
        {
          PingusError::raise("Error: (head) section not found in '" + pathname.str() + "'");
        }
      else
        {
          pout(PINGUS_DEBUG_LOADING) << "Reading head" << std::endl;
          head.read_string("levelname",        impl->levelname);
          head.read_string("description",      impl->description);
          head.read_size  ("levelsize",        impl->size);
          head.read_string("music",            impl->music);
          head.read_int   ("time",             impl->time);
          head.read_int   ("difficulty",       impl->difficulty);
          head.read_int   ("number-of-pingus", impl->number_of_pingus);
          head.read_int   ("number-to-save",   impl->number_to_save);
          head.read_color ("ambient-light",    impl->ambient_light);
          head.read_string("author",           impl->author);

          pout(PINGUS_DEBUG_LOADING) << "Size: " << impl->size.width << " " << impl->size.height << std::endl;
          
          FileReader actions;
          if (head.read_section("actions", actions))
            {
              std::vector<std::string> lst = actions.get_section_names();
              for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i)
                {
                  int count = 0;
                  pout(PINGUS_DEBUG_LOADING) << "Actions: " << i->c_str() << std::endl;
                  if (actions.read_int(i->c_str(), count))
                    impl->actions[*i] = count;
                }
            }
          else
            {
              PingusError::raise("Error: (pingus-level head actions) not found in '" + pathname.str() + "'"); 
            }
        }
      
      FileReader objects;
      if (reader.read_section("objects", objects))
        {
          std::vector<FileReader> object_lst = objects.get_sections();
          for(std::vector<FileReader>::iterator i = object_lst.begin(); i != object_lst.end(); ++i)
            {
              impl->objects.push_back(*i);
            }
        }
    }
}
Esempio n. 25
0
ControllerPtr
Manager::create_controller(const Pathname& filename)
{
  ControllerPtr controller(new Controller(desc));
  
  FileReader reader = FileReader::parse(filename);

  if (reader.get_name() != "pingus-controller")
  {
    raise_exception(std::runtime_error, 
                    "Controller: invalid config file '" << filename.str() << "'");
  }
  else
  {
    const std::vector<FileReader>& sections = reader.get_sections();
    for (std::vector<FileReader>::const_iterator i = sections.begin();
         i != sections.end(); ++i)
    {
      if (StringUtil::has_suffix(i->get_name(), "pointer"))
      {
        const std::vector<FileReader>& pointers = i->get_sections();
        for(std::vector<FileReader>::const_iterator j = pointers.begin(); j != pointers.end(); ++j)
        {
          int id = desc.get_definition(i->get_name()).id;
          ControllerPointer* ctrl_pointer = controller->get_pointer(id);
          Pointer* pointer = create_pointer(*j, ctrl_pointer);
          if (pointer)
            ctrl_pointer->add_pointer(pointer);
          else
            log_error("Manager: pointer: Couldn't create pointer %1%", j->get_name());
        }

      }
      else if (StringUtil::has_suffix(i->get_name(), "scroller"))
      {
        const std::vector<FileReader>& scrollers = i->get_sections();
        for(std::vector<FileReader>::const_iterator j = scrollers.begin(); j != scrollers.end(); ++j)
        {
          int id = desc.get_definition(i->get_name()).id;
          ControllerScroller* ctrl_scroller = controller->get_scroller(id);
          Scroller* scroller = create_scroller(*j, ctrl_scroller);
          if (scroller)
            ctrl_scroller->add_scroller(scroller);
          else
            log_error("Manager: scroller: Couldn't create scroller %1%", j->get_name());
        }

      }
      else if (StringUtil::has_suffix(i->get_name(), "button"))
      {             
        const std::vector<FileReader>& buttons = i->get_sections();
        for(std::vector<FileReader>::const_iterator j = buttons.begin(); j != buttons.end(); ++j)
        {
          int id = desc.get_definition(i->get_name()).id;
          ControllerButton* ctrl_button = controller->get_button(id);
          Button* button = create_button(*j, ctrl_button);
          if (button)
            ctrl_button->add_button(button);
          else
            log_error("Manager: button: Couldn't create button %1%", j->get_name());
        }
      }
      else if (StringUtil::has_suffix(i->get_name(), "axis"))
      {
        const std::vector<FileReader>& axes = i->get_sections();
        for(std::vector<FileReader>::const_iterator j = axes.begin(); j != axes.end(); ++j)
        {
          int id = desc.get_definition(i->get_name()).id;
          ControllerAxis* ctrl_axis = controller->get_axis(id);
          Axis* axis = create_axis(*j, ctrl_axis);
          if (axis)
            ctrl_axis->add_axis(axis);
          else
            log_error("Manager: axis: Couldn't create axis %1%", j->get_name());
        }
      }
      else if (StringUtil::has_suffix(i->get_name(), "keyboard"))
      {
        const std::vector<FileReader>& keyboards = i->get_sections();
        for(std::vector<FileReader>::const_iterator j = keyboards.begin(); j != keyboards.end(); ++j)
        {
          int id = desc.get_definition(i->get_name()).id;
          ControllerKeyboard* ctrl_keyboard = controller->get_keyboard(id);
          Keyboard* keyboard = create_keyboard(*j, ctrl_keyboard);
          if (keyboard)
            ctrl_keyboard->add_keyboard(keyboard);
          else
            log_error("Manager: keyboard: Couldn't create keyboard %1%", j->get_name());
        }              
      }
      else
      {
        raise_exception(std::runtime_error, "Manager: Unkown Element in Controller Config: "
                        << i->get_name());
      }
    }
  }

  controllers.push_back(controller);
  return controller;
}
Esempio n. 26
0
SpriteData::SpriteData(const Pathname& pathname) :
  actions()
{
  if (pathname.exists())
  {
    const std::string ext = pathname.get_extension();

    if (ext == "sprite")
    {
      FileReader reader = FileReader::parse(pathname);

      if(reader.get_name() != "sprite") {
        std::ostringstream msg;
        msg << "File " << pathname << " is not a windstille sprite";
        throw std::runtime_error(msg.str());
      }
    
      parse(pathname.get_dirname(), reader);
    }
    else if (ext == "png" || ext == "jpg")
    {
      std::auto_ptr<SpriteAction> action(new SpriteAction());
      action->name   = "default";
      action->speed  = 1.0;
      action->scale  = 1.0f;
      action->offset = Vector2f(0, 0);
      action->surfaces.push_back(Surface::create(pathname));
      actions.push_back(action.release());
    }
    else
    {
      std::ostringstream str;
      str << "Sprite " << pathname << " has unknown suffix: '" << ext  << "'";
      throw std::runtime_error(str.str());
    }
  }
  else if (pathname.get_raw_path().length() > std::string(".sprite").length())
  { // If sprite file is not found, we search for a file with the
    // same name ending in .png
    Pathname pngfile(pathname.get_raw_path().substr(0, pathname.get_raw_path().length() - std::string(".sprite").length()) + ".png",
                     pathname.get_type());

    if (pngfile.exists())
    {
      std::auto_ptr<SpriteAction> action(new SpriteAction);
      action->name   = "default";
      action->speed  = 1.0;
      action->scale  = 1.0f;
      action->offset = Vector2f(0, 0);
      action->surfaces.push_back(Surface::create(pngfile));
      actions.push_back(action.release());
    }
    else
    {
      std::ostringstream str;
      str << "Couldn't find " << pngfile;
      throw std::runtime_error(str.str());
    }
  }
  else
  {
    std::ostringstream str;
    str << "Couldn't find " << pathname;
    throw std::runtime_error(str.str());
  }
}
Esempio n. 27
0
bool Pathname::CreateFolder(const char *path, void *security_descriptor)
{
  Pathname pth;
  pth.SetDirectory(path);
  return pth.CreateFolder(security_descriptor);
}
Esempio n. 28
0
ReaderObject
Reader::parse(const Pathname& pathname)
{
  return parse(pathname.get_sys_path());
}
Esempio n. 29
0
void
SExprFileWriter::write_path(const char* name, const Pathname& path)
{
  write_string(name, path.get_raw_path());
}
Esempio n. 30
0
Pathname::Pathname(const Pathname &other)
{
  _fullpath = NULL;
  if (other.IsNull()) SetNull();
  else RebuildData(other._path,other._filetitle,other._extension,strlen(other._path),strlen(other._filetitle),strlen(other._extension));  
}