Skip to content

Commit e9ffe6a

Browse files
authored
add Stackable Callbacks to dbBindCallback (#25)
* fix addon config cfgPatches * add Multiple callback support to dbBindCallback * add Call dbBindCallback callback directly when result is already ready
1 parent d37a416 commit e9ffe6a

11 files changed

Lines changed: 44 additions & 34 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
[submodule "mariadb-connector-c"]
55
path = mariadb-connector-c
66
url = https://github.com/dedmen/mariadb-connector-c.git
7+
branch = intercept_3_2
78
[submodule "mariadbpp"]
89
path = mariadbpp
910
url = https://github.com/dedmen/mariadbpp
11+
branch = intercept
1012
[submodule "wolfssl"]
1113
path = wolfssl
1214
url = https://github.com/wolfSSL/wolfssl
1315
[submodule "yaml-cpp"]
1416
path = yaml-cpp
1517
url = https://github.com/dedmen/yaml-cpp.git
18+
branch = intercept

CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ else()
3030
endif()
3131

3232

33-
#yaml resets c++17 so I just move it above ours so we don't have to re-set
34-
SET(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Don't want" FORCE)
35-
SET(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Don't want" FORCE)
36-
SET(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Don't want" FORCE)
37-
SET(YAML_CPP_INSTALL OFF CACHE BOOL "Don't want" FORCE)
38-
SET(MSVC_SHARED_RT OFF CACHE BOOL "want static" FORCE)
39-
40-
add_subdirectory(yaml-cpp)
41-
4233
set(CMAKE_CXX_STANDARD 17)
4334
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4435
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -69,13 +60,20 @@ else()
6960
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/OPT:REF /DEBUG:FULL")
7061
endif()
7162

63+
SET(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Don't want" FORCE)
64+
SET(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "Don't want" FORCE)
65+
SET(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "Don't want" FORCE)
66+
SET(YAML_CPP_INSTALL OFF CACHE BOOL "Don't want" FORCE)
67+
SET(MSVC_SHARED_RT OFF CACHE BOOL "want static" FORCE)
68+
69+
add_subdirectory(yaml-cpp)
7270

7371
add_subdirectory(mariadb-connector-c)
7472

7573
CONFIGURE_FILE("${CMAKE_CURRENT_BINARY_DIR}/mariadb-connector-c/include/mariadb_version.h"
7674
"${PROJECT_SOURCE_DIR}/mariadb-connector-c/include/mariadb_version.h")
77-
78-
75+
set(MariaDBClient_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/mariadb-connector-c/include")
76+
set(MariaDBClient_LIBRARY "${PROJECT_SOURCE_DIR}/mariadb-connector-c/libmariadb")
7977

8078
add_subdirectory(mariadbpp)
8179

addons/main/config.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class CfgPatches {
2-
class intercept_template_plugin { //Change this
3-
name = "Intercept Template Plugin"; //Change this
2+
class intercept_database {
3+
name = "Intercept Database";
44
units[] = {};
55
weapons[] = {};
66
requiredVersion = 1.82;
77
requiredAddons[] = {"intercept_core"};
8-
author = "Dedmen"; //Change this
9-
authors[] = {"Dedmen"}; //Change this
10-
url = "https://github.com/intercept/intercept-plugin-template"; //Change this
11-
version = "1.0";
12-
versionStr = "1.0";
13-
versionAr[] = {1,0};
8+
author = "Dedmen";
9+
authors[] = {"Dedmen"};
10+
url = "https://github.com/intercept/intercept-database";
11+
version = "1.5";
12+
versionStr = "1.5";
13+
versionAr[] = {1,5};
1414
};
1515
};
1616
class Intercept {

mariadb-connector-c

src/logger.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ void Logger::logThread(intercept::types::r_string message) {
2828
}
2929

3030
void Logger::pushTimestamp(std::ostream& str) const {
31-
std::time_t t = std::time(0); // get time now
32-
std::tm* now = std::localtime(&t);
33-
3431
auto currentTime = std::chrono::system_clock::now();
3532
auto millisSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(currentTime.time_since_epoch()).count();
3633
auto timeT = std::chrono::system_clock::to_time_t(currentTime);

src/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ void intercept::on_frame() {
5858
for (auto& it : Threading::get().completedAsyncTasks) {
5959
__itt_task_begin(domainMain, __itt_null, __itt_null, main_on_frame_callback);
6060

61-
if (!it->data->callback.is_nil() && it->data->res) {
61+
if (!it->data->callbacks.is_empty() && it->data->res) {
6262
logMessageWithTime("task callback");
6363
auto gd_res = new GameDataDBResult();
6464
gd_res->res = it->data->res;
65-
66-
sqf::call(it->data->callback, { gd_res, it->data->callbackArgs });
65+
for (auto& [code, arg] : it->data->callbacks)
66+
sqf::call(code, { gd_res, arg });
67+
it->data->callbacks.clear();
6768
}
6869
__itt_counter_dec(counter);
6970
__itt_task_end(domainMain);

src/res.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,21 @@ game_value Result::cmd_toParsedArray(game_state& state, game_value_parameter rig
304304
game_value Result::cmd_bindCallback(game_state&, game_value_parameter left, game_value_parameter right) {
305305
auto& res = left.get_as<GameDataDBAsyncResult>();
306306

307-
res->data->callback = right[0];
308-
res->data->callbackArgs = right[1]; //#TODO call directly if result is ready
307+
if (res->data->res) {
308+
auto gd_res = new GameDataDBResult();
309+
gd_res->res = res->data->res;
310+
sqf::call(right[0], { gd_res, right[1] });
311+
return {};
312+
}
313+
res->data->callbacks.push_back({ right[0], right[1] });
309314
return {};
310315
}
311316

312317
game_value Result::cmd_waitForResult(game_state&, game_value_parameter right) {
313318
auto& res = right.get_as<GameDataDBAsyncResult>();
314319

320+
//#TODO suspend in scheduled
321+
315322
res->data->fut.wait();
316323

317324
std::unique_lock l(Threading::get().asyncWorkMutex);
@@ -329,7 +336,12 @@ game_value Result::cmd_waitForResult(game_state&, game_value_parameter right) {
329336

330337
auto gd_res = new GameDataDBResult();
331338
gd_res->res = res->data->res;
332-
sqf::call(res->data->callback, { gd_res, res->data->callbackArgs });
339+
if (!res->data->callbacks.is_empty()) {
340+
for (auto& [code, arg] : res->data->callbacks)
341+
sqf::call(code, { gd_res, arg });
342+
res->data->callbacks.clear();
343+
}
344+
333345
return gd_res;
334346
}
335347

src/res.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ class GameDataDBAsyncResult : public game_data {
114114
std::future<bool> fut;
115115
mariadb::result_set_ref res;
116116
r_string statementName; //Is null if this was not a statement from config
117-
game_value callback;
118-
game_value callbackArgs;
117+
auto_array<std::pair<game_value, game_value>> callbacks;
119118
};
120119
std::shared_ptr<dataT> data;
121120
};

0 commit comments

Comments
 (0)