Skip to content

Commit 87d7f0e

Browse files
committed
improve maintainability
1 parent 88ecb3f commit 87d7f0e

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

components/doom/src/doom.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,32 @@ static std::unique_ptr<espp::Task> audio_task;
2121

2222
static const char *doom_argv[10];
2323

24+
enum class WeaponHaptics : int {
25+
FIST = 3,
26+
PISTOL = 2,
27+
SHOTGUN = 10,
28+
CHAINGUN = 12,
29+
ROCKET_LAUNCHER = 27,
30+
PLASMA_RIFLE = 14,
31+
BFG9000 = 47,
32+
CHAINSAW = 15,
33+
SUPER_SHOTGUN = 52
34+
};
35+
36+
// NOTE: The order of the enum values must match the order of the weapons in the
37+
// game, which is the wp_* enum values defined in doomdef.h
38+
static constexpr int WeaponHapticLookup[] = {
39+
(int)WeaponHaptics::FIST,
40+
(int)WeaponHaptics::PISTOL,
41+
(int)WeaponHaptics::SHOTGUN,
42+
(int)WeaponHaptics::CHAINGUN,
43+
(int)WeaponHaptics::ROCKET_LAUNCHER,
44+
(int)WeaponHaptics::PLASMA_RIFLE,
45+
(int)WeaponHaptics::BFG9000,
46+
(int)WeaponHaptics::CHAINSAW,
47+
(int)WeaponHaptics::SUPER_SHOTGUN
48+
};
49+
2450
// prboom includes
2551
extern "C" {
2652
/////////////////////////////////////////////
@@ -98,25 +124,8 @@ extern "C" {
98124

99125
void R_PlayerFire(player_t *player) {
100126
static auto& box = BoxEmu::get();
101-
int haptic_effect_index = 0;
102127
int weapon_fired = player->readyweapon;
103-
if (weapon_fired == wp_fist) {
104-
haptic_effect_index = 3;
105-
} else if (weapon_fired == wp_pistol) {
106-
haptic_effect_index = 2;
107-
} else if (weapon_fired == wp_shotgun) {
108-
haptic_effect_index = 10;
109-
} else if (weapon_fired == wp_chaingun) {
110-
haptic_effect_index = 12;
111-
} else if (weapon_fired == wp_missile) {
112-
haptic_effect_index = 27;
113-
} else if (weapon_fired == wp_plasma) {
114-
haptic_effect_index = 14;
115-
} else if (weapon_fired == wp_bfg) {
116-
haptic_effect_index = 47;
117-
} else if (weapon_fired == wp_supershotgun) {
118-
haptic_effect_index = 52;
119-
}
128+
int haptic_effect_index = WeaponHapticLookup[weapon_fired];
120129
box.play_haptic_effect(haptic_effect_index);
121130
}
122131

0 commit comments

Comments
 (0)