Browse Source

Video working with 32 bpp. Proper loading of hero on boat. Fixed problems with newly recruited hero blockvis info. Fixed possible crashes.

Michał W. Urbańczyk 16 years ago
parent
commit
1f75aeaf34
9 changed files with 113 additions and 42 deletions
  1. 7 1
      CCallback.cpp
  2. 2 2
      client/GUIClasses.cpp
  3. 1 0
      client/NetPacksClient.cpp
  4. 1 0
      hch/CObjectHandler.h
  5. 49 5
      hch/CVideoHandler.cpp
  6. 3 0
      hch/CVideoHandler.h
  7. 1 0
      lib/NetPacksLib.cpp
  8. 17 2
      lib/map.h
  9. 32 32
      mapHandler.cpp

+ 7 - 1
CCallback.cpp

@@ -120,7 +120,13 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode =
 {
 	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
 	if (!mode)
-		return gs->players[gs->currentPlayer].towns[val];
+	{
+		const std::vector<CGTownInstance *> &towns = gs->players[gs->currentPlayer].towns;
+		if(val < towns.size())
+			return towns[val];
+		else 
+			return NULL;
+	}
 	else 
 	{
 		//TODO: add some smart ID to the CTownInstance

+ 2 - 2
client/GUIClasses.cpp

@@ -2079,8 +2079,8 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, int creatureCount, StackState
 	}
 
 	//damage
-	int dmgMin = c->damageMin * State->dmgMultiplier;
-	int dmgMax = c->damageMax * State->dmgMultiplier;
+	int dmgMin = c->damageMin * (State ? State->dmgMultiplier : 1);
+	int dmgMax = c->damageMax * (State ? State->dmgMultiplier : 1);
 
 	printAt(CGI->generaltexth->allTexts[199], 155, 105, GEOR13, zwykly, bitmap);
 	SDL_itoa(dmgMin, pom, 10);

+ 1 - 0
client/NetPacksClient.cpp

@@ -244,6 +244,7 @@ void HeroRecruited::applyCl( CClient *cl )
 	}
 
 	CGI->mh->initHeroDef(h);
+	CGI->mh->printObject(h);
 	if(vstd::contains(cl->playerint,h->tempOwner))
 	{
 		cl->playerint[h->tempOwner]->heroCreated(h);

+ 1 - 0
hch/CObjectHandler.h

@@ -769,6 +769,7 @@ public:
 
 	CGBoat()
 	{
+		hero = NULL;
 		direction = 4;
 	}
 	template <typename Handler> void serialize(Handler &h, const int version)

+ 49 - 5
hch/CVideoHandler.cpp

@@ -124,6 +124,9 @@ CBIKHandler::CBIKHandler()
 
 	hBinkFile = NULL;
 	hBink = NULL;
+
+	buffer = NULL;
+	bufferSize = 0;
 }
 
 void CBIKHandler::open(std::string name)
@@ -151,14 +154,39 @@ void CBIKHandler::open(std::string name)
 		binkSetSoundSystem(waveout,NULL);
 
 	hBink = binkOpen(hBinkFile, 0x8a800000);
-	buffer = new char[hBink->width * hBink->width * 3];
+
+	allocBuffer();
 }
 
 void CBIKHandler::show( int x, int y, SDL_Surface *dst, bool update )
 {
-	int w = hBink->width, h = hBink->height;
+	const int w = hBink->width, 
+		h = hBink->height, 
+		Bpp = dst->format->BytesPerPixel;
+
+	int mode = -1;
+
+	//screen color depth might have changed... (eg. because F4)
+	if(bufferSize != w * h * Bpp)
+	{
+		freeBuffer();
+		allocBuffer(Bpp);
+	}
+
+	switch(Bpp)
+	{
+	case 3:
+		mode = 0;
+		break;
+	case 4:
+		mode = 1;
+		break;
+	default:
+		return; //not supported screen depth
+	}
+
 	binkDoFrame(hBink);
-	binkCopyToBuffer(hBink, buffer, w*3, h, 0, 0, 0);
+	binkCopyToBuffer(hBink, buffer, w*Bpp, h, 0, 0, mode);
 	blitBuffer(buffer, x, y, w, h, dst);
 	if(update)
 		SDL_UpdateRect(dst, x, y, w, h);
@@ -176,6 +204,9 @@ void CBIKHandler::close()
 	CloseHandle(hBinkFile);
 	hBinkFile = NULL;
 	delete [] buffer;
+
+	buffer = NULL;
+	bufferSize = 0;
 }
 
 bool CBIKHandler::wait()
@@ -201,6 +232,21 @@ void CBIKHandler::redraw( int x, int y, SDL_Surface *dst, bool update )
 		SDL_UpdateRect(dst, x, y, w, h);
 }
 
+void CBIKHandler::allocBuffer(int Bpp)
+{
+	if(!Bpp) Bpp = screen->format->BytesPerPixel;
+
+	bufferSize = hBink->width * hBink->height * Bpp;
+	buffer = new char[bufferSize];
+}
+
+void CBIKHandler::freeBuffer()
+{
+	delete [] buffer;
+	buffer = NULL;
+	bufferSize = 0;
+}
+
 void CSmackPlayer::nextFrame()
 {
 	ptrSmackNextFrame(data);
@@ -234,8 +280,6 @@ void CSmackPlayer::close()
 {
 	ptrSmackClose(data);
 	data = NULL;
-	delete [] buffer;
-	buffer = NULL;
 }
 
 void CSmackPlayer::open( std::string name )

+ 3 - 0
hch/CVideoHandler.h

@@ -72,10 +72,13 @@ public:
 
 class CBIKHandler : public DLLHandler, public IVideoPlayer
 {
+	void allocBuffer(int Bpp = 0);
+	void freeBuffer();
 public:
 	HANDLE hBinkFile;
 	HBINK hBink;
 	char * buffer;
+	int bufferSize;
 	BinkSetSoundSystem binkSetSoundSystem;
 	BinkOpen binkOpen;
 	//BinkGetPalette getPalette;

+ 1 - 0
lib/NetPacksLib.cpp

@@ -473,6 +473,7 @@ DLL_EXPORT void HeroRecruited::applyGs( CGameState *gs )
 	h->initHeroDefInfo();
 	gs->map->heroes.push_back(h);
 	gs->getPlayer(h->getOwner())->heroes.push_back(h);
+	h->initObj();
 	gs->map->addBlockVisTiles(h);
 	t->visitingHero = h;
 	h->visitedTown = t;

+ 17 - 2
lib/map.h

@@ -450,9 +450,24 @@ struct DLL_EXPORT Mapa : public CMapHeader
 						heroes[i]->visitedTown = towns[j];
 					}
 				}
-			}
 
-		}
+				vistile.x -= 2; //manifest pos
+				const TerrainTile &t = getTile(vistile);
+				if(t.tertype != TerrainTile::water) continue;
+				//hero stands on the water - he must be in the boat
+				for(int j = 0; j < t.visitableObjects.size(); j++)
+				{
+					if(t.visitableObjects[j]->ID == 8)
+					{
+						CGBoat *b = static_cast<CGBoat *>(t.visitableObjects[j]);
+						heroes[i]->boat = b;
+						b->hero = heroes[i];
+						removeBlockVisTiles(b);
+						break;
+					}
+				}
+			} //heroes loop
+		} //!saving
 	}
 };
 #endif // __MAP_H__

+ 32 - 32
mapHandler.cpp

@@ -334,45 +334,45 @@ void CMapHandler::initObjectRects()
 	//initializing objects / rects
 	for(size_t f=0; f < map->objects.size(); ++f)
 	{
-		if(!map->objects[f]) continue;
-		if((map->objects[f]->ID==HEROI_TYPE && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison)
-			|| !map->objects[f]->defInfo)
+		const CGObjectInstance *obj = map->objects[f];
+		if(	!obj
+			|| obj->ID==HEROI_TYPE && static_cast<const CGHeroInstance*>(obj)->inTownGarrison //garrisoned hero
+			|| obj->ID==8 && static_cast<const CGBoat*>(obj)->hero //boat wih hero (hero graphics is used)
+			|| !obj->defInfo
+			|| !obj->defInfo->handler) //no graphic...
 		{
 			continue;
 		}
-		CDefEssential * curd = map->objects[f]->defInfo->handler;
-		if(curd)
-		{
-			const SDL_Surface *bitmap = curd->ourImages[0].bitmap;
 
-			for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32
+		const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap;
+		for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32
+		{
+			for(int fy=0; fy<bitmap->h>>5; ++fy) //bitmap->h/32
 			{
-				for(int fy=0; fy<bitmap->h>>5; ++fy) //bitmap->h/32
+				SDL_Rect cr;
+				cr.w = 32;
+				cr.h = 32;
+				cr.x = fx<<5; //fx*32
+				cr.y = fy<<5; //fy*32
+				std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj,cr);
+				
+				if(    (obj->pos.x + fx - bitmap->w/32+1)  >=  0 
+					&& (obj->pos.x + fx - bitmap->w/32+1)  <  ttiles.size() - frameW 
+					&& (obj->pos.y + fy - bitmap->h/32+1)  >=  0 
+					&& (obj->pos.y + fy - bitmap->h/32+1)  <  ttiles[0].size() - frameH
+				  )
 				{
-					SDL_Rect cr;
-					cr.w = 32;
-					cr.h = 32;
-					cr.x = fx<<5; //fx*32
-					cr.y = fy<<5; //fy*32
-					std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(map->objects[f],cr);
-					
-					if(    (map->objects[f]->pos.x + fx - bitmap->w/32+1)  >=  0 
-						&& (map->objects[f]->pos.x + fx - bitmap->w/32+1)  <  ttiles.size() - frameW 
-						&& (map->objects[f]->pos.y + fy - bitmap->h/32+1)  >=  0 
-						&& (map->objects[f]->pos.y + fy - bitmap->h/32+1)  <  ttiles[0].size() - frameH
-					  )
-					{
-						//TerrainTile2 & curt =
-						//	ttiles
-						//	[map->objects[f]->pos.x + fx - bitmap->w/32]
-						//[map->objects[f]->pos.y + fy - bitmap->h/32]
-						//[map->objects[f]->pos.z];
-						ttiles[map->objects[f]->pos.x + fx - bitmap->w/32+1][map->objects[f]->pos.y + fy - bitmap->h/32+1][map->objects[f]->pos.z].objects.push_back(toAdd);
-					}
-				} // for(int fy=0; fy<bitmap->h/32; ++fy)
-			} //for(int fx=0; fx<bitmap->w/32; ++fx)
-		}//if curd
+					//TerrainTile2 & curt =
+					//	ttiles
+					//	[obj->pos.x + fx - bitmap->w/32]
+					//[obj->pos.y + fy - bitmap->h/32]
+					//[obj->pos.z];
+					ttiles[obj->pos.x + fx - bitmap->w/32+1][obj->pos.y + fy - bitmap->h/32+1][obj->pos.z].objects.push_back(toAdd);
+				}
+			} // for(int fy=0; fy<bitmap->h/32; ++fy)
+		} //for(int fx=0; fx<bitmap->w/32; ++fx)
 	} // for(int f=0; f<map->objects.size(); ++f)
+
 	for(int ix=0; ix<ttiles.size()-frameW; ++ix)
 	{
 		for(int iy=0; iy<ttiles[0].size()-frameH; ++iy)