Skip to content

Commit

Permalink
Reformatted some comments/docstrings to be in a standardised format.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackAshwell11 committed Dec 15, 2024
1 parent 2494d6e commit 861245f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 37 deletions.
6 changes: 2 additions & 4 deletions src/hades_extensions/include/generation/dijkstra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ struct Connection {
Position destination;
};

/// Calculate the shortest path in a grid from one pair to another using the A*
/// algorithm.
/// Calculate the shortest path in a grid from one pair to another using the A* algorithm.
///
/// @details https://en.wikipedia.org/wiki/A%2A_search_algorithm
/// @param grid - The 2D grid which represents the dungeon.
Expand All @@ -38,8 +37,7 @@ struct Connection {
/// @return A vector of positions mapping out the shortest path from start to end.
auto calculate_astar_path(const Grid &grid, const Position &start, const Position &end) -> std::vector<Position>;

/// Get the furthest position from the start position in the grid using a
/// Dijkstra map.
/// Get the furthest position from the start position in the grid using a Dijkstra map.
///
/// @param grid - The 2D grid which represents the dungeon.
/// @param start - The start position for the algorithm.
Expand Down
1 change: 0 additions & 1 deletion src/hades_extensions/include/generation/primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ struct Grid {

/// Place a rect in the 2D grid.
///
/// @details It is the responsibility of the caller to ensure that the rect fits in the grid.
/// @param rect - The rect to place in the 2D grid.
void place_rect(const Rect &rect) const {
for (int y{std::max(rect.top_left.y, 0)}; y < std::min(rect.bottom_right.y + 1, height); y++) {
Expand Down
6 changes: 2 additions & 4 deletions src/hades_extensions/src/ecs/steering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ auto arrive(const cpVect &current_position, const cpVect &target_position) -> cp
}

auto evade(const cpVect &current_position, const cpVect &target_position, const cpVect &target_velocity) -> cpVect {
// Calculate the future position of the target based on their distance, and steer away from it.
// Higher distances will require more time to reach, so the future position will be further away
// Calculate the future position of the target based on their distance, and steer away from it
return flee(current_position,
target_position + target_velocity * (cpvdist(target_position, current_position) / MAX_VELOCITY));
}
Expand Down Expand Up @@ -99,8 +98,7 @@ auto obstacle_avoidance(cpSpace *space, const cpVect &current_position, const cp
}

auto pursue(const cpVect &current_position, const cpVect &target_position, const cpVect &target_velocity) -> cpVect {
// Calculate the future position of the target based on their distance, and steer away from it.
// Higher distances will require more time to reach, so the future position will be further away
// Calculate the future position of the target based on their distance, and steer towards it
return seek(current_position,
target_position + target_velocity * (cpvdist(target_position, current_position) / MAX_VELOCITY));
}
Expand Down
5 changes: 2 additions & 3 deletions src/hades_extensions/src/ecs/systems/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ void EffectSystem::update(const double delta_time) const {
auto &applied_effects{std::get<0>(component_tuple)->applied_effects};
std::vector<StatusEffectType> expired_status_effects;

// Update the status effects and keep track of the expired ones.
// Note that in reality, delta_time will be ~0.016 (60 FPS), so big jumps in time where multiple intervals are
// covered within a single update should never happen.
// Update the status effects and keep track of the expired ones. Note that in reality, delta_time will be ~0.016
// (60 FPS), so big jumps in time where multiple intervals are covered within a single update should never happen.
// But if they do, this will accumulate the leftover time and the status effect is applied in subsequent updates
for (auto &[status_effect_type, status_effect] : std::get<0>(component_tuple)->applied_effects) {
status_effect.time_counter += delta_time;
Expand Down
6 changes: 2 additions & 4 deletions src/hades_extensions/src/ecs/systems/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ auto InventorySystem::add_item_to_inventory(const GameObjectID game_object_id, c
get_registry()->notify_callbacks(EventType::InventoryUpdate, game_object_id);
get_registry()->notify_callbacks(EventType::SpriteRemoval, item);

// If the item has a kinematic component, set the collected flag to true to
// prevent collision detection
// If the item has a kinematic component, set the collected flag to true to prevent collision detection
if (get_registry()->has_component(item, typeid(KinematicComponent))) {
get_registry()->get_component<KinematicComponent>(item)->collected = true;
}
Expand All @@ -61,8 +60,7 @@ auto InventorySystem::remove_item_from_inventory(const GameObjectID game_object_
return false;
}

// Remove the item from the inventory, delete the game object, and notify the
// callbacks
// Remove the item from the inventory, delete the game object, and notify the callbacks
inventory->items.erase(inventory->items.begin() + index);
get_registry()->delete_game_object(item_id);
get_registry()->notify_callbacks(EventType::InventoryUpdate, game_object_id);
Expand Down
6 changes: 2 additions & 4 deletions src/hades_extensions/src/game_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ void GameEngine::create_game_objects() {
continue;
}

// If the tile is not a wall tile, we want an extra floor tile placed at
// the same position
// If the tile is not a wall tile, we want an extra floor tile placed at the same position
static const std::unordered_map<TileType, GameObjectType> tile_to_game_object_type{
{TileType::Floor, GameObjectType::Floor},
{TileType::Wall, GameObjectType::Wall},
Expand Down Expand Up @@ -106,8 +105,7 @@ void GameEngine::generate_enemy(const double /*delta_time*/) {
}
std::ranges::shuffle(floor_positions, std::mt19937{std::random_device{}()});

// Determine which floor to place the enemy on only trying
// ENEMY_RETRY_ATTEMPTS times
// Determine which floor to place the enemy on only trying ENEMY_RETRY_ATTEMPTS times
const auto &factories{get_factories()};
for (auto attempt{0}; attempt < std::min(static_cast<int>(floor_positions.size()), ENEMY_RETRY_ATTEMPTS); attempt++) {
const auto position{floor_positions[attempt]};
Expand Down
10 changes: 4 additions & 6 deletions src/hades_extensions/src/generation/dijkstra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ auto pathfind(const Grid &grid, const Position &start, const Position &end,
} // namespace

auto calculate_astar_path(const Grid &grid, const Position &start, const Position &end) -> std::vector<Position> {
// Explore the grid using the A* algorithm with the Chebyshev distance
// heuristic and then check if we've reached the end
// Explore the grid using the A* algorithm with the Chebyshev distance heuristic and then check if we've reached the
// end
const auto obstacle_check{
[&grid](const Position &neighbour) { return grid.get_value(neighbour) == TileType::Obstacle; }};
const auto chebyshev_heuristic{
Expand All @@ -76,8 +76,7 @@ auto calculate_astar_path(const Grid &grid, const Position &start, const Positio
return {};
}

// Backtrack through the neighbours to get the resultant path since we've
// reached the end
// Backtrack through the neighbours to get the resultant path since we've reached the end
std::vector<Position> path;
for (Position current{end}; current != start; current = result.at(current).source) {
path.push_back(current);
Expand All @@ -91,8 +90,7 @@ auto get_furthest_position(const Grid &grid, const Position &start) -> Position
Position furthest_position{.x = -1, .y = -1};
int max_distance{-1};

// Explore the grid using the Dijkstra algorithm to find the furthest
// position from the start
// Explore the grid using the Dijkstra algorithm to find the furthest position from the start
const auto floor_check{[&grid](const Position &neighbour) { return grid.get_value(neighbour) != TileType::Floor; }};
const auto dijkstra_heuristic{[&max_distance, &furthest_position](const Position &neighbour, const int cost) {
if (cost > max_distance) {
Expand Down
3 changes: 1 addition & 2 deletions src/hades_extensions/src/generation/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ void place_tiles(const Grid &grid, std::mt19937 &random_generator, const TileTyp
valid_positions.pop_back();
grid.set_value(possible_tile, target_tile);

// Remove all tiles from valid_positions within MIN_TILE_DISTANCE of the
// placed tile
// Remove all tiles from valid_positions within MIN_TILE_DISTANCE of the placed tile
std::erase_if(valid_positions, [&possible_tile](const Position &pos) {
return std::abs(pos.x - possible_tile.x) <= MIN_TILE_DISTANCE ||
std::abs(pos.y - possible_tile.y) <= MIN_TILE_DISTANCE;
Expand Down
5 changes: 2 additions & 3 deletions src/hades_extensions/tests/ecs/systems/test_attacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class AttackSystemFixture : public testing::Test {
return target;
}};

// Create the targets and add the attack system offseting the positions
// by (32, 32) since grid_pos_to_pixel() converts the target position to
//(32, 32)
// Create the targets and add the attack system offseting the positions by (32, 32) since grid_pos_to_pixel()
// converts the target position to (32, 32)
targets = {
create_target({12, -68}), create_target({52, 92}), create_target({-168, 132}), create_target({132, -68}),
create_target({-68, -68}), create_target({32, -168}), create_target({32, -160}), create_target({32, 32}),
Expand Down
3 changes: 1 addition & 2 deletions src/hades_extensions/tests/ecs/systems/test_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ TEST_F(InventorySystemFixture, TestInventorySystemRemoveItemFromInventoryValid)
auto sprite_removal_callback{[&](const GameObjectID game_object_id) { sprite_removal = game_object_id; }};
registry.add_callback(EventType::SpriteRemoval, sprite_removal_callback);

// Add two items and remove one of them from the inventory and check the
// results
// Add two items and remove one of them from the inventory and check the results
const auto item_id_one{create_item(GameObjectType::HealthPotion)};
const auto item_id_two{create_item(GameObjectType::HealthPotion)};
ASSERT_TRUE(get_inventory_system()->add_item_to_inventory(0, item_id_one));
Expand Down
3 changes: 1 addition & 2 deletions src/hades_extensions/tests/ecs/systems/test_movements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class FootprintSystemFixture : public testing::Test {
registry.add_system<FootprintSystem>();
registry.add_system<SteeringMovementSystem>();

// Set the position of the game object to (0, 0) since grid_pos_to_pixel
// sets the position to (32, 32)
// Set the position of the game object to (0, 0) since grid_pos_to_pixel() sets the position to (32, 32)
cpBodySetPosition(*registry.get_component<KinematicComponent>(0)->body, cpvzero);
}

Expand Down
3 changes: 1 addition & 2 deletions src/hades_extensions/tests/ecs/test_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ TEST_F(RegistryFixture, TestRegistryGameObjectKinematicComponent) {
ASSERT_FALSE(cpSpaceContainsShape(registry.get_space(), shape));
}

/// Test that a game object with duplicate components is added to the registry correctly.
/// Test that a game object with two identical components only adds the first one.
TEST_F(RegistryFixture, TestRegistryGameObjectDuplicateComponents) {
// Test that creating a game object with two of the same components only adds the first one
registry.create_game_object(GameObjectType::Player, cpvzero,
{std::make_shared<TestGameObjectComponentTwo>(std::vector({10})),
std::make_shared<TestGameObjectComponentTwo>(std::vector({20}))});
Expand Down

0 comments on commit 861245f

Please sign in to comment.