void CPlayerCharacter::Save_t( const CTFileName &fnFile) // throw char * { CTFileStream strm; strm.Create_t(fnFile); Write_t(&strm); strm.Close(); }
static void LoadOneFile(const CTFileName &fnm) { try { // open the file CTFileStream strm; strm.Open_t(fnm); // count number of lines INDEX ctLines = 0; while(!strm.AtEOF()) { CTString strLine; strm.GetLine_t(strLine); ctLines++; } strm.SetPos_t(0); // allocate that much CTString *astr = _astrCredits.Push(ctLines); // load all lines for(INDEX iLine = 0; iLine<ctLines && !strm.AtEOF(); iLine++) { strm.GetLine_t(astr[iLine]); } strm.Close(); _bCreditsOn = TRUE; } catch (char *strError) { CPrintF("%s\n", strError); } }
// save anim set file BOOL CSeriousSkaStudioApp::SaveAnimSetFile(CAnimSet &as, BOOL bConvert) { DisableRendering(); CTFileName fnAnimSet = as.GetName(); fnAnimSet = fnAnimSet.NoExt() + ".aal"; try { fnAnimSet.RemoveApplicationPath_t(); } catch(char *){} // back up current skeleton list file CTString strBackUp; try { strBackUp.Load_t(fnAnimSet); } catch(char*){} CTFileStream ostrFile; try { ostrFile.Create_t(fnAnimSet,CTStream::CM_TEXT); SaveAnimSet_t(as,ostrFile); ostrFile.Close(); } catch(char *strError) { ErrorMessage(strError); EnableRendering(); return FALSE; } if(bConvert) { ConvertAnimSet(fnAnimSet); } EnableRendering(); return TRUE; }
void CPlayerCharacter::Load_t( const CTFileName &fnFile) // throw char * { CTFileStream strm; strm.Open_t(fnFile); Read_t(&strm); strm.Close(); }
// Save smc file void CSeriousSkaStudioApp::SaveSmcFile(CModelInstance &mi,BOOL bSaveChildren) { CSeriousSkaStudioDoc *pDoc = GetDocument(); // first get first model instance that has its file CModelInstance *pmiParent=NULL; CModelInstance *pmiFirst=&mi; CTFileName fnSmc = mi.mi_fnSourceFile; CModelInstance *pfmi = mi.GetFirstNonReferencedParent(GetDocument()->m_ModelInstance); if(pfmi!=NULL) { pmiParent = pfmi->GetParent(pDoc->m_ModelInstance); pmiFirst = pfmi; fnSmc = pfmi->mi_fnSourceFile; } DisableRendering(); try { fnSmc.RemoveApplicationPath_t(); } catch(char *){} CTFileStream ostrFile; // try to save model instance try { ostrFile.Create_t(fnSmc,CTStream::CM_TEXT); SaveModelInstance_t(pmiFirst,pmiParent,ostrFile,bSaveChildren); ostrFile.Close(); NotificationMessage("Smc '%s' saved.",pmiFirst->mi_fnSourceFile); } catch(char *strError) { ErrorMessage(strError); } EnableRendering(); }
void CAM_Stop(void) { if (_bCameraOn) { _strScript.Close(); } _bCameraOn = FALSE; }
/* * Load entire world (both brushes and current state). */ void CWorld::Load_t(const CTFileName &fnmWorld) // throw char * { // remember the file wo_fnmFileName = fnmWorld; // open the file CTFileStream strmFile; strmFile.Open_t(fnmWorld); // check engine build allowing reinit BOOL bNeedsReinit; _pNetwork->CheckVersion_t(strmFile, TRUE, bNeedsReinit); // read the world from the file Read_t(&strmFile); // close the file strmFile.Close(); // if reinit is needed if (bNeedsReinit) { // reinitialize SetProgressDescription(TRANS("converting from old version")); CallProgressHook_t(0.0f); ReinitializeEntities(); CallProgressHook_t(1.0f); // reinitialize SetProgressDescription(TRANS("saving converted file")); CallProgressHook_t(0.0f); Save_t(fnmWorld); CallProgressHook_t(1.0f); } }
// sets image info structure members with info form file of any supported graphic format // (CT RAW, PCX8, PCX24, TGA32 uncompressed), but does not load picture content nor palette INDEX CImageInfo::GetGfxFileInfo_t( const CTFileName &strFileName) // throw char * { CTFileStream GfxFile; TGAHeader TGAhdr; PCXHeader PCXhdr; // lets assume it's a TGA file GfxFile.Open_t( strFileName, CTStream::OM_READ); GfxFile.Read_t( &TGAhdr, sizeof( struct TGAHeader)); GfxFile.Close(); // check for supported targa format if( (TGAhdr.ImageType==2 || TGAhdr.ImageType==10) && TGAhdr.BitsPerPixel>=24) { // targa it is, so clear image info and set new values Clear(); ii_Width = TGAhdr.Width; ii_Height = TGAhdr.Height; ii_BitsPerPixel = TGAhdr.BitsPerPixel; // we done here, no need to check further return TGA_FILE; } // we miss Targa, so lets check for supported PCX format GfxFile.Open_t( strFileName, CTStream::OM_READ); GfxFile.Read_t( &PCXhdr, sizeof( struct PCXHeader)); GfxFile.Close(); // check for supported PCX format if( (PCXhdr.MagicID == 10) && (PCXhdr.PixelBits == 8)) { // PCX it is, so clear image info and set new values Clear(); ii_Width = PCXhdr.Xmax - PCXhdr.Xmin + 1; ii_Height = PCXhdr.Ymax - PCXhdr.Ymin + 1; ii_BitsPerPixel = PCXhdr.PixelBits * PCXhdr.Planes; // we done here, no need to check further return PCX_FILE; } // we didn't found a supported gfx format, sorry ... return UNSUPPORTED_FILE; }
// save TGA routine void CImageInfo::SaveTGA_t( const CTFileName &strFileName) const // throw char * { TGAHeader *pTGAHdr; UBYTE *pTGABuffer, *pTGAImage; SLONG slFileSize; PIX pixBitmapSize = ii_Width*ii_Height; CTFileStream TGAFile; // determine and check image info format SLONG slBytesPerPixel = ii_BitsPerPixel/8; ASSERT( slBytesPerPixel==3 || slBytesPerPixel==4); if( slBytesPerPixel!=3 && slBytesPerPixel!=4) throw( TRANS( "Unsupported BitsPerPixel in ImageInfo header.")); // determine TGA file size and allocate memory slFileSize = sizeof(struct TGAHeader) + pixBitmapSize *slBytesPerPixel; pTGABuffer = (UBYTE*)AllocMemory( slFileSize); pTGAHdr = (struct TGAHeader*)pTGABuffer; pTGAImage = pTGABuffer + sizeof(struct TGAHeader); // set TGA picture size dimensions memset( pTGABuffer, 0x0, sizeof(struct TGAHeader)); pTGAHdr->Width = (UWORD)ii_Width; pTGAHdr->Height = (UWORD)ii_Height; pTGAHdr->BitsPerPixel = (UBYTE)ii_BitsPerPixel; pTGAHdr->ImageType = 2; // flip image vertically BOOL bAlphaChannel = (slBytesPerPixel==4); FlipBitmap( ii_Picture, pTGAImage, ii_Width, ii_Height, 1, bAlphaChannel); // convert CroTeam's pixel format to TGA format UBYTE *pubTmp = pTGAImage; // need 'walking' pointer for( INDEX iPix=0; iPix<pixBitmapSize; iPix++) { // flip bytes Swap( pubTmp[0], pubTmp[2]); // R & B channels pubTmp += slBytesPerPixel; } // save entire TGA memory to file and close it TGAFile.Create_t( strFileName); TGAFile.Write_t( pTGABuffer, slFileSize); TGAFile.Close(); // free temorary allocated memory for TGA image format FreeMemory( pTGABuffer); }
void CDlgCreateSpecularTexture::CreateTexture( CTFileName fnTexture, FLOAT fExp) { CImageInfo II; CTFileStream fsFile; CTextureData TD; INDEX iSelectedSize = m_comboSizeInPixels.GetCurSel(); ASSERT( iSelectedSize != CB_ERR); PIX pixSize = 1UL<<iSelectedSize; PIX pixSizeI = pixSize; PIX pixSizeJ = pixSize; UBYTE *pubImage = (UBYTE *)AllocMemory(pixSize*pixSize*3); II.Attach(pubImage, pixSize, pixSize, 24); for (PIX pixI=0; pixI<pixSizeI; pixI++) { for (PIX pixJ=0; pixJ<pixSizeJ; pixJ++) { FLOAT fS = pixI*2.0f/pixSizeI-1; FLOAT fT = pixJ*2.0f/pixSizeJ-1; FLOAT fZ = Sqrt(1-2*fS*fS-2*fT*fT); fZ = Clamp(fZ, 0.0f, 1.0f); FLOAT fZN = FLOAT(pow(fZ, fExp)); ASSERT(fZN>=0 && fZN<=1); UBYTE ub = UBYTE(fZN*255); pubImage[(pixJ*pixSize+pixI)*3+0] = ub; pubImage[(pixJ*pixSize+pixI)*3+1] = ub; pubImage[(pixJ*pixSize+pixI)*3+2] = ub; } } try { TD.Create_t( &II, pixSize, 1, FALSE); fsFile.Create_t( fnTexture); TD.Write_t( &fsFile); fsFile.Close(); } // if failed catch (char *strError) { // report error AfxMessageBox(CString(strError)); } II.Detach(); FreeMemory(pubImage); }
// save skeleton list file BOOL CSeriousSkaStudioApp::SaveSkeletonListFile(CSkeleton &skl, BOOL bConvert) { DisableRendering(); CTFileName fnSkeletonList = skl.GetName(); fnSkeletonList = fnSkeletonList.NoExt() + ".asl"; try { fnSkeletonList.RemoveApplicationPath_t(); } catch(char *){} // back up current skeleton list file CTString strBackUp; try { strBackUp.Load_t(fnSkeletonList); } catch(char*){} CTFileStream ostrFile; try { ostrFile.Create_t(fnSkeletonList,CTStream::CM_TEXT); SaveSkeletonList_t(skl,ostrFile); ostrFile.Close(); } catch(char *strError) { ErrorMessage(strError); EnableRendering(); return FALSE; } if(bConvert) { if(!ConvertSkeleton(fnSkeletonList)) { // convert failed if(strBackUp.Length()>0) { // try returning old mesh list file try { strBackUp.Save_t(fnSkeletonList); } catch(char*){} } } } EnableRendering(); return TRUE; }
// save mesh list file BOOL CSeriousSkaStudioApp::SaveMeshListFile(MeshInstance &mshi, BOOL bConvert) { DisableRendering(); // get mesh list filename CTFileName fnMeshList = mshi.mi_pMesh->GetName(); fnMeshList = fnMeshList.NoExt() + ".aml"; try { fnMeshList.RemoveApplicationPath_t(); } catch(char *){} CTString strBackUp; try { // back up current mesh list file strBackUp.Load_t(fnMeshList); } catch(char*){} // save mesh instance in new mesh list file CTFileStream ostrFile; try { ostrFile.Create_t(fnMeshList,CTStream::CM_TEXT); SaveMeshInstance_t(mshi,ostrFile); ostrFile.Close(); } catch(char *strError) { ErrorMessage(strError); EnableRendering(); return FALSE; } // if new mesh list file needs to be converted if(bConvert) { if(!ConvertMesh(fnMeshList)) { // convert failed if(strBackUp.Length()>0) { // try returning old mesh list file try { strBackUp.Save_t(fnMeshList); } catch(char*){} } } } EnableRendering(); return TRUE; }
/* PCX *********************************************************************** * This routine reads file with given file name and if it is valid PCX file it * loads it into given ImageInfo structure in CroTeam true-color format. * (and, if the one exists, loads the palette) */ void CImageInfo::LoadPCX_t( const CTFileName &strFileName) // throw char * { PCXHeader *pPCXHdr; UBYTE *pPCXBuffer, *pPCXImage, *pPCXDecodedImage, *pTmp; UBYTE data, counter; SLONG pic_size, PCX_size, slFileSize; CTFileStream PCXFile; Clear(); // inconvinent way to determine file size PCXFile.Open_t( strFileName, CTStream::OM_READ); slFileSize = PCXFile.GetStreamSize(); // load entire PCX file to memory, as is, and close it (no further usage) pPCXBuffer = (UBYTE*)AllocMemory( slFileSize); PCXFile.Read_t( pPCXBuffer, slFileSize); PCXFile.Close(); // PCX header starts at the begining of the PCX file pPCXHdr = (struct PCXHeader*)pPCXBuffer; // PCX image bytes definition follows up pPCXImage = pPCXBuffer + sizeof( struct PCXHeader); // detremine picture size dimensions ii_Width = (SLONG)(pPCXHdr->Xmax - pPCXHdr->Xmin +1); ii_Height = (SLONG)(pPCXHdr->Ymax - pPCXHdr->Ymin +1); ii_BitsPerPixel = (SLONG)pPCXHdr->Planes*8; pic_size = ii_Width * ii_Height * ii_BitsPerPixel/8; // allocate memory for image content ii_Picture = (UBYTE*)AllocMemory( pic_size); // allocate memory for decoded PCX file that hasn't been converted to CT RAW Image format PCX_size = (SLONG)(pPCXHdr->BytesPerLine * ii_Height * ii_BitsPerPixel/8); pPCXDecodedImage = (UBYTE*)AllocMemory( PCX_size); pTmp = pPCXDecodedImage; // save pointer for latter usage // decode PCX file for( INDEX i=0; i<PCX_size; ) // i is incremented by counter value at the and of the loop { // read one byte from PCX image in memory data = *pPCXImage++; // check byte-run mark if( (data & 0xC0) == 0xC0) { counter = data & 0x3F; // determine repeat value data = *pPCXImage++; // read repeated data // put several bytes of PCX image to decoded image area in memory for( INDEX j=0; j<counter; j++) *pPCXDecodedImage++ = data; } else { // put just one byte from PCX image to decoded image area in memory counter = 1; *pPCXDecodedImage++ = data; } // increment encoded image counter i += counter; } pPCXDecodedImage = pTmp; // reset pointer // convert decoded PCX image to CroTeam RAW Image Info format SLONG slBytesPerPixel = ii_BitsPerPixel/8; for( INDEX y=0; y<ii_Height; y++) { SLONG slYSrcOfs = y * ii_Width * slBytesPerPixel; SLONG slYDstOfs = y * pPCXHdr->BytesPerLine * slBytesPerPixel; // channel looper for( INDEX p=0; p<slBytesPerPixel; p++) { SLONG slPOffset = p * pPCXHdr->BytesPerLine; // byte looper for( INDEX x=0; x<ii_Width; x++) *(ii_Picture + slYSrcOfs + x*slBytesPerPixel + p) = *(pPCXDecodedImage + slYDstOfs + slPOffset + x); } } // free temorary allocated memory for PCX encoded and decoded image FreeMemory( pPCXBuffer); FreeMemory( pPCXDecodedImage); }
void CImageInfo::LoadTGA_t( const CTFileName &strFileName) // throw char * { TGAHeader *pTGAHdr; UBYTE *pTGABuffer, *pTGAImage; SLONG slFileSize; CTFileStream TGAFile; Clear(); // determine file size TGAFile.Open_t( strFileName, CTStream::OM_READ); slFileSize = TGAFile.GetStreamSize(); // load entire TGA file to memory, as is, and close it (no further usage) pTGABuffer = (UBYTE*)AllocMemory( slFileSize); TGAFile.Read_t( pTGABuffer, slFileSize); TGAFile.Close(); // TGA header starts at the begining of the TGA file pTGAHdr = (struct TGAHeader*)pTGABuffer; // TGA image bytes definition follows up pTGAImage = pTGABuffer + sizeof(struct TGAHeader) + pTGAHdr->IdLenght; // detremine picture size dimensions ii_Width = (SLONG)pTGAHdr->Width; ii_Height = (SLONG)pTGAHdr->Height; ii_BitsPerPixel = (SLONG)pTGAHdr->BitsPerPixel; SLONG slBytesPerPixel = ii_BitsPerPixel/8; PIX pixBitmapSize = ii_Width*ii_Height; BOOL bAlphaChannel = (slBytesPerPixel==4); // check for supported file types ASSERT( slBytesPerPixel==3 || slBytesPerPixel==4); if( slBytesPerPixel!=3 && slBytesPerPixel!=4) throw( TRANS("Unsupported BitsPerPixel in TGA format.")); // allocate memory for image content ii_Picture = (UBYTE*)AllocMemory( ii_Width*ii_Height *slBytesPerPixel); UBYTE *pubSrc = pTGAImage; // need 'walking' pointers UBYTE *pubDst = ii_Picture; // determine TGA image type if( pTGAHdr->ImageType==10) { // RLE encoded UBYTE ubControl; INDEX iBlockSize; BOOL bRepeat; PIX pixCurrentSize=0; // loop thru blocks while( pixCurrentSize<pixBitmapSize) { // readout control byte ubControl = *pubSrc++; bRepeat = ubControl&0x80; iBlockSize = (ubControl&0x7F) +1; // repeat or copy color values for( INDEX i=0; i<iBlockSize; i++) { *pubDst++ = pubSrc[0]; *pubDst++ = pubSrc[1]; *pubDst++ = pubSrc[2]; if( bAlphaChannel) *pubDst++ = pubSrc[3]; if( !bRepeat) pubSrc += slBytesPerPixel; } // advance for next block if repeated if( bRepeat) pubSrc += slBytesPerPixel; // update image size pixCurrentSize += iBlockSize; } // mark that image was encoded to ImageInfo buffer pTGAImage = ii_Picture; } // not true-colored? else if( pTGAHdr->ImageType!=2) { // whoops! ASSERTALWAYS("Unsupported TGA format."); throw( TRANS("Unsupported TGA format.")); } // determine image flipping INDEX iFlipType; switch( (pTGAHdr->Descriptor&0x30)>>4) { case 0: iFlipType = 1; break; // vertical flipping case 1: iFlipType = 3; break; // diagonal flipping case 3: iFlipType = 2; break; // horizontal flipping default: iFlipType = 0; break; // no flipping (just copying) } // do flipping FlipBitmap( pTGAImage, ii_Picture, ii_Width, ii_Height, iFlipType, bAlphaChannel); // convert TGA pixel format to CroTeam pubSrc = ii_Picture; // need 'walking' pointer again for( INDEX iPix=0; iPix<pixBitmapSize; iPix++) { // flip bytes Swap( pubSrc[0], pubSrc[2]); // R & B channels pubSrc += slBytesPerPixel; } // free temorary allocated memory for TGA image format FreeMemory( pTGABuffer); }