Hello Guest

[UNSOLVED] Input Component

  • 4 Replies
  • 6432 Views
[UNSOLVED] Input Component
« on: January 25, 2017, 18:47:42 »
Hi,

I'm currently reading the book "Game Programming Patterns" and I am now wondering how I can create an InputComponent system.

Like in this book they had an example of an Input Component which has some class, in Java it would be an Interface, I guess, which has an update method.
Then there is an class called PlayerInput which implements the Interface and uses the provided methods to update the player. Every player in this Game then
creates it's own instance of PlayerInput and calls the update method. Other parts of the Game which need input stuff would then create their own implementation of
the interface like it is done for the player.

I'm now wondering, how I could do something like that with LWJGL 3.

http://gameprogrammingpatterns.com/component.html

Using LWJGL 3.1.1

Thx in advance.
ShadowDragon
« Last Edit: January 25, 2017, 19:12:38 by ShadowDragon »

*

Kai

Re: [UNSOLVED] Input Component
« Reply #1 on: January 25, 2017, 20:49:36 »
What exactly is your question? How you would do input handling with LWJGL 3?
For that, LWJGL 3 uses GLFW. See: http://www.glfw.org/docs/latest/input_guide.html
Knowing that, you are free to follow any software design/architecture decisions you like.
« Last Edit: January 25, 2017, 20:52:12 by Kai »

Re: [UNSOLVED] Input Component
« Reply #2 on: January 26, 2017, 16:41:10 »
What exactly is your question? How you would do input handling with LWJGL 3?
For that, LWJGL 3 uses GLFW. See: http://www.glfw.org/docs/latest/input_guide.html
Knowing that, you are free to follow any software design/architecture decisions you like.
Question: How to do input handling with a component based system?  ???

The GLFW docs describe input handling itself good, but not how to do it with a component based system.

That's what I want to have... I just have no idea how to get such stuff working with GLFW and LWJGL 3.


What am I thinking:
Notes: The components could be used multiply times. Like there are two Players... Player 1 creates an instance of PlayerInput and Player 2 creates an instance for itself. Well, not quite sure about that note... but could be nice to have.
« Last Edit: January 26, 2017, 16:45:55 by ShadowDragon »

*

Kai

Re: [UNSOLVED] Input Component
« Reply #3 on: January 26, 2017, 19:37:43 »
Okay, a well-meant advice: before you drown yourself in unnecessarily complex designs, you should first start with the most simple and straightforward approach, possible. You will be amazed by how far you can get by keeping things simple and solving problems in the most simple way once you encounter them.
Developing software by following designs you've merely read about, is going to make things much more difficult for you.
I'm asking you to start simple and, in a way, just make mistakes and learn from them.
No one will come up with a design that is just right from the beginning. Things evolve.

Re: [UNSOLVED] Input Component
« Reply #4 on: January 26, 2017, 20:01:07 »
Okay, a well-meant advice: before you drown yourself in unnecessarily complex designs, you should first start with the most simple and straightforward approach, possible. You will be amazed by how far you can get by keeping things simple and solving problems in the most simple way once you encounter them.
Developing software by following designs you've merely read about, is going to make things much more difficult for you.
I'm asking you to start simple and, in a way, just make mistakes and learn from them.
No one will come up with a design that is just right from the beginning. Things evolve.
I know. I've currently got a simple way to handle input, but I want to have a more component based way to handle things.
The problem is just... I've only know how to do it the default way in GLFW with having one method in one class handling the input for everything.

Like this is my current way of handling things:
Code: [Select]
glfwSetKeyCallback(this.window, this.keyCallback = GLFWKeyCallback.create((window, key, scancode, action, mods) -> { this.onKey(key, action); } ));But this approach is very limited, especially when working with multiply people on the project who do not all know about input handling or graphics etc.

The picture I posted in the last post is basically an example which actually shows a bit of what was described in the book I'm reading and it's quite easy to implement..
Just one interface or abstract class with an updateInput method and classes for everything which needs an input. This classes override the updateInput method and fill it with
actual content, like if(key W is pressed -> player move forward).

So basically like described above, GLFW docs teach you how to do it the way I'm currently doing it, but not how to get it working the way I want. Without LWJGL 3 and GLFW, so with plane Java Graphics classes and stuff I would direclty know I have to register the input handler that way to do it... but with GLFW.... no clue...

And yeah... things evovle... better not to ask how often I re-wrote parts of my code or the entire code base... :P
« Last Edit: January 26, 2017, 20:02:43 by ShadowDragon »