novelrt / NovelRT

A cross-platform 2D game engine accompanied by a strong toolset for visual novels.
MIT License
184 stars 42 forks source link

Input resets from KeyDownHeld to Idle on each frame #576

Closed DynamicField closed 1 year ago

DynamicField commented 1 year ago

Describe the issue: Using the ECS Input system, holding a key while it is in KeyDownHeld mode will switch it to Idle on the next frame.

Please provide the steps to reproduce if possible:

  1. Clone the repo
  2. Switch to 'main' branch
  3. Build with... whatever? As usual?
  4. Copy and paste the following code into samples/InputEcsPipeline/main.c, inside the system's lambda:

    scheduler.RegisterSystem([&](auto delta, auto catalogue) {
    ComponentView<NovelRT::Ecs::Input::InputEventComponent> events =
        catalogue.template GetComponentView<NovelRT::Ecs::Input::InputEventComponent>();
    ComponentView<TransformComponent> transforms = catalogue.template GetComponentView<TransformComponent>();
    NovelRT::Maths::GeoVector2F scale = NovelRT::Maths::GeoVector2F::Zero();
    NovelRT::Maths::GeoVector2F move = NovelRT::Maths::GeoVector2F::Zero();
    
    NovelRT::Ecs::Input::InputEventComponent input;
    +    if (events.TryGetComponent(up, input)) {
    +        switch (input.state) {
    +            case KeyState::Idle:
    +                logger.logInfo("[Up] Idle");
    +                break;
    +            case KeyState::KeyUp:
    +                logger.logInfo("[Up] KeyUp");
    +                break;
    +            case KeyState::KeyDown:
    +                logger.logInfo("[Up] KeyDown");
    +                break;
    +            case KeyState::KeyDownHeld:
    +                logger.logInfo("[Up] KeyDownHeld");
    +                break;
    +        }
    +    } else {
    +        logger.logInfo("[Up] Idle (TryGetComponent failed!)");
    +    }
  5. Run 'InputEcsPipeline'
  6. Hold the W key and observe the stuttering in novel-chans bursting into the air
  7. Look at the logs, alternating between KeyDown, KeyDownHeld, and Idle image

Expected behaviour: While pressed, the key state should stay at KeyDownHeld until the key is released.

Please tell us about your environment: