home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-21 | 7.6 KB | 157 lines |
- // Definition of an entity for the multi-user client
-
- // Written by Bernie Roehl, December 1996
-
- package multi;
-
- import java.util.*;
-
- public class Entity {
- int id; // entity id; also, SSRC for main RTP session
- int state = OKAY; // OKAY, STALE, DEAD, GONE
- boolean needInfo = true; // true if we need to update our registry info
-
- boolean hidden = false; // user doesn't want to see this avatar
- boolean muted = false; // user doesn't want to hear this avatar (including text)
-
- // from update messages:
- boolean changed = false; // true if we've changed recently
- long lastHeardFrom; // local timestamp of last update from entity
- Vec3 location; // X, Y, Z
- Rotation orientation; // rotation axis and angle
- long timestamp; // time for which location and orientation
- int region = 0; // region that this entity is in
- float size = 0; // approximate size (for acuity filtering)
- int seqnum = 0; // sequence number of most recent update
-
- // from registry host:
- boolean registry_changed; // set if the registry data has changed
- String cname; // unique canonical name (as per RTP)
- String url; // URL of file describing the entity (usually VRML)
- boolean has_new_url; // new URL has been set
- String nickname; // entity's nickname
- long creationTime; // world timestamp of entity's creation
- boolean persistent = false; // true if entity persists after owner leaves
- boolean avatar = false; // true if the entity is run by a human
- String owner; // username of entity's owner
- String[] info; // additional (SDES-style) entity info
-
- int text_SSRC; // SSRC of text data
- // unused as yet:
- int audio_SSRC; // SSRC of audio data
- int facial_expression_SSRC; // SSRC of MPEG-4 facial expression data
- int body_posture_SSRC; // SSRC of MPEG-4 body posture data
-
- Object representation; // reference to VRML node of shared object (for example)
-
- // accessor methods:
- public int getId() { return id; }
- public synchronized int getState() { return state; }
- public synchronized void setState(int state) { state = state; }
- public final static int OKAY = 0, STALE = 1, DEAD = 2, GONE = 3;
- public synchronized boolean needsInfo() { return needInfo; }
- public synchronized void needsAllInfo() { needInfo = true; }
- public synchronized void gotAllInfo() { needInfo = false; }
- public synchronized boolean hasNewURL() { return has_new_url; }
- public synchronized void markNewURL() { has_new_url = true; }
- public synchronized void unmarkNewURL() { has_new_url = false; }
-
- public synchronized boolean isHidden() { return hidden; }
- public synchronized void Hide(boolean flag) { hidden = flag; changed = true; }
- public synchronized boolean isMuted() { return muted; }
- public synchronized void Mute(boolean flag) { muted = flag; changed = true; }
-
- public synchronized int getTextSSRC() { return text_SSRC; }
- public synchronized void setTextSSRC(int ssrc) { text_SSRC = ssrc; }
-
- public synchronized Vec3 getLocation() { return location; }
- public synchronized Rotation getOrientation() { return orientation; }
- public synchronized long getTimestamp() { return timestamp; }
- public synchronized int getRegion() { return region; }
- public synchronized float getSize() { return size; }
- public synchronized long getLastUpdate() { return lastHeardFrom; }
- public synchronized boolean hasChanged() { return changed; }
- public synchronized void markUnchanged() { changed = false; }
- public int getSequenceNumber() { return seqnum; }
-
- public synchronized String getName() { return cname; }
- public synchronized void setName(String name) { cname = new String(name); }
- public synchronized String getURL() { return url; }
- public synchronized void setURL(String u) { url = new String(u); }
- public synchronized String getNickName() { return nickname; }
- public synchronized void setNickName(String name) { nickname = new String(name); }
- public synchronized long getCreationTime() { return creationTime; }
- public synchronized void setCreationTime(long time) { creationTime = time; }
- public synchronized boolean isPersistent() { return persistent; }
- public synchronized void setPersistent(boolean flag) { persistent = flag; }
- public synchronized boolean isAvatar() { return avatar; }
- public synchronized void setAvatar(boolean flag) { avatar = flag; }
- public synchronized String getOwner() { return owner; }
- public synchronized void setOwner(String own) { owner = new String(own); }
- public synchronized String[] getInfo() { return info; }
- public synchronized void setInfo(String[] inf) { info = inf; }
- public synchronized boolean registryHasChanged() { return registry_changed; }
- public synchronized void markRegistryChanged() { registry_changed = true; }
- public synchronized void markRegistryUnchanged() { registry_changed = false; }
-
- public synchronized Object getRepresentation() { return representation; }
- public synchronized void setRepresentation(Object obj) { representation = obj; }
-
- public synchronized void dump() {
- System.out.println("Entity " + id + " (state = " + state + ")");
- System.out.println("\tlocation = " + location + ", orientation = " + orientation);
- System.out.println("\ttimestamp = " + timestamp);
- System.out.println("\tregion = " + region + ", size = " + size);
- System.out.println("\tchanged = " + changed + ", last heard from = " + lastHeardFrom);
- if (text_SSRC != 0)
- System.out.println("Text SSRC = " + text_SSRC);
- if (needInfo == false) {
- if (nickname != null) System.out.println("\tnickname = " + nickname);
- System.out.println("\tname = " + cname + "; url = " + url);
- if (owner != null) System.out.println("\towner = " + owner);
- System.out.println("\tavatar = " + avatar + ", persistent = " + persistent);
- System.out.println("\tcreation time = " + creationTime);
- System.out.println("\trepresentation = " + representation);
- if (info != null)
- for (int i = 0; i < info.length; ++i)
- if (info[i] != null)
- System.out.println("\t" + info[i]);
- }
- }
-
- // constructor -- not public!
- Entity(int entid) {
- id = entid;
- lastHeardFrom = System.currentTimeMillis();
- location = new Vec3(0, 0, 0);
- orientation = new Rotation(0, 1, 0, 0);
- }
-
- public synchronized void update(UpdateMessage update) {
- if (update.getEntityId() != id)
- // id mismatch; ignore it
- return;
- if (update.getSequenceNumber() < seqnum)
- // packet is out-of-sequence; ignore it
- return;
- changed = true;
- location = update.getLocation();
- orientation = update.getOrientation();
- timestamp = update.getTimestamp();
- region = update.getRegion();
- size = update.getSize();
- if (update.isGone())
- state = GONE;
- else
- state = OKAY;
- lastHeardFrom = System.currentTimeMillis();
- }
-
- public synchronized void age() {
- if ((lastHeardFrom - System.currentTimeMillis()) > 10000)
- state = STALE; // 10 seconds since last update
- }
-
- }
-
-