From: <sto...@us...> - 2003-01-01 20:55:12
|
Update of /cvsroot/csp/APPLICATIONS/TerrainToolSet/RAW2txt In directory sc8-pr-cvs1:/tmp/cvs-serv8303 Added Files: RAW2txt.dsp raw2txt.cpp Log Message: no message --- NEW FILE: RAW2txt.dsp --- # Microsoft Developer Studio Project File - Name="RAW2txt" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** NICHT BEARBEITEN ** # TARGTYPE "Win32 (x86) Console Application" 0x0103 CFG=RAW2txt - Win32 Debug !MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE !MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl !MESSAGE !MESSAGE NMAKE /f "RAW2txt.mak". !MESSAGE !MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben !MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel: !MESSAGE !MESSAGE NMAKE /f "RAW2txt.mak" CFG="RAW2txt - Win32 Debug" !MESSAGE !MESSAGE Für die Konfiguration stehen zur Auswahl: !MESSAGE !MESSAGE "RAW2txt - Win32 Release" (basierend auf "Win32 (x86) Console Application") !MESSAGE "RAW2txt - Win32 Debug" (basierend auf "Win32 (x86) Console Application") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe RSC=rc.exe !IF "$(CFG)" == "RAW2txt - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "Release" # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c # ADD BASE RSC /l 0x407 /d "NDEBUG" # ADD RSC /l 0x407 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "RAW2txt - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "Debug" # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD BASE RSC /l 0x407 /d "_DEBUG" # ADD RSC /l 0x407 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF # Begin Target # Name "RAW2txt - Win32 Release" # Name "RAW2txt - Win32 Debug" # Begin Group "Quellcodedateien" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=.\raw2txt.cpp # End Source File # End Group # Begin Group "Header-Dateien" # PROP Default_Filter "h;hpp;hxx;hm;inl" # End Group # Begin Group "Ressourcendateien" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" # End Group # End Target # End Project --- NEW FILE: raw2txt.cpp --- // Combat Simulator Project - RAW2txt - writes RAW data to a text file // Copyright (C) 2002 The Combat Simulator Project // http://csp.sourceforge.net // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** * This tool can be used to verify the result of the fractal * generator. It converts the binary data from a RAW file * to text. This text file can either be opened with an editor, * or the data can be imported to Excel. This was used during * the development of the fractal tool, mostly to track down * bugs by analyzing the output of the fractal routines. * * @author Martin "Stormbringer" Hoffmann <sto...@gm...> */ #include "stdio.h" #include "stdlib.h" #include "string.h" #include "io.h" #include "fcntl.h" #include "SYS\STAT.H" #include "math.h" short *aiHeightmap, *fract_map; int iWidth, iHeight; char cSourceFileName[256], cDestFileName[256], cPosX[256], cPosY[256], cStringBuffer[256], cSize[256]; long iSourceFileHandle, iDestFileHandle; int LoadRAWTerrain(int iFile) { int success; long lsize; short *buffer; float fwidth; int iWidth, iHeight; // Load SCN data and save to internal structure lsize = _filelength(iFile); lsize /= 2; // SCN uses 16bit height values, so we have to divide by 2 // to get the real number of height map values fwidth = (float)sqrt((double)lsize); // compute terrain width from size of file iWidth = (int)fwidth; iHeight = (int)fwidth; aiHeightmap = new short[lsize]; buffer = new short[lsize]; fract_map = new short[lsize]; success = _read(iFile, buffer, (lsize*sizeof(short))); for (int y=0; y<iWidth; y++) for (int x=0; x<iWidth; x++) { fract_map[y*iWidth+x] = (short)buffer[y*iWidth+x]; } delete []buffer; return iWidth; } /** * ConvertRAWtoTXT - writes RAW data to a text file * * This function can be used to verify the result of the fractal * generator. It converts the binary data from a RAW file * to text. This text file can either be opened with an editor, * or the data can be imported to Excel. This was used during * the development of the fractal tool, mostly to track down * bugs by analyzing the output of the fractal routines. * * @author Martin "Stormbringer" Hoffmann <sto...@gm...> */ int ConvertRAWtoTXT(int iDestFileHandle, int iSourceFileHandle) { char cValue[100], cBuffer[100]; int countX, countY, intbuffer, Success; int uiCurrentQuadWidth = (int)(sqrt((float)_filelength(iSourceFileHandle)/2)); for(countY=0;countY<uiCurrentQuadWidth;countY++) { for(countX=0;countX<uiCurrentQuadWidth;countX++) { intbuffer = (int)fract_map[countY*uiCurrentQuadWidth+countX]; cBuffer[0] = (char)0; itoa(intbuffer, cValue, 10); int diff=0; diff = 6 - strlen(cValue); for(int i=0;i<diff;i++) { strcat(cBuffer, "0"); } if(intbuffer < 0) { _strnset(cBuffer, '-', 1); _strnset(cValue, '0', 1); } else { _strnset(cBuffer, ' ', 1); } strcat(cBuffer, cValue); Success = _write(iDestFileHandle, cBuffer, strlen(cBuffer)); strcpy(cValue, ", "); Success = _write(iDestFileHandle, cValue, strlen(cValue)); } strcpy(cValue, "\n"); Success = write(iDestFileHandle, cValue, strlen(cValue)); } _chmod(cDestFileName, _S_IREAD | _S_IWRITE); _close(iDestFileHandle); return 1; } int main(int argc, char* argv[]) { if(argc < 2) { printf("Not enough parameters!\n"); return -1; } // Source and Destination file names strcpy(cSourceFileName, argv[1]); strcpy(cDestFileName, argv[2]); iSourceFileHandle = _open(cSourceFileName, _O_BINARY); if(iSourceFileHandle==-1) { printf("unable to open '%s'!\n", cSourceFileName); char text[100]; gets(text); return -1; } iDestFileHandle = _open(cDestFileName, _O_CREAT | _O_RDWR, _S_IREAD | _S_IWRITE); if(iDestFileHandle==-1) { printf("unable to open '%s'!\n", cDestFileName); char text[100]; gets(text); _close(iSourceFileHandle); return -1; } LoadRAWTerrain(iSourceFileHandle); ConvertRAWtoTXT(iDestFileHandle, iSourceFileHandle); _close(iSourceFileHandle); _close(iDestFileHandle); return 0; } |