⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map_sin.c

📁 quakeIII源码这个不用我多说吧
💻 C
📖 第 1 页 / 共 3 页
字号:
	// in linear order for each entity

	newbrushes = mapent->numbrushes;
	worldbrushes = entities[0].numbrushes;

	temp = malloc(newbrushes*sizeof(mapbrush_t));
	memcpy (temp, mapbrushes + mapent->firstbrush, newbrushes*sizeof(mapbrush_t));

#if	0		// let them keep their original brush numbers
	for (i=0 ; i<newbrushes ; i++)
		temp[i].entitynum = 0;
#endif

	// make space to move the brushes (overlapped copy)
	memmove (mapbrushes + worldbrushes + newbrushes,
		mapbrushes + worldbrushes,
		sizeof(mapbrush_t) * (nummapbrushes - worldbrushes - newbrushes) );

	// copy the new brushes down
	memcpy (mapbrushes + worldbrushes, temp, sizeof(mapbrush_t) * newbrushes);

	// fix up indexes
	entities[0].numbrushes += newbrushes;
	for (i=1 ; i<num_entities ; i++)
		entities[i].firstbrush += newbrushes;
	free (temp);

	mapent->numbrushes = 0;
} //*/

/*
================
ParseMapEntity
================
* /
qboolean	Sin_ParseMapEntity (void)
{
	entity_t	*mapent;
	epair_t		*e;
	side_t		*s;
	int			i, j;
	int			startbrush, startsides;
	vec_t		newdist;
	mapbrush_t	*b;

	if (!GetToken (true))
		return false;

	if (strcmp (token, "{") )
		Error ("ParseEntity: { not found");
	
	if (num_entities == MAX_MAP_ENTITIES)
		Error ("num_entities == MAX_MAP_ENTITIES");

	startbrush = nummapbrushes;
	startsides = nummapbrushsides;

	mapent = &entities[num_entities];
	num_entities++;
	memset (mapent, 0, sizeof(*mapent));
	mapent->firstbrush = nummapbrushes;
	mapent->numbrushes = 0;
//	mapent->portalareas[0] = -1;
//	mapent->portalareas[1] = -1;

	do
	{
		if (!GetToken (true))
			Error ("ParseEntity: EOF without closing brace");
		if (!strcmp (token, "}") )
			break;
		if (!strcmp (token, "{") )
			ParseBrush (mapent);
		else
		{
			e = ParseEpair ();
#ifdef SIN
         //HACK HACK HACK
         // MED Gotta do this here
         if ( !stricmp(e->key, "surfacefile") )
            {
            if (!surfacefile[0])
               {
               strcpy( surfacefile, e->value );
               }
		      printf ("--- ParseSurfaceFile ---\n");
		      printf ("Surface script: %s\n", surfacefile);
		      if (!ParseSurfaceFile(surfacefile))
               {
		         Error ("Script file not found: %s\n", surfacefile);
               }
            }
#endif
			e->next = mapent->epairs;
			mapent->epairs = e;
		}
	} while (1);

#ifdef SIN
    if (!(strlen(ValueForKey(mapent, "origin")))  && ((num_entities-1) != 0))
        {
        mapbrush_t     *brush;
        vec3_t		    origin;
  	    char		    string[32];
        vec3_t          mins, maxs;
        int			    start, end;
        // Calculate bounds

        start = mapent->firstbrush;
	    end = start + mapent->numbrushes;
	    ClearBounds (mins, maxs);

	    for (j=start ; j<end ; j++)
            {
	        brush = &mapbrushes[j];
		    if (!brush->numsides)
			    continue;	// not a real brush (origin brush) - shouldn't happen
		    AddPointToBounds (brush->mins, mins, maxs);
		    AddPointToBounds (brush->maxs, mins, maxs);
            }

        // Set the origin to be the centroid of the entity.
        VectorAdd ( mins, maxs, origin);
		VectorScale( origin, 0.5f, origin );

		sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
		SetKeyValue ( mapent, "origin", string);
//        qprintf("Setting origin to %s\n",string);
        }
#endif

	GetVectorForKey (mapent, "origin", mapent->origin);

#ifdef SIN
	if (
         (!strcmp ("func_areaportal", ValueForKey (mapent, "classname"))) ||
         (!strcmp ("func_group", ValueForKey (mapent, "classname"))) ||
      	(!strcmp ("detail", ValueForKey (mapent, "classname")) && !entitydetails)
      )
      {
      VectorClear( mapent->origin );
      }
#endif

	//
	// if there was an origin brush, offset all of the planes and texinfo
	//
	if (mapent->origin[0] || mapent->origin[1] || mapent->origin[2])
	{
		for (i=0 ; i<mapent->numbrushes ; i++)
		{
			b = &mapbrushes[mapent->firstbrush + i];
			for (j=0 ; j<b->numsides ; j++)
			{
				s = &b->original_sides[j];
				newdist = mapplanes[s->planenum].dist -
					DotProduct (mapplanes[s->planenum].normal, mapent->origin);
				s->planenum = FindFloatPlane (mapplanes[s->planenum].normal, newdist);
#ifdef SIN
				s->texinfo = TexinfoForBrushTexture (&mapplanes[s->planenum],
					&side_brushtextures[s-brushsides], mapent->origin, &side_newrefs[s-brushsides]);
            // 
            // save off lightinfo
            //
            s->lightinfo = LightinfoForBrushTexture (	&side_brushtextures[s-brushsides] );
#else
				s->texinfo = TexinfoForBrushTexture (&mapplanes[s->planenum],
					&side_brushtextures[s-brushsides], mapent->origin);
#endif
			}
			MakeBrushWindings (b);
		}
	}

	// group entities are just for editor convenience
	// toss all brushes into the world entity
	if (!strcmp ("func_group", ValueForKey (mapent, "classname")))
	{
		MoveBrushesToWorld (mapent);
		mapent->numbrushes = 0;
		mapent->wasdetail = true;
      FreeValueKeys( mapent );
		return true;
	}
#ifdef SIN
	// detail entities are just for editor convenience
	// toss all brushes into the world entity as detail brushes
	if (!strcmp ("detail", ValueForKey (mapent, "classname")) && !entitydetails)
	{
		for (i=0 ; i<mapent->numbrushes ; i++)
		{
         int j;
         side_t * s;
			b = &mapbrushes[mapent->firstbrush + i];
   	   if (nodetail)
            {
            b->numsides = 0;
            continue;
            }
         if (!fulldetail)
            {
   	      // set the contents for the entire brush
	         b->contents |= CONTENTS_DETAIL;
			   // set the contents in the sides as well
			   for (j=0, s=b->original_sides ; j<b->numsides ; j++,s++)
		   	   {
               s->contents |= CONTENTS_DETAIL;
	   	   	}
            }
         else
            {
   	      // set the contents for the entire brush
	         b->contents |= CONTENTS_SOLID;
			   // set the contents in the sides as well
			   for (j=0, s=b->original_sides ; j<b->numsides ; j++,s++)
		   	   {
               s->contents |= CONTENTS_SOLID;
	   	   	}
            }
		}
		MoveBrushesToWorld (mapent);
		mapent->wasdetail = true;
      FreeValueKeys( mapent );
      // kill off the entity
   	// num_entities--;
		return true;
	}
#endif

	// areaportal entities move their brushes, but don't eliminate
	// the entity
	if (!strcmp ("func_areaportal", ValueForKey (mapent, "classname")))
	{
		char	str[128];

		if (mapent->numbrushes != 1)
			Error ("Entity %i: func_areaportal can only be a single brush", num_entities-1);

		b = &mapbrushes[nummapbrushes-1];
		b->contents = CONTENTS_AREAPORTAL;
		c_areaportals++;
		mapent->areaportalnum = c_areaportals;
		// set the portal number as "style"
		sprintf (str, "%i", c_areaportals);
		SetKeyValue (mapent, "style", str);
		MoveBrushesToWorld (mapent);
		return true;
	}

	return true;
} //end of the function Sin_ParseMapEntity */

//===================================================================

/*
================
LoadMapFile
================
* /
void Sin_LoadMapFile (char *filename)
{		
	int		i;
#ifdef SIN
   int num_detailsides=0;
   int num_detailbrushes=0;
   int num_worldsides=0;
   int num_worldbrushes=0;
   int      j,k;
#endif

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

	LoadScriptFile (filename);

	nummapbrushsides = 0;
	num_entities = 0;
	
	while (ParseMapEntity ())
	{
	}

	ClearBounds (map_mins, map_maxs);
	for (i=0 ; i<entities[0].numbrushes ; i++)
	{
		if (mapbrushes[i].mins[0] > 4096)
			continue;	// no valid points
		AddPointToBounds (mapbrushes[i].mins, map_mins, map_maxs);
		AddPointToBounds (mapbrushes[i].maxs, map_mins, map_maxs);
	}
#ifdef SIN
   for (j=0;  j<num_entities; j++)
      {
	   for (i=0 ; i<entities[j].numbrushes ; i++)
	      {
         side_t * s;
         mapbrush_t *b;
			b = &mapbrushes[entities[j].firstbrush + i];
         if (b->numsides && b->contents & CONTENTS_DETAIL)
            num_detailbrushes++;
         else if (b->numsides)
            num_worldbrushes++;
			for (k=0, s=b->original_sides ; k<b->numsides ; k++,s++)
			   {
            if (s->contents & CONTENTS_DETAIL)
               num_detailsides++;
            else
               num_worldsides++;
			   }
   	   }
      }
#endif

	qprintf ("%5i brushes\n", nummapbrushes);
	qprintf ("%5i clipbrushes\n", c_clipbrushes);
	qprintf ("%5i total sides\n", nummapbrushsides);
	qprintf ("%5i boxbevels\n", c_boxbevels);
	qprintf ("%5i edgebevels\n", c_edgebevels);
	qprintf ("%5i entities\n", num_entities);
	qprintf ("%5i planes\n", nummapplanes);
	qprintf ("%5i areaportals\n", c_areaportals);
	qprintf ("size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0],map_mins[1],map_mins[2],
		map_maxs[0],map_maxs[1],map_maxs[2]);
#ifdef SIN
	qprintf ("%5i detailbrushes\n", num_detailbrushes);
	qprintf ("%5i worldbrushes\n", num_worldbrushes);
	qprintf ("%5i detailsides\n", num_detailsides);
	qprintf ("%5i worldsides\n", num_worldsides);
#endif

} //end of the function Sin_LoadMap */


#ifdef ME		//Begin MAP loading from BSP file
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void Sin_CreateMapTexinfo(void)
{
	int i;
	vec_t defaultvec[4] = {1, 0, 0, 0};

	memcpy(map_texinfo[0].vecs[0], defaultvec, sizeof(defaultvec));
	memcpy(map_texinfo[0].vecs[1], defaultvec, sizeof(defaultvec));
	map_texinfo[0].flags = 0;
	map_texinfo[0].value = 0;
	strcpy(map_texinfo[0].texture, "generic/misc/red");	//no texture
	map_texinfo[0].nexttexinfo = -1;
	for (i = 1; i < sin_numtexinfo; i++)
	{
		memcpy(map_texinfo[i].vecs, sin_texinfo[i].vecs, sizeof(float) * 2 * 4);
		map_texinfo[i].flags = sin_texinfo[i].flags;
		map_texinfo[i].value = 0;
		strcpy(map_texinfo[i].texture, sin_texinfo[i].texture);
		map_texinfo[i].nexttexinfo = -1;
	} //end for
} //end of the function Sin_CreateMapTexinfo
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void Sin_SetLeafBrushesModelNumbers(int leafnum, int modelnum)
{
	int i, brushnum;
	sin_dleaf_t *leaf;

	leaf = &sin_dleafs[leafnum];
	for (i = 0; i < leaf->numleafbrushes; i++)
	{
		brushnum = sin_dleafbrushes[leaf->firstleafbrush + i];
		brushmodelnumbers[brushnum] = modelnum;
		dbrushleafnums[brushnum] = leafnum;
	} //end for
} //end of the function Sin_SetLeafBrushesModelNumbers
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void Sin_InitNodeStack(void)
{
	nodestackptr = nodestack;
	nodestacksize = 0;
} //end of the function Sin_InitNodeStack
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void Sin_PushNodeStack(int num)
{
	*nodestackptr = num;
	nodestackptr++;
	nodestacksize++;
	//
	if (nodestackptr >= &nodestack[NODESTACKSIZE])
	{
		Error("Sin_PushNodeStack: stack overflow\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -