Server Help

Misc User Apps - Map editor snags and snares

Helicon - Tue Nov 11, 2003 4:59 pm
Post subject: Map editor snags and snares
(I am going to use this thread to encapsulate all of my basic (stupid) and not so stupid questions)

Here we go:

1: is there a constant string of data in a map file which will always signify the end of the bitmap (if it has one) which i could use to split a .lvl?

2: Are there any prewritten file parsers (w/ src) for maps available somewhere?

i will probably have some gfx/buffering/performace issues soon...
Mine GO BOOM - Tue Nov 11, 2003 5:17 pm
Post subject:
1. Use the BITMAPFILEHEADER structure for loading the size of the bmp. I believe there is even a quick hack that I wrote up on skipping past the BMP section somewhere in the Misc User Apps, just do a search for it. But if you are making a map editor, I'd recommend actually learning to read the BMP section correctly.

The bfSize is the full size of the whole BMP section. So just seek that many bits from the beginning of the file, and thats where the LVL data will be placed.

If the first 2 bytes are not BM, then there is no tileset for the map, thus you use the default one, which should be supplied by your map editor.

Code: Show/Hide
typedef struct tagBITMAPFILEHEADER {
  WORD    bfType;
  DWORD   bfSize;
  WORD    bfReserved1;
  WORD    bfReserved2;
  DWORD   bfOffBits;
} BITMAPFILEHEADER, *PBITMAPFILEHEADER;

Members

bfType
    Specifies the file type, must be BM.
bfSize
    Specifies the size, in bytes, of the bitmap file.
bfReserved1
    Reserved; must be zero.
bfReserved2
    Reserved; must be zero.
bfOffBits
    Specifies the offset, in bytes, from the beginning of the BITMAPFILEHEADER structure to the bitmap bits.


2. I'd recommend you creating your own parser. Most of them out there, such as what I wrote up for someone here before, just skip pasted all the good stuff, and may assume that the tile information is correct, and comes in chunks of 4 bytes.

Plus, if you create your own parser, you could support png tilesets and such. If a good map editor came out that is can support different image types natively, it would be very simple for Priitk to add it into continuum. Thus it can decrease the filesizes by a great deal. Could maybe store the tile information compressed.
Anonymous - Tue Nov 11, 2003 5:49 pm
Post subject:
I think they may be something on SSDL (sslvl?) written in VB with source that can read map files and give stats. Although as MGB says it assumes data comes in 4 byte chunks (I think Asss has this problem too), so it can only read the map file up to a certain point (on my machine anyway).

I also think maps are sent zlib compressed, but saving space on the end users machine is always nice.
SuSE - Tue Nov 11, 2003 5:58 pm
Post subject:
I wouldn't bother with anything at ssdownloads (for taking coding notes sa_tongue.gif)
Mine GO BOOM - Tue Nov 11, 2003 10:26 pm
Post subject:
Anonymous wrote:
it assumes data comes in 4 byte chunks (I think Asss has this problem too)


For ASSS, it will read it all, but does not error checking if the last chunk is < 4 bytes, it just ignores it. A good map editor should warn the user that the map maybe invalid, and attempt to do error checking on the data, to see where it might have fucked up.
SuSE - Tue Nov 11, 2003 10:31 pm
Post subject:
ie - it should work sa_tongue.gif
Helicon - Wed Nov 12, 2003 4:04 pm
Post subject:
will see what i can do... java has not historically been my choice for handling bit-by-bit filetypes
Dustpuppy - Thu Nov 13, 2003 11:03 am
Post subject:
MERV loads maps, you could take a look at the source. It's in map.* IIRC
Helicon - Thu Nov 13, 2003 4:22 pm
Post subject:
i've been hacking, and so far my only concerns have been dealing with the annoyance of not knowing whether the first bits are bmp are not... java is not very friendly below the Byte size... it will end up being no problem.. though i will undoubtedly have to get someone to look over it.
Anonymous - Thu Nov 13, 2003 5:00 pm
Post subject:
Whether the first bits are bmp or not?
Can't you just do a string check for the 'BM' header?
Helicon - Thu Nov 13, 2003 5:46 pm
Post subject:
i can identify, but if i find its not a bmp, i have to concat that data to map data. It's not a serious issue, i was just momentarily frustrated by it
Helicon - Thu Nov 13, 2003 10:03 pm
Post subject:
Next Question:

java is a serious pain here... though JNI is going to be a bad idea if this can be done in java:

i have never had to read a 12-bit int.
Java supports bools and bytes, nothing in between
does anyone know how to do the following in java:
split 3 bytes into 2 consecutive 12-bit ints
make an int from 12 booleans

this should get me working(buggy) lvl loader, assuming i know what im doing (i don't)
Dr Brain - Thu Nov 13, 2003 10:16 pm
Post subject:
int int1 = byte1 << 4 + byte2 >> 4;
int int2 = (byte2 << 8 + byte3) & (0xFFF);

Note: if the compiler doesnt like it, cast the bytes to ints.

int from tweleve bools is harder. You could simply do 12 consecutive OR masks, but thats a real real pain. If you can byte shift bools into ints, it makes it easier.
Helicon - Thu Nov 13, 2003 10:33 pm
Post subject:
we non-programmers suck with anything smaller than classes sa_tongue.gif

thanks brain (*poit*)
Dr Brain - Thu Nov 13, 2003 11:06 pm
Post subject:
Check the API for a bit storage class. It may be able to export to an int.
Helicon - Thu Nov 13, 2003 11:08 pm
Post subject:
did so, maybe im looking in the wrong places... but i dont think so
Dr Brain - Fri Nov 14, 2003 9:31 am
Post subject:
Well, I found a bitset, but that doesnt give you back an integer.

It may be easier to store everything in the integer, and when you need to get the boolean, simply:

boolean myBool = (myBitInt & (1 << x) == (1 << x))

where x is the place you need, starting at 0.
Cyan~Fire - Fri Nov 14, 2003 4:12 pm
Post subject:
Sorry, I have barely any Java experience, but there isn't a C++ union type thing in Java? It would be easy to form an integer from bits with a union.
Helicon - Fri Nov 14, 2003 5:07 pm
Post subject:
i dont believe there are native unions. what i want is a struct, which isn't supported

thanks brain,but once i get to ints i'm happy. I can just reverse the operation to write 12 - bit ints to files
Helicon - Tue Nov 18, 2003 8:49 pm
Post subject:
i've hit a stumbling block on the lvl loader... is there a good (reliable) java bitmap class around that supports conversion to Image object s, clipping subimages, and reading files like lvls without splitting off the ends (just read length in the file)???
Dr Brain - Tue Nov 18, 2003 10:57 pm
Post subject:
So you need a way to view the tileset as an Image? Is that what you need?

Take a look at the javax.imageio package. It can read a FileStream into a BufferedImage, which you can take and clip and stuff.

Reading the LVL data from the Image is probably impossible. What you will probably have to do is to read the file in twice (or put it into a buffer). Read it once for the tileset using imageio, and once again for the lvl data.
Helicon - Wed Nov 19, 2003 4:47 pm
Post subject:
could someone give me a rundown on how to skip over the bitmap with a stream?
also, i'm needing to convert to unsigned int for the file size. i don't want to mess this up. any solutions?
Dr Brain - Wed Nov 19, 2003 8:51 pm
Post subject:
I don't know specifics of the bitmap format, but all you need to do is read the bitmap stuff until its end, then pass your BufferedReader into your LVL parser.

Unisgned int? How do you mean convert? From what, into what?
Helicon - Wed Nov 19, 2003 10:56 pm
Post subject:
here comes a mess...
this has (somewhere) gone very wrong
please take a look.
obviously some of these classes are not completed. I attempted to finish the read/input ones, and wrote a test app for it. That's when things get ugly

any help appreciated.
Thanks
Dr Brain - Thu Nov 20, 2003 9:19 am
Post subject:
Ok, looking through your code, the easiest way to do what you want is to pass the two reading functions the same FileStream. That way, when one is done reading the bitmap, the stream is all ready to read in the LVL. You should be careful of missing a single read at the transition, I'm not sure if that will happen, but you should be careful.

I'm not familiar with the BMP format, but a simple google search should yeild BMP reading code (its not included in imageio :<). The only thing you need to watch for is that the code doesn't read the entire stream, but rather stops when its done with the bitmap section.
Helicon - Thu Nov 20, 2003 4:02 pm
Post subject:
i considered that approach, i can't remember now why i split it. I think it had something to do with feeding to the Bitmap class(not mine, given by a friend) a File object.
Helicon - Sat Nov 22, 2003 10:40 pm
Post subject: JInternalFrames
in the following zip, run the test class.
Nothing appears if i use an instance of MapDocument - which extends JInternalFrame.

Except nothing appears in the desktop pane.

Now change the MapDocument to JInternalFrame in the initialisaion and declaration in Test. Everything will work like a charm....

please see the addDocument(Document) method in class Main to see what the problem is.. i think the problem may be there. either that or i have set something amok with the desktop pane.
Dr Brain - Sun Nov 23, 2003 12:04 am
Post subject:
I will take a look at it tomorow when I get home.
Dr Brain - Mon Nov 24, 2003 11:37 pm
Post subject:
Don't know. I don't have the time at the moment to give it a full debug, but there are plenty of decent tutorials on doing what you want.
Helicon - Tue Nov 25, 2003 7:19 pm
Post subject:
no tutorials... i got it to run. something to do with the order of calls to show it. maybe its my runtimes. in any case, it now ~works~.

Thanks anyway
Helicon - Tue Nov 25, 2003 11:55 pm
Post subject:
about imageio, i did some tests. it hits jpeg, png, gif well, but i havent had success loading and g.drawImage() with bitmaps... i don't suppose you'd all mind moving to png though would you?

oh and a minor correction.. i did some more tests with graphics painting (benchmark-ish) and it turns out my test implementations from before hand were nothing like the actual situation will call for (assuming i'm not wrong again). Hope returns... java performance, talley-ho!!!
Goldeye - Mon Dec 15, 2003 10:55 pm
Post subject:
I'm working on a C# map editor. Goals are to include the basic lvl stuff, and a nice little environment for lvz. Maybe even throw a set editor on top for fun.
I'm using DirectDraw for it, makes sense to anyway since its what Cont uses..
So far my problems have been in things about forms.. Anyone know how I would make a fixed tool window that stays on top when you are in the main window, but doesn't take focus from the main window (tileset) I have to close the tileset or the close button is faded out on the main window. I tried having it as an MDI child, and was having some problems, will try it again though.

Heres what I did to check if first two bytes are BM.
Code: Show/Hide

//Check if there is a tileset.

         byte[] header= new byte[6];
         //Open the
         System.IO.FileStream lvl = System.IO.File.Open(tileSetPath,FileMode.Open,FileAccess.ReadWrite);
         lvl.Read(header,0,6);
         //If first two bytes of header != "BM", assume theres no tileset.
         if(header[0] != 0x42 || header[1] != 0x4D)
            return;
         //Reset the FileStream so you can...
         lvl.Flush();
         //Load the tileset to a bitmap.
         tileSetBMP = new Bitmap(lvl);
         lvl.Close();


Theres a function to change a byte array to a dword(uint32) System.BitConverter.ToUInt32(byte[] value, int startindex), which I'll be using to get the length. But how can you sightread the length off of the 4 bytes after BM?
50% Packetloss - Tue Dec 16, 2003 1:50 am
Post subject:
Hopefully this helps? Its C++ and all Mine GO BOOM's code

Mine GO BOOM wrote:

Then every 4bytes (or int) you read in, just type it to a struct tilerecord. Example (quick hack, didn't debug/compile):

Code: Show/Hide
#pragma pack(1)
struct tilerecord
{
   unsigned int x     : 12;
   unsigned int y     : 12;
   unsigned int tile  : 8;
};

struct lvlheader
{
   unsigned short type; /* should be 19778, aka 'B' followed by 'M' */
   unsigned int lengh;
};
#pragma pack()

char buff[6];
struct tilerecord *tile = (struct tilerecord*)buff;
struct lvlheader *header = (struct lvlheader*)buff;
/* could use a union, but this is good enough */
FILE *f;

f = fopen(LVLFILENAME, "rb");
if (!f) return 0; /* couldn't open file */

if (fread(buff, 6, 1, f)) /* check to see if has bmp data up front */
{
   if (header->type == 19778) /* yep, has the string "BM" up front */
      fseek(f, header->length, SEEK_SET); /* skip forward to end of BMP data */
   else /* didn't have header up front, means should be tile info */
      fseek(f, 0, SEEK_SET); /* rewind to front again */
}
else /* couldn't read 6 bytes, which COULD mean a lvl with only 1 tile, or an empty file */
   fseek(f, 0, SEEK_SET);

/* We should now be where the tile info is at */
while (fread(buff, 4, 1, f))
{
   /* keep reading until we cannot read 4 bytes anymore */
   if (tile->tile == 220) /* check to see if wormhole */
   {
      /* Do your "found a wormhole" stuff here.
       * Remember, it only tells the upper-left corner of a wormhole,
       * so the actual area includes the 4x4 box (i think) to the right/down
       * of this position.
       */
   }
}
fclose(f);

nintendo64 - Thu Dec 18, 2003 10:54 am
Post subject:
What directx headers are you using?, CTM uses 2 and if you're going to use DirectDraw use DX2 or DX3 ones. I recommend using GDI for the map editor.

-nintendo64
Goldeye - Mon Dec 22, 2003 2:21 am
Post subject:
Heh, I was using DX9.. its the only one that microsoft encapsulated into .NET :/ There is no way I'll manage to do the same with any earlier DX using Managed C++ <shudder>. C# is fun because it lets you do everything you want without guessing how many ____'s you need.

As for GDI, I really have no clue how to use it. icon_sad.gif Then again, I don't have much clue of anything here. What would be the most practical way to load enough tiles at once to do whats needed. After all, I don't wanna deal with 1000000 bitmap objects.. Last time I tried that I ended the process when it was only using 200,000KB of ram.
2dragons - Wed Feb 25, 2004 1:33 am
Post subject:
I'm actuallly working on a full lvl/lvz editor in java. I've had pretty good success, fairly smooth scrolling considering it is java. I'll include a wrapped jar to exe file if you want a very basic preview.

I'll also include a couple classes I used to read in the map.
* please note it is mostly a quick hack but hopefully the code can help you along your way.

I'm sure you can probably rip the jar out of the exe. But I'll probably give anyone the source once I get it more complete.
Mr Ekted - Wed Feb 25, 2004 1:58 am
Post subject:
WARNING: DO NOT WRITE CODE LIKE MGB
Mine GO BOOM - Wed Feb 25, 2004 10:47 am
Post subject:
Mr Ekted wrote:
WARNING: DO NOT WRITE CODE LIKE MGB

You forgot to bold that, fixed it for you.

Not all my code is bad. And that example above was done by pure memory alone (excluding the structs).
Mr Ekted - Wed Feb 25, 2004 11:25 am
Post subject:
LOL

I'm talking about the layout of the code. It is unreadable. Even if you live with it like that for yourself, take a minute and make it nice before posting.
Anonymous - Wed Feb 25, 2004 2:29 pm
Post subject:
ugg, just some minor technicalities lol... icon_smile.gif
Helicon - Fri Apr 23, 2004 8:28 pm
Post subject:
next question, still in the map format:

how would one (in java code) convert from an int containing bits for a signed integer into an int representing the same value but in two's compliment and signed???
CypherJF - Sat Apr 24, 2004 2:09 am
Post subject:
You'll be able to find the length of the BMP portion of the .lvl, by what Dr Brain suggested, checking the BMP format. So the BMP will be substr(0, length determined by reading into the BMP struct-1?)
Cyan~Fire - Sat Apr 24, 2004 10:39 am
Post subject:
So wait, right now you have a bunch of ints containing either 1 or 0? I have no clue how you got there, but if it is, just left shift each int to the place you want it to go in the final number and add it to a signed sum integer. If it is the bits, then you won't have to worry about 'converting' to two's complement, since it will already be in it. (If the number exceeds 127, it will be negative.)

Nice to see some progress icon_biggrin.gif
Helicon - Sat Apr 24, 2004 10:47 am
Post subject:
the bits are read raw from a file generated by c or c++ code.
unsigend ints are not available in java (all ints and bytes are signed). In addition, casting in java maintains numerical value across types, not bits (two's compliment). hence there is a change in encoding between types. A non-cast mathematical conversion is required. I've nearly got it right, though suggestions are still welcome.
Helicon - Sat Apr 24, 2004 1:45 pm
Post subject:
perhaps i can make my situation more clear:

reading the attached map with the following code:

Code: Show/Hide
byte[] rawInput = new byte[4];
while (fs.read(rawInput) != -1) {
   int row = rawInput[0] << 4 + rawInput[1] >> 4;
   int col = ((rawInput[1]) << 8) + ((rawInput[2]) & (0xFFF));
   System.out.println("Read tile: (" + row + "," + col + ") value: " + rawInput[3]);
}


yields
Quote:
Read tile: (0,0) value: 1
Read tile: (65536,4096) value: 1
Read tile: (2,8192) value: 1
Read tile: (196608,12288) value: 1

in actuality, the tiles are at
(1,1) (2,2) (3,3) (4,4)
and are all value 1 (0???) - they will need to be converted as well as larger numbers are made negative

i assume that the upperleftmost tile is stored as (1,1) and not (0,0)??

perhaps this makes the need more clear: i need to convert the values of row and col to their signed equivalents, and then back for writing
Mr Ekted - Sat Apr 24, 2004 3:45 pm
Post subject:
Something is seriously wrong. Tile coords are stored in row order in the lvl file, and the coords go from 0,0 to 1023,1023. Your code for picking out the bit fields is wrong. I wouldn't use the mechanism you are using. You are asking for trouble. Read your map data into an unsigned long...

Code: Show/Hide
unsigned long data;

x = data & 0x03ff;
y = (data >> 12) & 0x03ff;
tile = data >> 24;


No new/delete. No messing with bytes.
Helicon - Sat Apr 24, 2004 4:31 pm
Post subject:
did i mention that this is Java code? it is a java map editor...
Mr Ekted - Sat Apr 24, 2004 4:36 pm
Post subject:
Well, your byte handling is incorrect, and possibly makes a false assumption, although I don't know java. In C, if you shift a byte, the result is a byte, so...

Code: Show/Hide
BYTE a;
int b;

a = 0xff;
b = a << 8;


b = 0


Doesn't java have an unsigned 32-bit type?
Helicon - Sat Apr 24, 2004 4:44 pm
Post subject:
Mr Ekted wrote:
Doesn't java have an unsigned 32-bit type?

no they are all signed except the 16bit char
Cyan~Fire - Sun Apr 25, 2004 11:10 am
Post subject:
Does it really matter? Even if the data ends up 'negative' the bits are still what they should be. Therefore, doing bitwise operators on it should have the same result even if it was unsigned. (Using Ekted's method, at least; I don't really understand yours.)
Helicon - Sun Apr 25, 2004 2:27 pm
Post subject:
bytes must be promoted to ints to allow for all 8-bit unsigned values, and the uint12s can remain java's signed 21 bit ints.
Mr Ekted - Sun Apr 25, 2004 3:36 pm
Post subject:
Make sure you understand my post about shifting bytes, and how Java handles it. It will make the difference between reading a map and not.
CypherJF - Sun Apr 25, 2004 8:19 pm
Post subject:
I haven't had a chance to look at the VB code for map editors; but it can be done w/o bit shifting... :/ FACTs map editor source has it.
Helicon - Sun Apr 25, 2004 10:04 pm
Post subject:
the formulas from MERV and Ekted work fine in c# and c++, but not in java:

Code: Show/Hide
int r = dis.readInt();
System.out.println("Raw SInt32 = \t" + Integer.toBinaryString(r));
int tile = (r >>> 24);
int y = (r >>> 12) & 0x03FF;
int x = r & 0x03FF;
System.out.println("x = \t" + Integer.toBinaryString(x));
System.out.println("y = \t" + Integer.toBinaryString(y));
//int t = r & 0x000000ff; // this reads the tile fine
System.out.println("(" + x + "," + y + ") = " + tile);

(>>> is the unsigned right shift which always fills 0s)

yields
Code: Show/Hide
Raw SInt32 =    10101001
x =    10101001
y =    0
(169,0) = 0
Raw SInt32 =    1000100000000000010101001
x =    10101001
y =    100000000
(169,256) = 1
Raw SInt32 =    10001000000000000010101001
x =    10101001
y =    1000000000
(169,512) = 2
Raw SInt32 =    11001100000000000010101001
x =    10101001
y =    1100000000
(169,768) = 3
for default.lvl
note that toBinaryString() does not represent leading 0s

the following mask code is always good for the tile value:
Code: Show/Hide
int tile = r & 0x000000ff;


special notes:
anything shifted to position 32 in a java int is lost.
the same goes for pos 64 in a long


perhaps i am not precisely clear on the map format.
i have been referencing http://www4.ncsu.edu:8030/~rniyenga/subspace/old/lvlformat.html

a hex view of default.lvl shows strange results

what exactly is the structure, bit by bit, of the format. i am under the impression that it is this:

Quote:
xxxx xxxx xx00 yyyy yyyy yy00 tttt tttt = 32 bits
where xs are x value bits, and so on where 0s are illegal (>1023)


this seems to conflict with the diagram on the format page... so i must be missing something

i've had no problem loading maps with these procedures in c# and c++. but java is the target...

thanks to all for continued patience and help... i can be remarkably absent-minded, but i am going to get this
Mr Ekted - Sun Apr 25, 2004 11:13 pm
Post subject:
What exactly does readInt() do?
Helicon - Mon Apr 26, 2004 7:18 am
Post subject:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInput.html#readInt()
Mr Ekted - Mon Apr 26, 2004 5:06 pm
Post subject:
Aha! This is backwards. The value you read will be in the wrong byte order. That's why your math doesn't work. Change your math assuming the bytes in your int look like:

xx yx yy tt

and it should work.
Helicon - Mon Apr 26, 2004 5:15 pm
Post subject:
yeah i got it at school today... i had to print out about 4 test coords to figure it out though... thanks all!
Mr Ekted - Mon Apr 26, 2004 5:45 pm
Post subject:
I bet Java has a function to reverse byte order so you can deal with Intel stuff.
CypherJF - Mon Apr 26, 2004 6:15 pm
Post subject:
hm, why oh why did someone said the language takes care of the byte order for you. I believe it was C++ they were talking about? Java does not? I'm confused sa_tongue.gif
Cyan~Fire - Mon Apr 26, 2004 7:00 pm
Post subject:
Java is cross platform, so you have to deal with different byte orders. C++ is not, so the mandatory recompile takes care of it.

Once again, the flaws of Java.
Helicon - Mon Apr 26, 2004 7:31 pm
Post subject:
the flaws of java are undone:

an untested Tile class:
Code: Show/Hide

package MapEditor.Data;

import java.awt.Image;

/**
* represents a single tile at a location on a map
*/
public class Tile {
   private int value;
   private int x;
   private int y;

   public Tile(int value, int x, int y) throws IllegalArgumentException {
      try {
         setValue(value);
         setX(x);
         setY(y);
      } catch (IllegalArgumentException e) {
         throw e;
      }
   }
   public int getValue() {
      return value;
   }
   public void setValue(int value) throws IllegalArgumentException {
      if (!testTileValue(value)) throw getStandardTileValueException(value);
      this.value = value;
   }
   public int getX() {
      return x;
   }
   public void setX(int x) throws IllegalArgumentException {
      if (!testTileLocationValue(x)) throw getStandardTileLocationException(x);
      this.x = x;
   }
   public int getY() {
      return y;
   }
   public void setY(int y) throws IllegalArgumentException {
      if (!testTileLocationValue(y)) throw getStandardTileLocationException(y);
      this.y = y;
   }
   /**
    * @see TileSet.getTileImage()
    */
   public Image getTileImage(TileSet set) {
      return set.getTileImage(this.getValue());
   }
   public String toString() {
      return "(" + getX() + "," + getY() + ") = " + getValue();
   }
   /**
    * @param v the value to test
    * @return whether v is a valid VIE tile value
    */
   public static boolean testTileValue(int v) {
      if (v == 216 || v == 217 || v == 219 || v == 220) return true;
      if ((v >= 1 && v <= 190)) return true;
      return false;
   }
   /**
    * @param n the location value to test
    * @return whether 0 <=n <=1023
    */
   public static boolean testTileLocationValue(int n) {
      if (n >= 0 && n <= 1023) return true;
      return false;
   }
   public static IllegalArgumentException getStandardTileLocationException(int v) {
      return new IllegalArgumentException("Tile location " + v
            + " is invalid (must be 0 to 1023");
   }
   public static IllegalArgumentException getStandardTileValueException(int v) {
      return new IllegalArgumentException("Tile value " + v
            + " is invalid (must be 1-190, 216,217,219, or 220");
   }
}


Code: Show/Hide

   /**
    * NOTE: write(int) or read(int) do not demand all 32 bits, use
    * DataInputStream and DataOutputStream to encode LVLS
    *
    * @param t the tile to encode
    * @return a 32 bit java integer that represents the tile in LVL format
    */
   public static int buildRawData(Tile t) {
      int ret = ((t.getX() & 0x000000ff) << 24) | ((t.getY() & 0x0000000f) << 20)
            | ((t.getX() & 0x0000000f) << 8) | ((t.getY() & 0x00000ff0) << 4)
            | (t.getValue() & 0x000000ff);
      return ret;
   }


Code: Show/Hide

   /**
    * NOTE: write(int) or read(int) do not demand all 32 bits, use
    * DataInputStream and DataOutputStream to encode LVLS
    *
    * @param r the int to be parsed
    * @return a tile representing the raw tile's encoded information
    */
   public static Tile parseRawTileData(int r) {
      int tile = r & 0x000000ff;
      int x = ((r & 0x000f0000) >>> 8) | ((r & 0xff000000) >>> 24);
      int y = ((r & 0x0000ff00) >>> 4) | ((r & 0x00f00000) >>> 20);

      return new Tile(tile, x, y);
   }


these functions have been tested by reading in and building the same data from functions. Needless to say, more testing is probably a good idea. i will do so when i am feeling less enthusiastic...
Helicon - Wed Apr 28, 2004 11:42 pm
Post subject:
in case there were notions of vapourware (like i'd give a damn...) here is a screen shot from the semi-operational, abhorently buggy first working build:
2dragons - Thu Apr 29, 2004 3:43 am
Post subject:
These are the files I wrote for my lvl/lvz editor. Hopefully they can help u.
Cyan~Fire - Thu Apr 29, 2004 10:48 pm
Post subject:
Hey, not bad. Sorry about my pessimism earlier. icon_smile.gif
Anonymous - Fri Jun 18, 2004 2:20 am
Post subject:
Is there going to be another release anytime soon?
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group