Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cmdline "-gen gcc -O 1"
- #ifndef NULL
- const NULL = cast(any ptr,0)
- #endif
- /'
- desktop\ldcad\shadow
- desktop\ldcad\ldraw\parts
- 1 <colour> x y z a b c d e f g h i <file>
- 2 <colour> x1 y1 z1 x2 y2 z2
- 3 <colour> x1 y1 z1 x2 y2 z2 x3 y3 z3
- 4 <colour> x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
- 5 <colour> x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4
- '/
- 'dim shared as string sFilenames
- 'redim shared as long aDatFiles()
- type LineType1Struct 'line type 1
- as single fX,fY,fZ,fA,fB,fC,fD,fE,fF,fG,fH,fI
- as ulong lFileOffset
- end type
- type LineType2Struct 'line type 2
- as single fX1,fY1,fZ1,fX2,Y2,fZ2
- end type
- type LineType3Struct 'line type 3
- as single fX1,fY1,fZ1,fX2,Y2,fZ2,fX3,fY3,fZ3
- end type
- type LineType4Struct 'line type 4
- as single fX1,fY1,fZ1,fX2,Y2,fZ2,fX3,fY3,fZ3,fX4,fY4,fZ4
- end type
- type LineType5Struct 'line type 5
- as single fX1,fY1,fZ1,fX2,Y2,fZ2,fX3,fY3,fZ3,fX4,fY4,fZ4
- end type
- type PartStruct
- bType as ubyte 'type ID (line/primitves
- union 'flags
- bFlags as ubyte 'optional flags/bitfield???
- end union
- union 'color/data
- wColour as ushort
- wData as ushort
- end union
- union '> type specific data
- _1 as LineType1Struct
- _2 as LineType2Struct
- _3 as LineType3Struct
- _4 as LineType4Struct
- _5 as LineType5Struct
- end union
- end type
- type DATFile
- iFilenameOffset as long 'offset for the file name string
- iPartCount as long 'number of parts in this file
- dim as PartStruct tParts( (1 shl 25)-1 ) 'maximum number of parts (dynamic)
- end type
- function ReadInt( pFile as ubyte ptr , byref iInt as long ) as long
- dim as long iResu = 0, iRead, iHasDigits=0
- do
- select case pFile[iRead]
- case asc("0") to asc("9") 'add a digit to the number
- iResu=iResu*10+(pFile[iRead]-asc("0"))
- iHasDigits = 1
- case asc(" "),9 'skip spaces/tab
- if iHasDigits then exit do
- case asc(!"\r") 'skip the \r in case EOL is \r\n
- rem nothing to do here
- case asc(!"!\n"),0 'if it's EOL/EOF then we assume it was read 0
- iHasDigits = 1 : exit do
- case else
- exit do
- end select
- iRead += 1
- loop
- 'we're done processing digits, but did we read a number at all?
- if iHasDigits=0 then iInt=pFile[iRead] : return -1
- iInt = iResu
- return iRead
- end function
- function LoadFile( sFile as string , sFilename as string = "" ) as DATFile ptr
- #macro CheckError(_s)
- if iResu<0 then
- print _s " error reading '"+sFilename+"' at line " & iLineNum
- iFailed = 1 : exit do
- end if
- #endmacro
- #macro NextLine()
- while *pFile <> asc(!"\n") andalso *pfile : pFile += 1 : wend
- if *pFile=0 then exit do 'last line of file so we're done SUCCESS
- iLineNum += 1 : pFile += 1 : continue do 'now it point to the being of next line
- #endmacro
- dim as long iLastPart=0 , iLimitParts=-1 , iFailed=0, iLineNum = 1
- dim as long iType = any , iResu = any
- var pFile = cast(ubyte ptr, strptr(sFile)) 'pointer to the file
- dim as DATFile ptr pT = NULL 'pointer to the file structure in memory
- #define PartsToBytes(_N) (offsetof(DATFile,tParts(0))+(_N)*sizeof(PartStruct))
- do
- if iLastPart > iLimitParts then 'allocate more entries if necessary
- iLimitParts += 4096 'we increase the allocation every N parts
- var pNew = reallocate( pT , PartsToBytes(iLimitParts+1) )
- if pNew=NULL then
- print "Failed to allocate memory to load file"
- iFailed = 1 : exit do 'gives up
- end if
- pT = pNew
- end if
- 'at this point we should assume we are at the begin of a line so we get a line type
- iResu = ReadInt( pFile , iType )
- CheckError( "Syntax" ) 'failed to read the line type integer?
- pFile += iResu 'advancing to the next component
- select case iType 'which line type is it?
- case 0 to 5 'ignore if comment OR empty line and advance to next line
- NextLine()
- end select
- sleep : system
- loop
- 'clean-up
- if iFailed then 'clean-up in case of faillure
- if pT then deallocate(pT): pT=NULL 'deallocate previous buffer
- else
- pT->iPartCount = iLastPart
- pT = reallocate( pT , PartsToBytes(pT->iPartCount) )
- print iLineNum & " lines and " & pT->iPartCount & " parts were read"
- end if
- return pT
- end function
- #define EOL !"\n"
- dim as string sModel = _
- "1 4 0 0 0 1 0 0 0 1 0 0 0 1 3024.dat" EOL _
- "1 1 0 8 0 1 0 0 0 1 0 0 0 1 3024.dat" EOL _
- "1 2 0 16 0 1 0 0 0 1 0 0 0 1 3005.dat" EOL _
- "1 2 0 -2 -21 1 0 0 0 1 0 0 0 1 63710p01.dat"
- print LoadFile( sModel , "MyModel.ldr" )
- sleep
- dim as double dTIME = timer
- var f = freefile()
- if open("C:\Users\kris\Desktop\n\datsville_rev002.013_inlined_n_boxed_f.mpd" for input as #f) then
- print "Failed to open file": sleep:system
- end if
- dim as uinteger uFileSize = lof(f)
- print csng(uFileSize/(1024*1024));"mb"
- #if 0
- dim as string sLine
- while not eof(f)
- line input #f, sLine
- 'parse them
- wend
- #endif
- dim as string sFile = string( lof(f) , 0 )
- get #f,,sFile
- #if 0
- var iLineStart = 1
- do
- var iPos = instr( iLineStart , sFile , !"\n" )
- if iPos=0 then exit do
- iLineStart = iPos+1
- loop
- #endif
- dim as long iLineCount
- for N as long = 0 to uFileSize-1
- select case sFile[N]
- case asc(!"\n")
- iLineCount += 1
- end select
- next N
- print timer-dTIME
- sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement