-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Keep a radius of cached regions loaded #2967
base: master
Are you sure you want to change the base?
Conversation
This implements an enhancement from cabaletta#324. I created the ChunkLoader class. This handles loading chunks around the player and render view entity in a given radius. The chunks are loaded from disk using the CachedWorld.tryLoadFromDisk function. If a chunk has not yet been added to the cache (in memory or on disk) then this will not cache it.
|
||
/** | ||
* Loads an area around the player and renderViewEntity to the cache. | ||
* The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think you meant to leave that here.
// Don't do anything if the world doesn't exist. Like in the main menu. | ||
if (worldData == null) return; | ||
loadAroundChunk(player.chunkCoordX, player.chunkCoordZ); | ||
// Only load around the renderViewEntity if it's in a different chunk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also don't do anything if the position didn't change since last tick?
Don't know whether the overhead of reloading every tick is more than the overhead of checking this.
src/main/java/baritone/Baritone.java
Outdated
@@ -120,6 +121,9 @@ | |||
this.worldProvider = new WorldProvider(); | |||
this.selectionManager = new SelectionManager(this); | |||
this.commandManager = new CommandManager(this); | |||
|
|||
ChunkLoader chunkLoader = new ChunkLoader(this, 2); // load 3 by 3 area of chunks around the player. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#324 suggested loading 3 by 3 regions around the player, not chunks.
Loading 3 by 3 chunks changes almost nothing, it now just loads the next region 16 blocks before you reach the region border instead of when you reach it.
if (worldData == null) return; | ||
loadAroundChunk(player.chunkCoordX, player.chunkCoordZ); | ||
// Only load around the renderViewEntity if it's in a different chunk. | ||
if (player.chunkCoordX != renderViewEntity.chunkCoordX || player.chunkCoordZ != renderViewEntity.chunkCoordZ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should compare region coords here because you can only load entire regions at once.
Previously the ChunkLoader would load chunks around the player but this was a misinterpretation. Now the renamed RedionLoader class loads regions around the player.
Thanks for the code review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two oversights and some formatting
src/main/java/baritone/Baritone.java
Outdated
RegionLoader chunkLoader = new RegionLoader(this, 2); // load 3 by 3 area of chunks around the player. | ||
this.gameEventHandler.registerEventListener(chunkLoader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to change the variable and the comment
public void onTick(TickEvent event) {this.loadRegions();} | ||
|
||
@Override | ||
public void onRenderPass(RenderEvent event) {this.loadRegions();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function body should be on a new line, but I'm not sure about that
EntityPlayerSP player = mc.player; | ||
Entity renderViewEntity = mc.getRenderViewEntity(); | ||
// Don't do anything before the player is loaded. | ||
if (player == null || renderViewEntity == null) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always use
if (cond) {
something();
}
rather than
if (cond) something();
} | ||
|
||
private void loadAroundRegion(int regionX, int regionZ) { | ||
System.out.println("loading around region x: " + regionX + " z: " + regionZ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remove this massive logspam. If you are flying around with freecam this is 9 lines per frame and tick.
I fixed it. Thanks again for looking it over. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
This implements an enhancement from #324. I created the ChunkLoader
class. This handles loading chunks around the player and render view
entity in a given radius. The chunks are loaded from disk using the
CachedWorld.tryLoadFromDisk function. If a chunk has not yet been
added to the cache (in memory or on disk) then this will not cache it.
Curently the class is initialized from the Baritone constructor. I don't know if this is okay or if it should be done elsewhere.
I couldn't find a good place for it because it needs to be registered with the GameEventHandler.
I also noticed that the ICachedWorld interface does not include the tryLoadFromDisk function even though it is public.
I don't know if this is intentional or not. In this commit I decided to just cast the ICachedWorld to a CachedWorld.