-
-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#55 add example demonstrating optional columns
- Loading branch information
1 parent
4d129f6
commit e2a5737
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.bake_cache | ||
.DS_Store | ||
.vscode | ||
gcov | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef OPTIONAL_H | ||
#define OPTIONAL_H | ||
|
||
/* This generated file contains includes for project dependencies */ | ||
#include "optional/bake_config.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
) | ||
(.) | ||
.|. | ||
| | | ||
_.--| |--._ | ||
.-'; ;`-'& ; `&. | ||
\ & ; & &_/ | ||
|"""---...---"""| | ||
\ | | | | | | | / | ||
`---.|.|.|.---' | ||
* 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 OPTIONAL_BAKE_CONFIG_H | ||
#define OPTIONAL_BAKE_CONFIG_H | ||
|
||
/* Headers of public dependencies */ | ||
#include <flecs.h> | ||
|
||
/* Headers of private dependencies */ | ||
#ifdef OPTIONAL_IMPL | ||
/* No dependencies */ | ||
#endif | ||
|
||
/* Convenience macro for exporting symbols */ | ||
#ifndef OPTIONAL_STATIC | ||
#if OPTIONAL_IMPL && (defined(_MSC_VER) || defined(__MINGW32__)) | ||
#define OPTIONAL_EXPORT __declspec(dllexport) | ||
#elif OPTIONAL_IMPL | ||
#define OPTIONAL_EXPORT __attribute__((__visibility__("default"))) | ||
#elif defined _MSC_VER | ||
#define OPTIONAL_EXPORT __declspec(dllimport) | ||
#else | ||
#define OPTIONAL_EXPORT | ||
#endif | ||
#else | ||
#define OPTIONAL_EXPORT | ||
#endif | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"id": "optional", | ||
"type": "application", | ||
"value": { | ||
"author": "Jane Doe", | ||
"description": "A simple hello world flecs application", | ||
"public": false, | ||
"use": [ | ||
"flecs" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <optional.h> | ||
|
||
typedef float Health; | ||
typedef float Stamina; | ||
typedef float Mana; | ||
|
||
void Regenerate(ecs_rows_t *rows) { | ||
ECS_COLUMN(rows, Health, health, 1); | ||
ECS_COLUMN(rows, Stamina, stamina, 2); | ||
ECS_COLUMN(rows, Mana, mana, 3); | ||
|
||
for (int i = 0; i < rows->count; i ++) { | ||
if (health) { | ||
health[i] ++; | ||
printf("%d: process health\n", (int)rows->entities[i]); | ||
} | ||
|
||
if (stamina) { | ||
stamina[i] ++; | ||
printf("%d: process stamina\n", (int)rows->entities[i]); | ||
} | ||
|
||
if (mana) { | ||
mana[i] ++; | ||
printf("%d: process mana\n", (int)rows->entities[i]); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
/* Create the world, pass arguments for overriding the number of threads,fps | ||
* or for starting the admin dashboard (see flecs.h for details). */ | ||
ecs_world_t *world = ecs_init_w_args(argc, argv); | ||
|
||
ECS_COMPONENT(world, Health); | ||
ECS_COMPONENT(world, Stamina); | ||
ECS_COMPONENT(world, Mana); | ||
|
||
ECS_SYSTEM(world, Regenerate, EcsOnUpdate, ?Health, ?Stamina, ?Mana); | ||
|
||
/* Create three entities that will all match with the Regenerate system */ | ||
ecs_new(world, Health); | ||
ecs_new(world, Stamina); | ||
ecs_new(world, Mana); | ||
|
||
/* Run systems */ | ||
ecs_progress(world, 0); | ||
|
||
/* Cleanup */ | ||
return ecs_fini(world); | ||
} |