Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Map editor snags and snares
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic Printable version
 View previous topic  SS NewsMaker 1.3 Post :: Post Greenland Lvz Editor  View next topic  
Author Message
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Sun Apr 25, 2004 2:27 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sun Apr 25, 2004 3:36 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Sun Apr 25, 2004 8:19 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Sun Apr 25, 2004 10:04 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sun Apr 25, 2004 11:13 pm    Post subject: Reply to topic Reply with quote

What exactly does readInt() do?
Back to top
View users profile Send private message Add User to Ignore List
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Mon Apr 26, 2004 7:18 am    Post subject: Reply to topic Reply with quote

http://java.sun.com/j2se/1.4.2/docs/api/java/io/DataInput.html#readInt()
Back to top
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Mon Apr 26, 2004 5:06 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Mon Apr 26, 2004 5:15 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Mon Apr 26, 2004 5:45 pm    Post subject: Reply to topic Reply with quote

I bet Java has a function to reverse byte order so you can deal with Intel stuff.
Back to top
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Mon Apr 26, 2004 6:15 pm    Post subject: Reply to topic Reply with quote

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
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Mon Apr 26, 2004 7:00 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Mon Apr 26, 2004 7:31 pm    Post subject: Reply to topic Reply with quote

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...
Back to top
View users profile Send private message Add User to Ignore List
Helicon
Server Help Squatter


Joined: Dec 03 2002
Posts: 771
Location: GNU Doldrums
Offline

PostPosted: Wed Apr 28, 2004 11:42 pm    Post subject: Reply to topic Reply with quote

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 76 time(s)
Back to top
View users profile Send private message Add User to Ignore List
2dragons
Novice


Joined: Feb 17 2004
Posts: 95
Offline

PostPosted: Thu Apr 29, 2004 3:43 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:36
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Apr 29, 2004 10:48 pm    Post subject: Reply to topic Reply with quote

Hey, not bad. Sorry about my pessimism earlier. icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Guest
Guest


Offline

PostPosted: Fri Jun 18, 2004 2:20 am    Post subject: Reply to topic Reply with quote

Is there going to be another release anytime soon?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Misc User Apps All times are GMT - 5 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 613 page(s) served in previous 5 minutes.

phpBB Created this page in 0.485816 seconds : 43 queries executed (91.7%): GZIP compression disabled