reworked code for player positioning on startup and new game

actorid
Marc Zinnschlag 11 years ago
parent 0cd40294a2
commit 7bc97fb8b8

@ -404,7 +404,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
// Create the world
mEnvironment.setWorld( new MWWorld::World (*mOgre, mFileCollections, mContentFiles,
mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
mActivationDistanceOverride));
mActivationDistanceOverride, mCellName));
MWBase::Environment::get().getWorld()->setupPlayer();
input->setPlayer(&mEnvironment.getWorld()->getPlayer());
@ -440,31 +440,6 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mechanics->buildPlayer();
window->updatePlayer();
// load cell
ESM::Position pos;
MWBase::World *world = MWBase::Environment::get().getWorld();
if (!mCellName.empty())
{
if (world->findExteriorPosition(mCellName, pos)) {
world->changeToExteriorCell (pos);
}
else {
world->findInteriorPosition(mCellName, pos);
world->changeToInteriorCell (mCellName, pos);
}
}
else
{
pos.pos[0] = pos.pos[1] = pos.pos[2] = 0;
pos.rot[0] = pos.rot[1] = pos.rot[2] = 0;
world->changeToExteriorCell (pos);
}
Ogre::FrameEvent event;
event.timeSinceLastEvent = 0;
event.timeSinceLastFrame = 0;
frameRenderingQueued(event);
mOgre->getRoot()->addFrameListener (this);
// scripts
@ -502,15 +477,15 @@ void OMW::Engine::go()
// Play some good 'ol tunes
MWBase::Environment::get().getSoundManager()->playPlaylist(std::string("Explore"));
if (!mStartupScript.empty())
MWBase::Environment::get().getWindowManager()->executeInConsole (mStartupScript);
// start in main menu
if (!mSkipMenu)
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
else
MWBase::Environment::get().getStateManager()->newGame (true);
if (!mStartupScript.empty())
MWBase::Environment::get().getWindowManager()->executeInConsole (mStartupScript);
// Start the main rendering loop
while (!mEnvironment.get().getStateManager()->hasQuitRequest())
Ogre::Root::getSingleton().renderOneFrame();

@ -101,7 +101,8 @@ namespace MWBase
virtual ~World() {}
virtual void startNewGame() = 0;
virtual void startNewGame (bool bypass) = 0;
///< \param bypass Bypass regular game start.
virtual void clear() = 0;

@ -125,11 +125,10 @@ void MWState::StateManager::newGame (bool bypass)
{
cleanup();
MWBase::Environment::get().getWorld()->startNewGame (bypass);
if (!bypass)
{
MWBase::Environment::get().getWorld()->startNewGame();
MWBase::Environment::get().getWindowManager()->setNewGame (true);
}
else
MWBase::Environment::get().getWorld()->setGlobalInt ("chargenstate", -1);

@ -121,13 +121,15 @@ namespace MWWorld
const Files::Collections& fileCollections,
const std::vector<std::string>& contentFiles,
const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir,
ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap, int mActivationDistanceOverride)
ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap,
int activationDistanceOverride, const std::string& startCell)
: mPlayer (0), mLocalScripts (mStore),
mSky (true), mCells (mStore, mEsm),
mActivationDistanceOverride (mActivationDistanceOverride),
mActivationDistanceOverride (activationDistanceOverride),
mFallback(fallbackMap), mPlayIntro(0), mTeleportEnabled(true), mLevitationEnabled(true),
mFacedDistance(FLT_MAX), mGodMode(false), mContentFiles (contentFiles),
mGoToJail(false)
mGoToJail(false),
mStartCell (startCell)
{
mPhysics = new PhysicsSystem(renderer);
mPhysEngine = mPhysics->getEngine();
@ -168,7 +170,7 @@ namespace MWWorld
mWorldScene = new Scene(*mRendering, mPhysics);
}
void World::startNewGame()
void World::startNewGame (bool bypass)
{
mGoToJail = false;
mLevitationEnabled = true;
@ -181,23 +183,44 @@ namespace MWWorld
MWBase::Environment::get().getWindowManager()->updatePlayer();
// FIXME: this will add cell 0,0 as visible on the global map
ESM::Position pos;
const int cellSize = 8192;
pos.pos[0] = cellSize/2;
pos.pos[1] = cellSize/2;
pos.pos[2] = 0;
pos.rot[0] = 0;
pos.rot[1] = 0;
pos.rot[2] = 0;
mWorldScene->changeToExteriorCell(pos);
if (bypass && !mStartCell.empty())
{
ESM::Position pos;
if (findExteriorPosition (mStartCell, pos))
{
changeToExteriorCell (pos);
}
else
{
findInteriorPosition (mStartCell, pos);
changeToInteriorCell (mStartCell, pos);
}
}
else
{
/// \todo if !bypass, do not add player location to global map for the duration of one
/// frame
ESM::Position pos;
const int cellSize = 8192;
pos.pos[0] = cellSize/2;
pos.pos[1] = cellSize/2;
pos.pos[2] = 0;
pos.rot[0] = 0;
pos.rot[1] = 0;
pos.rot[2] = 0;
mWorldScene->changeToExteriorCell(pos);
}
// FIXME: should be set to 1, but the sound manager won't pause newly started sounds
mPlayIntro = 2;
if (!bypass)
{
// FIXME: should be set to 1, but the sound manager won't pause newly started sounds
mPlayIntro = 2;
// set new game mark
mGlobalVariables["chargenstate"].setInteger (1);
mGlobalVariables["pcrace"].setInteger (3);
// set new game mark
mGlobalVariables["chargenstate"].setInteger (1);
mGlobalVariables["pcrace"].setInteger (3);
}
// we don't want old weather to persist on a new game
delete mWeatherManager;

@ -120,6 +120,9 @@ namespace MWWorld
std::map<MWWorld::Ptr, MagicBoltState> mMagicBolts;
std::map<MWWorld::Ptr, ProjectileState> mProjectiles;
std::string mStartCell;
void updateWeather(float duration);
int getDaysPerMonth (int month) const;
@ -179,11 +182,13 @@ namespace MWWorld
const Files::Collections& fileCollections,
const std::vector<std::string>& contentFiles,
const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir,
ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap, int mActivationDistanceOverride);
ToUTF8::Utf8Encoder* encoder, const std::map<std::string,std::string>& fallbackMap,
int activationDistanceOverride, const std::string& startCell);
virtual ~World();
virtual void startNewGame();
virtual void startNewGame (bool bypass);
///< \param bypass Bypass regular game start.
virtual void clear();

Loading…
Cancel
Save