netThread.h

Go to the documentation of this file.
00001 /*
00002  * netThread.h
00003  *
00004  *  Created on: Jan 10, 2012
00005  *      Author: sushil
00006  */
00007 
00008 #ifndef NETTHREAD_H_
00009 #define NETTHREAD_H_
00010 
00011 #include <deque>
00012 #include <map>
00013 
00014 //#include <engine.h>
00015 #include <boost/asio.hpp>
00016 #include <boost/thread.hpp>
00017 //#include <boost/date_time/posix_time/posix_time.hpp>
00018 
00019 #include <messages.h>
00020 #include <listener.h>
00021 #include <sender.h>
00022 #include <ent.h>
00023 #include <boost/date_time/posix_time/posix_time.hpp>
00024 #include <netCommon.h>
00025 
00026 using namespace boost::posix_time;
00027 using boost::asio::ip::udp;
00028 
00029 namespace FastEcslent {
00030 
00031         class Engine;
00032 
00033         class NetThread {
00034 
00035         private:
00036                 void runThread();
00037                 void sendUnknownEntQueries();
00038                 boost::thread netThread;
00039                 int TICK_SLEEP_TIME;
00040 
00041                 ptime  startTime;
00042                 bool quit;
00043 
00044                 std::map<int, State*> unknows;
00045                 std::map<int, Entity*> netIdToEntMap;
00046                 std::map<Entity*, int> netEntToIdMap;
00047 
00048                 std::deque<CommandEntity*> commandQueue;
00049                 std::deque<SquelchEntity*> squelchQueue;
00050 
00051                 udp::endpoint myIP;
00052                 NetCommon *netCommon;
00053 
00054         public:
00055                 Engine* engine;
00056 
00057                 Listener*    listener;
00058                 Sender*      sender;
00059 
00060                 bool insideLobby;
00061                 bool isServer;
00062                 int port;
00063 
00064                 std::string myIPAddress;
00065                 boost::posix_time::milliseconds *sleepTime;
00066 
00067                 NetThread(Engine* eng) {
00068                         engine = eng;
00069                 }
00070                 void run();
00071                 void init();
00072                 void stopAndJoin();
00073                 void stop();
00074 
00075                 int getNetId(Entity* ent);
00076                 Entity* getEntityFromNetId(int entID);
00077 
00078                 //helpers
00079                 void clientTick();
00080                 void handleServerMessages();
00081                 void updateState(Message *m);
00082                 void updateState(State *s);
00083                 void createEntFromClientReq(int builderid, FastEcslent::EntityType ent, Ogre::Vector3 pos);
00084                 void createEntFromClientReq(Message *m);
00085                 void createEntFromClientRes(int builderid, int builtid);
00086                 void createEntFromClientRes(Message *m);
00087                 void createEnt(Message *m);
00088                 void createEnt(Info *info);
00089                 void sendCommands();
00090                 void sendCommand(int id, float dh, float ds);
00091                 void squelchEnts(Message *m);
00092 
00093                 void serverTick();
00094                 void handleClientMessages();
00095                 void handleMessage(Message *m);
00096                 void sendInfo(Message *m);
00097                 void propagateCommand(Message *m);
00098 
00099                 void combineCommandsIntoNetMessage();
00100                 void combineSquelchesIntoNetMessage();
00101 
00102                 void sendLobbyClientResponse(std::string clientIP, int port, int side, int player);
00103                 void lobbyStart();
00104 
00105                 void addCommand(CommandEntity *m);
00106                 void addSquelch(SquelchEntity *m);
00107 
00108                 void requestMineralPatchID(int mineralid);
00109                 void responseMineralPatchID(Message *m);
00110                 void updateMineralPatchID(Message *m);
00111                 void serve();
00112 
00113                 void gameTick();
00114         };
00115 
00116 }
00117 
00118 #endif /* NETTHREAD_H_ */

Generated on Fri Dec 13 14:54:16 2013 for FastECSLent by  doxygen 1.5.4