Beispiel #1
0
ERR_STATE *ERR_get_state(void)
	{
	ERR_STATE *ret=NULL,tmp,*tmpp;
	int i;
	unsigned long pid;

	pid=(unsigned long)CRYPTO_thread_id();

	CRYPTO_r_lock(CRYPTO_LOCK_ERR);
	if (thread_hash == NULL)
		{
		CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
		CRYPTO_w_lock(CRYPTO_LOCK_ERR);
		if (thread_hash == NULL)
			{
			MemCheck_off();
			thread_hash=lh_new(pid_hash,pid_cmp);
			MemCheck_on();
			CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
			if (thread_hash == NULL) return(getFallback());
			}
		else
			CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
		}
	else
		{
		tmp.pid=pid;
		ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp);
		CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
		}

	/* ret == the error state, if NULL, make a new one */
	if (ret == NULL)
		{
		ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE));
		if (ret == NULL) return(getFallback());
		ret->pid=pid;
		ret->top=0;
		ret->bottom=0;
		for (i=0; i<ERR_NUM_ERRORS; i++)
			{
			ret->err_data[i]=NULL;
			ret->err_data_flags[i]=0;
			}
		CRYPTO_w_lock(CRYPTO_LOCK_ERR);
		tmpp=(ERR_STATE *)lh_insert(thread_hash,ret);
		CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
		if (tmpp != NULL) /* old entry - should not happen */
			{
			ERR_STATE_free(tmpp);
			}
		}
	return(ret);
	}
ModelResource* ModelBaseUnmanagedFactory::createModelResource( const string& p_name, 
												 const string* p_path/*=NULL*/)
{
	ModelResource* model = NULL;
	// Check and read the file
	AglScene* scene = readScene(p_name,p_path);
	//
	if (scene)
	{ 
		vector<ModelResource*>* models = createAllModelData(scene,1);
		if ((*models)[0]!=NULL)
		{
			model = (*models)[0];
			readAndStoreEmpties(-1,model,scene); // read leftover empties
		}
	}
	else
	{
		model = getFallback();
	}
	// cleanup
	delete scene;

	return model;
}
vector<ModelResource*>* ModelBaseFactory::createModelResources( const string& p_name, 
														const string* p_path)
{
	InstanceInstruction currentInstance={p_name,AglMatrix::identityMatrix()};
	//
	vector<ModelResource*>* models = NULL;
	vector<InstanceInstruction>* instanceInstructions = new vector<InstanceInstruction>();
	int instanceCount = 0;
	// Check and read the file
	do 
	{	
		if (!instanceInstructions->empty()) instanceInstructions->pop_back();

		int modelFoundId = m_modelResourceCache->getResourceId(currentInstance.filename);
		// ---------------------
		// New mesh
		// ---------------------
		if (modelFoundId==-1)  // if it does not exist, create new
		{
			AglScene* scene = readScene(currentInstance.filename,p_path);
			//
			if (scene)
			{ 
				// DEBUGWARNING(( ("Loading meshes from "+currentInstance.filename+" instance="+toString(instanceCount)).c_str() ));
				if (instanceCount==0) 
				{
					// just a normal mesh, just copy resource instructions
					models = createAllModelData(&currentInstance,
						scene,
						instanceInstructions);		
					// read leftover empties
					if ((*models)[0]!=NULL)
					{
						ModelResource* model = (*models)[0];
						SourceData source={scene,NULL,NULL,-1,string("")};
						readAndStoreEmpties(source,model,currentInstance.transform,
							&currentInstance,instanceInstructions); 
						readAndStoreParticleSystems(source,model);
					}
				}
				else
				{
					// an instance needs to add(instead of copy) to original collection from 
					// the instance's read collection.
					// it also needs to copy the model resource data
					vector<ModelResource*>* prefetched = createAllModelData(&currentInstance,
						scene,
						instanceInstructions);
					// read leftover empties
					ModelResource* root = (*prefetched)[0];
					if (root!=NULL)
					{
						SourceData source={scene,NULL,NULL,-1,string("")};
						readAndStoreEmpties(source,root,currentInstance.transform,
											&currentInstance,instanceInstructions); 
						readAndStoreParticleSystems(source,root);
					}
					//
					ModelResourceCollection* modelresourceCollection = m_modelResourceCache->getResource(currentInstance.filename);
					unsigned int start = modelresourceCollection->rootIndex+1;
					unsigned int size = prefetched->size();
					for (unsigned int n=start;n<size;n++)
					{
						ModelResource* model = new ModelResource( *(*prefetched)[n] );
						// mesh transform
						model->transform *= currentInstance.transform;
						// 
						models->push_back(model);
					}
				}

			}
			else
			{
				models->push_back(getFallback());
			}
			// cleanup
			m_scenes.push_back(scene);
			//delete scene;
		}
		else // the mesh already exists
		{
		// ---------------------
		// Existing mesh
		// ---------------------
			if (instanceCount==0) 
			{
				// just a normal mesh, just copy resource instructions
				models = &m_modelResourceCache->getResource(currentInstance.filename)->collection;
			}
			else					
			{
				// an instance needs to add to original collection from  the instance's collection
				// it also needs to copy the model resource data
				ModelResourceCollection* modelresourceCollection = m_modelResourceCache->getResource(currentInstance.filename);
				vector<ModelResource*>* prefetched = &modelresourceCollection->collection;

				unsigned int root = modelresourceCollection->rootIndex;
				unsigned int size = prefetched->size();
				for (unsigned int n=0;n<size;n++)
				{
					ModelResource* model = new ModelResource( *(*prefetched)[n] );
					// mesh transform
					model->transform *= currentInstance.transform;
					AglMatrix* base= &(model->transform);
					// instances
					for (unsigned int x=0;x<model->instances.size();x++)
					{
						InstanceInstruction instruction = model->instances[x];
						instruction.transform *= currentInstance.transform;
						instanceInstructions->push_back(instruction);
					}
					// 
					if (n!=root) 
						models->push_back(model);
					else
						delete model;
				}
			}
		}

		// read and prepare next instance if file had any instances specified
		if (!instanceInstructions->empty())
		{
			currentInstance = instanceInstructions->back();
		}
		instanceCount++;

	} while (!instanceInstructions->empty());


	delete instanceInstructions;

	return models;
}