Properly link flecs library
This commit is contained in:
5
engine/libs/flecs/examples/cpp/hello_world/.gitignore
vendored
Normal file
5
engine/libs/flecs/examples/cpp/hello_world/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.bake_cache
|
||||
.DS_Store
|
||||
.vscode
|
||||
gcov
|
||||
bin
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef HELLO_WORLD_H
|
||||
#define HELLO_WORLD_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "hello_world/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef HELLO_WORLD_BAKE_CONFIG_H
|
||||
#define HELLO_WORLD_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
12
engine/libs/flecs/examples/cpp/hello_world/project.json
Normal file
12
engine/libs/flecs/examples/cpp/hello_world/project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "hello_world",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"author": "Jane Doe",
|
||||
"description": "A simple hello world flecs application",
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++"
|
||||
}
|
||||
}
|
||||
50
engine/libs/flecs/examples/cpp/hello_world/src/main.cpp
Normal file
50
engine/libs/flecs/examples/cpp/hello_world/src/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <hello_world.h>
|
||||
#include <iostream>
|
||||
|
||||
// Component types
|
||||
struct Position {
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
// Tag types
|
||||
struct Eats { };
|
||||
struct Apples { };
|
||||
|
||||
int main(int, char *[]) {
|
||||
// Create the world
|
||||
flecs::world ecs;
|
||||
|
||||
// Register system
|
||||
ecs.system<Position, Velocity>()
|
||||
.each([](Position& p, Velocity& v) {
|
||||
p.x += v.x;
|
||||
p.y += v.y;
|
||||
});
|
||||
|
||||
// Create an entity with name Bob, add Position and food preference
|
||||
flecs::entity Bob = ecs.entity("Bob")
|
||||
.set(Position{0, 0})
|
||||
.set(Velocity{1, 2})
|
||||
.add<Eats, Apples>();
|
||||
|
||||
// Show us what you got
|
||||
std::cout << Bob.name() << "'s got [" << Bob.type().str() << "]\n";
|
||||
|
||||
// Run systems twice. Usually this function is called once per frame
|
||||
ecs.progress();
|
||||
ecs.progress();
|
||||
|
||||
// See if Bob has moved (he has)
|
||||
const Position *p = Bob.get<Position>();
|
||||
std::cout << Bob.name() << "'s position is {" << p->x << ", " << p->y << "}\n";
|
||||
|
||||
// Output
|
||||
// Bob's got [Position, Velocity, (Identifier,Name), (Eats,Apples)]
|
||||
// Bob's position is {2, 4}
|
||||
}
|
||||
Reference in New Issue
Block a user