Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code speed up and cleanup #3414

Merged
merged 3 commits into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VisualStudio/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\engine;$(MSBuildThisFileDirectory)..\src\fheroes2\gui;$(MSBuildThisFileDirectory)..\src\fheroes2\maps;$(MSBuildThisFileDirectory)..\src\fheroes2\kingdom;$(MSBuildThisFileDirectory)..\src\fheroes2\campaign;$(MSBuildThisFileDirectory)..\src\fheroes2\game;$(MSBuildThisFileDirectory)..\src\fheroes2\dialog;$(MSBuildThisFileDirectory)..\src\fheroes2\system;$(MSBuildThisFileDirectory)..\src\fheroes2\spell;$(MSBuildThisFileDirectory)..\src\fheroes2\monster;$(MSBuildThisFileDirectory)..\src\fheroes2\castle;$(MSBuildThisFileDirectory)..\src\fheroes2\agg;$(MSBuildThisFileDirectory)..\src\fheroes2\heroes;$(MSBuildThisFileDirectory)..\src\fheroes2\resource;$(MSBuildThisFileDirectory)..\src\fheroes2\ai;$(MSBuildThisFileDirectory)..\src\fheroes2\army;$(MSBuildThisFileDirectory)..\src\fheroes2\battle;$(MSBuildThisFileDirectory)..\src\fheroes2\pocketpc;$(MSBuildThisFileDirectory)..\src\fheroes2\objects;$(MSBuildThisFileDirectory)..\src\fheroes2\world;$(MSBuildThisFileDirectory)..\src\fheroes2\image;$(MSBuildThisFileDirectory)..\src\thirdparty\libsmacker;$(MSBuildThisFileDirectory)packages\installed\zlib\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;WITH_ZLIB;WITH_MIXER;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatSpecificWarningsAsErrors>4018;4100;4189;4309;4319;4389;4592;4715;4800</TreatSpecificWarningsAsErrors>
<TreatSpecificWarningsAsErrors>4018;4100;4189;4309;4319;4389;4592;4702;4715;4800</TreatSpecificWarningsAsErrors>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\src\fheroes2\system;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
Expand Down
6 changes: 3 additions & 3 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,12 +936,12 @@ namespace fheroes2

void Blit( const Image & in, int32_t inX, int32_t inY, Image & out, int32_t outX, int32_t outY, int32_t width, int32_t height, bool flip )
{
if ( !Verify( in, inX, inY, out, outX, outY, width, height ) ) {
if ( in.singleLayer() && out.singleLayer() && !flip ) {
Copy( in, inX, inY, out, outX, outY, width, height );
return;
}

if ( in.singleLayer() && out.singleLayer() && !flip ) {
Copy( in, inX, inY, out, outX, outY, width, height );
if ( !Verify( in, inX, inY, out, outX, outY, width, height ) ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
***************************************************************************/
#pragma once

#include <cstdint>
#include <memory>
#include <stdint.h>
#include <string>
#include <vector>

Expand Down
14 changes: 13 additions & 1 deletion src/engine/localevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,19 @@ LocalEvent & LocalEvent::GetClean()
bool LocalEvent::HandleEvents( bool delay, bool allowExit )
{
if ( colorCycling.isRedrawRequired() ) {
fheroes2::Display::instance().render();
// Looks like there is no explicit rendering so the code for color cycling was executed here.
if ( delay ) {
fheroes2::Time timeCheck;
fheroes2::Display::instance().render();

if ( timeCheck.getMs() > loop_delay ) {
// Since rendering took more than waiting time so we should not wait.
delay = false;
}
}
else {
fheroes2::Display::instance().render();
}
}

SDL_Event event;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/localevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class LocalEvent
void ( *redraw_cursor_func )( s32, s32 );
void ( *keyboard_filter_func )( int, int );

int loop_delay;
uint32_t loop_delay;

// These members are used for restoring music and sounds when an user reopens the window
bool _isHiddenWindow;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/math_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#pragma once

#include <cmath>
#include <stdint.h>
#include <cstdint>

#ifndef M_PI
#define M_PI 3.14159265358979323846
Expand Down
2 changes: 1 addition & 1 deletion src/engine/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef H2PAL_H
#define H2PAL_H

#include <stdint.h>
#include <cstdint>
#include <vector>

namespace PAL
Expand Down
2 changes: 1 addition & 1 deletion src/engine/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void StreamBuf::put8( char v )
u8 StreamBuf::get8()
{
if ( sizeg() )
return static_cast<u8>( 255u ) & *itget++;
return *itget++;
else
return 0u;
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#pragma once

#include <chrono>
#include <stdint.h>
#include <cstdint>

namespace fheroes2
{
Expand Down
1 change: 0 additions & 1 deletion src/engine/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>

#include "logging.h"
Expand Down
7 changes: 7 additions & 0 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,13 @@ namespace fheroes2

return true;
}
case ICN::HEROES:
LoadOriginalICN( id );
if ( !_icnVsSprite[id].empty() ) {
// This is main menu image which doesn't shouldn't have any transform layer.
_icnVsSprite[id][0]._disableTransformLayer();
}
return true;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace AI
{
public:
virtual void KingdomTurn( Kingdom & kingdom );
virtual void CastleTurn( Castle & castle, bool defensive = false );
virtual void CastleTurn( Castle & castle, bool defensive );
virtual void BattleTurn( Battle::Arena & arena, const Battle::Unit & unit, Battle::Actions & actions );
virtual void HeroTurn( Heroes & hero );
virtual void HeroesTurn( VecHeroes & ) {}
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/ai_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ namespace AI
// castles AI turn
for ( KingdomCastles::iterator it = castles.begin(); it != castles.end(); ++it )
if ( *it )
CastleTurn( **it );
CastleTurn( **it, false );

status.RedrawTurnProgress( 3 );

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/ai/normal/ai_normal.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace AI
public:
Normal();
void KingdomTurn( Kingdom & kingdom ) override;
void CastleTurn( Castle & castle, bool defensive = false ) override;
void CastleTurn( Castle & castle, bool defensive ) override;
void BattleTurn( Battle::Arena & arena, const Battle::Unit & currentUnit, Battle::Actions & actions ) override;
void HeroesTurn( VecHeroes & heroes ) override;

Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/army/army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
***************************************************************************/

#include <algorithm>
#include <cmath>
#include <functional>
#include <math.h>
#include <set>

#include "agg_image.h"
Expand Down Expand Up @@ -1561,7 +1561,7 @@ Monster Army::GetStrongestMonster() const
Monster monster( Monster::UNKNOWN );
for ( const Troop * troop : *this ) {
if ( troop->isValid() && troop->GetMonster().GetMonsterStrength() > monster.GetMonsterStrength() ) {
monster = *troop;
monster = troop->GetID();
}
}
return monster;
Expand Down
3 changes: 3 additions & 0 deletions src/fheroes2/battle/battle_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,9 @@ Battle::Interface::Interface( Arena & a, s32 center )
, teleport_src( -1 )
, listlog( NULL )
{
// Since this surface is going to be copied directly on screen it shouldn't have any transform layer.
_mainSurface._disableTransformLayer();

const Settings & conf = Settings::Get();

Cursor::Get().Hide();
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/dialog/dialog_thievesguild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void DrawHeroStats( const std::vector<ValueColors> & v, const fheroes2::Point &
}
}

void DrawPersonality( const Colors & colors, fheroes2::Point & pos, int step )
void DrawPersonality( const Colors & colors, const fheroes2::Point & pos, int step )
{
for ( size_t i = 0; i < colors.size(); ++i ) {
const Player * player = Players::Get( colors[i] );
Expand All @@ -269,7 +269,7 @@ void DrawPersonality( const Colors & colors, fheroes2::Point & pos, int step )
}
}

void DrawBestMonsterIcons( const Colors & colors, fheroes2::Point & pos, int step )
void DrawBestMonsterIcons( const Colors & colors, const fheroes2::Point & pos, int step )
{
for ( size_t i = 0; i < colors.size(); ++i ) {
const Monster monster = world.GetKingdom( colors[i] ).GetStrongestMonster();
Expand Down
3 changes: 1 addition & 2 deletions src/fheroes2/game/fheroes2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ int main( int argc, char ** argv )

SDL_ShowCursor( SDL_DISABLE ); // hide system cursor

// Ensure the mouse position is updated to prevent bad initial values.
// Initialize local event processing.
LocalEvent::Get().RegisterCycling( fheroes2::PreRenderSystemInfo, fheroes2::PostRenderSystemInfo );
LocalEvent::Get().GetMouseCursor();

// Update mouse cursor when switching between software emulation and OS mouse modes.
fheroes2::cursor().registerUpdater( Cursor::Refresh );
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/game/game_delays.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef H2GAME_DELAYS_H
#define H2GAME_DELAYS_H

#include <stdint.h>
#include <cstdint>
#include <vector>

namespace Game
Expand Down
4 changes: 3 additions & 1 deletion src/fheroes2/game/game_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ namespace Game
IS_LOYALTY = 0x4000
};

HeaderSAV( const int saveFileVersion )
HeaderSAV() = delete;

explicit HeaderSAV( const int saveFileVersion )
: status( 0 )
, gameType( 0 )
, _saveFileVersion( saveFileVersion )
Expand Down
4 changes: 0 additions & 4 deletions src/fheroes2/game/game_startgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include <cassert>
#include <vector>

#ifdef AI
#undef AI
#endif

#include "agg.h"
#include "agg_image.h"
#include "ai.h"
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/gui/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool Cursor::SetThemes( int name, bool force )
fheroes2::cursor().update( spr, -offset_x, -offset_y );

// immediately apply new offset, force
const fheroes2::Point currentPos = LocalEvent::Get().GetMouseCursor();
const fheroes2::Point & currentPos = LocalEvent::Get().GetMouseCursor();
Move( currentPos.x, currentPos.y );
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/gui/interface_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Interface::Basic::CalculateHeroPath( Heroes * hero, s32 destinationIdx ) co
gameArea.SetRedraw();

LocalEvent & le = LocalEvent::Get();
const fheroes2::Point mousePos = le.GetMouseCursor();
const fheroes2::Point & mousePos = le.GetMouseCursor();
if ( gameArea.GetROI() & mousePos ) {
const int32_t cursorIndex = gameArea.GetValidTileIdFromPoint( mousePos );
Cursor::Get().SetThemes( GetCursorTileIndex( cursorIndex ) );
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/image/embedded_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#ifdef WITH_ZLIB

#include <stdint.h>
#include <cstdint>

const uint8_t errorMessage[]
= { 0x78, 0x9c, 0xed, 0x9d, 0x0d, 0x7a, 0xa4, 0x38, 0x92, 0x86, 0x4f, 0xb2, 0xdd, 0x4e, 0x5f, 0x61, 0x0b, 0x04, 0x02, 0xdf, 0xa9, 0x0d, 0xcb, 0x8f, 0x40, 0xc2, 0xd3,
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/kingdom/kingdom_overview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct HeroRow
class StatsHeroesList : public Interface::ListBox<HeroRow>
{
public:
StatsHeroesList( const fheroes2::Point & pt, KingdomHeroes & );
StatsHeroesList( const fheroes2::Point & pt, const KingdomHeroes & );

bool Refresh( KingdomHeroes & heroes );

Expand All @@ -118,7 +118,7 @@ class StatsHeroesList : public Interface::ListBox<HeroRow>
void SetContent( const KingdomHeroes & heroes );
};

StatsHeroesList::StatsHeroesList( const fheroes2::Point & pt, KingdomHeroes & heroes )
StatsHeroesList::StatsHeroesList( const fheroes2::Point & pt, const KingdomHeroes & heroes )
: Interface::ListBox<HeroRow>( pt )
{
const fheroes2::Sprite & back = fheroes2::AGG::GetICN( ICN::OVERVIEW, 13 );
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/kingdom/view_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ void ViewWorld::ViewWorldWindow( const int color, const ViewWorldMode mode, Inte
}
else if ( le.MousePressLeft( visibleScreenInPixels ) ) {
if ( isDrag ) {
const fheroes2::Point newMousePos = le.GetMouseCursor();
const fheroes2::Point & newMousePos = le.GetMouseCursor();
const fheroes2::Point
newRoiCenter( initRoiCenter.x - ( newMousePos.x - initMousePos.x ) * TILEWIDTH / tileSizePerZoomLevel[static_cast<int>( currentROI._zoomLevel )],
initRoiCenter.y - ( newMousePos.y - initMousePos.y ) * TILEWIDTH / tileSizePerZoomLevel[static_cast<int>( currentROI._zoomLevel )] );
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/monster/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/

#include <math.h>
#include <cmath>

#include "castle.h"
#include "difficulty.h"
Expand Down
4 changes: 1 addition & 3 deletions src/fheroes2/system/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ class Settings
// UNUSED = 0x40008000,
BATTLE_SOFT_WAITING = 0x40010000,
BATTLE_REVERSE_WAIT_ORDER = 0x40020000,
BATTLE_SKIP_INCREASE_DEFENSE = 0x40200000,

SETTINGS_LAST
BATTLE_SKIP_INCREASE_DEFENSE = 0x40200000
};

Settings( const Settings & ) = delete;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/bin2txt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ int main( int argc, char ** argv )
for ( size_t frameId = 0; frameId < 16; ++frameId ) {
const int frameValue = static_cast<int>( data[5 + setId * 16 + frameId] );
if ( frameValue < 10 )
file << " " << static_cast<int>( frameValue ) << " ";
file << " " << frameValue << " ";
else
file << static_cast<int>( frameValue ) << " ";
file << frameValue << " ";
}
file << "\n";
}
Expand Down