Skip to main content
added 119 characters in body
Source Link
dreta
  • 3.5k
  • 4
  • 21
  • 37

Your input component doesn't need any logic. It needs a control scheme since that's going to differ among entities but that's all. The rest should be handled by the system. It's the same as it is for rendering and physics, just detect which entity has the component and act upon it. Putting input handling logic in the component is a dead end because there's only so much it can do before you start creating hacks.

Trying to avoid one switch statement at a cost of creating inheritance chains is a poor decision since you gain absolutely nothing. You need the same logic for handling the input. The switch statement was created for situations like this one, it doesn't make your application less robust in this case. Also adding a new type of control is going to be easier with a switch statement; just add one more case and a function to handle it. Otherwise you're bloating your inheritance chains more and relying on run-time type checking, again, gaining nothing in return.

Your input component doesn't need any logic. It needs a control scheme since that's going to differ among entities but that's all. The rest should be handled by the system. It's the same as it is for rendering and physics, just detect which entity has the component and act upon it.

Trying to avoid one switch statement at a cost of creating inheritance chains is a poor decision since you gain absolutely nothing. You need the same logic for handling the input. The switch statement was created for situations like this one, it doesn't make your application less robust in this case. Also adding a new type of control is going to be easier with a switch statement; just add one more case and a function to handle it. Otherwise you're bloating your inheritance chains more and relying on run-time type checking, again, gaining nothing in return.

Your input component doesn't need any logic. It needs a control scheme since that's going to differ among entities but that's all. The rest should be handled by the system. It's the same as it is for rendering and physics, just detect which entity has the component and act upon it. Putting input handling logic in the component is a dead end because there's only so much it can do before you start creating hacks.

Trying to avoid one switch statement at a cost of creating inheritance chains is a poor decision since you gain absolutely nothing. You need the same logic for handling the input. The switch statement was created for situations like this one, it doesn't make your application less robust. Also adding a new type of control is going to be easier with a switch statement; just add one more case and a function to handle it. Otherwise you're bloating your inheritance chains more and relying on run-time type checking, again, gaining nothing in return.

Source Link
dreta
  • 3.5k
  • 4
  • 21
  • 37

Your input component doesn't need any logic. It needs a control scheme since that's going to differ among entities but that's all. The rest should be handled by the system. It's the same as it is for rendering and physics, just detect which entity has the component and act upon it.

Trying to avoid one switch statement at a cost of creating inheritance chains is a poor decision since you gain absolutely nothing. You need the same logic for handling the input. The switch statement was created for situations like this one, it doesn't make your application less robust in this case. Also adding a new type of control is going to be easier with a switch statement; just add one more case and a function to handle it. Otherwise you're bloating your inheritance chains more and relying on run-time type checking, again, gaining nothing in return.