Skip to content

Commit 88c476a

Browse files
committed
v1.0.0
1 parent 07a37ed commit 88c476a

File tree

8 files changed

+476
-266
lines changed

8 files changed

+476
-266
lines changed

README.md

+48-13
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
kult :fire: <a href="https://travis-ci.org/r-lyeh/kult"><img src="https://api.travis-ci.org/r-lyeh/kult.svg?branch=master" align="right" /></a>
1+
kult :crystal_ball: <a href="https://travis-ci.org/r-lyeh/kult"><img src="https://api.travis-ci.org/r-lyeh/kult.svg?branch=master" align="right" /></a>
22
====
33

4-
- Kult is a lightweight entity/component/system library written in C++11.
5-
- Kult is tiny.
6-
- Kult is header-only.
7-
- Kult is expressive.
8-
- Kult has no dependencies.
9-
- Kult is zlib/libpng licensed.
4+
Kult is a lightweight entity/component/system library (C++11).
105

11-
### sample
6+
## Features
7+
- [x] Expressive.
8+
- [x] Tiny, cross-platform, self-contained, header-only.
9+
- [x] ZLIB/libPNG licensed.
10+
11+
### Showcase
1212
```c++
1313
#include <iostream>
1414
#include "kult.hpp"
@@ -32,12 +32,11 @@ kult::component<'pos2', vec2> position;
3232
kult::component<'vel2', vec2> velocity;
3333

3434
// systems
35-
kult::system movement = [&]( double t, float dt ) {
35+
kult::system<float> movement = [&]( float dt ) {
3636
for( auto &entity : kult::join( position, velocity ) ) {
3737
entity[ position ].x += entity[ velocity ].x * dt;
3838
entity[ position ].y += entity[ velocity ].y * dt;
3939
}
40-
return true;
4140
};
4241

4342
// app
@@ -54,13 +53,49 @@ int main(int argc, const char **argv) {
5453

5554
// simulate 100 frames
5655
for( int i = 0; i < 100; ++i ) {
57-
movement(0, 1/60.f);
56+
movement( 1/60.f );
5857
}
5958

6059
// print status
61-
std::cout << player.str() << std::endl;
62-
std::cout << enemy.str() << std::endl;
60+
std::cout << player.dump() << std::endl;
61+
std::cout << enemy.dump() << std::endl;
62+
63+
// purge entities
64+
player.purge();
65+
enemy.purge();
66+
67+
// print status
68+
std::cout << player.dump() << std::endl;
69+
std::cout << enemy.dump() << std::endl;
6370

6471
return 0;
6572
}
6673
```
74+
75+
### Output
76+
```
77+
{ name: player #1,
78+
desc: this is our warrior,
79+
pos2: (x:3.33333,y:6.66666),
80+
vel2: (x:2,y:4),
81+
}
82+
{ name: orc #1,
83+
pos2: (x:0,y:0),
84+
}
85+
{}
86+
{}
87+
```
88+
89+
### Reading
90+
- https://github.com/sosolimited/Entity-Component-Samples
91+
92+
### Alternatives
93+
- https://github.com/alecthomas/entityx
94+
- https://github.com/dbralir/ginseng
95+
- https://github.com/miguelmartin75/anax
96+
- https://github.com/Nocte-/es
97+
- https://github.com/SuperV1234/SSVEntitySystem
98+
99+
### Changelog
100+
- v1.0.0 (2015/11/24): Allow external serializer; new entity methods; extra join/exclude sugars; improve dump info
101+
- v0.0.0 (2014/05/04): Initial commit

sample2.cc bench.cxx

+35-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int main( int argc, char **argv )
3232
// benchmark its access time
3333

3434
{
35-
std::cout << "Benchmarking... ";
35+
std::cout << "Benchmarking get<T>(id) syntax... ";
3636
std::chrono::microseconds seconds1, seconds2;
3737
{
3838
auto t_start = std::chrono::high_resolution_clock::now();
@@ -55,5 +55,39 @@ int main( int argc, char **argv )
5555
std::cout << dump(obj1) << std::endl;
5656
}
5757

58+
{
59+
// obj
60+
kult::entity obj;
61+
kult::component<'cter', size_t> counter;
62+
63+
{
64+
std::cout << "Benchmarking T[id] syntax... ";
65+
std::chrono::microseconds seconds1, seconds2;
66+
{
67+
auto t_start = std::chrono::high_resolution_clock::now();
68+
for( size_t i = 0; i < 200000000; ++i )
69+
counter[ obj ]++;
70+
seconds1 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t_start);
71+
}
72+
size_t &ref = counter[ obj ];
73+
{
74+
auto t_start = std::chrono::high_resolution_clock::now();
75+
for( size_t i = 0; i < 200000000; ++i )
76+
ref++;
77+
seconds2 = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t_start);
78+
}
79+
double relative_speed = double( seconds1.count() ) / seconds2.count();
80+
std::cout << "relative access is x" << std::fixed << std::setprecision(2) << relative_speed << " times " << ( seconds1 >= seconds2 ? "slower" : "faster" ) << " than direct access" << std::endl;
81+
}
82+
83+
// debug obj
84+
std::cout << dump(obj) << std::endl;
85+
86+
kult::purge(obj);
87+
88+
// debug obj
89+
std::cout << dump(obj) << std::endl;
90+
}
91+
5892
return 0;
5993
}

sample1.cc demo1.cc

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// demo1: construct two objects dinamically using the add<component_t>(id) syntax
2+
13
#include <string>
24
#include <sstream>
35
#include <iostream>
@@ -40,6 +42,9 @@ int main( int argc, char **argv )
4042
// print objects
4143
std::cout << dump(obj1) << std::endl;
4244
std::cout << dump(obj2) << std::endl;
45+
46+
purge(obj2);
47+
std::cout << dump(obj2) << std::endl;
4348
}
4449

4550
return 0;

sample5.cc demo2.cc

File renamed without changes.

sample6.cc demo3.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int main(int argc, char **argv) {
2727

2828
for( unsigned times = 0; times < 100; ++times ) {
2929
movementSystem(0.0016f);
30-
std::cout << get<position>(player) << std::endl;
30+
std::cout << dump(player) << std::endl;
3131
}
3232

3333
return 0;

sample7.cc demo4.cc

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ kult::component<'pos2', vec2> position;
2020
kult::component<'vel2', vec2> velocity;
2121

2222
// systems
23-
kult::system movement = [&]( double t, float dt ) {
23+
kult::system<float> movement = [&]( float dt ) {
2424
for( auto &entity : kult::join( position, velocity ) ) {
2525
entity[ position ].x += entity[ velocity ].x * dt;
2626
entity[ position ].y += entity[ velocity ].y * dt;
2727
}
28-
return true;
2928
};
3029

3130
// app
@@ -42,12 +41,20 @@ int main(int argc, const char **argv) {
4241

4342
// simulate 100 frames
4443
for( int i = 0; i < 100; ++i ) {
45-
movement(0, 1/60.f);
44+
movement( 1/60.f );
4645
}
4746

4847
// print status
49-
std::cout << player.str() << std::endl;
50-
std::cout << enemy.str() << std::endl;
48+
std::cout << player.dump() << std::endl;
49+
std::cout << enemy.dump() << std::endl;
50+
51+
// purge entities
52+
player.purge();
53+
enemy.purge();
54+
55+
// print status
56+
std::cout << player.dump() << std::endl;
57+
std::cout << enemy.dump() << std::endl;
5158

5259
return 0;
5360
}

0 commit comments

Comments
 (0)