mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* experimental smooth hero move support (minor graphical glitches exist but I hope they'll be removed soon; I hope there are no more problems with it, but please test)
* small graphical glitch fixed
This commit is contained in:
		| @@ -478,7 +478,7 @@ void CTerrainRect::hover(bool on) | ||||
| 	if (!on) | ||||
| 		LOCPLINT->adventureInt->statusbar.clear(); | ||||
| } | ||||
| void CTerrainRect::showPath() | ||||
| void CTerrainRect::showPath(const SDL_Rect * extRect) | ||||
| { | ||||
| 	for (size_t i=0; i < currentPath->nodes.size()-1; ++i) | ||||
| 	{ | ||||
| @@ -705,45 +705,91 @@ void CTerrainRect::showPath() | ||||
| 				continue; | ||||
| 			int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w), | ||||
| 				hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h); | ||||
| 			if (hvx<0 && hvy<0) | ||||
|  | ||||
| 			SDL_Rect prevClip; | ||||
| 			SDL_GetClipRect(screen, &prevClip); | ||||
| 			SDL_SetClipRect(screen, extRect); //preventing blitting outside of that rect | ||||
|  | ||||
| 			if(ADVOPT.smoothMove) //version for smooth hero move, with pos shifts | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y)); | ||||
| 				if (hvx<0 && hvy<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x + moveX, y + moveY)); | ||||
| 				} | ||||
| 				else if(hvx<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY)); | ||||
| 				} | ||||
| 				else if (hvy<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY)); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY)); | ||||
| 				} | ||||
| 			} | ||||
| 			else if(hvx<0) | ||||
| 			else //standard version | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0), | ||||
| 					screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y)); | ||||
| 			} | ||||
| 			else if (hvy<0) | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0), | ||||
| 					screen,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y)); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0), | ||||
| 					screen,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y)); | ||||
| 				if (hvx<0 && hvy<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, screen, &genRect(32, 32, x, y)); | ||||
| 				} | ||||
| 				else if(hvx<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y)); | ||||
| 				} | ||||
| 				else if (hvy<0) | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y)); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp | ||||
| 						(arrows->ourImages[pn].bitmap, &genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx, 0, 0), | ||||
| 						screen, &genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y)); | ||||
| 				} | ||||
| 			} | ||||
| 			SDL_SetClipRect(screen, &prevClip); | ||||
|  | ||||
| 		} | ||||
| 	} //for (int i=0;i<currentPath->nodes.size()-1;i++) | ||||
| } | ||||
| void CTerrainRect::show() | ||||
| { | ||||
| 	SDL_Surface * teren = CGI->mh->terrainRect //TODO use me | ||||
| 		(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, | ||||
| 		tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, | ||||
| 		&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, | ||||
| 		screen, &genRect(pos.h, pos.w, pos.x, pos.y) | ||||
| 		); | ||||
| 	if(ADVOPT.smoothMove && (moveX != 0 || moveY != 0)) | ||||
| 	{ | ||||
| 		CGI->mh->terrainRectSmooth | ||||
| 			(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, | ||||
| 			tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, | ||||
| 			&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, | ||||
| 			screen, &genRect(pos.h, pos.w, pos.x, pos.y), moveX, moveY | ||||
| 			); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		CGI->mh->terrainRect | ||||
| 			(LOCPLINT->adventureInt->position.x,LOCPLINT->adventureInt->position.y, | ||||
| 			tilesw,tilesh,LOCPLINT->adventureInt->position.z,LOCPLINT->adventureInt->anim, | ||||
| 			&LOCPLINT->cb->getVisibilityMap(), true, LOCPLINT->adventureInt->heroAnim, | ||||
| 			screen, &genRect(pos.h, pos.w, pos.x, pos.y) | ||||
| 			); | ||||
| 	} | ||||
| 	//SDL_BlitSurface(teren,&genRect(pos.h,pos.w,0,0),screen,&genRect(547,594,7,6)); | ||||
| 	//SDL_FreeSurface(teren); | ||||
| 	if (currentPath && LOCPLINT->adventureInt->position.z==currentPath->startPos().z) //drawing path | ||||
| 	{ | ||||
| 		showPath(); | ||||
| 		showPath(&genRect(pos.h, pos.w, pos.x, pos.y)); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -57,7 +57,7 @@ public: | ||||
| 	void hover(bool on); | ||||
| 	void mouseMoved (const SDL_MouseMotionEvent & sEvent); | ||||
| 	void show(); | ||||
| 	void showPath(); | ||||
| 	void showPath(const SDL_Rect * extRect); | ||||
| 	int3 whichTileIsIt(const int & x, const int & y); //x,y are cursor position | ||||
| 	int3 whichTileIsIt(); //uses current cursor pos | ||||
| }; | ||||
|   | ||||
| @@ -495,6 +495,7 @@ void CSDL_Ext::blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| 	for(int i=0; i<dstRect->h; i++) | ||||
| 	{ | ||||
| 		sp += src->w - dstRect->w; | ||||
| 		dp = (Uint8 *)dst->pixels + (i+dstRect->y)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; | ||||
| 		for(int j=0; j<dstRect->w; j++, sp++) | ||||
| 		{ | ||||
| @@ -506,6 +507,36 @@ void CSDL_Ext::blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| { | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| 	for(int i=0; i<dstRect->h; i++) | ||||
| 	{ | ||||
| 		if(i + dstRect->y + 1 >= dst->clip_rect.y && i + dstRect->y + 1 <= dst->clip_rect.y + dst->clip_rect.h) | ||||
| 		{ | ||||
| 			dp = (Uint8 *)dst->pixels + (i+dstRect->y)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; | ||||
| 			for(int j=0; j<dstRect->w; j++, sp++) | ||||
| 			{ | ||||
| 				if((dstRect->x+dstRect->w - j-1) >= dst->clip_rect.x && (dstRect->x+dstRect->w - j) <= dst->clip_rect.x + dst->clip_rect.w) | ||||
| 				{ | ||||
| 					const SDL_Color * const color = src->format->palette->colors+(*sp); | ||||
| 					*(--dp) = color->r; | ||||
| 					*(--dp) = color->g; | ||||
| 					*(--dp) = color->b; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					dp-=3; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			sp+=dstRect->w; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| { | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| @@ -519,6 +550,37 @@ void CSDL_Ext::blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface | ||||
| 			*(dp++) = color->g; | ||||
| 			*(dp++) = color->r; | ||||
| 		} | ||||
| 		sp += src->w - dstRect->w; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::blitWithRotate2clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| { | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| 	for(int i=0; i<dstRect->h; i++) | ||||
| 	{ | ||||
| 		if((dstRect->y + dstRect->h - i) >= dst->clip_rect.y && (dstRect->y + dstRect->h - i) <= dst->clip_rect.y + dst->clip_rect.h) | ||||
| 		{ | ||||
| 			dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + dstRect->x*dst->format->BytesPerPixel; | ||||
| 			for(int j=0; j<dstRect->w; j++, sp++) | ||||
| 			{ | ||||
| 				if(j + dstRect->x >= dst->clip_rect.x && j + dstRect->x+1 <= dst->clip_rect.x + dst->clip_rect.w) | ||||
| 				{ | ||||
| 					const SDL_Color * const color = src->format->palette->colors+(*sp); | ||||
| 					*(dp++) = color->b; | ||||
| 					*(dp++) = color->g; | ||||
| 					*(dp++) = color->r; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 						dp+=3; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			sp+=dstRect->w; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -527,6 +589,7 @@ void CSDL_Ext::blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| 	for(int i=0; i<dstRect->h; i++) | ||||
| 	{ | ||||
| 		sp += src->w - dstRect->w; | ||||
| 		dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; | ||||
| 		for(int j=0; j<dstRect->w; j++, sp++) | ||||
| 		{ | ||||
| @@ -538,6 +601,36 @@ void CSDL_Ext::blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CSDL_Ext::blitWithRotate3clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| { | ||||
| 	Uint8 *dp, *sp = (Uint8 *)src->pixels; | ||||
| 	for(int i=0; i<dstRect->h; i++) | ||||
| 	{ | ||||
| 		if((dstRect->y + dstRect->h - i) >= dst->clip_rect.y && (dstRect->y + dstRect->h - i) <= dst->clip_rect.y + dst->clip_rect.h) | ||||
| 		{ | ||||
| 			dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel; | ||||
| 			for(int j=0; j<dstRect->w; j++, sp++) | ||||
| 			{ | ||||
| 				if((dstRect->x+dstRect->w - j-1) >= dst->clip_rect.x && (dstRect->x+dstRect->w - j-1) <= dst->clip_rect.x + dst->clip_rect.w) | ||||
| 				{ | ||||
| 					const SDL_Color * const color = src->format->palette->colors+(*sp); | ||||
| 					*(--dp) = color->r; | ||||
| 					*(--dp) = color->g; | ||||
| 					*(--dp) = color->b; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					dp -=3; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			sp+=dstRect->w; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect) | ||||
| { | ||||
| 	if(src && src->format->BytesPerPixel==1 && dst && (dst->format->BytesPerPixel==3 || dst->format->BytesPerPixel==4)) //everything's ok | ||||
|   | ||||
| @@ -37,6 +37,9 @@ namespace CSDL_Ext | ||||
| 	void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| 	void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| 	void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests | ||||
| 	void blitWithRotate1clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect | ||||
| 	void blitWithRotate2clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect | ||||
| 	void blitWithRotate3clip(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests preserving clip_rect | ||||
| 	int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface | ||||
| 	Uint32 colorToUint32(const SDL_Color * color); //little endian only | ||||
| 	void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) | ||||
|   | ||||
| @@ -229,6 +229,7 @@ struct SettingsGrammar : public grammar<SettingsGrammar> | ||||
| 							  | "trimY=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::advmapTrimY)] | ||||
| 							  | "tilesWidth=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::tilesW)] | ||||
| 							  | "tilesHeight=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::tilesH)] | ||||
| 							  | "smoothMove=" >> uint_p[SetAdventureProp_a(&AdventureMapConfig::smoothMove)] | ||||
| 							)  | ||||
| 						 ) | ||||
| 				| str_p("background=") >> fname[SetAdventureStr(&AdventureMapConfig::mainGraphic)] | ||||
|   | ||||
| @@ -32,6 +32,7 @@ namespace config | ||||
| 		int infoboxX, infoboxY; | ||||
| 		//advmap | ||||
| 		int tilesW, tilesH, advmapX, advmapY, advmapTrimX, advmapTrimY; | ||||
| 		bool smoothMove; | ||||
| 		//general properties | ||||
| 		std::string mainGraphic; | ||||
| 		//buttons | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| clientSettings | ||||
| { | ||||
| 	port=3030; | ||||
| 	resolution=1024x768; // format: WxH | ||||
| 	resolution=800x600; // format: WxH | ||||
| 	bpp=24; // bpp!=24 => problems | ||||
| 	fullscreen=0; //0 - windowed mode, 1 - fullscreen | ||||
| 	server=127.0.0.1; //use 127.0.0.1 for localhost | ||||
| @@ -16,7 +16,7 @@ GUISettings | ||||
| 	{ | ||||
| 		AdventureMap | ||||
| 		{ | ||||
| 			AdvMap: x=7 y=6 tilesWidth=19 tilesHeight=18 trimX=15 trimY=29; | ||||
| 			AdvMap: x=7 y=6 tilesWidth=19 tilesHeight=18 trimX=15 trimY=29 smoothMove=1; | ||||
| 			InfoBox: x=605 y=389; | ||||
| 			gem0: x=6 y=508 graphic=agemLL.def; | ||||
| 			gem1: x=556 y=508 graphic=agemLR.def; | ||||
| @@ -44,7 +44,7 @@ GUISettings | ||||
| 	{ | ||||
| 		AdventureMap | ||||
| 		{ | ||||
| 			AdvMap: x=7 y=6 tilesWidth=19 tilesHeight=18 trimX=15 trimY=29; | ||||
| 			AdvMap: x=7 y=6 tilesWidth=19 tilesHeight=18 trimX=15 trimY=29 smoothMove=1; | ||||
| 			InfoBox: x=829 y=389; | ||||
| 		 	gem0: x=6 y=508 graphic=agemLL.def; | ||||
| 			gem1: x=780 y=508 graphic=agemLR.def; | ||||
| @@ -73,7 +73,7 @@ GUISettings | ||||
| 	{ | ||||
| 		AdventureMap | ||||
| 		{ | ||||
| 			AdvMap: x=7 y=6 tilesWidth=26 tilesHeight=23 trimX=15 trimY=20; | ||||
| 			AdvMap: x=7 y=6 tilesWidth=26 tilesHeight=23 trimX=15 trimY=20 smoothMove=1; | ||||
| 			InfoBox: x=829 y=557; | ||||
| 			gem0: x=6 y=676 graphic=agemLL.def; | ||||
| 			gem1: x=780 y=676 graphic=agemLR.def; | ||||
|   | ||||
							
								
								
									
										267
									
								
								mapHandler.cpp
									
									
									
									
									
								
							
							
						
						
									
										267
									
								
								mapHandler.cpp
									
									
									
									
									
								
							| @@ -760,6 +760,273 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, | ||||
| 	//borders printed | ||||
| 	return su; | ||||
| } | ||||
|  | ||||
| SDL_Surface * CMapHandler::terrainRectSmooth(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect, int moveX, int moveY) | ||||
| { | ||||
| 	if(!otherHeroAnim) | ||||
| 		heroAnim = anim; //the same, as it should be | ||||
| 	//setting surface to blit at | ||||
| 	SDL_Surface * su = NULL; //blitting surface CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface); | ||||
| 	if(extSurf) | ||||
| 	{ | ||||
| 		su = extSurf; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		 su = CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface); | ||||
| 	} | ||||
| 	SDL_Rect prevClip; | ||||
| 	SDL_GetClipRect(su, &prevClip); | ||||
| 	if(extRect) SDL_SetClipRect(su, extRect); //preventing blitting outside of that rect | ||||
|  | ||||
| 	if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) ) | ||||
| 		throw new std::string("terrainRect: out of range"); | ||||
| 	////printing terrain | ||||
| 	for (int bx= (moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1); by<dy+1; by++) | ||||
| 		{ | ||||
| 			const TerrainTile2 & tile = ttiles[x+bx][y+by][level]; | ||||
| 			SDL_Rect sr; | ||||
| 			sr.y=by*32 + moveY + extRect->y; | ||||
| 			sr.x=bx*32 + moveX + extRect->x; | ||||
| 			sr.h=sr.w=32; | ||||
| 			//validateRectTerr(&sr, extRect); | ||||
| 			if(tile.terbitmap) | ||||
| 			{ | ||||
| 				SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap, &genRect(sr.h, sr.w, 0, 0), su, &sr); | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				switch(tile.tileInfo->siodmyTajemniczyBajt%4) | ||||
| 				{ | ||||
| 				case 0: | ||||
| 					SDL_BlitSurface(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview], | ||||
| 						&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 					break; | ||||
| 				case 1: | ||||
| 					CSDL_Ext::blitWithRotate1clip(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview], | ||||
| 						&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 					break; | ||||
| 				case 2: | ||||
| 					CSDL_Ext::blitWithRotate2clip(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview], | ||||
| 						&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 					break; | ||||
| 				default: | ||||
| 					CSDL_Ext::blitWithRotate3clip(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview], | ||||
| 						&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 					break; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	////terrain printed | ||||
| 	////printing rivers | ||||
| 	for (int bx=(moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1); by<dy+1; by++) | ||||
| 		{ | ||||
| 			SDL_Rect sr; | ||||
| 			sr.y=by*32 + moveY + extRect->y; | ||||
| 			sr.x=bx*32 + moveX + extRect->x; | ||||
| 			sr.h=sr.w=32; | ||||
| 			//validateRectTerr(&sr, extRect); | ||||
| 			if(ttiles[x+bx][y+by][level].rivbitmap.size()) | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	////rivers printed | ||||
| 	////printing roads | ||||
| 	for (int bx=(moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1) - 1; by<dy+1; by++) | ||||
| 		{ | ||||
| 			if(y+by<=-4) | ||||
| 				continue; | ||||
| 			SDL_Rect sr; | ||||
| 			sr.y=by*32+16 + moveY + extRect->y; | ||||
| 			sr.x=bx*32 + moveX + extRect->x; | ||||
| 			sr.h=sr.w=32; | ||||
| 			//validateRectTerr(&sr, extRect); | ||||
| 			if(ttiles[x+bx][y+by][level].roadbitmap.size()) | ||||
| 			{ | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()], &genRect(sr.h, sr.w, 0, (by==-1 ? 16 : 0)),su,&sr); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	////roads printed | ||||
| 	////printing objects | ||||
|  | ||||
| 	for (int bx=(moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1); by<dy+1; by++) | ||||
| 		{ | ||||
| 			for(int h=0; h < ttiles[x+bx][y+by][level].objects.size(); ++h) | ||||
| 			{ | ||||
| 				SDL_Rect sr; | ||||
| 				sr.w = 32; | ||||
| 				sr.h = 32; | ||||
| 				sr.x = (bx)*32 + moveX + extRect->x; | ||||
| 				sr.y = (by)*32 + moveY + extRect->y; | ||||
| 				//validateRectTerr(&sr, extRect); | ||||
|  | ||||
| 				SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second; | ||||
| 				pp.h = sr.h; | ||||
| 				pp.w = sr.w; | ||||
| 				const CGHeroInstance * themp = (dynamic_cast<const CGHeroInstance*>(ttiles[x+bx][y+by][level].objects[h].first)); | ||||
|  | ||||
| 				if(themp && themp->moveDir && !themp->isStanding && themp->ID!=62) //last condition - this is not prison | ||||
| 				{ | ||||
| 					int imgVal = 8; | ||||
| 					SDL_Surface * tb; | ||||
|  | ||||
| 					if(themp->type==NULL) | ||||
| 						continue; | ||||
| 					std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages; | ||||
|  | ||||
|                     size_t gg; | ||||
| 					for(gg=0; gg<iv.size(); ++gg) | ||||
| 					{ | ||||
| 						if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding)) | ||||
| 						{ | ||||
| 							tb = iv[gg+heroAnim%imgVal].bitmap; | ||||
| 							break; | ||||
| 						} | ||||
| 					} | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr); | ||||
| 					pp.y+=imgVal*2-32; | ||||
| 					sr.y-=16; | ||||
| 					SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr); | ||||
| 				} | ||||
| 				else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison) | ||||
| 				{ | ||||
| 					int imgVal = 8; | ||||
| 					SDL_Surface * tb; | ||||
|  | ||||
| 					if(themp->type==NULL) | ||||
| 						continue; | ||||
| 					std::vector<Cimage> & iv = themp->type->heroClass->moveAnim->ourImages; | ||||
|  | ||||
|                     size_t gg; | ||||
| 					for(gg=0; gg < iv.size(); ++gg) | ||||
| 					{ | ||||
| 						if(iv[gg].groupNumber==getHeroFrameNum(themp->moveDir, !themp->isStanding)) | ||||
| 						{ | ||||
| 							tb = iv[gg].bitmap; | ||||
| 							break; | ||||
| 						} | ||||
| 					} | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr); | ||||
| 					if(themp->pos.x==x+bx && themp->pos.y==y+by) | ||||
| 					{ | ||||
| 						SDL_Rect bufr = sr; | ||||
| 						bufr.x-=2*32; | ||||
| 						bufr.y-=1*32; | ||||
| 						bufr.h = 64; | ||||
| 						bufr.w = 96; | ||||
| 						if(bufr.x-extRect->x>-64) | ||||
| 							SDL_BlitSurface(graphics->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+(heroAnim/4)%imgVal].bitmap, NULL, su, &bufr); | ||||
| 					} | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					int imgVal = ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages.size(); | ||||
| 					int phaseShift = ttiles[x+bx][y+by][level].objects[h].first->animPhaseShift; | ||||
|  | ||||
| 					//setting appropriate flag color | ||||
| 					if((ttiles[x+bx][y+by][level].objects[h].first->tempOwner>=0 && ttiles[x+bx][y+by][level].objects[h].first->tempOwner<8) || ttiles[x+bx][y+by][level].objects[h].first->tempOwner==255) | ||||
| 						CSDL_Ext::setPlayerColor(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[(anim+phaseShift)%imgVal].bitmap, ttiles[x+bx][y+by][level].objects[h].first->tempOwner); | ||||
| 					 | ||||
| 					CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[(anim+phaseShift)%imgVal].bitmap,&pp,su,&sr); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	////objects printed, printing shadow | ||||
| 	for (int bx=(moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1); by<dy+1; by++) | ||||
| 		{ | ||||
| 			SDL_Rect sr; | ||||
| 			sr.y=by*32 + moveY + extRect->y; | ||||
| 			sr.x=bx*32 + moveX + extRect->x; | ||||
| 			sr.h=sr.w=32; | ||||
| 			//validateRectTerr(&sr, extRect); | ||||
| 			 | ||||
| 			if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !(*visibilityMap)[bx+x][by+y][level]) | ||||
| 			{ | ||||
| 				SDL_Surface * hide = getVisBitmap(bx+x, by+y, *visibilityMap, level); | ||||
| 				CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	////shadow printed | ||||
| 	//printing borders | ||||
| 	for (int bx=(moveX <= 0 ? 0 : -1); bx<dx+1; bx++) | ||||
| 	{ | ||||
| 		for (int by=(moveY <= 0 ? 0 : -1); by<dy+1; by++) | ||||
| 		{ | ||||
| 			if(bx+x<0 || by+y<0 || bx+x>map->width+(-1) || by+y>map->height+(-1)) | ||||
| 			{ | ||||
| 				SDL_Rect sr; | ||||
| 				sr.y=by*32 + moveY + extRect->y; | ||||
| 				sr.x=bx*32 + moveX + extRect->x; | ||||
| 				sr.h=sr.w=32; | ||||
| 				//validateRectTerr(&sr, extRect); | ||||
| 				SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap,&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
| 			} | ||||
| 			else  | ||||
| 			{ | ||||
| #ifdef MARK_BLOCKED_POSITIONS | ||||
| 				if(ttiles[x+bx][y+by][level].tileInfo->blocked) //temporary hiding blocked positions | ||||
| 				{ | ||||
| 					SDL_Rect sr; | ||||
| 					sr.y=by*32 + moveY; | ||||
| 					sr.x=bx*32 + moveX; | ||||
| 					sr.h=sr.w=32; | ||||
| 					//validateRectTerr(&sr, extRect); | ||||
|  | ||||
| 					SDL_Surface * ns =  CSDL_Ext::newSurface(32, 32, CSDL_Ext::std32bppSurface); | ||||
| 					for(int f=0; f<ns->w*ns->h*4; ++f) | ||||
| 					{ | ||||
| 						*((unsigned char*)(ns->pixels) + f) = 128; | ||||
| 					} | ||||
|  | ||||
| 					SDL_BlitSurface(ns,&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
|  | ||||
| 					SDL_FreeSurface(ns); | ||||
| 				} | ||||
| #endif | ||||
| #ifdef MARK_VISITABLE_POSITIONS | ||||
| 				if(ttiles[x+bx][y+by][level].tileInfo->visitable) //temporary hiding visitable positions | ||||
| 				{ | ||||
| 					SDL_Rect sr; | ||||
| 					sr.y=by*32 + moveY; | ||||
| 					sr.x=bx*32 + moveX; | ||||
| 					sr.h=sr.w=32; | ||||
| 					//validateRectTerr(&sr, extRect); | ||||
|  | ||||
| 					SDL_Surface * ns = CSDL_Ext::newSurface(32, 32, CSDL_Ext::std32bppSurface); | ||||
| 					for(int f=0; f<ns->w*ns->h*4; ++f) | ||||
| 					{ | ||||
| 						*((unsigned char*)(ns->pixels) + f) = 128; | ||||
| 					} | ||||
|  | ||||
| 					SDL_BlitSurface(ns,&genRect(sr.h, sr.w, 0, 0),su,&sr); | ||||
|  | ||||
| 					SDL_FreeSurface(ns); | ||||
| 				} | ||||
| #endif | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	//borders printed | ||||
| 	SDL_SetClipRect(su, &prevClip); //restoring clip_rect | ||||
| 	return su; | ||||
| } | ||||
| SDL_Surface * CMapHandler::getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl) | ||||
| { | ||||
| 	int size = visibilityMap.size()-1;							//is tile visible. arrangement: (like num keyboard) | ||||
|   | ||||
| @@ -104,7 +104,8 @@ public: | ||||
| 	void roadsRiverTerrainInit(); | ||||
| 	void prepareFOWDefs(); | ||||
|  | ||||
| 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it | ||||
| 	SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect); | ||||
| 	SDL_Surface * terrainRectSmooth(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL, int moveX = 0, int moveY = 0); //if extSurf is specified, blit to it | ||||
| 	void updateWater(); | ||||
| 	unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function | ||||
| 	void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper | ||||
|   | ||||
		Reference in New Issue
	
	Block a user