Skip to content

Commit

Permalink
rejigger entity sets
Browse files Browse the repository at this point in the history
  • Loading branch information
gorlak committed Sep 28, 2010
1 parent 04d59e1 commit 8113115
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Core/SceneGraph/EntityInstance.cpp
Expand Up @@ -180,6 +180,79 @@ SceneNodeTypePtr EntityInstance::CreateNodeType( Scene* scene ) const
return nodeType;
}

void EntityInstance::CheckNodeType()
{
Base::CheckNodeType();

CheckSets();
}

void EntityInstance::CheckSets()
{
const Helium::Path& path = GetEntityPath();

Asset::EntityPtr entity;
try
{
entity = GetEntity();
}
catch ( const Helium::Exception& ex )
{
Log::Warning( TXT("%s\n"), ex.What() );
}

if ( !entity && !path.empty() )
{
tstringstream str;
str << TXT("Failed to load entity class for entity ") << GetName() << TXT(".") << std::endl;
str << TXT("The entity '") << path.c_str() << TXT("' has moved or been deleted.") << std::endl;
Log::Error( str.str().c_str() );
}

const tstring& currentClassSet = path.Get();

EntityInstanceType* type = Reflect::AssertCast<EntityInstanceType>( m_NodeType );
if (type)
{
// find the set
M_InstanceSetSmartPtr::const_iterator found = type->GetSets().find(currentClassSet);

// if we found it, and it contains us, and we are using it
if (found != type->GetSets().end() && found->second->ContainsInstance(this) && m_ClassSet == found->second.Ptr())
{
// we are GTG
return;
}

// the set we are entering
EntitySet* newClassSet = NULL;

// create new class object if it does not already exist
if (found == type->GetSets().end())
{
// create
newClassSet = new EntitySet (type, path);

// save
type->AddSet( newClassSet );
}
else
{
// existing
newClassSet = Reflect::AssertCast<EntitySet>( found->second );
}

// check previous membership
if (m_ClassSet)
{
m_ClassSet->RemoveInstance(this);
}

// add to the new class collection
newClassSet->AddInstance(this);
}
}

Scene* EntityInstance::GetNestedScene( GeometryMode mode, bool load_on_demand ) const
{
if (m_ClassSet->GetEntity())
Expand Down
2 changes: 2 additions & 0 deletions Core/SceneGraph/EntityInstance.h
Expand Up @@ -42,6 +42,8 @@ namespace Helium
virtual tstring GenerateName() const HELIUM_OVERRIDE;
virtual tstring GetApplicationTypeName() const HELIUM_OVERRIDE;
virtual SceneNodeTypePtr CreateNodeType( Scene* scene ) const HELIUM_OVERRIDE;
virtual void CheckNodeType() HELIUM_OVERRIDE;
void CheckSets();

// retrieve the nested scene from the scene manager
Scene* GetNestedScene(GeometryMode mode, bool load_on_demand = true) const;
Expand Down

0 comments on commit 8113115

Please sign in to comment.