Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Change switch-case for std::pair in controls.cpp #603

@bufalo1973

Description

@bufalo1973

I think it would be better to change the switch in void Controls_ActionToStr(char buff[128], ACTIONS act) to something like:

#include

std::pair<ACTIONS, std::string> ActionStr[] = {
std::make_pair(ACT_UP, "ACT_UP"),
std::make_pair(ACT_DOWN, "ACT_DOWN"),
std::make_pair(ACT_LEFT, "ACT_LEFT"),
std::make_pair(ACT_RIGHT, "ACT_RIGHT"),
std::make_pair(ACT_ACTION, "ACT_ACTION"),
std::make_pair(ACT_JUMP, "ACT_JUMP"),
std::make_pair(ACT_ROLL, "ACT_ROLL"),
std::make_pair(ACT_DRAWWEAPON, "ACT_DRAWWEAPON"),
std::make_pair(ACT_LOOK, "ACT_LOOK"),
std::make_pair(ACT_WALK, "ACT_WALK"),
std::make_pair(ACT_SPRINT, "ACT_SPRINT"),
std::make_pair(ACT_CROUCH, "ACT_CROUCH"),
std::make_pair(ACT_STEPLEFT, "ACT_STEPLEFT"),
std::make_pair(ACT_STEPRIGHT, "ACT_STEPRIGHT"),
std::make_pair(ACT_LOOKUP, "ACT_LOOKUP"),
std::make_pair(ACT_LOOKDOWN, "ACT_LOOKDOWN"),
std::make_pair(ACT_LOOKLEFT, "ACT_LOOKLEFT"),
std::make_pair(ACT_LOOKRIGHT, "ACT_LOOKRIGHT"),
std::make_pair(ACT_NEXTWEAPON, "ACT_NEXTWEAPON"),
std::make_pair(ACT_PREVWEAPON, "ACT_PREVWEAPON"),
std::make_pair(ACT_FLARE, "ACT_FLARE"),
std::make_pair(ACT_BIGMEDI, "ACT_BIGMEDI"),
std::make_pair(ACT_SMALLMEDI, "ACT_SMALLMEDI"),
std::make_pair(ACT_WEAPON1, "ACT_WEAPON1"),
std::make_pair(ACT_WEAPON2, "ACT_WEAPON2"),
std::make_pair(ACT_WEAPON3, "ACT_WEAPON3"),
std::make_pair(ACT_WEAPON4, "ACT_WEAPON4"),
std::make_pair(ACT_WEAPON5, "ACT_WEAPON5"),
std::make_pair(ACT_WEAPON6, "ACT_WEAPON6"),
std::make_pair(ACT_WEAPON7, "ACT_WEAPON7"),
std::make_pair(ACT_WEAPON8, "ACT_WEAPON8"),
std::make_pair(ACT_WEAPON9, "ACT_WEAPON9"),
std::make_pair(ACT_WEAPON10, "ACT_WEAPON10"),
std::make_pair(ACT_BINOCULARS, "ACT_BINOCULARS"),
std::make_pair(ACT_PLS, "ACT_PLS"),
std::make_pair(ACT_PAUSE, "ACT_PAUSE"),
std::make_pair(ACT_INVENTORY, "ACT_INVENTORY"),
std::make_pair(ACT_DIARY, "ACT_DIARY"),
std::make_pair(ACT_MAP, "ACT_MAP"),
std::make_pair(ACT_LOADGAME, "ACT_LOADGAME"),
std::make_pair(ACT_SAVEGAME, "ACT_SAVEGAME"),
std::make_pair(ACT_CONSOLE, "ACT_CONSOLE"),
std::make_pair(ACT_SCREENSHOT, "ACT_SCREENSHOT"),
std::make_pair(ACT_LASTINDEX, (std::string)NULL)
};

void Controls_ActionToStr(char buff[128], ACTIONS act)
{
strncpy(buff, ActionStr[act].second.c_str(), 128);
};

It might be a little faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions