Skip to content

Commit 5cc29f3

Browse files
committed
1pt of ServersList's implemention
1 parent 42381e1 commit 5cc29f3

16 files changed

Lines changed: 530 additions & 77 deletions

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,3 @@ jobs:
4848
# Execute tests defined by the CMake configuration.
4949
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
5050
run: ctest -C ${{env.BUILD_TYPE}}
51-

.vscode/c_cpp_properties.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"name": "Linux",
55
"includePath": [
66
"${workspaceFolder}/**",
7-
"/usr/include/x86_64-linux-gnu/qt5/QtWidgets",
87
"/usr/include/x86_64-linux-gnu/qt6/QtWidgets",
9-
"/usr/include/x86_64-linux-gnu/qt5/QtCore",
10-
"/usr/include/x86_64-linux-gnu/qt5"
8+
"/usr/include/x86_64-linux-gnu/qt6/QtWidgets",
9+
"/usr/include/x86_64-linux-gnu/qt6/QtCore",
10+
"/usr/include/x86_64-linux-gnu/qt6"
1111
],
1212
"defines": [],
1313
"compilerPath": "/usr/bin/gcc-13",
@@ -17,4 +17,4 @@
1717
}
1818
],
1919
"version": 4
20-
}
20+
}

.vscode/settings.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,14 @@
6868
"qsharedpointer": "cpp",
6969
"fstream": "cpp"
7070
},
71-
"C_Cpp.default.compilerPath": "/usr/bin/gcc-13"
71+
"C_Cpp.default.compilerPath": "/usr/bin/gcc-13",
72+
"C_Cpp.default.intelliSenseMode": "linux-gcc-x64",
73+
"C_Cpp.default.cppStandard": "c++23",
74+
"C_Cpp.default.cStandard": "c23",
75+
"C_Cpp.inlayHints.autoDeclarationTypes.showOnLeft": true,
76+
"C_Cpp.inlayHints.autoDeclarationTypes.enabled": true,
77+
"C_Cpp.inlayHints.parameterNames.enabled": true,
78+
"C_Cpp.inlayHints.referenceOperator.enabled": true,
79+
"C_Cpp.inlayHints.referenceOperator.showSpace": true,
80+
"C_Cpp.formatting": "clangFormat"
7281
}

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ set(HEADERS
8585
include/RakNetWorker.h
8686
include/ThreadWorker.h
8787
include/WorkerClass.h
88+
include/IntervalWorker.h
8889
include/scorebwindow.h
8990
include/Game/CAnimationInfo.h
9091
include/Game/playback.h
@@ -131,7 +132,11 @@ file(GLOB XML_SRC "lib/tinyxml/*.cpp")
131132
file(GLOB XML_HDR "lib/tinyxml/*.h")
132133
add_library(TinyXML ${XML_SRC} ${XML_HDR})
133134

134-
target_link_libraries(${PROJECT_NAME} PRIVATE RakNet TinyXML)
135+
file(GLOB QUERY_SRC "lib/query/*.cpp")
136+
file(GLOB QUERY_HDR "lib/query/*.h")
137+
add_library(QueryAPI ${QUERY_SRC} ${QUERY_HDR})
138+
139+
target_link_libraries(${PROJECT_NAME} PRIVATE RakNet TinyXML QueryAPI)
135140

136141
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -lstdc++ -fsanitize=address") ## -fsanitize=thread
137142

include/IntervalWorker.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
#include <QThread>
3+
#include <chrono>
4+
#include <thread>
5+
#include <functional>
6+
7+
class IntervalWorker : public QThread {
8+
Q_OBJECT
9+
public:
10+
explicit IntervalWorker(int intervalMs, std::function<void()> task = nullptr)
11+
: m_interval(intervalMs), m_task(std::move(task)) {}
12+
13+
signals:
14+
void tick();
15+
16+
protected:
17+
void run() override {
18+
auto next_tick = std::chrono::steady_clock::now();
19+
const auto duration = std::chrono::milliseconds(m_interval);
20+
21+
while (!isInterruptionRequested()) {
22+
// 1. Emit signal for UI updates (asynchronous)
23+
emit tick();
24+
25+
// 2. Execute functional task if provided (synchronous in this thread)
26+
if (m_task) {
27+
m_task();
28+
}
29+
30+
next_tick += duration;
31+
32+
// 3. Precision sleep
33+
// Use a check to ensure we haven't already passed next_tick
34+
if (std::chrono::steady_clock::now() < next_tick) {
35+
std::this_thread::sleep_until(next_tick);
36+
} else {
37+
// If the task was so slow it exceeded 750ms, reset next_tick
38+
next_tick = std::chrono::steady_clock::now();
39+
}
40+
}
41+
}
42+
43+
private:
44+
const int m_interval;
45+
const std::function<void()> m_task;
46+
};

include/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "RakNetWorker.h"
4545
#include "WorkerClass.h"
4646

47+
#include "IntervalWorker.h"
48+
4749
class MainWindow : public QMainWindow {
4850
Q_OBJECT
4951

include/scorebwindow.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cstdlib>
1515

1616
#include "./globals.h"
17+
#include "./utils.h"
1718

1819
class Scoreboard : public QWidget
1920
{
@@ -26,8 +27,6 @@ class Scoreboard : public QWidget
2627
private:
2728
QTableWidget *tableWidget;
2829

29-
bool isRowEmpty(int row);
30-
3130
public:
3231
struct PlayerDTA
3332
{

include/serverswindow.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@
1616
#include <QtWidgets/QHBoxLayout>
1717

1818
#include "./globals.h"
19+
#include "./utils.h"
20+
21+
#include "../lib/query/QueryAPI.h"
22+
23+
#include <map>
24+
#include <variant>
25+
#include <vector>
26+
27+
#define MAX_SERVERS (150)
1928

20-
#define MAX_SERVERS 100
2129
class ServersList : public QDialog
2230
{
2331
Q_OBJECT
@@ -37,14 +45,21 @@ class ServersList : public QDialog
3745
QLineEdit *lineEdit;
3846
QLabel *label;
3947

40-
struct srvData
48+
struct srvDTA
4149
{
42-
char *srvAddr;
43-
short srvPort;
44-
char *SRVName;
50+
std::string address;
51+
int port;
4552
};
4653

47-
int srvCount;
48-
srvData srvList[MAX_SERVERS];
54+
using ListValue = std::variant<std::string, int>;
55+
std::map<int, std::vector<ListValue>> srvData;
56+
57+
int srvsCount = -1;
58+
59+
public:
60+
bool addServer(const srvDTA& server);
61+
bool removeServer(int serverid);
62+
63+
void onTick();
4964
};
5065
#endif

include/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QtMultimedia/QMediaPlayer>
1818
#include <QtCore/QSharedPointer>
1919
#include <QtCore/QRegularExpression>
20+
#include <QtWidgets/QTableWidget>
2021

2122
#include "common.h"
2223
#include "globals.h"
@@ -71,3 +72,7 @@ const char *getWeaponName(int weaponid);
7172
bool IsVehicleIndexValid(int vehicleid);
7273

7374
void centerOverParent(QWidget* child, QWidget* parent);
75+
76+
// QTableWidget...
77+
bool isTableWidgetRowEmpty(QTableWidget *tabelWidget, int row);
78+
void updateTableWidgetSize(QTableWidget *tabelWidget, int playersCount);

0 commit comments

Comments
 (0)