Skip to content

Commit 93425b2

Browse files
authored
v0.0.1
v0.0.1
2 parents 1eddb6e + 8ab2f03 commit 93425b2

File tree

5 files changed

+2978
-9
lines changed

5 files changed

+2978
-9
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
language: node_js
2+
branches:
3+
only:
4+
- develop
25
node_js:
36
- node
47
script:

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ it out.
4848

4949
## Local Link
5050

51-
In order to link this package to another one, you can either use `npm install`
52-
with a local path, or `npm link`.
51+
In order to link this package to another one, you can either use `yarn add file:[PATH_TO_FLECS]`
52+
with a local path, or `yarn link`.
5353

5454
Just be careful: the package that is published (and so that you should link)
5555
is in the `dist` folder.

README.md

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# flecs
1+
# Flecs
2+
3+
[![Build Status](https://travis-ci.com/DavidPeicho/flecs.svg?branch=main)](https://travis-ci.com/DavidPeicho/flecs)
4+
25

36
> 🚧 Flecs is a work-in-progress and might be unstable, use it at your
47
> own risks 🚧
58
69
Fast & Flexible EntityComponentSystem (ECS) for JavaScript and Typescript, available in browser and Node.js.
710

811
Get started with:
9-
* The [Documentation](./doc.md)
10-
* The [Examples](./examples)
12+
* The [Documentation](./DOC.md)
13+
* The [Examples](./example)
1114

1215
> 🔍 I am currently looking for people to help me to identify their needs in order to drive the development of this [library further](#stable-version).
1316
@@ -35,14 +38,117 @@ The library will prioritize stability improvements over feature development.
3538
* System Grouping
3639
* System Topological Sorting
3740
* Automatic Component Registration
41+
* Component Properties Merging
42+
* System Queries Merging
3843
* TypeScript Decorators
3944
* For component properties
4045
* For system ordering and configuration
4146

47+
## Install
48+
49+
Using npm:
50+
51+
```sh
52+
npm install flecs
53+
```
54+
55+
Using yarn
56+
57+
```sh
58+
yarn add flecs
59+
```
60+
61+
The library is distributed as an ES6 module, but also comes with two UMD builds:
62+
* `fecs/umd/fecs.js` → Development build with debug assertions
63+
* `fecs/umd/fecs.min.js` → Minified production build, without debug assertions
64+
4265
## Usage Example
4366

4467
```js
45-
class Component {}
68+
import {
69+
ComponentData,
70+
TagComponent,
71+
NumberProp,
72+
RefProp,
73+
World
74+
} from 'flecs';
75+
76+
/**
77+
* Components definition.
78+
*/
79+
80+
class Position2D extends ComponentData {}
81+
Position2D.Properties = {
82+
x: NumberProp(),
83+
y: NumberProp()
84+
};
85+
86+
class FollowTarget extends ComponentData {}
87+
FollowTarget.Properties = {
88+
target: RefProp(),
89+
speed: NumberProp(1.0)
90+
};
91+
92+
class PlayerTag extends TagComponent {}
93+
class ZombieTag extends TagComponent {}
94+
95+
/**
96+
* Systems definition.
97+
*/
98+
99+
class ZombieFollowSystem extends System {
100+
101+
execute(delta) {
102+
this.queries.zombies.execute((entity) => {
103+
const { speed, target } = entity.read(FollowTarget);
104+
const position = entity.write(Position2D);
105+
const deltaX = target.x - position.x;
106+
const deltaY = target.y - position.y;
107+
const len = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
108+
if (len >= 0.00001) {
109+
position.x += speed * delta * (deltaX / len);
110+
position.y += speed * delta * (deltaY / len);
111+
}
112+
});
113+
}
114+
115+
}
116+
ZombieFollowSystem.Queries = {
117+
// Select entities with all three components `ZombieTag`, `FollowTarget`, and
118+
// `Position2D`.
119+
zombies: [ZombieTag, FollowTarget, Position2D]
120+
}
121+
122+
const world = new World();
123+
124+
// Creates a player entity.
125+
const playerEntity = world.create().add(PlayerTag).add(Position2D);
126+
const playerPosition = playerEntity.read();
127+
128+
// Creates 100 zombies at random positions with a `FollowTarget` component that
129+
// will make them follow our player.
130+
for (let i = 0; i < 100; ++i) {
131+
world.create()
132+
.add(ZombieTag)
133+
.add(Position2D, {
134+
x: Math.floor(Math.random() * 50.0) - 100.0,
135+
y: Math.floor(Math.random() * 50.0) - 100.0
136+
})
137+
.add(FollowTarget, { target: playerPosition })
138+
}
139+
140+
// Runs the animation loop and execute all systems every frame.
141+
142+
let lastTime = 0.0;
143+
function loop() {
144+
const currTime = performance.now();
145+
const deltaTime = currTime - lastTime;
146+
lastTime = currTime;
147+
world.execute(deltaTime);
148+
requestAnimationFrame(loop);
149+
}
150+
lastTime = performance.now();
151+
loop();
46152
```
47153

48154
## Stable Version
@@ -61,7 +167,7 @@ Please feel free to reach out directly in the [Github Issues](https://github.com
61167

62168
## Benchmarks
63169

64-
TODO
170+
Coming soon.
65171

66172
## Contributing
67173

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "fecs",
2+
"name": "flecs",
33
"version": "0.0.1",
44
"description": "Fast & Flexible EntityComponentSystem (ECS) for JavaScript & TypeScript",
55
"repository": {
@@ -10,7 +10,8 @@
1010
"license": "MIT",
1111
"keywords": [
1212
"ecs",
13-
"entity component system"
13+
"entity component system",
14+
"game"
1415
],
1516
"type": "module",
1617
"main": "./umd/fecs.js",

0 commit comments

Comments
 (0)