Просмотр исходного кода

Minor changes/cleanups. Adventure map is shown :)

Michał W. Urbańczyk 17 лет назад
Родитель
Сommit
b72d065265
7 измененных файлов с 59 добавлено и 163 удалено
  1. 2 2
      client/Client.cpp
  2. 0 32
      lib/Connection.cpp
  3. 23 126
      lib/Connection.h
  4. 32 0
      lib/NetPacks.h
  5. 1 2
      server/CGameHandler.cpp
  6. 0 0
      server/CVCMIServer.cpp
  7. 1 1
      server/VCMI_server.vcproj

+ 2 - 2
client/Client.cpp

@@ -15,11 +15,11 @@ CClient::CClient(void)
 CClient::CClient(CConnection *con, StartInfo *si)
 	:serv(con)
 {
-	timeHandler tmh, pomtime;
+	timeHandler tmh;
 	CConnection &c(*con);
 ////////////////////////////////////////////////////
 	ui8 pom8;
-	c << ui8(2) << ui8(1);
+	c << ui8(2) << ui8(1); //new game; one client
 	c << *si;
 	c >> pom8;
 	if(pom8) throw "Server cannot open the map!";

+ 0 - 32
lib/Connection.cpp

@@ -18,38 +18,6 @@ using namespace boost::asio::ip;
 #define LIL_ENDIAN
 #endif
 
-//CConnection & operator<<(CConnection &c, const std::string &data)
-//{
-//	boost::uint32_t length = data.size();
-//	c << length;
-//	c.write(data.c_str(),length);
-//	return c;
-//}
-//CConnection & operator>>(CConnection &c, std::string &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	data.resize(length);
-//	c.read((void*)data.c_str(),length);
-//	return c;
-//}
-//CConnection & operator<<(CConnection &c, const char * &data)
-//{
-//	boost::uint32_t length = strlen(data);
-//	c << length;
-//	c.write(data,length);
-//	return c;
-//}
-//CConnection & operator>>(CConnection &c, char * &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	std::cout <<"Alokujemy " <<length << " bajtow."<<std::endl;
-//	data = new char[length];
-//	c.read(data,length);
-//	return c;
-//}
-
 void CConnection::init()
 {
 #ifdef LIL_ENDIAN

+ 23 - 126
lib/Connection.h

@@ -4,25 +4,13 @@
 #include <vector>
 #include <set>
 
-#include <boost/type_traits/is_pointer.hpp>
 #include <boost/type_traits/is_fundamental.hpp>
 #include <boost/type_traits/is_enum.hpp>
-#include <boost/type_traits/is_volatile.hpp>
-#include <boost/type_traits/is_const.hpp>
-#include <boost/type_traits/is_same.hpp>
-#include <boost/type_traits/remove_all_extents.hpp>
-#include <boost/serialization/is_abstract.hpp>
 
 #include <boost/mpl/eval_if.hpp>
-#include <boost/mpl/and.hpp>
-#include <boost/mpl/less.hpp>
-#include <boost/mpl/greater_equal.hpp>
 #include <boost/mpl/equal_to.hpp>
 #include <boost/mpl/int.hpp>
 #include <boost/mpl/identity.hpp>
-#include <boost/mpl/list.hpp>
-#include <boost/mpl/empty.hpp>
-#include <boost/mpl/not.hpp>
 
 const int version = 63;
 class CConnection;
@@ -243,16 +231,27 @@ public:
 		for(ui32 i=0;i<length;i++)
 			*this >> data[i];
 	}
-	//template <typename T>
-	//void saveSerializable(T &data)
-	//{
-	//	data.serialize(*static_cast<COSer*>(this),version);
-	//}
-	//template <typename T>
-	//void loadSerializable(T &data)
-	//{
-	//	data.serialize(*static_cast<CISer*>(this),version);
-	//}
+	template <typename T>
+	void saveSerializable(const std::set<T> &data)
+	{
+		boost::uint32_t length = data.size();
+		*this << length;
+		for(std::set<T>::iterator i=data.begin();i!=data.end();i++)
+			*this << *i;
+	}
+	template <typename T>
+	void loadSerializable(std::set<T> &data)
+	{
+		boost::uint32_t length;
+		*this >> length;
+		data.resize(length);
+		T ins;
+		for(ui32 i=0;i<length;i++)
+		{
+			*this >> ins;
+			data.insert(ins);
+		}
+	}
 
 	template <typename T>
 	void save(const T &data)
@@ -270,6 +269,7 @@ public:
 			>::type typex;
 		typex::invoke(*this, data);
 	}
+
 	template <typename T>
 	void load(T &data)
 	{
@@ -308,107 +308,4 @@ public:
 	int read(void * data, unsigned size);
 	int readLine(void * data, unsigned maxSize);
 	~CConnection(void);
-};
-
-
-//DLL_EXPORT CConnection & operator<<(CConnection &c, const std::string &data);
-//DLL_EXPORT CConnection & operator>>(CConnection &c, std::string &data);
-//DLL_EXPORT CConnection & operator<<(CConnection &c, const char * &data);
-//DLL_EXPORT CConnection & operator>>(CConnection &c, char * &data);
-//
-//template <typename T> CConnection & operator<<(CConnection &c, std::vector<T> &data)
-//{
-//	boost::uint32_t length = data.size();
-//	c << length;
-//	for(ui32 i=0;i<length;i++)
-//		c << data[i];
-//	return c;
-//}
-//template <typename T> CConnection & operator>>(CConnection &c,  std::vector<T> &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	data.resize(length);
-//	for(ui32 i=0;i<length;i++)
-//		c >> data[i];
-//	return c;
-//}
-//template <typename T> CConnection & operator<<(CConnection &c, std::set<T> &data)
-//{
-//	boost::uint32_t length = data.size();
-//	c << length;
-//	for(std::set<T>::iterator i=data.begin();i!=data.end();i++)
-//		c << *i;
-//	return c;
-//}
-//template <typename T> CConnection & operator>>(CConnection &c,  std::set<T> &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	data.resize(length);
-//	T pom;
-//	for(int i=0;i<length;i++)
-//	{
-//		c >> pom;
-//		data.insert(pom);
-//	}
-//	return c;
-//}
-//template <typename T> CConnection & operator<<(CConnection &c, const T &data)
-//{
-//	c.write(&data,sizeof(data));
-//	return c;
-//}
-//template <typename T> CConnection & operator>>(CConnection &c, T &data)
-//{
-//	c.read(&data,sizeof(data));
-//	return c;
-//}
-//template <typename T> CConnection & operator<(CConnection &c, std::vector<T> &data)
-//{
-//	boost::uint32_t length = data.size();
-//	c << length;
-//	for(ui32 i=0;i<length;i++)
-//		data[i].serialize(c.send,version);
-//	return c;
-//}
-//template <typename T> CConnection & operator>(CConnection &c,  std::vector<T> &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	data.resize(length);
-//	for(ui32 i=0;i<length;i++)
-//		data[i].serialize(c.rec,version);
-//	return c;
-//}
-//template <typename T> CConnection & operator<(CConnection &c, std::set<T> &data)
-//{
-//	boost::uint32_t length = data.size();
-//	c << length;
-//	for(std::set<T>::iterator i=data.begin();i!=data.end();i++)
-//		i->serialize(c.send,version);
-//	return c;
-//}
-//template <typename T> CConnection & operator>(CConnection &c,  std::set<T> &data)
-//{
-//	boost::uint32_t length;
-//	c >> length;
-//	data.resize(length);
-//	T pom;
-//	for(int i=0;i<length;i++)
-//	{
-//		pom.serialize(c.rec,version);
-//		data.insert(pom);
-//	}
-//	return c;
-//}
-//template <typename T> CConnection & operator<(CConnection &c, T &data)
-//{
-//	data.serialize(c.send,version);
-//	return c;
-//}
-//template <typename T> CConnection & operator>(CConnection &c, T &data)
-//{
-//	data.serialize(c.rec,version);
-//	return c;
-//}
+};

+ 32 - 0
lib/NetPacks.h

@@ -0,0 +1,32 @@
+#include "../global.h"
+
+struct NewTurn
+{
+	struct Hero
+	{
+		ui32 id, move, mana; //id is a general serial id
+		template <typename Handler> void serialize(Handler &h, const int version)
+		{
+			h -= id -= move -= mana;
+		}
+	};
+	struct Resources
+	{
+		ui8 player;
+		si32 resources[RESOURCE_QUANTITY];
+		template <typename Handler> void serialize(Handler &h, const int version)
+		{
+			h -= resources;
+		}
+	};
+
+	std::set<Hero> heroes;
+	std::set<Resources> res;
+
+
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h += heroes += res;
+	}
+}; 

+ 1 - 2
server/CGameHandler.cpp

@@ -50,7 +50,6 @@ CGameHandler::~CGameHandler(void)
 }
 void CGameHandler::init(StartInfo *si, int Seed)
 {
-
 	Mapa *map = new Mapa(si->mapname);
 	gs = new CGameState();
 	gs->init(si,map,Seed);
@@ -115,7 +114,7 @@ void CGameHandler::run()
 	{//init conn.
 		ui8 quantity, pom;
 		//ui32 seed;
-		(*cc) << gs->scenarioOps->mapname;// << gs->map->checksum << seed;
+		(*cc) << gs->scenarioOps->mapname << gs->map->checksum << gs->seed;
 		(*cc) >> quantity;
 		for(int i=0;i<quantity;i++)
 		{

+ 0 - 0
server/server_main.cpp → server/CVCMIServer.cpp


+ 1 - 1
server/VCMI_server.vcproj

@@ -176,7 +176,7 @@
 				>
 			</File>
 			<File
-				RelativePath=".\server_main.cpp"
+				RelativePath=".\CVCMIServer.cpp"
 				>
 			</File>
 		</Filter>