Пример #1
0
PFAMILYNODE  FamilyTreeAddChild ( PFAMILYTREE *root, POINTER userdata, uintptr_t key )
{
	if( root )
	{
		PFAMILYNODE node;
		if( !(*root ) )
			(*root) = CreateFamilyTree( NULL, NULL );
		node = (PFAMILYNODE)GetFromSet( FAMILYNODE, &(*root)->nodes /*Allocate( sizeof( FAMILYNODE )*/ );
		node->child = NULL;
		node->younger = NULL;
		node->flags.bUsed = 0;
		node->userdata = userdata;
		node->key = key;
		node->parent = (*root)->prior;
		if( !node->parent )
		{
			if( ( node->elder = (*root)->family ) )
				(*root)->family->younger = node;
			(*root)->family = node;
		}
		else
		{
			if( ( node->elder = (*root)->prior->child ) )
				node->elder->younger = node;
			(*root)->prior->child = node;
		}
		(*root)->prior = node;
		(*root)->lastfound = node;
		(*root)->current = node;
		return node;
	}
	return NULL;
}
Пример #2
0
INDEX SrvrOpenWorld( uint32_t client_id, CTEXTSTR name )
{
	PWORLD world;
	INDEX iWorld;
	uintptr_t psvResult;
	psvResult = ForAllInSet( WORLD, g.worlds, CompareWorldName, (uintptr_t)name );
	if( psvResult )
	{
		world = (PWORLD)psvResult;
		iWorld = GetMemberIndex( WORLD, &g.worlds, world );
#if defined( WORLD_SCAPE_SERVER_EXPORTS ) || defined( WORLDSCAPE_SERVICE )
		SrvrMarkWorldUpdated( client_id, iWorld );
#endif
	}
	else
	{
		world = GetFromSet( WORLD, &g.worlds );
		iWorld = GetMemberIndex( WORLD, &g.worlds, world );
#if defined( WORLD_SCAPE_SERVER_EXPORTS ) || defined( WORLDSCAPE_SERVICE )
		SrvrMarkWorldUpdated( client_id, iWorld );
#endif
		world->name = SrvrMakeName( client_id, iWorld, name );
		// get from set is zero initialized.
		//world->lines = NULL;
		//world->walls = NULL;
		//world->sectors = NULL;
		//world->textures = NULL;
		//world->names = NULL; // derr just made a name for this world itself... then do what?!
		//world->spacetree = NULL;
		SrvrCreateSquareSector( client_id, iWorld, VectorConst_0, 50 );
	}
	return iWorld;
}
Пример #3
0
INDEX SrvrMakeTexture( uint32_t client_id, INDEX iWorld, INDEX iName )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PFLATLAND_TEXTURE texture;
	INDEX iTexture = INVALID_INDEX;
	FINDTHING ft;
	ft.iWorld = iWorld;
	ft.iName  = iName;
	if( iName != INVALID_INDEX )
	{
		iTexture = ForAllTextures( iWorld, FindTextureName, (uintptr_t)&ft );
		if( iTexture != INVALID_INDEX )
			texture = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
		else
		{
			texture = GetFromSet( FLATLAND_TEXTURE, &world->textures );
			iTexture = GetMemberIndex( FLATLAND_TEXTURE, &world->textures, texture );
			texture->iName = iName;
		}
	}
#if defined( WORLD_SCAPE_SERVER_EXPORTS ) || defined( WORLDSCAPE_SERVICE )
	MarkTextureUpdated( client_id, iWorld, iTexture );
#endif
	return iTexture;
}
Пример #4
0
void *LAYER_DATA::operator new( size_t sz, struct LAYER_DATAset_tag **frompool )
{
	if( sz != sizeof( LAYER_DATA ) )
		return NULL;
	//if( !(*frompool ) )
    //  (*frompool) = new LAYER_DATASET;
	PLAYER_DATA layer = GetFromSet( LAYER_DATA, (frompool) );
	layer->pool = frompool;
	return layer;
}
Пример #5
0
void classify( char *file, uint8_t* p, uintptr_t size )
{
    int n;
    for( n = 0; n < size; n += 12 )
    {
        PRELATION relation = GetFromSet( RELATION, &relations );
        relation->card = p + n;
        relation->file = file;
        relation->number = ( n / 12 ) + 1;
        PRELATION *rel = related[p[n+0]] + p[n+1];
        LinkThing( rel[0], relation );
        totalCount++;
        //TickLog( "classify", n / 12 );
    }
}
Пример #6
0
INDEX MakeName( INDEX iWorld, CTEXTSTR text )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	// anmes should be cached... and referenced...
	// ahh well we'll deal with this for now... there's not
	// that many names....
	//   see procreg for someone who needs to worry.
	PNAME name = GetFromSet( NAME, &world->names );
	INDEX iName = GetMemberIndex( NAME, &world->names, name );
	MemSet( name, 0, sizeof( NAME ) );
	if( text )
		SetName( iWorld, iName, text );
#ifdef WORLDSCAPE_SERVICE
	MarkNameUpdated( iWorld, iName );
#endif
	return iName;
}
Пример #7
0
void *LAYER::operator new( size_t sz, LAYERSET **frompool, LAYER_DATASET **fromdatapool )
{
	if( sz != sizeof( LAYER ) )
		return NULL;
	if( !(*frompool ) )
	{
		//(*frompool) = NULL; //new LAYERSET;
		PLAYER layer0 = GetSetMember( LAYER, (frompool), 0 );
		// grab the 0'th layer from the pool.
		// this layer is the root of all layers, and allows
		// the tracking of the order of under/over
		// by being a well known variable that this
		// module has access to.
		layer0->next = NULL;
		layer0->prior = NULL;
		layer0->flags.bRoot = 1;
	}
	PLAYER layer = GetFromSet( LAYER, (frompool) );
	MemSet( layer, 0, sizeof( LAYER ) );
	layer->pool = frompool;
	layer->pLayerData = new( fromdatapool ) LAYER_DATA();
	layer->link_top();
	return layer;
}
Пример #8
0
void CPROC EditResizeCallback( uintptr_t dwUser  )
{
	PEDITOR pe = (PEDITOR)dwUser;
	//PFACETSET *ppfs;
	//PFACET pf;

	//PLINESEGPSET *pplps;
	//PMYLINESEGSET *ppls;
	//PMYLINESEG pl;
	//int l;
	// ShowCurrent();
	//ClearImage( surface );
	{
		//IMAGE_RECTANGLE r;
		//GetDisplayPosition( pe->hVideo, pe->ptUpperLeft, pe->ptUpperLeft + 1, NULL, NULL );
		/*
		GetWindowRect( pe->hVideo->hWndOutput, &r );
		pe->ptUpperLeft[0] = r.left //+ GetSystemMetrics( SM_CXBORDER )
									  + GetSystemMetrics( SM_CXFRAME );
		pe->ptUpperLeft[1] = r.top + GetSystemMetrics( SM_CYBORDER )
									 + GetSystemMetrics( SM_CYFRAME )
									 + GetSystemMetrics( SM_CYCAPTION );
									 */
	}
#if 0
	SetClip( (RCOORD)GetDisplayImage( pe->hVideo )->width,
				(RCOORD)GetDisplayImage( pe->hVideo )->height );
	ppfs = pe->pCurrent->objinfo->ppFacetPool;
	ppls = GetFromSet( LINEPSEG, pe->pCurrent->objinfo->ppLinePool );
	//ForAllInSet( FACET, &pe->pCurrent->objinfo->ppFacetPool, DrawLineSegs );
	//int f;
	//for( f = 0; f < ; f++ )
	{
		int lines;
		//pf = GetFromSet( FACET, pfs->pFacets + f;
		pplps = &pf->pLineSet;
		lines = CountUsedInSet( LINESEGP, pf->pLineSet );
		for( l = 0; l < lines; l++ )
		{
			RAY ld; // local directional...
			PLINESEGP plsp = GetSetMember( LINESEGP, pplps, l );
			pl = GetSetMember( MYLINESEG, ppls, plsp->nLine );
			if( pl == pe->pCurrentLine )
			{
				ApplyInverseR( pe->TView, &ld, &pl->r );
				DrawLine(surface, ld.o, ld.n, pl->dFrom-5, pl->dFrom, Color( 192, 192, 0 ) );
				DrawLine(surface, ld.o, ld.n, pl->dFrom, pl->dTo, Color( 0, 150, 0 ) );
				DrawLine(surface, ld.o, ld.n, pl->dTo, pl->dTo+5, Color( 192, 192, 0 ) );
				GetViewPoint(surface, &pe->ptO, ld.o );
				add( ld.o, ld.o, ld.n ); // add one slope to origin to get slope point
				GetViewPoint(surface, &pe->ptN, ld.o );
				MarkOrigin( pe, surface );
				MarkSlope( pe,surface );
			}
			else
			if( pf = pe->pCurrentFacet )
			{
				ApplyInverseR( pe->TView, &ld, &pl->r );
				DrawLine(surface, ld.o, ld.n, pl->dFrom, pl->dTo, Color( 0, 0, 150 ) );
			}
			else
			{
				ApplyInverseR( pe->TView, &ld, &pl->r );
				DrawLine(surface, ld.o, ld.n, pl->dFrom, pl->dTo, Color( 92, 92, 92 ) );
			}
		}
	}
	UpdateDisplay( pe->hVideo );
#endif
}
Пример #9
0
int SrvrLoadWorldFromFile( uint32_t client_id, FILE *file, INDEX iWorld )
{
	FILE *pFile;
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	int sz = 0, cnt, version, size;
	char tag[4]; // read in make sure we're still aligned in the file...
	int linesize;
	int nlines;
	PFLATLAND_MYLINESEG *linearray;
	int wallsize;
	int nwalls;
	PWALL *wallarray;
	int sectorsize;
	int nsectors;
	PSECTOR *sectorarray;
	int namesize;
	int nnames;
	PNAME *namearray;
	int texturesize;
	int ntextures;
	PFLATLAND_TEXTURE *texturearray;

	INDEX texture;

	if( !world )
		return 0;
	{
		char buffer[256];
      GetNameText( iWorld, world->name, buffer, sizeof( buffer ) );
		Fopen( pFile, buffer, "rb" );
	}
	if( !pFile )
      return 0;
	ResetWorld( iWorld ); // make sure this thing is empty );

	sz += fread( tag, 1, 4, pFile );
	if( strncmp( tag, "FLAT", 4 ) ) 
	{
		Log( "Alignment error in file load... totally invalid file." );
		return 0;
	}
	sz += fread( &size, 1, sizeof( size ), pFile );
	if( size < 10 ) // can assume that it was a version ID
		version = size;
	else
		sz = fread( &version, 1, sizeof( version ), pFile );

	if( version < 8 )
	{
		texture = SrvrMakeTexture( client_id, iWorld, SrvrMakeName( client_id, iWorld, WIDE( "Default" ) ) );
		SrvrSetSolidColor( client_id, iWorld, texture, AColor( 43, 76, 180, 0x80 ) );
	}
	Log1( "Loading version: %d", version );

	sz += fread( tag, 1, 4, pFile );
	if( strncmp( tag, "LINE", 4 ) )
	{
		// was not LINE or FLAT tag...
		Log( "Alignment error in file line load." );
		return 0;
	}

	if( version > 9 )
		sz += fread( &linesize, 1, sizeof( linesize ), pFile );

	sz += fread( &nlines, 1, sizeof(nlines), pFile );
	linearray = (PFLATLAND_MYLINESEG*)Allocate( sizeof( PFLATLAND_MYLINESEG ) * nlines );
	for( cnt = 0; cnt < nlines; cnt++ )
	{
		PFLATLAND_MYLINESEG pls;
		LINESEGFILE lsf;
		sz += fread( &lsf, 1, sizeof(LINESEGFILE), pFile );
		pls = GetFromSet( FLATLAND_MYLINESEG, &world->lines );
#ifdef OUTPUT_TO_VIRTUALITY
		pls->pfl = CreateFacetLine( world->object, lsf.r.o, lsf.r.n, lsf.start, lsf.end );
#endif
		linearray[cnt] = pls;
		/* some sort of update line... */
		SetRay( &pls->r, &lsf.r );
		if( version < 9 )
		{
			pls->r.o[1] = -pls->r.o[1];
			pls->r.n[1] = -pls->r.n[1];
		}
		pls->dFrom = lsf.start;
		pls->dTo = lsf.end;

	}

	sz += fread( tag, 1, 4, pFile );
	if( strncmp( tag, "WALL", 4 ) )
	{
		Log( "Alignment error in file wall load." );
		return 0;
	}
	if( version > 9 )
		sz += fread( &wallsize, 1, sizeof( wallsize ), pFile );

	sz += fread( &nwalls, 1, sizeof(nwalls), pFile );
	wallarray = (PWALL*)Allocate( sizeof( PWALL ) * nwalls );
	for( cnt = 0; cnt < nwalls; cnt++ )
	{
		wallarray[cnt] = GetFromSet( WALL, &world->walls );
	}
	for( cnt = 0; cnt < nwalls; cnt++ )
	{
		FILEWALLV1 ReadWall1;
		FILEWALLV2 ReadWall2;
		PWALL pwall;
		pwall = wallarray[cnt];
		if( version < 2 )
		{
			sz += fread( &ReadWall1, 1, sizeof( FILEWALLV1 ), pFile );
			pwall->flags = ReadWall1.flags;
			pwall->iSector = ReadWall1.nSector;

			SetLineWorld( world, pwall->iLine, linearray[ReadWall1.nLine] );

			if( ReadWall1.nWallInto == -1 )
				pwall->iWallInto = INVALID_INDEX;
			else
				pwall->iWallInto = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall1.nWallInto] );
			pwall->iWallStart = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall1.nWallStart] );
			pwall->iWallEnd = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall1.nWallEnd] );
		}
		else 
		{
			sz += fread( &ReadWall2, 1, sizeof( FILEWALLV2 ), pFile );
			pwall->flags = ReadWall2.flags;
			pwall->iSector = ReadWall2.nSector;
			if( ReadWall2.nLine != -1 )
			{
				pwall->iLine = GetMemberIndex( FLATLAND_MYLINESEG, &world->lines, linearray[ReadWall2.nLine] );
				//SetLine( pwall->line, linearray[ReadWall2.nLine] );
			}
			else
			{
				Log( "Wall without line? cant be!" );
				DebugBreak();
				pwall->iLine = INVALID_INDEX;
			}
			if( ReadWall2.nWallInto == -1 )
				pwall->iWallInto = INVALID_INDEX;
			else
				pwall->iWallInto = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall2.nWallInto] );
			pwall->iWallStart = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall2.nWallStart] );
			pwall->iWallEnd = GetMemberIndex( WALL, &world->walls, wallarray[ReadWall2.nWallEnd] );
		}
	}	

	sz += fread( tag, 1, 4, pFile );
	if( strncmp( tag, "SECT", 4 ) )
	{
		Log2( "Alignment error in file sector load. %s(%d)", __FILE__, __LINE__ );
		return 0;
	}
	if( version > 9 )
		sz += fread( &sectorsize, 1, sizeof( sectorsize ), pFile );
	sz += fread( &nsectors, 1, sizeof(nsectors), pFile );
	sectorarray = (PSECTOR*)Allocate( sizeof( PSECTOR ) * nsectors );
	for( cnt = 0; cnt < nsectors; cnt++ )
	{
		FILESECTORV3 ReadSector3;
		FILESECTORV4 ReadSector4;
		FILESECTORV5 ReadSector5;
		FILESECTORV8 ReadSector8;
		INDEX sector;
		sectorarray[cnt] = GetFromSet( SECTOR, &world->sectors );
#ifdef OUTPUT_TO_VIRTUALITY
		sectorarray[cnt]->facet = AddNormalPlane( world->object, VectorConst_0, VectorConst_Z, 0 );
#endif
		sector =  GetMemberIndex( SECTOR, &world->sectors, sectorarray[cnt] );
		if( version < 8 )
		{
			// one texture is sufficient...
			// in fact textures should be highly sharable.
			sectorarray[cnt]->iTexture = texture;
		}
		if( version < 4 )
		{	
			/*
			{
			char name[20];
			sprintf( name, "%d", SectorIDs++ );
			sectorarray[cnt]->name = GetName( &world->names, name );
			}
			*/
			sectorarray[cnt]->iName = INVALID_INDEX;
			sz += fread( &ReadSector3, 1, sizeof( FILESECTORV3 ), pFile );
			sectorarray[cnt]->flags = ReadSector3.flags;
			sectorarray[cnt]->iWorld = iWorld;
			SetRay( &sectorarray[cnt]->r, &ReadSector3.r );
			sectorarray[cnt]->iWall = GetMemberIndex( WALL, &world->walls, wallarray[ReadSector3.nwall] );

			if( version < 3 )
			{
				ComputeSectorOrigin( iWorld, sector);
			}
		}
		else if( version < 5 )
		{
			sz += fread( &ReadSector4, 1, sizeof( FILESECTORV4 ), pFile );
			/*
			{
			char name[20];
			sprintf( name, "%d", ReadSector4.nID );
			sectorarray[cnt]->name = GetName( &world->names, name );
			if( atoi( name ) > SectorIDs )
			SectorIDs = atoi( name );
			}
			*/
			sectorarray[cnt]->iName = INVALID_INDEX;
			sectorarray[cnt]->flags = ReadSector4.flags;
			sectorarray[cnt]->iWorld = iWorld;
			SetRay( &sectorarray[cnt]->r, &ReadSector4.r );
			sectorarray[cnt]->iWall = GetMemberIndex( WALL, &world->walls, wallarray[ReadSector4.nwall] );
		}
		else if( version < 8 )
		{
			sz += fread( &ReadSector5, 1, sizeof( FILESECTORV5 ), pFile );
			sectorarray[cnt]->iName = ReadSector5.nName;
			sectorarray[cnt]->flags = ReadSector5.flags;
			sectorarray[cnt]->iWorld = iWorld;
			SetRay( &sectorarray[cnt]->r, &ReadSector5.r );
			sectorarray[cnt]->iWall = GetMemberIndex( WALL, &world->walls, wallarray[ReadSector5.nwall] );
		}
		else
		{
			sz += fread( &ReadSector8, 1, sizeof( FILESECTORV8 ), pFile );
			sectorarray[cnt]->iName = ReadSector8.nName;
			sectorarray[cnt]->flags = ReadSector8.flags;
			sectorarray[cnt]->iWorld = iWorld;
			SetRay( &sectorarray[cnt]->r, &ReadSector8.r );
			sectorarray[cnt]->iWall = ReadSector8.nwall;
			sectorarray[cnt]->iTexture = ReadSector8.nTexture;
		}
		// walls should all be valid at this point...
		// have valid lines, and valid linkings...
		ComputeSectorPointList( iWorld, sector, NULL );
		ComputeSectorOrigin( iWorld, sector );
#ifdef OUTPUT_TO_VIRTUALITY
		OrderObjectLines( world->object );
#endif
	}

	// fix sector references in walls.
	//for( cnt = 0; cnt < nwalls; cnt++ )
	//{
	//	wallarray[cnt]->iSector = wallarray[cnt]->iSector;
	//}

	for( cnt = 0; cnt < nwalls; cnt++ )
	{
		if( wallarray[cnt]->iLine == INVALID_INDEX )
		{
			SrvrDestroySector( client_id, iWorld, wallarray[cnt]->iSector );
			Log( "attempting to fix broken walls" );
			break;
		}
	}

	if( version >= 5 )
	{
		sz += fread( tag, 1, 4, pFile );
		if( strncmp( tag, "NAME", 4 ) )
		{
			Log2( "Alignment error in name section load. %s(%d)", __FILE__, __LINE__ );
			return 0;
		}
		if( version > 9 )
			sz += fread( &namesize, 1, sizeof( namesize ), pFile );
		sz += fread( &nnames, 1, sizeof(nnames), pFile );
		namearray = (PNAME*)Allocate( sizeof( PNAME ) * nnames );
		for( cnt = 0; cnt < nnames; cnt++ )
		{  	
			namearray[cnt] = GetFromSet( NAME, &world->names );
			if( version < 6 )
			{
				uint32_t length;
 				namearray[cnt]->name = (struct name_data*)Allocate( sizeof( *namearray[cnt]->name ) );
				sz += fread( &length, 1, sizeof( length ), pFile );
            namearray[cnt]->name[0].length = length;
				namearray[cnt]->name[0].name = (TEXTSTR)Allocate( namearray[cnt]->name[0].length + 1 );
 				sz += fread( namearray[cnt]->name[0].name, 1, namearray[cnt]->name[0].length, pFile );
		      namearray[cnt]->name[0].name[namearray[cnt]->name[0].length] = 0;
		      namearray[cnt]->lines = 1;
			}
			else if( version < 7 )
			{
				int l;
				sz += fread( &namearray[cnt]->lines, 1, sizeof( namearray[cnt]->lines ), pFile );
				if( namearray[cnt]->lines )
				{
					namearray[cnt]->name = (struct name_data*)Allocate( sizeof( *namearray[cnt]->name ) * namearray[cnt]->lines );
					for( l = 0; l < namearray[cnt]->lines; l++ )
					{
						sz += fread( &namearray[cnt]->name[l].length, 1, sizeof( namearray[cnt]->name[l].length ), pFile );
						namearray[cnt]->name[l].name = (TEXTSTR)Allocate( namearray[cnt]->name[l].length + 1 );
						sz += fread( namearray[cnt]->name[l].name, 1, namearray[cnt]->name[l].length, pFile );
						namearray[cnt]->name[l].name[namearray[cnt]->name[l].length] = 0;
					}	
				}
				else
					namearray[cnt]->name = NULL;
			}
			else
			{
				int l;
				sz += fread( &namearray[cnt]->flags, 1, sizeof( namearray[cnt]->flags ), pFile );
				sz += fread( &namearray[cnt]->lines, 1, sizeof( namearray[cnt]->lines ), pFile );
				if( namearray[cnt]->lines )
				{
					namearray[cnt]->name = (struct name_data*)Allocate( sizeof( *namearray[cnt]->name ) * namearray[cnt]->lines );
					for( l = 0; l < namearray[cnt]->lines; l++ )
					{
						sz += fread( &namearray[cnt]->name[l].length, 1, sizeof( namearray[cnt]->name[l].length ), pFile );
						namearray[cnt]->name[l].name = (TEXTSTR)Allocate( namearray[cnt]->name[l].length + 1 );
						sz += fread( namearray[cnt]->name[l].name, 1, namearray[cnt]->name[l].length, pFile );
						namearray[cnt]->name[l].name[namearray[cnt]->name[l].length] = 0;
					}	
				}
				else
					namearray[cnt]->name = NULL;
			}
		}
       /*
		for( cnt = 0; cnt < nsectors; cnt++ )
		{
			if( (int)sectorarray[cnt]->iName == -1 )
				sectorarray[cnt]->iName = INVALID_INDEX;
			else
			{
				int n;
				PNAME pName = namearray[(int)sectorarray[cnt]->name];
				if( pName->name && pName->name[0].name )
					if( ( n = atoi( pName->name[0].name ) ) > SectorIDs )
						SectorIDs = n;
				sectorarray[cnt]->name = pName;
			}
	   }
      */
		if( version >= 8 )
		{
			sz += fread( tag, 1, 4, pFile );
			if( strncmp( tag, "TEXT", 4 ) )
			{
				Log2( "Alignment error in texture section load. %s(%d)", __FILE__, __LINE__ );
				return 0;
			}
			if( version > 9 )
				sz += fread( &texturesize, 1, sizeof( texturesize ), pFile );
			sz += fread( &ntextures, 1, sizeof(ntextures), pFile );
			texturearray = (PFLATLAND_TEXTURE*)Allocate( sizeof( PFLATLAND_TEXTURE ) * ntextures );
			for( cnt = 0; cnt < ntextures; cnt++ )
			{
				char flag;
				int nName;
				sz += fread( &nName, 1, sizeof( nName ), pFile );
				texturearray[cnt] = GetFromSet( FLATLAND_TEXTURE, &world->textures );
				texturearray[cnt]->iName = GetMemberIndex( NAME, &world->names, namearray[nName] );
				sz += fread( &flag, 1, sizeof( flag ), pFile );
				texturearray[cnt]->flags.bColor = flag;
				if( flag )
				{
					sz += fread( &texturearray[cnt]->data.color, 1, sizeof(CDATA), pFile );
				}
			}
		   
			//for( cnt = 0; cnt < nsectors; cnt++ )
			//{
			//	int ntexture = (int)sectorarray[cnt]->iTexture;
         //   sectorarray[cnt]->texture = NULL;
			//	SetTexture( sectorarray[cnt]->texture, texturearray[ntexture] );
			//}
			Release( texturearray );
		}

		Release( namearray );
	}

	if( version > 9 )
	{
		if( sz != size )
		{
			Log2( "Total load size %d is not %d", sz, size );
		}
	}

	//for( cnt = 0; cnt < nsectors; cnt++ )
	{
		//PSECTOR pSector = sectorarray[cnt];
		// again with the min/max fetch with
		// spacetree add
		//pSector->spacenode = AddSpaceNode( &world->spacetree, pSector, min, max );
	}

	Release( linearray );
	Release( wallarray );
	Release( sectorarray );
	ValidateWorldLinks(iWorld);
	return version;
}
Пример #10
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;
}
Пример #11
0
LAYER::LAYER( PODBC odbc, PLIST peices, INDEX iLoadLayer )
{
	if( !this )
		return;
	if( iLayer && iLayer != INVALID_INDEX )
	{
		lprintf( WIDE("Recovering prior layer") );
		return;
	}
	{
		CTEXTSTR *results;
		if( SQLRecordQueryf( odbc, NULL, &results, NULL
					  , WIDE("select x,y,min_x,min_y,width,height,linked_from_id,linked_from_x,linked_from_y,linked_to_id,linked_to_x,linked_to_y,route,peice_info_id,peice_type from board_layer where board_layer_id=%lu")
					  , iLoadLayer
					  ) && results )
		{
			PIPEICE peice_type = ::GetPeice( peices, results[14] );
			
			pLayerData->psvInstance = peice_type->Load( odbc, atoi( results[13] ) );//, pLayerData->psvInstance );
			pLayerData->SetPeice( peice_type );
			pds_path = CreateDataStack( sizeof( LAYER_PATH_NODE ) );
			x = atoi( results[0] );
			y = atoi( results[1] );
			min_x = atoi( results[2] );
			min_y = atoi( results[3] );
			w = IntCreateFromText( results[4] );
			h = IntCreateFromText( results[5] );
			flags.bRoute = atoi( results[12] );

		    iLayer = iLoadLayer;

			INDEX iStart = IntCreateFromText( results[6] );
			if( iStart != INVALID_INDEX )
			{
				int32_t x, y;
				x = atoi( results[7] );
				y = atoi( results[8] );
				PLAYER loaded_route_start_layer;
				loaded_route_start_layer = FindLayer( iStart );
				if( !loaded_route_start_layer )
					loaded_route_start_layer = GetFromSet( LAYER, pool ); //new(pool,pLayerData->pool) LAYER( odbc, peices, iStart );
				loaded_route_start_layer->pLayerData->peice->methods->ConnectBegin( loaded_route_start_layer->pLayerData->psvInstance
												, x, y // connect x, y
												, pLayerData->peice, pLayerData->psvInstance );
				loaded_route_start_layer->Link( this, LINK_VIA_START, x, y);
			}

			INDEX iEnd = IntCreateFromText( results[9] );
			if( iEnd != INVALID_INDEX )
			{
				int32_t x, y;
				x = atoi( results[10] );
				y = atoi( results[11] );
				PLAYER loaded_route_end_layer;
				loaded_route_end_layer = FindLayer( iEnd );
				if( !loaded_route_end_layer )
					loaded_route_end_layer = GetFromSet( LAYER, pool ); //new(pool,pLayerData->pool) LAYER( odbc, peices, iEnd );
				loaded_route_end_layer->pLayerData->peice->methods->ConnectEnd( loaded_route_end_layer->pLayerData->psvInstance
												, x, y // connect x, y
												, pLayerData->peice, pLayerData->psvInstance );
				loaded_route_end_layer->Link( this, LINK_VIA_END, x, y );
			}



			//}
		}
		SQLEndQuery( odbc );
		for( SQLRecordQueryf( odbc, NULL, &results, NULL, WIDE("select x,y,fore,back from board_layer_path where board_layer_id=%lu order by board_layer_path_id desc"), iLoadLayer );
			results;
			FetchSQLRecord( odbc, &results ) )
		{
			// add path node for a routed type peice
			LAYER_PATH_NODE node;
			node.x = atoi( results[0] );
			node.y = atoi( results[1] );
			node.flags.ForeDir = atoi( results[2] );
			node.flags.BackDir = atoi( results[3] );
			PushData( &pds_path, &node );
		}
	}
   //return iLayer;
}
Пример #12
0
int main( void )
{
	int n;
	char tmp[256];
   int card_count = 0;
	int card;
	char *cardset;
	int cardset_start = 0;
	int cardset_end = 32000;
	snprintf( tmp, sizeof( tmp ), "cards.dat" );
	printf( "Loading cardset....\n" );
	LoadCardset( tmp, &card_count, &cardset );
	{
      int num;
      //int s =  ( n - 1 ) / 15;
		printf( "Sorting cardset...\n" );
		for( card = 0; card < card_count; card++ )
		{
			PCARD_TESTER tester = GetFromSet( CARD_TESTER, &test_set );
			tester->card = cardset + (card * 25);
			//lprintf( "card %d(%d) = %p", card, GetMemberIndex( CARD_TESTER, &test_set, tester ), tester );
			for( num = 0; num < 25; num++ )
			{
				if( num == 12 )
					continue;
				{
					PCARD_TESTER_LINK link = GetFromSet( CARD_TESTER_LINK, &test_set_links );
					PCARD_TESTER_LINK *base_tester= &sorted_cards[cardset[card*25+num]];
					link->tester = tester;
					//lprintf( "Add card %d to %d", card, cardset[card*25+num] );
					if( link->next = (*base_tester) )
						(*base_tester)->me = &link->next;
					(*base_tester) = link;
				}
			}
		}
	}
	printf( "Drawing balls...\n" );
	for( n = 0; n < 0x40000000; n++ )
	{
      int *source_balls = DrawRandomNumbers2();
		int *balls;
		int ball;

		switch( n % 6 )
		{
		case 0:
			max_counts[0] = 5;
			max_counts[1] = 15;
			max_counts[2] = 15;
			max_counts[3] = 15;
			max_counts[4] = 5;
			break;
		case 1:
			max_counts[0] = 15;
			max_counts[1] = 5;
			max_counts[2] = 15;
			max_counts[3] = 15;
			max_counts[4] = 5;
			break;
		case 2:
			max_counts[0] = 5;
			max_counts[1] = 15;
			max_counts[2] = 15;
			max_counts[3] = 5;
			max_counts[4] = 15;
			break;
		case 3:
			max_counts[0] = 15;
			max_counts[1] = 5;
			max_counts[2] = 15;
			max_counts[3] = 5;
			max_counts[4] = 15;
			break;
		case 4:
			max_counts[0] = 5;
			max_counts[1] = 5;
			max_counts[2] = 15;
			max_counts[3] = 15;
			max_counts[4] = 15;
			break;
		case 5:
			max_counts[0] = 15;
			max_counts[1] = 15;
			max_counts[2] = 15;
			max_counts[3] = 5;
			max_counts[4] = 5;
			break;
		}

      balls = PickBalls( source_balls );

		for( card = 0; card < card_count; card++ )
		{
			PCARD_TESTER tester = GetSetMember( CARD_TESTER, &test_set, card );
			tester->marks = 0;
		}
		for( ball = 0; ball <= 75; ball++ )
		{
			lprintf( "First card %p", sorted_cards[ball] );
			
		}
		for( ball = 0; ball < 45; ball++ )
		{
			int cards_marked = 0;
			int real_ball = balls[ball];
			PCARD_TESTER_LINK tester;
			PCARD_TESTER_LINK prior = NULL;
			PCARD_TESTER_LINK _prior = NULL;
			lprintf( "First card %p", sorted_cards[real_ball] );
			for( tester = sorted_cards[real_ball]; tester; tester = tester->next )
			{
				cards_marked++;
				tester->tester->marks++;
				_prior = prior;
				prior = tester;
			}
			lprintf( "Marked %d cards with %d", cards_marked, real_ball );
		}

		printf( "balls: " );
		for( ball = 0; ball < 75; ball++ )
		{
			printf( "%d,", balls[ball] );
		}
		printf( "\n" );
		fflush( stdout );
		{
			for( ball = 0; ball < 25; ball++ )
			{
				marks[ball] = 0;
			}
			ForAllInSet( CARD_TESTER, test_set, TestOk, 0 );
			printf( "cards with X marks: " );
			for( ball = 0; ball < 25; ball++ )
			{
				printf( "%d,", marks[ball] );
			}
		}
		printf( "\n" );
		fflush( stdout );
		{
			for( ball = 0; ball < 25; ball++ )
			{
				marks[ball] = 0;
			}
			ForAllInSet( CARD_TESTER, test_set, TestOk2, 0 );
			printf( "cards with X marks: " );
			for( ball = 0; ball < 25; ball++ )
			{
				printf( "%d,", marks[ball] );
			}
		}
		printf( "\n" );
		fflush( stdout );
	}
	return 0;
}