1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

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

This commit is contained in:
Michał W. Urbańczyk 2009-08-01 10:08:16 +00:00
parent 3cdff92e42
commit 1f75aeaf34
9 changed files with 113 additions and 42 deletions

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

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

View File

@ -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 )

View File

@ -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;

View File

@ -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;

View File

@ -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__

View File

@ -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)