Skip to content

perf: Optimization + chunk system - #228

Draft
michelfinley wants to merge 8 commits into
sloukit:mainfrom
michelfinley:perf/optimization
Draft

perf: Optimization + chunk system#228
michelfinley wants to merge 8 commits into
sloukit:mainfrom
michelfinley:perf/optimization

Conversation

@michelfinley

Copy link
Copy Markdown

Summary

This PR optimizes several code sections to improve performace.

  • implement a chunk system for rendering and collision checks
  • [WIP] use numpy for pathfinding to reduce fps drops when NPCs start moving
  • several small performance improvements
  • fix pygbag compatibility

Overall, this increases average FPS by about 2-2.5x on both desktop and pygbag

Checklist

  • I have tested this change locally and it works as expected.
  • I have made sure that the code follows the formatting and style guidelines of the project.

Labels

type: enhancement, game-playtesting

Sprites are now rendered in chunks to reduce the amount of calls to pygame.Surface.blit

Entity collision does also work in chunks now, so Entities only check for collision with nearby colliders

---

This is still work in progress, some small issues are not yet fixed:

- the Player does not yet collide with the barn entrance on the cow herding minigame

- the use of emotes currently crashes the game

- the rendering chunk manager is centred on the Player instead of the Camera, which results in the map not being fully loaded during times when the Camera is not centred on the Player (i.e. cutscenes and close to the map border)

- the Player currently collides with dead NPCs
@DangerousVanilla

Copy link
Copy Markdown
Collaborator

@michelfinley, looks like a lot of great work going on here! You might check with @tank-king too, he was doing some work toward optimizing the blur effect when you where the glasses and possibly something else I can't remember.

Super nice to see you have the FPS like 4x on my PC at least but when you put on those glasses it still drops to an abysmal 35fps or so which will become unplayable online with pygbag. That might already be on your agenda here, just figured I'd throw it out there just in case!

@tank-king

Copy link
Copy Markdown
Collaborator

Very good! I have the draft of my performance boost fix, I can post it here if you want, or I can make a new PR once this draft is completed.

@Mega-JC Mega-JC added type: enhancement Improvements to any established aspect of the project area: code quality Improving the quality of the codebase labels Oct 31, 2024
@sloukit

sloukit commented Nov 6, 2024

Copy link
Copy Markdown
Owner

@DangerousVanilla can you approve this for merging?

@michelfinley

Copy link
Copy Markdown
Author

@tank-king Thanks! Whatever you prefer, you are welcome to add it here if you'd like :D

@michelfinley

Copy link
Copy Markdown
Author

@DangerousVanilla Thanks a lot! Nice that the games performance increased even more on your side than it did on mine, it makes me really optimistic that it eventually runs on pygbag with good avg fps :D
And yeah... I've also noticed that the FPS often drop when NPCs are searching for a new path, leading to stuttering - I'm still looking to improve that as well

@DangerousVanilla

Copy link
Copy Markdown
Collaborator

@sloukit, it doesn't look like this PR ever got completed. There are some visual issues like black screen on startup and some odd texture stretching during the intro that will need fixed before testing can continue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: code quality Improving the quality of the codebase type: enhancement Improvements to any established aspect of the project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants