forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Avatar.h
Go to the documentation of this file.
1
9
#ifndef AVATAR_H
10
#define AVATAR_H
11
12
#include <set>
13
#include <list>
14
#include <bitset>
15
#include "
Forest.h
"
16
#include "
Packet.h
"
17
#include "
CtlPkt.h
"
18
#include "
NetBuffer.h
"
19
#include "PacketStore.h"
20
#include "HashSet.h"
21
22
namespace
forest {
23
36
class
Avatar
{
37
public
:
38
Avatar
(ipa_t,
comt_t
,
comt_t
);
39
~
Avatar
();
40
41
bool
init
(ipa_t,
string
&,
string
&,
char
*);
42
void
run
(uint32_t);
43
const
static
int
STATUS_REPORT
= 1;
44
private
:
45
const
static
int
UPDATE_PERIOD
= 50;
46
const
static
int
LISTEN_PORT
= 30130;
47
const
static
int
NUM_ITEMS
= 10;
48
const
static
int
GRID
= 10000;
49
const
static
int
MAXNEAR
= 1000;
50
// speeds below are the amount avatar moves during an update period
51
const
static
int
SLOW
=100;
52
const
static
int
MEDIUM
=250;
53
const
static
int
FAST
=600;
54
const
static
int
STOPPED = 0;
55
56
// network parameters
57
fAdr_t
myAdr
;
58
ipa_t
myIp
;
59
fAdr_t
rtrAdr
;
60
ipa_t
rtrIp
;
61
ipp_t
rtrPort
;
62
fAdr_t
ccAdr
;
63
int
sock
;
64
ipp_t
listenPort
;
65
int
listenSock
;
66
int
connSock
;
67
uint64_t
nonce
;
68
69
// comtrees
70
comt_t
comt
;
71
comt_t
firstComt
;
72
comt_t
lastComt
;
73
74
// avatar properties
75
int
x
;
76
int
y
;
77
double
direction
;
78
double
deltaDir
;
79
double
speed
;
80
81
// data structures defining walls in virtual world
82
const
static
int
MAX_VIS
=20;
83
int
worldSize
;
84
char
*
walls
;
85
set<int> *
myVisSet
;
86
88
// data for managing signalling interactions with ComtCtl
89
const
static
uint32_t
SWITCH_TIMEOUT
= 500000;
90
const
static
bool
RETRY
=
true
;
91
enum
STATE {
92
IDLE, JOINING, LEAVING
93
};
94
STATE
switchState
;
95
uint32_t
switchTimer
;
96
int
switchCnt
;
97
comt_t
nextComt
;
98
int
seqNum
;
99
long
long
subSeqNum
;
100
101
// data structures for multicast subscriptions and other avatars
102
set<int> *
mySubs
;
103
HashSet *
visibleAvatars
;
104
HashSet *
nearAvatars
;
105
int
numVisible
;
107
int
numNear
;
108
109
PacketStore
*
ps
;
110
111
// private helper methods
112
int
groupNum
(
int
,
int
);
113
bool
login
(ipa_t,
string
,
string
);
114
bool
setupWalls
(
const
char
*);
115
bool
separated
(
int
,
int
);
116
void
updateVisSet();
117
void
computeVisSet
(
int
, set<int>&);
118
bool
isVis
(
int
,
int
);
119
bool
linesIntersect(
double
,
double
,
double
,
double
,
120
double
,
double
,
double
,
double
);
121
122
void
updateStatus
(uint32_t);
123
void
updateNearby
(
int
);
124
void
updateSubs
();
125
void
sendStatus
(
int
);
126
127
void
startComtSwitch
(
comt_t
, uint32_t);
128
bool
completeComtSwitch
(pktx, uint32_t);
129
void
send2comtCtl
(
CtlPkt::CpType
,
bool
=
false
);
130
comt_t
check4command
();
131
void
forwardReport
(uint32_t,
int
,
int
=0);
132
133
void
subscribeAll
();
134
void
unsubscribeAll
();
135
void
subscribe(list<int>&);
136
void
unsubscribe
(list<int>&);
137
138
bool
connect
();
139
bool
disconnect
();
140
void
send
(
int
);
141
int
receive
();
142
};
143
144
}
// ends namespace
145
146
#endif
forest-net
cpp
include
Avatar.h
Generated on Mon Aug 4 2014 11:13:35 for forest-net by
1.8.4