Skip to content

Commit 711ea9f

Browse files
committed
feat: transfered from ecsact_runtime
0 parents  commit 711ea9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4066
-0
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests

.bazelrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
startup --windows_enable_symlinks
2+
common --enable_bzlmod
3+
build --registry=https://raw.githubusercontent.com/bazelboost/registry/main
4+
build --registry=https://bcr.bazel.build
5+
build --enable_platform_specific_config
6+
build --incompatible_use_platforms_repo_for_constraints
7+
build --incompatible_enable_cc_toolchain_resolution
8+
build --incompatible_strict_action_env
9+
build --enable_runfiles
10+
build --noincompatible_remove_rule_name_parameter
11+
query --noincompatible_remove_rule_name_parameter
12+
13+
# Temporary until https://github.com/grailbio/bazel-toolchain/pull/198 is merged
14+
build:linux --extra_toolchains=@llvm_toolchain//:cc-toolchain-x86_64-linux
15+
16+
common:ci --announce_rc
17+
common:ci --verbose_failures
18+
common:ci --keep_going
19+
common:ci --disk_cache=~/.cache/bazel-disk-cache
20+
21+
try-import %workspace%/user.bazelrc

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.3.2

.clang-format

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
AccessModifierOffset: -2
2+
AlignAfterOpenBracket: BlockIndent
3+
AlignConsecutiveAssignments: false
4+
AlignConsecutiveDeclarations: true
5+
AlignEscapedNewlines: Left
6+
AlignOperands: DontAlign
7+
AlignTrailingComments: false
8+
AllowAllArgumentsOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: None
13+
AllowShortIfStatementsOnASingleLine: WithoutElse
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: true
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BraceWrapping:
22+
AfterClass: false
23+
AfterControlStatement: false
24+
AfterEnum: false
25+
AfterFunction: false
26+
AfterNamespace: false
27+
AfterStruct: false
28+
AfterUnion: false
29+
AfterExternBlock: false
30+
BeforeCatch: false
31+
BeforeElse: false
32+
IndentBraces: false
33+
SplitEmptyFunction: false
34+
SplitEmptyRecord: false
35+
SplitEmptyNamespace: false
36+
BreakAfterJavaFieldAnnotations: false
37+
BreakBeforeBinaryOperators: None
38+
BreakBeforeBraces: Custom
39+
BreakBeforeInheritanceComma: false
40+
BreakBeforeTernaryOperators: true
41+
BreakConstructorInitializers: BeforeComma
42+
BreakConstructorInitializersBeforeComma: false
43+
BreakStringLiterals: true
44+
ColumnLimit: 80
45+
CompactNamespaces: false
46+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
47+
ConstructorInitializerIndentWidth: 2
48+
ContinuationIndentWidth: 2
49+
Cpp11BracedListStyle: true
50+
DerivePointerAlignment: false
51+
DisableFormat: false
52+
ExperimentalAutoDetectBinPacking: false
53+
FixNamespaceComments: true
54+
IncludeBlocks: Preserve
55+
IncludeIsMainRegex: "(Test)?$"
56+
IndentCaseLabels: true
57+
IndentPPDirectives: AfterHash
58+
IndentWidth: 2
59+
IndentWrappedFunctionNames: false
60+
InsertBraces: true
61+
JavaScriptQuotes: Leave
62+
JavaScriptWrapImports: true
63+
KeepEmptyLinesAtTheStartOfBlocks: false
64+
MacroBlockBegin: ""
65+
MacroBlockEnd: ""
66+
MaxEmptyLinesToKeep: 1
67+
NamespaceIndentation: None
68+
PackConstructorInitializers: NextLine
69+
PenaltyBreakAssignment: 10
70+
PenaltyBreakBeforeFirstCallParameter: 30
71+
PenaltyBreakComment: 10
72+
PenaltyBreakFirstLessLess: 0
73+
PenaltyBreakString: 10
74+
PenaltyExcessCharacter: 400
75+
PenaltyReturnTypeOnItsOwnLine: 350
76+
PointerAlignment: Left
77+
ReflowComments: true
78+
RequiresClausePosition: OwnLine
79+
SortIncludes: false
80+
SortUsingDeclarations: true
81+
SpaceAfterCStyleCast: false
82+
SpaceAfterLogicalNot: false
83+
SpaceAfterTemplateKeyword: false
84+
SpaceBeforeAssignmentOperators: true
85+
SpaceBeforeCtorInitializerColon: true
86+
SpaceBeforeInheritanceColon: true
87+
SpaceBeforeParens: Never
88+
SpaceBeforeRangeBasedForLoopColon: true
89+
SpaceInEmptyParentheses: false
90+
SpacesBeforeTrailingComments: 1
91+
SpacesInAngles: Never
92+
SpacesInContainerLiterals: false
93+
SpacesInCStyleCastParentheses: false
94+
SpacesInParentheses: false
95+
SpacesInSquareBrackets: false
96+
SeparateDefinitionBlocks: Always
97+
Standard: Latest
98+
TabWidth: 2
99+
UseTab: ForContinuationAndIndentation

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# bazel
2+
bazel-*
3+
user.bazelrc
4+
5+
# dev stuff
6+
compile_commands.json
7+
external
8+
.cache/
9+
.vs

BUILD.bazel

Whitespace-only changes.

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module(name = "ecsact_rt_reference")
2+
3+
bazel_dep(name = "rules_cc", version = "0.0.8")
4+
bazel_dep(name = "ecsact_runtime")
5+
bazel_dep(name = "ecsact_codegen")
6+
7+
git_override(
8+
module_name = "ecsact_codegen",
9+
remote = "https://github.com/ecsact-dev/ecsact_codegen",
10+
commit = "d947cb8bef1c488d814dc2b43bd4a0ab982572cd",
11+
)

WORKSPACE.bazel

Whitespace-only changes.

async_reference/BUILD.bazel

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@ecsact_runtime//bazel:copts.bzl", "copts")
3+
4+
package(default_visibility = ["//visiblity:public"])
5+
6+
exports_files([
7+
"async_reference.hh",
8+
"async_reference.cc",
9+
"async.cc",
10+
])
11+
12+
cc_library(
13+
name = "async_reference",
14+
srcs = ["async_reference.cc"],
15+
hdrs = ["async_reference.hh"],
16+
copts = copts,
17+
linkstatic = True,
18+
visibility = ["//visibility:public"],
19+
deps = [
20+
"//:async",
21+
"//:core",
22+
"//async_reference/callbacks:async_callbacks",
23+
"//async_reference/callbacks:execution_callbacks",
24+
"//async_reference/detail/c_execution_options",
25+
"//async_reference/request_id_factory",
26+
"//async_reference/tick_manager",
27+
"//async_reference/util",
28+
"//async_reference/util:types",
29+
],
30+
)
31+
32+
cc_library(
33+
name = "async",
34+
srcs = ["async.cc"],
35+
copts = copts,
36+
defines = ["ECSACT_ASYNC_API_EXPORT="],
37+
visibility = ["//visibility:public"],
38+
deps = [
39+
":async_reference",
40+
"//:async",
41+
],
42+
)
43+
44+
filegroup(
45+
name = "sources",
46+
srcs = glob([
47+
"**/*.cc",
48+
"**/*.hh",
49+
]) + [
50+
"//async_reference/callbacks:callback_source",
51+
"//async_reference/detail/c_execution_options:c_execution_source",
52+
"//async_reference/tick_manager:tick_source",
53+
"//async_reference/util:util_source",
54+
"//async_reference/request_id_factory:sources",
55+
"//serialize_reference:serialize_source",
56+
],
57+
visibility = ["//visibility:public"],
58+
)

async_reference/async.cc

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <optional>
2+
3+
#include "ecsact/runtime/async.h"
4+
#include "async_reference.hh"
5+
#include "callbacks/async_callbacks.hh"
6+
#include "request_id_factory/request_id_factory.hh"
7+
8+
using namespace ecsact::async_reference;
9+
10+
// NOTE: These are the singletons for managing the reference library state.
11+
// This file should be small. Declare a few variables and call a few
12+
// functions in the C function bodies. Keep the logic minimal.
13+
static auto async_callbacks = detail::async_callbacks{};
14+
static auto request_id_factory = detail::request_id_factory{};
15+
static auto reference = std::optional<detail::async_reference>{};
16+
17+
ecsact_async_request_id ecsact_async_connect(const char* connection_string) {
18+
auto req_id = request_id_factory.next_id();
19+
reference.emplace(async_callbacks);
20+
reference->connect(req_id, connection_string);
21+
return req_id;
22+
}
23+
24+
void ecsact_async_disconnect() {
25+
if(reference) {
26+
reference->disconnect();
27+
reference.reset();
28+
}
29+
}
30+
31+
void ecsact_async_flush_events(
32+
const ecsact_execution_events_collector* execution_evc,
33+
const ecsact_async_events_collector* async_evc
34+
) {
35+
async_callbacks.invoke(async_evc);
36+
if(reference) {
37+
reference->invoke_execution_events(execution_evc);
38+
}
39+
}
40+
41+
ecsact_async_request_id ecsact_async_enqueue_execution_options(
42+
const ecsact_execution_options options
43+
) {
44+
auto req_id = request_id_factory.next_id();
45+
if(!reference) {
46+
async_callbacks.add(detail::types::async_error{
47+
.error = ECSACT_ASYNC_ERR_NOT_CONNECTED,
48+
.request_ids = {req_id},
49+
});
50+
return req_id;
51+
}
52+
53+
reference->enqueue_execution_options(req_id, options);
54+
return req_id;
55+
}
56+
57+
int32_t ecsact_async_get_current_tick() {
58+
if(reference) {
59+
return reference->get_current_tick();
60+
}
61+
return 0;
62+
}

0 commit comments

Comments
 (0)