Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Admiral-Fish committed Jan 14, 2020
1 parent 55dc6a6 commit 51a5460
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 84 deletions.
12 changes: 12 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
BasedOnStyle: WebKit

AlignAfterOpenBracket: Align
AllowShortFunctionsOnASingleLine: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Allman
BreakConstructorInitializers: AfterColon
ColumnLimit: 140
ConstructorInitializerAllOnOneLineOrOnePerLine: true
NamespaceIndentation: All
PointerAlignment: Right
8 changes: 4 additions & 4 deletions Core/Gen7/WildSearcher7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <Core/Util/Utility.hpp>
#include <QtConcurrent>

static const QVector<u8> grassSlots = { 19, 39, 49, 59, 69, 79, 89, 94, 98, 99 };
static const QVector<u8> waterSlots = { 78, 98, 99 };
constexpr u8 grassSlots[10] = { 19, 39, 49, 59, 69, 79, 89, 94, 98, 99 };
constexpr u8 waterSlots[3] = { 78, 98, 99 };

WildSearcher7::WildSearcher7(const QDateTime &start, const QDateTime &end, u32 startFrame, u32 endFrame, bool useSynch,
int synchNature, WildType type, int gender, const Profile7 &profile, const WildFilter &filter)
Expand Down Expand Up @@ -212,7 +212,7 @@ u8 WildSearcher7::getSlot(u8 value)
{
for (u8 i = 0; i < 10; i++)
{
if (value <= grassSlots.at(i))
if (value <= grassSlots[i])
{
return i + 1;
}
Expand All @@ -222,7 +222,7 @@ u8 WildSearcher7::getSlot(u8 value)

for (u8 i = 0; i < 3; i++)
{
if (value <= waterSlots.at(i))
if (value <= waterSlots[i])
{
return i + 1;
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <cstdint>

#ifndef GLOBAL_HPP
#define GLOBAL_HPP

#include <cstdint>

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
Expand Down
38 changes: 13 additions & 25 deletions Core/RNG/MT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@

#include "MT.hpp"

constexpr u32 LOWERMASK = 0x7FFFFFFF;
constexpr u32 UPPERMASK = 0x80000000;
constexpr u16 M = 397;
constexpr u16 N = 624;
constexpr u32 TEMPERINGMASKB = 0x9D2C5680;
constexpr u32 TEMPERINGMASKC = 0xEFC60000;
constexpr u32 mag01[2] = { 0x0, 0x9908B0DF };

MT::MT(u32 seed, u32 frames)
{
initialize(seed);
Expand All @@ -37,7 +29,7 @@ void MT::initialize(u32 seed)
{
mt[0] = seed;

for (index = 1; index < N; index++)
for (index = 1; index < 624; index++)
{
mt[index] = (0x6C078965 * (mt[index - 1] ^ (mt[index - 1] >> 30))) + index;
}
Expand All @@ -54,37 +46,33 @@ void MT::advanceFrames(u32 frames)

u32 MT::nextUInt()
{
if (index >= N)
if (index >= 624)
{
shuffle();
}

u32 y = mt[index++];
y ^= (y >> 11);
y ^= (y << 7) & TEMPERINGMASKB;
y ^= (y << 15) & TEMPERINGMASKC;
y ^= (y << 7) & 0x9D2C5680;
y ^= (y << 15) & 0xEFC60000;
y ^= (y >> 18);
return y;
}

void MT::shuffle()
{
u16 i = 0;

for (; i < 227; i++)
for (u16 i = 0; i < 624; i++)
{
u32 y = (mt[i] & UPPERMASK) | (mt[i + 1] & LOWERMASK);
mt[i] = mt[i + M] ^ (y >> 1) ^ mag01[y & 1];
}
u32 y = (mt[i] & 0x80000000) | (mt[(i + 1) % 624] & 0x7FFFFFFF);
u32 next = y >> 1;

for (; i < 623; i++)
{
u32 y = (mt[i] & UPPERMASK) | (mt[i + 1] & LOWERMASK);
mt[i] = mt[i - 227] ^ (y >> 1) ^ mag01[y & 1];
}
if (y & 1)
{
next ^= 0x9908B0DF;
}

u32 y = (mt[623] & UPPERMASK) | (mt[0] & LOWERMASK);
mt[623] = mt[396] ^ (y >> 1) ^ mag01[y & 1];
mt[i] = next ^ mt[(i + 397) % 624];
}

index -= 624;
}
30 changes: 12 additions & 18 deletions Core/RNG/SFMT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

#include "SFMT.hpp"

constexpr u32 CMSK1 = 0xdfffffef;
constexpr u32 CMSK2 = 0xddfecb7f;
constexpr u32 CMSK3 = 0xbffaffff;
constexpr u32 CMSK4 = 0xbffffff6;
constexpr u8 CSL1 = 18;
constexpr u8 CSR1 = 11;
constexpr u16 N32 = 624;
constexpr u32 parity[4] = { 0x1, 0x0, 0x0, 0x13c9e684 };

SFMT::SFMT(u32 seed, u32 frames)
Expand All @@ -38,7 +31,7 @@ void SFMT::initialize(u32 seed)
{
sfmt[0] = seed;

for (index = 1; index < N32; index++)
for (index = 1; index < 624; index++)
{
sfmt[index] = (0x6C078965 * (sfmt[index - 1] ^ (sfmt[index - 1] >> 30))) + index;
}
Expand Down Expand Up @@ -89,7 +82,7 @@ void SFMT::advanceFrames(u32 frames)

u32 SFMT::nextUInt()
{
if (index >= N32)
if (index >= 624)
{
shuffle();
}
Expand All @@ -99,7 +92,7 @@ u32 SFMT::nextUInt()

u64 SFMT::nextULong()
{
if (index >= N32)
if (index >= 624)
{
shuffle();
}
Expand All @@ -115,24 +108,25 @@ void SFMT::shuffle()
u16 b = 488;
u16 c = 616;
u16 d = 620;

do
{
sfmt[a + 3] = sfmt[a + 3] ^ (sfmt[a + 3] << 8) ^ (sfmt[a + 2] >> 24) ^ (sfmt[c + 3] >> 8)
^ ((sfmt[b + 3] >> CSR1) & CMSK4) ^ (sfmt[d + 3] << CSL1);
sfmt[a + 3] = sfmt[a + 3] ^ (sfmt[a + 3] << 8) ^ (sfmt[a + 2] >> 24) ^ (sfmt[c + 3] >> 8) ^ ((sfmt[b + 3] >> 11) & 0xbffffff6)
^ (sfmt[d + 3] << 18);
sfmt[a + 2] = sfmt[a + 2] ^ (sfmt[a + 2] << 8) ^ (sfmt[a + 1] >> 24) ^ (sfmt[c + 3] << 24) ^ (sfmt[c + 2] >> 8)
^ ((sfmt[b + 2] >> CSR1) & CMSK3) ^ (sfmt[d + 2] << CSL1);
^ ((sfmt[b + 2] >> 11) & 0xbffaffff) ^ (sfmt[d + 2] << 18);
sfmt[a + 1] = sfmt[a + 1] ^ (sfmt[a + 1] << 8) ^ (sfmt[a] >> 24) ^ (sfmt[c + 2] << 24) ^ (sfmt[c + 1] >> 8)
^ ((sfmt[b + 1] >> CSR1) & CMSK2) ^ (sfmt[d + 1] << CSL1);
sfmt[a] = sfmt[a] ^ (sfmt[a] << 8) ^ (sfmt[c + 1] << 24) ^ (sfmt[c] >> 8) ^ ((sfmt[b] >> CSR1) & CMSK1)
^ (sfmt[d] << CSL1);
^ ((sfmt[b + 1] >> 11) & 0xddfecb7f) ^ (sfmt[d + 1] << 18);
sfmt[a] = sfmt[a] ^ (sfmt[a] << 8) ^ (sfmt[c + 1] << 24) ^ (sfmt[c] >> 8) ^ ((sfmt[b] >> 11) & 0xdfffffef) ^ (sfmt[d] << 18);
c = d;
d = a;
a += 4;
b += 4;
if (b >= N32)
if (b >= 624)
{
b = 0;
}
} while (a < N32);
} while (a < 624);

index -= 624;
}
16 changes: 10 additions & 6 deletions Core/RNG/SHA256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ constexpr u32 K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c2
0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb,
0xbef9a3f7, 0xc67178f2 };

inline u32 rightRotate(u32 val, u8 count)
{
return (val >> count) | (val << (32 - count));
}

inline u32 changeEndian(u32 num)
{
return ((num >> 24) & 0xff) | ((num << 8) & 0xff0000) | ((num >> 8) & 0xff00) | ((num << 24) & 0xff000000);
}

u32 SHA256::hash(u32 tick, u32 epochLow, u32 epochHigh)
{
u32 w[64] = { changeEndian(tick), 0, changeEndian(epochLow), changeEndian(epochHigh), 0x80000000, 0, 0, 0, 0, 0, 0,
Expand All @@ -36,7 +46,6 @@ u32 SHA256::hash(u32 tick, u32 epochLow, u32 epochHigh)
// w[16] is always changeEndian(tick) as long as w[1] == 0 is true, precompute
w[16] = changeEndian(tick);

auto rightRotate = [](u32 val, u8 count) { return (val >> count) | (val << (32 - count)); };
for (u8 i = 17; i < 64; i++)
{
u32 sig0 = rightRotate(w[i - 15], 7) ^ rightRotate(w[i - 15], 18) ^ (w[i - 15] >> 3);
Expand Down Expand Up @@ -78,8 +87,3 @@ u32 SHA256::hash(u32 tick, u32 epochLow, u32 epochHigh)

return changeEndian(a + 0x6a09e667);
}

u32 SHA256::changeEndian(u32 num)
{
return ((num >> 24) & 0xff) | ((num << 8) & 0xff0000) | ((num >> 8) & 0xff00) | ((num << 24) & 0xff000000);
}
1 change: 0 additions & 1 deletion Core/RNG/SHA256.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
namespace SHA256
{
u32 hash(u32 tick, u32 epochLow, u32 epochHigh);
u32 changeEndian(u32 num);
};

#endif // SHA256_HPP
2 changes: 2 additions & 0 deletions Forms/Gen6/Event6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ void Event6::setupModels()

QSettings setting;
if (setting.contains("event6/geometry"))
{
this->restoreGeometry(setting.value("event6/geometry").toByteArray());
}
}

void Event6::search()
Expand Down
6 changes: 3 additions & 3 deletions Forms/Gen6/ProfileEditor6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ ProfileEditor6::ProfileEditor6(QWidget *parent)
setupModels();
}

ProfileEditor6::ProfileEditor6(const Profile6 &profile, QWidget *parent)
: QDialog(parent)
, ui(new Ui::ProfileEditor6)
ProfileEditor6::ProfileEditor6(const Profile6 &profile, QWidget *parent) : QDialog(parent), ui(new Ui::ProfileEditor6)
{
ui->setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
Expand Down Expand Up @@ -86,7 +84,9 @@ void ProfileEditor6::setupModels()

QSettings setting;
if (setting.contains("profileEditor/geometry"))
{
this->restoreGeometry(setting.value("profileEditor/geometry").toByteArray());
}
}

void ProfileEditor6::accepted()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen6/ProfileManager6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ void ProfileManager6::setupModels()

QSettings setting;
if (setting.contains("profileManager/geometry"))
{
this->restoreGeometry(setting.value("profileManager/geometry").toByteArray());
}
}

void ProfileManager6::create()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen6/Stationary6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void Stationary6::setupModel()

QSettings setting;
if (setting.contains("stationary6/geometry"))
{
this->restoreGeometry(setting.value("stationary6/geometry").toByteArray());
}
}

void Stationary6::search()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen7/ID7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ void ID7::setupModel()

QSettings setting;
if (setting.contains("id7/geometry"))
{
this->restoreGeometry(setting.value("id7/geometry").toByteArray());
}
}

void ID7::search()
Expand Down
7 changes: 3 additions & 4 deletions Forms/Gen7/ProfileEditor7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ ProfileEditor7::ProfileEditor7(QWidget *parent)
setupModels();
}

ProfileEditor7::ProfileEditor7(const Profile7 &profile, QWidget *parent)
: QDialog(parent)
, ui(new Ui::ProfileEditor7)
ProfileEditor7::ProfileEditor7(const Profile7 &profile, QWidget *parent) : QDialog(parent), ui(new Ui::ProfileEditor7)
{
ui->setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
Expand All @@ -58,7 +56,6 @@ ProfileEditor7::ProfileEditor7(u32 tick, u32 offset, QWidget *parent)
{
ui->setupUi(this);
setAttribute(Qt::WA_QuitOnClose, false);
setWindowFlags(Qt::Widget | Qt::MSWindowsFixedSizeDialogHint);

setupModels();

Expand Down Expand Up @@ -100,7 +97,9 @@ void ProfileEditor7::setupModels()

QSettings setting;
if (setting.contains("profileEditor/geometry"))
{
this->restoreGeometry(setting.value("profileEditor/geometry").toByteArray());
}
}

void ProfileEditor7::accepted()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen7/ProfileManager7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ void ProfileManager7::setupModels()

QSettings setting;
if (setting.contains("profileManager/geometry"))
{
this->restoreGeometry(setting.value("profileManager/geometry").toByteArray());
}
}

void ProfileManager7::create()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen7/Stationary7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ void Stationary7::setupModel()

QSettings setting;
if (setting.contains("stationary7/geometry"))
{
this->restoreGeometry(setting.value("stationary7/geometry").toByteArray());
}
}

void Stationary7::search()
Expand Down
2 changes: 2 additions & 0 deletions Forms/Gen7/Wild7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void Wild7::setupModel()

QSettings setting;
if (setting.contains("wild7/geometry"))
{
this->restoreGeometry(setting.value("wild/geometry").toByteArray());
}
}

void Wild7::search()
Expand Down
2 changes: 2 additions & 0 deletions Forms/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ void MainWindow::setupModel()

QSettings setting;
if (setting.contains("mainWindow/geometry"))
{
this->restoreGeometry(setting.value("mainWindow/geometry").toByteArray());
}
}

void MainWindow::setupStyle()
Expand Down
Loading

0 comments on commit 51a5460

Please sign in to comment.