Skip to content

Commit

Permalink
Refactor -- Changed incorrect instances of "number" to "index".
Browse files Browse the repository at this point in the history
  • Loading branch information
Espyo committed Oct 4, 2024
1 parent f71455e commit db33135
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 45 deletions.
1 change: 0 additions & 1 deletion Source/documents/Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ Small tasks (for when I'm feeling lazy)
Cleanup
Remove magic numbers and magic strings (make numbers and strings into constants)
Try to refactor the mission strategy patterns to also work for the area editor logic
Replace all instances of "number" when in reality it should be "index"
Use enum class, and hopefully there won't be any problems due to all the times I need to cast to and from int, or use values from multiple enums.


Expand Down
20 changes: 10 additions & 10 deletions Source/source/area/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,13 +887,13 @@ bool is_polygon_clockwise(vector<vertex*> &vertexes) {
* @brief Returns whether this vertex is convex or not.
*
* @param vec List of all vertexes.
* @param nr Index number of the vertex to check.
* @param idx Index of the vertex to check.
* @return Whether it is convex.
*/
bool is_vertex_convex(const vector<vertex*> &vec, size_t nr) {
const vertex* cur_v = vec[nr];
const vertex* prev_v = get_prev_in_vector(vec, nr);
const vertex* next_v = get_next_in_vector(vec, nr);
bool is_vertex_convex(const vector<vertex*> &vec, size_t idx) {
const vertex* cur_v = vec[idx];
const vertex* prev_v = get_prev_in_vector(vec, idx);
const vertex* next_v = get_next_in_vector(vec, idx);
float angle_prev =
get_angle(
point(cur_v->x, cur_v->y),
Expand All @@ -914,18 +914,18 @@ bool is_vertex_convex(const vector<vertex*> &vec, size_t nr) {
*
* @param vec List of all vertexes.
* @param concaves List of concave vertexes.
* @param nr Index number of the vertex to check.
* @param idx Index of the vertex to check.
* @return Whether it is an ear.
*/
bool is_vertex_ear(
const vector<vertex*> &vec, const vector<size_t> &concaves, size_t nr
const vector<vertex*> &vec, const vector<size_t> &concaves, size_t idx
) {
//A vertex is an ear if the triangle of it, the previous, and next vertexes
//does not contain any other vertex inside. Also, if it has vertexes inside,
//they mandatorily are concave, so only check those.
const vertex* v = vec[nr];
const vertex* pv = get_prev_in_vector(vec, nr);
const vertex* nv = get_next_in_vector(vec, nr);
const vertex* v = vec[idx];
const vertex* pv = get_prev_in_vector(vec, idx);
const vertex* nv = get_next_in_vector(vec, idx);

for(size_t c = 0; c < concaves.size(); c++) {
const vertex* v_to_check = vec[concaves[c]];
Expand Down
4 changes: 2 additions & 2 deletions Source/source/area/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ bool get_polys_is_outer(
vertex* get_rightmost_vertex(const unordered_set<edge*> &edges);
vertex* get_rightmost_vertex(vertex* v1, vertex* v2);
bool is_polygon_clockwise(vector<vertex*> &vertexes);
bool is_vertex_convex(const vector<vertex*> &vec, size_t nr);
bool is_vertex_convex(const vector<vertex*> &vec, size_t idx);
bool is_vertex_ear(
const vector<vertex*> &vec, const vector<size_t> &concaves, size_t nr
const vector<vertex*> &vec, const vector<size_t> &concaves, size_t idx
);
TRIANGULATION_ERROR trace_edges(
vertex* start_v_ptr, const sector* s_ptr, bool going_cw,
Expand Down
2 changes: 1 addition & 1 deletion Source/source/area/sector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sector::~sector() {
* @brief Adds an edge to the sector's list of edges, if it's not there already.
*
* @param e_ptr Edge to add.
* @param e_idx Index number of the edge to add.
* @param e_idx Index of the edge to add.
*/
void sector::add_edge(edge* e_ptr, size_t e_idx) {
for(size_t i = 0; i < edges.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion Source/source/game_states/area_editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class area_editor : public editor {
//During stage 1, was the working sector to the left?
bool is_working_at_stage_1_left = false;

//Nr. of drawing nodes before a useless split part 2. Or INVALID.
//Number of drawing nodes before a useless split part 2. Or INVALID.
size_t useless_split_part_2_checkpoint = INVALID;

};
Expand Down
4 changes: 2 additions & 2 deletions Source/source/game_states/gameplay/drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1992,14 +1992,14 @@ void gameplay_state::draw_world_components(ALLEGRO_BITMAP* bmp_output) {

//Time to draw!
for(size_t c = 0; c < components.size(); c++) {
components[c].nr = c;
components[c].idx = c;
}

sort(
components.begin(), components.end(),
[] (const world_component & c1, const world_component & c2) -> bool {
if(c1.z == c2.z) {
return c1.nr < c2.nr;
return c1.idx < c2.idx;
}
return c1.z < c2.z;
}
Expand Down
20 changes: 10 additions & 10 deletions Source/source/game_states/gameplay/hud_bubble_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ struct hud_bubble_manager {
* @brief Returns the necessary information for the bubble to know how
* to draw itself.
*
* @param number Number of the registered bubble.
* @param id ID of the registered bubble.
* @param content The content the bubble should use is returned here.
* A default-constructed object is returned on error.
* @param pos The final position it should use is returned here.
* @param size The final size it should use is returned here.
*/
void get_drawing_info(
size_t number,
size_t id,
t* content, point* pos, point* size
) {
float transition_anim_ratio = transition_timer / transition_duration;

auto it = bubbles.find(number);
auto it = bubbles.find(id);
if(it == bubbles.end()) {
*content = t();
return;
Expand Down Expand Up @@ -291,12 +291,12 @@ struct hud_bubble_manager {
/**
* @brief Registers a bubble.
*
* @param bubble GUI item that represents this bubble.
* @param number Number of this item in its "family". For instance, if
* @param id ID of this item in its "family". For instance, if
* this is the icon for the second leader, this value is 1 (0-indexed).
* @param bubble GUI item that represents this bubble.
*/
void register_bubble(size_t number, gui_item* bubble) {
bubbles[number] = bubble_t(bubble);
void register_bubble(size_t id, gui_item* bubble) {
bubbles[id] = bubble_t(bubble);
}

/**
Expand All @@ -315,12 +315,12 @@ struct hud_bubble_manager {
/**
* @brief Updates the reference and content of a given bubble.
*
* @param number Number of the registered bubble.
* @param id ID of the registered bubble.
* @param new_ref New reference.
* @param new_content New content.
*/
void update(size_t number, void* new_ref, t new_content) {
auto it = bubbles.find(number);
void update(size_t id, void* new_ref, t new_content) {
auto it = bubbles.find(id);
if(it == bubbles.end()) return;
if(it->second.ref != new_ref && !transition_is_setup) {
for(auto &b : bubbles) {
Expand Down
11 changes: 5 additions & 6 deletions Source/source/mob_categories/mob_category.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,20 @@ mob_category* mob_category_manager::get_from_pname(const string &pname) const {
/**
* @brief Registers a new mob category.
*
* @param nr ID of the category.
* @param id ID of the category.
* @param category Pointer to its data.
*/
void mob_category_manager::register_category(
MOB_CATEGORY nr,
mob_category* category
MOB_CATEGORY id, mob_category* category
) {
if(nr >= categories.size()) {
if(id >= categories.size()) {
categories.insert(
categories.end(),
(nr + 1) - categories.size(),
(id + 1) - categories.size(),
nullptr
);
}
categories[nr] = category;
categories[id] = category;
}


Expand Down
2 changes: 1 addition & 1 deletion Source/source/mob_categories/mob_category.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct mob_category_manager {

//--- Function declarations ---

void register_category(MOB_CATEGORY nr, mob_category* category);
void register_category(MOB_CATEGORY id, mob_category* category);
mob_type* find_mob_type(const string &name) const;
mob_type* find_mob_type_from_folder_name(
const mob_category* cat, const string &name
Expand Down
2 changes: 1 addition & 1 deletion Source/source/mob_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class mob_fsm {
//Knowing the previous states' names helps with debugging.
string prev_state_names[STATE_HISTORY_SIZE];

//If this is INVALID, use the mob type's first state nr. Else, use this.
//If this is INVALID, use the mob type's first state index. Else, use this.
size_t first_state_override = INVALID;


Expand Down
8 changes: 4 additions & 4 deletions Source/source/mobs/mob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,15 +1914,15 @@ mob_type::vulnerability_t mob::get_hazard_vulnerability(
/**
* @brief Returns the hitbox in the current animation with the specified number.
*
* @param nr The hitbox's number.
* @param idx The hitbox's index.
* @return The hitbox.
*/
hitbox* mob::get_hitbox(size_t nr) const {
hitbox* mob::get_hitbox(size_t idx) const {
sprite* s;
get_sprite_data(&s, nullptr, nullptr);
if(!s) return nullptr;
if(s->hitboxes.empty()) return nullptr;
return &s->hitboxes[nr];
return &s->hitboxes[idx];
}


Expand Down Expand Up @@ -2897,7 +2897,7 @@ void mob::send_message(mob* receiver, string &msg) const {
/**
* @brief Sets the mob's animation.
*
* @param nr Animation index.
* @param idx Animation index.
* It's the animation instance index from the database.
* @param options Options to start the new animation with.
* @param pre_named If true, the animation has already been named in-engine.
Expand Down
6 changes: 3 additions & 3 deletions Source/source/mobs/mob.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class mob {
virtual void draw_mob();

void set_animation(
size_t nr,
size_t idx,
const START_ANIM_OPTION options = START_ANIM_OPTION_NORMAL,
bool pre_named = true,
float mob_speed_baseline = 0.0f
Expand Down Expand Up @@ -441,7 +441,7 @@ class mob {
dist get_distance_between(
const mob* m2_ptr, const dist* regular_distance_cache = nullptr
) const;
hitbox* get_hitbox(size_t nr) const;
hitbox* get_hitbox(size_t idx) const;
hitbox* get_closest_hitbox(
const point &p, size_t h_type = INVALID, dist* d = nullptr
) const;
Expand Down Expand Up @@ -571,7 +571,7 @@ class mob_with_anim_groups {

//--- Members ---

//Index number of its current base animation.
//Index of its current base animation.
size_t cur_base_anim_idx = INVALID;


Expand Down
2 changes: 1 addition & 1 deletion Source/source/mobs/mob_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ enum START_ANIM_OPTION {
//Start the new animation like normal.
START_ANIM_OPTION_NORMAL,

//Start from whatever frame number the previous animation was at.
//Start from whatever frame index the previous animation was at.
START_ANIM_OPTION_NO_RESTART,

//Start on a random time.
Expand Down
4 changes: 2 additions & 2 deletions Source/source/world_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class world_component {
//Its Z coordinate.
float z = 0.0f;

//Index number in the list of world components. Used for sorting.
size_t nr = 0;
//Index in the list of world components. Used for sorting.
size_t idx = 0;

};

0 comments on commit db33135

Please sign in to comment.