コード例 #1
0
void SrvrMergeOverlappingWalls( uint32_t client_id, INDEX iWorld, PORTHOAREA rect )
{
	// for all walls - find a wall without a mate in the rect area...
	// then for all remaining walls - find another wall that is the 
	// same line as this one....
	GETWORLD(iWorld);

	int nwalls, n;
	PWALL *wallarray;
	wallarray = GetLinearWallArray( world->walls, &nwalls );
	for( n = 0; n < nwalls; n++ )
	{
		_POINT start, end;
		PWALL wall = wallarray[n];
		if( wall->iWallInto == INVALID_INDEX )
		{
			PFLATLAND_MYLINESEG line = GetLine( wall->iLine );
			addscaled( start, line->r.o, line->r.n, line->dFrom );
			addscaled( end, line->r.o, line->r.n, line->dTo );
			if( PointInRect( start, rect ) &&
			    PointInRect( end, rect ) )
			{
				int m;
				for( m = n+1; m < nwalls; m++ )
				{
					PWALL wall2 = wallarray[m];
					if( wall2->iWallInto == INVALID_INDEX )
					{
						_POINT start2, end2;
						PFLATLAND_MYLINESEG line = GetLine( wall2->iLine );
						addscaled( start2, line->r.o, line->r.n, line->dFrom );
						addscaled( end2, line->r.o, line->r.n, line->dTo );
						/*
						if( PointInRect( start2, rect ) && 
							 PointInRect( end2, rect ) )
						{
							Log4( "starts: (%12.12g,%12.12g) vs (%12.12g,%12.12g)" 
										,start[0], start[1]
										,start2[0], start2[1] );
							Log4( "ends  : (%12.12g,%12.12g) vs (%12.12g,%12.12g)" 
										,end[0], end[1]
										,end2[0], end2[1] );
						}
						*/
						if( ( Near( start2, start ) &&
						      Near( end2, end ) ) 
						  ||( Near( start2, end ) &&
						      Near( end2, start ) ) )
						{
							SrvrMergeWalls( client_id, iWorld, GetWallIndex( wall ), GetWallIndex( wall2 ) );
							break;
						}

					}
				}
			}
		}	
	}
	Release( wallarray );
}
コード例 #2
0
int CPROC CheckWallInRect( uint32_t client_id, PWALL wall, PGROUPWALLSELECTINFO psi )
{
	GETWORLD(psi->iWorld);
	_POINT p1, p2;
	PORTHOAREA rect = psi->rect; // shorter pointer
	if( wall->iLine == INVALID_INDEX )
	{
		PSECTOR sector = GetSector( wall->iSector );
   		Log( "Line didn't exist..." );
   		if( sector )
		{
			PNAME name = GetName( sector->iName );
   			Log( "Sector exists..." );
   			if( name &&
				name[0].name )
		   		Log1( "Wall in Sector %s does not have a line", name[0].name );
			else
				Log( "Sector referenced does not have a name" );
		}
		else
			Log( "Wall should not be active... WHY is it?!" );
   }
   else
   {
		PFLATLAND_MYLINESEG line = GetLine( wall->iLine );
		addscaled( p1, line->r.o, line->r.n, line->dFrom );
		addscaled( p2, line->r.o, line->r.n, line->dTo );
		if( !PointInRect( p1, rect) ||
	   	 !PointInRect( p2, rect) )
		{
			return 0;
		}
   		else
		{
			if( psi->ppwalls )
			{
				psi->ppwalls[psi->nwalls++] = GetWallIndex( wall );
				SrvrBalanceALine( client_id, psi->iWorld, wall->iLine );
			}
			else
				psi->nwalls++;
		}
	}
	return 0; // abort immediate...
}
コード例 #3
0
INDEX CPROC CheckSectorInRect( INDEX sector, PSECTORSELECTINFO psi )
{
	PORTHOAREA rect = psi->rect;
	INDEX pStart, pCur;
	int priorend = TRUE;
	_POINT p;
   //GETWORLD( psi->iWorld );
	pCur = pStart = GetFirstWall( psi->iWorld, sector, &priorend );
	do
	{
		PFLATLAND_MYLINESEG line;
		GetLineData( psi->iWorld, GetWallLine( psi->iWorld, pCur ), &line );
		if( priorend )
		{
			addscaled( p, line->r.o, line->r.n, line->dTo );
		}
		else
		{
			addscaled( p, line->r.o, line->r.n, line->dFrom );
		}
		//Log7( "Checking (%g,%g) vs (%g,%g)-(%g,%g)", 
		if( p[0] < (rect->x) ||
		    p[0] > (rect->x + rect->w) ||
          p[1] < (rect->y) ||
		    p[1] > (rect->y + rect->h) )
		{
			pCur = INVALID_INDEX;
			break;
		}
		pCur = GetNextWall( psi->iWorld
								, pCur, &priorend );
	}while( pCur != pStart );
	if( pCur == pStart )
	{
		if( psi->ppsectors )
			psi->ppsectors[psi->nsectors++] = sector;
		else
			psi->nsectors++;
	}
	return 0;
}
コード例 #4
0
INDEX SrvrCreateSquareSector( uint32_t client_id, INDEX iWorld, PC_POINT pOrigin, RCOORD size )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PSECTOR pSector;
	INDEX iSector;
	_POINT o, n;
	pSector = GetFromSet( SECTOR, &world->sectors );
#ifdef OUTPUT_TO_VIRTUALITY
	pSector->facet = AddNormalPlane( world->object, VectorConst_0, VectorConst_Z, 0 );
#endif
	iSector = GetMemberIndex( SECTOR, &world->sectors, pSector );
	/*
	{
		char name[20];
		sprintf( name, "%d", SectorIDs++ );
		pSector->name = GetName( &world->names, name );
	}
	*/
	pSector->iName = INVALID_INDEX;
	pSector->iWorld = iWorld;
	/* east */
	addscaled( o, pOrigin, VectorConst_X, size/2 );
	scale( n, VectorConst_Y, 20 );
	// creates an open line....
	pSector->iWall = SrvrCreateWall( client_id, iWorld, iSector, INVALID_INDEX, FALSE, INVALID_INDEX, FALSE, o, n );
	/* south */
	addscaled( o, pOrigin, VectorConst_Y, size/2 );
	scale( n, VectorConst_X, -20 );
	// creates a wall whos start is at the start of the wall...
	SrvrCreateWall( client_id, iWorld, iSector, pSector->iWall, TRUE, INVALID_INDEX, FALSE, o, n );
	/* west */
	addscaled( o, pOrigin, VectorConst_Y, -size/2 );
	scale( n, VectorConst_X, -20 );
	SrvrCreateWall( client_id, iWorld, iSector, pSector->iWall, FALSE, INVALID_INDEX, FALSE, o, n );
	/* north */
	addscaled( o, pOrigin, VectorConst_X, -size/2 );
	scale( n, VectorConst_Y, 20 );
	{
		PWALL pWall = GetSetMember( WALL, &world->walls, pSector->iWall );
		SrvrCreateWall( client_id, iWorld, iSector
					 , pWall->iWallStart, TRUE
					 , pWall->iWallEnd, TRUE, o, n );
	}
	//ComputeSectorPointList( iWorld, iSector, NULL );
	//ComputeSectorOrigin( iWorld, iSector );
#ifdef OUTPUT_TO_VIRTUALITY
	OrderObjectLines( world->object );
#endif
	SetPoint( pSector->r.n, VectorConst_Y );
	//DumpWall( pSector->wall );
	//DumpWall( pSector->wall->wall_at_start );
	//DumpWall( pSector->wall->wall_at_end );
	//DumpWall( pSector->wall->wall_at_start->wall_at_end );
	{
		INDEX texture = SrvrMakeTexture( client_id, iWorld, SrvrMakeName( client_id, iWorld, WIDE( "Default" ) ) );
		PFLATLAND_TEXTURE pTexture = GetSetMember( FLATLAND_TEXTURE, &world->textures, texture );
		if( !pTexture->flags.bColor )
			SrvrSetSolidColor( client_id, iWorld, texture, AColor( 170, 170, 170, 0x80 ) );
		SrvrSetTexture( client_id, iWorld, iSector, texture );
	}
#ifdef WORLDSCAPE_SERVER
	/* this doesn't exist in direct library */
	MarkSectorUpdated( client_id, iWorld, iSector );
#endif
	return iSector;
}
コード例 #5
0
/* void do_line(BITMAP *bmp, int x1, y1, x2, y2, int d, void (*proc)())
 *  Calculates all the points along a line between x1, y1 and x2, y2,
 *  calling the supplied function for each one. This will be passed a
 *  copy of the bmp parameter, the x and y position, and a copy of the
 *  d parameter (so do_line() can be used with putpixel()).
 */
IMAGE_NAMESPACE

#define int S_32
//unsigned long DOALPHA( unsigned long over, unsigned long in, unsigned long a );

#define FIX_SHIFT 18
#define ROUND_ERROR ( ( 1<< ( FIX_SHIFT - 1 ) ) - 1 )


void CPROC do_line( ImageFile *pImage, int x1, int y1
						 , int x2, int y2, CDATA d )
{
	if( pImage->flags & IF_FLAG_FINAL_RENDER )
	{
		int glDepth = 1;
		VECTOR v1[2], v2[2];
		VECTOR v3[2], v4[2];
		VECTOR slope;
		RCOORD tmp;
		VECTOR normal;
		int v = 0;

		TranslateCoord( pImage, (S_32*)&x1, (S_32*)&y1 );
		TranslateCoord( pImage, (S_32*)&x2, (S_32*)&y2 );
		v1[v][0] = x1;
		v1[v][1] = y1;
		v1[v][2] = 0.0;
		v2[v][0] = x2;
		v2[v][1] = y2;
		v2[v][2] = 0.0;

		sub( slope, v2[v], v1[v] );
		normalize( slope );
		tmp = slope[0];
		slope[0] = -slope[1];
		slope[1] = tmp;

		addscaled( v1[v], v1[v], slope, -0.5 );
		addscaled( v4[v], v1[v], slope, 1.0 );
		addscaled( v2[v], v2[v], slope, -0.5 );
		addscaled( v3[v], v2[v], slope, 1.0 );

		while( pImage && pImage->pParent )
		{
			glDepth = 0;
			if(pImage->transform )
			{
				Apply( pImage->transform, v1[1-v], v1[v] );
				Apply( pImage->transform, v2[1-v], v2[v] );
				Apply( pImage->transform, v3[1-v], v3[v] );
				Apply( pImage->transform, v4[1-v], v4[v] );
				v = 1-v;
			}
			pImage = pImage->pParent;
		}
		if( pImage->transform )
		{
			Apply( pImage->transform, v1[1-v], v1[v] );
			Apply( pImage->transform, v2[1-v], v2[v] );
			Apply( pImage->transform, v3[1-v], v3[v] );
			Apply( pImage->transform, v4[1-v], v4[v] );
			v = 1-v;
		}

			static LPDIRECT3DVERTEXBUFFER9 pQuadVB;

         if( !pQuadVB )
				g_d3d_device->CreateVertexBuffer(sizeof( D3DVERTEX )*4,
															D3DUSAGE_WRITEONLY,
															D3DFVF_CUSTOMVERTEX,
															D3DPOOL_MANAGED,
															&pQuadVB,
															NULL);
			D3DVERTEX* pData;
			//lock buffer (NEW)
			pQuadVB->Lock(0,0,(void**)&pData,0);
         //lprintf( "line color should be %08x", d );
			//copy data to buffer (NEW)
			{
				pData[0].fX = v1[v][vRight] * l.scale;
				pData[0].fY = v1[v][vUp] * l.scale;
				pData[0].fZ = v1[v][vForward] * l.scale;
				pData[0].dwColor = d;
				pData[1].fX = v2[v][vRight] * l.scale;
				pData[1].fY = v2[v][vUp] * l.scale;
				pData[1].fZ = v2[v][vForward] * l.scale;
				pData[1].dwColor = d;
				pData[2].fX = v4[v][vRight] * l.scale;
				pData[2].fY = v4[v][vUp] * l.scale;
				pData[2].fZ = v4[v][vForward] * l.scale;
				pData[2].dwColor = d;
				pData[3].fX = v3[v][vRight] * l.scale;
				pData[3].fY = v3[v][vUp] * l.scale;
				pData[3].fZ = v3[v][vForward] * l.scale;
				pData[3].dwColor = d;
			}
			//unlock buffer (NEW)
			pQuadVB->Unlock();

			g_d3d_device->SetFVF( D3DFVF_CUSTOMVERTEX );
			g_d3d_device->SetStreamSource(0,pQuadVB,0,sizeof(D3DVERTEX));
			g_d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			//pQuadVB->Release();

	}
   else
	{
   int err, delx, dely, len, inc;
   if( !pImage || !pImage->image ) return;
   delx = x2 - x1;
   if( delx < 0 )
      delx = -delx;

   dely = y2 - y1;
   if( dely < 0 )
      dely = -dely;

   if( dely > delx ) // length for y is more than length for x
   {
      len = dely;
      if( y1 > y2 )
      {
         int tmp = x1;
         x1 = x2;
         x2 = tmp;
         y1 = y2; // x1 is start...
      }
      if( x2 > x1 )
         inc = 1;
      else
         inc = -1;

      err = -(dely / 2);
      while( len >= 0 )
      {
         plot( pImage, x1, y1, d );
         y1++;
         err += delx;
         while( err >= 0 )
         {
            err -= dely;
            x1 += inc;
         }
         len--;
      }
   }
   else
   {
      if( !delx ) // 0 length line
         return;
      len = delx;
      if( x1 > x2 )
      {
         int tmp = y1;
         y1 = y2;
         y2 = tmp;
         x1 = x2; // x1 is start...
      }
      if( y2 > y1 )
         inc = 1;
      else
         inc = -1;

      err = -(delx / 2);
      while( len >= 0 )
      {
         plot( pImage, x1, y1, d );
         x1++;
         err += dely;
         while( err >= 0 )
         {
            err -= delx;
            y1 += inc;
         }
         len--;
      }
   }
   MarkImageUpdated( pImage );
	}
}