Commit ada10af7 by Jonathan Thomas

Improved client render performance (only query nearby entities every 3rd call)

parent 929305ad
Pipeline #12670 passed with stages
in 2 minutes 6 seconds
...@@ -15,6 +15,7 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -15,6 +15,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
### Changed ### Changed
- Chat Bubble rendering & interacting is now dependent on whitelist / blacklist config - Chat Bubble rendering & interacting is now dependent on whitelist / blacklist config
- Improved client render performance (only query nearby entities every 3rd call)
- Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee. - Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee.
- Fixed certain behaviors from colliding with others (i.e. mutual exclusive ones) - Fixed certain behaviors from colliding with others (i.e. mutual exclusive ones)
- Updated README.md with new video thumbnail, and simplified text, added spoiler to install instructions - Updated README.md with new video thumbnail, and simplified text, added spoiler to install instructions
......
...@@ -47,6 +47,8 @@ public class BubbleRenderer { ...@@ -47,6 +47,8 @@ public class BubbleRenderer {
public static int overlay = OverlayTexture.DEFAULT_UV; public static int overlay = OverlayTexture.DEFAULT_UV;
public static List<String> whitelist = new ArrayList<>(); public static List<String> whitelist = new ArrayList<>();
public static List<String> blacklist = new ArrayList<>(); public static List<String> blacklist = new ArrayList<>();
private static int queryEntityDataCount = 0;
private static List<Entity> relevantEntities;
public static void drawTextBubbleBackground(String base_name, MatrixStack matrices, float x, float y, float width, float height, int friendship) { public static void drawTextBubbleBackground(String base_name, MatrixStack matrices, float x, float y, float width, float height, int friendship) {
// Set shader & texture // Set shader & texture
...@@ -351,26 +353,35 @@ public class BubbleRenderer { ...@@ -351,26 +353,35 @@ public class BubbleRenderer {
// Get camera position // Get camera position
Vec3d interpolatedCameraPos = new Vec3d(camera.getPos().x, camera.getPos().y, camera.getPos().z); Vec3d interpolatedCameraPos = new Vec3d(camera.getPos().x, camera.getPos().y, camera.getPos().z);
// Get all entities // Increment query counter
List<Entity> nearbyEntities = world.getOtherEntities(null, area); queryEntityDataCount++;
// Filter to include only MobEntity & PlayerEntity but exclude any camera 1st person entity and any entities with passengers // This query count helps us cache the list of relevant entities. We can refresh
List<Entity> relevantEntities = nearbyEntities.stream() // the list every 3rd call to this render function
.filter(entity -> (entity instanceof MobEntity || entity instanceof PlayerEntity)) if (queryEntityDataCount % 3 == 0 || relevantEntities == null) {
.filter(entity -> !entity.hasPassengers()) // Get all entities
.filter(entity -> !(entity.equals(cameraEntity) && !camera.isThirdPerson())) List<Entity> nearbyEntities = world.getOtherEntities(null, area);
.filter(entity -> !(entity.equals(cameraEntity) && entity.isSpectator()))
.filter(entity -> { // Filter to include only MobEntity & PlayerEntity but exclude any camera 1st person entity and any entities with passengers
Identifier entityId = Registries.ENTITY_TYPE.getId(entity.getType()); relevantEntities = nearbyEntities.stream()
String entityIdString = entityId.toString(); .filter(entity -> (entity instanceof MobEntity || entity instanceof PlayerEntity))
// Check blacklist first .filter(entity -> !entity.hasPassengers())
if (blacklist.contains(entityIdString)) { .filter(entity -> !(entity.equals(cameraEntity) && !camera.isThirdPerson()))
return false; .filter(entity -> !(entity.equals(cameraEntity) && entity.isSpectator()))
} .filter(entity -> {
// If whitelist is not empty, only include entities in the whitelist Identifier entityId = Registries.ENTITY_TYPE.getId(entity.getType());
return whitelist.isEmpty() || whitelist.contains(entityIdString); String entityIdString = entityId.toString();
}) // Check blacklist first
.collect(Collectors.toList()); if (blacklist.contains(entityIdString)) {
return false;
}
// If whitelist is not empty, only include entities in the whitelist
return whitelist.isEmpty() || whitelist.contains(entityIdString);
})
.collect(Collectors.toList());
queryEntityDataCount = 0;
}
for (Entity entity : relevantEntities) { for (Entity entity : relevantEntities) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment