MouJouNakki / Archimedes-Fluids

Other
4 stars 3 forks source link

Custom refactor to 1.20.1 codebase to reduce impact on tick performance / server #12

Closed Syclusion closed 11 months ago

Syclusion commented 11 months ago

Heavily modified MixinFlowingFluid to enhance the amount of server resources it draws, same done to fluidpool. Server performance was top priority, focusing on transferFluid specifically. Fluidlogging is probably broken, will be fixed in the next update. Many files were trimmed and optimized to max tps. Will provide supporting documentation for performance improvements upon request. (Can't really think of anything else to write so here is a chatgpt analysis). Feel free to make modifications to this, hoping to make this mod the best it can be.

Comparing the original and optimized versions of the MixinFlowingFluid Java class reveals several changes focused on code optimization and functionality enhancements:

Import Statements: The optimized version includes additional import statements for ArrayList, Arrays, Collections, and List, which are used for handling collections more efficiently in the code.

Fluid Transfer Logic:

In the original version, the transferFluid method was overloaded multiple times with different parameter sets. The optimized version streamlines this by using fewer overloads and more explicit method calls, improving readability and potentially performance. The original code uses a random shuffle method (shuffledCopy) directly on Direction.Plane.HORIZONTAL. The optimized version manually creates a list of directions, shuffles it, and iterates through it. This change could be for more control over the shuffling process. Direction Handling:

The optimized code introduces an array of directions and a shuffled list of directions within the tick method. This change might be for better control over the order of processing directions, which could affect how fluids spread in the game environment. Randomness in Fluid Spread:

The optimized version includes a conditional check amount == 1 && Math.random() < 0.3 which adds an element of randomness to the fluid spread when the fluid amount is 1. This feature seems to be an enhancement to make the fluid behavior more dynamic. Refactoring and Code Cleanliness:

The optimized version appears to be more refactored with a clearer separation of concerns, making the code easier to read and maintain. For instance, extracting fluid transfer logic into separate methods. Error Handling:

In the changeFluid method, both versions throw an exception when the fluid amount exceeds a certain limit. However, the error message formatting seems more concise in the optimized version. Code Comments:

The original version includes a commented-out line .setValue(ArchimedesFluids.FLUIDLOGGED, new Fluidlogging(this)), which is not present in the optimized version. This might indicate a cleanup of unused or experimental code. Shadow Methods:

Both versions include several @Shadow annotated methods. These are likely unchanged between versions and are used for accessing or modifying the behavior of private methods in the superclass (due to the nature of mixins in modding frameworks like SpongePowered). Overall, the optimizations seem to focus on improving the fluid dynamics, enhancing the randomness and realism of fluid behavior, and making the code more readable and maintainable. The changes do not drastically alter the core functionality but refine and enhance it.

Syclusion commented 11 months ago

Not ready yet actually, sawy

Syclusion commented 11 months ago

Should be gucci, triple checked this time. Last version had really bad bug where fluids would delete over time. Tested changes and seems fixed

Syclusion commented 11 months ago

Also fluidlogging appears fully functional after changes

Syclusion commented 11 months ago

Let me know if you have any more questions, first attempt at a pr. But I did my best :)