From b69e1ba1039cf3523a3312e586756ce3edd8aefb Mon Sep 17 00:00:00 2001 From: shmocz <112764837+shmocz@users.noreply.github.com> Date: Tue, 19 Sep 2023 07:27:33 +0300 Subject: [PATCH] feat: Add get_async_cmd helper --- src/command/is_command.hpp | 11 ++++++++++- src/commands_yr.cpp | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/command/is_command.hpp b/src/command/is_command.hpp index f1419ec..7f7caca 100644 --- a/src/command/is_command.hpp +++ b/src/command/is_command.hpp @@ -83,9 +83,12 @@ struct ISCommand { template std::pair get_cmd( - std::function*)> fn) { + std::function*)> fn, bool async = false) { return {MessageT().GetTypeName(), [=](iservice_cmd* c) { ISCommand Q(c); + if (async) { + Q.async(); + } try { dprintf("exec {} ", MessageT().GetTypeName()); fn(&Q); @@ -96,6 +99,12 @@ std::pair get_cmd( }}; } +template +std::pair get_async_cmd( + std::function*)> fn) { + return get_cmd(fn, true); +} + /// /// Unpacks the message stored in cmd->result() to appropriate message type, and /// returns pointer to the result and instance of the message. diff --git a/src/commands_yr.cpp b/src/commands_yr.cpp index b7bd68e..193c9a0 100644 --- a/src/commands_yr.cpp +++ b/src/commands_yr.cpp @@ -22,6 +22,7 @@ #include #include +using ra2yrcpp::command::get_async_cmd; using ra2yrcpp::command::get_cmd; using ra2yrcpp::command::message_result; @@ -187,9 +188,8 @@ auto mission_clicked() { } auto add_event() { - return get_cmd([](auto* Q) { + return get_async_cmd([](auto* Q) { auto args = Q->command_data(); - Q->async(); put_gameloop_command(Q, [args](auto* it) { const auto frame_delay = args.frame_delay(); @@ -247,7 +247,7 @@ auto add_event() { } auto place_query() { - return get_cmd([](auto* Q) { + return get_async_cmd([](auto* Q) { auto args = Q->command_data(); if (static_cast(args.coordinates().size()) > cfg::PLACE_QUERY_MAX_LENGTH) { @@ -256,7 +256,6 @@ auto place_query() { args.coordinates().size() - cfg::PLACE_QUERY_MAX_LENGTH); wrprintf("truncated place query to size {}", args.coordinates().size()); } - Q->async(); put_gameloop_command(Q, [args](auto* it) { auto [C, cmd, fn] = *it;