//========================================================================================
// ReadChunkData
//========================================================================================
geBoolean ReadChunkData(GBSP_Chunk *Chunk, void *Data, geVFile *f)
{
	if (geVFile_Read(f, Data, Chunk->Size * Chunk->Elements) != GE_TRUE)
		return GE_FALSE;

	return GE_TRUE;
}
Example #2
0
DirTree *DirTree_CreateFromFile(geVFile *File)
{
	DirTree *		Res;
	DirTree_Header	Header;
	long			StartPosition;
	long			EndPosition;
	
	if	(geVFile_Tell(File, &StartPosition) == GE_FALSE)
		return GE_FALSE;

	if	(geVFile_Read(File, &Header, sizeof(Header)) == GE_FALSE)
		return NULL;

	if	(Header.Signature != DIRTREE_FILE_SIGNATURE)
		return GE_FALSE;

	if	(ReadTree(File, &Res) == GE_FALSE)
		return NULL;

	geVFile_Tell(File, &EndPosition);
	if	(Header.Size != EndPosition - StartPosition)
	{
		DirTree_Destroy(Res);
		return NULL;
	}

	return Res;
}
Example #3
0
//static	BOOL GetSoundData( char* Name, unsigned char** dataPtr)
static	BOOL GetSoundData( geVFile *File, unsigned char** dataPtr)
{
//	FILE * f;
	int32 Size;
	uint8 *data;
//	int32		CurPos;

#if 0
	f = fopen(Name, "rb");
	
	if (!f)
	{
		geErrorLog_Add(GE_ERR_FILE_OPEN_ERROR, NULL);
		return FALSE;
	}
#endif

#if 0
	CurPos = ftell (f);				// Save the startinf pos into this function
	fseek (f, 0, SEEK_END);			// Seek to end
	Size = ftell (f);				// Get End (this will be the size)
	fseek (f, CurPos, SEEK_SET);	// Restore file position
#endif

	if	(geVFile_Size(File, &Size) == GE_FALSE)
		return FALSE;

	data = geRam_Allocate(Size);

	if (!data) 
	{
		geErrorLog_Add(GE_ERR_OUT_OF_MEMORY, NULL);
		return FALSE;
	}
	
	if	(geVFile_Read(File, data, Size) == GE_FALSE)
	{
		geRam_Free(data);
		return FALSE;
	}

//	fread(data, Size, 1, f);

//	fclose(f);
	*dataPtr = data;
	return( TRUE );
}
Example #4
0
//========================================================================================
//	ReadChunk
//========================================================================================
static geBoolean ReadChunk(GBSP_BSPData *BSP, GBSP_Chunk *Chunk, geVFile *f)
{
	int	i;

	if (geVFile_Read(f, Chunk, sizeof(GBSP_Chunk)) == GE_FALSE)
	{
		return GE_FALSE;
	}

	switch(Chunk->Type)
	{
		case GBSP_CHUNK_HEADER:
		{
//		printf("GBSP_CHUNK_HEADER\n");
			if (sizeof(GBSP_Header) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			if (!ReadChunkData(Chunk, (void*)&BSP->GBSPHeader, f))
				return GE_FALSE;
			if (strcmp(BSP->GBSPHeader.TAG, "GBSP"))
			{
				geErrorLog_Add(GE_ERR_INVALID_BSP_TAG, NULL);
				return GE_FALSE;
			}
			if (BSP->GBSPHeader.Version != GBSP_VERSION)
			{
				geErrorLog_Add(GE_ERR_INVALID_BSP_VERSION, NULL);
				return GE_FALSE;
			}
			break;
		}
		case GBSP_CHUNK_MODELS:
		{
//		printf("GBSP_CHUNK_MODELS\n");
			if (sizeof(GFX_Model) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXModels = Chunk->Elements;
			BSP->GFXModels = GE_RAM_ALLOCATE_ARRAY(GFX_Model, BSP->NumGFXModels);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXModels, f))
				return GE_FALSE;
			// Walk the models and zero out the motion pointers
			for	(i = 0; i < BSP->NumGFXModels; i++)
				BSP->GFXModels[i].Motion = NULL;
			break;
		}
		case GBSP_CHUNK_NODES:
		{
//		printf("GBSP_CHUNK_NODES\n");
			if (sizeof(GFX_Node) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXNodes = Chunk->Elements;
			BSP->GFXNodes = (GFX_Node*)geRam_Allocate(sizeof(GFX_Node)*BSP->NumGFXNodes);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXNodes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_BNODES:
		{
//		printf("GBSP_CHUNK_BNODES\n");
			if (sizeof(GFX_BNode) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXBNodes = Chunk->Elements;
			if (BSP->NumGFXBNodes)
			{
				BSP->GFXBNodes = (GFX_BNode*)geRam_Allocate(sizeof(GFX_BNode)*BSP->NumGFXBNodes);
				if (!ReadChunkData(Chunk, (void*)BSP->GFXBNodes, f))
					return GE_FALSE;
			}
			break;
		}
		case GBSP_CHUNK_LEAFS:
		{
//		printf("GBSP_CHUNK_LEAFS\n");
			if (sizeof(GFX_Leaf) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXLeafs = Chunk->Elements;
			BSP->GFXLeafs = (GFX_Leaf*)geRam_Allocate(sizeof(GFX_Leaf)*BSP->NumGFXLeafs);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXLeafs, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_CLUSTERS:
		{
//		printf("GBSP_CHUNK_CLUSTERS\n");
			if (sizeof(GFX_Cluster) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXClusters = Chunk->Elements;
			//BSP->GFXClusters = GE_RAM_ALLOCATE_ARRAY(GFX_Cluster, BSP->NumGFXClusters);
			BSP->GFXClusters = (GFX_Cluster*)geRam_Allocate(sizeof(GFX_Cluster)*BSP->NumGFXClusters);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXClusters, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_AREAS:
		{
//		printf("GBSP_CHUNK_AREAS\n");
			if (sizeof(GFX_Area) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXAreas = Chunk->Elements;
			BSP->GFXAreas = GE_RAM_ALLOCATE_ARRAY(GFX_Area, BSP->NumGFXAreas);
			if (!ReadChunkData(Chunk, BSP->GFXAreas, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_AREA_PORTALS:
		{
//		printf("GBSP_CHUNK_AREA_PORTALS\n");
			if (sizeof(GFX_AreaPortal) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXAreaPortals = Chunk->Elements;
			BSP->GFXAreaPortals = GE_RAM_ALLOCATE_ARRAY(GFX_AreaPortal, BSP->NumGFXAreaPortals);
			if (!ReadChunkData(Chunk, BSP->GFXAreaPortals, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_PORTALS:
		{
//		printf("GBSP_CHUNK_PORTALS\n");
			if (sizeof(GFX_Portal) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXPortals = Chunk->Elements;
			BSP->GFXPortals = (GFX_Portal*)geRam_Allocate(sizeof(GFX_Portal)*BSP->NumGFXPortals);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXPortals, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_PLANES:
		{
//		printf("GBSP_CHUNK_PLANES\n");
			if (sizeof(GFX_Plane) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXPlanes = Chunk->Elements;
			BSP->GFXPlanes = (GFX_Plane*)geRam_Allocate(sizeof(GFX_Plane)*BSP->NumGFXPlanes);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXPlanes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_FACES:
		{
//		printf("GBSP_CHUNK_FACES\n");
			if (sizeof(GFX_Face) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXFaces = Chunk->Elements;
			BSP->GFXFaces = (GFX_Face*)geRam_Allocate(sizeof(GFX_Face)*BSP->NumGFXFaces);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXFaces, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LEAF_FACES:
		{
//		printf("GBSP_CHUNK_LEAF_FACES\n");
			if (sizeof(int32) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXLeafFaces = Chunk->Elements;
			BSP->GFXLeafFaces = (int32*)geRam_Allocate(sizeof(int32)*BSP->NumGFXLeafFaces);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXLeafFaces, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LEAF_SIDES:
		{
//		printf("GBSP_CHUNK_LEAF_SIDES\n");
			if (sizeof(GFX_LeafSide) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXLeafSides = Chunk->Elements;
			BSP->GFXLeafSides = (GFX_LeafSide*)geRam_Allocate(sizeof(GFX_LeafSide)*BSP->NumGFXLeafSides);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXLeafSides, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VERTS:
		{
//		printf("GBSP_CHUNK_VERTS\n");
			if (sizeof(geVec3d) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXVerts = Chunk->Elements;
			BSP->GFXVerts = (geVec3d*)geRam_Allocate(sizeof(geVec3d)*BSP->NumGFXVerts);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXVerts, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VERT_INDEX:
		{
//		printf("GBSP_CHUNK_VERT_INDEX\n");
			if (sizeof(int32) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}

			BSP->NumGFXVertIndexList = Chunk->Elements;
			BSP->GFXVertIndexList = (int32*)geRam_Allocate(sizeof(int32)*BSP->NumGFXVertIndexList);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXVertIndexList, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_RGB_VERTS:
		{
//		printf("GBSP_CHUNK_RGB_VERTS\n");
			if (sizeof(geVec3d) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXRGBVerts = Chunk->Elements;
			BSP->GFXRGBVerts = (geVec3d*)geRam_Allocate(sizeof(geVec3d)*BSP->NumGFXRGBVerts);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXRGBVerts, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXINFO:
		{
//		printf("GBSP_CHUNK_TEXINFO\n");
			if (sizeof(GFX_TexInfo) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXTexInfo = Chunk->Elements;
			BSP->GFXTexInfo = (GFX_TexInfo*)geRam_Allocate(sizeof(GFX_TexInfo)*BSP->NumGFXTexInfo);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXTexInfo, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXTURES:
		{
//		printf("GBSP_CHUNK_TEXTURES\n");
			if (sizeof(GFX_Texture) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXTextures = Chunk->Elements;
			BSP->GFXTextures = (GFX_Texture*)geRam_Allocate(sizeof(GFX_Texture)*BSP->NumGFXTextures);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXTextures, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXDATA:
		{
//		printf("GBSP_CHUNK_TEXDATA\n");
			if (sizeof(uint8) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXTexData = Chunk->Elements;
			BSP->GFXTexData = (uint8*)geRam_Allocate(sizeof(uint8)*BSP->NumGFXTexData);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXTexData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_ENTDATA:
		{
//		printf("GBSP_CHUNK_ENTDATA\n");
			if (sizeof(uint8) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXEntData = Chunk->Elements;
			BSP->GFXEntData = (uint8*)geRam_Allocate(sizeof(uint8)*BSP->NumGFXEntData);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXEntData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LIGHTDATA:
		{
//		printf("GBSP_CHUNK_LIGHTDATA\n");
			if (sizeof(uint8) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXLightData = Chunk->Elements;
			BSP->GFXLightData = (uint8*)geRam_Allocate(sizeof(uint8)*BSP->NumGFXLightData);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXLightData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VISDATA:
		{
//		printf("GBSP_CHUNK_VISDATA\n");
			if (sizeof(uint8) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXVisData = Chunk->Elements;
			BSP->GFXVisData = (uint8*)geRam_Allocate(sizeof(uint8)*BSP->NumGFXVisData);
			if (!ReadChunkData(Chunk, (void*)BSP->GFXVisData, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_SKYDATA:
		{
//		printf("GBSP_CHUNK_SKYDATA\n");
			if (sizeof(GFX_SkyData) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			if (!ReadChunkData(Chunk, (void*)&BSP->GFXSkyData, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_PALETTES:
		{
//		printf("GBSP_CHUNK_PALETTES\n");
			if (sizeof(DRV_Palette) != Chunk->Size)
			{
				geErrorLog_Add(GE_ERR_BAD_BSP_FILE_CHUNK_SIZE, NULL);
				return GE_FALSE;
			}
			BSP->NumGFXPalettes = Chunk->Elements;
			BSP->GFXPalettes = (DRV_Palette*)geRam_Allocate(sizeof(DRV_Palette)*BSP->NumGFXPalettes);
			if	(BSP->GFXPalettes == NULL)
				return GE_FALSE;
			if (!ReadChunkData(Chunk, (void*)BSP->GFXPalettes, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_MOTIONS:
		{
//		printf("GBSP_CHUNK_MOTIONS\n");
			return LoadMotions(BSP, f);
		}

		case GBSP_CHUNK_END:
		{
//		printf("GBSP_CHUNK_END\n");
			break;
		}
		default:
//		printf("Don't know what this chunk is\n");
			return GE_FALSE;
	}

	return TRUE;
}
Example #5
0
//========================================================================================
// ReadChunkData
//========================================================================================
static geBoolean ReadChunkData(GBSP_Chunk *Chunk, void *Data, geVFile *f)
{
	return geVFile_Read(f, Data, Chunk->Size * Chunk->Elements);
}
//========================================================================================
//	ReadChunk
//========================================================================================
geBoolean ReadChunk(GBSP_Chunk *Chunk, geVFile *f)
{
	if (geVFile_Read(f, Chunk, sizeof(GBSP_Chunk)) != GE_TRUE)
	{
		return GE_FALSE;
	}

#ifdef	DEBUGCHUNKS
	if	(Chunk->Type != GBSP_CHUNK_END)
	{
		long	Pos;

		geVFile_Tell(f, &Pos);
		GHook.Printf(" ReadChunk: @%08x '%s', %d elements of %d size\n", Pos,
		ChunkNames[Chunk->Type], Chunk->Elements, Chunk->Size);
	}
	else
	{
		long	Pos;

		geVFile_Tell(f, &Pos);
		GHook.Printf(" ReadChunk: @%08x 'GBSP_CHUNK_END', %d elements of %d size\n", Pos, Chunk->Elements, Chunk->Size);
	}
#endif

	switch(Chunk->Type)
	{
		case GBSP_CHUNK_HEADER:
		{
			if (!ReadChunkData(Chunk, (void*)&GBSPHeader, f))
				return GE_FALSE;
			if (strcmp(GBSPHeader.TAG, "GBSP"))
				return GE_FALSE;
			if (GBSPHeader.Version != GBSP_VERSION)
				return GE_FALSE;

			break;
		}
		case GBSP_CHUNK_MODELS:
		{
			NumGFXModels = Chunk->Elements;
			GFXModels = GE_RAM_ALLOCATE_ARRAY(GFX_Model, NumGFXModels);
			if (!ReadChunkData(Chunk, GFXModels, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_NODES:
		{
			NumGFXNodes = Chunk->Elements;
			GFXNodes = GE_RAM_ALLOCATE_ARRAY(GFX_Node,NumGFXNodes);
			if (!ReadChunkData(Chunk, GFXNodes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_BNODES:
		{
			NumGFXBNodes = Chunk->Elements;
			GFXBNodes = GE_RAM_ALLOCATE_ARRAY(GFX_BNode,NumGFXBNodes);
			if (!ReadChunkData(Chunk, GFXBNodes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LEAFS:
		{
			NumGFXLeafs = Chunk->Elements;
			GFXLeafs = GE_RAM_ALLOCATE_ARRAY(GFX_Leaf,NumGFXLeafs);
			if (!ReadChunkData(Chunk, GFXLeafs, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_CLUSTERS:
		{
			NumGFXClusters = Chunk->Elements;

			GFXClusters = GE_RAM_ALLOCATE_ARRAY(GFX_Cluster,NumGFXClusters);
			if (!ReadChunkData(Chunk, GFXClusters, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_AREAS:
		{
			NumGFXAreas = Chunk->Elements;
			GFXAreas = GE_RAM_ALLOCATE_ARRAY(GFX_Area,NumGFXAreas);
			if (!ReadChunkData(Chunk, GFXAreas, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_AREA_PORTALS:
		{
			NumGFXAreaPortals = Chunk->Elements;
			GFXAreaPortals = GE_RAM_ALLOCATE_ARRAY(GFX_AreaPortal,NumGFXAreaPortals);
			if (!ReadChunkData(Chunk, GFXAreaPortals, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_PORTALS:
		{
			NumGFXPortals = Chunk->Elements;
			GFXPortals = GE_RAM_ALLOCATE_ARRAY(GFX_Portal,NumGFXPortals);
			if (!ReadChunkData(Chunk, GFXPortals, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_PLANES:
		{
			NumGFXPlanes = Chunk->Elements;
			GFXPlanes = GE_RAM_ALLOCATE_ARRAY(GFX_Plane,NumGFXPlanes);
			if (!ReadChunkData(Chunk, GFXPlanes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_FACES:
		{
			NumGFXFaces = Chunk->Elements;
			GFXFaces = GE_RAM_ALLOCATE_ARRAY(GFX_Face,NumGFXFaces);
			if (!ReadChunkData(Chunk, GFXFaces, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LEAF_FACES:
		{
			NumGFXLeafFaces = Chunk->Elements;
			GFXLeafFaces = GE_RAM_ALLOCATE_ARRAY(int32,NumGFXLeafFaces);
			if (!ReadChunkData(Chunk, GFXLeafFaces, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LEAF_SIDES:
		{
			NumGFXLeafSides = Chunk->Elements;

			GFXLeafSides = GE_RAM_ALLOCATE_ARRAY(GFX_LeafSide,NumGFXLeafSides);
			if (!ReadChunkData(Chunk, GFXLeafSides, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VERTS:
		{
			NumGFXVerts = Chunk->Elements;
			GFXVerts = GE_RAM_ALLOCATE_ARRAY(geVec3d,NumGFXVerts);
			if (!ReadChunkData(Chunk, GFXVerts, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VERT_INDEX:
		{
			NumGFXVertIndexList = Chunk->Elements;
			GFXVertIndexList = GE_RAM_ALLOCATE_ARRAY(int32,NumGFXVertIndexList);
			if (!ReadChunkData(Chunk, GFXVertIndexList, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_RGB_VERTS:
		{
			NumGFXRGBVerts = Chunk->Elements;
			GFXRGBVerts = GE_RAM_ALLOCATE_ARRAY(geVec3d,NumGFXRGBVerts);
			if (!ReadChunkData(Chunk, GFXRGBVerts, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXINFO:
		{
			NumGFXTexInfo = Chunk->Elements;
			GFXTexInfo = GE_RAM_ALLOCATE_ARRAY(GFX_TexInfo,NumGFXTexInfo);
			if (!ReadChunkData(Chunk, GFXTexInfo, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXTURES:
		{
			NumGFXTextures = Chunk->Elements;
			GFXTextures = GE_RAM_ALLOCATE_ARRAY(GFX_Texture,NumGFXTextures);
			if (!ReadChunkData(Chunk, GFXTextures, f))
				return GE_FALSE;
			break;
		}

		case GBSP_CHUNK_TEXDATA:
		{
//	GHook.Printf(" Reading TEXDATA: %d bytes of %d size \n", Chunk->Elements, Chunk->Size);
			NumGFXTexData = Chunk->Elements;
			GFXTexData = GE_RAM_ALLOCATE_ARRAY(uint8,NumGFXTexData);
			if (!ReadChunkData(Chunk, GFXTexData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_ENTDATA:
		{
			NumGFXEntData = Chunk->Elements;
			GFXEntData = GE_RAM_ALLOCATE_ARRAY(uint8,NumGFXEntData);
			if (!ReadChunkData(Chunk, GFXEntData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_LIGHTDATA:
		{
			NumGFXLightData = Chunk->Elements;
			GFXLightData = GE_RAM_ALLOCATE_ARRAY(uint8,NumGFXLightData);
			if (!ReadChunkData(Chunk, GFXLightData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_VISDATA:
		{
			NumGFXVisData = Chunk->Elements;
			GFXVisData = GE_RAM_ALLOCATE_ARRAY(uint8,NumGFXVisData);
			if (!ReadChunkData(Chunk, GFXVisData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_SKYDATA:
		{
			if (!ReadChunkData(Chunk, &GFXSkyData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_PALETTES:
		{
			NumGFXPalettes = Chunk->Elements;
			GFXPalettes = GE_RAM_ALLOCATE_ARRAY(DRV_Palette,NumGFXPalettes);
			if (!GFXPalettes)
				return GE_FALSE;
			if (!ReadChunkData(Chunk, GFXPalettes, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_MOTIONS:
		{
			//	GHook.Printf(" Reading motions: %d Elements of %d size\n", Chunk->Elements, Chunk->Size);
			NumGFXMotionBytes = Chunk->Elements;
			GFXMotionData = GE_RAM_ALLOCATE_ARRAY(uint8,NumGFXMotionBytes);
			if (!ReadChunkData(Chunk, GFXMotionData, f))
				return GE_FALSE;
			break;
		}
		case GBSP_CHUNK_END:
		{
			break;
		}
		default:
			return GE_FALSE;
	}

	return GE_TRUE;
}
Example #7
0
//=======================================================================================
//	LoadPortalFile
//=======================================================================================
geBoolean LoadPortalFile(char *FileName)
{
	int32		LeafFrom, LeafTo;
	VIS_Portal	*pPortal;
	VIS_Leaf	*pLeaf;
	GBSP_Poly	*pPoly;
	int32		i, NumVerts;
	char		TAG[13];
	geVFile		*f;

	pPoly = NULL;

	// open the file
	f = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, FileName, NULL, GE_VFILE_OPEN_READONLY);

	if (!f)		// opps
	{
		GHook.Error("LoadPortalFile:  Could not open %s for reading.\n", FileName);
		goto ExitWithError;
	}
	
	// 
	//	Check the TAG
	//
	if (geVFile_Read(f, TAG, sizeof(char) * 12) != GE_TRUE)
	{
		GHook.Error("LoadPortalFile:  Error reading portal file TAG.\n");
		goto ExitWithError;
	}

	if (strncmp(TAG, "GBSP_PRTFILE", 12))
	{
		GHook.Error("LoadPortalFile:  %s is not a GBSP Portal file.\n", FileName);
		goto ExitWithError;
	}

	//
	//	Get the number of portals
	//
	if (geVFile_Read(f, &NumVisPortals, sizeof(int32)) != GE_TRUE)
	{
		GHook.Error("LoadPortalFile:  Error reading NumVisPortals.\n");
		goto ExitWithError;
	}

	if (NumVisPortals >= MAX_TEMP_PORTALS)
	{
		GHook.Error("LoadPortalFile:  Max portals for temp buffers.\n");
		goto ExitWithError;
	}
	
	VisPortals = GE_RAM_ALLOCATE_ARRAY(VIS_Portal,NumVisPortals);
	
	if (!VisPortals)
	{
		GHook.Error("LoadPortalFile:  Out of memory for VisPortals.\n");
		goto ExitWithError;
	}
	
	memset(VisPortals, 0, sizeof(VIS_Portal)*NumVisPortals);

	VisSortedPortals = GE_RAM_ALLOCATE_ARRAY(pVIS_Portal,NumVisPortals);
	
	if (!VisSortedPortals)
	{
		GHook.Error("LoadPortalFile:  Out of memory for VisSortedPortals.\n");
		goto ExitWithError;
	}

	//
	//	Get the number of leafs
	//
	if (geVFile_Read(f, &NumVisLeafs, sizeof(int32)) != GE_TRUE)
	{
		GHook.Error("LoadPortalFile:  Error reading NumVisLeafs.\n");
		goto ExitWithError;
	}

	if (NumVisLeafs > NumGFXLeafs)
		goto ExitWithError;
	
	VisLeafs = GE_RAM_ALLOCATE_ARRAY(VIS_Leaf,NumVisLeafs);
	if (!VisLeafs)
	{
		GHook.Error("LoadPortalFile:  Out of memory for VisLeafs.\n");
		goto ExitWithError;
	}

	memset(VisLeafs, 0, sizeof(VIS_Leaf)*NumVisLeafs);
	
	//
	//	Load in the portals
	//
	for (i=0; i< NumVisPortals; i++)
	{
		if (geVFile_Read(f, &NumVerts, sizeof(int32)) != GE_TRUE)
		{
			GHook.Error("LoadPortalFile:  Error reading NumVerts.\n");
			goto ExitWithError;
		}

		pPoly = AllocPoly(NumVerts);

		if (!pPoly)
			goto ExitWithError;

		if (geVFile_Read(f, pPoly->Verts, sizeof(geVec3d) * NumVerts) != GE_TRUE)
		{
			GHook.Error("LoadPortalFile:  Error reading portal vertices.\n");
			goto ExitWithError;
		}
		
		if (geVFile_Read(f, &LeafFrom, sizeof(int32)) != GE_TRUE)
		{
			GHook.Error("LoadPortalFile:  Error reading portal LeafFrom.\n");
			goto ExitWithError;
		}
		
		if (geVFile_Read(f, &LeafTo, sizeof(int32)) != GE_TRUE)
		{
			GHook.Error("LoadPortalFile:  Error reading portal LeafTo.\n");
			goto ExitWithError;
		}

		if (LeafFrom >= NumVisLeafs || LeafFrom < 0)
		{
			GHook.Error("LoadPortalFile:  Invalid LeafFrom: %i.\n", LeafFrom);
			goto ExitWithError;
		}

		if (LeafTo >= NumVisLeafs || LeafTo < 0)
		{
			GHook.Error("LoadPortalFile:  Invalid LeafTo: %i.\n", LeafTo);
			goto ExitWithError;
		}

		pLeaf = &VisLeafs[LeafFrom];
		pPortal = &VisPortals[i];

		pPortal->Poly = pPoly;
		pPortal->Leaf = LeafTo;
		PlaneFromVerts(pPoly->Verts, &pPortal->Plane);
		
		pPortal->Next = pLeaf->Portals;
		pLeaf->Portals = pPortal;

		CalcPortalInfo(pPortal);
	}
	
	NumVisLeafBytes = ((NumVisLeafs+63)&~63) >> 3;
	NumVisPortalBytes = ((NumVisPortals+63)&~63) >> 3;

	NumVisPortalLongs = NumVisPortalBytes/sizeof(uint32);
	NumVisLeafLongs = NumVisLeafBytes/sizeof(uint32);

	geVFile_Close(f);

	return GE_TRUE;

	// ==== ERROR ===
	ExitWithError:
	{
		if (f)
			geVFile_Close(f);

		if (VisPortals)
			geRam_Free(VisPortals);
		if (VisSortedPortals)
			geRam_Free(VisSortedPortals);
		if (VisLeafs)
			geRam_Free(VisLeafs);

		if (pPoly)
			FreePoly(pPoly);

		VisPortals = NULL;
		VisSortedPortals = NULL;
		VisLeafs = NULL;
		pPoly = NULL;

		return GE_FALSE;
	}
}
/* ------------------------------------------------------------------------------------ */
CAnimGif::CAnimGif(const char *szFile, int fileformat)
{
	long Size;

	GifSize = GlobalColorSize = 0;
	Active = false;
	Texture = false;
	GlobalColorTable = NULL;

	if(!CCD->OpenRFFile(&MainFS, fileformat, szFile, GE_VFILE_OPEN_READONLY))
		return;

	geVFile_Size(MainFS, &Size);

	Palette = geBitmap_Palette_Create(GE_PIXELFORMAT_32BIT_XRGB, 256);
	theBmp = NULL;
	pcGif = NULL;

	if(geVFile_Read(MainFS, buffer, 13) == GE_TRUE)
	{
		if(!strncmp((char *)buffer, "GIF89a", 6) || !strncmp((char *)buffer, "GIF87a", 6))
		{
			nWidth = *(WORD*)(buffer+6);
			nWidth = ((nWidth-1)|0x3)+1;
			nHeight = *(WORD*)(buffer+8);
			BackgroundColor = *(buffer+11);

			if(buffer[10]&0x80)
			{
				GlobalColorSize = 0x01<<((buffer[10]&0x07)+1);
				GlobalColorTable = new BYTE[3*GlobalColorSize];
				if(geVFile_Read(MainFS, GlobalColorTable, 3*GlobalColorSize) != GE_TRUE)
				{
					delete[] GlobalColorTable;
					geVFile_Close(MainFS);
					geBitmap_Palette_Destroy(&Palette);
					return;
				}
			}

			GifSize = Size-3*GlobalColorSize-12;
			pcGifTrack=pcGif = new BYTE[GifSize];

			if(geVFile_Read(MainFS, pcGif, GifSize) == GE_TRUE)
			{
				TotalReadByte = 0;
				FirstFrame = true;

				theBmp = geBitmap_Create(nWidth, nHeight, 1, GE_PIXELFORMAT_8BIT);
				geBitmap_SetPreferredFormat(theBmp, GE_PIXELFORMAT_8BIT);
				geEngine_AddBitmap(CCD->Engine()->Engine(), theBmp);
				geBitmap_GetInfo(theBmp,&Info,NULL);
				geBitmap_ClearMips(theBmp);

				if(GetImage(false))
				{
					Active = true;
				}
			}
		}
	}

	geVFile_Close(MainFS);
	return;
}
Example #9
0
static	geBoolean	ReadTree(geVFile *File, DirTree **TreePtr)
{
	int			Terminator;
	int			Length;
	DirTree *	Tree;

	if	(geVFile_Read(File, &Terminator, sizeof(Terminator)) == GE_FALSE)
		return GE_FALSE;

	if	(Terminator == DIRTREE_LIST_TERMINATED)
	{
		*TreePtr = NULL;
		return GE_TRUE;
	}

	Tree = geRam_Allocate(sizeof(*Tree));
	if	(!Tree)
		return GE_FALSE;
	memset(Tree, 0, sizeof(*Tree));

	// Read the name
	if	(geVFile_Read(File, &Length, sizeof(Length)) == GE_FALSE)
		goto fail;

	assert(Length > 0);
	Tree->Name = geRam_Allocate(Length);
	if	(!Tree->Name)
	{
		geRam_Free(Tree);
		return GE_FALSE;
	}
	
	if	(geVFile_Read(File, Tree->Name, Length) == GE_FALSE)
		goto fail;

//printf("Reading '%s'\n", Tree->Name);

	// Read out the attribute information
	if	(geVFile_Read(File, &Tree->Time, sizeof(Tree->Time)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->AttributeFlags, sizeof(Tree->AttributeFlags)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Size, sizeof(Tree->Size)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Offset, sizeof(Tree->Offset)) == GE_FALSE)
		goto fail;

	if	(geVFile_Read(File, &Tree->Hints.HintDataLength, sizeof(Tree->Hints.HintDataLength)) == GE_FALSE)
		goto fail;

	if	(Tree->Hints.HintDataLength != 0)
	{
		Tree->Hints.HintData = geRam_Allocate(Tree->Hints.HintDataLength);
		if	(!Tree->Hints.HintData)
			goto fail;
		//bug fix. someone got copy happy and forgot to remove the & from Tree->Hints.HintData
		if	(geVFile_Read(File, Tree->Hints.HintData, Tree->Hints.HintDataLength) == GE_FALSE)
			goto fail;
	}

//printf("Reading children of '%s'\n", Tree->Name);
	// Read the children
	if	(ReadTree(File, &Tree->Children) == GE_FALSE)
		goto fail;

//printf("Reading siblings of '%s'\n", Tree->Name);
	// Read the Siblings
	if	(ReadTree(File, &Tree->Siblings) == GE_FALSE)
		goto fail;

//DirTree_Dump(Tree);

	*TreePtr = Tree;

	return GE_TRUE;

fail:
	DirTree_Destroy(Tree);
	return GE_FALSE;
}