-
Notifications
You must be signed in to change notification settings - Fork 7
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
Rewrite #56
Draft
tversteeg
wants to merge
75
commits into
master
Choose a base branch
from
refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Split debug into multiple scenes that can be scrolled through with space. Change all `f64` to `f32` for usage with the parry crate.
Add Axis-Aligned Bounding Rectangle (AABR) type. Add orientable Rectangle shape that can calculate it's AABR. Debug draw AABR.
Refactor constraints so they are more extensible without needing too much boilerplate. Spatial grid ignores entities outside of its bounds.
Start profiling.
Add many profiling measurements. Fix some clippy warnings.
Using Ramer Douglas Peucker for line simplifacation and Marching Squares for finding the edges of the image.
Note for finding islands in the solid shape algorithm:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another attempt at rewriting it, this time using the
pixels
crate for rendering pixels as both a WASM- and a desktop application.I ended up not liking bevy for my previous attempt. I'm also removing the ECS (for now) since it added a lot of complexity. Furthermore, I'm trying to keep the code as simple as possible without any "smart" solutions for future long-term problems that might not even occur. And nothing screams "keeping-it-simple" like writing your own physics engine, right? I fell in the trap of writing complicated things again…
The physics engine is based on Extended Position Based Dynamics, I'm roughly following this paper but of course only for 2D. The
bevy_xpbd
crate is also a great source. For collision detection, I first planned to use theparry
crate, but I also wanted to give this a shot myself. I got the Separating Axis Theorem to work properly for the narrow-phase collision detection, but I couldn't get proper contact points, so I switched toparry
. At first I implemented the broad-phase detection using a Spatial Hash Grid with a fixed bucket size. The performance was not so great and due to all buckets being statically allocated the size of the grid was also very limited. So I switched to thebvh-arena
crate.After getting the physics engine somewhat functional, I did manage that the performance was quite bad. I played around with different benchmarks and profiling to see what was the culprit, and it's mostly related to the data layout of
RigidBody
, which grew to be a huge struct with 224 bytes of data. Of course iterating over this is not very efficient cache-wise, so I made the decision to locally refactor the rigidbody structure into an ECS, abstracting this behind getters and setters using the handles I previously also used so it wouldn't leak into the rest of the game logic.To make the terrain destructible similarly to Worms and also to allow creation of simple breakable projectiles such as stones or shrapnel, I've implemented a solid shape type, which is a bitmap that automatically generates a sprite with an outline. It also automatically generates a polygon collider by doing a Marching Squares algorithm on the first outline pixel it finds. This is then simplified with an implementation of the Ramer-Douglas-Peucker algorithm.
Another major improvement is the
assets_manager
crate I've integrated. This allows for hot-reloading of assets, which saves a tremendous amount of time with tweaking variables and waiting for re-compiles.The art style is inspired by the vector art of my previous bevy attempt, but now it's a pixel-art version of that. I'm procedurally generating the terrain in quite a simple way: a buffer is created for each horizontal height and a random factor is to everyone from its previous neighbor, also a direction is changed every set amount of pixels as an additional factor. I could have created a prettier implementation with something like perlin noise but this suffices for now.
http://tversteeg.nl/castle-game/
Some progress screenshares:
collision-detection.webm
rigidbodies.webm
walking-unit.webm
box-debug.webm
draw-hole.webm