00001
00002
00003
00004
00005
00006
00007
00008 #ifndef STATE_H_
00009 #define STATE_H_
00010
00011
00012 namespace FastEcslent {
00013
00014 const int MaxMessageSize = 65536;
00015
00016 struct __attribute__((__packed__)) PackedHeader{
00017 unsigned char msgType;
00018 int millisecondsFromStart;
00019 int numberOfStructs;
00020 int sizeOfStruct;
00021 };
00022
00023 typedef struct PackedHeader Header;
00024
00025 enum MessageTypes {
00026 INFOMESSAGETYPE = 0,
00027 STATEMESSAGETYPE = 1,
00028 REQUESTINFOMESSAGETYPE = 2,
00029 REQUESTSHIPSTATUSMESSAGETYPE = 3,
00030 COMMANDENTITYMESSAGETYPE = 4,
00031 CREATEENTITYMESSAGETYPE = 5,
00032 REPOSITIONENTITYMESSAGETYPE = 6,
00033 SQUELCHMESSAGETYPE = 7,
00034 NUMBEROFMESSAGETYPES = 8,
00035
00036 LOBBYSERVERTYPE = 30,
00037 LOBBYJOINREQUESTTYPE = 31,
00038 LOBBYJOINRESPONSETYPE = 32,
00039 LOBBYGAMESTARTTYPE = 33,
00040 LOBBYSLOTSWAPTYPE = 34,
00041 LOBBYEXITTYPE = 35
00042 };
00043
00044 struct __attribute__((__packed__)) PackedReqInfo{
00045 int id;
00046 };
00047
00048 typedef struct PackedReqInfo ReqInfo;
00049
00050 struct __attribute__((__packed__)) PackedState{
00051 int id;
00052 float px, py, pz;
00053 float vx, vy, vz;
00054 float yaw;
00055 float rSpeed;
00056 float ds;
00057 float dh;
00058 int flag;
00059 };
00060
00061 typedef struct PackedState State;
00062
00063 struct __attribute__((__packed__)) PackedInfo {
00064 int id;
00065 char label[256];
00066 char type[256] ;
00067 float maxSpeed;
00068 float maxSpeedReverse;
00069 float length;
00070 float beam;
00071 float draft;
00072 int playerId;
00073 int side;
00074
00075 };
00076
00077 typedef struct PackedInfo Info;
00078
00079 struct __attribute__((__packed__)) PackedCommandEntity {
00080 int id;
00081 float dh;
00082 float ds;
00083 } ;
00084
00085 typedef struct PackedCommandEntity CommandEntity;
00086
00087 struct __attribute__((__packed__)) PackedSquelchEntity {
00088 int id;
00089 } ;
00090
00091 typedef struct PackedSquelchEntity SquelchEntity;
00092
00093 struct __attribute__((__packed__)) PackedCreateEntity{
00094 char label[256];
00095 char entType[256];
00096 float px, py, pz;
00097 float yaw;
00098 } ;
00099
00100 typedef struct PackedCreateEntity CreateEntity;
00101
00102 struct __attribute__((__packed__)) PackedRepositionEntity {
00103 int id;
00104 float px, py, pz;
00105 float vx, vy, vz;
00106 float yaw;
00107 char label[256];
00108 };
00109
00110 typedef struct PackedRepositionEntity RepositionEntity;
00111
00112 struct __attribute__((__packed__)) PackedLobbyServer {
00113 int port;
00114 char name[64];
00115 unsigned int ip;
00116 int side;
00117 int player;
00118 int slot;
00119 char isHost;
00120 };
00121
00122 typedef struct PackedLobbyServer LobbyServer;
00123
00124 struct __attribute__((__packed__)) PackedLobbyJoinRequest {
00125 int port;
00126 unsigned int serverIP;
00127 unsigned int clientIP;
00128 char clientName[64];
00129 };
00130
00131 typedef struct PackedLobbyJoinRequest LobbyJoinRequest;
00132
00133 struct __attribute__((__packed__)) PackedLobbyJoinResponse {
00134 int port;
00135 unsigned int serverIP;
00136 unsigned int clientIP;
00137 int side;
00138 int player;
00139 };
00140
00141 typedef struct PackedLobbyJoinResponse LobbyJoinResponse;
00142
00143 struct __attribute__((__packed__)) PackedLobbyGameStart {
00144 int port;
00145 unsigned int serverIP;
00146 };
00147
00148 typedef struct PackedLobbyGameStart LobbyGameStart;
00149
00150 struct __attribute__((__packed__)) PackedLobbyExit {
00151 unsigned int serverIP;
00152 unsigned int clientIP;
00153 int port;
00154 };
00155
00156 typedef struct PackedLobbyExit LobbyExit;
00157
00158 struct __attribute__((__packed__)) PackedLobbySlotSwap {
00159 unsigned int serverIP;
00160 unsigned int newpos;
00161 unsigned int oldpos;
00162 unsigned int newside;
00163 unsigned int newplayer;
00164 int port;
00165 };
00166
00167 typedef struct PackedLobbySlotSwap LobbySlotSwap;
00168
00169 struct __attribute__((__packed__)) PackedMessage {
00170 Header head;
00171 char data[MaxMessageSize - sizeof(Header)];
00172 };
00173
00174 typedef struct PackedMessage Message;
00175
00176 const int MessageSize = sizeof(Message);
00177 const int HeaderSize = sizeof(Header);
00178 const int StateSize = sizeof(State) - sizeof(unsigned short);
00179 const int ReqInfoSize = sizeof(ReqInfo);
00180 const int InfoSize = sizeof(Info);
00181 const int CommandEntitySize = sizeof(CommandEntity);
00182 const int CreateEntitySize = sizeof(CreateEntity);
00183 const int RepositionEntitySize = sizeof(RepositionEntity);
00184 const int SquelchEntitySize = sizeof(SquelchEntity);
00185
00186 const int LobbyServerSize = sizeof(LobbyServer);
00187 const int LobbyJoinRequestSize = sizeof(LobbyJoinRequest);
00188 const int LobbyJoinResponseSize = sizeof(LobbyJoinResponse);
00189 const int LobbyGameStartSize = sizeof(LobbyGameStart);
00190 const int LobbyExitSize = sizeof(LobbyExit);
00191 const int LobbySlotSwapSize = sizeof(LobbySlotSwap);
00192
00193 void printMessageHeader(Header h);
00194 void printMessageData(Message *m);
00195 void printMessage(Message *m);
00196 void printState(State *s);
00197
00198
00199 }
00200
00201 #endif