home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch18 / multi / UpdateMessage.java < prev    next >
Encoding:
Java Source  |  1997-02-21  |  1.5 KB  |  49 lines

  1. // An update message for the multi-user protocol
  2.  
  3. // Written by Bernie Roehl, December 1996
  4.  
  5. package multi;
  6.  
  7. import java.io.*;
  8.  
  9. class UpdateMessage {
  10.     int seqnum;
  11.     int entid;
  12.     long timestamp = System.currentTimeMillis(); 
  13.     Vec3 location = new Vec3();
  14.     Rotation orientation = new Rotation();
  15.     int region;
  16.     float size;
  17.     boolean gone;
  18.  
  19.     // accessor methods:
  20.     public int getEntityId() { return entid; }
  21.     public Vec3 getLocation() { return location; }
  22.     public Rotation getOrientation() { return orientation; }
  23.     public long getTimestamp() { return timestamp; }
  24.     public int getRegion() { return region; }
  25.     public float getSize() { return size; }
  26.     boolean isGone() { return gone; }
  27.     int getSequenceNumber() { return seqnum; }
  28.  
  29.     public UpdateMessage(byte[] buffer) throws IOException {
  30.         ByteArrayInputStream bin = new ByteArrayInputStream(buffer);
  31.         DataInputStream in = new DataInputStream(bin);
  32.         in.readByte();  // ignore version, padding, extension, CSRC count
  33.         if (in.readByte() != 79)  // payload type; marker is zero
  34.             throw new IOException("bad payload type!");
  35.         int seq = in.readShort();
  36.         seqnum = seq;
  37.         timestamp = in.readInt() << 16;
  38.         entid = in.readInt();
  39.         location.read(in);
  40.         orientation.read(in);
  41.         region = in.readInt();
  42.         size = in.readFloat();
  43.         int flags = in.readInt();
  44.         gone = ((flags & 0x0001) == 0x0001) ? true : false;
  45.     }
  46.  
  47. }
  48.  
  49.