how to use OverlayManager to Destroy/Reload an overlay

Problems building or running the engine, queries about how to use features etc.
Post Reply
cycheng
Gnoblar
Posts: 13
Joined: Thu Aug 31, 2006 3:35 pm

how to use OverlayManager to Destroy/Reload an overlay

Post by cycheng » Thu Aug 31, 2006 3:58 pm

Hi,

My code architecture is :
void Scene::Load() {
mResourceGroup = "MyResGroup";

ResourceGroupManager::getSingleton().addResourceLocation(...);
ResourceGroupManager::getSingleton().addResourceLocation(...);
ResourceGroupManager::getSingleton().addResourceLocation(...);
...;

ResourceGroupManager::getSingleton().initialiseResourceGroup( mResourceGroup );
}

void Scene::destroySceneObjects( void ) {
if( mResourceGroup ) {
ResourceGroupManager::getSingleton().unloadResourceGroup( mResourceGroup );
ResourceGroupManager::getSingleton().destroyResourceGroup( mResourceGroup );
}
// destroy all overlay while changing scene
OverlayManager::getSingleton().destroyAllOverlayElements(false);
OverlayManager::getSingleton().destroyAllOverlayElements(true);
OverlayManager::getSingleton().destroyAll();
}

My problem is, when I change scene, I have to destroy all overlay by
OverlayManager, I can not only destroy the scene's overlay, because
OverlayManager::mLoadedScripts, this member record the overlay scripts
that have been loaded into ogre, and when I reload the scene, I can
not parse overlay scripts again just because :
void OverlayManager::parseScript(DataStreamPtr& stream, const String& groupName)
{
if ( !stream->getName().empty() &&
mLoadedScripts.find(stream->getName()) != mLoadedScripts.end())
{
LogManager::getSingleton().logMessage(
"Skipping loading overlay include: '"
+ stream->getName() + " as it is already loaded.");
return;
}
...;
}

I think i have to find someway to erase mLoadedScripts, but the
OverlayManager does not seems to provide the method.

Is there another solution to do this?

Thanks a lot :)
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 2
Contact:

Post by sinbad » Thu Aug 31, 2006 5:32 pm

Separate out your overlays into scripts based on the units you wish to destroy, then use getOrigin() to identify which ones you want to destroy.
0 x

cycheng
Gnoblar
Posts: 13
Joined: Thu Aug 31, 2006 3:35 pm

Post by cycheng » Sat Sep 02, 2006 1:07 pm

Thanks :)

I will try, if success, i will show part of my code to help those who have same
problem like this.
0 x

DZ
Gnoblar
Posts: 5
Joined: Sun Jan 14, 2007 4:22 am

Post by DZ » Sat Mar 29, 2008 8:22 pm

sinbad wrote:Separate out your overlays into scripts based on the units you wish to destroy, then use getOrigin() to identify which ones you want to destroy.
But, if i destroy them through:

Code: Select all

OverlayManager::getSingleton().destroyOverlayElement();
OverlayManager::getSingleton().destroy();
They are not going to load again, because no elements ever removed from mLoadedScripts. Only way to remove something from this set is OverlayManager::destroyAll(void) which calls mLoadedScripts.clear(); See below.

Code: Select all

Find all "mLoadedScripts", Match case, Whole word, Subfolders, Find Results 1, "Current Project", "*.c;*.cpp;*.cxx;*.cc;*.tli;*.tlh;*.h;*.hpp;*.hxx;*.hh;*.inl;*.rc;*.resx;*.idl;*.asm;*.inc"
  OgreMain\include\OgreOverlayManager.h(74):		LoadedScripts mLoadedScripts;
  OgreMain\src\OgreOverlayManager.cpp(168):		mLoadedScripts.clear();
  OgreMain\src\OgreOverlayManager.cpp(181):			mLoadedScripts.find(stream->getName()) != mLoadedScripts.end())
  OgreMain\src\OgreOverlayManager.cpp(264):		mLoadedScripts.insert(stream->getName());
  Matching lines: 4    Matching files: 2    Total files searched: 385
I've put

Code: Select all

Overlay *o = i->second;
mLoadedScripts.erase( o->getOrigin() );
delete o;
instead of

Code: Select all

delete i->second;
in OverlayManager::destroy(Overlay* overlay) and OverlayManager::destroy(const String& name) methods as a temporary fix. But it will only work in assumption, that there is only one overlay per script file. And it will not work for overlay templates at all.

What do you think of that?
0 x

cycheng
Gnoblar
Posts: 13
Joined: Thu Aug 31, 2006 3:35 pm

Post by cycheng » Mon Dec 15, 2008 8:34 am

I finally change my method :)

I thought Overlay is a kind of "Global Resource", and do not allow individiual load/reload, so, when I need to clear all overlay resource, I will ask all loaded scenes (only one in active, others are not active) if somebody use/load the "Global Resource", if it is true, then I do not destroy all overlay, else, I could destroy all overlay
0 x

Post Reply