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); } }
// enable dictionary in writable file from this point void CTStream::DictionaryWriteBegin_t(const CTFileName &fnmImportFrom, SLONG slImportOffset) { ASSERT(strm_slDictionaryPos==0); ASSERT(strm_dmDictionaryMode == DM_NONE); strm_ntDictionary.SetAllocationParameters(100, 5, 5); strm_ctDictionaryImported = 0; // if importing an existing dictionary to start with if (fnmImportFrom!="") { // open that file CTFileStream strmOther; strmOther.Open_t(fnmImportFrom); // read the dictionary in that stream strmOther.ReadDictionary_intenal_t(slImportOffset); // copy the dictionary here CopyDictionary(strmOther); // write dictionary importing data WriteID_t("DIMP"); // dictionary import *this<<fnmImportFrom<<slImportOffset; // remember how many filenames were imported strm_ctDictionaryImported = strm_afnmDictionary.Count(); } // write dictionary position chunk id WriteID_t("DPOS"); // dictionary position // remember where position will be placed strm_slDictionaryPos = GetPos_t(); // leave space for position *this<<SLONG(0); // start dictionary strm_dmDictionaryMode = DM_ENABLED; }
void CPlayerCharacter::Load_t( const CTFileName &fnFile) // throw char * { CTFileStream strm; strm.Open_t(fnFile); Read_t(&strm); strm.Close(); }
void CAM_Start(const CTFileName &fnmDemo) { _bCameraOn = FALSE; CTFileName fnmScript = fnmDemo.NoExt()+".ini"; if( cam_bRecord) { try { _strScript.Create_t(fnmScript); } catch(char *strError) { CPrintF("Camera: %s\n", strError); return; }; _cp.cp_vPos = FLOAT3D(0,0,0); _cp.cp_aRot = ANGLE3D(0,0,0); _cp.cp_aFOV = 90.0f; _cp.cp_fSpeed = 1; _cp.cp_tmTick = 0.0f; } else { try { _strScript.Open_t(fnmScript); } catch(char *strError) { (void)strError; return; }; } _bCameraOn = TRUE; _bInitialized = 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; }
// get level info for given filename BOOL GetLevelInfo(CLevelInfo &li, const CTFileName &fnm) { // try to try { // open the world file CTFileStream strm; strm.Open_t(fnm); // skip initial chunk ids strm.ExpectID_t("BUIV"); // 'build version' INDEX iDummy; strm>>iDummy; // the version number strm.ExpectID_t("WRLD"); // 'world' strm.ExpectID_t("WLIF"); // 'world info' if (strm.PeekID_t()==CChunkID("DTRS")) { strm.ExpectID_t("DTRS"); // 'world info' } // read the name strm>>li.li_strName; // read the flags strm>>li.li_ulSpawnFlags; // translate name li.li_strName = TranslateConst(li.li_strName, 0); // if dummy name if (li.li_strName=="") { // use filename li.li_strName = fnm.FileName(); } // remember filename li.li_fnLevel = fnm; // succeed return TRUE; // if failed } catch (char *strError) { (void) strError; //CPrintF("Invalid world file '%s': %s\n", (const char*) fnm, strError); // set dummy info li = CLevelInfo(); // fail return FALSE; } }
/* * Load just world brushes from a file with entire world information. */ void CWorld::LoadBrushes_t(const CTFileName &fnmWorld) // throw char * { // remember the file wo_fnmFileName = fnmWorld; // open the file CTFileStream strmFile; strmFile.Open_t(fnmWorld); // check engine build disallowing reinit BOOL bNeedsReinit; _pNetwork->CheckVersion_t(strmFile, FALSE, bNeedsReinit); ASSERT(!bNeedsReinit); strmFile.ExpectID_t("WRLD"); // 'world' // read the world brushes from the file ReadBrushes_t(&strmFile); }
// load a filelist static BOOL LoadFileList(CDynamicStackArray<CTFileName> &afnm, const CTFileName &fnmList) { afnm.PopAll(); try { CTFileStream strm; strm.Open_t(fnmList); while(!strm.AtEOF()) { CTString strLine; strm.GetLine_t(strLine); strLine.TrimSpacesLeft(); strLine.TrimSpacesRight(); if (strLine!="") { afnm.Push() = strLine; } } return TRUE; } catch(char *strError) { CPrintF("%s\n", strError); return FALSE; } }
/* 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); }
static void LoadSettings(const CTFileName &fnConfig) { if(!_bInitialized) return; if(!FileExists(fnConfig)) return; try { CTFileStream istr; istr.Open_t(fnConfig,CTFileStream::OM_READ); INDEX iVersion; ULONG ulFlags; INDEX iFontSize; INDEX iFirstChar; INDEX iLastChar; INDEX iAlignH; INDEX iAlignV; INDEX iPaddingX; INDEX iPaddingY; INDEX iWidthAdd; INDEX iHeightAdd; INDEX ctShadows; INDEX iTexWidth; INDEX iTexHeight; CTString strFontName; CTString strSampleText; istr>>iVersion; if(iVersion!=CONFIG_VERSION) { WarningMessage("Invalid config version.\nExpected Ver \"%d\" but found \"%d\"\n", CONFIG_VERSION, iVersion); return; } istr>>ulFlags; istr>>iFontSize; istr>>iFirstChar; istr>>iLastChar; istr>>iAlignH; istr>>iAlignV; istr>>iPaddingX; istr>>iPaddingY; istr>>iWidthAdd; istr>>iHeightAdd; istr>>ctShadows; istr>>iTexWidth; istr>>iTexHeight; istr>>strFontName; istr>>strSampleText; istr>>_bShowTexture; istr>>_bShowGrid; istr>>_fnCharacterTable; UpdatePreviewButton(); SetFontFlags(ulFlags); SetControlInt(IEC_FONT_SIZE,iFontSize); SetControlInt(IEC_FIRST_CHAR,iFirstChar); SetControlInt(IEC_LAST_CHAR,iLastChar); SetComboIndex(IDC_ALIGN_H,iAlignH); SetComboIndex(IDC_ALIGN_V,iAlignV); SetControlInt(IEC_PADDINGX,iPaddingX); SetControlInt(IEC_PADDINGY,iPaddingY); SetControlInt(IEC_WIDTH_ADD,iWidthAdd); SetControlInt(IEC_HEIGHT_ADD,iHeightAdd); SetControlInt(IEC_SHADOW_PASSES,ctShadows); SetComboInt(ICB_TEX_WIDTH,iTexWidth); SetComboInt(ICB_TEX_HEIGHT,iTexHeight); SetComboString(ICB_FONT_NAMES,strFontName); SetStringToControl(IEC_SAMPLE_TEXT,strSampleText); LoadCharTable(_fnCharacterTable); GenerateFont(); } catch(char *strErr) { WarningMessage("%s", strErr); } }