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

Add cost stamps #1745

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

Add cost stamps #1745

wants to merge 10 commits into from

Conversation

dmwever
Copy link
Contributor

@dmwever dmwever commented Jan 22, 2025

fixes #1676.

libopenage/pathfinding/cost_field.h Outdated Show resolved Hide resolved
@dmwever dmwever requested a review from jere8184 January 23, 2025 22:17
/**
* Cost stamp vector.
*/
std::vector<std::optional<cost_stamp_t>> cost_stamps;
Copy link
Contributor

Choose a reason for hiding this comment

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

you need to make sure cost_stamps is initialised in the constructor with the correct size

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.

Looks pretty good so far.

In addition to the fixes to the comments I made, you should also add unit tests for stamping and unstamping the cost field in tests.cpp.

libopenage/pathfinding/cost_field.cpp Outdated Show resolved Hide resolved
Comment on lines +63 to +64
this->cost_stamps[idx]->original_cost = original_cost;
this->cost_stamps[idx]->stamp_time = stamped_at;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this code will work, i.e. it could segfault because the optional value is not initialized. You have to explicitely assign it a cost_stamp_t struct before you can access the members directly. So you have to write something like

this->cost_stamps[idx] = cost_stamp_t{
    orginal_cost,
    stamped_at,
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Learning the ropes of c++ here.

libopenage/pathfinding/cost_field.cpp Outdated Show resolved Hide resolved
* @param cost Cost to set.
* @param stamped_at Time at which the cost cell is to be stamped.
*
* @return True if the cell was successfully stamped, false if the cell was already stamped.
Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit over overwriting the stamp? I'm just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I was considering what would happen if one stamp was placed, and then if another stamp was placed while the first was active. If the stamp is overwritten, how do we communicate with the object that placed the first stamp? If that first object unstamps, it would unstamp the second object's stamp value. If instead we tell the second object that there is already a stamp in place there, we avoid data miscommunication. The downside is that we can't double-stamp, but that would be the downside with stamp overwriting as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cost stamps (pathfinder)
3 participants