|
Platform-dependent files? |
Ron Ofir
Member #2,357
May 2002
|
Hi all, I have tried making a small Allegro app for my Java game that takes a bitmap and writes out all of the coordinates of non-white pixels to a file. It writes the pixels in pairs of two integers, no spaces, no tabs, no newlines, just integers. The app runs fine (after some debugging of course), so I went on to try and read the file in my Java game, however the results seem very wrong. When I should get a pair of 4 4 I get 67108864 67108864, and so on. I tried reading the file using the Allegro app and the numbers come out fine (eexcept for the last pair that comes twice for some reason, but I think I'm doing wrong EOF checks). The application is running on an Ubuntu Linux and the Java game is running on Windows XP, so I thought it might be some endian problems, and here comes my problem: How can you choose different byte order in Java for reading files? I would also be glad for any other endian-issues feedback/random info. (I'm using simple fwrite-fread in order to write and check the file, and DataInputStream in order to read it, oh, and both applications read/write the same number of pairs) Cookies promised. |
Fladimir da Gorf
Member #1,565
October 2001
|
I wouldn't rely on any specific format when using DataInputStream. You should use your own stream handler if you make any assumptions. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Peter Hull
Member #1,136
March 2001
|
I agree with Fladimir; DataInputStream should probably only be used with files created by DataOutputStream. However you should be able to find the format used with Google. Assuming it's simply a big endian format, you can use the relevant Allegro functions, for example #include <allegro.h> int main(int argc, char* argv[]) { PACKFILE* f = pack_fopen(argv[1], F_WRITE); int i = 4; pack_mputl(i, f); pack_fclose(f); return 0; } END_OF_MAIN() produces a file with a 4 in it, that can be read by this program
Random info: I had leeks for dinner today Pete
|
Fladimir da Gorf
Member #1,565
October 2001
|
For general communication between programs made with different languages, I'd use XML. OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Ron Ofir
Member #2,357
May 2002
|
I'll check the pack_mputl solution. I don't want to use XML as it will make the files about 20 times bigger and complicate the writing (not so much, but still). BTW, don't you have to initialize allegro (in console mode, SYSTEM_NONE) in order to use it's routines? |
GullRaDriel
Member #3,861
September 2003
|
For general communication between programs made with different languages, I'd use A SIMPLE TEXT FILE. "Code is like shit - it only smells if it is not yours" |
Ron Ofir
Member #2,357
May 2002
|
Java uses big-endian so Peter's solution works. I've just tried it with a couple of things and it looks great (I'll post screenshots later when I add some more effects). |
James Stanley
Member #7,275
May 2006
|
Quote: I had leeks for dinner today
Leeks are horrible! |
|