Example #1
0
void AssignSound()
{
  CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
  AddSlash(strBasePath);
  CString strPath = strBasePath;
  strPath += "sound\\";

  CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Sound files (*.wav,*.mp3)|*.wav;*.mp3||", g_pParentWnd);
  dlgFile.m_ofn.lpstrInitialDir = strPath;
  if (dlgFile.DoModal() == IDOK)
  {
	  SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"noise");	
    CString str = dlgFile.GetPathName().GetBuffer(0);
    str.MakeLower();
    strBasePath.MakeLower();
    QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
    QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
    int n = str.Find(strBasePath);
    if (n == 0)
    {
      str = str.Right(str.GetLength() - strBasePath.GetLength());
    }

	  SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));	
    AddProp();
    g_pParentWnd->GetXYWnd()->SetFocus();
  }
}
Example #2
0
int QERApp_EClassScanDir( const char *path, void* hPlug ){
	char temp[NAME_MAX];
	char filebase[NAME_MAX];
	char filename[NAME_MAX];
	char          *s;
	eclass_t      *e;
	DIR           *dir;
	struct dirent *dirlist;

	QE_ConvertDOSToUnixName( temp, path );
	strcpy( filebase, path );
	s = filebase + strlen( filebase ) - 1;
	while ( *s != '\\' && *s != '/' && s != filebase )
		s--;
	*s = 0;

	dir = opendir( path );
	if ( dir != NULL ) {
		while ( ( dirlist = readdir( dir ) ) != NULL )
		{
			sprintf( filename, "%s/%s", filebase, dirlist->d_name );
			Eclass_ScanFile( filename );

			if ( eclass_found ) {
				e = eclass_e;
				e->modelpath = strdup( dirlist->d_name );
				e->nShowFlags |= ECLASS_PLUGINENTITY;
				e->hPlug = hPlug;
			}
		}
		closedir( dir );
	}
	return 0;
}
Example #3
0
void Eclass_InitForSourceDirectory (char *path)
{
	struct _finddata_t fileinfo;
	int		handle;
	char	filename[1024];
	char	filebase[1024];
	char    temp[1024];
	char	*s;

	QE_ConvertDOSToUnixName( temp, path );

	Sys_Printf ("Eclass_InitForSourceDirectory: %s\n", temp );

	strcpy (filebase, path);
	s = filebase + strlen(filebase)-1;
	while (*s != '\\' && *s != '/' && s!=filebase)
		s--;
	*s = 0;

	eclass = NULL;

	handle = _findfirst (path, &fileinfo);
	if (handle != -1)
	{
		do
		{
			sprintf (filename, "%s\\%s", filebase, fileinfo.name);
			Eclass_ScanFile (filename);
		} while (_findnext( handle, &fileinfo ) != -1);

		_findclose (handle);
	}

	eclass_bad = Eclass_InitFromText ("/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?");
}
Example #4
0
/*
=================
Eclass_ScanFile
=================
*/
void Eclass_ScanFile (char *filename)
{
	int		size;
	char	*data;
	eclass_t	*e;
	int		i;
	char    temp[1024];

	QE_ConvertDOSToUnixName( temp, filename );

	Sys_Printf ("ScanFile: %s\n", temp);

	size = LoadFile (filename, (void *)&data);

	for (i=0 ; i<size ; i++)
		if (!strncmp(data+i, "/*QUAKED",8))
		{
			e = Eclass_InitFromText (data+i);
			if (e)
				Eclass_InsertAlphabetized (e);
			else
				printf ("Error parsing: %s in %s\n",debugname, filename);
		}

	free (data);
}
Example #5
0
void BuildWadList( char *wadstr ){
	char wads[2048]; // change to CString usage ?
	wads[0] = 0;
	char *p1,*p2;
	char cleanwadname[QER_MAX_NAMELEN];

	g_WadList = NULL;

	strcpy( wads,wadstr );
	QE_ConvertDOSToUnixName( wads,wads );

	// ok, we got the list of ; delimited wads, now split it into a GSList that contains
	// just the wad names themselves.

	p1 = wads;

	do
	{
		p2 = strchr( p1,';' );
		if ( p2 ) {
			*p2 = 0; // swap the ; with a null terminator

		}
		if ( strchr( p1,'/' ) || strchr( p1,'\\' ) ) {
			ExtractFileName( p1,cleanwadname );

			trim( cleanwadname );

			if ( *cleanwadname ) {
				g_WadList = g_slist_append( g_WadList, strdup( cleanwadname ) );
				Sys_Printf( "wad: %s\n",cleanwadname );
			}
		}
		else
		{
			trim( p1 );
			if ( *p1 ) {
				g_WadList = g_slist_append( g_WadList, strdup( p1 ) );
				Sys_Printf( "wad: %s\n",p1 );
			}
		}
		if ( p2 ) {
			p1 = p2 + 1; // point back to the remainder of the string
		}
		else{
			p1 = NULL; // make it so we exit the loop.

		}
	} while ( p1 );

	// strip the ".wad" extensions.
	for ( GSList *l = g_WadList; l != NULL ; l = l->next )
	{
		p1 = (char *)l->data;

		if ( p1[strlen( p1 ) - 4] == '.' ) {
			p1[strlen( p1 ) - 4] = 0;
		}
	}
}
Example #6
0
//
//===========
//Map_SaveSelected
//===========
//
// Saves selected world brushes and whole entities with partial/full selections
//
void Map_SaveSelected(char* pFilename)
{
	entity_t	*e, *next;
	FILE *f;
	char temp[1024];
	int count;

	QE_ConvertDOSToUnixName(temp, pFilename);
	f = fopen(pFilename, "w");

	if (!f)
	{
		Sys_Printf ("ERROR!!!! Couldn't open %s\n", pFilename);
		return;
	}

	// write world entity first
	Entity_WriteSelected(world_entity, f);

	// then write all other ents
	count = 1;
	for (e=entities.next ; e != &entities ; e=next)
	{
  	fprintf (f, "// entity %i\n", count);
   	count++;
 		Entity_WriteSelected(e, f);
		next = e->next;
	}
	fclose (f);
}
Example #7
0
// clean a texture name to the qtexture_t name format we use internally
// NOTE: there are so many cases .. this may need to get updated to cover all of them
// we expect a "textures/" path on top, except if bAddTexture is set to true .. in case we add in needed
// NOTE: case sensitivity: the engine is case sensitive. we store the shader name with case information and save with case
// information as well. but we assume there won't be any case conflict and so when doing lookups based on shader name,
// we compare as case insensitive. That is Radiant is case insensitive, but knows that the engine is case sensitive.
//++timo FIXME: we need to put code somewhere to detect when two shaders that are case insensitive equal are present
char* CleanTextureName(const char* name, bool bAddTexture)
{
  static char stdName[QER_MAX_NAMELEN];
  strcpy( stdName, name );
  QE_ConvertDOSToUnixName( stdName, stdName );
  if (stdName[strlen(name)-4] == '.')
  // strip extension
  stdName[strlen(stdName)-4] = '\0';
  // check we have "textures/"
  char *cut = strstr( stdName, "textures/" );
  if (!cut)
	{
		if (bAddTexture)
		{
#if 0
			Sys_Printf("CleanTextureName: adding \"texture/\" to %s\n", stdName );
#endif
			char aux[QER_MAX_NAMELEN];
			sprintf( aux, "textures/%s", stdName );
			strcpy( stdName, aux );
		}
#if 0
		else
		{
			Sys_Printf("WARNING: \"textures/\" not found in CleanTextureName\n");
		}
#endif
	}
  return stdName;
}
Example #8
0
void Sys_MarkMapModified( void ){
	char title[PATH_MAX];

	if ( modified != 1 ) {
		modified = true; // mark the map as changed
		sprintf( title, "%s *", currentmap );

		QE_ConvertDOSToUnixName( title, title );
		Sys_SetTitle( title );
	}
}
Example #9
0
// this is a modified version of Texture_ForName
qtexture_t* WINAPI QERApp_TryTextureForName( const char* name )
{
	qtexture_t* q;
	char filename[1024];
	for ( q = g_qeglobals.d_qtextures ; q ; q = q->next )
	{
		if ( !strcmp( name,  q->filename ) )
			return q;
	}
	// try loading from file .. this is a copy of the worst part of Texture_ForName
	char cWork[1024];
	sprintf( filename, "%s/%s.tga", ValueForKey( g_qeglobals.d_project_entity, "texturepath" ), name );
	QE_ConvertDOSToUnixName( cWork, filename );
	strcpy( filename, cWork );
	unsigned char* pPixels = NULL;
	int nWidth;
	int nHeight;
	LoadImage( filename, &pPixels, &nWidth, &nHeight );
	if ( pPixels == NULL )
	{
		// try jpg
		// blatant assumption of .tga should be fine since we sprintf'd it above
		int nLen = strlen( filename );
		filename[nLen - 3] = 'j';
		filename[nLen - 2] = 'p';
		filename[nLen - 1] = 'g';
		LoadImage( filename, &pPixels, &nWidth, &nHeight );;
		if ( pPixels == NULL )
		{
			// try png
			// blatant assumption of .tga should be fine since we sprintf'd it above
			int nLen = strlen( filename );
			filename[nLen - 3] = 'p';
			filename[nLen - 2] = 'n';
			filename[nLen - 1] = 'g';
			LoadImage( filename, &pPixels, &nWidth, &nHeight );
		}
	}
	if ( pPixels )
	{
		q = Texture_LoadTGATexture( pPixels, nWidth, nHeight, NULL, 0, 0, 0 );
		//++timo storing the filename .. will be removed by shader code cleanup
		// this is dirty, and we sure miss some places were we should fill the filename info
		strcpy( q->filename, name );
		SetNameShaderInfo( q, filename, name );
		Sys_Printf( "done.\n", name );
		free( pPixels );
		return q;
	}
	return NULL;
}
Example #10
0
void Eclass_InitForSourceDirectory (char *path)
{
	struct _finddata_t fileinfo;
	int		handle;
	char	filename[1024];
	char	filebase[1024];
	char    temp[1024];
	char	*s;

	QE_ConvertDOSToUnixName( temp, path );

	Sys_Printf ("Eclass_InitForSourceDirectory: %s\n", temp );

	strcpy (filebase, path);
	s = filebase + strlen(filebase)-1;
	while (*s != '\\' && *s != '/' && s!=filebase)
		s--;
	*s = 0;

	CleanUpEntities();
	eclass = NULL;
	//#ifdef BUILD_LIST
	if (g_bBuildList)
		strDefFile = "";
	//#endif
	handle = _findfirst (path, &fileinfo);
	if (handle != -1)
	{
		do
		{
			sprintf (filename, "%s\\%s", filebase, fileinfo.name);
			Eclass_ScanFile (filename);
		} while (_findnext( handle, &fileinfo ) != -1);

		_findclose (handle);
	}

	//#ifdef BUILD_LIST
	if (g_bBuildList)
	{
		CFile file;
		if (file.Open("c:\\entities.def", CFile::modeCreate | CFile::modeWrite)) 
		{
			file.Write(strDefFile.GetBuffer(0), strDefFile.GetLength());
			file.Close();
		}
	}
	//#endif

	eclass_bad = Eclass_InitFromText ("/*QUAKED UNKNOWN_CLASS (0 0.5 0) ?");
}
Example #11
0
//#endif
void Eclass_ScanFile (char *filename)
{
	int		size;
	char	*data;
	eclass_t	*e;
	int		i;
	char    temp[1024];

	QE_ConvertDOSToUnixName( temp, filename );

	Sys_Printf ("ScanFile: %s\n", temp);

	// BUG
	size = LoadFile (filename, (void**)&data);
	eclass_found = false;
	for (i=0 ; i<size ; i++)
		if (!strncmp(data+i, "/*QUAKED",8))
		{

			//#ifdef BUILD_LIST
			if (g_bBuildList)
			{
				CString strDef = "";
				int j = i;
				while (1)
				{
					strDef += *(data+j);
					if (*(data+j) == '/' && *(data+j-1) == '*')
						break;
					j++;
				}
				strDef += "\r\n\r\n\r\n";
				strDefFile += strDef;
			}
			//#endif
			e = Eclass_InitFromText (data+i);
			if (e)
				Eclass_InsertAlphabetized (e);
			else
				printf ("Error parsing: %s in %s\n",debugname, filename);

			// single ?
			eclass_e = e;
			eclass_found = true;
			if ( parsing_single )
				break;
		}

		free (data);		
}
Example #12
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);
	}	
}
Example #13
0
//
//================
//Map_ImportFile
//================
//
void Map_ImportFile (char *filename)
{
  char* buf;
	char temp[1024];
	Sys_BeginWait ();
	QE_ConvertDOSToUnixName( temp, filename );
  if (LoadFile (filename, (void **)&buf) != -1)
  {
    Map_ImportBuffer(buf);
    free(buf);
    Map_BuildBrushData();
  }
	Sys_UpdateWindows (W_ALL);
	modified = true;
	Sys_EndWait();
}
Example #14
0
void Brush_Build( brush_t *b )
{
	char	title[1024];

	if(modified != 1)
	{
		modified = true;	// mark the map as changed
		sprintf (title, "%s *", currentmap);

		QE_ConvertDOSToUnixName(title,title);
		Sys_SetTitle(title);
	}

	/*
	** build the windings and generate the bounding box
	*/
	Brush_BuildWindings( b );

	// Move the points and edges if in select mode
	if(g_qeglobals.d_select_mode == sel_vertex || g_qeglobals.d_select_mode == sel_edge)
		SetupVertexSelection ();
}
Example #15
0
// is Eclass_InitForModelDirectory
int WINAPI QERApp_EClassScanDir( char *path, HMODULE hPlug )
{
	struct _finddata_t	fileinfo;
	int					handle;
	char				temp[ _MAX_PATH ];
	char				filebase[ _MAX_PATH ];
	char				filename[ _MAX_PATH ];
	char				*s;
	eclass_t			*e;
	QE_ConvertDOSToUnixName( temp, path );
	strcpy (filebase, path);
	s = filebase + strlen(filebase)-1;
	while (*s != '\\' && *s != '/' && s!=filebase)
		s--;
	*s = 0;
	handle = _findfirst (path, &fileinfo);
	if (handle != -1)
	   {
		do
		{			
			sprintf (filename, "%s\\%s", filebase, fileinfo.name);
			Eclass_ScanFile (filename);
			
			if (eclass_found)
            {
				e = eclass_e;
				e->modelpath = strdup( fileinfo.name );
				e->nShowFlags |= ECLASS_PLUGINENTITY;
				e->hPlug = hPlug;
            }
		} while (_findnext( handle, &fileinfo ) != -1);
		
		_findclose (handle);
	   }
	return 0;
}
Example #16
0
qtexture_t* WINAPI QERApp_Try_Texture_ForName(const char* name)
{
	qtexture_t *q;
	char f1[1024],f2[1024];
	unsigned char *pPixels = NULL;
	int nWidth,nHeight;

  // convert the texture name to the standard format we use in qtexture_t
  char *stdName = CleanTextureName(name);

  // use the hash table
  q = NULL;
  g_qeglobals.d_qtexmap->Lookup( stdName, (void *&)q );
  if (q)
    return q;
#ifdef QTEXMAP_DEBUG
  for (q=g_qeglobals.d_qtextures ; q ; q=q->next)
	{
		if (!strcmp(stdName,  q->name))
    {
      Sys_Printf("ERROR: %s is not in texture map, but was found in texture list\n");
			return q;
    }
	}
#endif
#if 0
  for (q=g_qeglobals.d_qtextures ; q ; q=q->next)
	{
		if (!strcmp(stdName,  q->name))
				return q;
	}
#endif
	//++timo TODO: say something about loading the file?
	// try loading the texture
	//++timo FIXME: "texturepath" is no use now?
	sprintf(f1, "%s/%s", ValueForKey (g_qeglobals.d_project_entity, "basepath"), name);
	QE_ConvertDOSToUnixName( f2, f1 );
	// NOTE: we may need a global strategy to support default extensions etc.
	strcpy(f1,f2);
	// check wether a filename extension was provided
	// NOTE: only works for 3 letters extensions ( .tga .jpg ... )
	if (f1[strlen(f1)-4] == '.')
	{
		// try straight loading
		LoadImage( f1, &pPixels, &nWidth, &nHeight );
	}
	if (!pPixels)
	{
		// try adding extensions, .tga first
		sprintf(f2,"%s.tga",f1);
		LoadImage( f2, &pPixels, &nWidth, &nHeight );
		if (!pPixels)
		{
			// .jpg
			sprintf(f2,"%s.jpg",f1);
			LoadImage( f2, &pPixels, &nWidth, &nHeight );
		}
	}
	if (!pPixels)
		// we failed
		return NULL;
	else
	{
		// TODO: display .pk3 file name if loaded from .pk3 (needs to write a VFS .. sort of)
		Sys_Printf("LOADED: %s\n", f2 );
	}
	// instanciate a new qtexture_t
	// NOTE: when called by a plugin we must make sure we have set Radiant's GL context before binding the texture

	// we'll be binding the GL texture now
	// need to check we are using a right GL context
	// with GL plugins that have their own window, the GL context may be the plugin's, in which case loading textures will bug
	HDC currentHDC = qwglGetCurrentDC();
	HGLRC currentHGLRC = qwglGetCurrentContext();
	//++timo FIXME: this may duplicate with qtexture_t* WINAPI QERApp_Texture_ForName (const char *name)
	//++timo FIXME: we need a list of lawfull GL contexts or something?
	// I'd rather always use the same GL context for binding...
	if (currentHDC != g_qeglobals.d_hdcBase || currentHGLRC != g_qeglobals.d_hglrcBase)
	{
#ifdef _DEBUG
		Sys_Printf("Switching context!\n");
#endif
		qwglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase );
	}

	//++timo TODO: remove that and use our own implementation?
	q = Texture_LoadTGATexture( pPixels, nWidth, nHeight, NULL, 0, 0, 0);
	free(pPixels);
	// fill qtexture_t information
	//++timo FIXME: filename will be removed .. name for qtexture_t is actually the filename now
  // NOTE: see qtexture_s::name for naming conventions, must remove filename extension
	strcpy( q->filename, name );
	strcpy( q->name, name );
	// only strip extension if extension there is!
	if (q->name[strlen(q->name)-4] == '.')
		q->name[strlen(q->name)-4]='\0';
	// hook into the main qtexture_t list
	q->next = g_qeglobals.d_qtextures;
	g_qeglobals.d_qtextures = q;
  // push it in the map
  g_qeglobals.d_qtexmap->SetAt( q->name, q );

	return q;
}
Example #17
0
/*
===========
Map_SaveFile
===========
*/
void Map_SaveFile (char *filename, qboolean use_region )
{
	entity_t	*e, *next;
	FILE		*f;
	char         temp[1024];
	int			count;

  if (filename == NULL || strlen(filename) == 0)
  {
    CFileDialog dlgSave(FALSE, "map", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Map Files (*.map)|*.map||", AfxGetMainWnd());
    if (dlgSave.DoModal() == IDOK)
      filename = strdup(dlgSave.m_ofn.lpstrFile);
    else 
      return;
  }

	Pointfile_Clear ();
	QE_ConvertDOSToUnixName( temp, filename );

	if (!use_region)
	{
		char	backup[1024];

		// rename current to .bak
		strcpy (backup, filename);
		StripExtension (backup);
		strcat (backup, ".bak");
		_unlink (backup);
		rename (filename, backup);
	}

	Sys_Printf ("Map_SaveFile: %s\n", filename);

	f = fopen(filename, "w");

	if (!f)
	{
		Sys_Printf ("ERROR!!!! Couldn't open %s\n", filename);
		return;
	}

	if (use_region)
  {
		AddRegionBrushes ();
  }

	// write world entity first
	Entity_Write (world_entity, f, use_region);

	// then write all other ents
	count = 1;
	for (e=entities.next ; e != &entities ; e=next)
	{
		next = e->next;
		if (e->brushes.onext == &e->brushes)
    {
			Entity_Free (e);	// no brushes left, so remove it
    }
		else
    {
	   	fprintf (f, "// entity %i\n", count);
	  	count++;
			Entity_Write (e, f, use_region);
    }
	}

	// save the group info stuff
	Group_Save(f);

	fclose (f);

	if (use_region)
		RemoveRegionBrushes ();

	Sys_Printf ("Saved.\n");
	modified = false;

	if ( !strstr( temp, "autosave" ) )
		Sys_SetTitle (temp);

	if (!use_region)
	{
		time_t	timer;
		FILE	*f;

		time (&timer);
		MessageBeep (MB_ICONEXCLAMATION);
		f = fopen ("c:/tstamps.log", "a");
		if (f)
		{
			fprintf (f, "%s", filename);
			//fprintf (f, "%4i : %35s : %s", g_qeglobals.d_workcount, filename, ctime(&timer));
			fclose (f);
			g_qeglobals.d_workcount = 0;
		}
		fclose (f);
		Sys_Status ("Saved.\n", 0);
	}
	
  //Curve_WriteFile (filename);		//.trinity
  //Patch_WriteFile (filename);
}
Example #18
0
void QE_ExpandBspString( char* bspaction, char* out, char* mapname, bool useTemps )
{
	char*   in;
	char    src[2048];
	char    rsh[2048];
	char    base[2048];
	const char* basePath;
	const char* modDir;
	
	strcpy( src, mapname );
	strlwr( src );
	in = strstr( src, "maps/" );
	if ( !in )
	{
		in = strstr( src, "maps\\" );
	}
	if ( in )
	{
		in += 5;
		strcpy( base, in );
		in = base;
		while ( *in )
		{
			if ( *in == '\\' )
			{
				*in = '/';
			}
			in++;
		}
	}
	else
	{
		ExtractFileName( mapname, base );
	}
	
	if ( useTemps )
	{
		CString str;
		CString strExt = "map";
		if ( strstr( mapname, ".reg" ) )
		{
			strExt = "reg";
		}
		str.Format( "%s/maps/%i.%s", ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ), ::GetTickCount(), strExt );
		CopyFile( mapname, str, FALSE );
		sprintf( src, "-tempname %s %s/maps/%s", str, ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ), base );
	}
	else
	{
		sprintf( src, "%s/maps/%s", ValueForKey( g_qeglobals.d_project_entity, "remotebasepath" ), base );
	}
	strcpy( rsh, ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ) );
	
	QE_ConvertDOSToUnixName( src, src );
	
	in = ValueForKey( g_qeglobals.d_project_entity, bspaction );
	basePath = ValueForKey( g_qeglobals.d_project_entity, "basepath" );
	modDir = ValueForKey( g_qeglobals.d_project_entity, "moddir" );
	if ( modDir[0] == '/' || modDir[0] == '\\' )
		modDir++;
	while ( *in )
	{
		if ( in[0] == '!' )
		{
			strcpy( out, rsh );
			out += strlen( rsh );
			in++;
			continue;
		}
		if ( in[0] == '$' )
		{
			strcpy( out, "-gamedir " );
			out += strlen( "-gamedir " );
			strcpy( out, basePath );
			out += strlen( basePath );
			//strcpy(out,modDir);
			//out += strlen(modDir);
			
			*out = ' ';
			out++;
			strcpy( out, src );
			out += strlen( src );
			in++;
			continue;
		}
		if ( in[0] == '@' )
		{
			*out++ = '"';
			in++;
			continue;
		}
		*out++ = *in++;
	}
	*out = 0;
}
Example #19
0
void AssignModel()
{
#ifdef QUAKE3
	if (strASSIGNMODEL.GetLength())
	{
		SendMessage(hwndEnt[EntKeyField],	WM_SETTEXT, 0, (LPARAM)"model");
		SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM) ((LPCSTR)strASSIGNMODEL));//.GetBuffer(0));	
		strASSIGNMODEL="";		
		gEntityToSetBoundsOf = edit_entity;
		AddProp();
		edit_entity->md3Class = NULL;
		g_pParentWnd->GetXYWnd()->SetFocus();

//-----------
#if 1
		// brush is currently built at 0 angle, now fake a rotate away and back to fill inthe mins/maxs fields...
		//
		SetKeyValue(edit_entity, "angle", "0",	false);	// tell it that it has no angle, and don't rebuild
		SetFocus (g_qeglobals.d_hwndCamera);
		SetKeyValuePairs ();

		SetKeyValue(edit_entity, "angle", "90",	true);	// true = rebuild brush, rotate to some other angle
		SetFocus (g_qeglobals.d_hwndCamera);
		SetKeyValuePairs ();


		SetKeyValue(edit_entity, "angle", "0",	true);	// true = rebuild brush, rotate back to 0
		SetFocus (g_qeglobals.d_hwndCamera);
		SetKeyValuePairs ();
#endif
//-----------
	}
	else	
#endif
	{
	  CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
	  AddSlash(strBasePath);
	  CString strPath = strBasePath;
	  strPath += "models\\mapobjects\\";

	  CFileDialog dlgFile(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT, "Model files (*.md3)|*.md3||", g_pParentWnd);
	  dlgFile.m_ofn.lpstrInitialDir = strPath;
	  if (dlgFile.DoModal() == IDOK)
	  {
		  SendMessage(hwndEnt[EntKeyField], WM_SETTEXT, 0, (LPARAM)"model");
		CString str = dlgFile.GetPathName().GetBuffer(0);
		str.MakeLower();
		strBasePath.MakeLower();
		QE_ConvertDOSToUnixName(str.GetBuffer(0), str.GetBuffer(0));
		QE_ConvertDOSToUnixName(strBasePath.GetBuffer(0), strBasePath.GetBuffer(0));
		int n = str.Find(strBasePath);
		if (n == 0)
		{
		  str = str.Right(str.GetLength() - strBasePath.GetLength());
		}

		SendMessage(hwndEnt[EntValueField], WM_SETTEXT, 0, (LPARAM)str.GetBuffer(0));	
		gEntityToSetBoundsOf = edit_entity;
		AddProp();
		edit_entity->md3Class = NULL;
		g_pParentWnd->GetXYWnd()->SetFocus();
	  }
	}
}
Example #20
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 );
	}

}
Example #21
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);

}