Preload sky & water from the main menu

coverity_scan
scrawl 9 years ago
parent f9082502f8
commit 1cda2bf796

@ -651,6 +651,8 @@ void OMW::Engine::go()
}
else if (!mSkipMenu)
{
mEnvironment.getWorld()->preloadCommonAssets();
// start in main menu
mEnvironment.getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
try

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

@ -127,6 +127,29 @@ namespace MWRender
bool mWireframe;
};
class PreloadCommonAssetsWorkItem : public SceneUtil::WorkItem
{
public:
PreloadCommonAssetsWorkItem(Resource::ResourceSystem* resourceSystem)
: mResourceSystem(resourceSystem)
{
}
virtual void doWork()
{
for (std::vector<std::string>::const_iterator it = mModels.begin(); it != mModels.end(); ++it)
mResourceSystem->getSceneManager()->getTemplate(*it);
for (std::vector<std::string>::const_iterator it = mTextures.begin(); it != mTextures.end(); ++it)
mResourceSystem->getImageManager()->getImage(*it);
}
std::vector<std::string> mModels;
std::vector<std::string> mTextures;
private:
Resource::ResourceSystem* mResourceSystem;
};
RenderingManager::RenderingManager(osgViewer::Viewer* viewer, osg::ref_ptr<osg::Group> rootNode, Resource::ResourceSystem* resourceSystem,
const Fallback::Map* fallback, const std::string& resourcePath)
: mViewer(viewer)
@ -238,6 +261,17 @@ namespace MWRender
return mWorkQueue.get();
}
void RenderingManager::preloadCommonAssets()
{
osg::ref_ptr<PreloadCommonAssetsWorkItem> workItem (new PreloadCommonAssetsWorkItem(mResourceSystem));
mSky->listAssetsToPreload(workItem->mModels, workItem->mTextures);
mWater->listAssetsToPreload(workItem->mTextures);
workItem->mTextures.push_back("textures/_land_default.dds");
mWorkQueue->addWorkItem(workItem);
}
void RenderingManager::clearCache()
{
if (mTerrain.get())

@ -72,6 +72,8 @@ namespace MWRender
SceneUtil::WorkQueue* getWorkQueue();
void preloadCommonAssets();
void clearCache();
double getReferenceTime() const;

@ -1694,6 +1694,46 @@ void SkyManager::setWaterHeight(float height)
mUnderwaterSwitch->setWaterLevel(height);
}
void SkyManager::listAssetsToPreload(std::vector<std::string>& models, std::vector<std::string>& textures)
{
models.push_back("meshes/sky_atmosphere.nif");
if (mSceneManager->getVFS()->exists("meshes/sky_night_02.nif"))
models.push_back("meshes/sky_night_02.nif");
models.push_back("meshes/sky_night_01.nif");
models.push_back("meshes/sky_clouds_01.nif");
models.push_back("meshes\\ashcloud.nif");
models.push_back("meshes\\blightcloud.nif");
models.push_back("meshes\\snow.nif");
models.push_back("meshes\\blizzard.nif");
textures.push_back("textures/tx_mooncircle_full_s.dds");
textures.push_back("textures/tx_mooncircle_full_m.dds");
textures.push_back("textures/tx_masser_new.dds");
textures.push_back("textures/tx_masser_one_wax.dds");
textures.push_back("textures/tx_masser_half_wax.dds");
textures.push_back("textures/tx_masser_three_wax.dds");
textures.push_back("textures/tx_masser_one_wan.dds");
textures.push_back("textures/tx_masser_half_wan.dds");
textures.push_back("textures/tx_masser_three_wan.dds");
textures.push_back("textures/tx_masser_full.dds");
textures.push_back("textures/tx_secunda_new.dds");
textures.push_back("textures/tx_secunda_one_wax.dds");
textures.push_back("textures/tx_secunda_half_wax.dds");
textures.push_back("textures/tx_secunda_three_wax.dds");
textures.push_back("textures/tx_secunda_one_wan.dds");
textures.push_back("textures/tx_secunda_half_wan.dds");
textures.push_back("textures/tx_secunda_three_wan.dds");
textures.push_back("textures/tx_secunda_full.dds");
textures.push_back("textures/tx_sun_05.dds");
textures.push_back("textures/tx_sun_flash_grey_05.dds");
textures.push_back("textures/tx_raindrop_01.dds");
}
void SkyManager::setWaterEnabled(bool enabled)
{
mUnderwaterSwitch->setEnabled(enabled);

@ -153,6 +153,8 @@ namespace MWRender
/// Set height of water plane (used to remove underwater weather particles)
void setWaterHeight(float height);
void listAssetsToPreload(std::vector<std::string>& models, std::vector<std::string>& textures);
private:
void create();
///< no need to call this, automatically done on first enable()

@ -649,6 +649,18 @@ Water::~Water()
}
}
void Water::listAssetsToPreload(std::vector<std::string> &textures)
{
int frameCount = mFallback->getFallbackInt("Water_SurfaceFrameCount");
std::string texture = mFallback->getFallbackString("Water_SurfaceTexture");
for (int i=0; i<frameCount; ++i)
{
std::ostringstream texname;
texname << "textures/water/" << texture << std::setw(2) << std::setfill('0') << i << ".dds";
textures.push_back(texname.str());
}
}
void Water::setEnabled(bool enabled)
{
mEnabled = enabled;

@ -2,6 +2,7 @@
#define OPENMW_MWRENDER_WATER_H
#include <memory>
#include <vector>
#include <osg/ref_ptr>
#include <osg/Vec3f>
@ -85,6 +86,8 @@ namespace MWRender
const std::string& resourcePath);
~Water();
void listAssetsToPreload(std::vector<std::string>& textures);
void setEnabled(bool enabled);
bool toggle();

@ -3216,4 +3216,9 @@ namespace MWWorld
return mPhysics->getHitDistance(weaponPos, target);
}
void World::preloadCommonAssets()
{
mRendering->preloadCommonAssets();
}
}

@ -183,6 +183,8 @@ namespace MWWorld
virtual void startNewGame (bool bypass);
///< \param bypass Bypass regular game start.
virtual void preloadCommonAssets();
virtual void clear();
virtual int countSavedGameRecords() const;

Loading…
Cancel
Save