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

Tiny optimization potential in Gadget_Push_Button_Input #1090

Open
xezon opened this issue Feb 8, 2024 · 0 comments
Open

Tiny optimization potential in Gadget_Push_Button_Input #1090

xezon opened this issue Feb 8, 2024 · 0 comments

Comments

@xezon
Copy link
Contributor

xezon commented Feb 8, 2024

WindowMsgHandledType Gadget_Push_Button_Input(
    GameWindow *push_button, unsigned int message, unsigned int data_1, unsigned int data_2)
{
    WinInstanceData *instance_data = push_button->Win_Get_Instance_Data();

    switch (message) {
...
        case GWM_LEFT_DOWN: {
            _PushButtonData *data = static_cast<_PushButtonData *>(push_button->Win_Get_User_Data());
            AudioEventRTS click;

            if (data != nullptr && data->m_altSound.Is_Not_Empty()) {
                click.Set_Event_Name(data->m_altSound);
            } else {
                click.Set_Event_Name("GUIClick");
            }

            if (g_theAudio != nullptr) {
                g_theAudio->Add_Audio_Event(&click);
            }
...
        case GWM_RIGHT_DOWN: {
            _PushButtonData *data = static_cast<_PushButtonData *>(push_button->Win_Get_User_Data());
            AudioEventRTS click;

            if (data != nullptr && data->m_altSound.Is_Not_Empty()) {
                click.Set_Event_Name(data->m_altSound);
            } else {
                click.Set_Event_Name("GUIClick");
            }

            if ((instance_data->Get_Status() & WIN_STATUS_RIGHT_CLICK) == 0) {
                return MSG_IGNORED;
            }

            if (g_theAudio != nullptr) {
                g_theAudio->Add_Audio_Event(&click);
            }
...

Code is all over the place. AudioEventRTS click creation can be moved into g_theAudio test. And WIN_STATUS_RIGHT_CLICK status can be tested much earlier:

WindowMsgHandledType Gadget_Push_Button_Input(
    GameWindow *push_button, unsigned int message, unsigned int data_1, unsigned int data_2)
{
    WinInstanceData *instance_data = push_button->Win_Get_Instance_Data();

    switch (message) {
...
        case GWM_LEFT_DOWN: {
            _PushButtonData *data = static_cast<_PushButtonData *>(push_button->Win_Get_User_Data());

            if (g_theAudio != nullptr) {
                AudioEventRTS click;

                if (data != nullptr && data->m_altSound.Is_Not_Empty()) {
                    click.Set_Event_Name(data->m_altSound);
                } else {
                    click.Set_Event_Name("GUIClick");
                }
                g_theAudio->Add_Audio_Event(&click);
            }
...
        case GWM_RIGHT_DOWN: {
            if ((instance_data->Get_Status() & WIN_STATUS_RIGHT_CLICK) == 0) {
                return MSG_IGNORED;
            }

            _PushButtonData *data = static_cast<_PushButtonData *>(push_button->Win_Get_User_Data());

            if (g_theAudio != nullptr) {
                AudioEventRTS click;

                if (data != nullptr && data->m_altSound.Is_Not_Empty()) {
                    click.Set_Event_Name(data->m_altSound);
                } else {
                    click.Set_Event_Name("GUIClick");
                }
                g_theAudio->Add_Audio_Event(&click);
            }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant