Example #1
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;
}
Example #2
0
WORLD_PROC( INDEX, GetWallSector )( INDEX iWorld, INDEX iWall )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PWALL wall = GetSetMember( WALL, &world->walls, iWall );
	if( wall )
		return wall->iSector;
	return INVALID_INDEX;
}
Example #3
0
void GetTextureNameText( INDEX iWorld, INDEX iTexture, char *buf, int bufsize )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PFLATLAND_TEXTURE texture;
	if( iTexture == INVALID_INDEX )
		return;
	texture = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
	GetNameText( iWorld, texture->iName, buf, bufsize );
}
Example #4
0
void SrvrSetSolidColor( uint32_t client_id, INDEX iWorld, INDEX iTexture, CDATA color )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PFLATLAND_TEXTURE texture;
	if( iTexture == INVALID_INDEX )
		return;
	texture = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
	texture->flags.bColor = TRUE;
	texture->data.color = color;
#if defined( WORLD_SCAPE_SERVER_EXPORTS ) || defined( WORLDSCAPE_SERVICE )
	MarkTextureUpdated( client_id, iWorld, iTexture );
#endif
}
Example #5
0
INDEX SrvrSetTexture( uint32_t client_id, INDEX iWorld, INDEX iSector, INDEX iTexture )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PSECTOR sector;
	if( !world || iSector == INVALID_INDEX )
		return INVALID_INDEX;
	sector= GetSetMember( SECTOR, &world->sectors, iSector );
	sector->iTexture = iTexture;
#if defined( WORLD_SCAPE_SERVER_EXPORTS ) || defined( WORLDSCAPE_SERVICE )
	MarkSectorUpdated( client_id, iWorld, iSector );
#endif
	return iSector;
}
Example #6
0
//----------------------------------------------------------------------------
WORLD_PROC( uint32_t, GetSectorCount )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	if( world )
		return CountUsedInSet( SECTOR, world->sectors );
	return 0;
}
Example #7
0
//----------------------------------------------------------------------------
WORLD_PROC( PFLATLAND_MYLINESEGSET, GetLines )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	if( world )
		return world->lines;
	return NULL;
}
Example #8
0
void DeleteNames( INDEX iWorld  )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PNAMESET *ppNames = &world->names;
	ForAllInSet( NAME, *ppNames, (FAISCallback)DeleteAName, iWorld );
	DeleteSet( (GENERICSET**)ppNames );
}
Example #9
0
//----------------------------------------------------------------------------
WORLD_PROC( PSECTORSET, GetSectors )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	if( world )
		return world->sectors;
	return NULL;
}
Example #10
0
//----------------------------------------------------------------------------
WORLD_PROC( PWALLSET, GetWalls )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	if( world )
		return world->walls;
	return NULL;
}
Example #11
0
//----------------------------------------------------------------------------
WORLD_PROC( uint32_t, GetLineCount )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	if( world )
		return CountUsedInSet( FLATLAND_MYLINESEG, world->lines );
	return 0;
}
Example #12
0
//----------------------------------------------------------------------------
WORLD_PROC( uint32_t, GetWallCount )( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
   if( world )
		return CountUsedInSet( WALL, world->walls );
   return 0;
}
Example #13
0
static INDEX CPROC DeleteATexture( INDEX iTexture, uintptr_t psv )
{
	INDEX iWorld = (INDEX)psv;
	GETWORLD( iWorld );
	PFLATLAND_TEXTURE texture = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
	if( texture )
		DeleteName( iWorld, texture->iName );
	DeleteFromSet( FLATLAND_TEXTURE, world->textures, texture );
	return INVALID_INDEX;
}
Example #14
0
INDEX ForAllTextures( INDEX iWorld, INDEX(CPROC*f)(INDEX,uintptr_t), uintptr_t psv )
{
	struct {
		INDEX(CPROC*f)(INDEX,uintptr_t);
		uintptr_t psv;
	} info;
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	info.f = f;
	info.psv = psv;
	return (INDEX)ForEachSetMember( FLATLAND_TEXTURE, world->textures, TextureFilter, (uintptr_t)&info )-1;
}
Example #15
0
WORLD_PROC( void, GetNameText )( INDEX iWorld, INDEX iName, TEXTCHAR *text, int maxlen )
{	
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	PNAME name = GetSetMember( NAME, &world->names, iName );
	int l, ofs = 0;
	if( !name )
	{
		if( text )
			text[0] = 0;
		return;
	}
	for( l = 0; l < name->lines; l++ )
	{
		if( l )
		{
			text[ofs++] = '\\';
			text[ofs++] = 'n';
		}	
		MemCpy( text+ofs, name->name[l].name, name->name[l].length );
		ofs += name->name[l].length;
	}
	text[ofs] = 0;
}
Example #16
0
void LAYER::link_top(void )
{
	PLAYER layer0;
	layer0 = GetSetMember( LAYER, pool, 0 );
	if( layer0 )
	{
      //DebugBreak();
		if( next = layer0->next )
			next->prior = this;
		prior = NULL; // if top, no prior
		if( !layer0->next )
			layer0->prior = this;
		layer0->next = this;
      // layer0->me ?!
      //LinkThing( next, this );
	}
}
Example #17
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;
}
Example #18
0
void LAYER::isolate( void )
{
	// can't isoloate root
	if( flags.bRoot )
		return ;
	if( !pool )
		return;
	PLAYER layer0 = GetSetMember( LAYER, pool, 0 );;
	if( next )
	{
		next->prior = prior;
	}
	else
		layer0->prior = prior;
	if( prior )
		prior->next = next;
	else
		layer0->next = next;
   //UnlinkThing(this);
}
Example #19
0
void ResetWorld( INDEX iWorld )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	//SectorIDs = 0;
	DeleteSectors( iWorld );// deletes walls also...

	// should probably check that all walls are now now treferences...
	DeleteSet( (PGENERICSET*)&world->walls );
	// should probably check that all lines are now now treferences...
	DeleteSet( (PGENERICSET*)&world->lines );

	DeleteTextures( iWorld );

	DeleteNames( iWorld );

	//if( world->spacetree )
	//{
	//	Log( "Spaces remained on the tree..." );
	//	DeleteSpaceTree( &world->spacetree );
	//}
}
Example #20
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;
}
Example #21
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;
}
Example #22
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
}
Example #23
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;
}
Example #24
0
int SrvrSaveWorldToFile( FILE *pFile, INDEX iWorld )
{
	PWORLD pWorld = GetSetMember( WORLD, &g.worlds, iWorld );
	int sz = 0, tmp, cnt;
	int worldpos;
	int linesize, linepos;
	int nlines;
	PFLATLAND_MYLINESEG *linearray;
	int wallsize, wallpos;
	int nwalls;
	PWALL *wallarray;
	int sectorsize, sectorpos;
	int nsectors;
	PSECTOR *sectorarray;
	int namesize, namepos;
	int nnames;
	PNAME *namearray;
	int texturesize, texturepos;
	int ntextures;
	PFLATLAND_TEXTURE *texturearray;

#ifdef LOG_SAVETIMING
	uint32_t begin, start = GetTickCount();
	begin = start;
#endif
	linearray   = GetLinearLineArray( pWorld->lines, &nlines );
	wallarray   = GetLinearWallArray( pWorld->walls, &nwalls );
	sectorarray = GetLinearSectorArray( pWorld->sectors, &nsectors );
	namearray   = GetLinearNameArray( pWorld->names, &nnames );
	texturearray = GetLinearTextureArray( pWorld->textures, &ntextures );

#ifdef LOG_SAVETIMING
	Log1( "Built arrays: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	fwrite( "FLAT", 1, 4, pFile );
	//-------------------------------------------------
	// Version 0: did not save "FLAT" tag - assumes version 1 info
	// Version 1: had extra nInto - sector reference for wall links...
	// Version 2: didn't compute sector origins, need to fix 
	// Version 3: lacked having sector ID saved
	// Version 4: lacked a text name per sector
	//   new section introduced - NAME ... referenced name sets
	//   for (walls?) and sectors.
	// version 5: lacked a count of lines in names - assume one line. 
	// Version 6: added flags to name type
	// version 7: (see version 8 notes for changes from 7)
	// version 8: Added Texture information (default texture for prior versions)
	//            internal added sector point sets (computed on load)
	//            internal added line reference count (computed on load)
	//            added current grid sizes/ grid color (saved in flatland)
	// version 9: flipped image upside down so +Y is 'top' and -Y is 'low'
	//            any version less than this must mult Y by -1 on load.
	// version 10: going to add sizes per section(added), and consider
	//            splitting off 'section' handlers keyed on 
	//            section names - will need coordination though :/ .. not added
	// (current - no changes to save or load)
	// version 11: 
	//-------------------------------------------------
	tmp = CURRENTSAVEVERSION;  

	// writesize( pWorld )
	worldpos = ftell( pFile );
	fwrite( &sz, 1, sizeof( sz ), pFile ); 
	sz = 0;

	Log1( "Saving version %d", tmp );
	sz += fwrite( &tmp, 1, sizeof( tmp ), pFile );

	//----- write lines -------
	sz += fwrite( "LINE", 1, 4, pFile );
	WriteSize( line );
	linesize += fwrite( &nlines, 1, sizeof(nlines), pFile );
	for( cnt = 0; cnt < nlines; cnt++ )
	{
		LINESEGFILE lsf;
      SetRay( &lsf.r, &linearray[cnt]->r );
      lsf.start = linearray[cnt]->dFrom;
      lsf.end   = linearray[cnt]->dTo;
		linesize += fwrite( &lsf, 1, sizeof( LINESEGFILE ), pFile );
	}
	UpdateSize( line );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Lines: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "WALL", 1, 4, pFile );
	WriteSize( wall );
	wallsize += fwrite( &nwalls, 1, sizeof(nwalls), pFile );
	for( cnt = 0; cnt < nwalls; cnt++ )
	{
		FILEWALLV2 WriteWall;
		PWALL pwall = wallarray[cnt];
		WriteWall.flags = pwall->flags;

		tmp = WriteWall.nSector = FindInArray( (POINTER*)sectorarray, nsectors, GetUsedSetMember( SECTOR, &pWorld->sectors, pwall->iSector ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced sector... save will fail %d", cnt );

		tmp = WriteWall.nLine = FindInArray( (POINTER*)linearray, nlines, GetUsedSetMember( FLATLAND_MYLINESEG, &pWorld->lines, pwall->iLine ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced line... save will fail %d", cnt );

		if( pwall->iWallInto != INVALID_INDEX )
		{
			tmp = WriteWall.nWallInto = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallInto ) );
			if( tmp < 0 )
				Log1( "Failed to find referenced wall into... save will fail %d", cnt );
		}
		else
			WriteWall.nWallInto = -1;

		tmp = WriteWall.nWallStart = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallStart ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced starting wall... save will fail %d", cnt );

		tmp = WriteWall.nWallEnd = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, pwall->iWallEnd ) );
		if( tmp < 0 )
			Log1( "Failed to find referenced ending wall... save will fail %d", cnt );

		wallsize += fwrite( &WriteWall, 1, sizeof( WriteWall ), pFile );	
	}
	UpdateSize( wall );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Walls: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "SECT", 1, 4, pFile );
	WriteSize( sector );
	sectorsize += fwrite( &nsectors, 1, sizeof( nsectors ), pFile );
	for( cnt = 0; cnt < nsectors; cnt++ )
	{
		FILESECTORV8 WriteSector;
		WriteSector.nName = FindInArray( (POINTER*)namearray, nnames, GetUsedSetMember( NAME, &pWorld->names, sectorarray[cnt]->iName ) );
		//WriteSector.nID = sectorarray[cnt]->nID;
		WriteSector.flags = sectorarray[cnt]->flags;
		SetRay( &WriteSector.r, &sectorarray[cnt]->r );
		tmp = WriteSector.nwall = FindInArray( (POINTER*)wallarray, nwalls, GetUsedSetMember( WALL, &pWorld->walls, sectorarray[cnt]->iWall ) );
		if( tmp < 0 )
			Log1( "Failed to find wall referenced by sector.. save failing %d", cnt );
		WriteSector.nTexture = FindInArray( (POINTER*)texturearray, ntextures, GetUsedSetMember( FLATLAND_TEXTURE, &pWorld->textures, sectorarray[cnt]->iTexture ) );
		if( tmp < 0 )
			Log1( "Failed to find texture referenced by sector.. save failing %d", cnt );
		sectorsize += fwrite( &WriteSector, 1, sizeof( WriteSector ), pFile );
	}
	UpdateSize( sector );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Sectors: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "NAME", 1, 4, pFile );
	WriteSize( name );
	namesize += fwrite( &nnames, 1, sizeof( nnames ), pFile );
	for( cnt = 0; cnt < nnames; cnt++ )
	{
		int l;
		uint16_t lines = namearray[cnt]->lines;
		namesize += fwrite( &namearray[cnt]->flags, 1, sizeof( namearray[cnt]->flags ), pFile );
		namesize += fwrite( &lines, 1, sizeof( lines ), pFile );
		for( l = 0; l < lines; l++ )
		{
			namesize += fwrite( &namearray[cnt]->name[l].length, 1, sizeof( namearray[cnt]->name[l].length ), pFile );
			namesize += fwrite( namearray[cnt]->name[l].name, 1, namearray[cnt]->name[l].length, pFile );
		}
	}
	UpdateSize( name );
#ifdef LOG_SAVETIMING
	Log1( "Wrote Names: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	sz += fwrite( "TEXT", 1, 4, pFile );

	WriteSize( texture );

	texturesize += fwrite( &ntextures, 1, sizeof( ntextures ), pFile );
	for( cnt = 0; cnt < ntextures; cnt++ )
	{
		char flag;
		int nName = FindInArray( (POINTER*)namearray, nnames, GetUsedSetMember( NAME, &pWorld->names, texturearray[cnt]->iName ) );
		texturesize += fwrite( &nName, 1, sizeof( nName ), pFile );
		flag = texturearray[cnt]->flags.bColor;
		texturesize += fwrite( &flag, 1, sizeof( flag ), pFile );
		// if flag is set - write cdata 
		if( flag )
		{
			texturesize += fwrite( &texturearray[cnt]->data.color, 1, sizeof( CDATA ), pFile );
		}				
	}

	UpdateSize( texture );

#ifdef LOG_SAVETIMING
	Log1( "Wrote Textures: %d", GetTickCount() - start );
	start = GetTickCount();
#endif
	{
		int endpos;
		endpos = ftell( pFile );
		fseek( pFile, worldpos, SEEK_SET );
		fwrite( &sz, 1, sizeof( sz ), pFile );
		fseek( pFile, endpos, SEEK_SET );
	}

#ifdef LOG_SAVETIMING
	Log1( "Wrote File: %d", GetTickCount() - begin );
#endif

	Release( texturearray );
	Release( namearray );
	Release( sectorarray );
	Release( wallarray );
	Release( linearray );
#ifdef LOG_SAVETIMING
	Log1( "Released arrays: %d", GetTickCount() - start );
#endif

	return sz;
}
Example #25
0
void GetTextureData( INDEX iWorld, INDEX iTexture, PFLATLAND_TEXTURE *pptexture )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	(*pptexture) = GetSetMember( FLATLAND_TEXTURE, &world->textures, iTexture );
}
Example #26
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;
}
Example #27
0
void GetNameData( INDEX iWorld, INDEX iName, PNAME *name )
{
	PWORLD world = GetSetMember( WORLD, &g.worlds, iWorld );
	(*name) = GetSetMember( NAME, &world->names, iName );
}