Skip to content

r-lyeh-archived/kult

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kult 🔮

Kult is a lightweight entity/component/system library (C++11).

Features

  • Expressive.
  • Tiny, cross-platform, self-contained, header-only.
  • ZLIB/libPNG licensed.

Showcase

#include <iostream>
#include "kult.hpp"

// custom type
struct vec2 {
    float x, y;

    template<typename T> friend T&operator<<( T &os, const vec2 &self ) {
        return os << "(x:" << self.x << ",y:" << self.y << ")", os;
    }
};

// entities
kult::entity player, enemy;

// components
kult::component<'name', std::string> name;
kult::component<'desc', std::string> description;
kult::component<'pos2', vec2> position;
kult::component<'vel2', vec2> velocity;

// systems
kult::system<float> movement = [&]( float dt ) {
    for( auto &entity : kult::join( position, velocity ) ) {
        entity[ position ].x += entity[ velocity ].x * dt;
        entity[ position ].y += entity[ velocity ].y * dt;
    }
};

// app
int main(int argc, const char **argv) {

    // assign properties dynamically
    player[ name ] = "player #1";
    player[ position ] = { 0, 0 };
    player[ velocity ] = { 2, 4 };
    player[ description ] = "this is our warrior";

    enemy[ name ] = "orc #1";
    enemy[ position ] = { 0, 0 };

    // simulate 100 frames
    for( int i = 0; i < 100; ++i ) {
        movement( 1/60.f );
    }

    // print status
    std::cout << player.dump() << std::endl;
    std::cout << enemy.dump() << std::endl;

    // purge entities
    player.purge();
    enemy.purge();

    // print status
    std::cout << player.dump() << std::endl;
    std::cout << enemy.dump() << std::endl;

    return 0;
}

Output

{       name: player #1,
        desc: this is our warrior,
        pos2: (x:3.33333,y:6.66666),
        vel2: (x:2,y:4),
}
{       name: orc #1,
        pos2: (x:0,y:0),
}
{}
{}

Reading

Alternatives

Changelog

  • v1.0.0 (2015/11/24): Allow external serializer; new entity methods; extra join/exclude sugars; improve dump info
  • v0.0.0 (2014/05/04): Initial commit

About

🔮 Lightweight entity/component/system library (C++11)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages