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

Remove old Rect, Point and Size classes #3316

Merged
merged 14 commits into from
May 4, 2021
Prev Previous commit
Next Next commit
Code speed up
  • Loading branch information
ihhub committed May 3, 2021
commit 456db6929f95abe760d5713b877ec5c5e8f19321
7 changes: 4 additions & 3 deletions src/fheroes2/gui/interface_gamearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void Interface::GameArea::DrawTile( fheroes2::Image & dst, const fheroes2::Image

void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzleDraw ) const
{
const fheroes2::Rect tileROI = GetVisibleTileROI();
const fheroes2::Rect & tileROI = GetVisibleTileROI();

int32_t minX = tileROI.x;
int32_t minY = tileROI.y;
Expand Down Expand Up @@ -194,8 +194,9 @@ void Interface::GameArea::Redraw( fheroes2::Image & dst, int flag, bool isPuzzle
std::vector<const Maps::Tiles *> topList;
std::vector<const Maps::Tiles *> objectList;

topList.reserve( ( maxY - minY ) * ( maxX - minX ) );
objectList.reserve( ( maxY - minY ) * ( maxX - minX ) );
const int32_t areaSize = ( maxY - minY ) * ( maxX - minX );
topList.reserve( areaSize );
objectList.reserve( areaSize );

// Bottom layer and objects.
const bool drawBottom = ( flag & LEVEL_BOTTOM ) == LEVEL_BOTTOM;
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/maps/maps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ bool Maps::isValidDirection( s32 from, int vector )
return false;
}

fheroes2::Point Maps::GetPoint( int32_t index )
fheroes2::Point Maps::GetPoint( const int32_t index )
{
return fheroes2::Point( index % world.w(), index / world.w() );
}
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/maps/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Maps
bool isValidAbsIndex( s32 );
bool isValidAbsPoint( s32 x, s32 y );

fheroes2::Point GetPoint( s32 );
fheroes2::Point GetPoint( const int32_t index );

s32 GetIndexFromAbsPoint( const fheroes2::Point & mp );
s32 GetIndexFromAbsPoint( s32 px, s32 py );
Expand Down
145 changes: 72 additions & 73 deletions src/fheroes2/maps/maps_tiles.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/fheroes2/maps/maps_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ namespace Maps

int32_t GetIndex() const
{
return maps_index;
return _index;
}

fheroes2::Point GetCenter( void ) const;
Expand Down Expand Up @@ -183,7 +183,7 @@ namespace Maps

void SetIndex( const uint32_t index )
{
maps_index = index;
_index = index;
}

void setBoat( int direction );
Expand Down Expand Up @@ -323,7 +323,7 @@ namespace Maps
Addons addons_level1;
Addons addons_level2; // 16

uint32_t maps_index = 0;
int32_t _index = 0;
uint16_t pack_sprite_index = 0;

uint32_t uniq = 0;
Expand Down
16 changes: 12 additions & 4 deletions src/fheroes2/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,22 @@ void World::InitKingdoms( void )
vec_kingdoms.Init();
}

const Maps::Tiles & World::GetTiles( u32 ax, u32 ay ) const
const Maps::Tiles & World::GetTiles( const int32_t x, const int32_t y ) const
{
return GetTiles( ay * w() + ax );
#ifdef WITH_DEBUG
return vec_tiles.at( y * width + x );
#else
return vec_tiles[y * width + x];
#endif
}

Maps::Tiles & World::GetTiles( u32 ax, u32 ay )
Maps::Tiles & World::GetTiles( const int32_t x, const int32_t y )
{
return GetTiles( ay * w() + ax );
#ifdef WITH_DEBUG
return vec_tiles.at( y * width + x );
#else
return vec_tiles[y * width + x];
#endif
}

const Maps::Tiles & World::GetTiles( const int32_t tileId ) const
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/world/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ class World : protected fheroes2::Size
return height;
}

const Maps::Tiles & GetTiles( u32, u32 ) const;
Maps::Tiles & GetTiles( u32, u32 );
const Maps::Tiles & GetTiles( const int32_t x, const int32_t y ) const;
Maps::Tiles & GetTiles( const int32_t x, const int32_t y );
const Maps::Tiles & GetTiles( const int32_t tileId ) const;
Maps::Tiles & GetTiles( const int32_t tileId );

Expand Down