Coder Social home page Coder Social logo

lazybobcat / fluffy Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 4.75 MB

Fluffy is a (wip) video game engine. Its objective is to help making or prototyping small games by provinding useful tools, scripting and UI.

License: Do What The F*ck You Want To Public License

CMake 0.68% C++ 66.94% Shell 0.02% C 30.64% Objective-C 1.05% GLSL 0.05% HTML 0.07% Python 0.47% Less 0.08% Makefile 0.01% Cuda 0.01%
library video-game entity-component-system video-game-engine

fluffy's Introduction

Generic badge Generic badge Build Status

Fluffy

Fluffy is still a work in progress.

Fluffy

Fluffy is a (wip) video game engine. Its objective is to help making or prototyping small games by provinding useful tools, an editor, scripting and a programming framework.

Fluffy contains

  • A visual editor based on ImGui
  • A fully working Entity-Component-System (ECS)
  • Scene management
  • Window handling
  • Graphics handling
  • Resource managers
  • Layers (screens/states)
  • Useful utility classes like Time, Signals/slots, Path, etc.
  • Logging

Fluffy will contain (in the future)

  • Scripting
  • Asset pipe

Fluffy needs

  • A compiler that supports C++20
  • OpenGL 3.3+ compatible GPU

Fluffy uses

How to compile

Use cmake and the compiler of your choice

Some code examples while waiting a documentation and the wiki

ECS

Entities are just identifiers. Components hold the actual data (but no functionality). Entity creation and assignment of Components:

struct Position : public Component<Position>
{
    Position() = default;
    Position(float x, float y) : x(x), y(y) {}
 
    float x = 0.f;
    float y = 0.f;
};

struct Speed : public Component<Speed>
{
    Speed() = default;
    Speed(float x, float y) : x(x), y(y) {}
 
    float x = 0.f;
    float y = 0.f;
};
 
{
    EntityManager em(eventManager);
    
    // Create the entity
    Entity entity1 = em.createEntity();
    
    // You can assign and initialize a component using the EntityManager
    em.assign<Position>(entity1.id(), 42.f, 30.f);
    
    // Or you can assign a component directly from the Entity
    entity1.assign<Speed>(10, 15);
}

Get back components from an Entity:

{
    // You can fetch it from the EntityManager...
    auto position = em.component<Position>(entity1.id());
    
    // ... or directly from the Entity
    auto speed = entity1.component<Speed>();
 
    std::cout << "Ent1 position is (" << position->x << ":" << position->y << ") with a speed of (" << speed->x << ":" << speed->y << ")" << std::endl;
}

Looping on a list of components:

{
    for (auto entity : entityManager.each<Speed, Position>()) {
        auto position = entity.component<Position>();
        auto speed = entity.component<Speed>();
        // ...
    }
}

System are responsible for the update ad handling of the dat stored in Components. Creating Systems:

class MovementSystem : public System<MovementSystem>
{
public:
    virtual void initialize(EntityManager& entityManager, EventManager& eventManager) override {
        // ...
    }
 
    virtual void update(EntityManager& entityManager, Time dt) override {
        for (auto entity : entityManager.each<Speed, Position>()) {
            auto position = entity.component<Position>();
            auto speed = entity.component<Speed>();
            position->x += speed->x * dt.seconds();
            position->y += speed->y * dt.seconds();
        }
    }
};
 
{
    SystemManager systemManager(em, eventManager);
 
    auto movementSystem = systemManager.add<MovementSystem>();
    systemManager.initialize();
    
    while (/** Game Loop or something **/) {
        systemManager.updateAll(seconds(1 / 60.f));
    }
}

Layers

fluffy's People

Contributors

lazybobcat avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

fluffy's Issues

Utility Random: linking error

There is a linking error when compiling a project using Fluffy as external dynamic library.
It may come from the template implementation

Sprite fragment shader doesn't compile on linux

OS: Linux
Vendor: Intel Open Source Technology Center
Renderer: Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2)
Version: 3.3 (Core Profile) Mesa 20.2.6

Maybe this is because of the old hardware but there are two issues when compiling the fragment shader on linux:

Conversion of float textSlot to int

texSlot is not properly converted to an integer. Here is an ugly workaround:

#version 330 core
in vec2 texCoord;
in vec4 spriteColor;
in float texSlot;

uniform sampler2D u_Textures[32];

out vec4 fragColor;

void main()
{
   switch(int(texSlot))
   {
      case 0: fragColor = spriteColor * texture(u_Textures[0], texCoord); break;
      case 1: fragColor = spriteColor * texture(u_Textures[1], texCoord); break;
      case 2: fragColor = spriteColor * texture(u_Textures[2], texCoord); break;
      case 3: fragColor = spriteColor * texture(u_Textures[3], texCoord); break;
      case 4: fragColor = spriteColor * texture(u_Textures[4], texCoord); break;
      case 5: fragColor = spriteColor * texture(u_Textures[5], texCoord); break;
      case 6: fragColor = spriteColor * texture(u_Textures[6], texCoord); break;
      case 7: fragColor = spriteColor * texture(u_Textures[7], texCoord); break;
      case 8: fragColor = spriteColor * texture(u_Textures[8], texCoord); break;
      case 9: fragColor = spriteColor * texture(u_Textures[9], texCoord); break;
      case 10: fragColor = spriteColor * texture(u_Textures[10], texCoord); break;
      case 11: fragColor = spriteColor * texture(u_Textures[11], texCoord); break;
      case 12: fragColor = spriteColor * texture(u_Textures[12], texCoord); break;
      case 13: fragColor = spriteColor * texture(u_Textures[13], texCoord); break;
      case 14: fragColor = spriteColor * texture(u_Textures[14], texCoord); break;
      case 15: fragColor = spriteColor * texture(u_Textures[15], texCoord); break;
      case 16: fragColor = spriteColor * texture(u_Textures[16], texCoord); break;
      case 17: fragColor = spriteColor * texture(u_Textures[17], texCoord); break;
      case 18: fragColor = spriteColor * texture(u_Textures[18], texCoord); break;
      case 19: fragColor = spriteColor * texture(u_Textures[19], texCoord); break;
      case 20: fragColor = spriteColor * texture(u_Textures[20], texCoord); break;
      case 21: fragColor = spriteColor * texture(u_Textures[21], texCoord); break;
      case 22: fragColor = spriteColor * texture(u_Textures[22], texCoord); break;
      case 23: fragColor = spriteColor * texture(u_Textures[23], texCoord); break;
      case 24: fragColor = spriteColor * texture(u_Textures[24], texCoord); break;
      case 25: fragColor = spriteColor * texture(u_Textures[25], texCoord); break;
      case 26: fragColor = spriteColor * texture(u_Textures[26], texCoord); break;
      case 27: fragColor = spriteColor * texture(u_Textures[27], texCoord); break;
      case 28: fragColor = spriteColor * texture(u_Textures[28], texCoord); break;
      case 29: fragColor = spriteColor * texture(u_Textures[29], texCoord); break;
      case 30: fragColor = spriteColor * texture(u_Textures[30], texCoord); break;
      case 31: fragColor = spriteColor * texture(u_Textures[31], texCoord); break;
   }
}

The default size of sampler2d (32) won't do

Hardware max texture slots is 16. The fact that we're creating a uniform sampler2D u_Textures[32]; makes the compilation to fail.
Either we need to make a separated shader for Linux with a limited number of textures slots (and limit it in the Painter as well). Or find a workaround.

Empty EntityComponentView returns data

While fetching an EntityComponentView from EntityManager::each() but there is no entity to fetch for the given components, it seems that the code is able to iterate on the View regardless. Leading to errors because of invalid entities.

It may have been fixed by 7748dc2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.