mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 03:15:32 +00:00
Merge remote-tracking branch 'scrawl/cmdline-savegame'
This commit is contained in:
commit
e830998739
9 changed files with 85 additions and 24 deletions
|
@ -472,9 +472,13 @@ void OMW::Engine::go()
|
|||
// Play some good 'ol tunes
|
||||
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
|
||||
|
||||
// start in main menu
|
||||
if (!mSkipMenu)
|
||||
if (!mSaveGameFile.empty())
|
||||
{
|
||||
MWBase::Environment::get().getStateManager()->loadGame(mSaveGameFile);
|
||||
}
|
||||
else if (!mSkipMenu)
|
||||
{
|
||||
// start in main menu
|
||||
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
|
||||
try
|
||||
{
|
||||
|
@ -622,3 +626,8 @@ void OMW::Engine::enableFontExport(bool exportFonts)
|
|||
{
|
||||
mExportFonts = exportFonts;
|
||||
}
|
||||
|
||||
void OMW::Engine::setSaveGameFile(const std::string &savegame)
|
||||
{
|
||||
mSaveGameFile = savegame;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ namespace OMW
|
|||
bool mScriptConsoleMode;
|
||||
std::string mStartupScript;
|
||||
int mActivationDistanceOverride;
|
||||
std::string mSaveGameFile;
|
||||
// Grab mouse?
|
||||
bool mGrab;
|
||||
|
||||
|
@ -204,6 +205,9 @@ namespace OMW
|
|||
|
||||
void enableFontExport(bool exportFonts);
|
||||
|
||||
/// Set the save game file to load after initialising the engine.
|
||||
void setSaveGameFile(const std::string& savegame);
|
||||
|
||||
private:
|
||||
Files::ConfigurationManager& mCfgMgr;
|
||||
};
|
||||
|
|
|
@ -152,6 +152,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
("script-blacklist-use", bpo::value<bool>()->implicit_value(true)
|
||||
->default_value(true), "enable script blacklisting")
|
||||
|
||||
("load-savegame", bpo::value<std::string>()->default_value(""),
|
||||
"load a save game file on game startup")
|
||||
|
||||
("skip-menu", bpo::value<bool>()->implicit_value(true)
|
||||
->default_value(false), "skip main menu on game startup")
|
||||
|
||||
|
@ -274,6 +277,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
|||
engine.setWarningsMode (variables["script-warn"].as<int>());
|
||||
engine.setScriptBlacklist (variables["script-blacklist"].as<StringsVector>());
|
||||
engine.setScriptBlacklistUse (variables["script-blacklist-use"].as<bool>());
|
||||
engine.setSaveGameFile (variables["load-savegame"].as<std::string>());
|
||||
|
||||
// other settings
|
||||
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
||||
|
|
|
@ -62,10 +62,13 @@ namespace MWBase
|
|||
///
|
||||
/// \note Slot must belong to the current character.
|
||||
|
||||
virtual void loadGame (const MWState::Character *character, const MWState::Slot *slot) = 0;
|
||||
///< Load a saved game file from \a slot.
|
||||
///
|
||||
/// \note \a slot must belong to \a character.
|
||||
virtual void loadGame (const std::string& filepath) = 0;
|
||||
///< Load a saved game directly from the given file path. This will search the CharacterManager
|
||||
/// for a Character containing this save file, and set this Character current if one was found.
|
||||
/// Otherwise, a new Character will be created.
|
||||
|
||||
virtual void loadGame (const MWState::Character *character, const std::string& filepath) = 0;
|
||||
///< Load a saved game file belonging to the given character.
|
||||
|
||||
///Simple saver, writes over the file if already existing
|
||||
/** Used for quick save and autosave **/
|
||||
|
|
|
@ -246,7 +246,7 @@ namespace MWGui
|
|||
else
|
||||
{
|
||||
assert (mCurrentCharacter && mCurrentSlot);
|
||||
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, mCurrentSlot);
|
||||
MWBase::Environment::get().getStateManager()->loadGame (mCurrentCharacter, mCurrentSlot->mPath.string());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,3 +190,8 @@ ESM::SavedGame MWState::Character::getSignature() const
|
|||
|
||||
return slot.mProfile;
|
||||
}
|
||||
|
||||
const boost::filesystem::path& MWState::Character::getPath() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
|
|
@ -54,12 +54,12 @@ namespace MWState
|
|||
/// \attention The \a slot pointer will be invalidated by this call.
|
||||
|
||||
SlotIterator begin() const;
|
||||
///< First slot is the most recent. Other slots follow in descending order of save date.
|
||||
///
|
||||
/// Any call to createSlot and updateSlot can invalidate the returned iterator.
|
||||
///< Any call to createSlot and updateSlot can invalidate the returned iterator.
|
||||
|
||||
SlotIterator end() const;
|
||||
|
||||
const boost::filesystem::path& getPath() const;
|
||||
|
||||
ESM::SavedGame getSignature() const;
|
||||
///< Return signature information for this character.
|
||||
///
|
||||
|
|
|
@ -291,16 +291,47 @@ void MWState::StateManager::quickSave (std::string name)
|
|||
saveGame(name, slot);
|
||||
}
|
||||
|
||||
void MWState::StateManager::loadGame (const Character *character, const Slot *slot)
|
||||
void MWState::StateManager::loadGame(const std::string& filepath)
|
||||
{
|
||||
for (CharacterIterator it = mCharacterManager.begin(); it != mCharacterManager.end(); ++it)
|
||||
{
|
||||
const MWState::Character& character = *it;
|
||||
for (MWState::Character::SlotIterator slotIt = character.begin(); slotIt != character.end(); ++slotIt)
|
||||
{
|
||||
const MWState::Slot& slot = *slotIt;
|
||||
if (slot.mPath == boost::filesystem::path(filepath))
|
||||
{
|
||||
loadGame(&character, slot.mPath.string());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// have to peek into the save file to get the player name
|
||||
ESM::ESMReader reader;
|
||||
reader.open (filepath);
|
||||
if (reader.getFormat()>ESM::Header::CurrentFormat)
|
||||
return; // format is too new -> ignore
|
||||
if (reader.getRecName()!=ESM::REC_SAVE)
|
||||
return; // invalid save file -> ignore
|
||||
reader.getRecHeader();
|
||||
ESM::SavedGame profile;
|
||||
profile.load (reader);
|
||||
reader.close();
|
||||
|
||||
MWState::Character* character = mCharacterManager.getCurrentCharacter(true, profile.mPlayerName);
|
||||
loadGame(character, filepath);
|
||||
mTimePlayed = profile.mTimePlayed;
|
||||
}
|
||||
|
||||
void MWState::StateManager::loadGame (const Character *character, const std::string& filepath)
|
||||
{
|
||||
try
|
||||
{
|
||||
cleanup();
|
||||
|
||||
mTimePlayed = slot->mProfile.mTimePlayed;
|
||||
|
||||
ESM::ESMReader reader;
|
||||
reader.open (slot->mPath.string());
|
||||
reader.open (filepath);
|
||||
|
||||
std::map<int, int> contentFileMap = buildContentFileIndexMap (reader);
|
||||
|
||||
|
@ -319,9 +350,11 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
|
|||
switch (n.val)
|
||||
{
|
||||
case ESM::REC_SAVE:
|
||||
|
||||
// don't need to read that here
|
||||
reader.skipRecord();
|
||||
{
|
||||
ESM::SavedGame profile;
|
||||
profile.load(reader);
|
||||
mTimePlayed = profile.mTimePlayed;
|
||||
}
|
||||
break;
|
||||
|
||||
case ESM::REC_JOUR:
|
||||
|
@ -391,7 +424,7 @@ void MWState::StateManager::loadGame (const Character *character, const Slot *sl
|
|||
mState = State_Running;
|
||||
|
||||
Settings::Manager::setString ("character", "Saves",
|
||||
slot->mPath.parent_path().filename().string());
|
||||
character->getPath().filename().string());
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->setNewGame(false);
|
||||
MWBase::Environment::get().getWorld()->setupPlayer();
|
||||
|
@ -431,7 +464,7 @@ void MWState::StateManager::quickLoad()
|
|||
{
|
||||
if (Character* mCurrentCharacter = getCurrentCharacter (false))
|
||||
if (const MWState::Slot* slot = &*mCurrentCharacter->begin()) //Get newest save
|
||||
loadGame (mCurrentCharacter, slot);
|
||||
loadGame (mCurrentCharacter, slot->mPath.string());
|
||||
}
|
||||
|
||||
void MWState::StateManager::deleteGame(const MWState::Character *character, const MWState::Slot *slot)
|
||||
|
@ -472,7 +505,7 @@ void MWState::StateManager::update (float duration)
|
|||
//Load last saved game for current character
|
||||
|
||||
MWState::Slot lastSave = *curCharacter->begin();
|
||||
loadGame(curCharacter, &lastSave);
|
||||
loadGame(curCharacter, lastSave.mPath.string());
|
||||
}
|
||||
else if(iButton==1)
|
||||
{
|
||||
|
|
|
@ -61,10 +61,13 @@ namespace MWState
|
|||
/** Used for quickload **/
|
||||
virtual void quickLoad();
|
||||
|
||||
virtual void loadGame (const Character *character, const Slot *slot);
|
||||
///< Load a saved game file from \a slot.
|
||||
///
|
||||
/// \note \a slot must belong to \a character.
|
||||
virtual void loadGame (const std::string& filepath);
|
||||
///< Load a saved game directly from the given file path. This will search the CharacterManager
|
||||
/// for a Character containing this save file, and set this Character current if one was found.
|
||||
/// Otherwise, a new Character will be created.
|
||||
|
||||
virtual void loadGame (const Character *character, const std::string &filepath);
|
||||
///< Load a saved game file belonging to the given character.
|
||||
|
||||
virtual Character *getCurrentCharacter (bool create = true);
|
||||
///< \param create Create a new character, if there is no current character.
|
||||
|
|
Loading…
Reference in a new issue