Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add field indexing example #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions noengine-cpp-field-indexing/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git

20 changes: 20 additions & 0 deletions noengine-cpp-field-indexing/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
startup --windows_enable_symlinks
common --enable_bzlmod
common --registry=https://raw.githubusercontent.com/ecsact-dev/bazel_registry/main
common --registry=https://raw.githubusercontent.com/bazelboost/registry/main
common --registry=https://raw.githubusercontent.com/zaucy/bazel-central-registry/add-curl-config2 # temporary
common --registry=https://bcr.bazel.build
build --enable_platform_specific_config
build --incompatible_enable_cc_toolchain_resolution
build --incompatible_strict_action_env
build --enable_runfiles
build --noincompatible_remove_rule_name_parameter
query --noincompatible_remove_rule_name_parameter

build [email protected]//:use_std_fs
query [email protected]//:use_std_fs
build [email protected]//:use_std_fs
query [email protected]//:use_std_fs

try-import %workspace%/user.bazelrc

2 changes: 2 additions & 0 deletions noengine-cpp-field-indexing/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
7.x

99 changes: 99 additions & 0 deletions noengine-cpp-field-indexing/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
IncludeBlocks: Preserve
IncludeIsMainRegex: "(Test)?$"
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PackConstructorInitializers: NextLine
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 400
PenaltyReturnTypeOnItsOwnLine: 350
PointerAlignment: Left
ReflowComments: true
RequiresClausePosition: OwnLine
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SeparateDefinitionBlocks: Always
Standard: Latest
TabWidth: 2
UseTab: ForContinuationAndIndentation
6 changes: 6 additions & 0 deletions noengine-cpp-field-indexing/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

6 changes: 6 additions & 0 deletions noengine-cpp-field-indexing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bazel-*
*.bazel.lock
user.bazelrc
/external
/.cache

61 changes: 61 additions & 0 deletions noengine-cpp-field-indexing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_ecsact//ecsact:defs.bzl", "ecsact_binary", "ecsact_codegen")

ecsact_codegen(
name = "ecsact_cpp_sources",
srcs = glob(["src/**/*.ecsact"]),
output_directory = "generated",
plugins = [
"@ecsact_lang_cpp//cpp_header_codegen",
"@ecsact_lang_cpp//cpp_systems_header_codegen",
"@ecsact_lang_cpp//systems_header_codegen",
"@ecsact_lang_cpp//cpp_systems_source_codegen",
],
)

ecsact_binary(
name = "ecsact_runtime",
srcs = glob(["src/**/*.ecsact"]),
recipes = [
"@ecsact_rt_entt",
],
)

cc_binary(
name = "ecsact-examples-noengine-cpp-sdl2",
srcs = glob(["src/**/*.cc", "src/**/*.hh"]) + [
":ecsact_cpp_sources",
],
copts = selects.with_or({
"@rules_cc//cc/compiler:clang": [
"-std=c++20",
"-fexperimental-library",
],
("@rules_cc//cc/compiler:msvc-cl", "@rules_cc//cc/compiler:clang-cl"): [
"/std:c++20",
"/permissive-",
"/Zc:preprocessor",
],
"//conditions:default": [
"-std=c++20",
],
}),
deps = [
":ecsact_runtime",
"@sdl2",
"@sdl2//:sdl2_main",
"@cute_c2",
"@imgui",
"@imgui//backends:sdlrenderer2",
"@imgui//backends:sdl2",
"@ecsact_runtime//:core",
"@ecsact_lang_cpp//:support",
"@ecsact_lang_cpp//:execution_context",
],
)

alias(
name = "example",
actual = ":ecsact-examples-noengine-cpp-sdl2",
)
66 changes: 66 additions & 0 deletions noengine-cpp-field-indexing/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module(name = "ecsact-examples-noengine-cpp-sdl2")

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "sdl2")
bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
bazel_dep(name = "ecsact_runtime", version = "0.6.2")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_ecsact", version = "0.5.2")
bazel_dep(name = "ecsact_cli", version = "0.3.7")
bazel_dep(name = "ecsact_lang_cpp", version = "0.4.1")
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2")
bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "ecsact_rt_entt", version = "0.3.2")
bazel_dep(name = "cute_c2")
bazel_dep(name = "imgui")

archive_override(
module_name = "cute_c2",
integrity = "sha256-8RRKdXKWnbKziyQ6rKZcIJwsEuRk/q8WP9P1iFCOGfg=",
urls = ["https://github.com/seaube/bazel_cute_headers/releases/download/bazel-cute-headers-2024-05-16/bzlmod_cute_c2_1.10.tar.gz"],
)

git_override(
module_name = "imgui",
commit = "975821a9513e230601b358aea829b9659de13d11",
remote = "https://github.com/zaucy/imgui.git",
)
git_override(
module_name = "sdl2",
commit = "2c8acf0e46f14ebbafe3ec9cc05d7ee4b6d7609f",
remote = "https://github.com/zaucy/sdl.git",
)
git_override(
module_name = "ecsact_rt_entt",
commit = "5ed2115146a9f187dca3c0ff9f8c66fbea09bf23",
remote = "https://github.com/ecsact-dev/ecsact_rt_entt.git",
)

ecsact = use_extension("@rules_ecsact//ecsact:extensions.bzl", "ecsact", dev_dependency = True)
ecsact.toolchain(use_ecsact_cli = True)
use_repo(ecsact, "ecsact_toolchain")

# TODO: https://github.com/bazelbuild/bazel-central-registry/pull/1916
git_override(
module_name = "libarchive",
commit = "7c331f92acea5243c195cdc6fb46ecfa11ce1ce2",
remote = "https://github.com/zaucy/libarchive.git",
)

git_override(
module_name = "hedron_compile_commands",
commit = "204aa593e002cbd177d30f11f54cff3559110bb9",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.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")

register_toolchains(
"@llvm_toolchain//:all",
"@ecsact_toolchain//:all",
dev_dependency = True,
)
10 changes: 10 additions & 0 deletions noengine-cpp-field-indexing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Requirements for running this example:

* [bazel](https://bazel.build/) (preferrably [bazelisk](https://github.com/bazelbuild/bazelisk))

## Running Example

```sh
bazel run //:example -c opt
```

1 change: 1 addition & 0 deletions noengine-cpp-field-indexing/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

107 changes: 107 additions & 0 deletions noengine-cpp-field-indexing/src/example.ecsact
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
main package example;

component Health { f32 value; }
component Position { f32 x; f32 y; }

component Region { i32 x1; i32 y1; i32 x2; i32 y2; }
component WithinRegion {
Region.x1 region_x1;
Region.y1 region_y1;
Region.x2 region_x2;
Region.y2 region_y2;
}

component InfluenceZone { f32 size; }
component WithinInfluenceZone {
Position.x origin_x;
Position.y origin_y;
InfluenceZone.size radius;
}

component Tree;
component Person { i32 seed; }
component EvacuationProbe;

component OnFire { f32 fuel; }
component FireExtinguished;

system SpreadFire {
readwrite OnFire;
readonly WithinInfluenceZone with (origin_x, origin_y, radius) {
adds OnFire;
}
}

system FireDamage {
readwrite OnFire;
readwrite Health;
}

system FireDiminish {
readwrite OnFire;
adds FireExtinguished;
}

system FireExtinguish {
include FireExtinguished;
removes OnFire;
}

action AddRegion {
i32 new_region_x1;
i32 new_region_y1;
i32 new_region_x2;
i32 new_region_y2;

include EvacuationProbe;
readwrite Position;

generates {
required Region;
}
}

system PersonMovementBehaviour {
readwrite Position;
}

system CalcWithinRegionParent(lazy) {
readonly Region;
system CalcWithinRegion {
readwrite WithinRegion;
readonly Position;
}
}

action EvacuateRegion {
i32 mouse_x;
i32 mouse_y;

include EvacuationProbe;
readwrite Position;
}

system StartEvacuation {
include EvacuationProbe;
readonly Position;
readonly WithinRegion;
notify onchange WithinRegion;
}

system Evacuate {
include EvacuationProbe;
readonly WithinRegion with (region_x1, region_y1, region_x2, region_y2) {
readwrite Position;
readwrite Health;
}
}

system RenderPeople {
include Person;
readonly Position;
}

system RenderEvacuationProbe {
include EvacuationProbe;
readonly Position;
}
Loading