From 66b708c168376ca562243afe7179e48f15d7d8d3 Mon Sep 17 00:00:00 2001 From: beegee1 Date: Sun, 17 Apr 2011 18:02:13 +0000 Subject: [PATCH] * PreGame interface gets now redrawn every frame. * Changed PreGame event handling and update/draw order. * Changed mouse cursor drawing in PreGame * Fixed linux bug where main menu WOG animation gets played only once, windows/linux video handling is now more similar * Minor code improvements --- client/CCursorHandler.cpp | 5 +++++ client/CCursorHandler.h | 1 + client/CMT.cpp | 1 + client/CPlayerInterface.cpp | 3 +++ client/CPreGame.cpp | 42 ++++++++++++++++++++----------------- client/CPreGame.h | 2 +- client/CVideoHandler.cpp | 9 ++++++-- client/CVideoHandler.h | 3 ++- client/GUIBase.cpp | 8 +++---- client/VCMI_client.vcxproj | 20 +++++++++--------- global.h | 10 --------- 11 files changed, 56 insertions(+), 48 deletions(-) diff --git a/client/CCursorHandler.cpp b/client/CCursorHandler.cpp index 43cb24a84..2868b10c4 100644 --- a/client/CCursorHandler.cpp +++ b/client/CCursorHandler.cpp @@ -76,6 +76,11 @@ void CCursorHandler::draw2() //blitAt(help,x,y); } +void CCursorHandler::draw(SDL_Surface *to) +{ + CSDL_Ext::blitSurface(cursors[mode]->ourImages[number].bitmap, 0, to, &genRect(40, 40, xpos, ypos)); +} + void CCursorHandler::shiftPos( int &x, int &y ) { if((mode==1 && number!=6) || mode ==3) diff --git a/client/CCursorHandler.h b/client/CCursorHandler.h index d136e0088..0c7e54220 100644 --- a/client/CCursorHandler.h +++ b/client/CCursorHandler.h @@ -32,6 +32,7 @@ public: void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) void dragAndDropCursor (SDL_Surface* image); // Replace cursor with a custom image. void draw1(); + void draw(SDL_Surface *to); void shiftPos( int &x, int &y ); void draw2(); diff --git a/client/CMT.cpp b/client/CMT.cpp index f3902c1a0..ccb28bd32 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -658,6 +658,7 @@ static void listenForEvents() void startGame(StartInfo * options, CConnection *serv/* = NULL*/) { GH.curInt =NULL; + SDL_FillRect(screen, 0, 0); if(gOnlyAI) { for(std::map::iterator it = options->playerInfos.begin(); diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index fce8093b5..c279a8f29 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1337,6 +1337,9 @@ void CPlayerInterface::update() else GH.simpleRedraw(); + if (conf.cc.showFPS) + GH.drawFPSCounter(); + // draw the mouse cursor and update the screen // todo: bad way of updating the cursor, update screen should be the last statement of the rendering process CCS->curh->draw1(); diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 3f499775a..edd28c78f 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -47,6 +47,7 @@ #include "../lib/RegisterTypes.cpp" #include #include "../CThreadHelper.h" +#include "CConfigHandler.h" /* * CPreGame.cpp, part of VCMI engine @@ -270,13 +271,14 @@ CMenuScreen::~CMenuScreen() void CMenuScreen::showAll( SDL_Surface * to ) { blitAt(CGP->mainbg, 0, 0, to); + CCS->videoh->update(pos.x + 8, pos.y + 105, to, true, false); CIntObject::showAll(to); } void CMenuScreen::show( SDL_Surface * to ) { CIntObject::show(to); - CCS->videoh->update(pos.x + 8, pos.y + 105, screen, true, false); + //CCS->videoh->update(pos.x + 8, pos.y + 105, screen, true, false); } void CMenuScreen::moveTo( CMenuScreen *next ) @@ -337,31 +339,33 @@ void CGPreGame::disposeGraphics() void CGPreGame::update() { + SDL_FillRect(screen, 0, 0); + if (GH.listInt.size() == 0) { CCS->musich->playMusic(musicBase::mainMenu, -1); - #ifdef _WIN32 CCS->videoh->open("ACREDIT.SMK"); - #else - CCS->videoh->open("ACREDIT.SMK", true, false); - #endif GH.pushInt(scrs[CMenuScreen::mainMenu]); } if(SEL) SEL->update(); - // draw the mouse cursor and update the screen - // todo: bad way of updating the cursor, update screen should be the last statement of the rendering process - CCS->curh->draw1(); - CSDL_Ext::update(screen); - CCS->curh->draw2(); - - GH.topInt()->show(screen); - // Handles mouse and key input GH.updateTime(); GH.handleEvents(); + + if (GH.curInt == 0) // no redraw, when a new game was created + return; + + GH.totalRedraw(); + + if (conf.cc.showFPS) + GH.drawFPSCounter(); + + // draw the mouse cursor and update the screen + CCS->curh->draw(screen); + CSDL_Ext::update(screen); } CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMultiMode MultiPlayer /*= CMenuScreen::SINGLE_PLAYER*/, const std::map *Names /*= NULL*/) @@ -3503,6 +3507,7 @@ CCampaignScreen::CCampaignButton::CCampaignButton(SDL_Surface *bg, const std::st // Create the button hover effect hoverLabel = new CLabel(pos.w / 2., pos.h + 20, FONT_MEDIUM, CENTER, tytulowy, ""); hoverLabel->ignoreLeadingWhitespace = false; + hoverLabel->autoRedraw = false; } CCampaignScreen::CCampaignButton::~CCampaignButton() @@ -3523,19 +3528,18 @@ void CCampaignScreen::CCampaignButton::hover(bool on) { // Deletes the text from the screen when you hover out of the bounds of the button hoverLabel->setTxt(" "); - GH.totalRedraw(); } } -void CCampaignScreen::CCampaignButton::show(SDL_Surface *to) +void CCampaignScreen::CCampaignButton::showAll(SDL_Surface *to) { - CIntObject::show(to); + CIntObject::showAll(to); if (status == CCampaignScreen::DISABLED || video == "" || button == 0) return; -#ifdef _WIN32 + // TODO: windows video code seem to have diverged a little bit // from non-windows code. Needs to be fixed and this ifdef removed. @@ -3552,7 +3556,7 @@ void CCampaignScreen::CCampaignButton::show(SDL_Surface *to) CCS->videoh->close(); blitAt(button, pos, to); } -#endif + if (status == CCampaignScreen::COMPLETED) // Draw a checked symbol when you completed the mission { @@ -3573,4 +3577,4 @@ void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousStat campState->camp = ourCampaign; GH.pushInt( new CBonusSelection(campState) ); } -} \ No newline at end of file +} diff --git a/client/CPreGame.h b/client/CPreGame.h index 235673542..e760f2ec6 100644 --- a/client/CPreGame.h +++ b/client/CPreGame.h @@ -449,7 +449,7 @@ class CCampaignScreen : public CIntObject CCampaignButton(SDL_Surface *bg, const std::string image, const int x, const int y, CampaignStatus status); // c-tor ~CCampaignButton(); // d-tor - void show(SDL_Surface *to); + void showAll(SDL_Surface *to); }; std::vector campButtons; // a container which holds all buttons where you can start a campaign diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index 8595e5c6e..fecf2d978 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -667,7 +667,8 @@ CVideoPlayer::CVideoPlayer() bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay) { close(); - + + this->fname = fname; offset = 0; refreshWait = 3; refreshCount = -1; @@ -871,7 +872,10 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo refreshCount = refreshWait; if (nextFrame()) show(x,y,dst,update); - } else { + else + open(fname); + } + else { redraw(x, y, dst, update); } @@ -880,6 +884,7 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo void CVideoPlayer::close() { + fname = ""; if (sws) { sws_freeContext(sws); sws = NULL; diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index 5aa5f568f..dcff9644b 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -235,7 +235,7 @@ public: ~CVideoPlayer(); bool init(); - bool open(std::string fname, bool loop=false, bool useOverlay=false); + bool open(std::string fname, bool loop = false, bool useOverlay = false); void close(); bool nextFrame(); // display next frame @@ -250,6 +250,7 @@ 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" diff --git a/client/GUIBase.cpp b/client/GUIBase.cpp index 5b84a1bf9..ad8ccbd49 100644 --- a/client/GUIBase.cpp +++ b/client/GUIBase.cpp @@ -10,6 +10,7 @@ #include "Graphics.h" #include "../CThreadHelper.h" #include "CConfigHandler.h" +#include /* * GUIBase.cpp, part of VCMI engine @@ -369,10 +370,7 @@ void CGuiHandler::run() { if(curInt) curInt->update(); // calls a update and drawing process of the loaded game interface object at the moment - - if (conf.cc.showFPS) - drawFPSCounter(); - + mainFPSmng->framerateDelay(); // holds a constant FPS } } HANDLE_EXCEPTION @@ -406,7 +404,7 @@ void CGuiHandler::drawFPSCounter() static SDL_Rect overlay = { 0, 0, 64, 32}; Uint32 black = SDL_MapRGB(screen->format, 10, 10, 10); SDL_FillRect(screen, &overlay, black); - std::string fps = toString(mainFPSmng->fps); + std::string fps = boost::lexical_cast(mainFPSmng->fps); CSDL_Ext::printAt(fps, 10, 10, FONT_BIG, yellow, screen); } diff --git a/client/VCMI_client.vcxproj b/client/VCMI_client.vcxproj index 921053915..cbcae125c 100644 --- a/client/VCMI_client.vcxproj +++ b/client/VCMI_client.vcxproj @@ -63,18 +63,18 @@ AllRules.ruleset - $(IncludePath) - $(LibraryPath) - $(IncludePath) - $(IncludePath) - $(LibraryPath) - $(LibraryPath) + D:\Program Files\boost\boost_1_46_1;$(IncludePath) + D:\Program Files\boost\boost_1_46_1\stage\lib;$(LibraryPath) + C:\C++\boost_1_42_0;$(IncludePath) + C:\C++\boost_1_42_0;$(IncludePath) + C:\C++\boost_1_42_0\stage\lib;$(LibraryPath) + C:\C++\boost_1_42_0\stage\lib;$(LibraryPath) /MP4 %(AdditionalOptions) Disabled - ..\..\include;%(AdditionalIncludeDirectories) + D:\Program Files\boost\boost_1_46_1;..\..\include;%(AdditionalIncludeDirectories) false false false @@ -88,7 +88,7 @@ SDL.lib;zdll.lib;SDL_image.lib;SDL_ttf.lib;SDL_mixer.lib;VCMI_lib.lib;%(AdditionalDependencies) NotSet - ../../libs;../;%(AdditionalLibraryDirectories) + D:\Program Files\boost\boost_1_46_1\stage\lib;../../libs;../;%(AdditionalLibraryDirectories) true false MachineX86 @@ -107,7 +107,7 @@ true true true - ..\..\include;%(AdditionalIncludeDirectories) + D:\Program Files\boost\boost_1_46_1;..\..\include;%(AdditionalIncludeDirectories) true Default MultiThreadedDLL @@ -118,7 +118,7 @@ SDL.lib;zdll.lib;SDL_image.lib;SDL_ttf.lib;SDL_mixer.lib;VCMI_lib.lib;%(AdditionalDependencies) - ../../libs;../;%(AdditionalLibraryDirectories) + D:\Program Files\boost\boost_1_46_1\stage\lib;../../libs;../;%(AdditionalLibraryDirectories) true NotSet true diff --git a/global.h b/global.h index 149d71a58..ab793779c 100644 --- a/global.h +++ b/global.h @@ -370,16 +370,6 @@ enum EAlignment GOOD, EVIL, NEUTRAL }; -// Converts an int/double or any data type you wish to a string -template -std::string toString(const T& value) -{ - std::ostringstream oss; - oss << value; - return oss.str(); -} - - //uncomment to make it work //#define MARK_BLOCKED_POSITIONS //#define MARK_VISITABLE_POSITIONS