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?