0

I'm working on a game from scratch in C++ which is based on an Entity Component System and I've ran into a bit of a problem with the way I've been designing my systems and components. I find myself making fairly big systems that handle all the behavior for an entity or in other words I have systems that operate on 1 entity for example I wanted two different camera behaviors a free camera for debugging and third person for gameplay, so I created DebugCameraSystem and ThirdPersonCameraSystem even for my player I ended up with a PlayerController

class  ThirdPersonCameraController: public ISystem {
public:
    void Update(float timestep) override {
        // Mouse Input
        if (gInputManager.IsMouseButtonDown(SDL_BUTTON_RIGHT)) {

        }

        // make the camera look at its target
    }
};

class  DebugCameraController : public ISystem {
public:
    void Update(float timestep) override {
        // Mouse Input
        if (gInputManager.IsMouseButtonDown(SDL_BUTTON_RIGHT)) {

        }

        // Keyboard Input
        if (gInputManager.IsKeyDown(SDLK_w)) {
        }

        if (gInputManager.IsKeyDown(SDLK_s)) {
        }
    }
};

class  PlayerController : public ISystem {
public:
    void Update(float timestep) override {
        

        // Keyboard Input
        if (gInputManager.IsKeyDown(SDLK_w)) {
        }

        if (gInputManager.IsKeyDown(SDLK_s)) {
        }

        // Jump
        if (gInputManager.IsKeyDown(SDLK_SPACE)) {
        }

        // Some ability
        if (gInputManager.IsKeyDown(SDLK_e)) {
        }
    }
};

I've done a bit of research, and the common solution I've seen seems to be making more general-purpose systems or systems that update components and systems that act on the updated components so instead of having those three systems I'd just have an InputSystem and then a MoveSystem. This raises a few questions though like how would I implement specific logic like the player shooting a gun or activating abilities? And I think that's what pushed me into my current direction.

Anyways what I'd like to know is my approach valid and I'm just overthinking things or am incorrectly using ECS?

7
  • 1
    Can you elaborate on the problem? seems like you are doing ECS here, I assume you have one player "entity" attach all the controllers you want (depending on mode) and each frame update gets called for all attached controllers?
    – Ewan
    Commented Feb 7 at 11:52
  • I guess what I'm trying to ask is do I want a single system that makes up the player or do I want to make multiple systems? So instead of having PlayerController I'd have MoveSystem, JumpSystem, AbilitySystem, etc.
    – Konjointed
    Commented Feb 8 at 0:45
  • isnt that what you have here in your example though? playercontroller, cameracontroller etc whats different about calling them systems?
    – Ewan
    Commented Feb 8 at 8:47
  • what problem have you encountered with the current setup that made you look for a solution
    – Ewan
    Commented Feb 8 at 8:48
  • The keypresses in playercontroller wpuld only ever apply the the player right? it doesn't make sense to split them unless you have a whole bunch of characters that should jump when you press jump
    – Ewan
    Commented Feb 8 at 8:50

0