1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Video in Tavern Window. Minor improvements.

This commit is contained in:
Michał W. Urbańczyk 2009-06-24 09:17:33 +00:00
parent 60f7048662
commit f0dea8d708
5 changed files with 68 additions and 18 deletions

View File

@ -892,7 +892,7 @@ void CPlayerInterface::handleMouseMotion(SDL_Event *sEvent)
} }
//adventure map scrolling with mouse //adventure map scrolling with mouse
if(!SDL_GetKeyState(NULL)[SDLK_LCTRL]) if(!SDL_GetKeyState(NULL)[SDLK_LCTRL] && adventureInt->active)
{ {
if(sEvent->motion.x<15) if(sEvent->motion.x<15)
{ {

View File

@ -2055,7 +2055,6 @@ StartInfo CPreGame::runLoop()
#ifdef _WIN32 #ifdef _WIN32
CGI->videoh->open("ACREDIT.SMK"); CGI->videoh->open("ACREDIT.SMK");
CGI->videoh->show(8, 105, screen, false);
#endif #endif
while(run) while(run)
@ -2336,7 +2335,9 @@ StartInfo CPreGame::runLoop()
SDL_Delay(20); //give time for other apps SDL_Delay(20); //give time for other apps
} }
ret.mode = (fromMenu==newGame) ? 0 : 1; ret.mode = (fromMenu==newGame) ? 0 : 1;
#ifdef _WIN32
CGI->videoh->close(); CGI->videoh->close();
#endif
return ret; return ret;
} }

View File

@ -39,6 +39,7 @@
#include "../lib/NetPacks.h" #include "../lib/NetPacks.h"
#include "CSpellWindow.h" #include "CSpellWindow.h"
#include "CHeroWindow.h" #include "CHeroWindow.h"
#include "../hch/CVideoHandler.h"
/* /*
* GUIClasses.cpp, part of VCMI engine * GUIClasses.cpp, part of VCMI engine
@ -2788,6 +2789,10 @@ CTavernWindow::CTavernWindow(const CGHeroInstance *H1, const CGHeroInstance *H2,
if(!H1) if(!H1)
recruit->block(1); recruit->block(1);
} }
#ifdef _WIN32
CGI->videoh->open("TAVERN.BIK");
#endif
} }
void CTavernWindow::recruitb() void CTavernWindow::recruitb()
@ -2799,6 +2804,9 @@ void CTavernWindow::recruitb()
CTavernWindow::~CTavernWindow() CTavernWindow::~CTavernWindow()
{ {
#ifdef _WIN32
CGI->videoh->close();
#endif
SDL_FreeSurface(bg); SDL_FreeSurface(bg);
delete cancel; delete cancel;
delete thiefGuild; delete thiefGuild;
@ -2837,6 +2845,9 @@ void CTavernWindow::close()
void CTavernWindow::show(SDL_Surface * to) void CTavernWindow::show(SDL_Surface * to)
{ {
blitAt(bg,pos.x,pos.y,to); blitAt(bg,pos.x,pos.y,to);
#ifdef _WIN32
CGI->videoh->update(pos.x+70, pos.y+56, to, true, false);
#endif
if(h1.h) if(h1.h)
h1.show(to); h1.show(to);
if(h2.h) if(h2.h)

View File

@ -181,6 +181,14 @@ int CBIKHandler::frameCount() const
return hBink->frameCount; return hBink->frameCount;
} }
void CBIKHandler::redraw( int x, int y, SDL_Surface *dst, bool update )
{
int w = hBink->width, h = hBink->height;
blitBuffer(buffer, x, y, w, h, dst);
if(update)
SDL_UpdateRect(dst, x, y, w, h);
}
void CSmackPlayer::nextFrame() void CSmackPlayer::nextFrame()
{ {
ptrSmackNextFrame(data); ptrSmackNextFrame(data);
@ -241,8 +249,22 @@ void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
//put frame to the buffer //put frame to the buffer
ptrSmackToBuffer(data, 0, 0, stripe, w, buf, 0x80000000); ptrSmackToBuffer(data, 0, 0, stripe, w, buf, 0x80000000);
ptrSmackDoFrame(data); ptrSmackDoFrame(data);
redraw(x, y, dst, update);
}
int CSmackPlayer::curFrame() const
{
return data->currentFrame;
}
int CSmackPlayer::frameCount() const
{
return data->frameCount;
}
void CSmackPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
{
int w = data->width, h = data->height;
/* Lock the screen for direct access to the pixels */ /* Lock the screen for direct access to the pixels */
if ( SDL_MUSTLOCK(dst) ) if ( SDL_MUSTLOCK(dst) )
{ {
@ -279,16 +301,6 @@ void CSmackPlayer::show( int x, int y, SDL_Surface *dst, bool update)
SDL_UpdateRect(dst, x, y, w, h); SDL_UpdateRect(dst, x, y, w, h);
} }
int CSmackPlayer::curFrame() const
{
return data->currentFrame;
}
int CSmackPlayer::frameCount() const
{
return data->frameCount;
}
CVideoPlayer::CVideoPlayer() CVideoPlayer::CVideoPlayer()
{ {
vidh = new CVidHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "VIDEO.VID")); vidh = new CVidHandler(std::string(DATA_DIR "Data" PATHSEPARATOR "VIDEO.VID"));
@ -308,6 +320,7 @@ void CVideoPlayer::open(std::string name)
current = &smkPlayer; current = &smkPlayer;
fname = name; fname = name;
first = true;
//extract video from video.vid so we can play it //extract video from video.vid so we can play it
vidh->extract(name, name); vidh->extract(name, name);
@ -365,15 +378,35 @@ bool CVideoPlayer::openAndPlayVideo(std::string name, int x, int y, SDL_Surface
return ret; return ret;
} }
void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool redraw, bool update ) void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, bool update )
{ {
bool w = wait(); //check if should keep current frame bool w = false;
if(!first)
{
w = wait(); //check if should keep current frame
if(!w)
nextFrame();
}
else
{
first = false;
}
if(!w)
nextFrame();
if(!w || redraw) //redraw if changed frame or we was told to
if(!w)
{
show(x,y,dst,update); show(x,y,dst,update);
}
else if (forceRedraw)
{
redraw(x, y, dst, update);
}
}
void CVideoPlayer::redraw( int x, int y, SDL_Surface *dst, bool update )
{
current->redraw(x, y, dst, update);
} }
//reads events and throws on key down //reads events and throws on key down

View File

@ -65,6 +65,7 @@ public:
virtual void close()=0; virtual void close()=0;
virtual void nextFrame()=0; virtual void nextFrame()=0;
virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0; virtual void show(int x, int y, SDL_Surface *dst, bool update = true)=0;
virtual void redraw(int x, int y, SDL_Surface *dst, bool update = true)=0; //reblits buffer
virtual bool wait()=0; virtual bool wait()=0;
virtual int curFrame() const =0; virtual int curFrame() const =0;
virtual int frameCount() const =0; virtual int frameCount() const =0;
@ -90,6 +91,7 @@ public:
void close(); void close();
void nextFrame(); void nextFrame();
void show(int x, int y, SDL_Surface *dst, bool update = true); void show(int x, int y, SDL_Surface *dst, bool update = true);
void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
bool wait(); bool wait();
int curFrame() const; int curFrame() const;
int frameCount() const; int frameCount() const;
@ -143,6 +145,7 @@ public:
void close(); void close();
void nextFrame(); void nextFrame();
void show(int x, int y, SDL_Surface *dst, bool update = true); void show(int x, int y, SDL_Surface *dst, bool update = true);
void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
bool wait(); bool wait();
int curFrame() const; int curFrame() const;
int frameCount() const; int frameCount() const;
@ -160,6 +163,7 @@ private:
IVideoPlayer *current; //points to bik or smk player, appropriate to type of currently played video IVideoPlayer *current; //points to bik or smk player, appropriate to type of currently played video
std::string fname; //name of current video file (empty if idle) std::string fname; //name of current video file (empty if idle)
bool first; //are we about to display the first frame (blocks update)
public: public:
CVideoPlayer(); //c-tor CVideoPlayer(); //c-tor
~CVideoPlayer(); //d-tor ~CVideoPlayer(); //d-tor
@ -169,7 +173,8 @@ public:
void close(); void close();
void nextFrame(); //move animation to the next frame void nextFrame(); //move animation to the next frame
void show(int x, int y, SDL_Surface *dst, bool update = true); //blit current frame void show(int x, int y, SDL_Surface *dst, bool update = true); //blit current frame
void update(int x, int y, SDL_Surface *dst, bool redraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true void redraw(int x, int y, SDL_Surface *dst, bool update = true); //reblits buffer
void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true); //moves to next frame if appropriate, and blits it or blits only if redraw paremeter is set true
bool wait(); //true if we should wait before displaying next frame (for keeping FPS) bool wait(); //true if we should wait before displaying next frame (for keeping FPS)
int curFrame() const; //current frame number <1, framecount> int curFrame() const; //current frame number <1, framecount>
int frameCount() const; int frameCount() const;