예제 #1
0
//----------------------------------------------------------------------------
// copying
//----------------------------------------------------------------------------
SEObjectPtr SEObject::Copy(bool bUniqueNames) const
{
    // Save the object to a memory buffer.
    SEStream tempSaveStream;
    tempSaveStream.Insert((SEObject*)this);
    char* pBuffer = 0;
    int iBufferSize = 0;
    bool bSuccessful = tempSaveStream.Save(pBuffer, iBufferSize);
    SE_ASSERT( bSuccessful );
    if( !bSuccessful )
    {
        return 0;
    }

    // Load the object from the memory buffer.
    SEStream tempLoadStream;
    bSuccessful = tempLoadStream.Load(pBuffer, iBufferSize);
    SE_ASSERT( bSuccessful );

    if( !bSuccessful )
    {
        return 0;
    }
    SE_DELETE[] pBuffer;

    if( bUniqueNames )
    {
        // Generate unique names.
        for( int i = 0; i < tempLoadStream.GetOrderedCount(); i++ )
        {
            SEObject* pObject = tempLoadStream.GetOrderedObject(i);
            SE_ASSERT( pObject );

            const std::string& rName = pObject->GetName();
            int iLength = (int)rName.length();
            if( iLength > 0 )
            {
                // Object has a name, append a character to make it unique.
                const char* pName = rName.c_str();
                char* acNewName = SE_NEW char[iLength + 2];
                const size_t uiSize = (size_t)(iLength + 2);
                SESystem::SE_Strcpy(acNewName, uiSize, pName);
                acNewName[iLength] = NameAppend;
                acNewName[iLength+1] = 0;
                pObject->SetName(std::string(acNewName));
                SE_DELETE[] acNewName;
            }
        }
    }

    return tempLoadStream.GetObjectAt(0);
}
예제 #2
0
//----------------------------------------------------------------------------
void SEApplication::TestStreaming(SESpatial* pScene, int iXPos, int iYPos,
    int iXSize, int iYSize, const char* acFilename)
{
    SEStream tempOStream;
    tempOStream.Insert(pScene);
    tempOStream.Save(acFilename);

    SEStream tempIStream;
    tempIStream.Load(acFilename);
    SESpatialPtr spScene = StaticCast<SESpatial>(tempIStream.GetObjectAt(0));
    spScene->SetName(acFilename);

    LaunchTreeControl(spScene, iXPos, iYPos, iXSize, iYSize);
}