1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Alles
  • Alles
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Mitglieder
  3. kim366

Beiträge von kim366

  • Programmier Strukturen (C++/Universell)

    • kim366
    • 24. November 2016 um 14:02

    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:

    Code
    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

    Code
    buttonPressedThisFrame

    is extremely long, so I have shortened it to

    Code
    bptf

    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

    Code
    void handleInput(o::Mouse m)

    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:

    Code
    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

    Code
    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?

Rechtliches

Impressum

Datenschutzerklärung