当前位置: 首页>>代码示例>>C++>>正文


C++ Savegame类代码示例

本文整理汇总了C++中Savegame的典型用法代码示例。如果您正苦于以下问题:C++ Savegame类的具体用法?C++ Savegame怎么用?C++ Savegame使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Savegame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lua_getfield

/**
 * \brief __newindex function of the environment of the savegame file.
 *
 * This special __newindex function catches declaration of global variables
 * to store them into the savegame.
 *
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int Savegame::l_newindex(lua_State* l) {

  return LuaTools::exception_boundary_handle(l, [&] {
    lua_getfield(l, LUA_REGISTRYINDEX, "savegame");
    Savegame* savegame = static_cast<Savegame*>(lua_touserdata(l, -1));
    lua_pop(l, 1);

    const std::string& key = LuaTools::check_string(l, 2);

    switch (lua_type(l, 3)) {

    case LUA_TBOOLEAN:
      savegame->set_boolean(key, lua_toboolean(l, 3));
      break;

    case LUA_TNUMBER:
      savegame->set_integer(key, (int) lua_tointeger(l, 3));
      break;

    case LUA_TSTRING:
      savegame->set_string(key, lua_tostring(l, 3));
      break;

    default:
      LuaTools::type_error(l, 3, "string, number or boolean");
    }

    return 0;
  });
}
开发者ID:cooljith91112,项目名称:solarus,代码行数:39,代码来源:Savegame.cpp

示例2: int

void
Levelset::refresh()
{
  for(std::vector<Level*>::iterator i = levels.begin(); i != levels.end(); ++i)
    {
      Savegame* savegame = SavegameManager::instance()->get((*i)->resname);

      if (savegame)
        {
          (*i)->accessible = (savegame->get_status() != Savegame::NONE);
          (*i)->finished   = (savegame->get_status() == Savegame::FINISHED);
        }
    }

  if (!levels.empty())
    {
      levels[0]->accessible = true; 
      for(std::vector<Level*>::size_type i = 0; i < levels.size()-1; ++i)
        if (levels[i]->finished)
          levels[i+1]->accessible = true;
    }

  completion = 0;
  for(std::vector<Level*>::iterator i = levels.begin(); i != levels.end(); ++i)
    if ((*i)->finished)
      completion += 1;
  completion = Math::clamp(0, completion * 100 / int(levels.size()), 100);
}
开发者ID:jinguoliang,项目名称:Maemo-pingus,代码行数:28,代码来源:levelset.cpp

示例3: Savegame

void
SavegameManager::store(Savegame& arg_savegame)
{
  Savegame* savegame = new Savegame(arg_savegame);
  SavegameTable::iterator i = find(savegame->get_filename());
  if (i == savegames.end())
  { // don't know anything about the savegame
    savegames.push_back(savegame);
  }
  else
  { // already have such a savegame
    if ((*i)->get_status() == Savegame::FINISHED
        && savegame->get_status() == Savegame::ACCESSIBLE)
    { // saved savegame is better then new game
      delete savegame;
    }
    else
    { // new game is better or equal, save it
      delete *i;
      *i = savegame;
    }
  }

  flush();
}
开发者ID:jcs12311,项目名称:pingus,代码行数:25,代码来源:savegame_manager.cpp

示例4: lua_getfield

/**
 * \brief __newindex function of the environment of the savegame file.
 *
 * This special __newindex function catches declaration of global variables
 * to store them into the savegame.
 *
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int Savegame::l_newindex(lua_State* l) {

  lua_getfield(l, LUA_REGISTRYINDEX, "savegame");
  Savegame* savegame = static_cast<Savegame*>(lua_touserdata(l, -1));
  lua_pop(l, 1);

  const std::string& key = luaL_checkstring(l, 2);

  switch (lua_type(l, 3)) {

    case LUA_TBOOLEAN:
      savegame->set_boolean(key, lua_toboolean(l, 3));
      break;

    case LUA_TNUMBER:
      savegame->set_integer(key, int(lua_tointeger(l, 3)));
      break;

    case LUA_TSTRING:
      savegame->set_string(key, lua_tostring(l, 3));
      break;

   default:
      luaL_typerror(l, 3, "string, number or boolean");
  }

  return 0;
}
开发者ID:PaperSeed,项目名称:solarus,代码行数:37,代码来源:Savegame.cpp

示例5:

bool
LevelDot::finished()
{
  Savegame* savegame = SavegameManager::instance()->get(plf.get_resname());
  if (savegame && savegame->get_status() == Savegame::FINISHED)
    return true;
  else
    return false;
}
开发者ID:jcs12311,项目名称:pingus,代码行数:9,代码来源:level_dot.cpp

示例6: filename

SavegameManager::SavegameManager(const std::string& arg_filename) :
  filename(System::get_userdir() + arg_filename),
  savegames()
{
  assert(instance_ == 0);
  instance_ = this;

  std::shared_ptr<lisp::Lisp> sexpr;

  try 
  {
    sexpr = lisp::Parser::parse(filename);
  }
  catch (const std::runtime_error& e) 
  {
    std::cerr << "SavegameManager: " << e.what() << std::endl;
    return;
  }

  if (!sexpr)
  {
    std::cerr << "SavegameManager: Couldn't find savegame file '" <<
      filename << "', starting with an empty one." << std::endl;
    return;
  }

  SExprFileReader reader(sexpr->get_list_elem(0));
  if (reader.get_name() != "pingus-savegame")
  {
    std::cerr << "Error: " << filename << ": not a (pingus-savegame) file" << std::endl;
    return;
  }

  const std::vector<FileReader>& sections = reader.get_sections();
  for(std::vector<FileReader>::const_iterator i = sections.begin();
      i != sections.end(); ++i)
  {
    Savegame* savegame = new Savegame(*i);
    SavegameTable::iterator j = find(savegame->get_filename());
    if (j != savegames.end())
    { // overwrite duplicates, shouldn't happen, but harmless
      std::cout << "SavegameManager: name collision: " << savegame->get_filename() << std::endl;
      delete *j;
      *j = savegame;
    }
    else
    {
      savegames.push_back(savegame);
    }
  }
}
开发者ID:jcs12311,项目名称:pingus,代码行数:51,代码来源:savegame_manager.cpp

示例7: ListDir

void iwSaveLoad::RefreshTable()
{
    static bool loadedOnce = false;

    GetCtrl<ctrlTable>(0)->DeleteAllItems();

    std::vector<std::string> saveFiles = ListDir(GetFilePath(FILE_PATHS[85]), "sav");
    for(std::vector<std::string>::iterator it = saveFiles.begin(); it != saveFiles.end(); ++it)
    {
        Savegame save;

        // Datei öffnen
        if(!save.Load(*it, false, false))
        {
            // Show errors only first time this is loaded
            if(!loadedOnce)
            {
                LOG.write(_("Invalid Savegame %1%! Reason: %2%\n"))
                    % *it
                    % (save.GetLastErrorMsg().empty() ? _("Unknown") : save.GetLastErrorMsg());
            }
            continue;
        }

        // Zeitstring erstellen
        std::string dateStr = TIME.FormatTime("%d.%m.%Y - %H:%i", &save.save_time);

        // Dateiname noch rausextrahieren aus dem Pfad
        bfs::path path = *it;
        if(!path.has_filename())
            continue;
        bfs::path fileName = path.filename();

        // ".sav" am Ende weg
        RTTR_Assert(fileName.has_extension());
        fileName.replace_extension();

        std::string fileNameStr = cvWideStringToUTF8(fileName.wstring());
        std::string startGF = helpers::toString(save.start_gf);

        // Und das Zeug zur Tabelle hinzufügen
        GetCtrl<ctrlTable>(0)->AddRow(0, fileNameStr.c_str(), save.mapName.c_str(), dateStr.c_str(), startGF.c_str(), it->c_str());
    }

    // Nach Zeit Sortieren
    bool bFalse = false;
    GetCtrl<ctrlTable>(0)->SortRows(2, &bFalse);
    loadedOnce = true;
}
开发者ID:vader1986,项目名称:s25client,代码行数:49,代码来源:iwSave.cpp

示例8: savegame_

void
LevelDot::unlock()
{
  Savegame* savegame = SavegameManager::instance()->get(plf.get_resname());
  if (savegame == 0 || savegame->get_status() == Savegame::NONE)
  {
    Savegame savegame_(plf.get_resname(),
                       Savegame::ACCESSIBLE,
                       0,
                       0);
    SavegameManager::instance()->store(savegame_);
  }
  else
  {
  }
}
开发者ID:jcs12311,项目名称:pingus,代码行数:16,代码来源:level_dot.cpp

示例9: Screen

/**
 * @brief Creates a game.
 * @param solarus the application object
 * @param savegame the saved data of this game (the specified object will be copied and stored into the game)
 */
Game::Game(Solarus &solarus, Savegame &savegame):

  Screen(solarus),
  savegame(savegame),
  pause_key_available(true),
  pause_menu(NULL), 
  gameover_sequence(NULL),
  reseting(false),
  restarting(false),
  keys_effect(NULL),
  current_map(NULL),
  next_map(NULL),
  previous_map_surface(NULL),
  transition_style(Transition::IMMEDIATE),
  transition(NULL),
  dungeon(NULL),
  crystal_switch_state(false),
  hud(NULL),
  hud_enabled(true),
  dialog_box(NULL) {

  // notify objects
  get_equipment().set_game(*this);
  solarus.get_debug_keys().set_game(this);

  // initialize members
  controls = new GameControls(*this);
  dialog_box = new DialogBox(*this);
  hero = new Hero(get_equipment());
  keys_effect = new KeysEffect();
  hud = new HUD(*this);

  // launch the starting map
  set_current_map(savegame.get_integer(Savegame::STARTING_MAP), "", Transition::FADE);
}
开发者ID:ziz,项目名称:solarus,代码行数:40,代码来源:Game.cpp

示例10: luaL_checkstring

/**
 * \brief Implementation of sol.game.load().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::game_api_load(lua_State* l) {

  const std::string& file_name = luaL_checkstring(l, 1);

  if (FileTools::get_quest_write_dir().empty()) {
    error(l, "Cannot load savegame: no write directory was specified in quest.dat");
  }

  Savegame* savegame = new Savegame(get_lua_context(l).get_main_loop(), file_name);

  RefCountable::ref(savegame);
  savegame->get_equipment().load_items();

  push_game(l, *savegame);
  RefCountable::unref(savegame);
  return 1;
}
开发者ID:abenavente406,项目名称:solarus,代码行数:22,代码来源:GameAPI.cpp

示例11: save

unsigned int BasicMonster::save(Savegame& sg)
{
	unsigned int id;
	if (sg.saved(this, &id)) return id;
	SaveBlock store("BasicMonster", id);
	storeAll(sg, store);
	sg << store;
	return id;
}
开发者ID:Zwergesel,项目名称:deadmeat,代码行数:9,代码来源:basicmonster.cpp

示例12: createSavegame

// for Savegame
bool Storage::createSavegame(int grp, int lvl, int timespent, int cols_left, int cols_over, QStringList used, QStringList marked)
{
    //qDebug() << "createSavegame";
    if (! m_db.isOpen()) return false;

    bool ret = false;

    QDateTime now = QDateTime::currentDateTime();

    Savegame *m = new Savegame;
    m->created = now.toTime_t();
    m->updated = now.toTime_t();
    m->grp = grp;
    m->lvl = lvl;
    m->timespent = timespent;
    m->cols_left = cols_left;
    m->cols_over = cols_over;
    m->setUsedCells(used);
    m->setMarkedCells(marked);

    QSqlQuery q;
    ret = q.prepare("INSERT INTO sg (created, updated, grp, lvl, timespent, cleft, cover, cused, cmarked) "
        "VALUES (:created, :updated, :grp, :lvl, :timespent, :cleft, :cover, :cused, :cmarked)");

    if (ret) {
        q.bindValue(":created", m->created);
        q.bindValue(":updated", m->updated);
        q.bindValue(":grp", m->grp);
        q.bindValue(":lvl", m->lvl);
        q.bindValue(":timespent", m->timespent);
        q.bindValue(":cleft", m->cols_left);
        q.bindValue(":cover", m->cols_over);
        q.bindValue(":cused", m->cells_used);
        q.bindValue(":cmarked", m->cells_marked);

        ret = q.exec();
    }

    if (ret) m->id = q.lastInsertId().toInt();

    //qDebug() << "created with id" << m->id;

    return ret;
}
开发者ID:jerryjj,项目名称:JapCross,代码行数:45,代码来源:storage.cpp

示例13: save

unsigned int Object::save(Savegame& sg)
{
	unsigned int id;
	if (sg.saved(this,&id)) return id;
	SaveBlock store("Object", id);
	store ("type", (int) type) ("name", name) ("formatFlags", formatFlags);
	store ("symbol", sym) ("color", color) ("visible", visible);
	sg << store;
	return id;
}
开发者ID:Zwergesel,项目名称:deadmeat,代码行数:10,代码来源:object.cpp

示例14: save

unsigned int Tool::save(Savegame& sg)
{
	unsigned int id;
	if (sg.saved(this,&id)) return id;
	SaveBlock store("Tool", id);
	store ("name", name) ("symbol", sym) ("color", color);
	store ("amount", amount) ("weight", weight) ("active", active);
	store ("tool", tool);
	sg << store;
	return id;
}
开发者ID:Zwergesel,项目名称:deadmeat,代码行数:11,代码来源:tool.cpp

示例15: ListDir

void iwSaveLoad::RefreshTable()
{
    static bool loadedOnce = false;

    GetCtrl<ctrlTable>(0)->DeleteAllItems();

    std::vector<std::string> saveFiles = ListDir(RTTRCONFIG.ExpandPath(FILE_PATHS[85]), "sav");
    for(auto& saveFile : saveFiles)
    {
        Savegame save;

        // Datei öffnen
        if(!save.Load(saveFile, false, false))
        {
            // Show errors only first time this is loaded
            if(!loadedOnce)
            {
                LOG.write(_("Invalid Savegame %1%! Reason: %2%\n")) % saveFile
                  % (save.GetLastErrorMsg().empty() ? _("Unknown") : save.GetLastErrorMsg());
            }
            continue;
        }

        // Zeitstring erstellen
        std::string dateStr = s25util::Time::FormatTime("%d.%m.%Y - %H:%i", save.GetSaveTime());

        // Dateiname noch rausextrahieren aus dem Pfad
        bfs::path path = saveFile;
        if(!path.has_filename())
            continue;
        // Just filename w/o extension
        bfs::path fileName = path.stem();

        std::string startGF = helpers::toString(save.start_gf);

        // Und das Zeug zur Tabelle hinzufügen
        GetCtrl<ctrlTable>(0)->AddRow(0, fileName.string().c_str(), save.GetMapName().c_str(), dateStr.c_str(), startGF.c_str(),
                                      saveFile.c_str());
    }

    // Nach Zeit Sortieren
    bool bFalse = false;
    GetCtrl<ctrlTable>(0)->SortRows(2, &bFalse);
    loadedOnce = true;
}
开发者ID:Return-To-The-Roots,项目名称:s25client,代码行数:45,代码来源:iwSave.cpp


注:本文中的Savegame类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。