Thread: Map object offset?

Results 1 to 7 of 7
  1. #1 Map object offset? 
    Registered Member Throat's Avatar
    Join Date
    Aug 2009
    Posts
    486
    Thanks given
    7
    Thanks received
    1
    Rep Power
    1
    Code:
            Stream stream = new Stream(abyte0);
    		int objectId = -1;
    		
    		do {
    			int objectIdOffset = stream.readUSmart2();
    			if (objectIdOffset == 0)
    				break;
    			objectId += objectIdOffset;
    			int loc = 0;
    			
    			do {
    				int objectPosOffset = stream.method422();
    				if (objectPosOffset  == 0)
    					break;
    				loc += objectPosOffset  - 1;
    				int localX = loc >> 6 & 0x3f;
    				int localY = loc & 0x3f;
    				int height = loc >> 12;
    				int objectData = stream.readUnsignedByte();
    				int type = objectData >> 2;
    				int direction = objectData & 3;
    Code:
    objectId = 6968
    objectPosOffset = 7339
    localX = 50
    localY = 42
    height = 1
    objectData = 40
    type = 10
    direction = 0
    Iirc, the red coloured lines above represent the offset of the object's position. But how is this calculated?

    Thanks.
    Reply With Quote  
     

  2. #2  
    plz dont take my wizard mind bombs Women's Avatar
    Join Date
    Mar 2010
    Posts
    1,881
    Thanks given
    724
    Thanks received
    1,162
    Rep Power
    4763
    Did you look in method422..?
    Reply With Quote  
     

  3. #3  
    Registered Member Throat's Avatar
    Join Date
    Aug 2009
    Posts
    486
    Thanks given
    7
    Thanks received
    1
    Rep Power
    1
    Quote Originally Posted by Women View Post
    Did you look in method422..?
    That's irrelevant, all it does is gets the short ...
    I'm talking about how the objectPosOffset was calculated (as in how it was created to serve as an offset, not how the short is gotten from the buffer).
    Reply With Quote  
     

  4. #4  
    Map object offset?



    Scu11's Avatar
    Join Date
    Aug 2007
    Age
    30
    Posts
    16,307
    Thanks given
    7,215
    Thanks received
    12,308
    Rep Power
    5000

    Attached image
    Reply With Quote  
     

  5. #5  
    Registered Member

    Join Date
    Feb 2007
    Posts
    994
    Thanks given
    25
    Thanks received
    47
    Rep Power
    604
    Here quick example of how the selection you have highlighted can be generated.

    Code:
    import java.util.ArrayList;
    import java.util.List;
    
    public class MapCompressTest {
    	
    	//stores the objects
    	private List<GameObject> list = new ArrayList<GameObject>();
    	
    	public static void main(String[] args) {
    		MapCompressTest test = new MapCompressTest();
    		
    		int lastValue = 0;
    		
    		//loop for the same object ids
    		for(GameObject obj : test.getList()) {
    			int compressed = obj.getCompressedValue();
    			
    			//the value is the same so write 1
    			if(lastValue == compressed) {
    				//TODO write one to the buffer
    				continue;
    			}
    			//otherwise check the dif between the two value
    			int dif = (compressed - lastValue) + 1;
    			
    			//debug to show example
    			System.out.println("Display");
    			GameObject.displayDecodeValue(compressed);
    			GameObject.displayDecodeValue(dif - 1);
    			
    			
    			//TODO write the dif to the stream
    			
    			//set the last value
    			lastValue = compressed;
    		}	
    	}
    	
    	public MapCompressTest() {
    		//same
    		list.add(new GameObject(1, 50, 40));
    		//same would give a change of 0
    		//list.add(new GameObject(1, 50, 40));
    		//new height
    		list.add(new GameObject(3, 50, 40));	
    	}
    	
    	public List<GameObject> getList() {
    		return list;
    	}
    	
    	
    	//containing class
    	public static class GameObject {
    		
    		private int height;
    		private int localX;
    		private int localY;
    		
    		public static void displayDecodeValue(int input) {
    			//uncompress the encoded value
    			System.out.println("Height:" +(input >> 12));
    			System.out.println("LocalX:" +((input >> 6) & 0x3f));
    			System.out.println("LocalY:" +((input) & 0x3f));
    		}
    		
    		public GameObject(int height, int localX, int localY) {
    			this.height = height;
    			this.localX = localX;
    			this.localY = localY;
    		}
    		
    		public int getCompressedValue() {
    			//compress the values into a 32bit int however we only require 14bits
    			//max value of localX and localY is 63 and 3 for height
    			return ((height << 12) | (localX << 6) | localY) ;
    		}
    	}
    
    }
    Reply With Quote  
     

  6. #6  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    the answer is 3 lines under the code

    Code:
    int localX = loc >> 6 & 0x3f;
    				int localY = loc & 0x3f;
    				int height = loc >> 12;
    Reply With Quote  
     

  7. #7  
    Renown Programmer
    veer's Avatar
    Join Date
    Nov 2007
    Posts
    3,746
    Thanks given
    354
    Thanks received
    1,370
    Rep Power
    3032
    in 377:
    Code:
    union obj_pos {
        struct {
            /* x,y are offsets into this current 64x64 region */
            uint y : 6; /* 0...63 */
            uint x : 6; /* 0...63 */
            uint plane : 2; /* 0...3 */
            /* unused 2 bits */
        };
        ushort enc; 
    }
    then for the delta ("objectPosOffset") it is calculated as (cur.pos.enc - prev.pos.enc) and written as an unsigned smart-sized value:
    Code:
        public int read_usmart() {
            int i = data[pointer] & 0xff;
            if (i < 128) /* size bit == 0 */
                return read_u8();
            else /* size bit == 1 */
                return read_u16() - 32768; /* use only latter 15-bits */
        }
    offsets are used because they will tend to be small numbers (iirc jagex tend to encode objects in ascending y,x,plane order, so the the delta will in most cases only actually require 6-bits [only y variant], followed by the lesser likely cases of 12-bits [x variant as well] and 14-bits [plane variant], in that order) and therefore landscape resource sizes will be reduced
    Reply With Quote  
     

  8. Thankful user:

    Normal DonatorGod


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Object Distance Offset calculation
    By Aleksandr in forum Requests
    Replies: 2
    Last Post: 09-17-2011, 11:31 PM
  2. Object map help
    By Brandyn in forum Help
    Replies: 3
    Last Post: 06-20-2010, 07:23 PM
  3. Object and Map
    By Ryan317 in forum Help
    Replies: 2
    Last Post: 05-25-2010, 10:59 PM
  4. Map Object Loading
    By Karilz in forum Help
    Replies: 11
    Last Post: 05-25-2010, 10:10 PM
  5. Offset on Object spawning
    By Xaves in forum Help
    Replies: 6
    Last Post: 05-06-2010, 06:36 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •