//================================================================================ // SaveGBSPFile //================================================================================ geBoolean SaveGBSPFile(char *FileName) { GBSP_ChunkData CurrentChunkData[] = { { GBSP_CHUNK_HEADER , sizeof(GBSP_Header) ,1 , &GBSPHeader}, { GBSP_CHUNK_MODELS , sizeof(GFX_Model) ,NumGFXModels , GFXModels }, { GBSP_CHUNK_NODES , sizeof(GFX_Node) ,NumGFXNodes , GFXNodes }, { GBSP_CHUNK_PORTALS , sizeof(GFX_Portal) ,NumGFXPortals , GFXPortals}, { GBSP_CHUNK_BNODES , sizeof(GFX_BNode) ,NumGFXBNodes , GFXBNodes }, { GBSP_CHUNK_PLANES , sizeof(GFX_Plane) ,NumGFXPlanes , GFXPlanes }, { GBSP_CHUNK_FACES , sizeof(GFX_Face) ,NumGFXFaces , GFXFaces }, { GBSP_CHUNK_AREAS , sizeof(GFX_Area) ,NumGFXAreas , GFXAreas }, { GBSP_CHUNK_AREA_PORTALS , sizeof(GFX_AreaPortal),NumGFXAreaPortals , GFXAreaPortals }, { GBSP_CHUNK_LEAF_FACES , sizeof(int32) ,NumGFXLeafFaces , GFXLeafFaces }, { GBSP_CHUNK_LEAF_SIDES , sizeof(GFX_LeafSide) ,NumGFXLeafSides , GFXLeafSides }, { GBSP_CHUNK_VERTS , sizeof(geVec3d) ,NumGFXVerts , GFXVerts }, { GBSP_CHUNK_VERT_INDEX , sizeof(int32) ,NumGFXVertIndexList , GFXVertIndexList}, { GBSP_CHUNK_RGB_VERTS , sizeof(geVec3d) ,NumGFXRGBVerts , GFXRGBVerts }, { GBSP_CHUNK_ENTDATA , sizeof(uint8) ,NumGFXEntData , GFXEntData}, { GBSP_CHUNK_TEXTURES , sizeof(GFX_Texture) ,NumGFXTextures , GFXTextures}, { GBSP_CHUNK_TEXINFO , sizeof(GFX_TexInfo) ,NumGFXTexInfo , GFXTexInfo}, { GBSP_CHUNK_TEXDATA , sizeof(uint8) ,NumGFXTexData , GFXTexData}, { GBSP_CHUNK_LIGHTDATA , sizeof(uint8) ,NumGFXLightData , GFXLightData}, { GBSP_CHUNK_LEAFS , sizeof(GFX_Leaf) ,NumGFXLeafs , GFXLeafs }, { GBSP_CHUNK_CLUSTERS , sizeof(GFX_Cluster) ,NumGFXClusters , GFXClusters}, { GBSP_CHUNK_VISDATA , sizeof(uint8) ,NumGFXVisData , GFXVisData}, { GBSP_CHUNK_SKYDATA , sizeof(GFX_SkyData) ,1 , &GFXSkyData}, { GBSP_CHUNK_PALETTES , sizeof(DRV_Palette) ,NumGFXPalettes , GFXPalettes}, { GBSP_CHUNK_MOTIONS , sizeof(uint8) ,NumGFXMotionBytes , GFXMotionData}, { GBSP_CHUNK_END , 0 ,0 ,NULL }, }; geVFile *f; f = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, FileName, NULL, GE_VFILE_OPEN_CREATE); if (!f) return GE_FALSE; if (!WriteChunks(CurrentChunkData, sizeof(CurrentChunkData) / sizeof(CurrentChunkData[0]), f)) { geVFile_Close(f); return GE_FALSE; } geVFile_Close(f); return GE_TRUE; }
AProject *AProject_CreateFromFilename (const char *Filename) { geVFile *FS; AProject *Project; FS = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_DOS, Filename, NULL, GE_VFILE_OPEN_READONLY); if (FS == NULL) { // unable to open file for reading return NULL; } Project = AProject_CreateFromFile (FS); geVFile_Close (FS); return Project; }
geBoolean AProject_WriteToFilename (const AProject *pProject, const char *Filename) { geVFile *FS; geBoolean rslt; FS = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_DOS, Filename, NULL, GE_VFILE_OPEN_CREATE); if (FS == NULL) { // unable to open file for writing geErrorLog_AddString (GE_ERR_FILEIO_WRITE, "Opening file",NULL); return GE_FALSE; } rslt = AProject_WriteToFile (pProject, FS); geVFile_Close (FS); return rslt; }
geBoolean DirTree_GetSize(const DirTree *Tree, long *Size) { geVFile * FS; geVFile_MemoryContext Context; /* This function is implemented via a write to a memory file for a few reasons. First, it makes it easier to maintain this code. We don't have to track format information in Write, Read and Size functions, just in Write and Read. Second, it gets us testing of the memory file system for free. Third, it was cute. The last one doesn't count, of course, but the other two are compelling. This API ends up being inefficient, but the assumption is that it will be called rarely. */ Context.Data = NULL; Context.DataLength = 0; FS = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_MEMORY, NULL, &Context, GE_VFILE_OPEN_CREATE); if (!FS) return GE_FALSE; if (DirTree_WriteToFile1(Tree, FS, Size) == GE_FALSE) return GE_FALSE; if (geVFile_Size(FS, Size) == GE_FALSE) return GE_FALSE; geVFile_Close(FS); return GE_TRUE; }
geBoolean CWadFile::Setup(const char *Filename) { geVFile * Library; geBoolean NoErrors = GE_FALSE; Library = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_VIRTUAL, Filename, NULL, GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_DIRECTORY); if (Library != NULL) { NoErrors = GE_TRUE; DestroyBitmapArray (); int nFiles = wadCountFiles (Library, "*.*"); if (nFiles > 0) { // make new array and fill it with loaded bitmaps mBitmaps = (WadFileEntry *)geRam_Allocate (nFiles * sizeof (WadFileEntry)); // and fill array with filenames NoErrors = GE_FALSE; geVFile_Finder *Finder = geVFile_CreateFinder (Library, "*.*"); if (Finder != NULL) { NoErrors = GE_TRUE; geVFile_Properties Props; while (geVFile_FinderGetNextFile (Finder) != GE_FALSE) { geVFile_FinderGetProperties (Finder, &Props); // load the file and create a DibBitmap from it geVFile *BmpFile = geVFile_Open (Library, Props.Name, GE_VFILE_OPEN_READONLY); geBitmap *TheBitmap; if (BmpFile == NULL) { NoErrors = GE_FALSE; } else { TheBitmap = geBitmap_CreateFromFile (BmpFile); geVFile_Close (BmpFile); if (TheBitmap == NULL) { NoErrors = GE_FALSE; } else { if (geBitmap_SetFormat (TheBitmap, GE_PIXELFORMAT_16BIT_555_RGB, GE_FALSE, 0, NULL) != GE_FALSE) { WadFileEntry *pe; geBitmap_Info info, info2; geBitmap_GetInfo (TheBitmap, &info, &info2); pe = &mBitmaps[mBitmapCount]; pe->bmp = TheBitmap; pe->Height = info.Height; pe->Width = info.Width; pe->Name = Util_Strdup (Props.Name); geBitmap_LockForReadNative (pe->bmp, &pe->LockedBitmap, 0, 0); pe->BitsPtr = geBitmap_GetBits (pe->LockedBitmap); ++mBitmapCount; } else { geBitmap_Destroy (&TheBitmap); NoErrors = GE_FALSE; } } } } geVFile_DestroyFinder (Finder); } } geVFile_Close (Library); } return GE_TRUE; }
ReturnCode FmtActor_DoMake(FmtActor_Options* options, MkUtil_Printf Printf) { ReturnCode retValue = RETURN_SUCCESS; geVFile *sf; geVFile *df; geBoolean ok; geActor_Def* A = NULL; // Actor files must be specified if(options->SourceActorFile[0] == 0) { Printf("ERROR: Must specify a source actor file\n"); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); return retValue; } if(options->DestinationActorFile[0] == 0) { Printf("ERROR: Must specify a destination actor file\n"); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); return retValue; } if(options->OptimizationLevel<0) { options->OptimizationLevel = 0; } sf = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->SourceActorFile,NULL,GE_VFILE_OPEN_READONLY); if (sf==NULL) { Printf("ERROR: Could not open source actor file (%s).\n", options->SourceActorFile); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); return retValue; } if (options->TextOutput) { df = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->DestinationActorFile,NULL,GE_VFILE_OPEN_CREATE); // df = fopen(options->DestinationActorFile,"w"); } else { df = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->DestinationActorFile,NULL,GE_VFILE_OPEN_CREATE); // df = fopen(options->DestinationActorFile,"wb"); } if (df==NULL) { Printf("ERROR: Could not open destination actor file (%s).\n", options->SourceActorFile); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); geVFile_Close(sf); unlink(options->DestinationActorFile); return retValue; } A = geActor_DefCreateFromFile(sf); geVFile_Close(sf); if (A==NULL) { Printf("ERROR: Failed to create actor from source actor file (%s).\n", options->SourceActorFile); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); geVFile_Close(df); unlink(options->DestinationActorFile); return retValue; } switch (options->OptimizationLevel) { case (0): break; default: break; } if (options->TextOutput) { ok = geActor_DefWriteToFile(A,df); } else { ok = geActor_DefWriteToBinaryFile(A,df); } if (ok == GE_TRUE) { ok = geVFile_Close(df); } if (options->SummaryFile[0]!=0) { FmtActor_Summary(A,options->SummaryFile,Printf); } geActor_DefDestroy(&A); if (ok == GE_FALSE) { Printf("ERROR: Failed to write destination actor file (%s).\n", options->DestinationActorFile); MkUtil_AdjustReturnCode(&retValue, RETURN_ERROR); unlink(options->DestinationActorFile); return retValue; } return retValue; }
//======================================================================================= // VisGBSPFile //======================================================================================= geBoolean VisGBSPFile(char *FileName, VisParms *Parms) { char PFile[200]; geVFile *f; f = NULL; GHook.Printf(" --- Vis GBSP File --- \n"); NoSort = !Parms->SortPortals; VisVerbose = Parms->Verbose; FullVis = Parms->FullVis; // Fill in the global bsp data if (!LoadGBSPFile(FileName)) { GHook.Error("PvsGBSPFile: Could not load GBSP file: %s\n", FileName); goto ExitWithError; } // Clean out any old vis data FreeFileVisData(); // Open the bsp file for writing f = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, FileName, NULL, GE_VFILE_OPEN_CREATE); if (!f) // Oops { GHook.Error("VisGBSPFile: Could not open GBSP file for writing: %s.\n", FileName); goto ExitWithError; } // Prepare the portal file name strcpy(PFile, FileName); StripExtension(PFile); DefaultExtension(PFile, ".GPF"); // Load the portal file if (!LoadPortalFile(PFile)) goto ExitWithError; GHook.Printf("NumPortals : %5i\n", NumVisPortals); // Write out everything but vis info if (!StartWritingVis(f)) goto ExitWithError; // Vis'em if (!VisAllLeafs()) goto ExitWithError; // Record the vis data NumGFXVisData = NumVisLeafs*NumVisLeafBytes; GFXVisData = LeafVisBits; // Save the leafs, clusters, vis data, etc if (!FinishWritingVis(f)) goto ExitWithError; // Free all the vis stuff FreeAllVisData(); // Free any remaining leftover bsp data FreeGBSPFile(); geVFile_Close(f); return GE_TRUE; // ==== ERROR ==== ExitWithError: { GHook.Error("PvsGBSPFile: Could not vis the file: %s\n", FileName); if (f) geVFile_Close(f); FreeAllVisData(); FreeGBSPFile(); return GE_FALSE; } }
//======================================================================================= // 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; }
void CMotionsDlg::OnDropFiles (HDROP hDrop) { // Files dropped. Add each one to the listbox. // The motion name defaults to the name part of the full pathname // First make sure to update the current motion info OnSelchangeMotionslist (); bool AddedOne = false; // get the count const UINT FileCount = DragQueryFile (hDrop, 0xffffffff, NULL, 0); for (UINT iFile = 0; iFile < FileCount; ++iFile) { // get the file and add it to the motions list char Filename[MAX_PATH]; char MotionName[MAX_PATH]; char NewFilename[MAX_PATH]; int Index; // get the filename DragQueryFile (hDrop, iFile, Filename, sizeof (Filename)); // if we get a path that's not relative to the current path, then just exit strcpy (NewFilename, Filename); if (!MakeHelp_GetRelativePath (m_Project, Filename, NewFilename)) { goto DropCleanup; } // Default motion name will be the base filename FilePath_GetName (Filename, MotionName); // Get motion type. // If the extension indicates that it's a Genesis3D motion file, then load // the motion and get its name. // We'll have to check for duplicates and display a message. ApjMotionFormat Fmt = AProject_GetMotionFormatFromFilename (Filename); if (Fmt == ApjMotion_Invalid) { // assume MAX Fmt = ApjMotion_Max; } else if (Fmt == ApjMotion_Mot) { // it's a Genesis3D motion file. Try to load it. geVFile *MotFile = geVFile_OpenNewSystem (NULL, GE_VFILE_TYPE_DOS, Filename, NULL, GE_VFILE_OPEN_READONLY); if (MotFile != NULL) { // opened...Let's try to load it. geMotion *Motion = geMotion_CreateFromFile (MotFile); if (Motion != NULL) { // get the name from the motion const char *Name = geMotion_GetName (Motion); if (Name != NULL) { strcpy (MotionName, Name); } geMotion_Destroy (&Motion); } geVFile_Close (MotFile); } } // Well, we've determined the motion name. Make sure it's unique. if (m_MotionsList.FindStringExact (-1, MotionName) != LB_ERR) { CString Msg; AfxFormatString2 (Msg, IDS_CANTDROPMOTION, Filename, MotionName); AfxMessageBox (Msg); } else { const geBoolean OptFlag = AOptions_GetMotionOptimizationFlag (m_Options); int OptLevel = AOptions_GetMotionOptimizationLevel (m_Options); // Everything's cool, so add it to the listbox. if (AProject_AddMotion (m_Project, MotionName, NewFilename, Fmt, OptFlag, OptLevel, "", &Index) != GE_FALSE) { // And add to listbox int LbItem = m_MotionsList.AddString (MotionName); if ((LbItem == LB_ERR) || (LbItem == LB_ERRSPACE)) { // couldn't add it to listbox, so remove it CString Msg; AProject_RemoveMotion (m_Project, Index); AfxFormatString1 (Msg, IDS_ERRORDROPMOTION, Filename); AfxMessageBox (Msg); } else { // Added it to the listbox, so update item data m_MotionsList.SetItemData (LbItem, Index); SetModifiedFlag (true); AddedOne = true; } } } } // Let's focus at the beginning, 'cause I don't know what else to do... if (AddedOne) { SetupCurrentItem (0); UpdateData (FALSE); } DropCleanup: // gotta do this or we'll leak memory and crash windows DragFinish (hDrop); }
ReturnCode MkActor_DoMake(MkActor_Options* options,MkUtil_Printf Printf) { ReturnCode retValue = RETURN_SUCCESS; geVFile *VF; //geActor* pActor = NULL; geActor_Def* pActorDef = NULL; // Actor file must be specified if(options->ActorFile[0] == 0) { Printf("ERROR: Must specify an actor file\n"); BAILOUT; } // Create the Actor from file or from scratch if(options->ConcatenateActor != MK_FALSE) { VF = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->ActorFile,NULL,GE_VFILE_OPEN_READONLY); if(VF == NULL) { Printf("ERROR: Could not open '%s' to concatenate\n", options->ActorFile); BAILOUT; } pActorDef = geActor_DefCreateFromFile(VF); geVFile_Close(VF); if(pActorDef == NULL) { Printf("ERROR: Could not create actor from file '%s'\n", options->ActorFile); BAILOUT; } } if(pActorDef == NULL) { pActorDef = geActor_DefCreate(); } if(pActorDef == NULL) { Printf("ERROR: Could not create Actor\n"); BAILOUT; } // Read the body file if(options->BodyFile[0] != 0) { geBody* pBody = NULL; VF = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->BodyFile,NULL,GE_VFILE_OPEN_READONLY); if(VF == NULL) { Printf("ERROR: Could not open '%s' body file\n", options->BodyFile); BAILOUT; } else { pBody = geBody_CreateFromFile(VF); geVFile_Close(VF); if(pBody == NULL) { Printf("ERROR: Could not create body from file '%s'\n", options->BodyFile); BAILOUT; } } if(geActor_GetBody(pActorDef) != NULL) { Printf("ERROR: An existing body is being replaced\n"); BAILOUT; } geActor_SetBody(pActorDef, pBody); } // Read the motions if(geStrBlock_GetCount(options->pMotionFileBlock) > 0) { int i, Count, Index; const char* filename; geMotion* pMotion; Count = geStrBlock_GetCount(options->pMotionFileBlock); for(i=0;i<Count;i++) { if (MkUtil_Interrupt()) { Printf("Interrupted\n"); BAILOUT; } filename = geStrBlock_GetString(options->pMotionFileBlock, i); VF = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,filename,NULL,GE_VFILE_OPEN_READONLY); if(VF == NULL) { Printf("ERROR: Could not open '%s' motion file\n", filename); BAILOUT; } else { pMotion = geMotion_CreateFromFile(VF); geVFile_Close(VF); if(pMotion == NULL) { Printf("ERROR: Could not create motion from file '%s'\n", filename); BAILOUT; } else { if(geActor_AddMotion(pActorDef, pMotion, &Index) == MK_FALSE) { Printf("ERROR: Motion file '%s' was not added\n", filename); geMotion_Destroy(&pMotion); BAILOUT; } } } } } // Rename any existing actor file { char bakname[_MAX_PATH]; strcpy(bakname, options->ActorFile); strcat(bakname, ".bak"); remove(bakname); rename(options->ActorFile, bakname); } // Write the actor VF = geVFile_OpenNewSystem(NULL,GE_VFILE_TYPE_DOS,options->ActorFile,NULL,GE_VFILE_OPEN_CREATE); if(VF == NULL) { Printf("ERROR: Could not create '%s' actor file\n", options->ActorFile); unlink(options->ActorFile); BAILOUT; } else { if(geActor_DefWriteToFile(pActorDef, VF) == GE_FALSE) { Printf("ERROR: Actor file '%s' was not written correctly\n", options->ActorFile); unlink(options->ActorFile); BAILOUT; } else { if (geVFile_Close(VF) == GE_FALSE) { Printf("ERROR: Actor file '%s' was not written correctly\n", options->ActorFile); unlink(options->ActorFile); BAILOUT; } else { Printf("SUCCESS: Actor file '%s' written successfully\n", options->ActorFile); } } } geActor_DefDestroy(&pActorDef); // cleans up all motions and body return retValue; }
static void Load(TPack_WindowData *pData) { char FileName[_MAX_PATH]; geVFile * VFS; int i; geVFile_Finder * Finder; if (pData->Dirty) { int Result; Result = MessageBox(NULL, "Do you want to save changes to the current file?", "Texture Packer", MB_YESNOCANCEL); if (Result == IDCANCEL) return; if (Result == IDYES) { #pragma message ("We don't respect CANCEL of saving dirty data in Load") if (pData->FileNameIsValid) Save(pData, pData->TXLFileName); else Save(pData, NULL); } } for (i = 0; i < pData->BitmapCount; i++) { if (!(pData->Bitmaps[i].Flags & ENTRY_DELETED)) { SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_DELETESTRING, (WPARAM)0, (LPARAM)0); free(pData->Bitmaps[i].Name); geBitmap_Destroy(&pData->Bitmaps[i].Bitmap); if (pData->Bitmaps[i].WinBitmap) DeleteObject(pData->Bitmaps[i].WinBitmap); } } if (pData->Bitmaps) geRam_Free(pData->Bitmaps); pData->Bitmaps = NULL; pData->BitmapCount = 0; pData->SelectedEntry = NULL; { OPENFILENAME ofn; // Windows open filename structure... char Filter[_MAX_PATH]; char Dir[_MAX_PATH]; FileName[0] = '\0'; GetCurrentDirectory(sizeof(Dir), Dir); ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = pData->hwnd; ofn.hInstance = pData->Instance; { char *c; // build actor file filter string strcpy (Filter, "Texture Libraries (*.txl)"); c = &Filter[strlen (Filter)] + 1; // c points one beyond end of string strcpy (c, "*.txl"); c = &c[strlen (c)] + 1; *c = '\0'; // 2nd terminating nul character } ofn.lpstrFilter = Filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = FileName; ofn.nMaxFile = sizeof(FileName); ofn.lpstrFileTitle = FileName; ofn.nMaxFileTitle = sizeof(FileName); ofn.lpstrInitialDir = Dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txl"; ofn.lCustData = 0; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; if (!GetOpenFileName (&ofn)) return; } VFS = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_VIRTUAL, FileName, NULL, GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_DIRECTORY); if (!VFS) { NonFatalError("Could not open file %s", FileName); return; } Finder = geVFile_CreateFinder(VFS, "*.*"); if (!Finder) { NonFatalError("Could not load textures from %s", FileName); geVFile_Close(VFS); return; } while (geVFile_FinderGetNextFile(Finder) != GE_FALSE) { geVFile_Properties Properties; geVFile_FinderGetProperties(Finder, &Properties); if (!AddTexture(pData, VFS, Properties.Name)) { geVFile_Close(VFS); return; } } strcpy(pData->TXLFileName, FileName); pData->FileNameIsValid = TRUE; pData->Dirty = FALSE; geVFile_Close(VFS); }
static BOOL AddTexture(TPack_WindowData *pData, geVFile *BaseFile, const char *Path) { geBitmap_Info PInfo; geBitmap_Info SInfo; geBitmap * Bitmap; BitmapEntry * NewBitmapList; geVFile * File; char FileName[_MAX_FNAME]; char * Name; Bitmap = NULL; File = NULL; _splitpath(Path, NULL, NULL, FileName, NULL); Name = strdup(FileName); if (!Name) { NonFatalError("Memory allocation error processing %s", Path); return FALSE; } if (BaseFile) File = geVFile_Open(BaseFile, Path, GE_VFILE_OPEN_READONLY); else File = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_DOS, Path, NULL, GE_VFILE_OPEN_READONLY); if (!File) { NonFatalError("Could not open %s", Path); goto fail; } Bitmap = geBitmap_CreateFromFile(File); geVFile_Close(File); if (!Bitmap) { NonFatalError("%s is not a valid bitmap", Path); goto fail; } geBitmap_GetInfo(Bitmap, &PInfo, &SInfo); if (PInfo.Format != GE_PIXELFORMAT_8BIT) { NonFatalError("%s is not an 8bit bitmap", Path); goto fail; } NewBitmapList = geRam_Realloc(pData->Bitmaps, sizeof(*NewBitmapList) * (pData->BitmapCount + 1)); if (!NewBitmapList) { NonFatalError("Memory allocation error processing %s", Path); goto fail; } NewBitmapList[pData->BitmapCount].Name = Name; NewBitmapList[pData->BitmapCount].Bitmap = Bitmap; NewBitmapList[pData->BitmapCount].WinBitmap = NULL; NewBitmapList[pData->BitmapCount].Flags = 0; pData->BitmapCount++; pData->Bitmaps = NewBitmapList; SendDlgItemMessage(pData->hwnd, IDC_TEXTURELIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)Name); return TRUE; fail: if (Name) free(Name); if (Bitmap) geBitmap_Destroy(&Bitmap); return FALSE; }
static void Save(TPack_WindowData *pData, const char *Path) { char FileName[_MAX_PATH]; geVFile * VFS; int i; if (!Path) { OPENFILENAME ofn; // Windows open filename structure... char Filter[_MAX_PATH]; char Dir[_MAX_PATH]; FileName[0] = '\0'; GetCurrentDirectory(sizeof(Dir), Dir); ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = pData->hwnd; ofn.hInstance = pData->Instance; { char *c; // build actor file filter string strcpy (Filter, "Texture Libraries (*.txl)"); c = &Filter[strlen (Filter)] + 1; // c points one beyond end of string strcpy (c, "*.txl"); c = &c[strlen (c)] + 1; *c = '\0'; // 2nd terminating nul character } ofn.lpstrFilter = Filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = FileName; ofn.nMaxFile = sizeof(FileName); ofn.lpstrFileTitle = FileName; ofn.nMaxFileTitle = sizeof(FileName); ofn.lpstrInitialDir = Dir; ofn.lpstrTitle = NULL; ofn.Flags = OFN_HIDEREADONLY; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txl"; ofn.lCustData = 0; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; if (!GetSaveFileName (&ofn)) return; Path = FileName; } unlink(Path); VFS = geVFile_OpenNewSystem(NULL, GE_VFILE_TYPE_VIRTUAL, Path, NULL, GE_VFILE_OPEN_CREATE | GE_VFILE_OPEN_DIRECTORY); if (!VFS) { NonFatalError("Could not open file %s", Path); return; } for (i = 0; i < pData->BitmapCount; i++) { geVFile * File; geBoolean WriteResult; if (pData->Bitmaps[i].Flags & ENTRY_DELETED) continue; File = geVFile_Open(VFS, pData->Bitmaps[i].Name, GE_VFILE_OPEN_CREATE); if (!File) { NonFatalError("Could not save bitmap %s", pData->Bitmaps[i].Name); geVFile_Close(VFS); return; } WriteResult = geBitmap_WriteToFile(pData->Bitmaps[i].Bitmap, File); geVFile_Close(File); if (WriteResult == GE_FALSE) { NonFatalError("Could not save bitmap %s", pData->Bitmaps[i].Name); geVFile_Close(VFS); return; } } strcpy(pData->TXLFileName, Path); pData->FileNameIsValid = TRUE; if (geVFile_Close(VFS) == GE_FALSE) NonFatalError("I/O error writing %s", Path); else pData->Dirty = FALSE; }
/* ------------------------------------------------------------------------------------ */ geSound_Def *SPool_Sound(const char *SName) { SPool *pool; geVFile *MainFS; if(EffectC_IsStringNull(SName) == GE_TRUE) { char szError[256]; sprintf(szError, "[WARNING] File %s - Line %d: Missing Required Field from Entity - Sound File: %s\n", __FILE__, __LINE__, SName); CCD->ReportError(szError, false); // changed QD 07/15/06 return NULL; /* CCD->ShutdownLevel(); delete CCD; CCD = NULL; MessageBox(NULL, szError, "Sound Manager", MB_OK); exit(-333); */ // end change } pool = Bottom; while(pool != NULL) { if(!stricmp(SName, pool->Name)) return pool->SoundDef; pool = pool->next; } CCD->OpenRFFile(&MainFS, kAudioFile, SName, GE_VFILE_OPEN_READONLY); if(!MainFS) return (geSound_Def*)NULL; pool = GE_RAM_ALLOCATE_STRUCT(SPool); memset(pool, 0, sizeof(SPool)); // changed QD 07/15/06 pool->Name = strdup(SName); pool->SoundDef = geSound_LoadSoundDef(CCD->Engine()->AudioSystem(), MainFS); geVFile_Close(MainFS); if(!pool->SoundDef) { char szError[256]; sprintf(szError, "[WARNING] File %s - Line %d: Unable to load file, invalid path or filename: %s", __FILE__, __LINE__, SName); CCD->ReportError(szError, false); free(pool->Name); geRam_Free(pool); return NULL; /* CCD->ShutdownLevel(); delete CCD; CCD = NULL; MessageBox(NULL, szError,"Sound Manager", MB_OK); exit(-333); */ } pool->next = Bottom; Bottom = pool; if(pool->next) pool->next->prev = pool; // end change return pool->SoundDef; }