ucsd-cse125-sp24 / group5

A character-based ability shooter 2v2 heavily inspired by Four Seasons
https://cse125.ucsd.edu/2024/cse125g5
6 stars 0 forks source link

Updated movement #13

Closed Melody-Ruth closed 5 months ago

Melody-Ruth commented 5 months ago

In this PR:

More explanation of the second part: We already had the players as Entities. I've put all of the information about each player into Components and added ComponentManagers to World to keep track of them. Physics functionality (e.g. changing the position of moving entities based on their velocity) is now in different Systems. I split the Systems up since we'll eventually have Entities that move but aren't player controlled, and the collision system will get much more complicated in the future. I moved loading up a ServerToClient packet out of ServerNetwork since I think the network shouldn't be messing with game state at all. Now we construct the packet in ServerGame using a helper function in World (since World is the one that has full knowledge of the game state). If we ever have global game state that's part of ServerGame instead of being a component, we can add that to the packet afterwards. Then we pass of the completed packet to ServerNetwork to send. Importantly, moving the packet sending also means that we only send an update to the clients once per tick instead of once every time we get a packet from them. This should fix the standardization issue where movement felt different on different platforms.

I'm using unique_ptrs and shared_ptrs instead of normal pointers, so hopefully memory leaks won't be an issue (but I don't know enough about c++ to say for sure).

Before approving, please read the code and also run it. The behavior we're looking for is that you can still see the world, adjust your view direction, and move, with the addition that movement feels smoother (small acceleration at the start). Also make sure that double jump works (if you press jump, then release and press it again while you're in the air, you should jump again).

Alanine42 commented 5 months ago

nice work! That's a ton of refactoring... will need some time to let them sink in

Tested, functionality stays the same.

realmatthewpeng commented 5 months ago

Also I'm not sure how to test for memory leaks, will need someone else to check on that front.

benjxia commented 5 months ago

Also I'm not sure how to test for memory leaks, will need someone else to check on that front.

Neither do I, on windows at least. So far I've just been eyeballing the memory leaks

benjxia commented 5 months ago

We shouldn't(?) get memory leaks if we keep using smart pointers though

Alanine42 commented 5 months ago

Also I'm not sure how to test for memory leaks, will need someone else to check on that front.

I don't think there're memory leaks... But if someone is willing to go through this would b really nice https://stackoverflow.com/questions/5134891/how-do-i-use-valgrind-to-find-memory-leaks

benjxia commented 5 months ago

Also I'm not sure how to test for memory leaks, will need someone else to check on that front.

I don't think there're memory leaks... But if someone is willing to go through this would b really nice https://stackoverflow.com/questions/5134891/how-do-i-use-valgrind-to-find-memory-leaks

Valgrind doesn't work on Windows. I'm well aware of how to find them in UNIX environments.