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

Encapsulate looking up a decorId from CollisionObjects #36

Merged

Conversation

Deconimus
Copy link
Contributor

@Deconimus Deconimus commented Mar 9, 2024

See this comment in #31.

Added int decorIdForCollisionObject(struct CollisionObject* collisionObject) to decor_object_list and replaced all relevant calls.

…nObjects into the function decorIdForCollisionObject(struct CollisionObject*)
@mwpenny mwpenny added the enhancement New feature or request label Mar 12, 2024
@mwpenny
Copy link
Owner

mwpenny commented Mar 12, 2024

Looks good. We might eventually need a global ID system for collision objects.

@mwpenny mwpenny merged commit 87af5a0 into mwpenny:master Mar 12, 2024
@Deconimus
Copy link
Contributor Author

We might eventually need a global ID system for collision objects.

Perhaps. For collision objects this could be kept rather simple though, e.g. COLLISION_TYPE_STATIC, COLLISION_TYPE_DYNAMIC, COLLISION_TYPE_DECOR etc.

I was thinking, maybe we should have a way of accessing the decor object that the collision object belongs to (if any). Looking at how collisionObject.trigger callbacks are implemented with their collisionObject.data void-pointer (e.g. in trigger_listener or fizzler). Collision objects of type COLLISION_TYPE_DECOR could either store the pointer to the decor object in collisionObject.data, or in a new pointer collisionObject.decor for stronger type-safety.

@Deconimus Deconimus deleted the encapsulate_decorIdFromCollisionObject branch March 12, 2024 19:22
@mwpenny
Copy link
Owner

mwpenny commented Mar 14, 2024

That's true. There are tradeoffs: IDs make comparisons between different types easy but add some duplication. The data pointer approach requires checks for each collision type but provides access to arbitrary object information after that.

Right now though, regardless of approach, the information needed in the end would ultimately just be the object type anyway (e.g., decorType == DECOR_TYPE_CUBE).

In most cases, I imagine only like types will be compared, and so the data pointer would work well for that. As we discussed in #31, this isn't needed right now, but would be useful when the time comes.

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

Successfully merging this pull request may close these issues.

2 participants