Skip to content

Commit 20bce37

Browse files
committed
clean up code
1 parent c9e41eb commit 20bce37

38 files changed

+628
-612
lines changed

src/Autostart.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LSSharedFileListItemRef FindLoginItemForCurrentBundle(CFArrayRef currentLoginIte
3838

3939
#endif // Q_OS_MAC
4040

41-
bool Autostart::IsActive()
41+
bool Autostart::Active()
4242
{
4343
#ifdef Q_WS_WIN
4444
const QString& applicationName = qApp->applicationName();

src/Autostart.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
class Autostart
44
{
55
public:
6-
bool IsActive();
6+
bool Active();
77
void SetActive( bool active );
88
};

src/CocoaInitializer.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
class CocoaInitializer
44
{
5-
public:
6-
CocoaInitializer();
7-
~CocoaInitializer();
8-
95
private:
106
class Private;
117
Private* d;
8+
9+
public:
10+
CocoaInitializer();
11+
~CocoaInitializer();
1212
};
1313

src/CocoaInitializer.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
class CocoaInitializer::Private
77
{
8-
public:
9-
NSAutoreleasePool* autoReleasePool_;
8+
public:
9+
NSAutoreleasePool* autoReleasePool_;
1010
};
1111

1212
CocoaInitializer::CocoaInitializer()

src/Core.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,60 @@
22
#include "Tracker.h"
33

44
Core::Core()
5-
: currentGameMode( MODE_UNKNOWN ), gameRunning( false )
5+
: mCurrentGameMode( MODE_UNKNOWN ), mGameRunning( false )
66
{
7-
sceneManager.RegisterObserver( this );
7+
mSceneManager.RegisterObserver( this );
88

9-
timer = new QTimer( this );
10-
connect( timer, SIGNAL( timeout() ), this, SLOT( Tick() ) );
11-
timer->start( 100 );
9+
mTimer = new QTimer( this );
10+
connect( mTimer, SIGNAL( timeout() ), this, SLOT( Tick() ) );
11+
mTimer->start( 100 );
1212
}
1313

1414
Core::~Core() {
15-
delete timer;
15+
delete mTimer;
1616
}
1717

1818
void Core::Tick() {
19-
bool wasGameRunning = gameRunning;
20-
gameRunning = Hearthstone::Instance()->IsRunning();
19+
bool wasGameRunning = mGameRunning;
20+
mGameRunning = Hearthstone::Instance()->Running();
2121

22-
if( wasGameRunning != gameRunning ) {
23-
if( gameRunning ) {
22+
if( wasGameRunning != mGameRunning ) {
23+
if( mGameRunning ) {
2424
LOG("Hearthstone found");
2525
} else {
2626
LOG("Hearthstone was closed");
2727
}
2828
}
2929

30-
if( gameRunning ) {
31-
sceneManager.Update();
30+
if( mGameRunning ) {
31+
mSceneManager.Update();
3232
}
3333
}
3434

3535
void Core::SceneChanged( Scene *oldScene, Scene *newScene ) {
36-
LOG( "Scene %s", newScene->GetName().c_str() );
36+
LOG( "Scene %s", newScene->Name().c_str() );
3737

38-
if( newScene->GetName() == "Ingame" ) {
38+
if( newScene->Name() == "Ingame" ) {
3939
if( oldScene ) {
40-
if( oldScene->GetName() == "Constructed" ) {
40+
if( oldScene->Name() == "Constructed" ) {
4141
ConstructedScene *constructed = ( ConstructedScene* )oldScene;
42-
currentGameMode = constructed->GetGameMode();
42+
mCurrentGameMode = constructed->GameMode();
4343
}
44-
if( oldScene->GetName() == "Arena" ) {
45-
currentGameMode = MODE_ARENA;
44+
if( oldScene->Name() == "Arena" ) {
45+
mCurrentGameMode = MODE_ARENA;
4646
}
4747
}
4848
}
4949

50-
if( oldScene && oldScene->GetName() == "Ingame" ) {
50+
if( oldScene && oldScene->Name() == "Ingame" ) {
5151
IngameScene *ingame = ( IngameScene* )oldScene;
5252

5353
Tracker::Instance()->AddResult(
54-
currentGameMode,
55-
ingame->GetOutcome(),
56-
ingame->GetGoingOrder(),
57-
ingame->GetOwnClass(),
58-
ingame->GetOpponentClass(),
59-
ingame->GetCardHistoryList() );
54+
mCurrentGameMode,
55+
ingame->Outcome(),
56+
ingame->GoingOrder(),
57+
ingame->OwnClass(),
58+
ingame->OpponentClass(),
59+
ingame->CardHistoryList() );
6060
}
6161
}

src/Core.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ class Core : public QObject, public SceneManagerObserver
1010
Q_OBJECT
1111

1212
private:
13-
QTimer *timer;
14-
15-
SceneManager sceneManager;
16-
GameMode currentGameMode;
17-
18-
bool gameRunning;
13+
QTimer* mTimer;
14+
SceneManager mSceneManager;
15+
GameMode mCurrentGameMode;
16+
bool mGameRunning;
1917

2018
private slots:
2119
void Tick();

src/Hearthstone.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ DEFINE_SINGLETON_SCOPE( Hearthstone )
1515

1616
Hearthstone::Hearthstone() {
1717
#ifdef Q_WS_MAC
18-
capture = new OSXWindowCapture( "Hearthstone" );
18+
mCapture = new OSXWindowCapture( "Hearthstone" );
1919
#elif defined Q_WS_WIN
20-
capture = new WinWindowCapture( "Hearthstone" );
20+
mCapture = new WinWindowCapture( "Hearthstone" );
2121
#endif
2222
}
2323

2424
Hearthstone::~Hearthstone() {
25-
if( capture != NULL )
26-
delete capture;
25+
if( mCapture != NULL )
26+
delete mCapture;
2727
}
2828

29-
bool Hearthstone::IsRunning() {
30-
return capture->WindowFound();
29+
bool Hearthstone::Running() {
30+
return mCapture->WindowFound();
3131
}
3232

3333
#ifdef Q_WS_WIN
@@ -36,11 +36,11 @@ inline float roundf( float x ) {
3636
}
3737
#endif
3838

39-
QPixmap Hearthstone::Capture(int vx, int vy, int vw, int vh) {
39+
QPixmap Hearthstone::Capture( int vx, int vy, int vw, int vh ) {
4040
int x, y, w, h;
4141

42-
int realCanvasWidth = capture->GetWidth();
43-
int realCanvasHeight = capture->GetHeight();
42+
int realCanvasWidth = mCapture->Width();
43+
int realCanvasHeight = mCapture->Height();
4444

4545
int virtualCanvasWidth = VIRTUAL_CANVAS_WIDTH;
4646
int virtualCanvasHeight = VIRTUAL_CANVAS_HEIGHT;
@@ -55,14 +55,14 @@ QPixmap Hearthstone::Capture(int vx, int vy, int vw, int vh) {
5555
w = roundf( vw * scale );
5656
h = roundf( vh * scale );
5757

58-
return capture->Capture( x, y, w, h );
58+
return mCapture->Capture( x, y, w, h );
5959
}
6060

61-
void Hearthstone::SetWindowCapture( WindowCapture *wc ) {
62-
if( capture != NULL )
63-
delete capture;
61+
void Hearthstone::SetWindowCapture( WindowCapture *windowCapture ) {
62+
if( mCapture != NULL )
63+
delete mCapture;
6464

65-
capture = wc;
65+
mCapture = windowCapture;
6666
}
6767

6868
void Hearthstone::EnableLogging() {
@@ -81,7 +81,7 @@ void Hearthstone::EnableLogging() {
8181
file.close();
8282

8383
LOG( "Ingame Log activated." );
84-
if( IsRunning() ) {
84+
if( Running() ) {
8585
LOG("Please restart Hearthstone for logging to take effect.");
8686
}
8787
}
@@ -101,7 +101,7 @@ string Hearthstone::LogConfigPath() {
101101
QString homeLocation = QDesktopServices::storageLocation( QDesktopServices::HomeLocation );
102102
QString configPath = homeLocation + "/Library/Preferences/Blizzard/Hearthstone/log.config";
103103
#elif defined Q_WS_WIN
104-
char buffer[MAX_PATH];
104+
char buffer[ MAX_PATH ];
105105
SHGetSpecialFolderPathA( NULL, buffer, CSIDL_LOCAL_APPDATA, FALSE );
106106
QString localAppData( buffer );
107107
QString configPath = localAppData + "\\Blizzard\\Hearthstone\\log.config";
@@ -129,10 +129,10 @@ string Hearthstone::LogPath() {
129129
return logPath.toStdString();
130130
}
131131

132-
int Hearthstone::GetWidth() {
133-
return capture->GetWidth();
132+
int Hearthstone::Width() {
133+
return mCapture->Width();
134134
}
135135

136-
int Hearthstone::GetHeight() {
137-
return capture->GetHeight();
136+
int Hearthstone::Height() {
137+
return mCapture->Height();
138138
}

src/Hearthstone.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ class Hearthstone
1515
DEFINE_SINGLETON( Hearthstone )
1616

1717
private:
18-
WindowCapture *capture;
18+
WindowCapture *mCapture;
1919

2020
public:
2121
// Allow to override window capture for test environment
22-
void SetWindowCapture( WindowCapture *wc );
22+
void SetWindowCapture( WindowCapture *windowCapture );
2323

24-
bool IsRunning();
24+
bool Running();
2525
QPixmap Capture( int vx, int vy, int vw, int vh );
2626

2727
void EnableLogging();
@@ -30,7 +30,7 @@ class Hearthstone
3030
string LogConfigPath();
3131
string LogPath();
3232

33-
int GetWidth();
34-
int GetHeight();
33+
int Width();
34+
int Height();
3535

3636
};

src/HearthstoneLogAnalyzer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <QStringList>
55

66
HearthstoneLogAnalyzer::HearthstoneLogAnalyzer() {
7-
connect( &logWatcher, SIGNAL( LineAdded(QString) ), this, SLOT( HandleLogLine(QString) ) );
7+
connect( &mLogWatcher, SIGNAL( LineAdded(QString) ), this, SLOT( HandleLogLine(QString) ) );
88
}
99

1010
void HearthstoneLogAnalyzer::HandleLogLine( const QString& line ) {

src/HearthstoneLogAnalyzer.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ class HearthstoneLogAnalyzer : public QObject
66
{
77
Q_OBJECT
88

9+
private:
10+
HearthstoneLogWatcher mLogWatcher;
11+
12+
private slots:
13+
void HandleLogLine( const QString& line );
14+
915
public:
1016
HearthstoneLogAnalyzer();
1117

@@ -14,10 +20,4 @@ class HearthstoneLogAnalyzer : public QObject
1420
void CardPlayed( Player player, const string& cardId );
1521
void CardReturned( Player player, const string& cardId );
1622
void CoinReceived( Player player );
17-
18-
private slots:
19-
void HandleLogLine( const QString& line );
20-
21-
private:
22-
HearthstoneLogWatcher logWatcher;
2323
};

src/HearthstoneLogWatcher.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,48 @@
55
#include <QTimer>
66

77
HearthstoneLogWatcher::HearthstoneLogWatcher()
8-
:path(Hearthstone::Instance()->LogPath().c_str()), lastSeekPos(0)
8+
: mPath( Hearthstone::Instance()->LogPath().c_str() ), mLastSeekPos( 0 )
99
{
1010
// We used QFileSystemWatcher before but it fails on windows
1111
// Windows File Notification seems to be very tricky with files
1212
// which are not explicitly flushed (which is the case for the Hearthstone Log)
1313
// QFileSystemWatcher fails, manual implemention with FindFirstChangeNotification
1414
// fails. So instead of putting too much work into a file-system depending solution
1515
// just use a low-overhead polling strategy
16-
QTimer *timer = new QTimer(this);
17-
connect(timer, SIGNAL(timeout()), this, SLOT(CheckForLogChanges()));
18-
timer->start(CHECK_FOR_LOG_CHANGES_INTERVAL_MS);
16+
QTimer *timer = new QTimer( this );
17+
connect( timer, SIGNAL( timeout() ), this, SLOT( CheckForLogChanges() ) );
18+
timer->start( CHECK_FOR_LOG_CHANGES_INTERVAL_MS );
1919

20-
QFile file(path);
21-
if(file.exists()) {
22-
lastSeekPos = file.size();
20+
QFile file( mPath );
21+
if( file.exists() ) {
22+
mLastSeekPos = file.size();
2323
}
2424
}
2525

2626
void HearthstoneLogWatcher::CheckForLogChanges() {
2727
// Only access disk when HS is running
28-
if(!Hearthstone::Instance()->IsRunning()) {
28+
if( !Hearthstone::Instance()->Running() ) {
2929
return;
3030
}
3131

32-
QFile file(path);
33-
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
32+
QFile file( mPath );
33+
if( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
3434
return;
3535
}
3636

3737
qint64 size = file.size();
38-
if(size < lastSeekPos) {
39-
lastSeekPos = size;
38+
if( size < mLastSeekPos ) {
39+
mLastSeekPos = size;
4040
} else {
41-
QTextStream stream(&file);
42-
stream.seek(lastSeekPos);
41+
QTextStream stream( &file );
42+
stream.seek( mLastSeekPos );
4343

44-
while(!stream.atEnd()) {
44+
while( !stream.atEnd() ) {
4545
QString line = stream.readLine();
4646
emit LineAdded(line);
4747
}
4848

49-
lastSeekPos = stream.pos();
49+
mLastSeekPos = stream.pos();
5050
}
5151
}
5252

src/HearthstoneLogWatcher.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class HearthstoneLogWatcher : public QObject
77
Q_OBJECT
88

99
private:
10-
QString path;
11-
qint64 lastSeekPos;
10+
QString mPath;
11+
qint64 mLastSeekPos;
1212

1313
public:
1414
HearthstoneLogWatcher();

0 commit comments

Comments
 (0)