Skip to content

Commit

Permalink
Standard Resharper formatting. Makes code a bit more spacious and eas…
Browse files Browse the repository at this point in the history
…ier to read.
  • Loading branch information
ciplogic committed Sep 8, 2018
1 parent 1db4f46 commit e04beeb
Show file tree
Hide file tree
Showing 48 changed files with 478 additions and 410 deletions.
4 changes: 2 additions & 2 deletions src/engine/IMG_savepng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int IMG_SavePNG_RW(SDL_RWops* src, SDL_Surface* surf, int compression)
png_colorp palette = nullptr;
int ret = -1;
int funky_format = 0;
SDL_PixelFormat* fmt{};
SDL_PixelFormat* fmt{};

if (!src || !surf)
{
Expand Down Expand Up @@ -245,7 +245,7 @@ int IMG_SavePNG_RW(SDL_RWops* src, SDL_Surface* surf, int compression)
0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
#else
auto* tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
#endif
if (!tempsurf)
{
Expand Down
28 changes: 14 additions & 14 deletions src/engine/TimeUtills.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

namespace time_utils
{
unsigned long long GetTickCount()
{
using namespace std::chrono;
return duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count();
}
unsigned long long GetTickCount()
{
using namespace std::chrono;
return duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count();
}

void TimeAction(const std::string& message, std::function<void()>& runAction)
{
const auto startTime = GetTickCount();
runAction();
const auto endTime = GetTickCount();
const auto delta = endTime - startTime;
Message("", message + ": " + to_string(delta), Font::BIG, Dialog::YES);
}
}
void TimeAction(const std::string& message, std::function<void()>& runAction)
{
const auto startTime = GetTickCount();
runAction();
const auto endTime = GetTickCount();
const auto delta = endTime - startTime;
Message("", message + ": " + to_string(delta), Font::BIG, Dialog::YES);
}
}
8 changes: 4 additions & 4 deletions src/engine/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Size Display::GetMaxMode(bool rotate) const
modes == (SDL_Rect **)-1)
{
H2ERROR("GetMaxMode: " << "no modes available");
return {};
return {};
}
int max = 0;
int cur = 0;
Expand All @@ -126,9 +126,9 @@ Size Display::GetMaxMode(bool rotate) const
}
}

Size result;
if (!modes[cur])
return {};
Size result;
if (!modes[cur])
return {};
result.w = modes[cur]->w;
result.h = modes[cur]->h;

Expand Down
2 changes: 1 addition & 1 deletion src/engine/sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Point& SpritePos::GetPos() const

Rect SpritePos::GetArea() const
{
return { GetPos(), GetSize() };
return {GetPos(), GetSize()};
}

void SpritePos::SetSurface(const Surface& sf)
Expand Down
2 changes: 1 addition & 1 deletion src/engine/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ std::string System::GetTime()
char buf[13] = {0};

time(&raw);
struct tm * tmi = localtime(&raw);
struct tm* tmi = localtime(&raw);

strftime(buf, sizeof buf - 1, "%X", tmi);

Expand Down
8 changes: 5 additions & 3 deletions src/engine/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
#include "translations.h"

using namespace std;

std::string _(const std::string& text)
{
return Translation::gettext(text);
return Translation::gettext(text);
}
std::string _n(const std::string &str, const std::string &plural, size_t n)

std::string _n(const std::string& str, const std::string& plural, size_t n)
{
return Translation::ngettext(str.c_str(), plural.c_str(), n);
return Translation::ngettext(str.c_str(), plural.c_str(), n);
}

namespace ModernTranslation
Expand Down
34 changes: 18 additions & 16 deletions src/engine/xmi2mid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pack_t unpackValue(const u8* ptr)

struct meta_t
{
meta_t()
meta_t()
{
}

Expand Down Expand Up @@ -145,7 +145,7 @@ struct IFFChunkHeader
{
}

IFFChunkHeader() = default;
IFFChunkHeader() = default;
};


Expand Down Expand Up @@ -173,7 +173,7 @@ struct GroupChunkHeader
{
}

GroupChunkHeader() = default;
GroupChunkHeader() = default;
};

ByteVectorWriter& operator<<(ByteVectorWriter& sb, const GroupChunkHeader& st)
Expand Down Expand Up @@ -296,7 +296,7 @@ struct XMIData
struct MidEvent
{
vector<u8> pack;
std::array<u8,4> data; // status, data1, data2, count
std::array<u8, 4> data; // status, data1, data2, count
//char status;
//std::vector<u8> data;

Expand Down Expand Up @@ -338,12 +338,13 @@ ByteVectorWriter& operator<<(ByteVectorWriter& sb, const MidEvent& st)
return sb;
}

struct MidEvents
struct MidEvents
{
vector<MidEvent> _items;
vector<MidEvent> _items;

size_t count() const
{
return _items.size();
return _items.size();
}

size_t size() const
Expand Down Expand Up @@ -382,7 +383,7 @@ struct MidEvents
if ((*it1).duration <= delta)
{
// note off
_items.emplace_back((*it1).duration - delta2, (*it1).command, (*it1).quantity, 0x7F);
_items.emplace_back((*it1).duration - delta2, (*it1).command, (*it1).quantity, 0x7F);
delta2 += (*it1).duration - delta2;
}
}
Expand Down Expand Up @@ -411,7 +412,7 @@ struct MidEvents
// end
if (0xFF == *ptr && 0x2F == *(ptr + 1))
{
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
break;
}
switch (*ptr >> 4)
Expand All @@ -432,7 +433,7 @@ struct MidEvents
// pitch bend
case 0x0E:
{
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
ptr += 3;
delta = 0;
}
Expand All @@ -443,7 +444,7 @@ struct MidEvents
// note on
case 0x09:
{
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
_items.emplace_back(delta, *ptr, *(ptr + 1), *(ptr + 2));
pack_t pack = unpackValue(ptr + 3);
notesoff.emplace_back(*ptr - 0x10, *(ptr + 1), pack.first);
ptr += 3 + pack.second;
Expand All @@ -456,15 +457,15 @@ struct MidEvents
// chanel pressure
case 0x0D:
{
_items.emplace_back(delta, *ptr, *(ptr + 1));
_items.emplace_back(delta, *ptr, *(ptr + 1));
ptr += 2;
delta = 0;
}
break;

// unused command
default:
_items.emplace_back(0, 0xFF, 0x2F, 0);
_items.emplace_back(0, 0xFF, 0x2F, 0);
H2ERROR("unknown st: 0x" << std::setw(2) << std::setfill('0') << std::hex <<
static_cast<int>(*ptr) << ", ln: "
<< static_cast<int>(&t.evnt[0] + t.evnt.size() - ptr));
Expand Down Expand Up @@ -509,9 +510,10 @@ ByteVectorWriter& operator<<(ByteVectorWriter& sb, const MidTrack& st)
return sb;
}

struct MidTracks
struct MidTracks
{
vector<MidTrack> _items;
vector<MidTrack> _items;

size_t count() const
{
return _items.size();
Expand All @@ -530,7 +532,7 @@ struct MidTracks
explicit MidTracks(const XMITracks& tracks)
{
for (const auto& track : tracks)
_items.emplace_back(track);
_items.emplace_back(track);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/agg/agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

namespace
{
const int FATSIZENAME = 15;
const int FATSIZENAME = 15;

std::vector<SDL_Color> pal_colors;
std::vector<uint32_t> pal_colors_u32;
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/agg/icn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,8 +2012,8 @@ bool ICN::isBattleMonsterICN(int icn)
int ICN::FromString(const std::string& str)
{
const icnmap_t* ptr = &icnmap[0];
while (ptr->type != UNKNOWN && !str.empty() && str!= ptr->name)
++ptr;
while (ptr->type != UNKNOWN && !str.empty() && str != ptr->name)
++ptr;
return ptr->type;
}

Expand Down
27 changes: 14 additions & 13 deletions src/fheroes2/ai/simple/ai_heroes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ s32 FindUncharteredTerritory(Heroes& hero, uint32_t scoute)
Maps::GetAroundIndexes(hero.GetIndex(), scoute, true, v);
Maps::Indexes res;

v.resize(distance(v.begin(),
remove_if(v.begin(), v.end(),
[](s32 it) {return Maps::TileIsUnderProtection(it); })));
v.resize(distance(v.begin(),
remove_if(v.begin(), v.end(),
[](s32 it) { return Maps::TileIsUnderProtection(it); })));


for (auto it = v.rbegin(); it != v.rend() && res.size() < 4; ++it)
Expand All @@ -217,8 +217,8 @@ s32 GetRandomHeroesPosition(Heroes& hero, uint32_t scoute)
Maps::Indexes res;

v.resize(distance(v.begin(),
remove_if(v.begin(), v.end(),
[](s32 it) {return Maps::TileIsUnderProtection(it); })));
remove_if(v.begin(), v.end(),
[](s32 it) { return Maps::TileIsUnderProtection(it); })));


for (auto it = v.rbegin(); it != v.rend() && res.size() < 4; ++it)
Expand Down Expand Up @@ -402,8 +402,9 @@ bool AI::HeroesGetTask(Heroes& hero)
// scan enemy hero
if (hero.GetSquarePatrol())
{
const Maps::Indexes& indicesAround = Maps::ScanAroundObject(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()),
hero.GetSquarePatrol(), MP2::OBJ_HEROES);
const Maps::Indexes& indicesAround = Maps::ScanAroundObject(
Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()),
hero.GetSquarePatrol(), MP2::OBJ_HEROES);
for (int result : indicesAround)
{
const Heroes* enemy = world.GetTiles(result).GetHeroes();
Expand All @@ -419,7 +420,7 @@ bool AI::HeroesGetTask(Heroes& hero)
if (conf.ExtHeroPatrolAllowPickup())
{
const Maps::Indexes& indicesAround = Maps::ScanAroundObjects(hero.GetIndex(),
hero.GetSquarePatrol(), objs1);
hero.GetSquarePatrol(), objs1);
for (auto result : indicesAround)
{
if (!HeroesValidObject(hero, result) || !hero.GetPath().Calculate(result))
Expand Down Expand Up @@ -543,11 +544,11 @@ bool AI::HeroesGetTask(Heroes& hero)
}
else
{
// remove invalid task
task.remove_if([&](s32&it)
{
return !AIHeroesValidObject2(&hero, it);
});
// remove invalid task
task.remove_if([&](s32& it)
{
return !AIHeroesValidObject2(&hero, it);
});
}

// random shuffle
Expand Down
9 changes: 6 additions & 3 deletions src/fheroes2/army/army_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ bool CanUpgradeTroopButNoResources(Troop& troop, Army* army)
bool candidate = false;
if (troop._monster.isAllowUpgrade() &&
// allow upgrade
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(troop._monster.GetUpgrade().GetDwelling()))
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(
troop._monster.GetUpgrade().GetDwelling()))
{
candidate = true;
}
Expand All @@ -54,7 +55,8 @@ bool CanUpgradeTroop(Troop& troop, Army* army)
bool candidate = false;
if (troop._monster.isAllowUpgrade() &&
// allow upgrade
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(troop._monster.GetUpgrade().GetDwelling()))
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(
troop._monster.GetUpgrade().GetDwelling()))
{
candidate = true;
}
Expand Down Expand Up @@ -497,7 +499,8 @@ bool ArmyBar::ActionBarDoubleClick(const Point& cursor, ArmyTroop& troop, const

if (troop._monster.isAllowUpgrade() &&
// allow upgrade
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(troop._monster.GetUpgrade().GetDwelling()))
castle && castle->GetRace() == troop._monster.GetRace() && castle->isBuild(
troop._monster.GetUpgrade().GetDwelling()))
{
flags |= Dialog::UPGRADE;

Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/army/army_troop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Troop::Set(const Monster& m, uint32_t c)

void Troop::SetMonster(const Monster& m)
{
_monster.id = m.GetID();
_monster.id = m.GetID();
}

void Troop::SetCount(uint32_t c)
Expand All @@ -78,7 +78,7 @@ void Troop::SetCount(uint32_t c)

void Troop::Reset()
{
_monster.id = Monster::UNKNOWN;
_monster.id = Monster::UNKNOWN;
count = 0;
}

Expand Down
Loading

0 comments on commit e04beeb

Please sign in to comment.