Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef EXCLUSIVE_RELATIONS_H
|
||||
#define EXCLUSIVE_RELATIONS_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "exclusive_relations/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 EXCLUSIVE_RELATIONS_BAKE_CONFIG_H
|
||||
#define EXCLUSIVE_RELATIONS_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"id": "exclusive_relations",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include <exclusive_relations.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
|
||||
|
||||
ECS_TAG(ecs, Platoon);
|
||||
|
||||
// Register Platoon as exclusive relationship. This ensures that an entity
|
||||
// can only belong to a single Platoon.
|
||||
ecs_add_id(ecs, Platoon, EcsExclusive);
|
||||
|
||||
// Create two platoons
|
||||
ecs_entity_t platoon_1 = ecs_new_id(ecs);
|
||||
ecs_entity_t platoon_2 = ecs_new_id(ecs);
|
||||
|
||||
// Create a unit
|
||||
ecs_entity_t unit = ecs_new_id(ecs);
|
||||
|
||||
// Add unit to platoon 1
|
||||
ecs_add_pair(ecs, unit, Platoon, platoon_1);
|
||||
|
||||
// Log platoon of unit
|
||||
printf("Unit in platoon 1: %s\n",
|
||||
ecs_has_pair(ecs, unit, Platoon, platoon_1) ? "true" : "false");
|
||||
printf("Unit in platoon 2: %s\n\n",
|
||||
ecs_has_pair(ecs, unit, Platoon, platoon_2) ? "true" : "false");
|
||||
|
||||
// Add unit to platoon 2. Because Platoon is an exclusive relationship, this
|
||||
// both removes (Platoon, platoon_1) and adds (Platoon, platoon_2) in a
|
||||
// single operation.
|
||||
ecs_add_pair(ecs, unit, Platoon, platoon_2);
|
||||
|
||||
printf("Unit in platoon 1: %s\n",
|
||||
ecs_has_pair(ecs, unit, Platoon, platoon_1) ? "true" : "false");
|
||||
printf("Unit in platoon 2: %s\n",
|
||||
ecs_has_pair(ecs, unit, Platoon, platoon_2) ? "true" : "false");
|
||||
|
||||
// Output:
|
||||
// Unit in platoon 1: true
|
||||
// Unit in platoon 2: false
|
||||
//
|
||||
// Unit in platoon 1: false
|
||||
// Unit in platoon 2: true
|
||||
|
||||
return ecs_fini(ecs);
|
||||
}
|
||||
Reference in New Issue
Block a user