1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

Fixed a few CWE-457

This commit is contained in:
AlexVinS
2016-11-27 17:48:18 +03:00
parent f11c54b5e9
commit c4ab962cc0
15 changed files with 116 additions and 93 deletions

View File

@ -36,7 +36,7 @@
#define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl)) #define LOGFL(text, formattingEl) print(boost::str(boost::format(text) % formattingEl))
CBattleAI::CBattleAI(void) CBattleAI::CBattleAI(void)
: side(-1) : side(-1), wasWaitingForRealize(false), wasUnlockingGs(false)
{ {
} }

View File

@ -83,6 +83,7 @@ struct SectorMap
Sector() Sector()
{ {
id = -1; id = -1;
water = false;
} }
}; };

View File

@ -18,7 +18,9 @@ CClientState * CCS = nullptr;
CGameInfo::CGameInfo() CGameInfo::CGameInfo()
{ {
generaltexth = nullptr;
mh = nullptr; mh = nullptr;
townh = nullptr;
} }
void CGameInfo::setFromLib() void CGameInfo::setFromLib()

View File

@ -620,6 +620,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
if (screenType == CMenuScreen::campaignList) if (screenType == CMenuScreen::campaignList)
{ {
opt = nullptr; opt = nullptr;
randMapTab = nullptr;
} }
else else
{ {
@ -3912,6 +3913,7 @@ CSavingScreen::~CSavingScreen()
ISelectionScreenInfo::ISelectionScreenInfo(const std::map<ui8, std::string> *Names /*= nullptr*/) ISelectionScreenInfo::ISelectionScreenInfo(const std::map<ui8, std::string> *Names /*= nullptr*/)
{ {
multiPlayer = CMenuScreen::SINGLE_PLAYER; multiPlayer = CMenuScreen::SINGLE_PLAYER;
screenType = CMenuScreen::mainMenu;
assert(!SEL); assert(!SEL);
SEL = this; SEL = this;
current = nullptr; current = nullptr;
@ -4102,6 +4104,8 @@ void StartWithCurrentSettings::apply(CSelectionScreen *selScreen)
CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config ) CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config )
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL;
pos.x += config["x"].Float(); pos.x += config["x"].Float();
pos.y += config["y"].Float(); pos.y += config["y"].Float();
pos.w = 200; pos.w = 200;
@ -4110,24 +4114,23 @@ CCampaignScreen::CCampaignButton::CCampaignButton(const JsonNode &config )
campFile = config["file"].String(); campFile = config["file"].String();
video = config["video"].String(); video = config["video"].String();
OBJ_CONSTRUCTION_CAPTURING_ALL;
status = config["open"].Bool() ? CCampaignScreen::ENABLED : CCampaignScreen::DISABLED; status = config["open"].Bool() ? CCampaignScreen::ENABLED : CCampaignScreen::DISABLED;
CCampaignHeader header = CCampaignHandler::getHeader(campFile); CCampaignHeader header = CCampaignHandler::getHeader(campFile);
hoverText = header.name; hoverText = header.name;
hoverLabel = nullptr;
if (status != CCampaignScreen::DISABLED) if (status != CCampaignScreen::DISABLED)
{ {
addUsedEvents(LCLICK | HOVER); addUsedEvents(LCLICK | HOVER);
image = new CPicture(config["image"].String()); new CPicture(config["image"].String());
hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::YELLOW, ""); hoverLabel = new CLabel(pos.w / 2, pos.h + 20, FONT_MEDIUM, CENTER, Colors::YELLOW, "");
parent->addChild(hoverLabel); parent->addChild(hoverLabel);
} }
if (status == CCampaignScreen::COMPLETED) if (status == CCampaignScreen::COMPLETED)
checkMark = new CPicture("CAMPCHK"); new CPicture("CAMPCHK");
} }
void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousState) void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousState)
@ -4142,10 +4145,13 @@ void CCampaignScreen::CCampaignButton::clickLeft(tribool down, bool previousStat
void CCampaignScreen::CCampaignButton::hover(bool on) void CCampaignScreen::CCampaignButton::hover(bool on)
{ {
if (on) if (hoverLabel)
hoverLabel->setText(hoverText); // Shows the name of the campaign when you get into the bounds of the button {
else if (on)
hoverLabel->setText(" "); hoverLabel->setText(hoverText); // Shows the name of the campaign when you get into the bounds of the button
else
hoverLabel->setText(" ");
}
} }
void CCampaignScreen::CCampaignButton::show(SDL_Surface * to) void CCampaignScreen::CCampaignButton::show(SDL_Surface * to)
@ -4198,7 +4204,7 @@ CCampaignScreen::CCampaignScreen(const JsonNode &config)
if (!config["exitbutton"].isNull()) if (!config["exitbutton"].isNull())
{ {
back = createExitButton(config["exitbutton"]); CButton * back = createExitButton(config["exitbutton"]);
back->hoverable = true; back->hoverable = true;
} }

View File

@ -129,7 +129,6 @@ class InfoCard : public CIntObject
std::shared_ptr<CAnimation> sFlags; std::shared_ptr<CAnimation> sFlags;
public: public:
CPicture *bg; CPicture *bg;
CMenuScreen::EState type;
bool network; bool network;
bool chatOn; //if chat is shown, then description is hidden bool chatOn; //if chat is shown, then description is hidden
@ -554,9 +553,6 @@ private:
class CCampaignButton : public CIntObject class CCampaignButton : public CIntObject
{ {
private: private:
CPicture *image;
CPicture *checkMark;
CLabel *hoverLabel; CLabel *hoverLabel;
CampaignStatus status; CampaignStatus status;
@ -572,7 +568,6 @@ private:
void show(SDL_Surface * to) override; void show(SDL_Surface * to) override;
}; };
CButton *back;
std::vector<CCampaignButton*> campButtons; std::vector<CCampaignButton*> campButtons;
std::vector<CPicture*> images; std::vector<CPicture*> images;

View File

@ -49,13 +49,20 @@ static si64 lodSeek(void * opaque, si64 pos, int whence)
CVideoPlayer::CVideoPlayer() CVideoPlayer::CVideoPlayer()
{ {
stream = -1;
format = nullptr; format = nullptr;
frame = nullptr; codecContext = nullptr;
codec = nullptr; codec = nullptr;
frame = nullptr;
sws = nullptr; sws = nullptr;
context = nullptr;
texture = nullptr; texture = nullptr;
dest = nullptr; dest = nullptr;
context = nullptr; destRect = genRect(0,0,0,0);
pos = genRect(0,0,0,0);
refreshWait = 0;
refreshCount = 0;
doLoop = false;
// Register codecs. TODO: May be overkill. Should call a // Register codecs. TODO: May be overkill. Should call a
// combination of av_register_input_format() / // combination of av_register_input_format() /
@ -143,17 +150,17 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
} }
// Allocate video frame // Allocate video frame
frame = av_frame_alloc(); frame = av_frame_alloc();
//setup scaling //setup scaling
if(scale) if(scale)
{ {
pos.w = screen->w; pos.w = screen->w;
pos.h = screen->h; pos.h = screen->h;
} }
else else
{ {
pos.w = codecContext->width; pos.w = codecContext->width;
pos.h = codecContext->height; pos.h = codecContext->height;
} }
// Allocate a place to put our YUV image on that screen // Allocate a place to put our YUV image on that screen
@ -174,7 +181,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
if (texture) if (texture)
{ // Convert the image into YUV format that SDL uses { // Convert the image into YUV format that SDL uses
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt, sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
pos.w, pos.h, pos.w, pos.h,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P,
SWS_BICUBIC, nullptr, nullptr, nullptr); SWS_BICUBIC, nullptr, nullptr, nullptr);
@ -205,8 +212,8 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
} }
} }
sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt, sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt,
pos.w, pos.h, screenFormat, pos.w, pos.h, screenFormat,
SWS_BICUBIC, nullptr, nullptr, nullptr); SWS_BICUBIC, nullptr, nullptr, nullptr);
} }
@ -357,7 +364,7 @@ void CVideoPlayer::close()
if (frame) if (frame)
{ {
av_frame_free(&frame);//will be set to null av_frame_free(&frame);//will be set to null
} }
if (codec) if (codec)

View File

@ -133,13 +133,13 @@ bool CAttackAnimation::checkInitialConditions()
} }
CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender) CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attacker, BattleHex _dest, const CStack *defender)
: CBattleStackAnimation(_owner, attacker), : CBattleStackAnimation(_owner, attacker),
soundPlayed(false), shooting(false), group(CCreatureAnim::SHOOT_FRONT),
dest(_dest), attackedStack(defender), attackingStack(attacker) soundPlayed(false),
dest(_dest), attackedStack(defender), attackingStack(attacker)
{ {
assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n"); assert(attackingStack && "attackingStack is nullptr in CBattleAttack::CBattleAttack !\n");
bool isCatapultAttack = attackingStack->hasBonusOfType(Bonus::CATAPULT) bool isCatapultAttack = attackingStack->hasBonusOfType(Bonus::CATAPULT)
&& owner->getCurrentPlayerInterface()->cb->battleHexToWallPart(_dest) >= 0; && owner->getCurrentPlayerInterface()->cb->battleHexToWallPart(_dest) >= 0;
assert(attackedStack || isCatapultAttack); assert(attackedStack || isCatapultAttack);
@ -150,7 +150,7 @@ CAttackAnimation::CAttackAnimation(CBattleInterface *_owner, const CStack *attac
CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner) CDefenceAnimation::CDefenceAnimation(StackAttackedInfo _attackedInfo, CBattleInterface * _owner)
: CBattleStackAnimation(_owner, _attackedInfo.defender), : CBattleStackAnimation(_owner, _attackedInfo.defender),
attacker(_attackedInfo.attacker), rangedAttack(_attackedInfo.indirectAttack), attacker(_attackedInfo.attacker), rangedAttack(_attackedInfo.indirectAttack),
killed(_attackedInfo.killed) killed(_attackedInfo.killed), timeToWait(0)
{ {
logAnim->debugStream() << "Created defence anim for " << _attackedInfo.defender->getName(); logAnim->debugStream() << "Created defence anim for " << _attackedInfo.defender->getName();
} }
@ -198,7 +198,7 @@ bool CDefenceAnimation::init()
//unit reversed //unit reversed
if(rangedAttack) //delay hit animation if(rangedAttack) //delay hit animation
{ {
for(std::list<ProjectileInfo>::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it) for(std::list<ProjectileInfo>::const_iterator it = owner->projectiles.begin(); it != owner->projectiles.end(); ++it)
{ {
if(it->creID == attacker->getCreature()->idNumber) if(it->creID == attacker->getCreature()->idNumber)
@ -243,7 +243,7 @@ CCreatureAnim::EAnimType CDefenceAnimation::getMyAnimType()
{ {
if(killed) if(killed)
return CCreatureAnim::DEATH; return CCreatureAnim::DEATH;
if (vstd::contains(stack->state, EBattleStackState::DEFENDING_ANIM)) if (vstd::contains(stack->state, EBattleStackState::DEFENDING_ANIM))
return CCreatureAnim::DEFENCE; return CCreatureAnim::DEFENCE;
@ -281,7 +281,7 @@ void CDefenceAnimation::endAnim()
delete this; delete this;
} }
CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames) CDummyAnimation::CDummyAnimation(CBattleInterface * _owner, int howManyFrames)
: CBattleAnimation(_owner), counter(0), howMany(howManyFrames) : CBattleAnimation(_owner), counter(0), howMany(howManyFrames)
{ {
logAnim->debugStream() << "Created dummy animation for " << howManyFrames <<" frames"; logAnim->debugStream() << "Created dummy animation for " << howManyFrames <<" frames";
@ -314,7 +314,7 @@ bool CMeleeAttackAnimation::init()
if(!attackingStack || myAnim->isDead()) if(!attackingStack || myAnim->isDead())
{ {
endAnim(); endAnim();
return false; return false;
} }
@ -370,7 +370,7 @@ bool CMeleeAttackAnimation::init()
} }
CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked) CMeleeAttackAnimation::CMeleeAttackAnimation(CBattleInterface * _owner, const CStack * attacker, BattleHex _dest, const CStack * _attacked)
: CAttackAnimation(_owner, attacker, _dest, _attacked) : CAttackAnimation(_owner, attacker, _dest, _attacked)
{ {
logAnim->debugStream() << "Created melee attack anim for " << attacker->getName(); logAnim->debugStream() << "Created melee attack anim for " << attacker->getName();
} }
@ -534,7 +534,7 @@ CMovementAnimation::CMovementAnimation(CBattleInterface *_owner, const CStack *_
} }
CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile) CMovementEndAnimation::CMovementEndAnimation(CBattleInterface * _owner, const CStack * _stack, BattleHex destTile)
: CBattleStackAnimation(_owner, _stack), destinationTile(destTile) : CBattleStackAnimation(_owner, _stack), destinationTile(destTile)
{ {
logAnim->debugStream() << "Created movement end anim for " << stack->getName(); logAnim->debugStream() << "Created movement end anim for " << stack->getName();
} }
@ -573,7 +573,7 @@ void CMovementEndAnimation::endAnim()
} }
CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack) CMovementStartAnimation::CMovementStartAnimation(CBattleInterface * _owner, const CStack * _stack)
: CBattleStackAnimation(_owner, _stack) : CBattleStackAnimation(_owner, _stack)
{ {
logAnim->debugStream() << "Created movement start anim for " << stack->getName(); logAnim->debugStream() << "Created movement start anim for " << stack->getName();
} }
@ -776,7 +776,7 @@ bool CShootingAnimation::init()
spi.dx = (destPos.x - spi.x) / spi.lastStep; spi.dx = (destPos.x - spi.x) / spi.lastStep;
spi.dy = (destPos.y - spi.y) / spi.lastStep; spi.dy = (destPos.y - spi.y) / spi.lastStep;
} }
else else
{ {
// Catapult attack // Catapult attack
spi.catapultInfo.reset(new CatapultProjectileInfo(Point(spi.x, spi.y), destPos)); spi.catapultInfo.reset(new CatapultProjectileInfo(Point(spi.x, spi.y), destPos));
@ -885,7 +885,7 @@ CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::str
CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip, bool _alignToBottom) CSpellEffectAnimation::CSpellEffectAnimation(CBattleInterface * _owner, std::string _customAnim, BattleHex _destTile, bool _Vflip, bool _alignToBottom)
:CBattleAnimation(_owner), effect(-1), destTile(_destTile), customAnim(_customAnim), x(-1), y(-1), dx(0), dy(0), Vflip(_Vflip), alignToBottom(_alignToBottom) :CBattleAnimation(_owner), effect(-1), destTile(_destTile), customAnim(_customAnim), x(-1), y(-1), dx(0), dy(0), Vflip(_Vflip), alignToBottom(_alignToBottom)
{ {
logAnim->debugStream() << "Created spell anim for " << customAnim; logAnim->debugStream() << "Created spell anim for " << customAnim;
} }
@ -893,21 +893,21 @@ bool CSpellEffectAnimation::init()
{ {
if(!isEarliest(true)) if(!isEarliest(true))
return false; return false;
if(customAnim.empty() && effect != ui32(-1) && !graphics->battleACToDef[effect].empty()) if(customAnim.empty() && effect != ui32(-1) && !graphics->battleACToDef[effect].empty())
{ {
customAnim = graphics->battleACToDef[effect][0]; customAnim = graphics->battleACToDef[effect][0];
} }
if(customAnim.empty()) if(customAnim.empty())
{ {
endAnim(); endAnim();
return false; return false;
} }
const bool areaEffect = (!destTile.isValid() && x == -1 && y == -1); const bool areaEffect = (!destTile.isValid() && x == -1 && y == -1);
if(areaEffect) //f.e. armageddon if(areaEffect) //f.e. armageddon
{ {
CDefHandler * anim = CDefHandler::giveDef(customAnim); CDefHandler * anim = CDefHandler::giveDef(customAnim);
@ -934,7 +934,7 @@ bool CSpellEffectAnimation::init()
owner->battleEffects.push_back(be); owner->battleEffects.push_back(be);
} }
} }
delete anim; delete anim;
} }
else // Effects targeted at a specific creature/hex. else // Effects targeted at a specific creature/hex.
@ -956,9 +956,9 @@ bool CSpellEffectAnimation::init()
be.currentFrame = 0; be.currentFrame = 0;
be.maxFrame = be.anim->ourImages.size(); be.maxFrame = be.anim->ourImages.size();
//todo: lightning anim frame count override //todo: lightning anim frame count override
// if(effect == 1) // if(effect == 1)
// be.maxFrame = 3; // be.maxFrame = 3;
@ -970,7 +970,7 @@ bool CSpellEffectAnimation::init()
{ {
be.x = x; be.x = x;
} }
if(y == -1) if(y == -1)
{ {
if(alignToBottom) if(alignToBottom)
@ -993,7 +993,7 @@ bool CSpellEffectAnimation::init()
owner->battleEffects.push_back(be); owner->battleEffects.push_back(be);
} }
//battleEffects //battleEffects
return true; return true;
} }

View File

@ -1557,8 +1557,7 @@ bool CFadeAnimation::isFinished() const
} }
CFadeAnimation::CFadeAnimation() CFadeAnimation::CFadeAnimation()
: fadingSurface(nullptr), : delta(0), fadingSurface(nullptr), fading(false), fadingCounter(0), shouldFreeSurface(false),
fading(false),
fadingMode(EMode::NONE) fadingMode(EMode::NONE)
{ {
} }

View File

@ -170,15 +170,15 @@ void CGuiHandler::updateTime()
void CGuiHandler::handleEvents() void CGuiHandler::handleEvents()
{ {
//player interface may want special event handling //player interface may want special event handling
if(nullptr != LOCPLINT && LOCPLINT->capturedAllEvents()) if(nullptr != LOCPLINT && LOCPLINT->capturedAllEvents())
return; return;
boost::unique_lock<boost::mutex> lock(eventsM); boost::unique_lock<boost::mutex> lock(eventsM);
while(!events.empty()) while(!events.empty())
{ {
SDL_Event ev = events.front(); SDL_Event ev = events.front();
events.pop(); events.pop();
this->handleEvent(&ev); this->handleEvent(&ev);
} }
} }
@ -286,14 +286,14 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
{ {
it->textInputed(sEvent->text); it->textInputed(sEvent->text);
} }
} }
else if(sEvent->type == SDL_TEXTEDITING) else if(sEvent->type == SDL_TEXTEDITING)
{ {
for(auto it : textInterested) for(auto it : textInterested)
{ {
it->textEdited(sEvent->edit); it->textEdited(sEvent->edit);
} }
} }
//todo: muiltitouch //todo: muiltitouch
else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT)) else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
{ {
@ -398,9 +398,9 @@ void CGuiHandler::renderFrame()
// Updating GUI requires locking pim mutex (that protects screen and GUI state). // Updating GUI requires locking pim mutex (that protects screen and GUI state).
// During game: // During game:
// When ending the game, the pim mutex might be hold by other thread, // When ending the game, the pim mutex might be hold by other thread,
// that will notify us about the ending game by setting terminate_cond flag. // that will notify us about the ending game by setting terminate_cond flag.
//in PreGame terminate_cond stay false //in PreGame terminate_cond stay false
bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
while(!terminate_cond.get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate while(!terminate_cond.get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
boost::this_thread::sleep(boost::posix_time::milliseconds(15)); boost::this_thread::sleep(boost::posix_time::milliseconds(15));
@ -412,25 +412,25 @@ void CGuiHandler::renderFrame()
if(nullptr != curInt) if(nullptr != curInt)
curInt->update(); curInt->update();
if (settings["general"]["showfps"].Bool()) if (settings["general"]["showfps"].Bool())
drawFPSCounter(); drawFPSCounter();
// draw the mouse cursor and update the screen // draw the mouse cursor and update the screen
CCS->curh->render(); CCS->curh->render();
if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr)) if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr))
logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError(); logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError();
SDL_RenderPresent(mainRenderer); SDL_RenderPresent(mainRenderer);
} }
mainFPSmng->framerateDelay(); // holds a constant FPS mainFPSmng->framerateDelay(); // holds a constant FPS
} }
CGuiHandler::CGuiHandler() CGuiHandler::CGuiHandler()
:lastClick(-500, -500) : lastClick(-500, -500),lastClickTime(0), defActionsDef(0), captureChildren(false)
{ {
curInt = nullptr; curInt = nullptr;
current = nullptr; current = nullptr;
@ -439,7 +439,7 @@ CGuiHandler::CGuiHandler()
// Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate // Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate
mainFPSmng = new CFramerateManager(48); mainFPSmng = new CFramerateManager(48);
//do not init CFramerateManager here --AVS //do not init CFramerateManager here --AVS
terminate_cond.set(false); terminate_cond.set(false);
} }
@ -477,7 +477,7 @@ SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key)
return SDLK_KP_6; return SDLK_KP_6;
default: default:
throw std::runtime_error("Wrong key!"); throw std::runtime_error("Wrong key!");
} }
} }
SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key) SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
@ -495,7 +495,7 @@ SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
REMOVE_KP(6) REMOVE_KP(6)
REMOVE_KP(7) REMOVE_KP(7)
REMOVE_KP(8) REMOVE_KP(8)
REMOVE_KP(9) REMOVE_KP(9)
REMOVE_KP(PERIOD) REMOVE_KP(PERIOD)
REMOVE_KP(MINUS) REMOVE_KP(MINUS)
REMOVE_KP(PLUS) REMOVE_KP(PLUS)
@ -546,6 +546,8 @@ CFramerateManager::CFramerateManager(int rate)
this->fps = 0; this->fps = 0;
this->accumulatedFrames = 0; this->accumulatedFrames = 0;
this->accumulatedTime = 0; this->accumulatedTime = 0;
this->lastticks = 0;
this->timeElapsed = 0;
} }
void CFramerateManager::init() void CFramerateManager::init()
@ -557,23 +559,23 @@ void CFramerateManager::framerateDelay()
{ {
ui32 currentTicks = SDL_GetTicks(); ui32 currentTicks = SDL_GetTicks();
timeElapsed = currentTicks - lastticks; timeElapsed = currentTicks - lastticks;
// FPS is higher than it should be, then wait some time // FPS is higher than it should be, then wait some time
if (timeElapsed < rateticks) if (timeElapsed < rateticks)
{ {
SDL_Delay(ceil(this->rateticks) - timeElapsed); SDL_Delay(ceil(this->rateticks) - timeElapsed);
} }
accumulatedTime += timeElapsed; accumulatedTime += timeElapsed;
accumulatedFrames++; accumulatedFrames++;
if(accumulatedFrames >= 100) if(accumulatedFrames >= 100)
{ {
//about 2 second should be passed //about 2 second should be passed
fps = ceil(1000.0 / (accumulatedTime/accumulatedFrames)); fps = ceil(1000.0 / (accumulatedTime/accumulatedFrames));
accumulatedTime = 0; accumulatedTime = 0;
accumulatedFrames = 0; accumulatedFrames = 0;
}; };
currentTicks = SDL_GetTicks(); currentTicks = SDL_GetTicks();
// recalculate timeElapsed for external calls via getElapsed() // recalculate timeElapsed for external calls via getElapsed()

View File

@ -49,11 +49,11 @@ public:
private: private:
typedef std::list<CIntObject*> CIntObjectList; typedef std::list<CIntObject*> CIntObjectList;
//active GUI elements (listening for events //active GUI elements (listening for events
CIntObjectList lclickable, CIntObjectList lclickable,
rclickable, rclickable,
hoverable, hoverable,
keyinterested, keyinterested,
motioninterested, motioninterested,
timeinterested, timeinterested,
@ -61,12 +61,12 @@ private:
doubleClickInterested, doubleClickInterested,
textInterested; textInterested;
void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb); void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);
public: public:
void handleElementActivate(CIntObject * elem, ui16 activityFlag); void handleElementActivate(CIntObject * elem, ui16 activityFlag);
void handleElementDeActivate(CIntObject * elem, ui16 activityFlag); void handleElementDeActivate(CIntObject * elem, ui16 activityFlag);
public: public:
//objs to blit //objs to blit
std::vector<IShowable*> objsToBlit; std::vector<IShowable*> objsToBlit;
@ -77,9 +77,13 @@ public:
Point lastClick; Point lastClick;
unsigned lastClickTime; unsigned lastClickTime;
ui8 defActionsDef; //default auto actions
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
std::list<CIntObject *> createdObj; //stack of objs being created
CGuiHandler(); CGuiHandler();
~CGuiHandler(); ~CGuiHandler();
void renderFrame(); void renderFrame();
void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering void totalRedraw(); //forces total redraw (using showAll), sets a flag, method gets called at the end of the rendering
@ -99,9 +103,6 @@ public:
void fakeMouseMove(); void fakeMouseMove();
void breakEventHandling(); //current event won't be propagated anymore void breakEventHandling(); //current event won't be propagated anymore
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
ui8 defActionsDef; //default auto actions
ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
std::list<CIntObject *> createdObj; //stack of objs being created
static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key
static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key
@ -109,7 +110,7 @@ public:
static bool isArrowKey(SDL_Keycode key); static bool isArrowKey(SDL_Keycode key);
static bool amIGuiThread(); static bool amIGuiThread();
static void pushSDLEvent(int type, int usercode = 0); static void pushSDLEvent(int type, int usercode = 0);
static CondSh<bool> terminate_cond; // confirm termination static CondSh<bool> terminate_cond; // confirm termination
}; };

View File

@ -1377,6 +1377,9 @@ CMapHandler::CMapHandler()
worldViewBlitter = new CMapWorldViewBlitter(this); worldViewBlitter = new CMapWorldViewBlitter(this);
puzzleViewBlitter = new CMapPuzzleViewBlitter(this); puzzleViewBlitter = new CMapPuzzleViewBlitter(this);
fadeAnimCounter = 0; fadeAnimCounter = 0;
map = nullptr;
tilesW = tilesH = 0;
offsetX = offsetY = 0;
egdeAnimation = make_unique<CAnimation>("EDG"); egdeAnimation = make_unique<CAnimation>("EDG");
egdeAnimation->preload(); egdeAnimation->preload();
@ -1413,6 +1416,11 @@ void CMapHandler::discardWorldViewCache()
cache.discardWorldViewCache(); cache.discardWorldViewCache();
} }
CMapHandler::CMapCache::CMapCache()
{
worldViewCachedScale = 0;
}
void CMapHandler::CMapCache::discardWorldViewCache() void CMapHandler::CMapCache::discardWorldViewCache()
{ {
for(auto & cache : data) for(auto & cache : data)

View File

@ -162,6 +162,7 @@ class CMapHandler
std::array< std::map<intptr_t, std::unique_ptr<IImage>>, (ui8)EMapCacheType::AFTER_LAST> data; std::array< std::map<intptr_t, std::unique_ptr<IImage>>, (ui8)EMapCacheType::AFTER_LAST> data;
float worldViewCachedScale; float worldViewCachedScale;
public: public:
CMapCache();
/// destroys all cached data (frees surfaces) /// destroys all cached data (frees surfaces)
void discardWorldViewCache(); void discardWorldViewCache();
/// updates scale and determines if currently cached data is still valid /// updates scale and determines if currently cached data is still valid

View File

@ -199,9 +199,6 @@ class CSlider : public CIntObject
int capacity;//how many elements can be active at same time (e.g. hero list = 5) int capacity;//how many elements can be active at same time (e.g. hero list = 5)
int positions; //number of highest position (0 if there is only one) int positions; //number of highest position (0 if there is only one)
bool horizontal; bool horizontal;
bool wheelScrolling;
bool keyScrolling;
int amount; //total amount of elements (e.g. hero list = 0-8) int amount; //total amount of elements (e.g. hero list = 0-8)
int value; //first active element int value; //first active element
int scrollStep; // how many elements will be scrolled via one click, default = 1 int scrollStep; // how many elements will be scrolled via one click, default = 1

View File

@ -1329,6 +1329,7 @@ bool IPropagator::shouldBeAttached(CBonusSystemNode *dest)
} }
CPropagatorNodeType::CPropagatorNodeType() CPropagatorNodeType::CPropagatorNodeType()
:nodeType(0)
{ {
} }
@ -1349,6 +1350,7 @@ CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter(int TerrainType)
} }
CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter() CreatureNativeTerrainLimiter::CreatureNativeTerrainLimiter()
: terrainType(-1)
{ {
} }
@ -1366,6 +1368,7 @@ CreatureFactionLimiter::CreatureFactionLimiter(int Faction)
} }
CreatureFactionLimiter::CreatureFactionLimiter() CreatureFactionLimiter::CreatureFactionLimiter()
: faction(-1)
{ {
} }
@ -1376,6 +1379,7 @@ int CreatureFactionLimiter::limit(const BonusLimitationContext &context) const
} }
CreatureAlignmentLimiter::CreatureAlignmentLimiter() CreatureAlignmentLimiter::CreatureAlignmentLimiter()
: alignment(-1)
{ {
} }

View File

@ -142,7 +142,7 @@ public:
EBonusType bonusType; EBonusType bonusType;
ui16 bonusID; //ID of skill/spell ui16 bonusID; //ID of skill/spell
CGScholar() : bonusType(EBonusType::RANDOM){}; CGScholar() : bonusType(EBonusType::RANDOM),bonusID(0){};
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void initObj(CRandomGenerator & rand) override; void initObj(CRandomGenerator & rand) override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)