Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathfinder history #1748

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

jere8184
Copy link
Contributor

@jere8184 jere8184 commented Jan 26, 2025

fixes: #1680

/**
* Array curve recording cell cost history,
*/
curve::Array<cost_t, CHUNK_SIZE> cell_cost_history;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should cell_cost_history be exposed? A simple getter that returns a constant ref to the curve?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be enough I think.

Copy link
Member

@heinezen heinezen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long wait, I was very busy with work 😅 Now that I have some time, I added a few suggestions to the code.

Comment on lines +110 to +115
void set_insert_range(const time::time_t &t, auto begin_it, auto end_it) {
ENSURE(std::distance(begin_it, end_it) <= Size,
"trying to insert more values than there are postions: max allowed = " << Size);
index_t i = 0;
std::for_each(begin_it, end_it, [&](const T &val) { this->set_insert(t, i++, val); });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea. Would it also make sense to make index configurable? Then we could even replace slices of the array.

@@ -105,6 +106,14 @@ class Array : event::EventEntity {
*/
std::pair<time::time_t, T> next_frame(const time::time_t &t, const index_t index) const;


void set_insert_range(const time::time_t &t, auto begin_it, auto end_it) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, would be nice if the method gets documented :)

}

bool CostField::stamp(size_t idx, cost_t cost, const time::time_t &stamped_at) {
if (this->cost_stamps[idx].has_value()) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always make if clauses multi-line for consistent code style.

Suggested change
if (this->cost_stamps[idx].has_value()) return false;
if (this->cost_stamps[idx].has_value()) {
return false;
}

}

bool CostField::unstamp(size_t idx, const time::time_t &unstamped_at) {
if (!this->cost_stamps[idx].has_value() || unstamped_at < this->cost_stamps[idx]->stamp_time) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and not/and/or should be used as operators for better readability.

Suggested change
if (!this->cost_stamps[idx].has_value() || unstamped_at < this->cost_stamps[idx]->stamp_time) return false;
if (not this->cost_stamps[idx].has_value() or unstamped_at < this->cost_stamps[idx]->stamp_time) {
return false;
}

@@ -14,6 +16,8 @@ namespace coord {
struct tile_delta;
} // namespace coord

const unsigned int CHUNK_SIZE = 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value should probably not be hardcoded because then the cost field size is not configurable anymore. I think we either need to make CostField a templated class or wait for the implementation of curve::Vector in #1677 . Both approaches would have pros and cons.

/**
* Array curve recording cell cost history,
*/
curve::Array<cost_t, CHUNK_SIZE> cell_cost_history;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be enough I think.

Comment on lines +128 to +130
/**
* Cost stamp for a given cost field cell.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small explanation of stamping for people who don't know what that is would be nice here. I added a suggesion below.

Suggested change
/**
* Cost stamp for a given cost field cell.
*/
/**
* Cost stamp for a cell on a cost field.
*
* Stamps are used when cell costs are temporarily overwritten, e.g. when placing a game object
* as an obstacle over terrain. Once the obstacle is removed, the cell can be reset to its original
* value recorded by the stamp.
*/

@heinezen heinezen added the area: simulation Involved in the game mechanics and simulation label Apr 8, 2025
@heinezen heinezen added improvement Enhancement of an existing component lang: c++ Done in C++ code labels Apr 8, 2025
@heinezen heinezen moved this from 📋 Backlog to 👀 In review in openage game simulation Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: simulation Involved in the game mechanics and simulation improvement Enhancement of an existing component lang: c++ Done in C++ code
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

Record history of cost changes in pathfinder
3 participants