Properly link flecs library

This commit is contained in:
2023-11-09 11:38:29 +01:00
parent dc585396c3
commit 8edcf9305c
1392 changed files with 390081 additions and 164 deletions

View File

@@ -0,0 +1,12 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("anonymous_entity.flecs");
// To create an entity without a name, use the _ character
_ :- SpaceShip
// Anonymous entities can be used as parents and children
SpaceShip _ {
_ :- Engine
}

View File

@@ -0,0 +1,20 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("docs.flecs");
// Plecs files can be used to annotate entities and components with
// documentation. These annotations use the flecs.doc addon.
@brief A brief description of planet Earth
@name The Earth
Earth {
- Planet
}
// Annotations can be created for entities definfed elsewhere. This makes it
// possible to have a file separate from source code where you annotate your
// prefabs, components and entities with documentation
@brief The Position component
Position

View File

@@ -0,0 +1,30 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("expressions.flecs");
using flecs.meta
// Create component types, see reflection example
Struct Position {
x :- {f32}
y :- {f32}
}
Struct Rectangle {
width :- {f32}
height :- {f32}
}
// Plecs files can contain variables that can be referenced later on when
// assigning values to components
const width = 5
// Variables and components can be assigned using expressions. Most arithmetic
// and conditional operators are supported.
const height = $width * 2
e {
- Position{0, -($height / 2)}
- Rectangle{$width, $height}
}

View File

@@ -0,0 +1,43 @@
// Plecs is a simple language for loading entities into flecs. It has as
// advantage that it natively integrates with Flecs features such as the
// reflection addon (meta), prefabs, hierarchies and relationships.
//
// The syntax has been designed to make it convenient for use cases like:
// - configuration files
// - asset descriptions (such as prefabs)
// - entity hierarchies/scene graphs
//
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("hello_world.flecs");
// This creates an entity my_spaceship with the SpaceShip tag. Note how neither
// the entity nor tag need to be defined in advance, if an entity did not yet
// exist, it will be created on the spot.
my_spaceship :- SpaceShip
// An entity can be declared in advance, which can be useful to ensure it is
// placed in a specific scope. To do this just specify the name:
Engine
// By opening a scope multiple components/tags can be added to the same entity
// without having to repeat the entity name.
my_spaceship {
- Freighter
- (Faction, Earth) // Relationships use the same syntax as the query DSL
}
// A scope can also be used to add child entities. Child entities and components
// can be added in the same scope.
my_spaceship {
- FasterThanLight
// This creates an engine entity with my_spaceship as parent
engine {
- Engine // The Engine tag is added to my_spaceship.engine
}
}
// The dot notation can be used to refer to nested entities
my_spaceship.engine :- Ftl

View File

@@ -0,0 +1,35 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("prefabs.flecs");
// Create a component types (see reflection.flecs example)
using flecs.meta
Struct Attack {
value :- {f32}
}
Struct Defense {
value :- {f32}
}
// To create a prefab, you can create an entity with the Prefab tag:
SpaceShip :- Prefab
// Alternatively you can use the shorthand declaration syntax which has the same
// result, and allows you to open a scope after the statement:
Prefab SpaceShip {
- Attack{50}
- Defense{50}
}
// To create a prefab that inherits from SpaceShip, we can use the : operator
Prefab Freighter : SpaceShip {
- Defense{100}
}
// We can create a prefab instance with the same : operator.
my_spaceship : Freighter {
- Attack{75} // Override component from SpaceShip
}

View File

@@ -0,0 +1,48 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("reflection.flecs");
// It is possible to set component values in a plecs file as long as the
// component is described with reflection data. Since we don't have a component
// yet, we'll first have to create one.
// Plecs does not have dedicated syntax for describing types, but since the
// reflection addon (flecs.meta) uses regular entities and components to store
// reflection data, we can use existing plecs syntax to create a type.
// First we'll add flecs.meta to the list of namespaces to search. This is not
// strictly necessary, but lets us write Struct instead of flecs.meta.Struct
using flecs.meta
// We can now create a struct like this. "Struct Position" is the shorthand
// declaration syntax for "Position :- Struct", and has as benefit that we can
// open a scope after the statement
Struct Position {
// Add two child entities with the Member component
x :- Member{type: f32}
y :- Member{type: f32}
}
// Plecs has a feature which makes it possible to specify a default type for a
// scope. The Struct component has Member as default type. This means we can
// also create a type like this, which is a bit shorter:
Struct Mass {
value :- {f32} // 'type' can be ommitted since it's the first member
}
// Similarly we can also define an enumeration type. The default scope type for
// Enum is Constant, which ensures amongst others that the child entities will
// be assigned with an incremenenting constant value automatically.
Enum Color {
Red
Green
Blue
}
// We can now create an entity that uses the types
my_entity {
- Position {x: 10, y: 20}
- Mass {100} // Member names are optional
- Color {Green} // Green will be automatically looked up in the Color scope
}

View File

@@ -0,0 +1,35 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("strings.flecs");
// Plecs component values can be populated with strings. To see how this works,
// we first need to create a component type (see reflection example).
using flecs.meta
Struct Shader {
filename :- {string}
code :- {string}
}
// Create component values with strings
my_pipeline {
- (Shader, Vertex) {
// Normal string
filename: "vert.glsl",
// Multiline string
code: `
void main() {
gl_Position = pos;
}`
}
- (Shader, Fragment) {
filename: "frag.glsl",
code: `
void main() {
frag_color = color;
}`
}
}

View File

@@ -0,0 +1,36 @@
// To see what the result of parsing this file looks like, copy the code and
// paste it into the editor at https://flecs.dev/explorer
//
// To load this file yourself, call ecs_plecs_from_file("with.flecs");
// Sometimes you want to add the same component to a lot of entities. To avoid
// repeating yourself, you can use the "with" keyword:
with Planet {
// With statements can be nested, which adds to the list of components to add
with InnerPlanet {
Mercury
Venus
Earth {
// A with scope contains regular statements so we can do anything we can
// do normally, like assign components and open scopes.
- SupportsLife
}
Mars
}
with OuterPlanet {
Jupiter
Saturn
Neptune
Uranus
}
}
// A with statement may be placed inside of a scope
Jupiter {
with Moon {
Io
Europa
Ganymede
Callisto
}
}