forest-net
an overlay networks for large-scale virtual worlds
|
Class that implements a simulated avatar in a virtual world. More...
#include <Avatar.h>
Public Member Functions | |
Avatar (ipa_t, comt_t, comt_t) | |
Constructor allocates space and initializes private data. More... | |
bool | init (ipa_t, string &, string &, char *) |
Perform all required initialization. More... | |
void | run (uint32_t) |
Main Avatar processing loop. More... | |
Static Public Attributes | |
static const int | STATUS_REPORT = 1 |
status report payload code | |
Private Types | |
enum | STATE { IDLE, JOINING, LEAVING } |
Private Member Functions | |
int | groupNum (int, int) |
Return the multicast group number associated with given position. More... | |
bool | login (ipa_t, string, string) |
Send username and password to the Client manager, and receive. More... | |
bool | setupWalls (const char *) |
Setup the internal representation of the walls. More... | |
bool | separated (int, int) |
Determine if two adjacent squares are separated by a wall. More... | |
void | updateVisSet () |
void | computeVisSet (int, set< int > &) |
Compute a visbility set for a given square in the virtual world. More... | |
bool | isVis (int, int) |
Determine if two squares are visible from each other. More... | |
bool | linesIntersect (double, double, double, double, double, double, double, double) |
void | updateStatus (uint32_t) |
Update status of avatar based on passage of time. More... | |
void | updateNearby (int) |
Update the set of nearby Avatars. More... | |
void | updateSubs () |
Update subscriptions without changing comtrees. More... | |
void | sendStatus (int) |
Send a status packet on the multicast group for the current location. More... | |
void | startComtSwitch (comt_t, uint32_t) |
Start the process of switching to a new comtree. More... | |
bool | completeComtSwitch (pktx, uint32_t) |
Attempt to complete the process of switching to a new comtree. More... | |
void | send2comtCtl (CtlPkt::CpType, bool=false) |
Send join or leave packet packet to the ComtreeController. More... | |
comt_t | check4command () |
Check for a new command from remote display program. More... | |
void | forwardReport (uint32_t, int, int=0) |
Send a status report to the remote controller for this avatar. More... | |
void | subscribeAll () |
Subscribe to all multicasts for regions that are currently visible and that we're not already subscribed to. | |
void | unsubscribeAll () |
Unsubscribe from all multicasts that we're currently subscribed to. | |
void | subscribe (list< int > &) |
void | unsubscribe (list< int > &) |
Unsubscribe from a list of multicast groups. More... | |
bool | connect () |
Send initial connect packet to forest router Uses comtree 1, which is for user signalling. | |
bool | disconnect () |
Send final disconnect packet to forest router. | |
void | send (int) |
Send packet to forest router and recycle storage. | |
int | receive () |
Return next waiting packet or 0 if there is none. | |
Private Attributes | |
fAdr_t | myAdr |
forest address of host | |
ipa_t | myIp |
IP address of interface. | |
fAdr_t | rtrAdr |
forest address of router | |
ipa_t | rtrIp |
IP address of router. | |
ipp_t | rtrPort |
IP port of router. | |
fAdr_t | ccAdr |
forest address of ComtreeController | |
int | sock |
socket number for forest network | |
ipp_t | listenPort |
port to connect to Controller on | |
int | listenSock |
listen socket for remote driver | |
int | connSock |
for connected socket | |
uint64_t | nonce |
nonce used when connecting | |
comt_t | comt |
current comtree | |
comt_t | firstComt |
lower range of comtrees | |
comt_t | lastComt |
upper range of comtrees | |
int | x |
x coordinate in virtual world | |
int | y |
y coordinate in virtual world | |
double | direction |
direction avatar is facing in deg | |
double | deltaDir |
change in direction per period | |
double | speed |
speed moving in UNITS/update period | |
int | worldSize |
of grid squares per dimension | |
char * | walls |
array of walls | |
set< int > * | myVisSet |
myVisSet contains multicast groups More... | |
STATE | switchState |
current state | |
uint32_t | switchTimer |
time last signalling packet sent | |
int | switchCnt |
number of attempts so far | |
comt_t | nextComt |
comtree we're switching to | |
int | seqNum |
sequence number of control packet | |
long long | subSeqNum |
sequence number for subscriptions | |
set< int > * | mySubs |
multicast group subscriptions | |
HashSet * | visibleAvatars |
set of visible avatars | |
HashSet * | nearAvatars |
set of nearby avatars More... | |
int | numVisible |
number of visible avatars | |
int | numNear |
number of nearby avatars | |
PacketStore * | ps |
pointer to packet store | |
Static Private Attributes | |
static const int | UPDATE_PERIOD = 50 |
ms between status updates | |
static const int | LISTEN_PORT = 30130 |
port for remote controller | |
static const int | NUM_ITEMS = 10 |
of items in status report | |
static const int | GRID = 10000 |
xy extent of one grid square | |
static const int | MAXNEAR = 1000 |
max # of nearby avatars | |
static const int | SLOW =100 |
slow avatar speed | |
static const int | MEDIUM =250 |
medium avatar speed | |
static const int | FAST =600 |
fast avatar speed | |
static const int | STOPPED = 0 |
static const int | MAX_VIS =20 |
max distance can "see" (in squares) | |
static const uint32_t | SWITCH_TIMEOUT = 500000 |
500 ms timeout | |
static const bool | RETRY = true |
flag used to signal retry | |
Class that implements a simulated avatar in a virtual world.
This class implements an avatar in a very simple virtual world. The world is just a square area that is divided into a set of grid squares. The avatar wanders randomly around the square, issuing status reports periodically, indicating where it is, the direction in which it's moving and its velocity. The status reports are sent on a multicast group associated with the the grid square it's currently in. The Avatar also subscribes to multicasts for all squares within its "visibility range".
Constructor allocates space and initializes private data.
mipa | is this host's IP address |
fc | is the first comtree in the range used by the avatar |
lc | is the last comtree in the range used by the avatar |
Definition at line 69 of file Avatar-save.cpp.
|
private |
Check for a new command from remote display program.
Check to see if the remote display has sent a comand and respond appropriately. Commands take the form of pairs (c,i) where c is a character that identifies a specific command, and i is an integer that provides an optional parameter value for the command. The current commands are defined below.
j steer the Avatar to the left l steer the Avatar to the right i speed up the Avatar k slow down the Avatar c change comtree to the given parameter value
Note that the integer parameter is sent even when the command doesn't use it
Definition at line 703 of file Avatar-save.cpp.
|
private |
Attempt to complete the process of switching to a new comtree.
This involves completing signalling interactions with ComtCtl, including re-sending signalling packets when timeouts occur.
p | is a packet number, or 0 if the caller just wants to check for a timeout |
now | is the current time |
Definition at line 519 of file Avatar-save.cpp.
|
private |
Compute a visbility set for a given square in the virtual world.
g1 | is the multicast group number for a square in the virtual world |
vSet | is a reference to a visibility set in which the result is to be returned |
Definition at line 266 of file Avatar-save.cpp.
|
private |
Send a status report to the remote controller for this avatar.
now | is the current time |
avType | is the type code for the avatar whose status is being sent: 1 means the Avatar for "this" object, 2 a visible avatar and 3 an avatar that we can "hear" but not see |
p | is an optional packet number; if present and non-zero, its payload is unpacked to produce the report to send to the avatar |
Definition at line 621 of file Avatar-save.cpp.
|
private |
Return the multicast group number associated with given position.
Assumes that SIZE is an integer multiple of GRID
x1 | is the x coordinate of the position of interest |
y1 | is the y coordinate of the position of interest |
Definition at line 987 of file Avatar-save.cpp.
bool forest::Avatar::init | ( | ipa_t | cmIpAdr, |
string & | uname, | ||
string & | pword, | ||
char * | wallsFile | ||
) |
Perform all required initialization.
Definition at line 93 of file Avatar-save.cpp.
|
private |
Determine if two squares are visible from each other.
g1 | is the group number of the first square |
g2 | is the group number of the second square |
Definition at line 996 of file Avatar-save.cpp.
|
private |
Send username and password to the Client manager, and receive.
cmIpAdr | is the IP address of the client manager |
uname | is the username to log in with |
pword | is the password to log in with |
Definition at line 143 of file Avatar-save.cpp.
void forest::Avatar::run | ( | uint32_t | finishTime) |
Main Avatar processing loop.
Operates on a cycle with a period of UPDATE_PERIOD milliseconds, Each cycle, update the current position, direction, speed; issue new SUB_UNSUB packet if necessary; read all incoming status reports and update the set of nearby avatars; finally, send new status report
finishTime | is the number of microseconds to to run before halting. |
Definition at line 400 of file Avatar-save.cpp.
|
private |
Send join or leave packet packet to the ComtreeController.
joinLeave | is either CLIENT_JOIN_COMTREE or CLIENT_LEAVE_COMTREE, depending on whether we want to join or leave the comtree |
Definition at line 663 of file Avatar-save.cpp.
|
private |
Send a status packet on the multicast group for the current location.
now | is the reference time for the status report |
Definition at line 594 of file Avatar-save.cpp.
|
private |
Determine if two adjacent squares are separated by a wall.
c0 | is the index of a square |
c0 | is the index of an adjacent square (may be diagonal) |
Definition at line 957 of file Avatar-save.cpp.
|
private |
Setup the internal representation of the walls.
wallsFile | contains the specification of the walls in the virtual world |
Definition at line 215 of file Avatar-save.cpp.
|
private |
Start the process of switching to a new comtree.
Unsubscribe to the current comtree and leave send signalling message to leave the current comtree.
newComt | is the number of the comtree we're switching to |
now | is the current time |
Definition at line 492 of file Avatar-save.cpp.
|
private |
Unsubscribe from a list of multicast groups.
glist | is a reference to a list of multicast group numbers. |
Definition at line 1150 of file Avatar-save.cpp.
|
private |
Update the set of nearby Avatars.
If the given packet is a status report, check to see if the sending avatar is visible. If it is visible, but not in our set of nearby avatars, then add it. If it is not visible but is in our set of nearby avatars, then delete it. Note: we assume that the visibility range and avatar speeds are such that we will get at least one report from a newly invisible avatar.
Definition at line 1247 of file Avatar-save.cpp.
|
private |
Update status of avatar based on passage of time.
now | is the reference time for the simulated update |
controlInput | is the input code from the controller, or -1 if no controller is connected, or 0 if no current input |
Definition at line 869 of file Avatar-save.cpp.
|
private |
Update subscriptions without changing comtrees.
Unsubscribe from all multicasts for squares that are not visible from our current position, then subscribe to all missing multicasts that are visible.
Definition at line 1209 of file Avatar-save.cpp.
|
private |
|
private |