Wednesday, April 15, 2020

TECS - Tight Entity Component System

Hi readers!

 

I have just finished my Master's so I had a little extra time to work on side projects...

 

It's been a while since my last post regarding BitEngine. The framework is still in development, but I found a few things that I wanted to improve before resuming development. That is a new Entity Component System.

 

Today I present Tight Entity Component System (TECS), a small header-only library that manages entity and components in a memory-efficient way. This development of this library was motivated by the new design decisions made for BitEngine, which includes decoupling more from the standard OOP approach and take a more data-oriented design. 

 

Before implementing TECS I studied how other implementations work, especially EnTT and EntityX and read many articles about the subject around the internet. There are many libraries out there, however, many seem no be now dead or they use resources in a different way from my current intentions. Also, some libraries have coupled the entity and component management with systems, which I also don't like. EnTT is an awesome library, but it has the same memory allocation problem, although there was even a discussion about the subject (here), I don't think it was implemented yet. I could probably just used one existing library and find workarounds for it to work in my case, or even modify the libraries so they would work with arena allocations. However, by doing that I would be missing part of the fun on implementing such an interesting system!

 

The library requires the user to provide a pointer of memory and size and specifies a few other parameters such as entity and component limits and a TypeProvider to enumerate the component types. The library has a type-safe interface, however, it also aims to expose an API to be used without types. Making it capable of dynamic run-time component manipulation without known types.

 

Some interesting features:

    • All allocations are constrained to a tight memory arena. Want to clear everything? just drop the arena and initiate the ECS again. This also helps in keeping your ECS working across boundaries.
    • Component references are guaranteed to be valid, independently if you add or remove more entities. Of course, if the entity or the component is removed, that reference no longer makes sense (you can still write data to it, but it might affect other entities) or components.
    • Components are tightly packed in memory (as much as possible) in order to be cache-friendly when iterating over them.
    • Compile-time type-safe API. Run-time types are planned to be supported as well.

     

    The library is currently functional and I have a few test cases to ensure it's behaviour. My initial goal was to make it Arena Allocator friendly and later performance efficient. Hopefully, it is already fast enough for relevant cases but I still need to perform some actual benchmarks to assess that.

     

    The library is very simple to use, first, we need to include the library and define some components:


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    #include <iostream>
    
    #include <tecs/tecs.h>
    
    struct Position {
        float x;
        float y;
    };
    
    struct Velocity {
        float x;
        float y;
    };
    
    CREATE_COMPONENT_TYPES(TypeProvider);
    REGISTER_COMPONENT_TYPE(TypeProvider, Position, 1);
    REGISTER_COMPONENT_TYPE(TypeProvider, Velocity, 2);
    

     

    Then we just need to allocate some memory and start using the ECS:


     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    int main()
    {
        // Feel free to allocate/manage the memory anyway you want.
        constexpr u32 MEMORY_SIZE = 1024 * 1024 * 8;
        char* memory = new char[MEMORY_SIZE]; // Allocate 8MB
    
        const u32 maxEntities = 1000;
    
        tecs::Ecs<TypeProvider, 8> ecs(tecs::ArenaAllocator(memory, MEMORY_SIZE), maxEntities);
    
        auto e = ecs.newEntity();
        ecs.addComponent<Position>(e) = {1, 1};
        ecs.addComponent<Velocity>(e) = {1, 1};
    
        e = ecs.newEntity();
        ecs.addComponent<Position>(e) = {1, 1};
        ecs.addComponent<Velocity>(e) = {2, 2};
    
        ecs.forEach<Position, Velocity>([](tecs::EntityHandle e, Position& pos, Velocity& vel) {
            pos.x += vel.x;
            pos.y += vel.y;
        });
    
        // Show entity positions:
        ecs.forEach<Position>([](tecs::EntityHandle e, Position& pos) {
            std::cout << "Entity: " << e << ", Position: " << pos.x << ", " << pos.y
                      << std::endl;
        });
    
        delete[] memory;
    }
    

     

    The next step is to replace the current Entity System used in BitEngine by TECS.

     

    Library on GitHub: MateusMP/TightECS

     

     

     

    Saturday, February 22, 2020

    Guerra² - A 2D Multiplayer Platform Shooter


    So, I have been very busy with my Master's degree and haven't had much time to update the blog (not that the updates were frequent anyways...)

    But recently I realized that one of the coolest projects I developed in the past is not here! So I'm republishing it!

     


    Guerra² would be read as "War²" in English. The name is a joke with the words "War" and "Squared", which relates to the game art style (since most elements are... Squares.)

    The gameplay was inspired in the game Soldat. And I developed this around 2011 if I remember correctly. This was one of my first, from the ground up, implementations of an Online Multiplayer game. At the time I had a PhP server hosting a lobby of rooms to play. But that server is now probably dead. It is still possible to play with CPUs or connect via IP to other players.

    You can change your game looks with a set of predefined skins and colors with a total of 590.625 different combinations!!!

    There are a few standard game modes, such as Capture The Flag, Death Match and Team Death Match. You can also choose to play by score or timed games.

    In order to make maps for the game, I also developed a Map Editor, which allows the creation of maps for all game styles. If you join a server that is currently using a map that you don't have installed, the game will download the map for you.

    Game controls are:
    WASD - Character Movement (W jump)
    Mouse - Aim and click to shoot
    Space Bar - Granade, hold to aim
    1~7 - Change weapon
    F4 - To play in full-screen

    Use the flags in the menu to change the game language.

    Guerra² Download

    Guerra² Map Editor Download






    Thinking of maybe doing a remake of this game...?

    Saturday, August 11, 2018

    Swipe Ninja

    Hello again!

    After a long time, since the last post, I bring great news!

    The once named Ninja Jump game has finally evolved into something!

    I present... Swipe Ninja!


    In this game you must avoid the obstacles and climb as high as possible!
    Do you have the dexterity of a Ninja?

    The game is available for android in the Google Play store!

    This is the first open release of the game, enjoy!

    Get it on Google Play

    Wednesday, August 2, 2017

    Ludum Dare 39 - Catalango

    Hello everyone!

    Today I'm here with a new game made in 72h! The game was created for the Ludum Dare 39!

    https://ldjam.com/events/ludum-dare/39/catalango

    [Once upon a time] In a world full of rodent cities, where fireflies are used as resources and food, a great colossus - the Cat-Emperor Von Gikkingen - and his loyal minion - the Nameless Calango - started a conquer march.
    Your mission, as the lizard-servant, is to get the famous resource to feed your Lord, avoiding the guardian rats along the way, avoid your Master mauling attacks… And at last, avoid letting the almighty colossus get too hungry, or you’ll be the food.
    So, prepare your little paws! Run! Jump! Loot and feed!

     More information and download links see the project at ldjam!

    Team:
    Sound: @enricohion
    Art: @enricohion (calango, firefly and rat) and @nana-lutzenberger (scenario and cat)
    Dev:@hikari-kyuubi, @yuiwara, and @mateusmp
    Game design and planning: All of the above!

    Friday, October 7, 2016

    BitEngine - C++ Game Framework

    Hi readers!

    I always liked to develop games using different engines, but they always missed something or had a not so good workflow for some tasks. Seeking to understand more deeply how those engines work and wanting to have a very customizable framework, I started this project "BitEngine".

    It has already been almost a year of development (not full time, of course!), but there still is a lot to be done. Usually I work on it during my free time, so the updates are not very frequent!

    See the code in GitHub, and check the wiki for more information about it.

    o/

    Friday, September 4, 2015

    Re-Upload - Fight Arena

    Republicando a pedidos... :)
    Fight Arena
     


    Fight Arena is a Fighting game, in the style of Super Smash Bros. This game was developed around 2010~2012.

    The game has 4 playable characters with a distinct set of skills. Each character has it's own themed stage. The controls can be changed in the game settings. This game support local-multiplayer. You can also play against CPU and in an all-vs-all or team game modes, with stocks or timed based games.

    The game has the following basic controls:
    Keyboard Arrows - Move character / define attack direction
    X - Basic Attack
    S - Special Attack
    C - Jump
    Z - Block, combine with left/right arrows to roll.

    The attacks follow the same idea from the Super Smash Bros series, and combinations to all 4 directions can make different attacks.
    Switch the game language in the main menu by selecting one of the flags.


    PT-BR

    Gênero: Luta
    Descrição: Jogo de luta no estilo de Super Smash Bros, você deve jogar os seus inimigos para fora
    do terreno para ganhar! Quanto mais você bate no inimigo mais vulnerável ele ficará e será jogado
    mais longe podendo ser jogado para fora do estágio. O jogo possui 4 personagens jogáveis e 4 fases
    temáticas para cada personagem.

    Controles:
    PLAYER 1:
    Setas esquerda e direita = No jogo: Movem o personagem; No menu: Move a seta do jogador.
    Seta para baixo = No jogo: agachar; No menu: Move a seta do jogador.
    Seta para cima = No menu: Move a seta do jogador.
    X = No jogo: ataque; No menu: Seleciona
    C = No jogo: pular (no ar = segundo pulo)
    S = No jogo: Poder especial (super pulo); No Menu: Voltar
    Z = No jogo: Defesa, se apertar para mover para algum lado o personagem rola.
    Enter = No jogo: Pausa
    Esc = No jogo: Com o jogo pausado você volta para o menu.
    PLAYER 2:
    J e L = No jogo: Movem o personagem; No menu: Move a seta do jogador.
    K = No jogo: agachar; No menu: Move a seta do jogador.
    I = No menu: Move a seta do jogador.
    O = No jogo: ataque; No menu: Seleciona
    Barra de Espaço = No jogo: pular (no ar = segundo pulo)
    U = No jogo: Poder especial (super pulo); No Menu: Voltar
    P = No jogo: Defesa, se apertar para mover para algum lado o personagem rola.
    Enter = No jogo: Pausa
    Esc = No jogo: Com o jogo pausado você volta para o menu.
    PLAYERS 3 E 4 possuem os mesmos comandos do player2!
    É possível trocar os comandos de cada jogador indo nas opções no menu principal!

    Informações:
    É possível modificar a resolução do jogo, mudar o volume dos Sons e da Música.
    O jogo possui Inteligência Artificial para que você possa jogar contra o computador. São 4 níveis de
    dificuldade que podem ser alterados na tela de seleção de personagem!
    É possível jogar em 2 modos de jogo:
    Tempo: O jogo termina quando o tempo acabar, o vencedor é o time ou o jogador que mais matou
    os outros.
    Vida: O jogo termina quando os demais jogadores perderem todas as vidas (Se for jogo de time por
    exemplo 2x2, o time que os jogadores perderem todas as vidas primeiro perde.)



    Download: mirror 1


    Thursday, May 17, 2012

    Ninja Jump - Nova versão!

    Olá!

    Hoje eu trouxe uma nova versão do Ninja Jump!
     Confira o log de atualizações:
    -Seleção de dificuldade no menu (Aperta A ou D na opção Jogar).
    -Fundo de jogo adicionado.
    -Algumas mudanças para o sistema de Score.
     -Sistema de Música arrumado.

    Imagem:




    Download:
    MediaFire