Skip to content

Adding pathfinding using SDF example #10

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zet23t
Copy link

@zet23t zet23t commented May 19, 2024

No description provided.

Copy link
Contributor

@JeffM2501 JeffM2501 left a comment

Choose a reason for hiding this comment

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

Please add a copy of the premake5.lua file to the folder so that it will build with the other examples.

Comment on lines 354 to 367
int pathRatStartX = 5;
int pathRatStartY = 25;
int pathRatEndX = 75;
int pathRatEndY = 25;
PathfindingNode *mapRat = (PathfindingNode *)MemAlloc(gridWidth * gridHeight * sizeof(PathfindingNode));
PathfindingNode *pathRat = (PathfindingNode *)MemAlloc(gridWidth * gridHeight * sizeof(PathfindingNode) * 4);
int pathRatLength = 0;
int ratWallFactor = 2;

// cat setup
int pathCatStartX = 5;
int pathCatStartY = 25;
int pathCatEndX = 75;
int pathCatEndY = 25;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lot of arguments, many that are just X and Y variants.
Can we use vector2 or some other structure to clean this up?

Copy link
Author

Choose a reason for hiding this comment

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

True. I can create a dedicated struct for each entity. It would be nice if raylib had a Vector2Int... I wanted to keep it integer based (not sure if worth it).

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything infernally uses floats, so is there any real benefit to keeping it ints? If you need to you can just call floor on the floats.

Copy link
Author

Choose a reason for hiding this comment

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

True. It was a decision based on gut feeling. I would keep it for now. I moved the data into structs so I hope it's more organized now.

Copy link
Contributor

@JeffM2501 JeffM2501 left a comment

Choose a reason for hiding this comment

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

The main function is a bit huge, It would be best to break that up into functions with descriptive names.

@zet23t zet23t force-pushed the main branch 2 times, most recently from 3b4e978 to 9280336 Compare May 19, 2024 21:07
@zet23t
Copy link
Author

zet23t commented May 19, 2024

I reworked it quite a bit and it's now more data oriented. I hope it's also more readable (or at least not less readable).


typedef struct Agent
{
int startX, startY;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to use floats when possible.


}

void Agent_findPath(Agent *agent, int enableJumping)
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is huge, can it be broken up more? maybe in places where you have comments, that should be a sub function for readability?

I fear that most people will not be able to follow this code.

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.

2 participants