Skip to content

Commit

Permalink
Code review - optimizations & best practice
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Krieger <[email protected]>
  • Loading branch information
RenechCDDA and akrieger committed Jun 9, 2024
1 parent 6e43d5a commit 567b509
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/npctalk_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
#include "imgui/imgui.h"
#include "imgui/imgui_internal.h"

static std::map<cbm_recharge_rule, std::string> recharge_map = {
static std::unordered_map<cbm_recharge_rule, std::string> recharge_map = {
{cbm_recharge_rule::CBM_RECHARGE_ALL, "<ally_rule_cbm_recharge_all_text>" },
{cbm_recharge_rule::CBM_RECHARGE_MOST, "<ally_rule_cbm_recharge_most_text>" },
{cbm_recharge_rule::CBM_RECHARGE_SOME, "<ally_rule_cbm_recharge_some_text>" },
{cbm_recharge_rule::CBM_RECHARGE_LITTLE, "<ally_rule_cbm_recharge_little_text>" },
{cbm_recharge_rule::CBM_RECHARGE_NONE, "<ally_rule_cbm_recharge_none_text>" },
};

static std::map<cbm_reserve_rule, std::string> reserve_map = {
static std::unordered_map<cbm_reserve_rule, std::string> reserve_map = {
{cbm_reserve_rule::CBM_RESERVE_ALL, "<ally_rule_cbm_reserve_all_text>" },
{cbm_reserve_rule::CBM_RESERVE_MOST, "<ally_rule_cbm_reserve_most_text>" },
{cbm_reserve_rule::CBM_RESERVE_SOME, "<ally_rule_cbm_reserve_some_text>" },
{cbm_reserve_rule::CBM_RESERVE_LITTLE, "<ally_rule_cbm_reserve_little_text>" },
{cbm_reserve_rule::CBM_RESERVE_NONE, "<ally_rule_cbm_reserve_none_text>" },
};

static std::map<combat_engagement, std::string> engagement_rules = {
static std::unordered_map<combat_engagement, std::string> engagement_rules = {
{combat_engagement::NONE, "<ally_rule_engagement_none>" },
{combat_engagement::CLOSE, "<ally_rule_engagement_close>" },
{combat_engagement::WEAK, "<ally_rule_engagement_weak>" },
Expand All @@ -48,7 +48,7 @@ static std::map<combat_engagement, std::string> engagement_rules = {
{combat_engagement::NO_MOVE, "<ally_rule_engagement_no_move>" },
};

static std::map<aim_rule, std::string> aim_rule_map = {
static std::unordered_map<aim_rule, std::string> aim_rule_map = {
{aim_rule::WHEN_CONVENIENT, "<ally_rule_aim_when_convenient>" },
{aim_rule::SPRAY, "<ally_rule_aim_spray>" },
{aim_rule::PRECISE, "<ally_rule_aim_precise>" },
Expand Down Expand Up @@ -84,8 +84,8 @@ void follower_rules_ui::draw_follower_rules_ui( npc *guy )
}

template<typename T>
void follower_rules_ui_impl::multi_rule_header( std::string id, T &rule,
std::map<T, std::string> rule_map, bool should_advance )
void follower_rules_ui_impl::multi_rule_header( const std::string &id, T &rule,
const std::unordered_map<T, std::string> &rule_map, bool should_advance )
{
if( ImGui::InvisibleButton( id.c_str(), ImVec2() ) || should_advance ) {
if( rule_map.upper_bound( rule ) == rule_map.end() ) {

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / build (src)

no member named 'upper_bound' in 'std::unordered_map<aim_rule, std::basic_string<char>>' [clang-diagnostic-error]

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / build (src)

no member named 'upper_bound' in 'std::unordered_map<cbm_recharge_rule, std::basic_string<char>>' [clang-diagnostic-error]

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / build (src)

no member named 'upper_bound' in 'std::unordered_map<cbm_reserve_rule, std::basic_string<char>>' [clang-diagnostic-error]

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / build (src)

no member named 'upper_bound' in 'std::unordered_map<combat_engagement, std::basic_string<char>>' [clang-diagnostic-error]

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

no member named 'upper_bound' in 'std::unordered_map<combat_engagement, std::__cxx11::basic_string<char>, std::hash<combat_engagement>, std::equal_to<combat_engagement>, std::allocator<std::pair<const combat_engagement, std::__cxx11::basic_string<char> > > >'

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

no member named 'upper_bound' in 'std::unordered_map<aim_rule, std::__cxx11::basic_string<char>, std::hash<aim_rule>, std::equal_to<aim_rule>, std::allocator<std::pair<const aim_rule, std::__cxx11::basic_string<char> > > >'

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

no member named 'upper_bound' in 'std::unordered_map<cbm_recharge_rule, std::__cxx11::basic_string<char>, std::hash<cbm_recharge_rule>, std::equal_to<cbm_recharge_rule>, std::allocator<std::pair<const cbm_recharge_rule, std::__cxx11::basic_string<char> > > >'

Check failure on line 91 in src/npctalk_rules.cpp

View workflow job for this annotation

GitHub Actions / Basic Build and Test (Clang 10, Ubuntu, Curses)

no member named 'upper_bound' in 'std::unordered_map<cbm_reserve_rule, std::__cxx11::basic_string<char>, std::hash<cbm_reserve_rule>, std::equal_to<cbm_reserve_rule>, std::allocator<std::pair<const cbm_reserve_rule, std::__cxx11::basic_string<char> > > >'
Expand Down Expand Up @@ -335,8 +335,6 @@ void follower_rules_ui_impl::draw_controls()

draw_colored_text( string_format( _( "Rules for your follower, %s" ), guy->disp_name() ) );
ImGui::Separator();
draw_colored_text( _( "Hotkey:" ) );
ImGui::NewLine();

if( ImGui::Button( _( "Import settings from follower" ) ) ) {
exporting_rules = false;
Expand All @@ -349,6 +347,10 @@ void follower_rules_ui_impl::draw_controls()
return;
}

draw_colored_text( _( "Hotkey:" ) );
ImGui::NewLine();


print_hotkey( assigned_hotkey );
if( ImGui::Button( _( "Default ALL" ) ) || pressed_key == assigned_hotkey ) {
ImGui::SetKeyboardFocusHere( -1 );
Expand Down
3 changes: 2 additions & 1 deletion src/npctalk_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class follower_rules_ui_impl : public cataimgui::window
// Prepares for a rule option with multiple valid selections. Advances and wraps through
// those options as the hotkey is pressed.
template<typename T>
void multi_rule_header( std::string id, T &rule, std::map<T, std::string> rule_map,
void multi_rule_header( const std::string &id, T &rule,
const std::unordered_map<T, std::string> &rule_map,
bool should_advance );

protected:
Expand Down

0 comments on commit 567b509

Please sign in to comment.