LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Clockwork on April 01, 2004, 23:29:42

Title: loading binary data
Post by: Clockwork on April 01, 2004, 23:29:42
I'm working on a loader for Quake 3 bsp files, and I'm curious about  how other people are getting large chunks of data off the file system and into buffers. I'm using a FileImageInputStream because that's the only input stream I could find where I could specify endian type. I can use that to read in one primative at a time, which is fine for my small Milkshape files, but I would expect it to be very slow for a quake level.
What I'm looking at right now is reading the whole vertex lump into one big byte array, then converting it into a byte buffer to pass on to lwjgl later. But I don't know if that's fast or if it will end up replicating the data in memory.

Any suggestions?
Title: loading binary data
Post by: spasi on April 02, 2004, 06:14:35
I'm using NIO. You get a Channel from a FileInputStream and you read straight to a ByteBuffer. Have you tried that?
Title: loading binary data
Post by: Clockwork on April 02, 2004, 12:20:50
No, I hadn't seen the FileChannel. That's exactly what I'm looking for, thanks.

Is there a way to control the byte ordering here, or is it not an issue? I recall having problems using a reader class from IO, which lead me to the FileImageInputStream with its setByteOrder method.
Title: loading binary data
Post by: Clockwork on April 02, 2004, 12:31:07
Wait a minute, you can't control the byte ordering on an amorphous block of data. So, I'd have to control it at the byte buffer level itself. And... yup there it is.

Thanks for getting me on track, Spasi.
Title: loading binary data
Post by: spasi on April 02, 2004, 13:06:15
You're welcome. You'll find it's actually pretty fast as well!
Title: loading binary data
Post by: Clockwork on April 02, 2004, 13:55:20
Heh, for a minute there I was starting to really miss C.  :wink: