Skip to content

Refactor/object position dimensions #93

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

Merged
merged 10 commits into from
May 11, 2024

Conversation

gilkeidar
Copy link
Contributor

Refactored Object position + dimensions information to avoid state duplication which required careful syncing of different fields.

Here is the new position + dimensions Object paradigm:

  1. Object now has a ModelType enum field that specifies the rendering model that this Object should render as by the client. (For the DM, this may require setting ModelType::None (which doesn't exist currently) or the client can simply hard-code the behavior that the DM shouldn't be rendered regardless of its specified model type)
  2. The Collider field in the Physics struct has been replaced: instead of a Collider * to one of the derived Collider classes (BoxCollider or SphereCollider), it now has a Collider enum field which can be either Box or Sphere, with collision detection placed in global functions declared in server/game/collider.hpp. This means colliders have no state and utilize the SharedPhysics fields of corner and dimensions to detect collisions.
  3. The position field in SharedPhysics has been removed.
  4. The dimensions field in SharedSolidSurface has been removed.

The Object class now has a new static field: static std::unordered_map<ModelType, glm::vec3> models which maps the ModelType enum values to their model's default dimensions. Currently, these are all hard-coded in object.cpp, but this can be replaced by the server reading the model object files upon initialization and populating this hash map dynamically.

Note: The hard-coded dimensions for ModelType::Player and ModelType::WarrenBear do NOT currently correspond to the actual model dimensions! Their values are my current guesses as I'm not sure how to extract the models' dimension data. If the player / warren bear do not render properly / in the right positions, this is likely why.

Closes #90

gilkeidar added 4 commits May 9, 2024 20:10
…SolidSurface` (note: player eye level + rendering and warren bear rendering positions are likely off from their expected locations
…d duplication object position and dimensions)
@gilkeidar gilkeidar added enhancement New feature or request Must have Gameplay i love gameeing labels May 10, 2024
@gilkeidar gilkeidar self-assigned this May 10, 2024
Copy link
Contributor

@Tyler-Lentz Tyler-Lentz left a comment

Choose a reason for hiding this comment

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

I'm doing this on my phone while riding the bus, so I'll be able to test on my computer in a bit. I just left the one potential tiny comment which might be nice to have. Also, if we could remove the commented out code that would be nice, so we don't get confused later. I'll drop the approve in a bit once I verify it works on my laptop (which it should but just want to be sure)

Overall this is incredibly helpful! Thanks so much for grinding this out!

auto player_pos = glm::vec3(sharedObject->physics.position.x, sharedObject->physics.position.y + 0.1, sharedObject->physics.position.z);
//auto player_pos = glm::vec3(sharedObject->physics.position.x, sharedObject->physics.position.y + 0.1, sharedObject->physics.position.z);

auto player_pos = sharedObject->physics.corner + (sharedObject->physics.dimensions / 2.0f);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can make a function on the Physics struct called getCenterPos that does this calculation for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added!

@Tyler-Lentz Tyler-Lentz self-requested a review May 10, 2024 20:56
Copy link
Contributor

@Tyler-Lentz Tyler-Lentz left a comment

Choose a reason for hiding this comment

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

just pushed a fix for the client side UI which had broken in a previous PR and we didn't notice. this should be good to merge once we clear out the commented code

yipee-1

gilkeidar added 5 commits May 10, 2024 14:07
…CollisionSphere()` and `detectCollisionBox()` to ensure correct behavior if the second argument of `detectCollision()` has `Collider::None`
…me code that did center position calculation with a call to this method
Copy link
Contributor

@atar13 atar13 left a comment

Choose a reason for hiding this comment

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

Looks great. I'm liking this new structure.

@gilkeidar gilkeidar merged commit 186a4ff into dev May 11, 2024
10 of 11 checks passed
@Tyler-Lentz Tyler-Lentz deleted the refactor/object-position-dimensions branch May 22, 2024 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Gameplay i love gameeing Must have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants