/*************/ /*** Utils ***/ /*************/ #include "stdafx.h" #include "MapEdit.h" #include "MapEditDoc.h" #include #include #include #include "GLEnabledView.h" #include #include #include #include "Utils.H" /**************************************************************************************/ void DbgMsg(const char * pszFmt,...) { char szBuf[256]; if (pszFmt) { va_list args; va_start(args,pszFmt); vsprintf(szBuf,pszFmt,args); OutputDebugString(szBuf); va_end(args); } } /**************************************************************************************/ const int TexAlignTable[]={1,2,4,8,16,32,64,128,256,512,1024}; const int TexAlignTableSize=sizeof(TexAlignTable)/sizeof(int); int AlignSize(int Size) { for (int i=0;iTexAlignTable[i] && SizeGetPathName(); GString Path; Path=FName.Drive(); Path+=FName.Dir(); Path.Append('\\'); Out=Path; Out+=In; } */ /**************************************************************************************/ /*!!! void MakePathRel2App(const char* In,char *Out) { GString RootPath=theApp.GetCurrent()->GetPathName(); GFName::makerelative(RootPath,In,Out); } */ /**************************************************************************************/ GString GetWorkingPath() { GFName FullPath=theApp.GetCurrent()->GetPathName(); GString Path; Path=FullPath.Drive(); Path+=FullPath.Dir(); Path.Append('\\'); return(Path); } /*****************************************************************************/ void CheckFilename(GString &Filename) { FILE *File; CString mexstr; GFName FName=Filename; GString Name; // Check File exists File=fopen(Filename,"r"); if (File) { fclose(File); return; } Name=FName.File(); Name.Append('.'); Name+=FName.Ext(); mexstr.Format("%s Not Found.\n\nPlease Locate\n", Filename); AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION); char BASED_CODE Filter[]= "All Files (*.*)|*.*||"; CFileDialog Dlg(true,NULL,Name,OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,Filter); if (Dlg.DoModal()!=IDOK) return; Filename=Dlg.GetPathName(); } /*****************************************************************************/ int round(float f) { if (f<0) { return (int)(f-0.5f); } else { return (int)(f+0.5f); } } /*****************************************************************************/ void *_MemAlloc(size_t Size) { CheckMem(); void *Ptr=malloc(Size); CheckMem(); return(Ptr); } /*****************************************************************************/ void _MemFree(void *Ptr) { CheckMem(); free(Ptr); CheckMem(); } /*****************************************************************************/ void CheckMem() { int Status = _heapchk(); switch( Status) { case _HEAPOK: // TRACE0(" OK - heap is fine\n" ); break; case _HEAPEMPTY: // TRACE0(" OK - heap is empty\n" ); break; case _HEAPBADBEGIN: TRACE0( "ERROR - bad start of heap\n" ); break; case _HEAPBADNODE: TRACE0( "ERROR - bad node in heap\n" ); break; } } /*****************************************************************************/ void GetExecPath(GString &Path) { #ifndef _DEBUG // Get application path char ExeFilename[2048]; GFName Exe; GetModuleFileName(GetModuleHandle(NULL),ExeFilename,2048); Exe=ExeFilename; Exe.File(0); Exe.Ext(0); Path=Exe.FullName(); #else Path="\\SpongeBob\\tools\\MapEdit\\"; #endif }