Procházet zdrojové kódy

* added support for serialization arrays of non-primitive types
* improved switching between fullscreen and windowed mode
* fixed crashbug occuring on closing adv options tab in pregame
* fixed crashbug on loading maps with events giving resources
* fixed data bug
* version set to 0.68b

Michał W. Urbańczyk před 16 roky
rodič
revize
5a36e61c32
7 změnil soubory, kde provedl 92 přidání a 49 odebrání
  1. 6 2
      CMT.cpp
  2. 32 22
      CPreGame.cpp
  3. 2 1
      CPreGame.h
  4. 1 1
      global.h
  5. 45 3
      lib/Connection.h
  6. 1 1
      map.cpp
  7. 5 19
      server/CGameHandler.cpp

+ 6 - 2
CMT.cpp

@@ -199,8 +199,12 @@ int main(int argc, char** argv)
 			else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4)
 			{
 				LOCPLINT->pim->lock();
-				screen = SDL_SetVideoMode(screen->w,screen->h,screen->format->BitsPerPixel,
-					SDL_SWSURFACE|SDL_DOUBLEBUF|((screen->flags&SDL_FULLSCREEN) ? 0 : SDL_FULLSCREEN));
+				bool full = !(screen->flags&SDL_FULLSCREEN);
+				SDL_QuitSubSystem(SDL_INIT_VIDEO);
+				SDL_InitSubSystem(SDL_INIT_VIDEO);
+				screen = SDL_SetVideoMode(conf.cc.resx,conf.cc.resy,conf.cc.bpp,SDL_SWSURFACE|SDL_DOUBLEBUF|(full?SDL_FULLSCREEN:0));  //initializing important global surface
+				SDL_WM_SetCaption(NAME.c_str(),""); //set window title
+				SDL_ShowCursor(SDL_DISABLE);
 				LOCPLINT->curint->show();
 				if(LOCPLINT->curint != LOCPLINT->adventureInt)
 					LOCPLINT->adventureInt->show();

+ 32 - 22
CPreGame.cpp

@@ -48,17 +48,42 @@ HighButton::HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel, int id)
 	pos=Pos;
 	ID=id;
 	highlightable=false;
+	freeimgs = false;
 };
 HighButton::HighButton()
 {
+	freeimgs = true;
 	state=0;
 }
+HighButton::~HighButton()
+{
+	if(freeimgs)
+		delete imgs;
+}
 void HighButton::show()
 {
 	blitAt(imgs->ourImages[state].bitmap,pos.x,pos.y);
 	updateRect(&pos);
 }
 
+void HighButton::hover(bool on)
+{
+	if (!highlightable) return;
+	int i;
+	if (on)
+	{
+		state=i=3;
+		highlighted=true;
+	}
+	else
+	{
+		state=i=0;
+		highlighted=false;
+	}
+	SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos);
+	updateRect(&pos);
+}
+
 void HighButton::press(bool down)
 {
 	int i;
@@ -93,28 +118,6 @@ void SetrButton::press(bool down)
 #endif
 	HighButton::press(down);
 }
-void HighButton::hover(bool on)
-{
-	if (!highlightable) return;
-	int i;
-	if (on)
-	{
-		state=i=3;
-		highlighted=true;
-	}
-	else
-	{
-		state=i=0;
-		highlighted=false;
-	}
-	SDL_BlitSurface(imgs->ourImages[i].bitmap,NULL,screen,&pos);
-	updateRect(&pos);
-}
-
-HighButton::~HighButton()
-{
-	delete imgs;
-}
 void Button::hover(bool on)
 {
 	HighButton::hover(on);
@@ -835,6 +838,7 @@ int MapSel::countWL()
 }
 void MapSel::printMaps(int from, int to, int at, bool abs)
 {
+	if (!slid->positionsAmnt) return; //no maps to print
 	if(slid->positionsAmnt < slid->capacity)
 		from = 0;
 	int help=-1;
@@ -1182,6 +1186,11 @@ void MapSel::init()
 		{
 			if (boost::ends_with(dir->path().filename(),".vlgm1"))
 			{
+				if( fs::file_size(dir->path()) < 16000 )
+				{
+					tlog3 << "Savegame " << dir->path() << " seems to be corrupted and will be ommited.\n";
+					continue;
+				}
 				pliczkiTemp.push_back("Games/"+(dir->path().leaf()));
 				std::time_t time = fs::last_write_time(dir->path());
 				datestemp.push_back(std::asctime(std::gmtime(&time)));
@@ -1219,6 +1228,7 @@ void MapSel::moveByOne(bool up)
 }
 void MapSel::select(int which, bool updateMapsList, bool forceSettingsUpdate)
 {
+	if(!curVector().size()) return;
 	if(which < 0)
 		return;
 	bool dontSaveSettings = ((selected!=which) || (CPG->ret.playerInfos.size()==0) || forceSettingsUpdate);

+ 2 - 1
CPreGame.h

@@ -27,9 +27,10 @@ struct HighButton
 	SDL_Rect pos;
 	CDefHandler* imgs;
 	int state;
+	bool freeimgs;
 	HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1);
 	HighButton();
-	~HighButton();
+	virtual ~HighButton();
 	bool selectable, selected;
 	bool highlightable, highlighted;
 	virtual void show();

+ 1 - 1
global.h

@@ -19,7 +19,7 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
 #define THC
 #endif
 
-#define NAME_VER ("VCMI 0.68a")
+#define NAME_VER ("VCMI 0.68b")
 #define CONSOLE_LOGGING_LEVEL 5
 #define FILE_LOGGING_LEVEL 6
 

+ 45 - 3
lib/Connection.h

@@ -22,6 +22,9 @@ class CConnection;
 
 namespace mpl = boost::mpl;
 
+template<typename T, size_t N> char (&_ArrayCountObj(const T (&)[N]))[N];  
+#define ARRAY_COUNT(arr)    (sizeof(_ArrayCountObj(arr)))
+
 namespace boost
 {
 	namespace asio
@@ -47,6 +50,7 @@ enum SerializationLvl
 {
 	Wrong=0,
 	Primitive,
+	Array,
 	Pointer,
 	Serializable
 };
@@ -92,6 +96,22 @@ struct LoadPointer
 	}
 };
 template<typename Ser,typename T>
+struct SaveArray
+{
+	static void invoke(Ser &s, const T &data)
+	{
+		s.saveArray(data);
+	}
+};
+template<typename Ser,typename T>
+struct LoadArray
+{
+	static void invoke(Ser &s, T &data)
+	{
+		s.loadArray(data);
+	}
+};
+template<typename Ser,typename T>
 struct LoadSerializable
 {
 	static void invoke(Ser &s, T &data)
@@ -105,7 +125,7 @@ struct SaveWrong
 {
 	static void invoke(Ser &s, const T &data)
 	{
-		throw std::exception("Wrong save serialization call!");
+		throw std::string("Wrong save serialization call!");
 	}
 };
 template<typename Ser,typename T>
@@ -113,7 +133,7 @@ struct LoadWrong
 {
 	static void invoke(Ser &s, const T &data)
 	{
-		throw std::exception("Wrong load serialization call!");
+		throw std::string("Wrong load serialization call!");
 	}
 };
 
@@ -132,7 +152,7 @@ struct SerializationLevel
 		//else
 		typename mpl::eval_if<
 			boost::is_array<T>,
-			mpl::int_<Primitive>,
+			mpl::int_<Array>,
 		//else
 		typename mpl::eval_if<
 			boost::is_pointer<T>,
@@ -191,6 +211,13 @@ public:
 			*this << *data;
 	}
 	template <typename T>
+	void saveArray(const T &data)
+	{
+		ui32 size = ARRAY_COUNT(data);
+		for(ui32 i=0; i < size; i++)
+			*this << data[i];
+	}
+	template <typename T>
 	void save(const T &data)
 	{
 		typedef 
@@ -201,12 +228,16 @@ public:
 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
 			mpl::identity<SavePointer<Serializer,T> >,
 			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Array> >,
+			mpl::identity<SaveArray<Serializer,T> >,
+			//else if
 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
 			mpl::identity<SaveSerializable<Serializer,T> >,
 			//else
 			mpl::identity<SaveWrong<Serializer,T> >
 			>
 			>
+			>
 			>::type typex;
 		typex::invoke(* this->This(), data);
 	}
@@ -285,12 +316,16 @@ public:
 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >,
 			mpl::identity<LoadPointer<Serializer,T> >,
 			//else if
+			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Array> >,
+			mpl::identity<LoadArray<Serializer,T> >,
+			//else if
 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Serializable> >,
 			mpl::identity<LoadSerializable<Serializer,T> >,
 			//else
 			mpl::identity<LoadWrong<Serializer,T> >
 			>
 			>
+			>
 			>::type typex;
 		typex::invoke(* this->This(), data);
 	}
@@ -305,6 +340,13 @@ public:
 		data.serialize(*this,version);
 	}	
 	template <typename T>
+	void loadArray(T &data)
+	{
+		ui32 size = ARRAY_COUNT(data);
+		for(ui32 i=0; i < size; i++)
+			*this >> data[i];
+	}
+	template <typename T>
 	void loadPointer(T &data)
 	{
 		ui8 hlp;

+ 1 - 1
map.cpp

@@ -775,7 +775,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i )
 		CCastleEvent nce;
 		nce.name = readString(bufor,i);
 		nce.message = readString(bufor,i);
-
+		nce.resources.resize(RESOURCE_QUANTITY);
 		for(int x=0; x < 7; x++)
 		{
 			nce.resources[x] = readNormalNr(bufor,i); 

+ 5 - 19
server/CGameHandler.cpp

@@ -1702,21 +1702,7 @@ customactionend:
 			}
 		}
 	}
-	catch (const std::exception& e)
-	{
-		tlog1 << "Exception during handling connection: " << e.what() << std::endl;
-		end2 = true;
-	}
-	catch (const std::exception * e)
-	{
-		tlog1 << "Exception during handling connection: " << e->what()<< std::endl;	
-		end2 = true;
-		delete e;
-	}
-	catch(...)
-	{
-		end2 = true;
-	}
+	HANDLE_EXCEPTION(end2 = true);
 handleConEnd:
 	tlog1 << "Ended handling connection\n";
 }
@@ -1948,6 +1934,10 @@ void CGameHandler::run(bool resume)
 
 	while (!end2)
 	{
+		if(!resume)
+			newTurn();
+		else
+			resume = false;
 
 		std::map<ui8,PlayerState>::iterator i;
 		if(!resume)
@@ -1957,10 +1947,6 @@ void CGameHandler::run(bool resume)
 
 		for(; i != gs->players.end(); i++)
 		{
-			if(!resume)
-				newTurn();
-			else
-				resume = false;
 
 			if((i->second.towns.size()==0 && i->second.heroes.size()==0)  || i->second.color<0 || i->first>=PLAYER_LIMIT  ) continue; //players has not towns/castle - loser
 			states.setFlag(i->first,&PlayerStatus::makingTurn,true);