1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +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); boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
if (!mode) 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 else
{ {
//TODO: add some smart ID to the CTownInstance //TODO: add some smart ID to the CTownInstance

View File

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

View File

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

View File

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

View File

@ -124,6 +124,9 @@ CBIKHandler::CBIKHandler()
hBinkFile = NULL; hBinkFile = NULL;
hBink = NULL; hBink = NULL;
buffer = NULL;
bufferSize = 0;
} }
void CBIKHandler::open(std::string name) void CBIKHandler::open(std::string name)
@ -151,14 +154,39 @@ void CBIKHandler::open(std::string name)
binkSetSoundSystem(waveout,NULL); binkSetSoundSystem(waveout,NULL);
hBink = binkOpen(hBinkFile, 0x8a800000); 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 ) 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); 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); blitBuffer(buffer, x, y, w, h, dst);
if(update) if(update)
SDL_UpdateRect(dst, x, y, w, h); SDL_UpdateRect(dst, x, y, w, h);
@ -176,6 +204,9 @@ void CBIKHandler::close()
CloseHandle(hBinkFile); CloseHandle(hBinkFile);
hBinkFile = NULL; hBinkFile = NULL;
delete [] buffer; delete [] buffer;
buffer = NULL;
bufferSize = 0;
} }
bool CBIKHandler::wait() 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); 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() void CSmackPlayer::nextFrame()
{ {
ptrSmackNextFrame(data); ptrSmackNextFrame(data);
@ -234,8 +280,6 @@ void CSmackPlayer::close()
{ {
ptrSmackClose(data); ptrSmackClose(data);
data = NULL; data = NULL;
delete [] buffer;
buffer = NULL;
} }
void CSmackPlayer::open( std::string name ) void CSmackPlayer::open( std::string name )

View File

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

View File

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

View File

@ -450,9 +450,24 @@ struct DLL_EXPORT Mapa : public CMapHeader
heroes[i]->visitedTown = towns[j]; 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__ #endif // __MAP_H__

View File

@ -334,17 +334,17 @@ void CMapHandler::initObjectRects()
//initializing objects / rects //initializing objects / rects
for(size_t f=0; f < map->objects.size(); ++f) for(size_t f=0; f < map->objects.size(); ++f)
{ {
if(!map->objects[f]) continue; const CGObjectInstance *obj = map->objects[f];
if((map->objects[f]->ID==HEROI_TYPE && static_cast<CGHeroInstance*>(map->objects[f])->inTownGarrison) if( !obj
|| !map->objects[f]->defInfo) || 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; continue;
} }
CDefEssential * curd = map->objects[f]->defInfo->handler;
if(curd)
{
const SDL_Surface *bitmap = curd->ourImages[0].bitmap;
const SDL_Surface *bitmap = obj->defInfo->handler->ourImages[0].bitmap;
for(int fx=0; fx<bitmap->w>>5; ++fx) //bitmap->w/32 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
@ -354,25 +354,25 @@ void CMapHandler::initObjectRects()
cr.h = 32; cr.h = 32;
cr.x = fx<<5; //fx*32 cr.x = fx<<5; //fx*32
cr.y = fy<<5; //fy*32 cr.y = fy<<5; //fy*32
std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(map->objects[f],cr); std::pair<const CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj,cr);
if( (map->objects[f]->pos.x + fx - bitmap->w/32+1) >= 0 if( (obj->pos.x + fx - bitmap->w/32+1) >= 0
&& (map->objects[f]->pos.x + fx - bitmap->w/32+1) < ttiles.size() - frameW && (obj->pos.x + fx - bitmap->w/32+1) < ttiles.size() - frameW
&& (map->objects[f]->pos.y + fy - bitmap->h/32+1) >= 0 && (obj->pos.y + fy - bitmap->h/32+1) >= 0
&& (map->objects[f]->pos.y + fy - bitmap->h/32+1) < ttiles[0].size() - frameH && (obj->pos.y + fy - bitmap->h/32+1) < ttiles[0].size() - frameH
) )
{ {
//TerrainTile2 & curt = //TerrainTile2 & curt =
// ttiles // ttiles
// [map->objects[f]->pos.x + fx - bitmap->w/32] // [obj->pos.x + fx - bitmap->w/32]
//[map->objects[f]->pos.y + fy - bitmap->h/32] //[obj->pos.y + fy - bitmap->h/32]
//[map->objects[f]->pos.z]; //[obj->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); 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 fy=0; fy<bitmap->h/32; ++fy)
} //for(int fx=0; fx<bitmap->w/32; ++fx) } //for(int fx=0; fx<bitmap->w/32; ++fx)
}//if curd
} // for(int f=0; f<map->objects.size(); ++f) } // for(int f=0; f<map->objects.size(); ++f)
for(int ix=0; ix<ttiles.size()-frameW; ++ix) for(int ix=0; ix<ttiles.size()-frameW; ++ix)
{ {
for(int iy=0; iy<ttiles[0].size()-frameH; ++iy) for(int iy=0; iy<ttiles[0].size()-frameH; ++iy)