Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ git_override(
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

git_override(
module_name = "ecsact_runtime",
commit = "9dcfb4bc18baf4cbaddc7124f02830a424945a64",
remote = "https://github.com/ecsact-dev/ecsact_runtime.git",
)

ecsact = use_extension("@rules_ecsact//ecsact:extensions.bzl", "ecsact", dev_dependency = True)
ecsact.toolchain(use_ecsact_cli = True)
use_repo(ecsact, "ecsact_toolchain")
Expand Down
1 change: 1 addition & 0 deletions async_reference/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ecsact_build_recipe(
"ecsact_async_disconnect",
"ecsact_async_enqueue_execution_options",
"ecsact_async_flush_events",
"ecsact_async_get_status",
"ecsact_async_get_current_tick",
],
)
Expand Down
24 changes: 24 additions & 0 deletions async_reference/async.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace ecsact::async_reference;
static auto async_callbacks = detail::async_callbacks{};
static auto request_id_factory = detail::request_id_factory{};
static auto reference = std::optional<detail::async_reference>{};
static auto last_status = ECSACT_ASYNC_STATUS_NONE;

ecsact_async_request_id ecsact_async_connect(const char* connection_string) {
auto req_id = request_id_factory.next_id();
Expand All @@ -32,12 +33,35 @@ void ecsact_async_flush_events(
const ecsact_execution_events_collector* execution_evc,
const ecsact_async_events_collector* async_evc
) {
auto current_status = ecsact_async_get_status();
if(current_status != last_status) {
last_status = current_status;
if(async_evc && async_evc->async_status_change_callback) {
async_evc->async_status_change_callback(
current_status,
async_evc->async_status_change_callback_user_data
);
}
}

async_callbacks.invoke(async_evc);
if(reference) {
reference->invoke_execution_events(execution_evc);
}
}

ecsact_async_status ecsact_async_get_status() {
if(!reference) {
return ECSACT_ASYNC_STATUS_NONE;
}

if(reference->is_connected()) {
return ECSACT_ASYNC_STATUS_CONNECTED;
} else {
return ECSACT_ASYNC_STATUS_PENDING;
}
}

ecsact_async_request_id ecsact_async_enqueue_execution_options(
const ecsact_execution_options options
) {
Expand Down
18 changes: 11 additions & 7 deletions async_reference/async_reference.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ static auto parse_connection_string(std::string_view str
return result;
}

bool async_reference::is_connected() const {
return is_connected_;
}

void async_reference::connect(
ecsact_async_request_id req_id,
const char* connection_string
Expand All @@ -74,7 +78,7 @@ void async_reference::connect(

// The good and bad strings simulate the outcome of connections
if(result.host != "good") {
is_connected = false;
is_connected_ = false;

async_callbacks.add(types::async_error{
.error = ECSACT_ASYNC_ERR_PERMISSION_DENIED,
Expand All @@ -100,7 +104,7 @@ void async_reference::connect(
}

registry_id = ecsact_create_registry("async_reference_impl_reg");
is_connected = true;
is_connected_ = true;
async_callbacks.add(types::async_request_complete{
.request_ids = {req_id},
});
Expand All @@ -111,7 +115,7 @@ void async_reference::enqueue_execution_options(
ecsact_async_request_id req_id,
const ecsact_execution_options& options
) {
if(!is_connected) {
if(!is_connected_) {
async_callbacks.add(types::async_error{
.error = ECSACT_ASYNC_ERR_NOT_CONNECTED,
.request_ids = {req_id},
Expand Down Expand Up @@ -140,7 +144,7 @@ void async_reference::execute_systems() {

nanoseconds execution_duration = {};

while(is_connected == true) {
while(is_connected_ == true) {
auto event = tick_manager.validate_pending_options();

std::visit(
Expand All @@ -159,7 +163,7 @@ void async_reference::execute_systems() {
.request_ids = err->request_ids,
});

is_connected = false;
is_connected_ = false;
break;
}

Expand Down Expand Up @@ -192,7 +196,7 @@ void async_reference::execute_systems() {

if(systems_error != ECSACT_EXEC_SYS_OK) {
async_callbacks.add(systems_error);
is_connected = false;
is_connected_ = false;
return;
}
}
Expand All @@ -212,7 +216,7 @@ int32_t async_reference::get_current_tick() {
}

void async_reference::disconnect() {
is_connected = false;
is_connected_ = false;
if(execution_thread.joinable()) {
execution_thread.join();
}
Expand Down
4 changes: 3 additions & 1 deletion async_reference/async_reference.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public:

void disconnect();

bool is_connected() const;

private:
std::atomic_int32_t _last_request_id = 0;

Expand All @@ -48,7 +50,7 @@ private:
std::thread execution_thread;
std::mutex execution_m;

std::atomic_bool is_connected = false;
std::atomic_bool is_connected_ = false;

std::chrono::milliseconds delta_time = {};
};
Expand Down
8 changes: 7 additions & 1 deletion test/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module(name = "ecsact_rt_reference_test")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.6")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.7")
bazel_dep(name = "ecsact_runtime", version = "0.6.7")
bazel_dep(name = "rules_ecsact", version = "0.5.6")
bazel_dep(name = "ecsact_cli", version = "0.3.16")
Expand All @@ -25,6 +25,12 @@ git_override(
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

git_override(
module_name = "ecsact_runtime",
commit = "9dcfb4bc18baf4cbaddc7124f02830a424945a64",
remote = "https://github.com/ecsact-dev/ecsact_runtime.git",
)

llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)
llvm.toolchain(llvm_version = "17.0.6")
use_repo(llvm, "llvm_toolchain")
Expand Down