I am trying to figure out how to properly use the FileEOF tier 1 command.
Example:
//generic cruft
SetErrorMode(2)
SetWindowTitle( "EOFtest" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 )
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
//write the file to test
fid = OpenToWrite("testfile.dat", 0)
WriteInteger(fid, 1)
WriteInteger(fid, 2)
CloseFile(fid)
//read the file to test
fid = OpenToRead("testfile.dat")
i1 = ReadInteger(fid)
eof1 = FileEOF(fid)
i2 = ReadInteger(fid)
eof2 = FileEOF(fid)
i3 = ReadInteger(fid)
eof3 = FileEOF(fid)
do
Print( ScreenFPS() )
Print(i1)
Print(i2)
Print(i3)
Print(eof1)
Print(eof2)
Print(eof3)
Sync()
loop
This prints on screen the following:
Which translates to having read the values 1,2,0 from the file. And gotten the corresponding EOF after each read as 0,0,1.
So I have a file with two integers, 1 and 2. I look at testfile.dat on disk and its size if 8. I xxd testfile.dat and see the contents as:
0100 0000 0200 0000
So I guess AppGameKit saves integers to file as 4 bytes each, with the least significant bytes first? So there is actually only 2 integers in the file. But the EOF after reading 2 bytes is reporting that the read is NOT at the end of the file yet. So I have to read a non-existent integer to figure out that the file ends.
Finally the Q: What is the correct procedure to actually use FileEOF? Do i really need to try to over-read (at each possible step..), and if it reports EOF, then discard the last read values (which I guess is 0 since AppGameKit seemingly happily reads non-existing data forever..)?