Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even more Input Idea's #69

Open
Shadowblitz16 opened this issue May 27, 2019 · 15 comments
Open

Even more Input Idea's #69

Shadowblitz16 opened this issue May 27, 2019 · 15 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented May 27, 2019

ok bear with me I know there has already been alot of changes to input that love2d didn't have.

this should be my final suggestion for inputs so I will try to make sure I don't miss anything.
the following functions should be implemented for more control over your game

Mouse

  • MouseButton Mouse.GetDown()
  • MouseButton Mouse.GetDownPrevious()
  • bool Mouse.IsDown(MouseButton button)
  • bool Mouse.IsDownPrevious(MouseButton button)

Keyboard

  • KeyConst Keyboard.GetDown()
  • KeyConst Keyboard.GetDownPrevious()
  • bool Keyboard.IsDown(KeyConst key)
  • bool Keyboard.IsDownPrevious(KeyConst key)

GamepadButton

  • GamepadButton Joystick.GetDown()
  • GamepadButton Joystick.GetDownPrevious()
  • bool Joystick.IsDown(GamepadButton button)
  • bool Joystick.IsDownPrevious(GamepadButton button)

GamepadAxis

  • GamepadAxis Joystick.GetAxis()
  • GamepadAxis Joystick.GetAxisPrevious()
  • bool Joystick.IsAxisChange(GamepadAxis axis, bool deadzone)
  • bool Joystick.IsAxisChangePrevious(GamepadAxis axis, bool deadzone)

doing this makes the newer Pressed and Released functions pointless because now you can make your own class and do something like

var Joystick = Joystick.GetJoysticks()[0];
var buttonCurr = Joystick.GetDown();
var buttonPrev = Joystick.GetDownPrevious();
var anyButtonPressed = 
(
    Joystick.GetDown(buttonCurr) && 
   !Joystick.GetDownPrevious(buttonPrev )
);
var anyButtonReleased = 
(
    !Joystick.GetDown(buttonCurr) && 
     Joystick.GetDownPrevious(buttonPrev )
);

which you could remove them or add pressed and released variants for JoyStickAxes as well so we can check if they just changed from 0 or just changed to 0

idk what do you think @endlesstravel?

@endlesstravel
Copy link
Owner

endlesstravel commented May 29, 2019

sorry for late to reply.

i think there may be multiple buttons pressed at the same time. so, it
Mouse.GetDown Keyboard.GetDown Joystick.GetDown should return array values.

As for and Joystick.GetAxis, I don't think it's reasonable. It's confusing if he only returns one value when he has multiple inputs. If he returns a value, he must return a key-to-value pair(which axis is pulled) of arrays.

Anyway, I try to give you a class:

copy the code https://gist.github.com/endlesstravel/db0f9f6f93b89a23cc8f56b44b70396c into your project.
and here is test code:

    class ISSUE69 : Scene
    {
        public override void Update(float dt)
        {
            Input.Update();
        }

        public override void Draw()
        {
            Graphics.Print(string.Join("\n",
                $"mouse down {string.Join(",", Input.GetMouseDown())}",
                $"Input.IsMouseDown(Input.MouseButton.LeftButton)) {Input.IsMouseDown(Input.MouseButton.LeftButton)}",

                $"key down {string.Join(",", Input.GetKeyboardDown())}",
                $"Input.IsKeyboardDown(KeyConstant.Space) {Input.IsKeyboardDown(KeyConstant.Space)}",

                $"joy key {string.Join(",", Joystick.GetJoysticks().Select(joy => string.Join(",", Input.GetGamepadDown(joy).Select(name => joy.GetGUID() + ":" + name))))}",
                $"joy axis {string.Join(",", Joystick.GetJoysticks().Select(joy => string.Join(",", Input.GetGamepadAxis(joy).Select(name => joy.GetGUID() + ":" + name))))}"
                ));
        }

    }

@Shadowblitz16
Copy link
Author

These could return arrays

  • MouseButton Mouse.GetDown()
  • MouseButton Mouse.GetDownPrevious()
  • KeyConst Keyboard.GetDown()
  • KeyConst Keyboard.GetDownPrevious()
  • GamepadButton Joystick.GetDown()
  • GamepadButton Joystick.GetDownPrevious()
  • GamepadAxis Joystick.GetAxis()
  • GamepadAxis Joystick.GetAxisPrevious()

as for they joystick axes they could be made to take array like everything else.
if I recall correctly lua love2d using used key to pair values with the key being a string

as for the class you posted I really don't want to have to call a update function that's kinda why I suggested this so you could have a input manager that doesn't require a update function.

@endlesstravel
Copy link
Owner

If you have no problems with these functions, I will integrate them into the library. I provide class is mean in facilitate your testing and understanding of my intentions.

I think the most controversial issue so far is the GetGamepadAxis and IsAxisChange.

  • GetGamepadAxis
    I think structure is more appropriate in C# than dictionary. so it was
public static AnxisValue GetGamepadAxis(this Joystick joy)

The define of AxisVlaue here line 165

  • IsAxisChange
    It's like this right now :
public static bool IsGamepadAxisChange(this Joystick joy, GamepadAxis axis)

I'm not sure what your deadzone means. Can you give me some description?

I want to add them to other namespaces(You don't need to call update manually either.). for example Love.Misc.Input. The reason is to prevent them from being used by the official Love in the future. It's best if you can accept it. But if you strongly suggest, I will add them to the library.

@Shadowblitz16
Copy link
Author

deadzone is the amount you need to press the joystick before it registers or return true.

I think these could be very useful in the love library,
however they would need their previous counterparts so we can check press and release values

as for the namespace I don't really know I think the the events should have been exposed in the original love2d as functions and things like getting input should have been easier

maybe I need to start suggesting features for love2d instead of love2dcs this way they can be native.

@endlesstravel
Copy link
Owner

so you need a function to set the dead zone size ?

@Shadowblitz16
Copy link
Author

no I just thought that if the user was able to pass a deadzone it could return a bool instead of a float.

@endlesstravel
Copy link
Owner

so, you want input a function as parameter, the Joystick.IsAxisChange will not return true until the input function returns true.
so, is it like:

public delegate bool DeadZoneFunc();
bool Joystick.IsAxisChange(GamepadAxis axis, DeadZoneFunc preparatoryFunction)

?

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Jun 2, 2019

basicly deadzone would just do
return (Maths.Abs(Joystick.IsGetAxis()) > deadzone)
although I see why it wouldn't be desired if a joystick axis needs to have different dead zones for each side.

@endlesstravel
Copy link
Owner

ok,I'm still confused. .I don't recommend such a "complex" function, which is too confusing. On the one hand, it returns to the case of changing the axis, on the other hand, it demands to limit the dead zone. If these two conditions are combined, the situation may be different.

@Shadowblitz16
Copy link
Author

don't worry about the deadzone parameter users can check it manually.
its better that way anyways.

so just do..

float Joystick.IsAxisChange(GamepadAxis axis)
float Joystick.IsAxisChangePrevious(GamepadAxis axis)

@endlesstravel
Copy link
Owner

Why is the function return float, can you give some description?

@Shadowblitz16
Copy link
Author

the float is how far you press the joystick axis.
for example if you press it left and you're using the constant GamepadAxis.LeftX it would be -1 and if your pressing right and you're using the constant GamepadAxis.LeftX it return 1;
pressing nothing would be 0;

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Jun 2, 2019

@endlesstravel so I had an idea to reduce the function count.
basically have a enum call InputState which would contain the options for previous and current.

you would pass these into the function optionally like so..

var currMouseInput = Mouse.GetDown(MouseButton.Left, InputState.Current);
var prevMouseInput = Mouse.GetDown(MouseButton.Left, InputState.Previous);

this would reduce the function count from 16 to 8 for mouse, keyboard, gamepadbutton, and gamepadaxis

@endlesstravel
Copy link
Owner

        public static AnxisValue GetGamepadAxis(this Joystick joy);
        public static AnxisValue GetGamepadAxisPrevious(this Joystick joy);
        public static GamepadButton[] GetGamepadDown(this Joystick joystick);
        public static GamepadButton[] GetGamepadDownPrevious(this Joystick joystick);
        public static KeyConstant[] GetKeyboardDown();
        public static KeyConstant[] GetKeyboardPrevious();
        public static MouseButton[] GetMouseDown();
        public static MouseButton[] GetMouseDownPrevious();
        public static bool IsGamepadAxisChange(this Joystick joy, GamepadAxis axis);
        public static bool IsGamepadDown(this Joystick joystick, GamepadButton gbtn);
        public static bool IsGamepadDownPrevious(this Joystick joystick, GamepadButton gbtn);
        public static bool IsKeyboardDown(KeyConstant key);
        public static bool IsKeyboardPrevious(KeyConstant key);
        public static bool IsMouseDown(MouseButton button);
        public static bool IsMouseDownPrevious(MouseButton button);

Love.Misc.InputBoost available 11.0.34

@Shadowblitz16
Copy link
Author

Shadowblitz16 commented Jul 7, 2019

@endlesstravel
some issues to note

  • 1
    all functions should take a parameter for whether you want the current input or the previous.
    so for example these..
    var currMouseInput = IsMouseDown(MouseButton.Left);
    var prevMouseInput = IsMouseDownPrevious(MouseButton.Left);
    should be
    var currMouseInput = IsMouseDown(MouseButton.Left, InputState.Current);
    var prevMouseInput =IsMouseDown(MouseButton.Left, InputState.Previous);
    this would would make the previous functions obsolete

  • 2
    adding to number 1, we need a way to get the current and previous axis value not whether it changed.
    so public static bool IsGamepadAxisChange(this Joystick joy, GamepadAxis axis);
    should be
    var currGamepadAxis = GetGamepadAxisValue(Joystick joy, GamepadAxis.LeftX, InputState.Current);
    var prevGamepadAxis = GetGamepadAxisValue(Joystick joy, GamepadAxis.LeftX, InputState.Previous);

  • 3
    adding to number 2 Gamepad functions should take a int for a controler index not a Joystick and should check if the joystick, joystickbutton or joystickaxis is invalid and if so return false or 0 depending on if its a button function or a axis function.

  • 4
    AnxisValue is misspelled and should be AxisValue
    AnxisValue GetGamepadAxis(this Joystick joy);
    should also return a array of single axis values to be consistent with the rest of the get functions

  • 5
    MouseButton should be a enum in the love system not the love.misc system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants