Ejemplo n.º 1
0
void
NodePreloader::MessageReceived(BMessage* message)
{
	// respond to node monitor notifications

	node_ref itemNode;
	switch (message->what) {
		case B_NODE_MONITOR:
		{
			switch (message->FindInt32("opcode")) {
				case B_ENTRY_REMOVED:
				{
					AutoLock<Benaphore> locker(fLock);
					message->FindInt32("device", &itemNode.device);
					message->FindInt64("node", &itemNode.node);
					Model* model = FindModel(itemNode);
					if (model == NULL)
						break;

					//PRINT(("preloader removing file %s\n", model->Name()));
					IconCache::sIconCache->Removing(model);
					fModelList.RemoveItem(model);
					break;
				}

				case B_ATTR_CHANGED:
				case B_STAT_CHANGED:
				{
					AutoLock<Benaphore> locker(fLock);
					message->FindInt32("device", &itemNode.device);
					message->FindInt64("node", &itemNode.node);

					const char* attrName;
					message->FindString("attr", &attrName);
					Model* model = FindModel(itemNode);
					if (model == NULL)
						break;

					BModelOpener opener(model);
					IconCache::sIconCache->IconChanged(model->ResolveIfLink());
					//PRINT(("preloader updating file %s\n", model->Name()));
					break;
				}
			}
			break;
		}

		default:
			_inherited::MessageReceived(message);
			break;
	}
}
Ejemplo n.º 2
0
	void MergeModel::handleRowsAboutToBeRemoved (const QModelIndex& parent,
			int first, int last)
	{
		auto model = static_cast<QAbstractItemModel*> (sender ());

		const auto startingRow = parent.isValid () ?
				0 :
				GetStartingRow (FindModel (model));
		beginRemoveRows (mapFromSource (parent),
				first + startingRow, last + startingRow);

		const auto rawItem = parent.isValid () ?
				static_cast<ModelItem*> (mapFromSource (parent).internalPointer ()) :
				Root_.get ();
		const auto& item = rawItem->shared_from_this ();

		auto it = item->EraseChildren (item->begin () + startingRow + first,
				item->begin () + startingRow + last + 1);

		RemovalRefreshers_.push ([=] () mutable
				{
					for ( ; it != item->end () && (*it)->GetModel () == model; ++it)
						(*it)->RefreshIndex (startingRow);
				});
	}
Ejemplo n.º 3
0
	void MergeModel::handleRowsInserted (const QModelIndex& parent, int first, int last)
	{
		const auto model = static_cast<QAbstractItemModel*> (sender ());

		const auto startingRow = parent.isValid () ?
				0 :
				GetStartingRow (FindModel (model));

		const auto rawItem = parent.isValid () ?
				static_cast<ModelItem*> (mapFromSource (parent).internalPointer ()) :
				Root_.get ();
		const auto& item = rawItem->shared_from_this ();

		for ( ; first <= last; ++first)
		{
			const auto& srcIdx = model->index (first, 0, parent);
			item->InsertChild (startingRow + first, model, srcIdx, item);
		}

		++last;
		last += startingRow;

		for (int rc = item->GetRowCount (); last < rc; ++last)
		{
			const auto child = item->GetChild (last);
			if (child->GetModel () != model)
				break;

			child->RefreshIndex (startingRow);
		}

		endInsertRows ();
	}
// Get CPUTModel from asset library
// If the model exists, then the existing model is Addref'ed and returned
//-----------------------------------------------------------------------------
CPUTModel *CPUTAssetLibrary::GetModel(const cString &name, bool nameIsFullPathAndFilename)
{
    // Resolve name to absolute path before searching
    cString absolutePathAndFilename;

    if (!nameIsFullPathAndFilename && name.at(0) == '%')
    {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(mSystemDirectoryName + _L("/Asset/") + name.substr(1) + _L(".mdl"), &absolutePathAndFilename);
    } else if (!nameIsFullPathAndFilename) {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(mModelDirectoryName + name + _L(".mdl"), &absolutePathAndFilename);
    } else {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(name, &absolutePathAndFilename);
    }

    // If we already have one by this name, then return it
    CPUTModel *pModel = FindModel(absolutePathAndFilename, true);
    if(NULL!=pModel)
    {
        pModel->AddRef();
        return pModel;
    }

    // Looks like no one calls GetModel().  Or, they never call it for missing models.
#if TODO // delegate
    // Model was not in the library, so create and load a new model
    pModel = new CPUTModel();
    pModel->LoadModelPayload(absolutePathAndFilename);
    AddModel(name, pModel);

    return CPUTModel::CreateMode( absolutePathAndFilename, aboslutePathAndFilename );
#endif

    return pModel;
}
// Get CPUTModel from asset library
// If the model exists, then the existing model is Addref'ed and returned
//-----------------------------------------------------------------------------
CPUTModel *CPUTAssetLibrary::GetModel(const cString &name, bool nameIsFullPathAndFilename)
{
    // Resolve name to absolute path before searching
    cString absolutePathAndFilename;
    CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
    pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mModelDirectoryName + name + _L(".mdl")), &absolutePathAndFilename);
    absolutePathAndFilename = nameIsFullPathAndFilename ? name : absolutePathAndFilename;

    // If we already have one by this name, then return it
    CPUTModel *pModel = FindModel(absolutePathAndFilename, true);
    if(NULL!=pModel)
    {
        pModel->AddRef();
        return pModel;
    }

    // Looks like no one calls GetModel().  Or, they never call it for missing models.
#if TODO // delegate
    // Model was not in the library, so create and load a new model
    pModel = new CPUTModel();
    pModel->LoadModelPayload(absolutePathAndFilename);
    AddModel(name, pModel);

    return CPUTModel::CreateMode( absolutePathAndFilename, aboslutePathAndFilename );
#endif

    return pModel;
}
Ejemplo n.º 6
0
CModel* CModelManager::AddModel(CString URI)
{
    TRACE("CModelManager::AddModel");

    CModel *model = FindModel(URI);
    if (model == NULL)
    {
        if (URI.Right(3) == "ifc" || URI.Right(3) == "IFC" || URI.Right(3) == "Ifc" ||
                URI.Right(6) == "ifcxml" || URI.Right(6) == "ifcXML" || URI.Right(6) == "ifcXml"||
                URI.Right(6) == "IFCxml" || URI.Right(6) == "IFCXML" || URI.Right(6) == "IFCXml"||
                URI.Right(6) == "Ifcxml" || URI.Right(6) == "IfcXML" || URI.Right(6) == "IfcXml")
        {
            model = new CIfcModel;
            ((CIfcModel*)model)->m_schemaFile = m_SchemaFile;
        }
        else
            model = new CGmlModel;

        model->m_URI = new char[URI.GetLength() + 1];
        model->m_filePath = new char[URI.ReverseFind('\\') + 2];
        model->m_fileName = new char[URI.GetLength() - URI.ReverseFind('\\') + 2];

        strcpy(model->m_URI, URI.GetBuffer());
        strcpy(model->m_filePath, URI.Mid(0, URI.ReverseFind('\\') + 1).GetBuffer());
        strcpy(model->m_fileName, URI.Mid(URI.ReverseFind('\\') + 1, URI.GetLength()).GetBuffer());

        m_models.push_back(model);
        model->OpenModel();
    }
    return model;
}
Ejemplo n.º 7
0
static void LoadModel_f(bool usage, int argc, char **argv)
{
	if (argc != 2 || usage)
	{
		appPrintf("Usage: loadmodel <filename>\n");
		return;
	}
	FindModel(argv[1]);
}
Ejemplo n.º 8
0
	MergeModel::iterator MergeModel::GetModelForRow (int row, int *starting)
	{
		const auto child = Root_->GetChild (row);
		const auto it = FindModel (child->GetModel ());

		if (starting)
			*starting = GetStartingRow (it);

		return it;
	}
Ejemplo n.º 9
0
	void MergeModel::handleRowsAboutToBeInserted (const QModelIndex& parent,
			int first, int last)
	{
		const auto model = static_cast<QAbstractItemModel*> (sender ());

		const auto startingRow = parent.isValid () ?
				0 :
				GetStartingRow (FindModel (model));
		beginInsertRows (mapFromSource (parent),
				first + startingRow, last + startingRow);
	}
Ejemplo n.º 10
0
	void MergeModel::handleModelAboutToBeReset ()
	{
		const auto model = static_cast<QAbstractItemModel*> (sender ());
		if (const auto rc = model->rowCount ())
		{
			const auto startingRow = GetStartingRow (FindModel (model));
			beginRemoveRows ({}, startingRow, rc + startingRow - 1);
			Root_->EraseChildren (Root_->begin () + startingRow, Root_->begin () + startingRow + rc);
			endRemoveRows ();
		}
	}
Ejemplo n.º 11
0
	void MergeModel::handleModelReset ()
	{
		const auto model = static_cast<QAbstractItemModel*> (sender ());
		if (const auto rc = model->rowCount ())
		{
			const auto startingRow = GetStartingRow (FindModel (model));

			beginInsertRows ({}, startingRow, rc + startingRow - 1);

			for (int i = 0; i < rc; ++i)
				Root_->InsertChild (startingRow + i, model, model->index (i, 0, {}), Root_);

			endInsertRows ();
		}
	}
Ejemplo n.º 12
0
size_t CModelLibrary::AddModel(const tstring& sModel, bool bStatic)
{
	if (!sModel.length())
		return 0;

	size_t iModel = FindModel(sModel);
	if (iModel != ~0)
		return iModel;

	m_apModels.push_back(new CModel(sModel));

	iModel = m_apModels.size()-1;
	m_apModels[iModel]->m_iCallList = CRenderer::CreateCallList(iModel);
	m_apModels[iModel]->m_bStatic = bStatic;
	return iModel;
}
Ejemplo n.º 13
0
Generator * ModelManager :: FindGen( const std::string & name ) const {
	std::vector <string> tmp;
	int n = ALib::Split( name,  NAMESEP_CHAR, tmp );
	if ( n < 1 || n > 2 ) {
		std::cerr << "Split " << name << " count is " << n << std::endl;
		throw Exception( "Invalid generator name " + ALib::SQuote( name ) );
	}
	string mname = n == 1 ? "" : tmp[0];
	string gname = n == 1 ?  tmp[0] : tmp[1];

	Model * mp = FindModel( mname );
	if ( mp == 0 ) {
		return 0;
	}

	Generator * gp = mp->FindGen( gname );
	return gp;
}
Ejemplo n.º 14
0
// Get CPUTModel from asset library
// If the model exists, then the existing model is Addref'ed and returned
//-----------------------------------------------------------------------------
CPUTModel *CPUTAssetLibrary::GetModel(const std::string &name, bool nameIsFullPathAndFilename)
{
    // Resolve name to absolute path before searching
    std::string absolutePathAndFilename;

    if (!nameIsFullPathAndFilename && name.at(0) == '%')
    {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(mSystemDirectoryName + "Asset/" + name.substr(1) + ".mdl", &absolutePathAndFilename);
    } else if (!nameIsFullPathAndFilename) {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(mModelDirectoryName + name + ".mdl", &absolutePathAndFilename);
    } else {
        CPUTFileSystem::ResolveAbsolutePathAndFilename(name, &absolutePathAndFilename);
    }

    // If we already have one by this name, then return it
    CPUTModel *pModel = FindModel(absolutePathAndFilename, true);
    if(NULL!=pModel)
    {
        pModel->AddRef();
        return pModel;
    }

    return pModel;
}
Ejemplo n.º 15
0
	void MergeModel::RemoveModel (QAbstractItemModel *model)
	{
		auto i = FindModel (model);

		if (i == Models_.end ())
		{
			qWarning () << Q_FUNC_INFO << "not found model" << model;
			return;
		}

		for (auto r = Root_->begin (); r != Root_->end (); )
			if ((*r)->GetModel () == model)
			{
				const auto idx = std::distance (Root_->begin (), r);

				beginRemoveRows ({}, idx, idx);
				r = Root_->EraseChild (r);
				endRemoveRows ();
			}
			else
				++r;

		Models_.erase (i);
	}
Ejemplo n.º 16
0
void gl_InitModels()
{
	int Lump, lastLump;
	FString path;
	int index;
	int i;

	FSpriteModelFrame smf;

	lastLump = 0;

	memset(&smf, 0, sizeof(smf));
	while ((Lump = Wads.FindLump("MODELDEF", &lastLump)) != -1)
	{
		FScanner sc(Lump);
		while (sc.GetString())
		{
			if (sc.Compare("model"))
			{
				sc.MustGetString();
				memset(&smf, 0, sizeof(smf));
				smf.xscale=smf.yscale=smf.zscale=1.f;

				smf.type = PClass::FindClass(sc.String);
				if (!smf.type || smf.type->Defaults == NULL) 
				{
					sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String);
				}
				GetDefaultByType(smf.type)->hasmodel=true;
				sc.MustGetStringName("{");
				while (!sc.CheckString("}"))
				{
					sc.MustGetString();
					if (sc.Compare("path"))
					{
						sc.MustGetString();
						FixPathSeperator(sc.String);
						path = sc.String;
						if (path[(int)path.Len()-1]!='/') path+='/';
					}
					else if (sc.Compare("model"))
					{
						sc.MustGetNumber();
						index=sc.Number;
						if (index<0 || index>=MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						sc.MustGetString();
						FixPathSeperator(sc.String);
						smf.models[index] = FindModel(path.GetChars(), sc.String);
						if (!smf.models[index])
						{
							Printf("%s: model not found\n", sc.String);
						}
					}
					else if (sc.Compare("scale"))
					{
						sc.MustGetFloat();
						smf.xscale=sc.Float;
						sc.MustGetFloat();
						smf.yscale=sc.Float;
						sc.MustGetFloat();
						smf.zscale=sc.Float;
					}
					// [BB] Added zoffset reading.
					else if (sc.Compare("zoffset"))
					{
						sc.MustGetFloat();
						smf.zoffset=sc.Float;
					}
					// [BB] Added model flags reading.
					else if (sc.Compare("ignoretranslation"))
					{
						smf.flags |= MDL_IGNORETRANSLATION;
					}
					else if (sc.Compare("pitchfrommomentum"))
					{
						smf.flags |= MDL_PITCHFROMMOMENTUM;
					}
					else if (sc.Compare("rotating"))
					{
						smf.flags |= MDL_ROTATING;
						smf.xrotate = 0.;
						smf.yrotate = 1.;
						smf.zrotate = 0.;
						smf.rotationCenterX = 0.;
						smf.rotationCenterY = 0.;
						smf.rotationCenterZ = 0.;
						smf.rotationSpeed = 1.;
					}
					else if (sc.Compare("rotation-speed"))
					{
						sc.MustGetFloat();
						smf.rotationSpeed = sc.Float;
					}
					else if (sc.Compare("rotation-vector"))
					{
						sc.MustGetFloat();
						smf.xrotate = sc.Float;
						sc.MustGetFloat();
						smf.yrotate = sc.Float;
						sc.MustGetFloat();
						smf.zrotate = sc.Float;
					}
					else if (sc.Compare("rotation-center"))
					{
						sc.MustGetFloat();
						smf.rotationCenterX = sc.Float;
						sc.MustGetFloat();
						smf.rotationCenterY = sc.Float;
						sc.MustGetFloat();
						smf.rotationCenterZ = sc.Float;
					}
					else if (sc.Compare("interpolatedoubledframes"))
					{
						smf.flags |= MDL_INTERPOLATEDOUBLEDFRAMES;
					}
					else if (sc.Compare("nointerpolation"))
					{
						smf.flags |= MDL_NOINTERPOLATION;
					}
					else if (sc.Compare("alignangle"))
					{
						smf.flags |= MDL_ALIGNANGLE;
					}
					else if (sc.Compare("alignpitch"))
					{
						smf.flags |= MDL_ALIGNPITCH;
					}
					else if (sc.Compare("rollagainstangle"))
					{
						smf.flags |= MDL_ROLLAGAINSTANGLE;
					}
					else if (sc.Compare("skin"))
					{
						sc.MustGetNumber();
						index=sc.Number;
						if (index<0 || index>=MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						sc.MustGetString();
						FixPathSeperator(sc.String);
						if (sc.Compare(""))
						{
							smf.skins[index]=NULL;
						}
						else
						{
							smf.skins[index]=LoadSkin(path.GetChars(), sc.String);
							if (smf.skins[index] == NULL)
							{
								Printf("Skin '%s' not found in '%s'\n",
									sc.String, smf.type->TypeName.GetChars());
							}
						}
					}
					else if (sc.Compare("frameindex") || sc.Compare("frame"))
					{
						bool isframe=!!sc.Compare("frame");

						sc.MustGetString();
						smf.sprite = -1;
						for (i = 0; i < (int)sprites.Size (); ++i)
						{
							if (strncmp (sprites[i].name, sc.String, 4) == 0)
							{
								if (sprites[i].numframes==0)
								{
									//sc.ScriptError("Sprite %s has no frames", sc.String);
								}
								smf.sprite = i;
								break;
							}
						}
						if (smf.sprite==-1)
						{
							sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars());
						}

						sc.MustGetString();
						FString framechars = sc.String;

						sc.MustGetNumber();
						index=sc.Number;
						if (index<0 || index>=MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						if (isframe)
						{
							sc.MustGetString();
							if (smf.models[index]!=NULL) 
							{
								smf.modelframes[index] = smf.models[index]->FindFrame(sc.String);
								if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars());
							}
							else smf.modelframes[index] = -1;
						}
						else
						{
							sc.MustGetNumber();
							smf.modelframes[index] = sc.Number;
						}

						for(i=0; framechars[i]>0; i++)
						{
							char map[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
							int c = toupper(framechars[i])-'A';

							if (c<0 || c>=29)
							{
								sc.ScriptError("Invalid frame character %c found", c+'A');
							}
							if (map[c]) continue;
							smf.frame=c;
							SpriteModelFrames.Push(smf);
							map[c]=1;
						}
					}
				}
			}
		}
	}

	// create a hash table for quick access
	SpriteModelHash = new int[SpriteModelFrames.Size ()];
	atterm(DeleteModelHash);
	memset(SpriteModelHash, 0xff, SpriteModelFrames.Size () * sizeof(int));

	for (i = 0; i < (int)SpriteModelFrames.Size (); i++)
	{
		int j = ModelFrameHash(&SpriteModelFrames[i]) % SpriteModelFrames.Size ();

		SpriteModelFrames[i].hashnext = SpriteModelHash[j];
		SpriteModelHash[j]=i;
	}
}
Ejemplo n.º 17
0
model_t	*FindModel(const char *name)
{
	guard(R_FindModel);

	TString<64> Name2;
	Name2.filename(name);

#if 0
	// try to load md3 instead of md2
	//!! disable later
	char *ext = strrchr(Name2, '.');
	if (ext && !strcmp(ext, ".md2"))
	{
		ext[3] = '3';		// ".md2" -> ".md3"
		if (GFileSystem->FileExists(Name2))
			return FindModel(Name2);
		// md3 model with the same name is not found -- load md2
		ext[3] = '2';		// ".md3" -> ".md2"
	}
#endif

	model_t *m;
	// search already loaded models
	for (int i = 0; i < modelCount; i++)
	{
		m = modelsArray[i];
		if (!m) continue;				//?? should not happens
		if (Name2 == m->Name)
		{
			// found
			if (m->type == MODEL_UNKNOWN)
				return NULL;			// model name was cached to avoid file system lookup again
			return m;
		}
	}
	if (Name2[0] == '*')
		Com_DropError("R_FindModel: inline model \"%s\" was not found", *Name2);

	if (modelCount == MAX_GLMODELS)
	{
		appWPrintf("R_FindModel: MAX_GLMODELS\n");
		return NULL;
	}

	/*----- not found -- load model ------*/
	unsigned len;
	unsigned *file;
	if (!(file = (unsigned*) GFileSystem->LoadFile(Name2, &len)))
	{
		m = new model_t;
		m->Name = Name2;
		modelsArray[modelCount++] = m;
		Com_DPrintf("R_FindModel: not found: %s\n", *Name2);
		return NULL;	// file not found
	}

	switch (LittleLong(*file))
	{
	case MD2_IDENT:
		m = LoadMd2(Name2, (byte*)file, len);
		break;
	case MD3_IDENT:
		m = LoadMd3(Name2, (byte*)file, len);
		break;
	case SP2_IDENT:
		m = LoadSp2(Name2, (byte*)file, len);
		break;
	case BYTES4('/','/','S','P'):
		m = LoadSpr(Name2, (byte*)file, len);
		break;
	default:
		// no error here: simply ignore unknown model formats
		appWPrintf("R_FindModel: unknown ID 0x%X in %s", (unsigned)LittleLong(*file), name);
		m = NULL;
	}
	if (m) modelsArray[modelCount++] = m;

	delete file;
	return m;

	unguardf(("mdl=%s", name));
}
Ejemplo n.º 18
0
picoModel_t    *LoadModel(char *name, int frame)
{
	int             i;
	picoModel_t    *model, **pm;


	/* init */
	if(numPicoModels <= 0)
		memset(picoModels, 0, sizeof(picoModels));

	/* dummy check */
	if(name == NULL || name[0] == '\0')
		return NULL;

	/* try to find existing picoModel */
	model = FindModel(name, frame);
	if(model != NULL)
		return model;

	/* none found, so find first non-null picoModel */
	pm = NULL;
	for(i = 0; i < MAX_MODELS; i++)
	{
		if(picoModels[i] == NULL)
		{
			pm = &picoModels[i];
			break;
		}
	}

	/* too many picoModels? */
	if(pm == NULL)
		Error("MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS);

	/* attempt to parse model */
	*pm = PicoLoadModel((char *)name, frame);

	/* if loading failed, make a bogus model to silence the rest of the warnings */
	if(*pm == NULL)
	{
		/* allocate a new model */
		*pm = PicoNewModel();
		if(*pm == NULL)
			return NULL;

		/* set data */
		PicoSetModelName(*pm, name);
		PicoSetModelFrameNum(*pm, frame);
	}

	/* debug code */
#if 0
	{
		int             numSurfaces, numVertexes;
		picoSurface_t  *ps;


		Sys_Printf("Model %s\n", name);
		numSurfaces = PicoGetModelNumSurfaces(*pm);
		for(i = 0; i < numSurfaces; i++)
		{
			ps = PicoGetModelSurface(*pm, i);
			numVertexes = PicoGetSurfaceNumVertexes(ps);
			Sys_Printf("Surface %d has %d vertexes\n", i, numVertexes);
		}
	}
#endif

	/* set count */
	if(*pm != NULL)
		numPicoModels++;

	/* return the picoModel */
	return *pm;
}
Ejemplo n.º 19
0
void RateMatrix::setModelConditions(
									string& rate_matrix, 
									string& rates_in, 
									string& freqs_in
								   )
{
	size_t j = 0;
	list<string> arg_split;
	vector<double>::iterator R_it;

	substitution_model = FindModel(rate_matrix);
	InitializeSubstitutionVectors();

	//////////
	/// Each entry in the input of frequencies is separated by the ',' token.
	//////////
	arg_split = split(freqs_in, ",");
	if (arg_split.size() == numStates) {
		vector<double>::iterator pi_t = pi.begin();
		for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it, ++pi_t)
			(*pi_t) = atof((*it).c_str());
	} else if ( 
			   substitution_model == SYM 
			   || substitution_model == JC69 
			   || substitution_model == K80 
			   || substitution_model == K81 
			   || substitution_model == TN93eq 
			   || substitution_model == TIMeq
			   || substitution_model == TVMeq
			   || numStates > 4 
			  ) {
		// Do not need to set frequencies from command-line. Already have preset  values.
	} else cerr << "setModelConditions: bad freqs in." << endl;

	arg_split = split(rates_in, ",");
	switch (substitution_model) {
		case SYM:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case GTR:
			if(arg_split.size() != NUM_NUC_REL_RATES) {
				cout << "GTR and SYM rate matrices require " << NUM_NUC_REL_RATES << " values in option --rel_rates (-r), only " << arg_split.size() << " supplied:" << endl;
				for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it, j++)
					cout << j << ": " << (*it) << endl;
				cout << endl;
				cout << " <list> = a,b,c,d,e,f--------------------------\n";
				cout << "     model GTR/SYM\n";
				cout << "           A C G T   \n";
				cout << "         | * a b c | \n";
				cout << "     Q = | a * d e | \n";
			    cout << "         | b d * f | \n";
			    cout << "         | c e f * | \n";
				cout << "\n";
				cout << " ----------------------------------------------\n";
				cout << "\n";
				exit(EXIT_FAILURE);
			}
			R_it = Sij.begin();
			for(list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it, ++R_it) 
				(*R_it) = atof((*it).c_str());
			if(Sij.back() != 1.0) {
				for(R_it = Sij.begin(); R_it != Sij.end(); ++R_it) 
					(*R_it) /= Sij.back();
			}
			break;
		case K80:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case F84:
		case HKY:
			if (arg_split.size() != 1) {
				cout << "K80 and HKY rate matrices require 1 values (kappa) in option --rel_rates (-r): " << rates_in << endl << endl;
				cout << " <list> = a -----------------------------------\n";
				cout << "     model K80/HKY/F84\n";
				cout << "           A C G T  \n";
				cout << "         | *   a   |\n";
				cout << "     Q = |   *   a |\n";
				cout << "         | a   *   |\n";
				cout << "         |   a   * |\n";
				cout << "\n";
				cout << " ----------------------------------------------\n";
				cout << "\n";
				exit(EXIT_FAILURE);
			}
			for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it) 
				kappa.push_back(atof((*it).c_str()));
		break;
		case TN93eq:
		case K81:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case TN93:
		case K81ne:
			if (arg_split.size() != 2) {
				cout << "K81 and TN93 rate matrices require 2 values in option --rel_rates (-r): " << rates_in << endl << endl;
				cout << " <list> = a,b ---------------------------------\n";
				cout << "     model K81/K81ne    model TN93/TN93eq\n";
				cout << "           A C G T            A C G T\n";
				cout << "         | *   a b |        | *   a   |\n";
				cout << "     Q = |   * b a |    Q = |   *   b |\n";
			    cout << "         | a b *   |        | a   *   |\n";
			    cout << "         | b a   * |        |   b   * |\n";
				cout << "\n";
				cout << " ----------------------------------------------\n";
				cout << "\n";
				exit(EXIT_FAILURE);
			}
			for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it) 
				kappa.push_back(atof((*it).c_str()));
			break;
		case TIMeq:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case TIM:
			if (arg_split.size() != 3) {
				cout << "TIM rate matrix require 3 values in option --rel_rates (-r): " << rates_in << endl << endl;
				cout << " <list> = a,b,c -------------------------------\n";
				cout << "     model TIM/TIMeq\n";
				cout << "           A C G T   \n";
				cout << "         | *   a b | \n";
				cout << "     Q = |   * b c | \n";
			    cout << "         | a b *   | \n";
			    cout << "         | b c   * | \n";
				cout << "\n";
				cout << " ----------------------------------------------\n";
				cout << "\n";
				exit(EXIT_FAILURE);
			}
			for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it) 
				kappa.push_back(atof((*it).c_str()));
			break;
		case TVMeq:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case TVM:
			if (arg_split.size() != 4) {
				cout << "TVM rate matrix require 4 values in option --rel_rates (-r): " << rates_in << endl << endl;
				cout << " <list> = a,b,c,d -----------------------------\n";
				cout << "     model TVM/TVMeq\n";
				cout << "           A C G T   \n";
				cout << "         | *   a b | \n";
				cout << "     Q = |   * c b | \n";
			    cout << "         | a c * d | \n";
			    cout << "         | b b d * | \n";
				cout << "\n";
				cout << " ----------------------------------------------\n";
				cout << "\n";
				exit(EXIT_FAILURE);
			}
			for (list<string>::iterator it = arg_split.begin(); it != arg_split.end(); ++it) 
				kappa.push_back(atof((*it).c_str()));
			break;
		case JC69:
			pi.at(A) = pi.at(C) = pi.at(G) = pi.at(T) = 0.25;
		case F81:
			if ( arg_split.empty() ) {
				cerr << "Input model does not require relative rates: " << modelNames[substitution_model] << endl;
				exit(EXIT_FAILURE);
			}
			break;
		case JTT:
		case PAM:
		case WAG:
		case BLOSUM:
		case MTREV:
		case CPREV:
			if ( arg_split.empty() ) {
				cerr << "Protein models do not require relative rates: " << modelNames[substitution_model] << endl;
				exit(EXIT_FAILURE);
			}
			break;
		default:
			cerr << "Unknown input model: " << rate_matrix << endl;
			exit(EXIT_FAILURE);
		break;
	}
}
Ejemplo n.º 20
0
/*
=================
idRenderModelManagerLocal::Preload
=================
*/
void idRenderModelManagerLocal::Preload( const idPreloadManifest& manifest )
{
	if( preload_MapModels.GetBool() )
	{
		// preload this levels images
		int	start = Sys_Milliseconds();
		int numLoaded = 0;
		idList< preloadSort_t > preloadSort;
		preloadSort.Resize( manifest.NumResources() );
		for( int i = 0; i < manifest.NumResources(); i++ )
		{
			const preloadEntry_s& p = manifest.GetPreloadByIndex( i );
			idResourceCacheEntry rc;
			idStrStatic< MAX_OSPATH > filename;
			if( p.resType == PRELOAD_MODEL )
			{
				filename = "generated/rendermodels/";
				filename += p.resourceName;
				idStrStatic< 16 > ext;
				filename.ExtractFileExtension( ext );
				filename.SetFileExtension( va( "b%s", ext.c_str() ) );
			}
			if( p.resType == PRELOAD_PARTICLE )
			{
				filename = "generated/particles/";
				filename += p.resourceName;
				filename += ".bprt";
			}
			if( !filename.IsEmpty() )
			{
				if( fileSystem->GetResourceCacheEntry( filename, rc ) )
				{
					preloadSort_t ps = {};
					ps.idx = i;
					ps.ofs = rc.offset;
					preloadSort.Append( ps );
				}
			}
		}
		
		preloadSort.SortWithTemplate( idSort_Preload() );
		
		for( int i = 0; i < preloadSort.Num(); i++ )
		{
			const preloadSort_t& ps = preloadSort[ i ];
			const preloadEntry_s& p = manifest.GetPreloadByIndex( ps.idx );
			if( p.resType == PRELOAD_MODEL )
			{
				idRenderModel* model = FindModel( p.resourceName );
				if( model != NULL )
				{
					model->SetLevelLoadReferenced( true );
				}
			}
			else if( p.resType == PRELOAD_PARTICLE )
			{
				declManager->FindType( DECL_PARTICLE, p.resourceName );
			}
			numLoaded++;
		}
		
		int	end = Sys_Milliseconds();
		common->Printf( "%05d models preloaded ( or were already loaded ) in %5.1f seconds\n", numLoaded, ( end - start ) * 0.001 );
		common->Printf( "----------------------------------------\n" );
	}
}
Ejemplo n.º 21
0
void gl_InitModels()
{
	int Lump, lastLump;
	FString path;
	int index, surface;
	int i;

	FSpriteModelFrame smf;

	lastLump = 0;

	for(unsigned i=0;i<Models.Size();i++)
	{
		delete Models[i];
	}
	Models.Clear();
	SpriteModelFrames.Clear();
	DeleteModelHash();

	// First, create models for each voxel
	for (unsigned i = 0; i < Voxels.Size(); i++)
	{
		FVoxelModel *md = new FVoxelModel(Voxels[i], false);
		Voxels[i]->VoxelIndex = Models.Push(md);
	}
	// now create GL model frames for the voxeldefs
	for (unsigned i = 0; i < VoxelDefs.Size(); i++)
	{
		FVoxelModel *md = (FVoxelModel*)Models[VoxelDefs[i]->Voxel->VoxelIndex];
		memset(&smf, 0, sizeof(smf));
		smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1;
		smf.modelIDs[0] = VoxelDefs[i]->Voxel->VoxelIndex;
		smf.skinIDs[0] = md->GetPaletteTexture();
		smf.xscale = smf.yscale = smf.zscale = VoxelDefs[i]->Scale;
		smf.angleoffset = VoxelDefs[i]->AngleOffset.Degrees;
		if (VoxelDefs[i]->PlacedSpin != 0)
		{
			smf.yrotate = 1.f;
			smf.rotationSpeed = VoxelDefs[i]->PlacedSpin / 55.55f;
			smf.flags |= MDL_ROTATING;
		}
		VoxelDefs[i]->VoxeldefIndex = SpriteModelFrames.Push(smf);
		if (VoxelDefs[i]->PlacedSpin != VoxelDefs[i]->DroppedSpin)
		{
			if (VoxelDefs[i]->DroppedSpin != 0)
			{
				smf.yrotate = 1.f;
				smf.rotationSpeed = VoxelDefs[i]->DroppedSpin / 55.55f;
				smf.flags |= MDL_ROTATING;
			}
			else
			{
				smf.yrotate = 0;
				smf.rotationSpeed = 0;
				smf.flags &= ~MDL_ROTATING;
			}
			SpriteModelFrames.Push(smf);
		}
	}

	memset(&smf, 0, sizeof(smf));
	smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1;
	while ((Lump = Wads.FindLump("MODELDEF", &lastLump)) != -1)
	{
		FScanner sc(Lump);
		while (sc.GetString())
		{
			if (sc.Compare("model"))
			{
				path = "";
				sc.MustGetString();
				memset(&smf, 0, sizeof(smf));
				smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1;
				smf.xscale=smf.yscale=smf.zscale=1.f;

				smf.type = PClass::FindClass(sc.String);
				if (!smf.type || smf.type->Defaults == nullptr) 
				{
					sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String);
				}
				sc.MustGetStringName("{");
				while (!sc.CheckString("}"))
				{
					sc.MustGetString();
					if (sc.Compare("path"))
					{
						sc.MustGetString();
						FixPathSeperator(sc.String);
						path = sc.String;
						if (path[(int)path.Len()-1]!='/') path+='/';
					}
					else if (sc.Compare("model"))
					{
						sc.MustGetNumber();
						index = sc.Number;
						if (index < 0 || index >= MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						sc.MustGetString();
						FixPathSeperator(sc.String);
						smf.modelIDs[index] = FindModel(path.GetChars(), sc.String);
						if (smf.modelIDs[index] == -1)
						{
							Printf("%s: model not found in %s\n", sc.String, path.GetChars());
						}
					}
					else if (sc.Compare("scale"))
					{
						sc.MustGetFloat();
						smf.xscale = sc.Float;
						sc.MustGetFloat();
						smf.yscale = sc.Float;
						sc.MustGetFloat();
						smf.zscale = sc.Float;
					}
					// [BB] Added zoffset reading. 
					// Now it must be considered deprecated.
					else if (sc.Compare("zoffset"))
					{
						sc.MustGetFloat();
						smf.zoffset=sc.Float;
					}
					// Offset reading.
					else if (sc.Compare("offset"))
					{
						sc.MustGetFloat();
						smf.xoffset = sc.Float;
						sc.MustGetFloat();
						smf.yoffset = sc.Float;
						sc.MustGetFloat();
						smf.zoffset = sc.Float;
					}
					// angleoffset, pitchoffset and rolloffset reading.
					else if (sc.Compare("angleoffset"))
					{
						sc.MustGetFloat();
						smf.angleoffset = sc.Float;
					}
					else if (sc.Compare("pitchoffset"))
					{
						sc.MustGetFloat();
						smf.pitchoffset = sc.Float;
					}
					else if (sc.Compare("rolloffset"))
					{
						sc.MustGetFloat();
						smf.rolloffset = sc.Float;
					}
					// [BB] Added model flags reading.
					else if (sc.Compare("ignoretranslation"))
					{
						smf.flags |= MDL_IGNORETRANSLATION;
					}
					else if (sc.Compare("pitchfrommomentum"))
					{
						smf.flags |= MDL_PITCHFROMMOMENTUM;
					}
					else if (sc.Compare("inheritactorpitch"))
					{
						smf.flags |= MDL_USEACTORPITCH | MDL_BADROTATION;
					}
					else if (sc.Compare("inheritactorroll"))
					{
						smf.flags |= MDL_USEACTORROLL;
					}
					else if (sc.Compare("useactorpitch"))
					{
						smf.flags |= MDL_USEACTORPITCH;
					}
					else if (sc.Compare("useactorroll"))
					{
						smf.flags |= MDL_USEACTORROLL;
					}
					else if (sc.Compare("rotating"))
					{
						smf.flags |= MDL_ROTATING;
						smf.xrotate = 0.;
						smf.yrotate = 1.;
						smf.zrotate = 0.;
						smf.rotationCenterX = 0.;
						smf.rotationCenterY = 0.;
						smf.rotationCenterZ = 0.;
						smf.rotationSpeed = 1.;
					}
					else if (sc.Compare("rotation-speed"))
					{
						sc.MustGetFloat();
						smf.rotationSpeed = sc.Float;
					}
					else if (sc.Compare("rotation-vector"))
					{
						sc.MustGetFloat();
						smf.xrotate = sc.Float;
						sc.MustGetFloat();
						smf.yrotate = sc.Float;
						sc.MustGetFloat();
						smf.zrotate = sc.Float;
					}
					else if (sc.Compare("rotation-center"))
					{
						sc.MustGetFloat();
						smf.rotationCenterX = sc.Float;
						sc.MustGetFloat();
						smf.rotationCenterY = sc.Float;
						sc.MustGetFloat();
						smf.rotationCenterZ = sc.Float;
					}
					else if (sc.Compare("interpolatedoubledframes"))
					{
						smf.flags |= MDL_INTERPOLATEDOUBLEDFRAMES;
					}
					else if (sc.Compare("nointerpolation"))
					{
						smf.flags |= MDL_NOINTERPOLATION;
					}
					else if (sc.Compare("skin"))
					{
						sc.MustGetNumber();
						index=sc.Number;
						if (index<0 || index>=MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						sc.MustGetString();
						FixPathSeperator(sc.String);
						if (sc.Compare(""))
						{
							smf.skinIDs[index]=FNullTextureID();
						}
						else
						{
							smf.skinIDs[index] = LoadSkin(path.GetChars(), sc.String);
							if (!smf.skinIDs[index].isValid())
							{
								Printf("Skin '%s' not found in '%s'\n",
									sc.String, smf.type->TypeName.GetChars());
							}
						}
					}
					else if (sc.Compare("surfaceskin"))
					{
						sc.MustGetNumber();
						index = sc.Number;
						sc.MustGetNumber();
						surface = sc.Number;

						if (index<0 || index >= MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}

						if (surface<0 || surface >= MD3_MAX_SURFACES)
						{
							sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, smf.type->TypeName.GetChars());
						}

						sc.MustGetString();
						FixPathSeperator(sc.String);
						if (sc.Compare(""))
						{
							smf.surfaceskinIDs[index][surface] = FNullTextureID();
						}
						else
						{
							smf.surfaceskinIDs[index][surface] = LoadSkin(path.GetChars(), sc.String);
							if (!smf.surfaceskinIDs[index][surface].isValid())
							{
								Printf("Surface Skin '%s' not found in '%s'\n",
									sc.String, smf.type->TypeName.GetChars());
							}
						}
					}
					else if (sc.Compare("frameindex") || sc.Compare("frame"))
					{
						bool isframe=!!sc.Compare("frame");

						sc.MustGetString();
						smf.sprite = -1;
						for (i = 0; i < (int)sprites.Size (); ++i)
						{
							if (strnicmp (sprites[i].name, sc.String, 4) == 0)
							{
								if (sprites[i].numframes==0)
								{
									//sc.ScriptError("Sprite %s has no frames", sc.String);
								}
								smf.sprite = i;
								break;
							}
						}
						if (smf.sprite==-1)
						{
							sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars());
						}

						sc.MustGetString();
						FString framechars = sc.String;

						sc.MustGetNumber();
						index=sc.Number;
						if (index<0 || index>=MAX_MODELS_PER_FRAME)
						{
							sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars());
						}
						if (isframe)
						{
							sc.MustGetString();
							if (smf.modelIDs[index] != -1)
							{
								FModel *model = Models[smf.modelIDs[index]];
								smf.modelframes[index] = model->FindFrame(sc.String);
								if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars());
							}
							else smf.modelframes[index] = -1;
						}
						else
						{
							sc.MustGetNumber();
							smf.modelframes[index] = sc.Number;
						}

						for(i=0; framechars[i]>0; i++)
						{
							char map[29]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
							int c = toupper(framechars[i])-'A';

							if (c<0 || c>=29)
							{
								sc.ScriptError("Invalid frame character %c found", c+'A');
							}
							if (map[c]) continue;
							smf.frame=c;
							SpriteModelFrames.Push(smf);
							GetDefaultByType(smf.type)->hasmodel = true;
							map[c]=1;
						}
					}
					else
					{
						sc.ScriptMessage("Unrecognized string \"%s\"", sc.String);
					}
				}
			}
		}
	}

	// create a hash table for quick access
	SpriteModelHash = new int[SpriteModelFrames.Size ()];
	atterm(DeleteModelHash);
	memset(SpriteModelHash, 0xff, SpriteModelFrames.Size () * sizeof(int));

	for (i = 0; i < (int)SpriteModelFrames.Size (); i++)
	{
		int j = ModelFrameHash(&SpriteModelFrames[i]) % SpriteModelFrames.Size ();

		SpriteModelFrames[i].hashnext = SpriteModelHash[j];
		SpriteModelHash[j]=i;
	}
}
Ejemplo n.º 22
0
void ModelManager :: AddModel( Model * m, ModelMode mm ) {
	if ( FindModel( m->Name() ) ) {
		throw Exception( "Duplicate model name " + ALib::SQuote( m->Name() ));
	}
	mModels.push_back( MME( m, mm ) );
}