Forum archive
Reading data from TILESXXX.ART files
- I am currently attempting to read the art file data format into a Visual Basic 2005 application and have encountered an odd problem with the X, Y dimensions of the tiles...
This information is stored as an array of shorts as defined in Ken's documentation "BUILDINF.TXT"
I am reading in the information as shorts, and I have also attemtped using ushort and integer data types as these are also 16 bit integer data types. Most values are being read just fine, however if an X or Y value is greater than 255 then I am getting a value that starts back at 0 again and counts back up to 255; this scenario repeats again at a value of 512
Here are some examples of what I mean. The following image dimensions are known to be within an art file:
256x128
512x400
These are the results that I am getting when I read the data in from the art file though:
0x128
0x144
All values that are originally less than 256 are showing up fine however.
This does not appear to be a problem with the art file...I suspect this to be something that Visual Basic 2005 is doing with the data type. Has anyone encountered anything like this before? If so, how did you get it to read in the correct values?
Here is a code sample:
Dim x As Integer
Dim pointer As Integer
Dim artversion As Long
Dim numtiles As Long
Dim localtilestart As Long
Dim localtileend As Long
Dim value As Byte() = My.Computer.FileSystem.ReadAllBytes("C:\DosBoxRoot\Duke3D_6\Tiles000.art")
artversion = CLng(value(0))
numtiles = CLng(value(4))
localtilestart = CLng(value(8))
localtileend = CLng(value(12))
Dim tilesizx((localtileend - localtilestart) + 1) As Short
Dim tilesizy((localtileend - localtilestart) + 1) As Short
pointer = 16
For x = 0 To ((localtileend - localtilestart))
tilesizx(x) = (value(pointer))
pointer = pointer + 2
Next
For x = 0 To ((localtileend - localtilestart))
tilesizy(x) = (value(pointer))
pointer = pointer + 2
NextEdited by JustAnotherBuildFan at Re: Reading data from TILESXXX.ART files
I'm not familiar with VB2005, but I'm pretty sure value(pointer) would only access a byte because you have it declared as a byte array. You could probably fix it by saying: value(pointer) + value(pointer+1)*256. Also, you should check whether CLng(value(0)) is actually accessing 4 bytes. I suspect it may not be. In QuickBasic (which is what VB is based on), the syntax would be:Dim artversion As Long
..
Dim tilesizx((localtileend - localtilestart) + 1) As Short
..
OPEN "C:\DosBoxRoot\Duke3D_6\Tiles000.art" FOR BINARY AS #1
GET #1, , artversion
..
GET #1, , tilesizx(x)- Thanks Ken! That worked perfectly.
I'm also more familiar with opening a file in binary as well; this method of opening a file as a byte array is supposed to be a more efficient method that is new to the VB .net environment. This was my first time trying to read from a file using this convention... I had just assumed that if I told it to grab a short value that it would have been intuitive enough to grab 2 bytes starting from the pointer - this does not appear to be the case however.
Works like a charm now. Thanks again :D