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

AStarGrid2D allow to disable (set solid ) all points when creating new instance - allow to override the default #7276

Closed
2fd5 opened this issue Jul 14, 2023 · 2 comments · Fixed by godotengine/godot#79495

Comments

@2fd5
Copy link

2fd5 commented Jul 14, 2023

Describe the project you are working on

realtime 2D grid based strategy

Describe the problem or limitation you are having in your project

In AStarGrid2D by default, all points are enabled (solid set to false). It is not optimal for my use case.
In my case the grid is mostly empty and is being populated at run time. Having them enabled by default forces user to iterate over whole grid and disable most or all points. This is one time operation in initialisation.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Allow for passing argument in constructor of AStarGrid2D to choose the default value. This way user might choose what is the most optimal for theirs use case

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Interface could be like that for example:

var astar_grid: AStarGrid2D = AStarGrid2D.new(solid = true)

If no argument is given the current default would be used of solid being default to false for each grid cell

If this enhancement will not be used often, can it be worked around with a few lines of script?

yes. iterate over every cell in grid and set set_point_solid to disable.

Is there a reason why this should be core and not an add-on in the asset library?

Seems to be more flexible and not forcing user to do unnecessary work. Allowing to chose default would cover bigger userbase.

@dalexeev
Copy link
Member

@2fd5 Could you please clarify what exactly is your problem? The grid update code takes 3 lines:

for i in range(a_star.region.position.x, a_star.region.end.x):
    for j in range(a_star.region.position.y, a_star.region.end.y):
        a_star.set_point_solid(Vector2i(i, j))

Perhaps you are worried about performance if the region is large? Please let me know if godotengine/godot#79495 is an acceptable solution for you.

@akien-mga akien-mga added this to the 4.2 milestone Aug 4, 2023
@2fd5
Copy link
Author

2fd5 commented Aug 13, 2023

@2fd5 Could you please clarify what exactly is your problem? The grid update code takes 3 lines:

for i in range(a_star.region.position.x, a_star.region.end.x):
    for j in range(a_star.region.position.y, a_star.region.end.y):
        a_star.set_point_solid(Vector2i(i, j))

Perhaps you are worried about performance if the region is large? Please let me know if godotengine/godot#79495 is an acceptable solution for you.

Main concern was performance. Thanks, fill_region will solve the issue plus cover more use cases, Thank you

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

Successfully merging a pull request may close this issue.

3 participants