예제 #1
0
//----------------------------------------------------------------------------
bool ResourceManager::LoadCachedResource (const std::string &filename)
{
	ScopedCS scopeCS(mResTableMutex);

	InStream inPut;

	if (inPut.Load(filename))
	{
		int numObjects = inPut.GetNumObjects();
		for (int i=0; i<numObjects; i++)
		{
			Object *obj = inPut.GetObjectAt(i);
			if (obj)
			{
				std::string filename = obj->GetResourcePath();
				LoadRecord rec;
				rec.Filename = filename;
				rec.Obj = obj;
				mResTable.insert(std::pair<std::string, LoadRecord>(filename, rec));
			}
		}

		return true;
	}

	return false;
}
예제 #2
0
//----------------------------------------------------------------------------
Object* Object::Copy(const std::string& uniqueNameAppend)
{
	// Save the object to a memory buffer.
	OutStream saveStream;

	saveStream.Insert((Object*)this);
	int bufferSize = 0;
	char* buffer = 0;
	saveStream.Save(bufferSize, buffer, BufferIO::BM_DEFAULT_WRITE);

	// Load the object from the memory buffer.
	InStream loadStream;
	loadStream.Load(bufferSize, buffer, BufferIO::BM_DEFAULT_READ);
	delete1(buffer);

	if (uniqueNameAppend != "")
	{
		int numObjects = loadStream.GetNumObjects();
		for (int i = 0; i < numObjects; i++)
		{
			PX2::Object *obj = loadStream.GetObjectAt(i);
			std::string name = obj->GetName();
			if (name.length() > 0)
			{
				name += uniqueNameAppend;
				obj->SetName(name);
			}
		}
	}

	return loadStream.GetObjectAt(0);
}
예제 #3
0
//----------------------------------------------------------------------------
Object* Object::Copy (const std::string& uniqueNameAppend) const
{
	// Save the object to a memory buffer.
	OutStream saveStream;
	saveStream.Insert((Object*)this);
	int bufferSize = 0;
	char* buffer = 0;
	saveStream.Save(bufferSize, buffer, BufferIO::BM_DEFAULT_WRITE);

	// Load the object from the memory buffer.
	InStream loadStream;
	loadStream.Load(bufferSize, buffer, BufferIO::BM_DEFAULT_READ);
	delete1(buffer);

	if (uniqueNameAppend != "")
	{
		// The names of the input scene were copied as is.  Generate unique
		// names for the output scene.
		int numObjects = loadStream.GetNumObjects();
		for (int i=0; i<numObjects; i++)
		{
			PX2::Object *obj = loadStream.GetObjectAt(i);
			std::string name = obj->GetName();
			if (name.length() > 0)
			{
				// The object has a name.  Append a string to make the name
				// unique.  TODO:  This code does not ensure that the
				// appended name is some other name in the copied scene.  To
				// do this would require building a set of names and verifying
				// that the appended names are not in this set.  For now we
				// think this is not worth the effort, but maybe later we can
				// add code to do this.
				name += uniqueNameAppend;
				obj->SetName(name);
			}
		}
	}

	return loadStream.GetObjectAt(0);
}