mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* fixed memory leak in battles
* blitting creature animatoins to rects (not tested!) * a few minor improvements
This commit is contained in:
		| @@ -233,7 +233,7 @@ void CTownList<T>::mouseMoved (SDL_MouseMotionEvent & sEvent) | ||||
| 	int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 	hx-=pos.x; | ||||
| 	hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 	float ny = (float)hy/(float)32; | ||||
| 	int ny = hy/32; | ||||
| 	if ((ny>SIZE || ny<0) || (from+ny>=items.size())) | ||||
| 	{ | ||||
| 		LOCPLINT->statusbar->clear(); | ||||
| @@ -263,10 +263,10 @@ void CTownList<T>::clickLeft(tribool down) | ||||
| 		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 		hx-=pos.x; | ||||
| 		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 		float ny = (float)hy/(float)32; | ||||
| 		int ny = hy/32; | ||||
| 		if (ny>SIZE || ny<0) | ||||
| 			return; | ||||
| 		if (SIZE==5 && ((int)(ny+from))==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE)) | ||||
| 		if (SIZE==5 && (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == TOWNI_TYPE)) | ||||
| 			LOCPLINT->openTownWindow(items[selected]);//print town screen | ||||
| 		else | ||||
| 			select(ny+from); | ||||
| @@ -322,7 +322,7 @@ void CTownList<T>::clickRight(tribool down) | ||||
| 		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 		hx-=pos.x; | ||||
| 		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 		float ny = (float)hy/(float)32; | ||||
| 		int ny = hy/32; | ||||
| 		if ((ny>5 || ny<0) || (from+ny>=items.size())) | ||||
| 		{ | ||||
| 			return; | ||||
|   | ||||
| @@ -8,7 +8,7 @@ | ||||
| #include "AdventureMapButton.h" | ||||
| class CDefHandler; | ||||
| class CCallback; | ||||
| class CPath;  | ||||
| struct CPath;  | ||||
| class CAdvMapInt; | ||||
| class CGHeroInstance; | ||||
| class CGTownInstance; | ||||
|   | ||||
| @@ -54,7 +54,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	//blitting menu background and terrain | ||||
| 	////blitting menu background and terrain | ||||
| 	blitAt(background, 0, 0); | ||||
| 	blitAt(menu, 0, 556); | ||||
| 	CSDL_Ext::update(); | ||||
| @@ -98,9 +98,9 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C | ||||
|  | ||||
| 	//preparing cells and hexes | ||||
| 	cellBorder = CGI->bitmaph->loadBitmap("CCELLGRD.BMP"); | ||||
| 	cellBorder = CSDL_Ext::alphaTransform(cellBorder); | ||||
| 	CSDL_Ext::alphaTransform(cellBorder); | ||||
| 	cellShade = CGI->bitmaph->loadBitmap("CCELLSHD.BMP"); | ||||
| 	cellShade = CSDL_Ext::alphaTransform(cellShade); | ||||
| 	CSDL_Ext::alphaTransform(cellShade); | ||||
| 	for(int h=0; h<187; ++h) | ||||
| 	{ | ||||
| 		bfield[h].myNumber = h; | ||||
| @@ -142,8 +142,8 @@ CBattleInterface::~CBattleInterface() | ||||
| 	SDL_FreeSurface(cellBorder); | ||||
| 	SDL_FreeSurface(cellShade); | ||||
|  | ||||
| 	for(int g=0; g<creAnims.size(); ++g) | ||||
| 		delete creAnims[g]; | ||||
| 	for(std::map< int, CCreatureAnimation * >::iterator g=creAnims.begin(); g!=creAnims.end(); ++g) | ||||
| 		delete g->second; | ||||
| } | ||||
|  | ||||
| void CBattleInterface::activate() | ||||
| @@ -531,7 +531,11 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG | ||||
| 	for(int i=0; i<dh->ourImages.size(); ++i) //transforming images | ||||
| 	{ | ||||
| 		if(flip) | ||||
| 			dh->ourImages[i].bitmap = CSDL_Ext::rotate01(dh->ourImages[i].bitmap);  | ||||
| 		{ | ||||
| 			SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); | ||||
| 			SDL_FreeSurface(dh->ourImages[i].bitmap);  | ||||
| 			dh->ourImages[i].bitmap = hlp; | ||||
| 		} | ||||
| 		dh->ourImages[i].bitmap = CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); | ||||
| 	} | ||||
| 	dh->alphaTransformed = true; | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
| #include "CGameState.h" | ||||
|  | ||||
| class CGameState; | ||||
| class CPath; | ||||
| struct CPath; | ||||
| class CGObjectInstance; | ||||
| class SComponent; | ||||
| class IChosen; | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| #define CCURSORHANDLER_H | ||||
|  | ||||
| struct SDL_Thread; | ||||
| struct CDefHandler; | ||||
| class CDefHandler; | ||||
| struct SDL_Surface; | ||||
|  | ||||
| class CCursorHandler //handles cursor | ||||
|   | ||||
							
								
								
									
										3
									
								
								CMT.cpp
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								CMT.cpp
									
									
									
									
									
								
							| @@ -327,11 +327,8 @@ int _tmain(int argc, _TCHAR* argv[]) | ||||
| 	THC tmh.getDif(); | ||||
| 	timeHandler pomtime;pomtime.getDif(); | ||||
| 	int xx=0, yy=0, zz=0; | ||||
| 	SDL_Event sEvent; | ||||
| 	srand ( time(NULL) ); | ||||
| 	SDL_Surface *temp; | ||||
| 	std::vector<SDL_Surface*> Sprites; | ||||
| 	float i; | ||||
| 	if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0) | ||||
| 	{ | ||||
| 		screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); | ||||
|   | ||||
| @@ -1962,7 +1962,7 @@ void CPlayerInterface::buildChanged(const CGTownInstance *town, int buildingID, | ||||
| } | ||||
|  | ||||
| void CPlayerInterface::battleStart(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, tribool side) //called by engine when battle starts; side=0 - left, side=1 - right | ||||
|  { | ||||
| { | ||||
| 	curint->deactivate(); | ||||
| 	curint = new CBattleInterface(army1,army2,hero1,hero2); | ||||
| 	curint->activate(); | ||||
| @@ -2232,10 +2232,10 @@ void CHeroList::clickLeft(tribool down) | ||||
| 		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 		hx-=pos.x; | ||||
| 		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 		float ny = (float)hy/(float)32; | ||||
| 		int ny = hy/32; | ||||
| 		if (ny>=5 || ny<0) | ||||
| 			return; | ||||
| 		if (((int)(ny+from))==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)) | ||||
| 		if ( (ny+from)==selected && (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)) | ||||
| 			LOCPLINT->openHeroWindow(items[selected].first);//print hero screen | ||||
| 		select(ny+from); | ||||
| 	} | ||||
| @@ -2294,7 +2294,7 @@ void CHeroList::mouseMoved (SDL_MouseMotionEvent & sEvent) | ||||
| 	int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 	hx-=pos.x; | ||||
| 	hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 	float ny = (float)hy/(float)32; | ||||
| 	int ny = hy/32; | ||||
| 	if ((ny>5 || ny<0) || (from+ny>=items.size())) | ||||
| 	{ | ||||
| 		LOCPLINT->adventureInt->statusbar.clear(); | ||||
| @@ -2323,7 +2323,7 @@ void CHeroList::clickRight(tribool down) | ||||
| 		int hx = LOCPLINT->current->motion.x, hy = LOCPLINT->current->motion.y; | ||||
| 		hx-=pos.x; | ||||
| 		hy-=pos.y; hy-=arrup->ourImages[0].bitmap->h; | ||||
| 		float ny = (float)hy/(float)32; | ||||
| 		int ny = hy/32; | ||||
| 		if ((ny>5 || ny<0) || (from+ny>=items.size())) | ||||
| 		{ | ||||
| 			return; | ||||
|   | ||||
| @@ -17,7 +17,7 @@ class CStack; | ||||
| class SComponent; | ||||
| class CCreature; | ||||
| struct SDL_Surface; | ||||
| class CPath; | ||||
| struct CPath; | ||||
| class CCreatureAnimation; | ||||
| class CSelectableComponent; | ||||
| class CCreatureSet; | ||||
|   | ||||
| @@ -478,7 +478,6 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	SDL_UpdateRect(src, 0, 0, src->w, src->h); | ||||
| 	return src; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -781,11 +781,11 @@ int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
| int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder) | ||||
| int CCreatureAnimation::nextFrameMiddle(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) | ||||
| { | ||||
| 	return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder); | ||||
| 	return nextFrame(dest,x-fullWidth/2,y-fullHeight/2,attacker,incrementFrame,yellowBorder,destRect); | ||||
| } | ||||
| int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder) | ||||
| int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker, bool incrementFrame, bool yellowBorder, SDL_Rect * destRect) | ||||
| { | ||||
| 	if(dest->format->BytesPerPixel<3) | ||||
| 		return -1; //not enough depth | ||||
| @@ -829,7 +829,7 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker | ||||
| 		LeftMargin, RightMargin, TopMargin,BottomMargin, | ||||
| 		i, add, FullHeight,FullWidth, | ||||
| 		TotalRowLength, // length of read segment | ||||
| 		NextSpriteOffset, RowAdd; | ||||
| 		RowAdd; | ||||
| 	unsigned char SegmentType, SegmentLength; | ||||
| 	 | ||||
| 	i=BaseOffset=SEntries[SIndex].offset; | ||||
| @@ -884,7 +884,8 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker | ||||
| 						int yB = ftcp/(FullWidth+add) + y; | ||||
| 						if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h) | ||||
| 						{ | ||||
| 							putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder); | ||||
| 							if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) | ||||
| 								putPixel(dest, xB + yB*dest->w, palette[FDef[BaseOffset+k]], FDef[BaseOffset+k], yellowBorder); | ||||
| 						} | ||||
| 						ftcp++; //increment pos | ||||
| 						if ((TotalRowLength+k+1)>=SpriteWidth) | ||||
| @@ -901,7 +902,8 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker | ||||
| 						int yB = ftcp/(FullWidth+add) + y; | ||||
| 						if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h) | ||||
| 						{ | ||||
| 							putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder); | ||||
| 							if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB)) | ||||
| 								putPixel(dest, xB + yB*dest->w, palette[SegmentType], SegmentType, yellowBorder); | ||||
| 						} | ||||
| 						ftcp++; //increment pos | ||||
| 					} | ||||
|   | ||||
| @@ -103,8 +103,8 @@ public: | ||||
| 	void setType(int type); //sets type of animation and cleares framecount | ||||
| 	int getType() const; //returns type of animation | ||||
|  | ||||
| 	int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false); //0 - success, any other - error //print next  | ||||
| 	int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false); //0 - success, any other - error //print next  | ||||
| 	int nextFrame(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next  | ||||
| 	int nextFrameMiddle(SDL_Surface * dest, int x, int y, bool attacker, bool incrementFrame = true, bool yellowBorder = false, SDL_Rect * destRect = NULL); //0 - success, any other - error //print next  | ||||
|  | ||||
| 	int framesInGroup(int group) const; //retirns number of fromes in given group | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user