Ich verfasse diesen Post auf Englisch, weil mir das leichter fällt (ja, meine Muttersprache ist Deutsch). Falls Ihr lieber auf Deutsch antwortet, tut dies. I have no idea what the right word for this is. Is it structure? Paradigm? Strategy?
I have the following struct:
namespace o
{
struct Mouse
{
// Button Pressed This Frame
bool bptf;
// Button Released This Frame
bool brtf;
// Button Pressed
bool bp = false;
// Mouse Properties
sf::Mouse::Button button;
sf::Vector2i position;
};
} // Namespace o
Alles anzeigen
All the properties are being updated every frame. The variable name
is extremely long, so I have shortened it to
since it is commented at the declaration anyways. Is this the correct thing to do?
I also have a function, which is called every frame, called
which surprisingly enough handles all the input. The project I am currently working on has to do with nodes and mouse controls are there for the selection and moving of said nodes. So in that function I have a few if-statements. Is it better to have completely dry code and only have every if-statement once, or is it better to logically separate them?
Examle:
void handleInput(o::Mouse m)
{
if (m.bp)
{
// Selection of Nodes
// Moving of Nodes
}
else if (m.brtf)
{
// Selection of Nodes
// Moving of Nodes
}
}
Alles anzeigen
vs
void handleInput(o::Mouse m)
{
// Selection of Nodes
if (m.bp)
{
}
else if (m.brtf)
{
}
// Moving of Nodes
if (m.bp)
{
}
else if (m.brtf)
{
}
}
Alles anzeigen
What is to be said about my project, is that those if-statements become quite nested (up to 6 tabstops with else-statements to each of them) and also cover keyboard input combined with mouse input (e.g. Ctrl + LMB).
Which of these strategies is the correct/best one to use?