Properly link flecs library
This commit is contained in:
7
engine/libs/flecs/examples/build/bazel/BUILD
Normal file
7
engine/libs/flecs/examples/build/bazel/BUILD
Normal file
@@ -0,0 +1,7 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
cc_binary(
|
||||
name = "example",
|
||||
srcs = ["main.cpp"],
|
||||
deps = ["@flecs//:flecs"]
|
||||
)
|
||||
22
engine/libs/flecs/examples/build/bazel/README.md
Normal file
22
engine/libs/flecs/examples/build/bazel/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
You can include the flecs repository in your `WORKSPACE` with:
|
||||
|
||||
```bazel
|
||||
git_repository(
|
||||
name = "flecs",
|
||||
remote = "https://github.com/SanderMertens/flecs",
|
||||
commit = "f150d96ba9ea8be2b24dbf2217368c231cb17720", # v2.3.2+merge329
|
||||
shallow_since = "1615075784 -0800",
|
||||
)
|
||||
```
|
||||
|
||||
And then add it to your `BUILD` with:
|
||||
|
||||
```bazel
|
||||
deps = ["@flecs//:flecs"]
|
||||
```
|
||||
|
||||
This directory contains a complete example of this usage. To try it you can run the following from your terminal:
|
||||
|
||||
```
|
||||
bazel run example
|
||||
```
|
||||
8
engine/libs/flecs/examples/build/bazel/WORKSPACE
Normal file
8
engine/libs/flecs/examples/build/bazel/WORKSPACE
Normal file
@@ -0,0 +1,8 @@
|
||||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
|
||||
|
||||
git_repository(
|
||||
name = "flecs",
|
||||
remote = "https://github.com/SanderMertens/flecs",
|
||||
commit = "f150d96ba9ea8be2b24dbf2217368c231cb17720", # v2.3.2+merge329
|
||||
shallow_since = "1615075784 -0800",
|
||||
)
|
||||
43
engine/libs/flecs/examples/build/bazel/main.cpp
Normal file
43
engine/libs/flecs/examples/build/bazel/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "flecs.h"
|
||||
#include <iostream>
|
||||
|
||||
/* Component types */
|
||||
struct Position {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
flecs::world world(argc, argv);
|
||||
|
||||
flecs::component<Position>(world, "Position");
|
||||
flecs::component<Velocity>(world, "Velocity");
|
||||
|
||||
flecs::system<Position, const Velocity>(world)
|
||||
.iter([](const flecs::iter& it,
|
||||
Position *p,
|
||||
const Velocity *v)
|
||||
{
|
||||
for (auto row : it) {
|
||||
p[row].x += v[row].x;
|
||||
p[row].y += v[row].y;
|
||||
|
||||
std::cout << "Moved " << it.entity(row).name() << " to {" <<
|
||||
p[row].x << ", " << p[row].y << "}" << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
flecs::entity(world, "MyEntity")
|
||||
.set<Position>({0, 0})
|
||||
.set<Velocity>({1, 1});
|
||||
|
||||
world.set_target_fps(1);
|
||||
|
||||
std::cout << "Application move_system is running, press CTRL-C to exit..." << std::endl;
|
||||
|
||||
/* Run systems */
|
||||
while (world.progress()) { }
|
||||
}
|
||||
13
engine/libs/flecs/examples/build/cmake/CMakeLists.txt
Normal file
13
engine/libs/flecs/examples/build/cmake/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
cmake_minimum_required (VERSION 2.8.7)
|
||||
|
||||
project (cmake_example)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
add_subdirectory (flecs)
|
||||
|
||||
add_executable(cmake_example main.cpp)
|
||||
add_executable(cmake_example_static main.cpp)
|
||||
|
||||
target_link_libraries(cmake_example flecs)
|
||||
target_link_libraries(cmake_example_static flecs_static)
|
||||
1
engine/libs/flecs/examples/build/cmake/README.md
Normal file
1
engine/libs/flecs/examples/build/cmake/README.md
Normal file
@@ -0,0 +1 @@
|
||||
For this to work, flecs needs to be a subdirectory of the example.
|
||||
40
engine/libs/flecs/examples/build/cmake/main.cpp
Normal file
40
engine/libs/flecs/examples/build/cmake/main.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "flecs.h"
|
||||
#include <iostream>
|
||||
|
||||
/* Component types */
|
||||
struct Position {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
flecs::world ecs(argc, argv);
|
||||
|
||||
ecs.system<Position, const Velocity>()
|
||||
.iter([](const flecs::iter& it,
|
||||
Position *p,
|
||||
const Velocity *v)
|
||||
{
|
||||
for (auto row : it) {
|
||||
p[row].x += v[row].x;
|
||||
p[row].y += v[row].y;
|
||||
|
||||
std::cout << "Moved " << it.entity(row).name() << " to {" <<
|
||||
p[row].x << ", " << p[row].y << "}" << std::endl;
|
||||
}
|
||||
});
|
||||
|
||||
ecs.entity("MyEntity")
|
||||
.set<Position>({0, 0})
|
||||
.set<Velocity>({1, 1});
|
||||
|
||||
ecs.set_target_fps(1);
|
||||
|
||||
std::cout << "Application move_system is running, press CTRL-C to exit..." << std::endl;
|
||||
|
||||
/* Run systems */
|
||||
while (ecs.progress()) { }
|
||||
}
|
||||
Reference in New Issue
Block a user