Esempio n. 1
0
File: map.c Progetto: dommul/super8
/*
================
LoadMapFile
================
*/
void LoadMapFile (char *filename)
{
	void	*buf;

	num_entities = 0;

	nummapbrushfaces = 0;
	nummapbrushes = 0;
	nummapplanes = 0;
	nummiptex = 0;
	mapversion = 0;

	LoadFile (filename, &buf);

	StartTokenParsing (buf);

	while (ParseEntity ());

	qfree (buf);

	qprintf ("--- LoadMapFile ---\n");
	qprintf ("%s\n", filename);
	qprintf ("%5i faces\n", nummapbrushfaces);
	qprintf ("%5i brushes\n", nummapbrushes);
	qprintf ("%5i entities\n", num_entities);
	qprintf ("%5i textures\n", nummiptex);
	qprintf ("%5i texinfo\n", numtexinfo);
}
Esempio n. 2
0
File: map.c Progetto: kellyrm/Q1
/*
================
LoadMapFile
================
*/
void LoadMapFile (char *filename)
{
	char *buf;

	Message (MSGVERBOSE, "------ LoadMapFile ------");

	LoadFile (filename, (void **)&buf);

	StartTokenParsing (buf);

	num_entities = 0;

	while (ParseEntity ())
	{
	}

	FreeOther (buf);

	if (num_entities == 0)
		Message(MSGERR, "No entities in map");

	if (PlayerStarts == 0)
		Message (MSGWARNCRIT, "No info_player_start entity in level");

	if (strlen(MapTitle) != 0)
		Message (MSGALWAYS, "Title: \"%s\"", MapTitle);

	Message (MSGVERBOSE, "%6i faces", nummapfaces);
	Message (MSGVERBOSE, "%6i brushes", nummapbrushes);
	Message (MSGVERBOSE, "%6i entities", num_entities);
	Message (MSGVERBOSE, "%6i miptex", nummiptex);
	Message (MSGVERBOSE, "%6i texinfo", numtexinfo);
}
Esempio n. 3
0
void WINAPI QERApp_LoadShaderFile (const char* filename)
{
	char* pBuff = NULL;
	int nSize = LoadFile(filename, reinterpret_cast<void**>(&pBuff));
	if (nSize == -1)
		nSize = PakLoadAnyFile(filename, reinterpret_cast<void**>(&pBuff));
	if (nSize > 0)
	{
		Sys_Printf("Parsing shaderfile %s\n", filename);
		StartTokenParsing(pBuff);
		while (GetToken(true))
		{
			// first token should be the path + name.. (from base)
			CShader *pShader = new CShader();
			// we want the relative filename only, it's easier for later lookup .. see QERApp_ReloadShaderFile
			char cTmp[1024];
			QE_ConvertDOSToUnixName( cTmp, filename );
			pShader->setShaderFileName( filename + strlen(ValueForKey(g_qeglobals.d_project_entity, "basepath")) + 1);
			if (pShader->Parse())
			{
				// do we already have this shader?
				//++timo NOTE: this may a bit slow, we may need to use a map instead of a dumb list
				if (g_Shaders.Shader_ForName( pShader->getName() ) != NULL)
				{
					Sys_Printf( "WARNING: shader %s is already in memory, definition in %s ignored.\n", pShader->getName(), filename );
					delete pShader;
				}
				else
				{
					pShader->IncRef();
					g_Shaders.Add( (LPVOID)pShader );
					int n = g_PrefsDlg.m_nShader;
					if ((g_PrefsDlg.m_nShader == CPrefsDlg::SHADER_ALL) || (g_PrefsDlg.m_nShader == CPrefsDlg::SHADER_COMMON && strstr(pShader->getName(), "common" )))
						// load the qtexture and display in tex wnd
						pShader->Activate();
				}
			}
			else
			{
				Sys_Printf("Error parsing shader %s\n", pShader->getName());
				delete pShader;
			}			
		}
		free (pBuff);
	}
	else
	{
		Sys_Printf("Unabled to read shaderfile %s\n", filename);
	}	
}
Esempio n. 4
0
void Map_Read( IDataStream *in, CPtrArray *map ){
	entity_t *pEntity;
	char *buf;

	unsigned long len = in->GetLength();
	buf = new char[len + 1];
	in->Read( buf, len );
	buf[len] = '\0';
	StartTokenParsing( buf );
	abortcode = MAP_NOERROR;

	while ( abortcode == MAP_NOERROR )
	{
		if ( !GetToken( true ) ) { // { or NULL
			break;
		}
		pEntity = Entity_Alloc();
		pEntity->pData = new CPtrArray;
		Entity_Parse( pEntity );
		map->Add( pEntity );
	}

	delete [] buf;

	if ( abortcode != MAP_NOERROR ) {
		int num_ents, num_brushes,i,j;
		entity_t *e;
		CPtrArray *brushes;

		num_ents = map->GetSize();
		for ( i = 0; i < num_ents; i++ )
		{
			e = (entity_t*)map->GetAt( i );
			brushes = (CPtrArray*)e->pData;
			num_brushes = brushes->GetSize();
			for ( j = 0; j < num_brushes; j++ )
			{
				Brush_Free( (brush_t *)brushes->GetAt( j ), true );
			}
			brushes->RemoveAll();
			delete brushes;
			Entity_Free( e );
		}
		map->RemoveAll();
	}
}
Esempio n. 5
0
void LoadMapFile (char *filename)

{

	char	*buf;

		

	LoadFile (filename, (void **)&buf);



	StartTokenParsing (buf);

	

	num_entities = 0;

	

	while (ParseEntity ())

	{

	}

	

	free (buf);

	

	logprint ("--- LoadMapFile ---\n");

	logprint ("%s\n", filename);

	logprint ("%5i brushes\n", nummapbrushes);

	logprint ("%5i entities\n", num_entities);

	logprint ("%5i miptex\n", nummiptex);

	logprint ("%5i texinfo\n", numtexinfo);

}
Esempio n. 6
0
/*
 =======================================================================================================================
    QE_LoadProject
 =======================================================================================================================
 */
bool QE_LoadProject(char *projectfile) {
	char		*data;
	ID_TIME_T		time;

	common->Printf("QE_LoadProject (%s)\n", projectfile);

	if ( fileSystem->ReadFile( projectfile, reinterpret_cast < void ** > (&data), &time) <= 0 ) {
		return false;
	}

	g_strProject = projectfile;
	g_PrefsDlg.m_strLastProject = projectfile;
	g_PrefsDlg.SavePrefs();

	CString strData = data;

	fileSystem->FreeFile( data );

	StartTokenParsing(strData.GetBuffer(0));
	g_qeglobals.d_project_entity = Entity_Parse(true);
	if (!g_qeglobals.d_project_entity) {
		Error("Couldn't parse %s", projectfile);
	}

	// set here some default project settings you need
	if (strlen(ValueForKey(g_qeglobals.d_project_entity, "brush_primit")) == 0) {
		SetKeyValue(g_qeglobals.d_project_entity, "brush_primit", "0");
	}

	g_qeglobals.m_bBrushPrimitMode = IntForKey(g_qeglobals.d_project_entity, "brush_primit");

	Eclass_InitForSourceDirectory(ValueForKey(g_qeglobals.d_project_entity, "entitypath"));
	g_Inspectors->FillClassList();	// list in entity window

	Map_New();

	// FillTextureMenu();
	FillBSPMenu();

	return true;
}
Esempio n. 7
0
void Eclass_ScanFile( char *filename ){
	int size;
	char    *data;
	char temp[1024];
	GSList *l_classes = NULL;
	char token_debug[1024];  //++Hydra FIXME: cleanup this.
	bool done = false;
	int len,classtype;

	char *token = Token();

	QE_ConvertDOSToUnixName( temp, filename );

	size = vfsLoadFullPathFile( filename, (void**)&data );
	if ( size <= 0 ) {
		Sys_FPrintf( SYS_ERR, "Eclass_ScanFile: %s not found\n", filename );
		return;
	}
	Sys_Printf( "ScanFile: %s\n", temp );

	// start parsing the file
	StartTokenParsing( data );

	// build a list of base classes first

	while ( !done )
	{
		// find an @ sign.
		do
		{
			if ( !GetToken( true ) ) {
				done = true;
				break;
			}
		} while ( token[0] != '@' );

		strcpy( temp,token + 1 ); // skip the @

		classtype = CLASS_NOCLASS;
		if ( !stricmp( temp,"BaseClass" ) ) {
			classtype = CLASS_BASECLASS;
		}
		if ( !stricmp( temp,"PointClass" ) ) {
			classtype = CLASS_POINTCLASS;
		}
		if ( !stricmp( temp,"SolidClass" ) ) {
			classtype = CLASS_SOLIDCLASS;
		}

		if ( classtype ) {
			class_t *newclass = (class_t *) malloc( sizeof( class_s ) );
			memset( newclass, 0, sizeof( class_s ) );
			newclass->classtype = classtype;

			while ( 1 )
			{
				GetTokenExtra( false,"(",false ); // option or =
				strcpy( token_debug,token );

				if ( !strcmp( token,"=" ) ) {
					UnGetToken();
					break;
				}
				else
				{
					strlower( token );
					if ( !strcmp( token,"base" ) ) {
						GetTokenExtra( false,"(",true ); // (

						if ( !strcmp( token,"(" ) ) {
							while ( GetTokenExtra( false,",)",false ) ) // option) or option,
							{
								newclass->l_baselist = g_slist_append( newclass->l_baselist, strdup( token ) );

								GetTokenExtra( false,",)",true ); // , or )
								if ( !strcmp( token,")" ) ) {
									break;
								}

							}
						}
					}
					else if ( !strcmp( token,"size" ) ) {
						// parse (w h d) or (x y z, x y z)

						GetTokenExtra( false,"(",true ); // (
						if ( !strcmp( token,"(" ) ) {
							int sizedone = false;
							float w,h,d;
							GetToken( false );
							w = atof( token );
							GetToken( false );
							h = atof( token );
							GetToken( false ); // number) or number ,
							strcpy( temp,token );
							len = strlen( temp );
							if ( temp[len - 1] == ')' ) {
								sizedone = true;
							}
							temp[len - 1] = 0;
							d = atof( temp );
							if ( sizedone ) {
								// only one set of cordinates supplied, change the W,H,D to mins/maxs
								newclass->boundingbox[0][0] = 0 - ( w / 2 );
								newclass->boundingbox[1][0] = w / 2;
								newclass->boundingbox[0][1] = 0 - ( h / 2 );
								newclass->boundingbox[1][1] = h / 2;
								newclass->boundingbox[0][2] = 0 - ( d / 2 );
								newclass->boundingbox[1][2] = d / 2;
								newclass->gotsize = true;
							}
							else
							{
								newclass->boundingbox[0][0] = w;
								newclass->boundingbox[0][1] = h;
								newclass->boundingbox[0][2] = d;
								GetToken( false );
								newclass->boundingbox[1][0] = atof( token );
								GetToken( false );
								newclass->boundingbox[1][1] = atof( token );
/*
                GetToken(false); // "number)" or "number )"
                strcpy(temp,token);
                len = strlen(temp);
                if (temp[len-1] == ')')
                  temp[len-1] = 0;
                else
                  GetToken(false); // )
                newclass->boundingbox[1][2] = atof(temp);
 */
								GetTokenExtra( false,")",false ); // number
								newclass->boundingbox[1][2] = atof( token );
								newclass->gotsize = true;
								GetTokenExtra( false,")",true ); // )
							}
						}
					}
					else if ( !strcmp( token,"color" ) ) {
						GetTokenExtra( false,"(",true ); // (
						if ( !strcmp( token,"(" ) ) {
							// get the color values (0-255) and normalize them if required.
							GetToken( false );
							newclass->color[0] = atof( token );
							if ( newclass->color[0] > 1 ) {
								newclass->color[0] /= 255;
							}
							GetToken( false );
							newclass->color[1] = atof( token );
							if ( newclass->color[1] > 1 ) {
								newclass->color[1] /= 255;
							}
							GetToken( false );
							strcpy( temp,token );
							len = strlen( temp );
							if ( temp[len - 1] == ')' ) {
								temp[len - 1] = 0;
							}
							newclass->color[2] = atof( temp );
							if ( newclass->color[2] > 1 ) {
								newclass->color[2] /= 255;
							}
							newclass->gotcolor = true;
						}
					}
					else if ( !strcmp( token,"iconsprite" ) ) {
						GetTokenExtra( false,"(",true ); // (
						if ( !strcmp( token,"(" ) ) {
							GetTokenExtra( false,")",false ); // filename)
							// the model plugins will handle sprites too.
							// newclass->sprite = strdup(token);
							newclass->model = strdup( token );
							GetTokenExtra( false,")",true ); // )
						}
					}
					else if ( !strcmp( token,"model" ) ) {
						GetTokenExtra( false,"(",true ); // (
						if ( !strcmp( token,"(" ) ) {
							GetTokenExtra( false,")",false ); // filename)
							newclass->model = strdup( token );
							GetTokenExtra( false,")",true ); // )
						}
					}
					else
					{
						// Unsupported
						GetToken( false ); // skip it.
					}

				}
			}

			GetToken( false ); // =
			strcpy( token_debug,token );
			if ( !strcmp( token,"=" ) ) {
				GetToken( false );
				newclass->classname = strdup( token );
			}

			// Get the description
			if ( newclass->classtype != CLASS_BASECLASS ) {
				GetToken( false );
				if ( !strcmp( token,":" ) ) {
					GetToken( false );
					newclass->description = strdup( token );
				}
				else{ UnGetToken(); // no description
				}
			}

			// now build the option list.
			GetToken( true ); // [ or []

			if ( strcmp( token,"[]" ) ) { // got some options ?
				if ( !strcmp( token,"[" ) ) {
					// yup
					bool optioncomplete = false;
					option_t *newoption;

					while ( 1 )
					{
						GetToken( true );
						if ( !strcmp( token,"]" ) ) {
							break; // no more options

						}
						// parse the data and build the option_t

						strcpy( temp,token );
						len = strlen( temp );
						char *ptr = strchr( temp,'(' );

						if ( !ptr ) {
							break;
						}

						newoption = (option_t *) malloc( sizeof( option_s ) );
						memset( newoption, 0, sizeof( option_s ) );

						*ptr++ = 0;
						newoption->epairname = strdup( temp );

						len = strlen( ptr );
						if ( ptr[len - 1] != ')' ) {
							break;
						}

						ptr[len - 1] = 0;
						strlower( ptr );
						if ( !strcmp( ptr,"integer" ) ) {
							newoption->optiontype = OPTION_INTEGER;
						}
						else if ( !strcmp( ptr,"choices" ) ) {
							newoption->optiontype = OPTION_CHOICES;
						}
						else if ( !strcmp( ptr,"flags" ) ) {
							newoption->optiontype = OPTION_FLAGS;
						}
						else // string
						{
							newoption->optiontype = OPTION_STRING;
						}

						switch ( newoption->optiontype )
						{
						case OPTION_STRING:
						case OPTION_INTEGER:
							if ( !TokenAvailable() ) {
								optioncomplete = true;
								break;
							}
							GetToken( false ); // :
							strcpy( token_debug,token );
							if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) {
								newoption->optioninfo = strdup( token + 1 );
							}
							else
							{
								GetToken( false );
								newoption->optioninfo = strdup( token );
							}
							if ( TokenAvailable() ) { // default value ?
								GetToken( false );
								if ( !strcmp( token,":" ) ) {
									if ( GetToken( false ) ) {
										newoption->optiondefault = strdup( token );
										optioncomplete = true;
									}
								}
							}
							else
							{
								optioncomplete = true;
							}
							break;

						case OPTION_CHOICES:
							GetTokenExtra( false,":",true ); // : or :"something like this" (bah!)
							strcpy( token_debug,token );
							if ( ( token[0] == ':' ) && ( strlen( token ) > 1 ) ) {
								if ( token[1] == '\"' ) {
									strcpy( temp,token + 2 );
									while ( 1 )
									{
										if ( !GetToken( false ) ) {
											break;
										}
										strcat( temp," " );
										strcat( temp,token );
										len = strlen( temp );
										if ( temp[len - 1] == '\"' ) {
											temp[len - 1] = 0;
											break;
										}
									}
								}
								newoption->optioninfo = strdup( temp );
							}
							else
							{
								GetToken( false );
								newoption->optioninfo = strdup( token );
							}
							GetToken( false ); // : or =
							strcpy( token_debug,token );
							if ( !strcmp( token,":" ) ) {
								GetToken( false );
								newoption->optiondefault = strdup( token );
							}
							else
							{
								UnGetToken();
							}
						// And Follow on...
						case OPTION_FLAGS:
							GetToken( false ); // : or =
							strcpy( token_debug,token );
							if ( strcmp( token,"=" ) ) { // missing ?
								break;
							}

							GetToken( true ); // [
							strcpy( token_debug,token );
							if ( strcmp( token,"[" ) ) { // missing ?
								break;
							}

							choice_t *newchoice;
							while ( 1 )
							{
								GetTokenExtra( true,":",true ); // "]" or "number", or "number:"
								strcpy( token_debug,token );
								if ( !strcmp( token,"]" ) ) { // no more ?
									optioncomplete = true;
									break;
								}
								strcpy( temp,token );
								len = strlen( temp );
								if ( temp[len - 1] == ':' ) {
									temp[len - 1] = 0;
								}
								else
								{
									GetToken( false ); // :
									if ( strcmp( token,":" ) ) { // missing ?
										break;
									}
								}
								if ( !TokenAvailable() ) {
									break;
								}
								GetToken( false ); // the name

								newchoice = (choice_t *) malloc( sizeof( choice_s ) );
								memset( newchoice, 0, sizeof( choice_s ) );

								newchoice->value = atoi( temp );
								newchoice->name = strdup( token );

								newoption->choices = g_slist_append( newoption->choices, newchoice );

								// ignore any remaining tokens on the line
								while ( TokenAvailable() ) GetToken( false );

								// and it we found a "]" on the end of the line, put it back in the queue.
								if ( !strcmp( token,"]" ) ) {
									UnGetToken();
								}
							}
							break;

						}

						// add option to the newclass

						if ( optioncomplete ) {
							if ( newoption ) {
								// add it to the list.
								newclass->l_optionlist = g_slist_append( newclass->l_optionlist, newoption );
							}
						}
						else
						{
							Sys_Printf( "%WARNING: Parse error occured in '%s - %s'\n",classnames[newclass->classtype],newclass->classname );
							Free_Option( newoption );
						}

					}
				}
				else
				{
					UnGetToken(); // shouldn't get here.
				}
			}

			// add it to our list.
			l_classes = g_slist_append( l_classes, newclass );

		}
	}

	// finished with the file now.
	g_free( data );

	Sys_Printf( "FGD scan complete, building entities...\n" );

	// Once we get here we should have a few (!) lists in memory that we
	// can extract all the information required to build a the eclass_t structures.

	Create_EClasses( l_classes );

	// Free everything

	GSList *p = l_classes;
	while ( p )
	{
		class_t *tmpclass = (class_t *)p->data;

#ifdef FGD_VERBOSE
		// DEBUG: dump the info...
		Sys_Printf( "%s: %s (", classnames[tmpclass->classtype],tmpclass->classname );
		for ( GSList *tmp = tmpclass->l_baselist; tmp != NULL; tmp = tmp->next )
		{
			if ( tmp != tmpclass->l_baselist ) {
				Sys_Printf( ", " );
			}
			Sys_Printf( "%s", (char *)tmp->data );
		}
		if ( tmpclass->gotsize ) {
			sprintf( temp,"(%.0f %.0f %.0f) - (%.0f %.0f %.0f)",tmpclass->boundingbox[0][0],
					 tmpclass->boundingbox[0][1],
					 tmpclass->boundingbox[0][2],
					 tmpclass->boundingbox[1][0],
					 tmpclass->boundingbox[1][1],
					 tmpclass->boundingbox[1][2] );
		}
		else{ strcpy( temp,"No Size" ); }
		Sys_Printf( ") '%s' Size: %s",tmpclass->description ? tmpclass->description : "No description",temp );
		if ( tmpclass->gotcolor ) {
			sprintf( temp,"(%d %d %d)",tmpclass->color[0],
					 tmpclass->color[1],
					 tmpclass->color[2] );
		}
		else{ strcpy( temp,"No Color" ); }
		Sys_Printf( " Color: %s Options:\n",temp );
		if ( !tmpclass->l_optionlist ) {
			Sys_Printf( "  No Options\n" );
		}
		else
		{
			option_t *tmpoption;
			int count;
			GSList *olst;
			for ( olst = tmpclass->l_optionlist, count = 1; olst != NULL; olst = olst->next, count++ )
			{
				tmpoption = (option_t *)olst->data;
				Sys_Printf( "  %d, Type: %s, EPair: %s\n", count,optionnames[tmpoption->optiontype], tmpoption->epairname );

				choice_t *tmpchoice;
				GSList *clst;
				int ccount;
				for ( clst = tmpoption->choices, ccount = 1; clst != NULL; clst = clst->next, ccount++ )
				{
					tmpchoice = (choice_t *)clst->data;
					Sys_Printf( "    %d, Value: %d, Name: %s\n", ccount, tmpchoice->value, tmpchoice->name );
				}
			}
		}

#endif

		// free the baselist.
		ClearGSList( tmpclass->l_baselist );
		Free_Class( tmpclass );
		p = g_slist_remove( p, p->data );
	}

}
Esempio n. 8
0
//
// =======================================================================================================================
//    Map_ImportFile Timo 09/01/99:: called by CXYWnd::Paste & Map_ImportFile if Map_ImportFile ( prefab ), the buffer
//    may contain brushes in old format ( conversion needed )
// =======================================================================================================================
//
void Map_ImportBuffer(char *buf, bool renameEntities) {
	entity_t	*ent;
	brush_t		*b = NULL;
	CPtrArray	ptrs;

	Select_Deselect();

	Undo_Start("import buffer");

	g_qeglobals.d_parsed_brushes = 0;
	if (buf) {
		CMapStringToString	mapStr;
		StartTokenParsing(buf);
		g_qeglobals.d_num_entities = 0;

		//
		// Timo will be used in Entity_Parse to detect if a conversion between brush
		// formats is needed
		//
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;
		g_qeglobals.mapVersion = 1.0;

		if (GetToken(true)) {
			if (stricmp(token, "Version") == 0) {
				GetToken(false);
				g_qeglobals.mapVersion = atof(token);
				common->Printf("Map version: %1.2f\n", g_qeglobals.mapVersion);
			} else {
				UngetToken();
			}
		}

		idDict RemappedNames;	// since I can't use "map <string, string>"... sigh. So much for STL...

		while (1) {
			//
			// use the selected brushes list as it's handy ent = Entity_Parse (false,
			// &selected_brushes);
			//
			ent = Entity_Parse(false, &active_brushes);
			if (!ent) {
				break;
			}

			// end entity for undo
			Undo_EndEntity(ent);

			// end brushes for undo
			for (b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext) {
				Undo_EndBrush(b);
			}

			if (!strcmp(ValueForKey(ent, "classname"), "worldspawn")) {
				// world brushes need to be added to the current world entity
				b = ent->brushes.onext;
				while (b && b != &ent->brushes) {
					brush_t *bNext = b->onext;
					Entity_UnlinkBrush(b);
					Entity_LinkBrush(world_entity, b);
					ptrs.Add(b);
					b = bNext;
				}
			}
			else {
				// the following bit remaps conflicting target/targetname key/value pairs
				CString str = ValueForKey(ent, "target");
				CString strKey;
				CString strTarget("");
				if (str.GetLength() > 0) {
					if (FindEntity("target", str.GetBuffer(0))) {
						if (!mapStr.Lookup(str, strKey)) {
							idStr key;
							UniqueTargetName(key);
							strKey = key;
							mapStr.SetAt(str, strKey);
						}

						strTarget = strKey;
						SetKeyValue(ent, "target", strTarget.GetBuffer(0));
					}
				}

				/*
				 * str = ValueForKey(ent, "name"); if (str.GetLength() > 0) { if
				 * (FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) {
				 * UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } Entity_SetName(ent,
				 * strKey.GetBuffer(0)); } }
				 */
				CString cstrNameOld = ValueForKey(ent, "name");
				Entity_Name(ent, renameEntities);
				CString cstrNameNew = ValueForKey(ent, "name");
				if (cstrNameOld != cstrNameNew)
				{
					RemappedNames.Set(cstrNameOld, cstrNameNew);
				}
				//
				// if (strTarget.GetLength() > 0) SetKeyValue(ent, "target",
				// strTarget.GetBuffer(0));
				// add the entity to the end of the entity list
				//
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;

				for (b = ent->brushes.onext; b != &ent->brushes; b = b->onext) {
					ptrs.Add(b);
				}
			}
		}

		// now iterate through the remapped names, and see if there are any target-connections that need remaking...
		//
		// (I could probably write this in half the size with STL, but WTF, work with what we have...)
		//
		int iNumKeyVals = RemappedNames.GetNumKeyVals();
		for (int iKeyVal=0; iKeyVal < iNumKeyVals; iKeyVal++)
		{
			const idKeyValue *pKeyVal = RemappedNames.GetKeyVal( iKeyVal );

			LPCSTR psOldName = pKeyVal->GetKey().c_str();
			LPCSTR psNewName = pKeyVal->GetValue().c_str();

			entity_t *pEntOld = FindEntity("name", psOldName);	// original ent we cloned from
			entity_t *pEntNew = FindEntity("name", psNewName);	// cloned ent

			if (pEntOld && pEntNew)
			{
				CString cstrTargetNameOld = ValueForKey(pEntOld, "target");
				if (!cstrTargetNameOld.IsEmpty())
				{
					// ok, this ent was targeted at another ent, so it's clone needs updating to point to
					//	the clone of that target, so...
					//
					entity_t *pEntOldTarget = FindEntity("name", cstrTargetNameOld);
					if ( pEntOldTarget )
					{
						LPCSTR psNewTargetName = RemappedNames.GetString( cstrTargetNameOld );
						if (psNewTargetName && psNewTargetName[0])
						{
							SetKeyValue(pEntNew, "target", psNewTargetName);
						}
					}
				}
			}
		}
	}

	//
	// ::ShowWindow(g_qeglobals.d_hwndEntity, FALSE);
	// ::LockWindowUpdate(g_qeglobals.d_hwndEntity);
	//
	g_bScreenUpdates = false;
	for (int i = 0; i < ptrs.GetSize(); i++) {
		Brush_Build(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
		Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]), true, false);
	}

	// ::LockWindowUpdate(NULL);
	g_bScreenUpdates = true;

	ptrs.RemoveAll();

	//
	// reset the "need conversion" flag conversion to the good format done in
	// Map_BuildBrushData
	//
	g_qeglobals.bNeedConvert = false;

	Sys_UpdateWindows(W_ALL);

	// Sys_MarkMapModified();
	mapModified = 1;

	Undo_End();
}
Esempio n. 9
0
/*
===========
QE_LoadProject
FIXME: the BuildShortPathName calls should be removed, it would get much more cleaner
  I don't have time to modify something so deep in the system, but this lead to a bug when loading .md3
	see Win_ent.cpp AssignModel
===========
*/
qboolean QE_LoadProject (char *projectfile)
{
	char	*data;
	Sys_Printf ("QE_LoadProject (%s)\n", projectfile);
	
	if ( LoadFileNoCrash (projectfile, (void **)&data) == -1)
		return false;
	
	g_strProject = projectfile;
	
	CString strData = data;
	free(data);
	
	CString strQ2Path = g_PrefsDlg.m_strQuake2;
	CString strQ2File;
	ExtractPath_and_Filename(g_PrefsDlg.m_strQuake2, strQ2Path, strQ2File);
	AddSlash(strQ2Path);
	
	
	char* pBuff = new char[1024];
	
	//BuildShortPathName(strQ2Path, pBuff, 1024);
	strcpy_s(pBuff, 1024,strQ2Path);	// Jonathan: strcpy_s replaces BuildShortPathName
	FindReplace(strData, "__Q2PATH", pBuff);
	//BuildShortPathName(g_strAppPath, pBuff, 1024);
	strcpy_s(pBuff, 1024,g_strAppPath);	// Jonathan: strcpy_s replaces BuildShortPathName
	FindReplace(strData, "__QERPATH", pBuff);
	
	char* pFile;
	if (GetFullPathName(projectfile, 1024, pBuff, &pFile))
	{
		g_PrefsDlg.m_strLastProject = pBuff;
		//BuildShortPathName(g_PrefsDlg.m_strLastProject, pBuff, 1024);
		g_PrefsDlg.m_strLastProject = pBuff;
		g_PrefsDlg.SavePrefs();
		
		ExtractPath_and_Filename(pBuff, strQ2Path, strQ2File);
		int nLen = strQ2Path.GetLength();
		if (nLen > 0)
		{
			if (strQ2Path[nLen - 1] == '\\')
				strQ2Path.SetAt(nLen-1,'\0');
			char* pBuffer = strQ2Path.GetBufferSetLength(_MAX_PATH + 1);
			int n = strQ2Path.ReverseFind('\\');
			if (n >=0 )
				pBuffer[n + 1] = '\0';
			strQ2Path.ReleaseBuffer();
			FindReplace(strData, "__QEPROJPATH", strQ2Path);
		}
	}
	
	
	StartTokenParsing (strData.GetBuffer(0));
	g_qeglobals.d_project_entity = Entity_Parse (true);
	if (!g_qeglobals.d_project_entity)
		Error ("Couldn't parse project file: %s", projectfile);

  // add a version checking to avoid people loading later versions of the project file and bitching against me
  int ver = IntForKey( g_qeglobals.d_project_entity, "version" );
  if (ver != 0)
  {
    char strMsg[1024];
    sprintf( strMsg, "This is a version %d project file. This build only supports <=0 project files.\n"
      "Please choose another project file or upgrade your version of Radiant.", ver );
    MessageBox( NULL, strMsg, "Can't load project file", MB_ICONERROR | MB_OK );
    return false;
  }

  for (int i = 0; i < g_nPathFixupCount; i++)
  {
    char *pPath = ValueForKey (g_qeglobals.d_project_entity, g_pPathFixups[i]);
    if (pPath[0] != '\\' && pPath[0] != '/')
    {
	    if (GetFullPathName(pPath, 1024, pBuff, &pFile))
      {
        SetKeyValue(g_qeglobals.d_project_entity, g_pPathFixups[i], pBuff);
      }
    }
  }

	delete []pBuff;

	// set here some default project settings you need
	if ( strlen( ValueForKey( g_qeglobals.d_project_entity, "brush_primit" ) ) == 0 )
	{
		SetKeyValue( g_qeglobals.d_project_entity, "brush_primit", "0" );
	}

	g_qeglobals.m_bBrushPrimitMode = IntForKey( g_qeglobals.d_project_entity, "brush_primit" );

  // usefull for the log file and debuggin f****d up configurations from users:
  // output the basic information of the .qe4 project file
  Sys_Printf("basepath    : %s\n", ValueForKey( g_qeglobals.d_project_entity, "basepath") );
  Sys_Printf("mapspath    : %s\n", ValueForKey( g_qeglobals.d_project_entity, "mapspath") );
//  the rsh command code is probably broken in these builds .. I would need ppl that actually use it ..
//  Sys_Printf("rshcmd         : %s\n", ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ) );
//  Sys_Printf("remotebasepath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ) );
  Sys_Printf("entitypath  : %s\n", ValueForKey( g_qeglobals.d_project_entity, "entitypath" ) );
  Sys_Printf("texturepath : %s\n", ValueForKey( g_qeglobals.d_project_entity, "texturepath" ) );

	Eclass_InitForSourceDirectory (ValueForKey (g_qeglobals.d_project_entity, "entitypath"));
	FillClassList();		// list in entity window
	
	Map_New();
	
	
	FillTextureMenu();
	FillBSPMenu();
	
	return true;
}
Esempio n. 10
0
//
//================
//Map_ImportFile
// Timo 09/01/99 : called by CXYWnd::Paste & Map_ImportFile
// if Map_ImportFile ( prefab ), the buffer may contain brushes in old format ( conversion needed )
//================
//
void Map_ImportBuffer (char* buf)
{
	entity_t* ent;
	brush_t* b = NULL;
	CPtrArray ptrs;

	Select_Deselect();

	Undo_Start("import buffer");

	g_qeglobals.d_parsed_brushes = 0;
	if (buf)
	{
		CMapStringToString mapStr;
		StartTokenParsing (buf);
		g_qeglobals.d_num_entities = 0;

		// Timo
		// will be used in Entity_Parse to detect if a conversion between brush formats is needed
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;

		while (1)
		{

			// use the selected brushes list as it's handy
			//ent = Entity_Parse (false, &selected_brushes);
			ent = Entity_Parse (false, &active_brushes);
			if (!ent)
				break;
			//end entity for undo
			Undo_EndEntity(ent);
			//end brushes for undo
			for(b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext)
			{
				Undo_EndBrush(b);
			}

			if (!strcmp(ValueForKey (ent, "classname"), "worldspawn"))
			{
				// world brushes need to be added to the current world entity

				b=ent->brushes.onext;
				while (b && b != &ent->brushes)
				{
					brush_t* bNext = b->onext;
					Entity_UnlinkBrush(b);
					Entity_LinkBrush(world_entity, b);
					ptrs.Add(b);
					b = bNext;
				}
			}
			else
			{
				// the following bit remaps conflicting target/targetname key/value pairs
				CString str = ValueForKey(ent, "target");
				CString strKey;
				CString strTarget("");
				if (str.GetLength() > 0)
				{
					if (FindEntity("target", str.GetBuffer(0)))
					{
						if (!mapStr.Lookup(str, strKey))
						{
							UniqueTargetName(strKey);
							mapStr.SetAt(str, strKey);
						}
						strTarget = strKey;
						SetKeyValue(ent, "target", strTarget.GetBuffer(0));
					}
				}
				str = ValueForKey(ent, "targetname");
				if (str.GetLength() > 0)
				{
					if (FindEntity("targetname", str.GetBuffer(0)))
					{
						if (!mapStr.Lookup(str, strKey))
						{
							UniqueTargetName(strKey);
							mapStr.SetAt(str, strKey);
						}
						SetKeyValue(ent, "targetname", strKey.GetBuffer(0));
					}
				}
				//if (strTarget.GetLength() > 0)
				//  SetKeyValue(ent, "target", strTarget.GetBuffer(0));

				// add the entity to the end of the entity list
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;

				for (b=ent->brushes.onext ; b != &ent->brushes ; b=b->onext)
				{
					ptrs.Add(b);
				}
			}
		}
	}

	//::ShowWindow(g_qeglobals.d_hwndEntity, FALSE);
	//::LockWindowUpdate(g_qeglobals.d_hwndEntity);
	g_bScreenUpdates = false; 
	for (int i = 0; i < ptrs.GetSize(); i++)
	{
		Brush_Build(reinterpret_cast<brush_t*>(ptrs[i]), true, false);
		Select_Brush(reinterpret_cast<brush_t*>(ptrs[i]), true, false);
	}
	//::LockWindowUpdate(NULL);
	g_bScreenUpdates = true; 

	ptrs.RemoveAll();

	// reset the "need conversion" flag
	// conversion to the good format done in Map_BuildBrushData
	g_qeglobals.bNeedConvert=false;

	Sys_UpdateWindows (W_ALL);
  //Sys_MarkMapModified();
	modified = true;

	Undo_End();

}
Esempio n. 11
0
/*
================
Map_LoadFile
================
*/
void Map_LoadFile (char *filename)
{
    char		*buf;
	entity_t	*ent;
	char         temp[1024];

	Sys_BeginWait ();
	Select_Deselect();
	//SetInspectorMode(W_CONSOLE);

	QE_ConvertDOSToUnixName( temp, filename );
	Sys_Printf ("Map_LoadFile: %s\n", temp );

	Map_Free ();
	//++timo FIXME: maybe even easier to have Group_Init called from Map_Free?
	Group_Init();

	g_qeglobals.d_parsed_brushes = 0;
	strcpy (currentmap, filename);

	if (LoadFile (filename, (void **)&buf) != -1)
	{

		StartTokenParsing (buf);
		g_qeglobals.d_num_entities = 0;

		// Timo
		// will be used in Entity_Parse to detect if a conversion between brush formats is needed
		g_qeglobals.bNeedConvert = false;
		g_qeglobals.bOldBrushes = false;
		g_qeglobals.bPrimitBrushes = false;

		while (1)
		{
			ent = Entity_Parse (false, &active_brushes);
			if (!ent)
				break;
			if (!strcmp(ValueForKey (ent, "classname"), "worldspawn"))
			{
				if (world_entity)
					Sys_Printf ("WARNING: multiple worldspawn\n");
				world_entity = ent;
			}
			else if (!strcmp(ValueForKey (ent, "classname"), "group_info"))
      {
        // it's a group thing!
        Group_Add(ent);
        Entity_Free(ent);
      }
      else
			{
				// add the entity to the end of the entity list
				ent->next = &entities;
				ent->prev = entities.prev;
				entities.prev->next = ent;
				entities.prev = ent;
				g_qeglobals.d_num_entities++;
			}
		}
	}

  free (buf);

	if (!world_entity)
	{
		Sys_Printf ("No worldspawn in map.\n");
		Map_New ();
		return;
	}

    Sys_Printf ("--- LoadMapFile ---\n");
    Sys_Printf ("%s\n", temp );

    Sys_Printf ("%5i brushes\n",  g_qeglobals.d_parsed_brushes );
    Sys_Printf ("%5i entities\n", g_qeglobals.d_num_entities);

	Map_RestoreBetween ();

	Sys_Printf ("Map_BuildAllDisplayLists\n");
    Map_BuildBrushData();

	// reset the "need conversion" flag
	// conversion to the good format done in Map_BuildBrushData
	g_qeglobals.bNeedConvert=false;

	//
	// move the view to a start position
	//
  ent = AngledEntity();

  g_pParentWnd->GetCamera()->Camera().angles[PITCH] = 0;
	if (ent)
	{
		GetVectorForKey (ent, "origin", g_pParentWnd->GetCamera()->Camera().origin);
		GetVectorForKey (ent, "origin", g_pParentWnd->GetXYWnd()->GetOrigin());
		g_pParentWnd->GetCamera()->Camera().angles[YAW] = FloatForKey (ent, "angle");
	}
	else
	{
		g_pParentWnd->GetCamera()->Camera().angles[YAW] = 0;
		VectorCopy (vec3_origin, g_pParentWnd->GetCamera()->Camera().origin);
		VectorCopy (vec3_origin, g_pParentWnd->GetXYWnd()->GetOrigin());
	}

	Map_RegionOff ();


	modified = false;
	Sys_SetTitle (temp);

	Texture_ShowInuse ();

	Sys_EndWait();
	Sys_UpdateWindows (W_ALL);

}