Author |
Message |
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: 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. _________________ Signatures just seem so quaint.
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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. _________________ 4,691 irradiated haggis!
|
|
Back to top |
|
|
CypherJF I gargle nitroglycerin
Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: 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. _________________ Performance is often the art of cheating carefully. - James Gosling
|
|
Back to top |
|
|
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: 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:
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
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:
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
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: Sun Apr 25, 2004 11:13 pm Post subject: |
|
|
|
|
What exactly does readInt() do?
|
|
Back to top |
|
|
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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.
|
|
Back to top |
|
|
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: 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!
|
|
Back to top |
|
|
Mr Ekted Movie Geek
Gender: Joined: Feb 09 2004 Posts: 1379 Offline
|
Posted: 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.
|
|
Back to top |
|
|
CypherJF I gargle nitroglycerin
Gender: Joined: Aug 14 2003 Posts: 2582 Location: USA Offline
|
Posted: 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
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: 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. _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
|
|
Back to top |
|
|
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: Mon Apr 26, 2004 7:31 pm Post subject: |
|
|
|
|
the flaws of java are undone:
an untested Tile class:
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");
}
}
|
/**
* 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;
} |
/**
* 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...
|
|
Back to top |
|
|
Helicon Server Help Squatter
Joined: Dec 03 2002 Posts: 771 Location: GNU Doldrums Offline
|
Posted: 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:
demo.PNG - 135.8 KB
File downloaded or viewed 80 time(s)
|
|
Back to top |
|
|
2dragons Novice
Joined: Feb 17 2004 Posts: 95 Offline
|
Posted: 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.
Map Editor.zip - 5.79 KB
File downloaded or viewed 69 time(s)
|
|
Back to top |
|
|
Cyan~Fire I'll count you!
Age:36 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Thu Apr 29, 2004 10:48 pm Post subject: |
|
|
|
|
Hey, not bad. Sorry about my pessimism earlier.
|
|
Back to top |
|
|
Guest Guest
Offline
|
Posted: Fri Jun 18, 2004 2:20 am Post subject: |
|
|
|
|
Is there going to be another release anytime soon?
|
|
Back to top |
|
|
|