Browse Source

Portability fix for „Win64”. 32-bit DLLs (bink, smack) cannot be loaded, so an empty player-placeholder is used to capture calls we can't properly handle.
Probably some fixes for Linux will be needed. (I guess the whole thing could use some refactoring to unify more code)

Michał W. Urbańczyk 14 years ago
parent
commit
05f166f751
4 changed files with 42 additions and 10 deletions
  1. 2 2
      client/CGameInfo.h
  2. 4 0
      client/CMT.cpp
  3. 9 5
      client/CVideoHandler.cpp
  4. 27 3
      client/CVideoHandler.h

+ 2 - 2
client/CGameInfo.h

@@ -29,7 +29,7 @@ class CGeneralTextHandler;
 class CConsoleHandler;
 class CCursorHandler;
 class CGameState;
-class CVideoPlayer;
+class IMainVideoPlayer;
 
 
 //a class for non-mechanical client GUI classes
@@ -40,7 +40,7 @@ public:
 	CMusicHandler * musich;
 	CConsoleHandler * consoleh;
 	CCursorHandler * curh;
-	CVideoPlayer * videoh;
+	IMainVideoPlayer * videoh;
 };
 
 struct Mapa;

+ 4 - 0
client/CMT.cpp

@@ -258,7 +258,11 @@ int main(int argc, char** argv)
 	tlog0 <<"\tInitializing screen: "<<pomtime.getDif() << std::endl;
 
 	// Initialize video
+#if defined _M_X64 && defined _WIN32 //Win64 -> cannot load 32-bit DLLs for video handling
+	CCS->videoh = new CEmptyVideoPlayer;
+#else
 	CCS->videoh = new CVideoPlayer;
+#endif
 	tlog0<<"\tInitializing video: "<<pomtime.getDif()<<std::endl;
 
 	//we can properly play intro only in the main thread, so we have to move loading to the separate thread

+ 9 - 5
client/CVideoHandler.cpp

@@ -67,7 +67,7 @@ void DLLHandler::Instantiate(const char *filename)
 	if(!dll)
 	{
 		tlog1 << "Failed loading " << filename << std::endl;
-		checkForError();
+		checkForError(true);
 	}
 #else
 	dll = dlopen(filename,RTLD_LOCAL | RTLD_LAZY);
@@ -78,6 +78,11 @@ void *DLLHandler::FindAddress(const char *symbol)
 {
 	void *ret;
 #ifdef _WIN32
+	if(!dll)
+	{
+		tlog1 << "Cannot look for " << symbol << " because DLL hasn't been appropriately loaded!\n";
+		return NULL;
+	}
 	ret = (void*) GetProcAddress(dll,symbol);
 	if(!ret)
 	{
@@ -114,7 +119,6 @@ DLLHandler::DLLHandler()
 CBIKHandler::CBIKHandler()
 {
 	Instantiate("BINKW32.DLL");
-
 	//binkGetError = FindAddress("_BinkGetError@0");
 	binkOpen = (BinkOpen)FindAddress("_BinkOpen@8");
 	binkSetSoundSystem = (BinkSetSoundSystem)FindAddress("_BinkSetSoundSystem@8");
@@ -125,6 +129,7 @@ CBIKHandler::CBIKHandler()
 	binkWait = (BinkWait)FindAddress("_BinkWait@4");
 	binkClose =  (BinkClose)FindAddress("_BinkClose@4");
 
+
 	hBinkFile = NULL;
 	hBink = NULL;
 
@@ -274,10 +279,9 @@ bool CSmackPlayer::wait()
 	return ptrSmackWait(data);
 }
 
-CSmackPlayer::CSmackPlayer()
+CSmackPlayer::CSmackPlayer() : data(NULL)
 {
 	Instantiate("smackw32.dll");
-
 	ptrSmackNextFrame = (SmackNextFrame)FindAddress("_SmackNextFrame@4");
 	ptrSmackWait = (SmackWait)FindAddress("_SmackWait@4");
 	ptrSmackDoFrame = (SmackDoFrame)FindAddress("_SmackDoFrame@4");
@@ -983,4 +987,4 @@ CVideoPlayer::~CVideoPlayer()
 	close();
 }
 
-#endif
+#endif

+ 27 - 3
client/CVideoHandler.h

@@ -71,6 +71,32 @@ public:
 	virtual bool wait()=0;
 	virtual int curFrame() const =0;
 	virtual int frameCount() const =0;
+
+};
+
+class IMainVideoPlayer : public IVideoPlayer
+{
+public:
+	std::string fname;  //name of current video file (empty if idle)
+
+	virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true){}
+	virtual bool openAndPlayVideo(std::string name, int x, int y, SDL_Surface *dst, bool stopOnKey = false) 
+	{
+		return false;
+	}
+};
+
+class CEmptyVideoPlayer : public IMainVideoPlayer
+{
+public:
+	virtual int curFrame() const {return -1;};
+	virtual int frameCount() const {return -1;};
+	virtual void redraw( int x, int y, SDL_Surface *dst, bool update = true ) {};
+	virtual void show( int x, int y, SDL_Surface *dst, bool update = true ) {};
+	virtual void nextFrame() {};
+	virtual void close() {};
+	virtual bool wait() {return false;};
+	virtual bool open( std::string name ) {return false;};
 };
 
 class CBIKHandler : public DLLHandler, public IVideoPlayer
@@ -160,7 +186,7 @@ public:
 
 class CVidHandler;
 
-class CVideoPlayer : public IVideoPlayer
+class CVideoPlayer : public IMainVideoPlayer
 {
 private:
 	CVidHandler vidh; //.vid file handling
@@ -171,7 +197,6 @@ private:
 
 	bool first; //are we about to display the first frame (blocks update)
 public:
-	std::string fname; //name of current video file (empty if idle)
 	
 	CVideoPlayer(); //c-tor
 	~CVideoPlayer(); //d-tor
@@ -251,7 +276,6 @@ public:
 	const char *data;			// video buffer
 	int length;					// video size
 	unsigned int offset;		// current data offset
-	std::string fname; //name of current video file (empty if idle)
 };
 
 #define VIDEO_WIN "win3.mjpg"